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
;
43 class CredentialsContainer
;
46 class HTMLMediaElement
;
52 } // namespace mozilla
54 //*****************************************************************************
55 // Navigator: Script "navigator" object
56 //*****************************************************************************
58 namespace mozilla::dom
{
64 } // namespace battery
69 class GamepadServiceTest
;
70 class NavigatorUserMediaSuccessCallback
;
71 class NavigatorUserMediaErrorCallback
;
75 nsTArray
<uint32_t> SanitizeVibratePattern(const nsTArray
<uint32_t>& aPattern
);
79 } // namespace network
81 class LegacyMozTCPSocket
;
86 class MediaCapabilities
;
90 class WindowGlobalChild
;
92 class Navigator final
: public nsISupports
, public nsWrapperCache
{
94 explicit Navigator(nsPIDOMWindowInner
* aInnerWindow
);
96 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
97 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Navigator
)
100 nsPIDOMWindowInner
* GetWindow() const { return mWindow
; }
102 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
105 * Called when the inner window navigates to a new page.
109 void GetProduct(nsAString
& aProduct
);
110 void GetLanguage(nsAString
& aLanguage
);
111 void GetAppName(nsAString
& aAppName
) const;
112 void GetAppVersion(nsAString
& aAppName
, CallerType aCallerType
,
113 ErrorResult
& aRv
) const;
114 void GetPlatform(nsAString
& aPlatform
, CallerType aCallerType
,
115 ErrorResult
& aRv
) const;
116 void GetUserAgent(nsAString
& aUserAgent
, CallerType aCallerType
,
117 ErrorResult
& aRv
) const;
119 void CheckProtocolHandlerAllowed(const nsAString
& aScheme
,
120 nsIURI
* aHandlerURI
, nsIURI
* aDocumentURI
,
122 void RegisterProtocolHandler(const nsAString
& aScheme
, const nsAString
& aURL
,
124 nsMimeTypeArray
* GetMimeTypes(ErrorResult
& aRv
);
125 nsPluginArray
* GetPlugins(ErrorResult
& aRv
);
126 bool PdfViewerEnabled();
127 Permissions
* GetPermissions(ErrorResult
& aRv
);
128 void GetDoNotTrack(nsAString
& aResult
);
129 bool GlobalPrivacyControl();
130 Geolocation
* GetGeolocation(ErrorResult
& aRv
);
131 Promise
* GetBattery(ErrorResult
& aRv
);
133 bool CanShare(const ShareData
& aData
);
134 already_AddRefed
<Promise
> Share(const ShareData
& aData
, ErrorResult
& aRv
);
136 static nsresult
GetPlatform(nsAString
& aPlatform
, Document
* aCallerDoc
,
137 bool aUsePrefOverriddenValue
);
139 static nsresult
GetAppVersion(nsAString
& aAppVersion
, Document
* aCallerDoc
,
140 bool aUsePrefOverriddenValue
);
142 static nsresult
GetUserAgent(nsPIDOMWindowInner
* aWindow
,
143 Document
* aCallerDoc
,
144 Maybe
<bool> aShouldResistFingerprinting
,
145 nsAString
& aUserAgent
);
147 // Clears the platform cache by calling:
148 // Navigator_Binding::ClearCachedPlatformValue(this);
149 void ClearPlatformCache();
151 // Clears the user agent cache by calling:
152 // Navigator_Binding::ClearCachedUserAgentValue(this);
153 void ClearUserAgentCache();
155 bool Vibrate(uint32_t aDuration
);
156 bool Vibrate(const nsTArray
<uint32_t>& aDuration
);
157 void SetVibrationPermission(bool aPermitted
, bool aPersistent
);
158 uint32_t MaxTouchPoints(CallerType aCallerType
);
159 void GetAppCodeName(nsAString
& aAppCodeName
, ErrorResult
& aRv
);
160 void GetOscpu(nsAString
& aOscpu
, CallerType aCallerType
,
161 ErrorResult
& aRv
) const;
162 void GetVendorSub(nsAString
& aVendorSub
);
163 void GetVendor(nsAString
& aVendor
);
164 void GetProductSub(nsAString
& aProductSub
);
165 bool CookieEnabled();
166 void GetBuildID(nsAString
& aBuildID
, CallerType aCallerType
,
167 ErrorResult
& aRv
) const;
168 bool JavaEnabled() { return false; }
169 uint64_t HardwareConcurrency();
170 bool TaintEnabled() { return false; }
172 already_AddRefed
<LegacyMozTCPSocket
> MozTCPSocket();
173 network::Connection
* GetConnection(ErrorResult
& aRv
);
174 MediaDevices
* GetMediaDevices(ErrorResult
& aRv
);
175 MediaDevices
* GetExtantMediaDevices() const { return mMediaDevices
; };
177 void GetGamepads(nsTArray
<RefPtr
<Gamepad
>>& aGamepads
, ErrorResult
& aRv
);
178 GamepadServiceTest
* RequestGamepadServiceTest(ErrorResult
& aRv
);
179 already_AddRefed
<Promise
> GetVRDisplays(ErrorResult
& aRv
);
180 void FinishGetVRDisplays(bool isWebVRSupportedInwindow
, Promise
* p
);
181 void GetActiveVRDisplays(nsTArray
<RefPtr
<VRDisplay
>>& aDisplays
) const;
182 void OnXRPermissionRequestAllow();
183 void OnXRPermissionRequestCancel();
184 VRServiceTest
* RequestVRServiceTest(ErrorResult
& aRv
);
185 bool IsWebVRContentDetected() const;
186 bool IsWebVRContentPresenting() const;
187 void RequestVRPresentation(VRDisplay
& aDisplay
);
188 XRSystem
* GetXr(ErrorResult
& aRv
);
189 already_AddRefed
<Promise
> RequestMIDIAccess(const MIDIOptions
& aOptions
,
192 bool SendBeacon(const nsAString
& aUrl
, const Nullable
<fetch::BodyInit
>& aData
,
195 void MozGetUserMedia(const MediaStreamConstraints
& aConstraints
,
196 NavigatorUserMediaSuccessCallback
& aOnSuccess
,
197 NavigatorUserMediaErrorCallback
& aOnError
,
198 CallerType aCallerType
, ErrorResult
& aRv
);
200 already_AddRefed
<ServiceWorkerContainer
> ServiceWorker();
201 // NOTE(krosylight): This currently exists solely for use counter purpose,
202 // since Navigator::ServiceWorker is also called by native functions. Remove
203 // this when we don't need the counter.
204 already_AddRefed
<ServiceWorkerContainer
> ServiceWorkerJS();
206 mozilla::dom::CredentialsContainer
* Credentials();
207 dom::Clipboard
* Clipboard();
208 webgpu::Instance
* Gpu();
209 dom::LockManager
* Locks();
211 static bool Webdriver();
213 void GetLanguages(nsTArray
<nsString
>& aLanguages
);
215 StorageManager
* Storage();
217 static void GetAcceptLanguages(nsTArray
<nsString
>& aLanguages
);
219 dom::MediaCapabilities
* MediaCapabilities();
220 dom::MediaSession
* MediaSession();
222 AddonManager
* GetMozAddonManager(ErrorResult
& aRv
);
224 // WebIDL helper methods
225 static bool HasUserMediaSupport(JSContext
* /* unused */,
226 JSObject
* /* unused */);
227 static bool HasShareSupport(JSContext
* /* unused */, JSObject
* /* unused */);
229 static bool HasMidiSupport(JSContext
* /* unused */, JSObject
* /* unused */);
231 nsPIDOMWindowInner
* GetParentObject() const { return GetWindow(); }
233 virtual JSObject
* WrapObject(JSContext
* cx
,
234 JS::Handle
<JSObject
*> aGivenProto
) override
;
236 // GetWindowFromGlobal returns the inner window for this global, if
238 static already_AddRefed
<nsPIDOMWindowInner
> GetWindowFromGlobal(
241 already_AddRefed
<Promise
> RequestMediaKeySystemAccess(
242 const nsAString
& aKeySystem
,
243 const Sequence
<MediaKeySystemConfiguration
>& aConfig
, ErrorResult
& aRv
);
245 bool HasCreatedMediaSession() const;
247 // Following methods are for the Autoplay Policy Detection API.
248 // https://w3c.github.io/autoplay/#autoplay-detection-methods
249 AutoplayPolicy
GetAutoplayPolicy(AutoplayPolicyMediaType aType
);
250 AutoplayPolicy
GetAutoplayPolicy(HTMLMediaElement
& aElement
);
251 AutoplayPolicy
GetAutoplayPolicy(AudioContext
& aContext
);
253 already_AddRefed
<dom::UserActivation
> UserActivation();
256 void ValidateShareData(const ShareData
& aData
, ErrorResult
& aRv
);
257 RefPtr
<MediaKeySystemAccessManager
> mMediaKeySystemAccessManager
;
260 void NotifyVRDisplaysUpdated();
261 void NotifyActiveVRDisplaysChanged();
263 bool TestTrialGatedAttribute() const { return true; }
266 virtual ~Navigator();
268 // This enum helps SendBeaconInternal to apply different behaviors to body
270 enum BeaconType
{ eBeaconTypeBlob
, eBeaconTypeArrayBuffer
, eBeaconTypeOther
};
272 bool SendBeaconInternal(const nsAString
& aUrl
, BodyExtractorBase
* aBody
,
273 BeaconType aType
, ErrorResult
& aRv
);
275 nsIDocShell
* GetDocShell() const {
276 return mWindow
? mWindow
->GetDocShell() : nullptr;
279 RefPtr
<nsPluginArray
> mPlugins
;
280 RefPtr
<Permissions
> mPermissions
;
281 RefPtr
<Geolocation
> mGeolocation
;
282 RefPtr
<battery::BatteryManager
> mBatteryManager
;
283 RefPtr
<Promise
> mBatteryPromise
;
284 RefPtr
<network::Connection
> mConnection
;
285 RefPtr
<CredentialsContainer
> mCredentials
;
286 RefPtr
<dom::Clipboard
> mClipboard
;
287 RefPtr
<MediaDevices
> mMediaDevices
;
288 RefPtr
<ServiceWorkerContainer
> mServiceWorkerContainer
;
289 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
290 RefPtr
<GamepadServiceTest
> mGamepadServiceTest
;
291 nsTArray
<RefPtr
<Promise
>> mVRGetDisplaysPromises
;
292 RefPtr
<VRServiceTest
> mVRServiceTest
;
293 RefPtr
<XRSystem
> mXRSystem
;
294 nsTArray
<uint32_t> mRequestedVibrationPattern
;
295 RefPtr
<StorageManager
> mStorageManager
;
296 RefPtr
<dom::MediaCapabilities
> mMediaCapabilities
;
297 RefPtr
<dom::MediaSession
> mMediaSession
;
298 RefPtr
<AddonManager
> mAddonManager
;
299 RefPtr
<webgpu::Instance
> mWebGpu
;
300 RefPtr
<Promise
> mSharePromise
; // Web Share API related
301 RefPtr
<dom::LockManager
> mLocks
;
302 RefPtr
<dom::UserActivation
> mUserActivation
;
305 } // namespace mozilla::dom
307 #endif // mozilla_dom_Navigator_h