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_workerscope_h__ michael@0: #define mozilla_dom_workerscope_h__ michael@0: michael@0: #include "Workers.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class Console; michael@0: class Function; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: BEGIN_WORKERS_NAMESPACE michael@0: michael@0: class WorkerPrivate; michael@0: class WorkerLocation; michael@0: class WorkerNavigator; michael@0: michael@0: class WorkerGlobalScope : public DOMEventTargetHelper, michael@0: public nsIGlobalObject michael@0: { michael@0: nsRefPtr mConsole; michael@0: nsRefPtr mLocation; michael@0: nsRefPtr mNavigator; michael@0: michael@0: protected: michael@0: WorkerPrivate* mWorkerPrivate; michael@0: michael@0: WorkerGlobalScope(WorkerPrivate* aWorkerPrivate); michael@0: virtual ~WorkerGlobalScope(); michael@0: michael@0: public: michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: virtual JSObject* michael@0: WrapGlobalObject(JSContext* aCx) = 0; michael@0: michael@0: virtual JSObject* michael@0: GetGlobalJSObject(void) MOZ_OVERRIDE michael@0: { michael@0: return GetWrapper(); michael@0: } michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope, michael@0: DOMEventTargetHelper) michael@0: michael@0: already_AddRefed michael@0: Self() michael@0: { michael@0: return nsRefPtr(this).forget(); michael@0: } michael@0: michael@0: already_AddRefed michael@0: GetConsole(); michael@0: michael@0: already_AddRefed michael@0: Location(); michael@0: michael@0: already_AddRefed michael@0: Navigator(); michael@0: michael@0: already_AddRefed michael@0: GetExistingNavigator() const; michael@0: michael@0: void michael@0: Close(JSContext* aCx); michael@0: michael@0: OnErrorEventHandlerNonNull* michael@0: GetOnerror(); michael@0: void michael@0: SetOnerror(OnErrorEventHandlerNonNull* aHandler); michael@0: michael@0: void michael@0: ImportScripts(JSContext* aCx, const Sequence& aScriptURLs, michael@0: ErrorResult& aRv); michael@0: michael@0: int32_t michael@0: SetTimeout(JSContext* aCx, Function& aHandler, const int32_t aTimeout, michael@0: const Sequence& aArguments, ErrorResult& aRv); michael@0: int32_t michael@0: SetTimeout(JSContext* /* unused */, const nsAString& aHandler, michael@0: const int32_t aTimeout, const Sequence& /* unused */, michael@0: ErrorResult& aRv); michael@0: void michael@0: ClearTimeout(int32_t aHandle, ErrorResult& aRv); michael@0: int32_t michael@0: SetInterval(JSContext* aCx, Function& aHandler, michael@0: const Optional& aTimeout, michael@0: const Sequence& aArguments, ErrorResult& aRv); michael@0: int32_t michael@0: SetInterval(JSContext* /* unused */, const nsAString& aHandler, michael@0: const Optional& aTimeout, michael@0: const Sequence& /* unused */, ErrorResult& aRv); michael@0: void michael@0: ClearInterval(int32_t aHandle, ErrorResult& aRv); michael@0: michael@0: void michael@0: Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const; michael@0: void michael@0: Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const; michael@0: michael@0: IMPL_EVENT_HANDLER(online) michael@0: IMPL_EVENT_HANDLER(offline) michael@0: IMPL_EVENT_HANDLER(close) michael@0: michael@0: void michael@0: Dump(const Optional& aString) const; michael@0: }; michael@0: michael@0: class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope michael@0: { michael@0: ~DedicatedWorkerGlobalScope() { } michael@0: michael@0: public: michael@0: DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate); michael@0: michael@0: static bool michael@0: Visible(JSContext* aCx, JSObject* aObj); michael@0: michael@0: virtual JSObject* michael@0: WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: void michael@0: PostMessage(JSContext* aCx, JS::Handle aMessage, michael@0: const Optional>& aTransferable, michael@0: ErrorResult& aRv); michael@0: michael@0: IMPL_EVENT_HANDLER(message) michael@0: }; michael@0: michael@0: class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope michael@0: { michael@0: const nsCString mName; michael@0: michael@0: ~SharedWorkerGlobalScope() { } michael@0: michael@0: public: michael@0: SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, michael@0: const nsCString& aName); michael@0: michael@0: static bool michael@0: Visible(JSContext* aCx, JSObject* aObj); michael@0: michael@0: virtual JSObject* michael@0: WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: void GetName(DOMString& aName) const { michael@0: aName.AsAString() = NS_ConvertUTF8toUTF16(mName); michael@0: } michael@0: michael@0: IMPL_EVENT_HANDLER(connect) michael@0: }; michael@0: michael@0: JSObject* michael@0: CreateGlobalScope(JSContext* aCx); michael@0: michael@0: END_WORKERS_NAMESPACE michael@0: michael@0: #endif /* mozilla_dom_workerscope_h__ */