dom/workers/SharedWorker.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/SharedWorker.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_dom_workers_sharedworker_h__
    1.10 +#define mozilla_dom_workers_sharedworker_h__
    1.11 +
    1.12 +#include "Workers.h"
    1.13 +
    1.14 +#include "mozilla/dom/BindingDeclarations.h"
    1.15 +#include "mozilla/dom/workers/bindings/MessagePort.h"
    1.16 +#include "mozilla/DOMEventTargetHelper.h"
    1.17 +
    1.18 +class nsIDOMEvent;
    1.19 +class nsPIDOMWindow;
    1.20 +
    1.21 +namespace mozilla {
    1.22 +class EventChainPreVisitor;
    1.23 +} // namespace mozilla
    1.24 +
    1.25 +BEGIN_WORKERS_NAMESPACE
    1.26 +
    1.27 +class MessagePort;
    1.28 +class RuntimeService;
    1.29 +class WorkerPrivate;
    1.30 +
    1.31 +class SharedWorker MOZ_FINAL : public DOMEventTargetHelper
    1.32 +{
    1.33 +  friend class MessagePort;
    1.34 +  friend class RuntimeService;
    1.35 +
    1.36 +  typedef mozilla::ErrorResult ErrorResult;
    1.37 +  typedef mozilla::dom::GlobalObject GlobalObject;
    1.38 +
    1.39 +  nsRefPtr<WorkerPrivate> mWorkerPrivate;
    1.40 +  nsRefPtr<MessagePort> mMessagePort;
    1.41 +  nsTArray<nsCOMPtr<nsIDOMEvent>> mSuspendedEvents;
    1.42 +  uint64_t mSerial;
    1.43 +  bool mSuspended;
    1.44 +
    1.45 +public:
    1.46 +  static already_AddRefed<SharedWorker>
    1.47 +  Constructor(const GlobalObject& aGlobal, JSContext* aCx,
    1.48 +              const nsAString& aScriptURL, const Optional<nsAString>& aName,
    1.49 +              ErrorResult& aRv);
    1.50 +
    1.51 +  already_AddRefed<MessagePort>
    1.52 +  Port();
    1.53 +
    1.54 +  uint64_t
    1.55 +  Serial() const
    1.56 +  {
    1.57 +    return mSerial;
    1.58 +  }
    1.59 +
    1.60 +  bool
    1.61 +  IsSuspended() const
    1.62 +  {
    1.63 +    return mSuspended;
    1.64 +  }
    1.65 +
    1.66 +  void
    1.67 +  Suspend();
    1.68 +
    1.69 +  void
    1.70 +  Resume();
    1.71 +
    1.72 +  void
    1.73 +  QueueEvent(nsIDOMEvent* aEvent);
    1.74 +
    1.75 +  void
    1.76 +  Close();
    1.77 +
    1.78 +  NS_DECL_ISUPPORTS_INHERITED
    1.79 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SharedWorker, DOMEventTargetHelper)
    1.80 +
    1.81 +  IMPL_EVENT_HANDLER(error)
    1.82 +
    1.83 +  virtual JSObject*
    1.84 +  WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.85 +
    1.86 +  virtual nsresult
    1.87 +  PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
    1.88 +
    1.89 +  WorkerPrivate*
    1.90 +  GetWorkerPrivate() const
    1.91 +  {
    1.92 +    return mWorkerPrivate;
    1.93 +  }
    1.94 +
    1.95 +private:
    1.96 +  // This class can only be created from the RuntimeService.
    1.97 +  SharedWorker(nsPIDOMWindow* aWindow,
    1.98 +               WorkerPrivate* aWorkerPrivate);
    1.99 +
   1.100 +  // This class is reference-counted and will be destroyed from Release().
   1.101 +  ~SharedWorker();
   1.102 +
   1.103 +  // Only called by MessagePort.
   1.104 +  void
   1.105 +  PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
   1.106 +              const Optional<Sequence<JS::Value>>& aTransferable,
   1.107 +              ErrorResult& aRv);
   1.108 +
   1.109 +  // Only called by RuntimeService.
   1.110 +  void
   1.111 +  NoteDeadWorker(JSContext* aCx);
   1.112 +};
   1.113 +
   1.114 +END_WORKERS_NAMESPACE
   1.115 +
   1.116 +#endif // mozilla_dom_workers_sharedworker_h__

mercurial