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/. */
7 #ifndef mozilla_dom_Navigator_h
8 #define mozilla_dom_Navigator_h
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/NavigatorBinding.h"
15 #include "mozilla/dom/Nullable.h"
16 #include "nsWrapperCache.h"
17 #include "nsHashKeys.h"
18 #include "nsInterfaceHashtable.h"
21 #include "mozilla/dom/MediaKeySystemAccessManager.h"
24 class nsMimeTypeArray
;
25 class nsPIDOMWindowInner
;
26 class nsIDOMNavigatorSystemMessages
;
35 class BodyExtractorBase
;
37 class systemMessageCallback
;
39 struct MediaStreamConstraints
;
40 class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams
;
41 class ServiceWorkerContainer
;
42 class CredentialsContainer
;
45 class PrivateAttribution
;
46 class HTMLMediaElement
;
53 } // namespace mozilla
55 //*****************************************************************************
56 // Navigator: Script "navigator" object
57 //*****************************************************************************
59 namespace mozilla::dom
{
65 } // namespace battery
70 class GamepadServiceTest
;
71 class NavigatorUserMediaSuccessCallback
;
72 class NavigatorUserMediaErrorCallback
;
76 nsTArray
<uint32_t> SanitizeVibratePattern(const nsTArray
<uint32_t>& aPattern
);
80 } // namespace network
82 class LegacyMozTCPSocket
;
87 class MediaCapabilities
;
91 class WindowGlobalChild
;
93 class Navigator final
: public nsISupports
, public nsWrapperCache
{
95 explicit Navigator(nsPIDOMWindowInner
* aInnerWindow
);
97 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
98 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Navigator
)
101 nsPIDOMWindowInner
* GetWindow() const { return mWindow
; }
103 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
106 * Called when the inner window navigates to a new page.
110 void GetProduct(nsAString
& aProduct
);
111 void GetLanguage(nsAString
& aLanguage
);
112 void GetAppName(nsAString
& aAppName
) const;
113 void GetAppVersion(nsAString
& aAppName
, CallerType aCallerType
,
114 ErrorResult
& aRv
) const;
115 void GetPlatform(nsAString
& aPlatform
, CallerType aCallerType
,
116 ErrorResult
& aRv
) const;
117 void GetUserAgent(nsAString
& aUserAgent
, CallerType aCallerType
,
118 ErrorResult
& aRv
) const;
120 void CheckProtocolHandlerAllowed(const nsAString
& aScheme
,
121 nsIURI
* aHandlerURI
, nsIURI
* aDocumentURI
,
123 void RegisterProtocolHandler(const nsAString
& aScheme
, const nsAString
& aURL
,
125 nsMimeTypeArray
* GetMimeTypes(ErrorResult
& aRv
);
126 nsPluginArray
* GetPlugins(ErrorResult
& aRv
);
127 bool PdfViewerEnabled();
128 Permissions
* GetPermissions(ErrorResult
& aRv
);
129 void GetDoNotTrack(nsAString
& aResult
);
130 bool GlobalPrivacyControl();
131 Geolocation
* GetGeolocation(ErrorResult
& aRv
);
132 Promise
* GetBattery(ErrorResult
& aRv
);
133 dom::WakeLockJS
* WakeLock();
135 bool CanShare(const ShareData
& aData
);
136 already_AddRefed
<Promise
> Share(const ShareData
& aData
, ErrorResult
& aRv
);
138 static nsresult
GetPlatform(nsAString
& aPlatform
, Document
* aCallerDoc
,
139 bool aUsePrefOverriddenValue
);
141 static nsresult
GetAppVersion(nsAString
& aAppVersion
, Document
* aCallerDoc
,
142 bool aUsePrefOverriddenValue
);
144 static nsresult
GetUserAgent(nsPIDOMWindowInner
* aWindow
,
145 Document
* aCallerDoc
,
146 Maybe
<bool> aShouldResistFingerprinting
,
147 nsAString
& aUserAgent
);
149 // Clears the platform cache by calling:
150 // Navigator_Binding::ClearCachedPlatformValue(this);
151 void ClearPlatformCache();
153 // Clears the user agent cache by calling:
154 // Navigator_Binding::ClearCachedUserAgentValue(this);
155 void ClearUserAgentCache();
157 bool Vibrate(uint32_t aDuration
);
158 bool Vibrate(const nsTArray
<uint32_t>& aDuration
);
159 void SetVibrationPermission(bool aPermitted
, bool aPersistent
);
160 uint32_t MaxTouchPoints(CallerType aCallerType
);
161 void GetAppCodeName(nsAString
& aAppCodeName
, ErrorResult
& aRv
);
162 void GetOscpu(nsAString
& aOscpu
, CallerType aCallerType
,
163 ErrorResult
& aRv
) const;
164 void GetVendorSub(nsAString
& aVendorSub
);
165 void GetVendor(nsAString
& aVendor
);
166 void GetProductSub(nsAString
& aProductSub
);
167 bool CookieEnabled();
168 void GetBuildID(nsAString
& aBuildID
, CallerType aCallerType
,
169 ErrorResult
& aRv
) const;
170 bool JavaEnabled() { return false; }
171 uint64_t HardwareConcurrency();
172 bool TaintEnabled() { return false; }
174 already_AddRefed
<LegacyMozTCPSocket
> MozTCPSocket();
175 network::Connection
* GetConnection(ErrorResult
& aRv
);
176 MediaDevices
* GetMediaDevices(ErrorResult
& aRv
);
177 MediaDevices
* GetExtantMediaDevices() const { return mMediaDevices
; };
179 void GetGamepads(nsTArray
<RefPtr
<Gamepad
>>& aGamepads
, ErrorResult
& aRv
);
180 GamepadServiceTest
* RequestGamepadServiceTest(ErrorResult
& aRv
);
181 already_AddRefed
<Promise
> RequestAllGamepads(ErrorResult
& aRv
);
182 already_AddRefed
<Promise
> GetVRDisplays(ErrorResult
& aRv
);
183 void FinishGetVRDisplays(bool isWebVRSupportedInwindow
, Promise
* p
);
184 void GetActiveVRDisplays(nsTArray
<RefPtr
<VRDisplay
>>& aDisplays
) const;
185 void OnXRPermissionRequestAllow();
186 void OnXRPermissionRequestCancel();
187 VRServiceTest
* RequestVRServiceTest(ErrorResult
& aRv
);
188 bool IsWebVRContentDetected() const;
189 bool IsWebVRContentPresenting() const;
190 void RequestVRPresentation(VRDisplay
& aDisplay
);
191 XRSystem
* GetXr(ErrorResult
& aRv
);
192 already_AddRefed
<Promise
> RequestMIDIAccess(const MIDIOptions
& aOptions
,
195 bool SendBeacon(const nsAString
& aUrl
, const Nullable
<fetch::BodyInit
>& aData
,
198 void MozGetUserMedia(const MediaStreamConstraints
& aConstraints
,
199 NavigatorUserMediaSuccessCallback
& aOnSuccess
,
200 NavigatorUserMediaErrorCallback
& aOnError
,
201 CallerType aCallerType
, ErrorResult
& aRv
);
203 already_AddRefed
<ServiceWorkerContainer
> ServiceWorker();
204 // NOTE(krosylight): This currently exists solely for use counter purpose,
205 // since Navigator::ServiceWorker is also called by native functions. Remove
206 // this when we don't need the counter.
207 already_AddRefed
<ServiceWorkerContainer
> ServiceWorkerJS();
209 mozilla::dom::CredentialsContainer
* Credentials();
210 dom::Clipboard
* Clipboard();
211 webgpu::Instance
* Gpu();
212 dom::LockManager
* Locks();
213 dom::PrivateAttribution
* PrivateAttribution();
215 static bool Webdriver();
217 void GetLanguages(nsTArray
<nsString
>& aLanguages
);
219 StorageManager
* Storage();
221 static void GetAcceptLanguages(nsTArray
<nsString
>& aLanguages
);
223 dom::MediaCapabilities
* MediaCapabilities();
224 dom::MediaSession
* MediaSession();
226 AddonManager
* GetMozAddonManager(ErrorResult
& aRv
);
228 // WebIDL helper methods
229 static bool HasUserMediaSupport(JSContext
* /* unused */,
230 JSObject
* /* unused */);
231 static bool HasShareSupport(JSContext
* /* unused */, JSObject
* /* unused */);
233 static bool HasMidiSupport(JSContext
* /* unused */, JSObject
* /* unused */);
235 nsPIDOMWindowInner
* GetParentObject() const { return GetWindow(); }
237 virtual JSObject
* WrapObject(JSContext
* cx
,
238 JS::Handle
<JSObject
*> aGivenProto
) override
;
240 // GetWindowFromGlobal returns the inner window for this global, if
242 static already_AddRefed
<nsPIDOMWindowInner
> GetWindowFromGlobal(
245 already_AddRefed
<Promise
> RequestMediaKeySystemAccess(
246 const nsAString
& aKeySystem
,
247 const Sequence
<MediaKeySystemConfiguration
>& aConfig
, ErrorResult
& aRv
);
249 bool HasCreatedMediaSession() const;
251 // Following methods are for the Autoplay Policy Detection API.
252 // https://w3c.github.io/autoplay/#autoplay-detection-methods
253 AutoplayPolicy
GetAutoplayPolicy(AutoplayPolicyMediaType aType
);
254 AutoplayPolicy
GetAutoplayPolicy(HTMLMediaElement
& aElement
);
255 AutoplayPolicy
GetAutoplayPolicy(AudioContext
& aContext
);
257 already_AddRefed
<dom::UserActivation
> UserActivation();
259 MediaKeySystemAccessManager
* GetOrCreateMediaKeySystemAccessManager();
262 void ValidateShareData(const ShareData
& aData
, ErrorResult
& aRv
);
263 RefPtr
<MediaKeySystemAccessManager
> mMediaKeySystemAccessManager
;
266 void NotifyVRDisplaysUpdated();
267 void NotifyActiveVRDisplaysChanged();
269 bool TestTrialGatedAttribute() const { return true; }
272 virtual ~Navigator();
274 // This enum helps SendBeaconInternal to apply different behaviors to body
276 enum BeaconType
{ eBeaconTypeBlob
, eBeaconTypeArrayBuffer
, eBeaconTypeOther
};
278 bool SendBeaconInternal(const nsAString
& aUrl
, BodyExtractorBase
* aBody
,
279 BeaconType aType
, ErrorResult
& aRv
);
281 nsIDocShell
* GetDocShell() const {
282 return mWindow
? mWindow
->GetDocShell() : nullptr;
285 RefPtr
<nsPluginArray
> mPlugins
;
286 RefPtr
<Permissions
> mPermissions
;
287 RefPtr
<Geolocation
> mGeolocation
;
288 RefPtr
<battery::BatteryManager
> mBatteryManager
;
289 RefPtr
<Promise
> mBatteryPromise
;
290 RefPtr
<network::Connection
> mConnection
;
291 RefPtr
<CredentialsContainer
> mCredentials
;
292 RefPtr
<dom::Clipboard
> mClipboard
;
293 RefPtr
<MediaDevices
> mMediaDevices
;
294 RefPtr
<ServiceWorkerContainer
> mServiceWorkerContainer
;
295 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
296 RefPtr
<GamepadServiceTest
> mGamepadServiceTest
;
297 nsTArray
<RefPtr
<Promise
>> mVRGetDisplaysPromises
;
298 RefPtr
<VRServiceTest
> mVRServiceTest
;
299 RefPtr
<XRSystem
> mXRSystem
;
300 nsTArray
<uint32_t> mRequestedVibrationPattern
;
301 RefPtr
<StorageManager
> mStorageManager
;
302 RefPtr
<dom::MediaCapabilities
> mMediaCapabilities
;
303 RefPtr
<dom::MediaSession
> mMediaSession
;
304 RefPtr
<AddonManager
> mAddonManager
;
305 RefPtr
<webgpu::Instance
> mWebGpu
;
306 RefPtr
<Promise
> mSharePromise
; // Web Share API related
307 RefPtr
<LockManager
> mLocks
;
308 RefPtr
<dom::PrivateAttribution
> mPrivateAttribution
;
309 RefPtr
<dom::UserActivation
> mUserActivation
;
310 RefPtr
<dom::WakeLockJS
> mWakeLock
;
313 } // namespace mozilla::dom
315 #endif // mozilla_dom_Navigator_h