michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_workers_sharedworker_h__ michael@0: #define mozilla_dom_workers_sharedworker_h__ michael@0: michael@0: #include "Workers.h" michael@0: michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: #include "mozilla/dom/workers/bindings/MessagePort.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: michael@0: class nsIDOMEvent; michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: class EventChainPreVisitor; michael@0: } // namespace mozilla michael@0: michael@0: BEGIN_WORKERS_NAMESPACE michael@0: michael@0: class MessagePort; michael@0: class RuntimeService; michael@0: class WorkerPrivate; michael@0: michael@0: class SharedWorker MOZ_FINAL : public DOMEventTargetHelper michael@0: { michael@0: friend class MessagePort; michael@0: friend class RuntimeService; michael@0: michael@0: typedef mozilla::ErrorResult ErrorResult; michael@0: typedef mozilla::dom::GlobalObject GlobalObject; michael@0: michael@0: nsRefPtr mWorkerPrivate; michael@0: nsRefPtr mMessagePort; michael@0: nsTArray> mSuspendedEvents; michael@0: uint64_t mSerial; michael@0: bool mSuspended; michael@0: michael@0: public: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, JSContext* aCx, michael@0: const nsAString& aScriptURL, const Optional& aName, michael@0: ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: Port(); michael@0: michael@0: uint64_t michael@0: Serial() const michael@0: { michael@0: return mSerial; michael@0: } michael@0: michael@0: bool michael@0: IsSuspended() const michael@0: { michael@0: return mSuspended; michael@0: } michael@0: michael@0: void michael@0: Suspend(); michael@0: michael@0: void michael@0: Resume(); michael@0: michael@0: void michael@0: QueueEvent(nsIDOMEvent* aEvent); michael@0: michael@0: void michael@0: Close(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SharedWorker, DOMEventTargetHelper) michael@0: michael@0: IMPL_EVENT_HANDLER(error) michael@0: michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult michael@0: PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; michael@0: michael@0: WorkerPrivate* michael@0: GetWorkerPrivate() const michael@0: { michael@0: return mWorkerPrivate; michael@0: } michael@0: michael@0: private: michael@0: // This class can only be created from the RuntimeService. michael@0: SharedWorker(nsPIDOMWindow* aWindow, michael@0: WorkerPrivate* aWorkerPrivate); michael@0: michael@0: // This class is reference-counted and will be destroyed from Release(). michael@0: ~SharedWorker(); michael@0: michael@0: // Only called by MessagePort. michael@0: void michael@0: PostMessage(JSContext* aCx, JS::Handle aMessage, michael@0: const Optional>& aTransferable, michael@0: ErrorResult& aRv); michael@0: michael@0: // Only called by RuntimeService. michael@0: void michael@0: NoteDeadWorker(JSContext* aCx); michael@0: }; michael@0: michael@0: END_WORKERS_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_workers_sharedworker_h__