tor-browser

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

WorkerNavigator.h (3751B)


      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_workernavigator_h__
      8 #define mozilla_dom_workernavigator_h__
      9 
     10 #include <stdint.h>
     11 
     12 #include "js/RootingAPI.h"
     13 #include "mozilla/AlreadyAddRefed.h"
     14 #include "mozilla/Assertions.h"
     15 #include "mozilla/RefPtr.h"
     16 #include "mozilla/StaticPrefs_privacy.h"
     17 #include "mozilla/dom/BindingDeclarations.h"
     18 #include "mozilla/dom/workerinternals/RuntimeService.h"
     19 #include "nsCycleCollectionParticipant.h"
     20 #include "nsISupports.h"
     21 #include "nsStringFwd.h"
     22 #include "nsTArray.h"
     23 #include "nsWrapperCache.h"
     24 
     25 namespace mozilla {
     26 class ErrorResult;
     27 
     28 namespace webgpu {
     29 class Instance;
     30 }  // namespace webgpu
     31 namespace dom {
     32 class StorageManager;
     33 class MediaCapabilities;
     34 class LockManager;
     35 class Permissions;
     36 class ServiceWorkerContainer;
     37 
     38 namespace network {
     39 class Connection;
     40 }  // namespace network
     41 
     42 class WorkerNavigator final : public nsWrapperCache {
     43  using NavigatorProperties =
     44      workerinternals::RuntimeService::NavigatorProperties;
     45 
     46  NavigatorProperties mProperties;
     47  RefPtr<StorageManager> mStorageManager;
     48  RefPtr<network::Connection> mConnection;
     49  RefPtr<dom::MediaCapabilities> mMediaCapabilities;
     50  RefPtr<webgpu::Instance> mWebGpu;
     51  RefPtr<dom::LockManager> mLocks;
     52  RefPtr<dom::Permissions> mPermissions;
     53  RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
     54  bool mOnline;
     55 
     56  WorkerNavigator(const NavigatorProperties& aProperties, bool aOnline);
     57  ~WorkerNavigator();
     58 
     59 public:
     60  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerNavigator)
     61  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(WorkerNavigator)
     62 
     63  static already_AddRefed<WorkerNavigator> Create(bool aOnLine);
     64 
     65  void Invalidate();
     66 
     67  virtual JSObject* WrapObject(JSContext* aCx,
     68                               JS::Handle<JSObject*> aGivenProto) override;
     69 
     70  nsISupports* GetParentObject() const { return nullptr; }
     71 
     72  void GetAppCodeName(nsString& aAppCodeName, ErrorResult& /* unused */) const {
     73    aAppCodeName.AssignLiteral("Mozilla");
     74  }
     75  void GetAppName(nsString& aAppName) const {
     76    aAppName.AssignLiteral("Netscape");
     77  }
     78 
     79  void GetAppVersion(nsString& aAppVersion, CallerType aCallerType,
     80                     ErrorResult& aRv) const;
     81 
     82  void GetPlatform(nsString& aPlatform, CallerType aCallerType,
     83                   ErrorResult& aRv) const;
     84 
     85  void GetProduct(nsString& aProduct) const { aProduct.AssignLiteral("Gecko"); }
     86 
     87  bool TaintEnabled() const { return false; }
     88 
     89  void GetLanguage(nsString& aLanguage) const {
     90    MOZ_ASSERT(mProperties.mLanguages.Length() >= 1);
     91    aLanguage.Assign(mProperties.mLanguages[0]);
     92  }
     93 
     94  void GetLanguages(nsTArray<nsString>& aLanguages) const {
     95    aLanguages = mProperties.mLanguages.Clone();
     96  }
     97 
     98  void GetUserAgent(nsString& aUserAgent, CallerType aCallerType,
     99                    ErrorResult& aRv) const;
    100 
    101  bool OnLine() const { return mOnline; }
    102 
    103  // Worker thread only!
    104  void SetOnLine(bool aOnline) { mOnline = aOnline; }
    105 
    106  bool GlobalPrivacyControl() const;
    107 
    108  void SetLanguages(const nsTArray<nsString>& aLanguages);
    109 
    110  uint64_t HardwareConcurrency() const;
    111 
    112  StorageManager* Storage();
    113 
    114  network::Connection* GetConnection(ErrorResult& aRv);
    115 
    116  dom::MediaCapabilities* MediaCapabilities();
    117 
    118  webgpu::Instance* Gpu();
    119 
    120  dom::LockManager* Locks();
    121 
    122  dom::Permissions* Permissions();
    123 
    124  already_AddRefed<ServiceWorkerContainer> ServiceWorker();
    125 };
    126 
    127 }  // namespace dom
    128 }  // namespace mozilla
    129 
    130 #endif  // mozilla_dom_workernavigator_h__