tor-browser

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

Navigator.h (11681B)


      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_Navigator_h
      8 #define mozilla_dom_Navigator_h
      9 
     10 #include "mozilla/MemoryReporting.h"
     11 #include "mozilla/dom/AddonManagerBinding.h"
     12 #include "mozilla/dom/BindingDeclarations.h"
     13 #include "mozilla/dom/Fetch.h"
     14 #include "mozilla/dom/MediaKeySystemAccessManager.h"
     15 #include "mozilla/dom/NavigatorBinding.h"
     16 #include "mozilla/dom/Nullable.h"
     17 #include "nsHashKeys.h"
     18 #include "nsInterfaceHashtable.h"
     19 #include "nsString.h"
     20 #include "nsTArray.h"
     21 #include "nsWrapperCache.h"
     22 
     23 class nsPluginArray;
     24 class nsMimeTypeArray;
     25 class nsPIDOMWindowInner;
     26 class nsIDOMNavigatorSystemMessages;
     27 class nsIPrincipal;
     28 class nsIURI;
     29 
     30 namespace mozilla {
     31 class ErrorResult;
     32 
     33 namespace dom {
     34 class AddonManager;
     35 class BodyExtractorBase;
     36 class Geolocation;
     37 class systemMessageCallback;
     38 class MediaDevices;
     39 struct MediaStreamConstraints;
     40 class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
     41 class ServiceWorkerContainer;
     42 class CredentialsContainer;
     43 class Clipboard;
     44 class LockManager;
     45 class NavigatorLogin;
     46 class PrivateAttribution;
     47 class HTMLMediaElement;
     48 class AudioContext;
     49 class WakeLockJS;
     50 }  // namespace dom
     51 namespace webgpu {
     52 class Instance;
     53 }  // namespace webgpu
     54 }  // namespace mozilla
     55 
     56 //*****************************************************************************
     57 // Navigator: Script "navigator" object
     58 //*****************************************************************************
     59 
     60 namespace mozilla::dom {
     61 
     62 class Permissions;
     63 
     64 namespace battery {
     65 class BatteryManager;
     66 }  // namespace battery
     67 
     68 class Promise;
     69 
     70 class Gamepad;
     71 class GamepadServiceTest;
     72 class NavigatorUserMediaSuccessCallback;
     73 class NavigatorUserMediaErrorCallback;
     74 
     75 struct MIDIOptions;
     76 
     77 nsTArray<uint32_t> SanitizeVibratePattern(const nsTArray<uint32_t>& aPattern);
     78 
     79 namespace network {
     80 class Connection;
     81 }  // namespace network
     82 
     83 class LegacyMozTCPSocket;
     84 class VRDisplay;
     85 class VRServiceTest;
     86 class XRSystem;
     87 class StorageManager;
     88 class MediaCapabilities;
     89 class MediaSession;
     90 class UserActivation;
     91 struct ShareData;
     92 class WindowGlobalChild;
     93 
     94 class Navigator final : public nsISupports, public nsWrapperCache {
     95 public:
     96  explicit Navigator(nsPIDOMWindowInner* aInnerWindow);
     97 
     98  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     99  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Navigator)
    100 
    101  void Invalidate();
    102  nsPIDOMWindowInner* GetWindow() const { return mWindow; }
    103 
    104  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    105 
    106  /**
    107   * Called when the inner window navigates to a new page.
    108   */
    109  void OnNavigation();
    110 
    111  void GetProduct(nsAString& aProduct);
    112  void GetLanguage(nsAString& aLanguage);
    113  void GetAppName(nsAString& aAppName) const;
    114  void GetAppVersion(nsAString& aAppName, CallerType aCallerType,
    115                     ErrorResult& aRv) const;
    116  void GetPlatform(nsAString& aPlatform, CallerType aCallerType,
    117                   ErrorResult& aRv) const;
    118  void GetUserAgent(nsAString& aUserAgent, CallerType aCallerType,
    119                    ErrorResult& aRv) const;
    120  bool OnLine();
    121  void CheckProtocolHandlerAllowed(const nsAString& aScheme,
    122                                   nsIURI* aHandlerURI, nsIURI* aDocumentURI,
    123                                   ErrorResult& aRv);
    124  void RegisterProtocolHandler(const nsAString& aScheme, const nsAString& aURL,
    125                               ErrorResult& aRv);
    126  nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv);
    127  nsPluginArray* GetPlugins(ErrorResult& aRv);
    128  bool PdfViewerEnabled();
    129  Permissions* GetPermissions(ErrorResult& aRv);
    130  void GetDoNotTrack(nsAString& aResult);
    131  bool GlobalPrivacyControl();
    132  Geolocation* GetGeolocation(ErrorResult& aRv);
    133  Promise* GetBattery(ErrorResult& aRv);
    134  dom::WakeLockJS* WakeLock();
    135 
    136  bool CanShare(const ShareData& aData);
    137  already_AddRefed<Promise> Share(const ShareData& aData, ErrorResult& aRv);
    138 
    139  static nsresult GetPlatform(nsAString& aPlatform, Document* aCallerDoc,
    140                              bool aUsePrefOverriddenValue);
    141 
    142  static nsresult GetAppVersion(nsAString& aAppVersion, Document* aCallerDoc,
    143                                bool aUsePrefOverriddenValue);
    144 
    145  static nsresult GetUserAgent(nsPIDOMWindowInner* aWindow,
    146                               Document* aCallerDoc,
    147                               Maybe<bool> aShouldResistFingerprinting,
    148                               nsAString& aUserAgent);
    149 
    150  // Clears the language cache by calling:
    151  // Navigator_Binding::ClearCachedLanguageValue(this); and
    152  // Navigator_Binding::ClearCachedLanguagesValue(this);
    153  void ClearLanguageCache();
    154 
    155  // Clears the platform cache by calling:
    156  // Navigator_Binding::ClearCachedPlatformValue(this);
    157  void ClearPlatformCache();
    158 
    159  // Clears the user agent cache by calling:
    160  // Navigator_Binding::ClearCachedUserAgentValue(this);
    161  void ClearUserAgentCache();
    162 
    163  bool Vibrate(uint32_t aDuration);
    164  bool Vibrate(const nsTArray<uint32_t>& aDuration);
    165  void SetVibrationPermission(bool aPermitted, bool aPersistent);
    166  uint32_t MaxTouchPoints(CallerType aCallerType);
    167  void GetAppCodeName(nsAString& aAppCodeName, ErrorResult& aRv);
    168  void GetOscpu(nsAString& aOscpu, CallerType aCallerType,
    169                ErrorResult& aRv) const;
    170  void GetVendorSub(nsAString& aVendorSub);
    171  void GetVendor(nsAString& aVendor);
    172  void GetProductSub(nsAString& aProductSub);
    173  bool CookieEnabled();
    174  void GetBuildID(nsAString& aBuildID, CallerType aCallerType,
    175                  ErrorResult& aRv) const;
    176  bool JavaEnabled() { return false; }
    177  uint64_t HardwareConcurrency();
    178  bool TaintEnabled() { return false; }
    179 
    180  already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
    181  network::Connection* GetConnection(ErrorResult& aRv);
    182  MediaDevices* GetMediaDevices(ErrorResult& aRv);
    183  MediaDevices* GetExtantMediaDevices() const { return mMediaDevices; };
    184 
    185  void GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads, ErrorResult& aRv);
    186  GamepadServiceTest* RequestGamepadServiceTest(ErrorResult& aRv);
    187  already_AddRefed<Promise> RequestAllGamepads(ErrorResult& aRv);
    188  already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
    189  void FinishGetVRDisplays(bool isWebVRSupportedInwindow, Promise* p);
    190  void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
    191  void OnXRPermissionRequestAllow();
    192  void OnXRPermissionRequestCancel();
    193  VRServiceTest* RequestVRServiceTest(ErrorResult& aRv);
    194  bool IsWebVRContentDetected() const;
    195  bool IsWebVRContentPresenting() const;
    196  void RequestVRPresentation(VRDisplay& aDisplay);
    197  XRSystem* GetXr(ErrorResult& aRv);
    198  already_AddRefed<Promise> RequestMIDIAccess(const MIDIOptions& aOptions,
    199                                              ErrorResult& aRv);
    200 
    201  bool SendBeacon(const nsAString& aUrl, const Nullable<fetch::BodyInit>& aData,
    202                  ErrorResult& aRv);
    203 
    204  void MozGetUserMedia(const MediaStreamConstraints& aConstraints,
    205                       NavigatorUserMediaSuccessCallback& aOnSuccess,
    206                       NavigatorUserMediaErrorCallback& aOnError,
    207                       CallerType aCallerType, ErrorResult& aRv);
    208 
    209  already_AddRefed<ServiceWorkerContainer> ServiceWorker();
    210  // NOTE(krosylight): This currently exists solely for use counter purpose,
    211  // since Navigator::ServiceWorker is also called by native functions. Remove
    212  // this when we don't need the counter.
    213  already_AddRefed<ServiceWorkerContainer> ServiceWorkerJS();
    214 
    215  mozilla::dom::CredentialsContainer* Credentials();
    216  dom::Clipboard* Clipboard();
    217  webgpu::Instance* Gpu();
    218  dom::LockManager* Locks();
    219  NavigatorLogin* Login();
    220  dom::PrivateAttribution* PrivateAttribution();
    221 
    222  static bool Webdriver();
    223 
    224  void GetLanguages(nsTArray<nsString>& aLanguages);
    225 
    226  StorageManager* Storage();
    227 
    228  static void GetAcceptLanguages(nsTArray<nsString>& aLanguages,
    229                                 const nsCString* aLanguageOverride);
    230 
    231  dom::MediaCapabilities* MediaCapabilities();
    232  dom::MediaSession* MediaSession();
    233 
    234  AddonManager* GetMozAddonManager(ErrorResult& aRv);
    235 
    236  // WebIDL helper methods
    237  static bool HasUserMediaSupport(JSContext* /* unused */,
    238                                  JSObject* /* unused */);
    239  static bool MozGetUserMediaSupport(JSContext* /* unused */,
    240                                     JSObject* /* unused */);
    241  static bool HasShareSupport(JSContext* /* unused */, JSObject* /* unused */);
    242 
    243  static bool HasMidiSupport(JSContext* /* unused */, JSObject* /* unused */);
    244 
    245  nsPIDOMWindowInner* GetParentObject() const { return GetWindow(); }
    246 
    247  virtual JSObject* WrapObject(JSContext* cx,
    248                               JS::Handle<JSObject*> aGivenProto) override;
    249 
    250  // GetWindowFromGlobal returns the inner window for this global, if
    251  // any, else null.
    252  static already_AddRefed<nsPIDOMWindowInner> GetWindowFromGlobal(
    253      JSObject* aGlobal);
    254 
    255  already_AddRefed<Promise> RequestMediaKeySystemAccess(
    256      const nsAString& aKeySystem,
    257      const Sequence<MediaKeySystemConfiguration>& aConfig, ErrorResult& aRv);
    258 
    259  bool HasCreatedMediaSession() const;
    260 
    261  // Following methods are for the Autoplay Policy Detection API.
    262  // https://w3c.github.io/autoplay/#autoplay-detection-methods
    263  AutoplayPolicy GetAutoplayPolicy(AutoplayPolicyMediaType aType);
    264  AutoplayPolicy GetAutoplayPolicy(HTMLMediaElement& aElement);
    265  AutoplayPolicy GetAutoplayPolicy(AudioContext& aContext);
    266 
    267  already_AddRefed<dom::UserActivation> UserActivation();
    268 
    269  MediaKeySystemAccessManager* GetOrCreateMediaKeySystemAccessManager();
    270 
    271 private:
    272  void ValidateShareData(const ShareData& aData, ErrorResult& aRv);
    273  RefPtr<MediaKeySystemAccessManager> mMediaKeySystemAccessManager;
    274 
    275 public:
    276  void NotifyVRDisplaysUpdated();
    277  void NotifyActiveVRDisplaysChanged();
    278 
    279  bool TestTrialGatedAttribute() const { return true; }
    280 
    281 private:
    282  virtual ~Navigator();
    283 
    284  // This enum helps SendBeaconInternal to apply different behaviors to body
    285  // types.
    286  enum BeaconType { eBeaconTypeBlob, eBeaconTypeArrayBuffer, eBeaconTypeOther };
    287 
    288  bool SendBeaconInternal(const nsAString& aUrl, BodyExtractorBase* aBody,
    289                          BeaconType aType, ErrorResult& aRv);
    290 
    291  nsIDocShell* GetDocShell() const {
    292    return mWindow ? mWindow->GetDocShell() : nullptr;
    293  }
    294 
    295  RefPtr<nsPluginArray> mPlugins;
    296  RefPtr<Permissions> mPermissions;
    297  RefPtr<Geolocation> mGeolocation;
    298  RefPtr<battery::BatteryManager> mBatteryManager;
    299  RefPtr<Promise> mBatteryPromise;
    300  RefPtr<network::Connection> mConnection;
    301  RefPtr<CredentialsContainer> mCredentials;
    302  RefPtr<dom::Clipboard> mClipboard;
    303  RefPtr<MediaDevices> mMediaDevices;
    304  RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
    305  nsCOMPtr<nsPIDOMWindowInner> mWindow;
    306  RefPtr<GamepadServiceTest> mGamepadServiceTest;
    307  nsTArray<RefPtr<Promise>> mVRGetDisplaysPromises;
    308  RefPtr<VRServiceTest> mVRServiceTest;
    309  RefPtr<XRSystem> mXRSystem;
    310  nsTArray<uint32_t> mRequestedVibrationPattern;
    311  RefPtr<StorageManager> mStorageManager;
    312  RefPtr<dom::MediaCapabilities> mMediaCapabilities;
    313  RefPtr<dom::MediaSession> mMediaSession;
    314  RefPtr<AddonManager> mAddonManager;
    315  RefPtr<webgpu::Instance> mWebGpu;
    316  RefPtr<Promise> mSharePromise;  // Web Share API related
    317  RefPtr<LockManager> mLocks;
    318  RefPtr<NavigatorLogin> mLogin;
    319  RefPtr<dom::PrivateAttribution> mPrivateAttribution;
    320  RefPtr<dom::UserActivation> mUserActivation;
    321  RefPtr<dom::WakeLockJS> mWakeLock;
    322 };
    323 
    324 }  // namespace mozilla::dom
    325 
    326 #endif  // mozilla_dom_Navigator_h