tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WorkerScope.h (20170B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_workerscope_h__
      8 #define mozilla_dom_workerscope_h__
      9 
     10 #include "js/TypeDecls.h"
     11 #include "js/loader/ModuleLoaderBase.h"
     12 #include "mozilla/Assertions.h"
     13 #include "mozilla/Attributes.h"
     14 #include "mozilla/DOMEventTargetHelper.h"
     15 #include "mozilla/Maybe.h"
     16 #include "mozilla/RefPtr.h"
     17 #include "mozilla/TimeStamp.h"
     18 #include "mozilla/UniquePtr.h"
     19 #include "mozilla/dom/AnimationFrameProvider.h"
     20 #include "mozilla/dom/ImageBitmapBinding.h"
     21 #include "mozilla/dom/ImageBitmapSource.h"
     22 #include "mozilla/dom/PerformanceWorker.h"
     23 #include "mozilla/dom/SafeRefPtr.h"
     24 #include "mozilla/dom/TimeoutManager.h"
     25 #include "mozilla/dom/TrustedTypePolicyFactory.h"
     26 #include "mozilla/dom/WorkerPrivate.h"
     27 #include "nsCOMPtr.h"
     28 #include "nsCycleCollectionParticipant.h"
     29 #include "nsIGlobalObject.h"
     30 #include "nsISupports.h"
     31 #include "nsWeakReference.h"
     32 
     33 #ifdef XP_WIN
     34 #  undef PostMessage
     35 #endif
     36 
     37 class nsAtom;
     38 class nsISerialEventTarget;
     39 
     40 namespace mozilla {
     41 class ErrorResult;
     42 struct VsyncEvent;
     43 
     44 namespace extensions {
     45 
     46 class ExtensionBrowser;
     47 
     48 }  // namespace extensions
     49 
     50 namespace dom {
     51 
     52 class AnyCallback;
     53 enum class CallerType : uint32_t;
     54 class ClientInfo;
     55 class ClientSource;
     56 class Clients;
     57 class Console;
     58 class CookieStore;
     59 class Crypto;
     60 class DOMString;
     61 class DebuggerNotificationManager;
     62 enum class EventCallbackDebuggerNotificationType : uint8_t;
     63 class EventHandlerNonNull;
     64 class FontFaceSet;
     65 class Function;
     66 class FunctionOrTrustedScriptOrString;
     67 class IDBFactory;
     68 class OnErrorEventHandlerNonNull;
     69 template <typename T>
     70 class Optional;
     71 class OwningTrustedScriptURLOrString;
     72 class Performance;
     73 class Promise;
     74 class RequestOrUTF8String;
     75 template <typename T>
     76 class Sequence;
     77 class ServiceWorkerDescriptor;
     78 class ServiceWorkerRegistration;
     79 class ServiceWorkerRegistrationDescriptor;
     80 struct StructuredSerializeOptions;
     81 class TimeoutManager;
     82 class WorkerDocumentListener;
     83 class WorkerLocation;
     84 class WorkerNavigator;
     85 class WorkerPrivate;
     86 class VsyncWorkerChild;
     87 class WebTaskScheduler;
     88 class WebTaskSchedulerWorker;
     89 class WebTaskSchedulingState;
     90 struct RequestInit;
     91 
     92 namespace cache {
     93 
     94 class CacheStorage;
     95 
     96 }  // namespace cache
     97 
     98 class WorkerGlobalScopeBase : public DOMEventTargetHelper,
     99                              public nsSupportsWeakReference,
    100                              public nsIGlobalObject {
    101  friend class WorkerPrivate;
    102 
    103 public:
    104  NS_DECL_ISUPPORTS_INHERITED
    105  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScopeBase,
    106                                                         DOMEventTargetHelper)
    107 
    108  WorkerGlobalScopeBase(WorkerPrivate* aWorkerPrivate,
    109                        UniquePtr<ClientSource> aClientSource);
    110 
    111  mozilla::dom::TimeoutManager* GetTimeoutManager() override final {
    112    return mTimeoutManager.get();
    113  }
    114 
    115  virtual bool WrapGlobalObject(JSContext* aCx,
    116                                JS::MutableHandle<JSObject*> aReflector) = 0;
    117 
    118  // EventTarget implementation
    119  JSObject* WrapObject(JSContext* aCx,
    120                       JS::Handle<JSObject*> aGivenProto) final {
    121    MOZ_CRASH("WrapObject not supported; use WrapGlobalObject.");
    122  }
    123 
    124  // nsIGlobalObject implementation
    125  JSObject* GetGlobalJSObject() final;
    126 
    127  JSObject* GetGlobalJSObjectPreserveColor() const final;
    128 
    129  bool IsSharedMemoryAllowed() const final;
    130 
    131  bool ShouldResistFingerprinting(RFPTarget aTarget) const final;
    132 
    133  OriginTrials Trials() const final;
    134 
    135  StorageAccess GetStorageAccess() final;
    136 
    137  nsICookieJarSettings* GetCookieJarSettings() final;
    138 
    139  nsIURI* GetBaseURI() const final;
    140 
    141  Maybe<ClientInfo> GetClientInfo() const final;
    142  Maybe<ClientState> GetClientState() const final;
    143 
    144  Maybe<ServiceWorkerDescriptor> GetController() const final;
    145 
    146  mozilla::Result<mozilla::ipc::PrincipalInfo, nsresult> GetStorageKey() final;
    147 
    148  virtual void Control(const ServiceWorkerDescriptor& aServiceWorker);
    149 
    150  // DispatcherTrait implementation
    151  nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const final;
    152  nsISerialEventTarget* SerialEventTarget() const final;
    153 
    154  MOZ_CAN_RUN_SCRIPT
    155  void ReportError(JSContext* aCx, JS::Handle<JS::Value> aError,
    156                   CallerType aCallerType, ErrorResult& aRv);
    157 
    158  // atob, btoa, and dump are declared (separately) by both WorkerGlobalScope
    159  // and WorkerDebuggerGlobalScope WebIDL interfaces
    160  void Atob(const nsAString& aAtob, nsAString& aOut, ErrorResult& aRv) const;
    161 
    162  void Btoa(const nsAString& aBtoa, nsAString& aOut, ErrorResult& aRv) const;
    163 
    164  already_AddRefed<Console> GetConsole(ErrorResult& aRv);
    165 
    166  Console* GetConsoleIfExists() const { return mConsole; }
    167 
    168  void InitModuleLoader(JS::loader::ModuleLoaderBase* aModuleLoader) {
    169    if (!mModuleLoader) {
    170      mModuleLoader = aModuleLoader;
    171    }
    172  }
    173 
    174  // The nullptr here is not used, but is required to make the override method
    175  // have the same signature as other GetModuleLoader methods on globals.
    176  JS::loader::ModuleLoaderBase* GetModuleLoader(
    177      JSContext* aCx = nullptr) override {
    178    return mModuleLoader;
    179  };
    180 
    181  uint64_t WindowID() const;
    182 
    183  // Usually global scope dies earlier than the WorkerPrivate, but if we see
    184  // it leak at least we can tell it to not carry away a dead pointer.
    185  void NoteWorkerTerminated() { mWorkerPrivate = nullptr; }
    186 
    187  ClientSource& MutableClientSourceRef() const { return *mClientSource; }
    188 
    189  bool IsBackgroundInternal() const override {
    190    MOZ_ASSERT(mWorkerPrivate);
    191    return mWorkerPrivate->IsRunningInBackground();
    192  }
    193 
    194  MOZ_CAN_RUN_SCRIPT bool RunTimeoutHandler(
    195      mozilla::dom::Timeout* aTimeout) override;
    196  bool IsFrozen() const override {
    197    return mWorkerPrivate->IsFrozenForWorkerThread();
    198  }
    199 
    200  // workers don't support both frozen and suspended,
    201  // either both are true, or both are false.
    202  bool IsSuspended() const override {
    203    return mWorkerPrivate->IsFrozenForWorkerThread();
    204  }
    205 
    206  void UpdateWebSocketCount(int32_t aDelta) override {
    207    if (aDelta == 0) {
    208      return;
    209    }
    210 
    211    MOZ_DIAGNOSTIC_ASSERT(
    212        aDelta > 0 || ((aDelta + mNumOfOpenWebSockets) < mNumOfOpenWebSockets));
    213 
    214    mNumOfOpenWebSockets += aDelta;
    215  }
    216 
    217  // Increase/Decrease the number of active IndexedDB databases for the
    218  // decision making of timeout-throttling.
    219  void UpdateActiveIndexedDBDatabaseCount(int32_t aDelta) override {
    220    AssertIsOnWorkerThread();
    221    mNumOfIndexedDBDatabases += aDelta;
    222  }
    223 
    224  bool HasOpenWebSockets() const override { return mNumOfOpenWebSockets; }
    225 
    226  bool HasActiveIndexedDBDatabases() const override {
    227    AssertIsOnWorkerThread();
    228    return mNumOfIndexedDBDatabases;
    229  }
    230 
    231  bool IsPlayingAudio() override {
    232    AssertIsOnWorkerThread();
    233    return mWorkerPrivate && mWorkerPrivate->IsPlayingAudio();
    234  }
    235 
    236  bool HasActivePeerConnections() override {
    237    AssertIsOnWorkerThread();
    238    return mWorkerPrivate && mWorkerPrivate->HasActivePeerConnections();
    239  }
    240 
    241  void TriggerUpdateCCFlag() override {
    242    mWorkerPrivate->UpdateCCFlag(WorkerPrivate::CCFlag::EligibleForTimeout);
    243  }
    244 
    245  static WorkerGlobalScopeBase* Cast(nsIGlobalObject* obj) {
    246    return static_cast<WorkerGlobalScopeBase*>(obj);
    247  }
    248 
    249 protected:
    250  ~WorkerGlobalScopeBase();
    251 
    252  CheckedUnsafePtr<WorkerPrivate> mWorkerPrivate;
    253 
    254  void AssertIsOnWorkerThread() const {
    255    MOZ_ASSERT(mWorkerThreadUsedOnlyForAssert == PR_GetCurrentThread());
    256  }
    257 
    258 private:
    259  RefPtr<Console> mConsole;
    260  RefPtr<JS::loader::ModuleLoaderBase> mModuleLoader;
    261  const UniquePtr<ClientSource> mClientSource;
    262  nsCOMPtr<nsISerialEventTarget> mSerialEventTarget;
    263 #ifdef DEBUG
    264  PRThread* mWorkerThreadUsedOnlyForAssert;
    265 #endif
    266  mozilla::UniquePtr<mozilla::dom::TimeoutManager> mTimeoutManager;
    267  uint32_t mNumOfOpenWebSockets{};
    268  uint32_t mNumOfIndexedDBDatabases{};
    269 };
    270 
    271 namespace workerinternals {
    272 
    273 class NamedWorkerGlobalScopeMixin {
    274 public:
    275  explicit NamedWorkerGlobalScopeMixin(const nsAString& aName) : mName(aName) {}
    276 
    277  void GetName(DOMString& aName) const;
    278 
    279 protected:
    280  ~NamedWorkerGlobalScopeMixin() = default;
    281 
    282 private:
    283  const nsString mName;
    284 };
    285 
    286 }  // namespace workerinternals
    287 
    288 class WorkerGlobalScope : public WorkerGlobalScopeBase {
    289 public:
    290  NS_DECL_ISUPPORTS_INHERITED
    291  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(WorkerGlobalScope,
    292                                           WorkerGlobalScopeBase)
    293 
    294  using WorkerGlobalScopeBase::WorkerGlobalScopeBase;
    295 
    296  void NoteTerminating();
    297 
    298  void NoteShuttingDown();
    299 
    300  // nsIGlobalObject implementation
    301  already_AddRefed<ServiceWorkerContainer> GetServiceWorkerContainer() final;
    302 
    303  RefPtr<ServiceWorker> GetOrCreateServiceWorker(
    304      const ServiceWorkerDescriptor& aDescriptor) final;
    305 
    306  RefPtr<ServiceWorkerRegistration> GetServiceWorkerRegistration(
    307      const ServiceWorkerRegistrationDescriptor& aDescriptor) const final;
    308 
    309  RefPtr<ServiceWorkerRegistration> GetOrCreateServiceWorkerRegistration(
    310      const ServiceWorkerRegistrationDescriptor& aDescriptor) final;
    311 
    312  DebuggerNotificationManager* GetOrCreateDebuggerNotificationManager() final;
    313 
    314  DebuggerNotificationManager* GetExistingDebuggerNotificationManager() final;
    315 
    316  Maybe<EventCallbackDebuggerNotificationType> GetDebuggerNotificationType()
    317      const final;
    318 
    319  mozilla::dom::StorageManager* GetStorageManager() final;
    320 
    321  void SetIsNotEligibleForMessaging() { mIsEligibleForMessaging = false; }
    322 
    323  bool IsEligibleForMessaging() final;
    324 
    325  void ReportToConsole(uint32_t aErrorFlags, const nsCString& aCategory,
    326                       nsContentUtils::PropertiesFile aFile,
    327                       const nsCString& aMessageName,
    328                       const nsTArray<nsString>& aParams,
    329                       const mozilla::SourceLocation& aLocation) final;
    330 
    331  // WorkerGlobalScope WebIDL implementation
    332  WorkerGlobalScope* Self() { return this; }
    333 
    334  already_AddRefed<WorkerLocation> Location();
    335 
    336  already_AddRefed<WorkerNavigator> Navigator();
    337 
    338  already_AddRefed<WorkerNavigator> GetExistingNavigator() const;
    339 
    340  FontFaceSet* GetFonts(ErrorResult&);
    341  FontFaceSet* GetFonts() final { return GetFonts(IgnoreErrors()); }
    342 
    343  MOZ_CAN_RUN_SCRIPT void ImportScripts(
    344      JSContext* aCx,
    345      const Sequence<OwningTrustedScriptURLOrString>& aScriptURLs,
    346      nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv);
    347 
    348  OnErrorEventHandlerNonNull* GetOnerror();
    349 
    350  void SetOnerror(OnErrorEventHandlerNonNull* aHandler);
    351 
    352  IMPL_EVENT_HANDLER(languagechange)
    353  IMPL_EVENT_HANDLER(offline)
    354  IMPL_EVENT_HANDLER(online)
    355  IMPL_EVENT_HANDLER(rejectionhandled)
    356  IMPL_EVENT_HANDLER(unhandledrejection)
    357 
    358  void Dump(const Optional<nsAString>& aString) const;
    359 
    360  Performance* GetPerformance();
    361 
    362  Performance* GetPerformanceIfExists() const { return mPerformance; }
    363 
    364  static bool IsInAutomation(JSContext* aCx, JSObject*);
    365 
    366  void GetJSTestingFunctions(JSContext* aCx,
    367                             JS::MutableHandle<JSObject*> aFunctions,
    368                             ErrorResult& aRv);
    369 
    370  // GlobalCrypto WebIDL implementation
    371  Crypto* GetCrypto(ErrorResult& aError);
    372 
    373  // WindowOrWorkerGlobalScope WebIDL implementation
    374  void GetOrigin(nsAString& aOrigin) const;
    375 
    376  bool CrossOriginIsolated() const final;
    377 
    378  MOZ_CAN_RUN_SCRIPT
    379  int32_t SetTimeout(JSContext* aCx,
    380                     const FunctionOrTrustedScriptOrString& aHandler,
    381                     int32_t aTimeout, const Sequence<JS::Value>& aArguments,
    382                     nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv);
    383 
    384  MOZ_CAN_RUN_SCRIPT
    385  void ClearTimeout(int32_t aHandle);
    386 
    387  MOZ_CAN_RUN_SCRIPT
    388  int32_t SetInterval(JSContext* aCx,
    389                      const FunctionOrTrustedScriptOrString& aHandler,
    390                      int32_t aTimeout, const Sequence<JS::Value>& aArguments,
    391                      nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv);
    392 
    393  MOZ_CAN_RUN_SCRIPT
    394  void ClearInterval(int32_t aHandle);
    395 
    396  already_AddRefed<Promise> CreateImageBitmap(
    397      const ImageBitmapSource& aImage, const ImageBitmapOptions& aOptions,
    398      ErrorResult& aRv);
    399 
    400  already_AddRefed<Promise> CreateImageBitmap(
    401      const ImageBitmapSource& aImage, int32_t aSx, int32_t aSy, int32_t aSw,
    402      int32_t aSh, const ImageBitmapOptions& aOptions, ErrorResult& aRv);
    403 
    404  void StructuredClone(JSContext* aCx, JS::Handle<JS::Value> aValue,
    405                       const StructuredSerializeOptions& aOptions,
    406                       JS::MutableHandle<JS::Value> aRetval,
    407                       ErrorResult& aError);
    408 
    409  already_AddRefed<Promise> Fetch(const RequestOrUTF8String& aInput,
    410                                  const RequestInit& aInit,
    411                                  CallerType aCallerType, ErrorResult& aRv);
    412 
    413  bool IsSecureContext() const;
    414 
    415  already_AddRefed<IDBFactory> GetIndexedDB(JSContext* aCx,
    416                                            ErrorResult& aErrorResult);
    417 
    418  already_AddRefed<cache::CacheStorage> GetCaches(ErrorResult& aRv);
    419 
    420  WebTaskScheduler* Scheduler();
    421  WebTaskScheduler* GetExistingScheduler() const;
    422  void SetWebTaskSchedulingState(WebTaskSchedulingState* aState) override;
    423  bool HasScheduledNormalOrHighPriorityWebTasks() const override;
    424 
    425  WebTaskSchedulingState* GetWebTaskSchedulingState() const override {
    426    return mWebTaskSchedulingState;
    427  }
    428 
    429  bool WindowInteractionAllowed() const;
    430 
    431  void AllowWindowInteraction();
    432 
    433  void ConsumeWindowInteraction();
    434 
    435  void StorageAccessPermissionGranted();
    436 
    437  virtual void OnDocumentVisible(bool aVisible) {}
    438 
    439  MOZ_CAN_RUN_SCRIPT_BOUNDARY
    440  virtual void OnVsync(const VsyncEvent& aVsync) {}
    441 
    442  TrustedTypePolicyFactory* TrustedTypes();
    443 
    444 protected:
    445  ~WorkerGlobalScope();
    446 
    447 private:
    448  MOZ_CAN_RUN_SCRIPT
    449  int32_t SetTimeoutOrInterval(
    450      JSContext* aCx, const FunctionOrTrustedScriptOrString& aHandler,
    451      int32_t aTimeout, const Sequence<JS::Value>& aArguments, bool aIsInterval,
    452      nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv);
    453 
    454  RefPtr<Crypto> mCrypto;
    455  RefPtr<WorkerLocation> mLocation;
    456  RefPtr<WorkerNavigator> mNavigator;
    457  RefPtr<FontFaceSet> mFontFaceSet;
    458  RefPtr<Performance> mPerformance;
    459  RefPtr<IDBFactory> mIndexedDB;
    460  RefPtr<cache::CacheStorage> mCacheStorage;
    461  RefPtr<DebuggerNotificationManager> mDebuggerNotificationManager;
    462  RefPtr<WebTaskSchedulerWorker> mWebTaskScheduler;
    463  RefPtr<WebTaskSchedulingState> mWebTaskSchedulingState;
    464  RefPtr<TrustedTypePolicyFactory> mTrustedTypePolicyFactory;
    465  uint32_t mWindowInteractionsAllowed = 0;
    466  bool mIsEligibleForMessaging{true};
    467 };
    468 
    469 class DedicatedWorkerGlobalScope final
    470    : public WorkerGlobalScope,
    471      public workerinternals::NamedWorkerGlobalScopeMixin {
    472 public:
    473  NS_DECL_ISUPPORTS_INHERITED
    474  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
    475      DedicatedWorkerGlobalScope, WorkerGlobalScope)
    476 
    477  DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
    478                             UniquePtr<ClientSource> aClientSource,
    479                             const nsString& aName);
    480 
    481  bool WrapGlobalObject(JSContext* aCx,
    482                        JS::MutableHandle<JSObject*> aReflector) override;
    483 
    484  void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
    485                   const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
    486 
    487  void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
    488                   const StructuredSerializeOptions& aOptions,
    489                   ErrorResult& aRv);
    490 
    491  void Close();
    492 
    493  MOZ_CAN_RUN_SCRIPT
    494  uint32_t RequestAnimationFrame(FrameRequestCallback& aCallback,
    495                                 ErrorResult& aError);
    496 
    497  MOZ_CAN_RUN_SCRIPT
    498  void CancelAnimationFrame(uint32_t aHandle, ErrorResult& aError);
    499 
    500  void OnDocumentVisible(bool aVisible) override;
    501 
    502  MOZ_CAN_RUN_SCRIPT_BOUNDARY
    503  void OnVsync(const VsyncEvent& aVsync) override;
    504 
    505  IMPL_EVENT_HANDLER(message)
    506  IMPL_EVENT_HANDLER(messageerror)
    507  IMPL_EVENT_HANDLER(rtctransform)
    508 
    509 private:
    510  ~DedicatedWorkerGlobalScope() = default;
    511 
    512  FrameRequestManager mFrameRequestManager;
    513  RefPtr<VsyncWorkerChild> mVsyncChild;
    514  RefPtr<WorkerDocumentListener> mDocListener;
    515  bool mDocumentVisible = false;
    516 };
    517 
    518 class SharedWorkerGlobalScope final
    519    : public WorkerGlobalScope,
    520      public workerinternals::NamedWorkerGlobalScopeMixin {
    521 public:
    522  SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
    523                          UniquePtr<ClientSource> aClientSource,
    524                          const nsString& aName);
    525 
    526  bool WrapGlobalObject(JSContext* aCx,
    527                        JS::MutableHandle<JSObject*> aReflector) override;
    528 
    529  void Close();
    530 
    531  IMPL_EVENT_HANDLER(connect)
    532 
    533 private:
    534  ~SharedWorkerGlobalScope() = default;
    535 };
    536 
    537 class ServiceWorkerGlobalScope final : public WorkerGlobalScope {
    538 public:
    539  NS_DECL_ISUPPORTS_INHERITED
    540  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope,
    541                                           WorkerGlobalScope)
    542 
    543  ServiceWorkerGlobalScope(
    544      WorkerPrivate* aWorkerPrivate, UniquePtr<ClientSource> aClientSource,
    545      const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor);
    546 
    547  bool WrapGlobalObject(JSContext* aCx,
    548                        JS::MutableHandle<JSObject*> aReflector) override;
    549 
    550  already_AddRefed<Clients> GetClients();
    551 
    552  ServiceWorkerRegistration* Registration();
    553 
    554  already_AddRefed<Promise> SkipWaiting(ErrorResult& aRv);
    555 
    556  SafeRefPtr<extensions::ExtensionBrowser> AcquireExtensionBrowser();
    557 
    558  IMPL_EVENT_HANDLER(install)
    559  IMPL_EVENT_HANDLER(activate)
    560 
    561  EventHandlerNonNull* GetOnfetch();
    562 
    563  void SetOnfetch(EventHandlerNonNull* aCallback);
    564 
    565  void EventListenerAdded(nsAtom* aType) override;
    566 
    567  already_AddRefed<mozilla::dom::CookieStore> CookieStore();
    568 
    569  IMPL_EVENT_HANDLER(message)
    570  IMPL_EVENT_HANDLER(messageerror)
    571 
    572  IMPL_EVENT_HANDLER(notificationclick)
    573  IMPL_EVENT_HANDLER(notificationclose)
    574 
    575  IMPL_EVENT_HANDLER(push)
    576  IMPL_EVENT_HANDLER(pushsubscriptionchange)
    577 
    578  IMPL_EVENT_HANDLER(cookiechange)
    579 
    580 private:
    581  ~ServiceWorkerGlobalScope();
    582 
    583  void NoteFetchHandlerWasAdded() const;
    584 
    585  RefPtr<Clients> mClients;
    586  const nsString mScope;
    587  RefPtr<ServiceWorkerRegistration> mRegistration;
    588  SafeRefPtr<extensions::ExtensionBrowser> mExtensionBrowser;
    589  RefPtr<mozilla::dom::CookieStore> mCookieStore;
    590 };
    591 
    592 class WorkerDebuggerGlobalScope final : public WorkerGlobalScopeBase {
    593 public:
    594  using WorkerGlobalScopeBase::WorkerGlobalScopeBase;
    595 
    596  bool WrapGlobalObject(JSContext* aCx,
    597                        JS::MutableHandle<JSObject*> aReflector) override;
    598 
    599  void Control(const ServiceWorkerDescriptor& aServiceWorker) override {
    600    MOZ_CRASH("Can't control debugger workers.");
    601  }
    602 
    603  void GetGlobal(JSContext* aCx, JS::MutableHandle<JSObject*> aGlobal,
    604                 ErrorResult& aRv);
    605 
    606  void CreateSandbox(JSContext* aCx, const nsAString& aName,
    607                     JS::Handle<JSObject*> aPrototype,
    608                     JS::MutableHandle<JSObject*> aResult, ErrorResult& aRv);
    609 
    610  void LoadSubScript(JSContext* aCx, const nsAString& aUrl,
    611                     const Optional<JS::Handle<JSObject*>>& aSandbox,
    612                     ErrorResult& aRv);
    613 
    614  MOZ_CAN_RUN_SCRIPT void EnterEventLoop();
    615 
    616  void LeaveEventLoop();
    617 
    618  void PostMessage(const nsAString& aMessage);
    619 
    620  void SetImmediate(Function& aHandler, ErrorResult& aRv);
    621 
    622  void ReportError(JSContext* aCx, const nsAString& aMessage);
    623 
    624  void RetrieveConsoleEvents(JSContext* aCx, nsTArray<JS::Value>& aEvents,
    625                             ErrorResult& aRv);
    626 
    627  void ClearConsoleEvents(JSContext* aCx, ErrorResult& aRv);
    628 
    629  void SetConsoleEventHandler(JSContext* aCx, AnyCallback* aHandler,
    630                              ErrorResult& aRv);
    631 
    632  void Dump(JSContext* aCx, const Optional<nsAString>& aString) const;
    633 
    634  IMPL_EVENT_HANDLER(message)
    635  IMPL_EVENT_HANDLER(messageerror)
    636 
    637 private:
    638  ~WorkerDebuggerGlobalScope() = default;
    639 };
    640 
    641 }  // namespace dom
    642 }  // namespace mozilla
    643 
    644 inline nsISupports* ToSupports(mozilla::dom::WorkerGlobalScope* aScope) {
    645  return static_cast<mozilla::dom::EventTarget*>(aScope);
    646 }
    647 
    648 #endif /* mozilla_dom_workerscope_h__ */