dom/workers/WorkerScope.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_dom_workerscope_h__
michael@0 7 #define mozilla_dom_workerscope_h__
michael@0 8
michael@0 9 #include "Workers.h"
michael@0 10 #include "mozilla/DOMEventTargetHelper.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace dom {
michael@0 14
michael@0 15 class Console;
michael@0 16 class Function;
michael@0 17
michael@0 18 } // namespace dom
michael@0 19 } // namespace mozilla
michael@0 20
michael@0 21 BEGIN_WORKERS_NAMESPACE
michael@0 22
michael@0 23 class WorkerPrivate;
michael@0 24 class WorkerLocation;
michael@0 25 class WorkerNavigator;
michael@0 26
michael@0 27 class WorkerGlobalScope : public DOMEventTargetHelper,
michael@0 28 public nsIGlobalObject
michael@0 29 {
michael@0 30 nsRefPtr<Console> mConsole;
michael@0 31 nsRefPtr<WorkerLocation> mLocation;
michael@0 32 nsRefPtr<WorkerNavigator> mNavigator;
michael@0 33
michael@0 34 protected:
michael@0 35 WorkerPrivate* mWorkerPrivate;
michael@0 36
michael@0 37 WorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
michael@0 38 virtual ~WorkerGlobalScope();
michael@0 39
michael@0 40 public:
michael@0 41 virtual JSObject*
michael@0 42 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 43
michael@0 44 virtual JSObject*
michael@0 45 WrapGlobalObject(JSContext* aCx) = 0;
michael@0 46
michael@0 47 virtual JSObject*
michael@0 48 GetGlobalJSObject(void) MOZ_OVERRIDE
michael@0 49 {
michael@0 50 return GetWrapper();
michael@0 51 }
michael@0 52
michael@0 53 NS_DECL_ISUPPORTS_INHERITED
michael@0 54 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope,
michael@0 55 DOMEventTargetHelper)
michael@0 56
michael@0 57 already_AddRefed<WorkerGlobalScope>
michael@0 58 Self()
michael@0 59 {
michael@0 60 return nsRefPtr<WorkerGlobalScope>(this).forget();
michael@0 61 }
michael@0 62
michael@0 63 already_AddRefed<Console>
michael@0 64 GetConsole();
michael@0 65
michael@0 66 already_AddRefed<WorkerLocation>
michael@0 67 Location();
michael@0 68
michael@0 69 already_AddRefed<WorkerNavigator>
michael@0 70 Navigator();
michael@0 71
michael@0 72 already_AddRefed<WorkerNavigator>
michael@0 73 GetExistingNavigator() const;
michael@0 74
michael@0 75 void
michael@0 76 Close(JSContext* aCx);
michael@0 77
michael@0 78 OnErrorEventHandlerNonNull*
michael@0 79 GetOnerror();
michael@0 80 void
michael@0 81 SetOnerror(OnErrorEventHandlerNonNull* aHandler);
michael@0 82
michael@0 83 void
michael@0 84 ImportScripts(JSContext* aCx, const Sequence<nsString>& aScriptURLs,
michael@0 85 ErrorResult& aRv);
michael@0 86
michael@0 87 int32_t
michael@0 88 SetTimeout(JSContext* aCx, Function& aHandler, const int32_t aTimeout,
michael@0 89 const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
michael@0 90 int32_t
michael@0 91 SetTimeout(JSContext* /* unused */, const nsAString& aHandler,
michael@0 92 const int32_t aTimeout, const Sequence<JS::Value>& /* unused */,
michael@0 93 ErrorResult& aRv);
michael@0 94 void
michael@0 95 ClearTimeout(int32_t aHandle, ErrorResult& aRv);
michael@0 96 int32_t
michael@0 97 SetInterval(JSContext* aCx, Function& aHandler,
michael@0 98 const Optional<int32_t>& aTimeout,
michael@0 99 const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
michael@0 100 int32_t
michael@0 101 SetInterval(JSContext* /* unused */, const nsAString& aHandler,
michael@0 102 const Optional<int32_t>& aTimeout,
michael@0 103 const Sequence<JS::Value>& /* unused */, ErrorResult& aRv);
michael@0 104 void
michael@0 105 ClearInterval(int32_t aHandle, ErrorResult& aRv);
michael@0 106
michael@0 107 void
michael@0 108 Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const;
michael@0 109 void
michael@0 110 Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const;
michael@0 111
michael@0 112 IMPL_EVENT_HANDLER(online)
michael@0 113 IMPL_EVENT_HANDLER(offline)
michael@0 114 IMPL_EVENT_HANDLER(close)
michael@0 115
michael@0 116 void
michael@0 117 Dump(const Optional<nsAString>& aString) const;
michael@0 118 };
michael@0 119
michael@0 120 class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
michael@0 121 {
michael@0 122 ~DedicatedWorkerGlobalScope() { }
michael@0 123
michael@0 124 public:
michael@0 125 DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
michael@0 126
michael@0 127 static bool
michael@0 128 Visible(JSContext* aCx, JSObject* aObj);
michael@0 129
michael@0 130 virtual JSObject*
michael@0 131 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 132
michael@0 133 void
michael@0 134 PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
michael@0 135 const Optional<Sequence<JS::Value>>& aTransferable,
michael@0 136 ErrorResult& aRv);
michael@0 137
michael@0 138 IMPL_EVENT_HANDLER(message)
michael@0 139 };
michael@0 140
michael@0 141 class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
michael@0 142 {
michael@0 143 const nsCString mName;
michael@0 144
michael@0 145 ~SharedWorkerGlobalScope() { }
michael@0 146
michael@0 147 public:
michael@0 148 SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
michael@0 149 const nsCString& aName);
michael@0 150
michael@0 151 static bool
michael@0 152 Visible(JSContext* aCx, JSObject* aObj);
michael@0 153
michael@0 154 virtual JSObject*
michael@0 155 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 156
michael@0 157 void GetName(DOMString& aName) const {
michael@0 158 aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
michael@0 159 }
michael@0 160
michael@0 161 IMPL_EVENT_HANDLER(connect)
michael@0 162 };
michael@0 163
michael@0 164 JSObject*
michael@0 165 CreateGlobalScope(JSContext* aCx);
michael@0 166
michael@0 167 END_WORKERS_NAMESPACE
michael@0 168
michael@0 169 #endif /* mozilla_dom_workerscope_h__ */

mercurial