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/Nullable.h"
15 #include "nsWrapperCache.h"
16 #include "nsHashKeys.h"
17 #include "nsInterfaceHashtable.h"
20 #include "mozilla/dom/MediaKeySystemAccessManager.h"
23 class nsMimeTypeArray
;
24 class nsPIDOMWindowInner
;
25 class nsIDOMNavigatorSystemMessages
;
34 class BodyExtractorBase
;
36 class systemMessageCallback
;
38 struct MediaStreamConstraints
;
40 class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams
;
41 class ServiceWorkerContainer
;
43 class CredentialsContainer
;
50 } // namespace mozilla
52 //*****************************************************************************
53 // Navigator: Script "navigator" object
54 //*****************************************************************************
56 namespace mozilla::dom
{
62 } // namespace battery
67 class GamepadServiceTest
;
68 class NavigatorUserMediaSuccessCallback
;
69 class NavigatorUserMediaErrorCallback
;
73 nsTArray
<uint32_t> SanitizeVibratePattern(const nsTArray
<uint32_t>& aPattern
);
77 } // namespace network
79 class LegacyMozTCPSocket
;
84 class MediaCapabilities
;
87 class WindowGlobalChild
;
89 class Navigator final
: public nsISupports
, public nsWrapperCache
{
91 explicit Navigator(nsPIDOMWindowInner
* aInnerWindow
);
93 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
94 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Navigator
)
97 nsPIDOMWindowInner
* GetWindow() const { return mWindow
; }
99 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
102 * For use during document.write where our inner window changes.
104 void SetWindow(nsPIDOMWindowInner
* aInnerWindow
);
107 * Called when the inner window navigates to a new page.
111 void GetProduct(nsAString
& aProduct
);
112 void GetLanguage(nsAString
& aLanguage
);
113 void GetAppName(nsAString
& aAppName
, CallerType aCallerType
) 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;
121 void CheckProtocolHandlerAllowed(const nsAString
& aScheme
,
122 nsIURI
* aHandlerURI
, nsIURI
* aDocumentURI
,
124 void RegisterProtocolHandler(const nsAString
& aScheme
, const nsAString
& aURL
,
126 nsMimeTypeArray
* GetMimeTypes(ErrorResult
& aRv
);
127 nsPluginArray
* GetPlugins(ErrorResult
& aRv
);
128 Permissions
* GetPermissions(ErrorResult
& aRv
);
129 void GetDoNotTrack(nsAString
& aResult
);
130 bool GlobalPrivacyControl();
131 Geolocation
* GetGeolocation(ErrorResult
& aRv
);
132 Promise
* GetBattery(ErrorResult
& aRv
);
134 bool CanShare(const ShareData
& aData
);
135 Promise
* Share(const ShareData
& aData
, ErrorResult
& aRv
);
137 static void AppName(nsAString
& aAppName
, nsIPrincipal
* aCallerPrincipal
,
138 bool aUsePrefOverriddenValue
);
140 static nsresult
GetPlatform(nsAString
& aPlatform
,
141 nsIPrincipal
* aCallerPrincipal
,
142 bool aUsePrefOverriddenValue
);
144 static nsresult
GetAppVersion(nsAString
& aAppVersion
,
145 nsIPrincipal
* aCallerPrincipal
,
146 bool aUsePrefOverriddenValue
);
148 static nsresult
GetUserAgent(nsPIDOMWindowInner
* aWindow
,
149 nsIPrincipal
* aCallerPrincipal
,
150 bool aIsCallerChrome
, nsAString
& aUserAgent
);
152 // Clears the platform cache by calling:
153 // Navigator_Binding::ClearCachedPlatformValue(this);
154 void ClearPlatformCache();
156 // Clears the user agent cache by calling:
157 // Navigator_Binding::ClearCachedUserAgentValue(this);
158 void ClearUserAgentCache();
160 bool Vibrate(uint32_t aDuration
);
161 bool Vibrate(const nsTArray
<uint32_t>& aDuration
);
162 void SetVibrationPermission(bool aPermitted
, bool aPersistent
);
163 uint32_t MaxTouchPoints(CallerType aCallerType
);
164 void GetAppCodeName(nsAString
& aAppCodeName
, ErrorResult
& aRv
);
165 void GetOscpu(nsAString
& aOscpu
, CallerType aCallerType
,
166 ErrorResult
& aRv
) const;
167 void GetVendorSub(nsAString
& aVendorSub
);
168 void GetVendor(nsAString
& aVendor
);
169 void GetProductSub(nsAString
& aProductSub
);
170 bool CookieEnabled();
171 void GetBuildID(nsAString
& aBuildID
, CallerType aCallerType
,
172 ErrorResult
& aRv
) const;
173 bool JavaEnabled() { return false; }
174 uint64_t HardwareConcurrency();
175 bool TaintEnabled() { return false; }
177 already_AddRefed
<LegacyMozTCPSocket
> MozTCPSocket();
178 network::Connection
* GetConnection(ErrorResult
& aRv
);
179 MediaDevices
* GetMediaDevices(ErrorResult
& aRv
);
180 MediaDevices
* GetExtantMediaDevices() const { return mMediaDevices
; };
182 void GetGamepads(nsTArray
<RefPtr
<Gamepad
>>& aGamepads
, ErrorResult
& aRv
);
183 GamepadServiceTest
* RequestGamepadServiceTest();
184 already_AddRefed
<Promise
> GetVRDisplays(ErrorResult
& aRv
);
185 void FinishGetVRDisplays(bool isWebVRSupportedInwindow
, Promise
* p
);
186 void GetActiveVRDisplays(nsTArray
<RefPtr
<VRDisplay
>>& aDisplays
) const;
187 void OnXRPermissionRequestAllow();
188 void OnXRPermissionRequestCancel();
189 VRServiceTest
* RequestVRServiceTest();
190 bool IsWebVRContentDetected() const;
191 bool IsWebVRContentPresenting() const;
192 void RequestVRPresentation(VRDisplay
& aDisplay
);
193 XRSystem
* GetXr(ErrorResult
& aRv
);
194 already_AddRefed
<Promise
> RequestMIDIAccess(const MIDIOptions
& aOptions
,
197 bool SendBeacon(const nsAString
& aUrl
, const Nullable
<fetch::BodyInit
>& aData
,
200 void MozGetUserMedia(const MediaStreamConstraints
& aConstraints
,
201 NavigatorUserMediaSuccessCallback
& aOnSuccess
,
202 NavigatorUserMediaErrorCallback
& aOnError
,
203 CallerType aCallerType
, ErrorResult
& aRv
);
205 already_AddRefed
<ServiceWorkerContainer
> ServiceWorker();
207 mozilla::dom::CredentialsContainer
* Credentials();
208 dom::Clipboard
* Clipboard();
209 webgpu::Instance
* Gpu();
210 dom::LockManager
* Locks();
212 static bool Webdriver();
214 void GetLanguages(nsTArray
<nsString
>& aLanguages
);
216 StorageManager
* Storage();
218 static void GetAcceptLanguages(nsTArray
<nsString
>& aLanguages
);
220 dom::MediaCapabilities
* MediaCapabilities();
221 dom::MediaSession
* MediaSession();
223 AddonManager
* GetMozAddonManager(ErrorResult
& aRv
);
225 // WebIDL helper methods
226 static bool HasUserMediaSupport(JSContext
* /* unused */,
227 JSObject
* /* unused */);
228 static bool HasShareSupport(JSContext
* /* unused */, JSObject
* /* unused */);
230 nsPIDOMWindowInner
* GetParentObject() const { return GetWindow(); }
232 virtual JSObject
* WrapObject(JSContext
* cx
,
233 JS::Handle
<JSObject
*> aGivenProto
) override
;
235 // GetWindowFromGlobal returns the inner window for this global, if
237 static already_AddRefed
<nsPIDOMWindowInner
> GetWindowFromGlobal(
240 already_AddRefed
<Promise
> RequestMediaKeySystemAccess(
241 const nsAString
& aKeySystem
,
242 const Sequence
<MediaKeySystemConfiguration
>& aConfig
, ErrorResult
& aRv
);
244 bool HasCreatedMediaSession() const;
247 void ValidateShareData(const ShareData
& aData
, ErrorResult
& aRv
);
248 RefPtr
<MediaKeySystemAccessManager
> mMediaKeySystemAccessManager
;
251 void NotifyVRDisplaysUpdated();
252 void NotifyActiveVRDisplaysChanged();
255 virtual ~Navigator();
257 // This enum helps SendBeaconInternal to apply different behaviors to body
259 enum BeaconType
{ eBeaconTypeBlob
, eBeaconTypeArrayBuffer
, eBeaconTypeOther
};
261 bool SendBeaconInternal(const nsAString
& aUrl
, BodyExtractorBase
* aBody
,
262 BeaconType aType
, ErrorResult
& aRv
);
264 nsIDocShell
* GetDocShell() const {
265 return mWindow
? mWindow
->GetDocShell() : nullptr;
268 RefPtr
<nsMimeTypeArray
> mMimeTypes
;
269 RefPtr
<nsPluginArray
> mPlugins
;
270 RefPtr
<Permissions
> mPermissions
;
271 RefPtr
<Geolocation
> mGeolocation
;
272 RefPtr
<battery::BatteryManager
> mBatteryManager
;
273 RefPtr
<Promise
> mBatteryPromise
;
274 RefPtr
<network::Connection
> mConnection
;
275 RefPtr
<CredentialsContainer
> mCredentials
;
276 RefPtr
<dom::Clipboard
> mClipboard
;
277 RefPtr
<MediaDevices
> mMediaDevices
;
278 RefPtr
<ServiceWorkerContainer
> mServiceWorkerContainer
;
279 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
280 RefPtr
<GamepadServiceTest
> mGamepadServiceTest
;
281 nsTArray
<RefPtr
<Promise
>> mVRGetDisplaysPromises
;
282 RefPtr
<VRServiceTest
> mVRServiceTest
;
283 RefPtr
<XRSystem
> mXRSystem
;
284 nsTArray
<uint32_t> mRequestedVibrationPattern
;
285 RefPtr
<StorageManager
> mStorageManager
;
286 RefPtr
<dom::MediaCapabilities
> mMediaCapabilities
;
287 RefPtr
<dom::MediaSession
> mMediaSession
;
288 RefPtr
<AddonManager
> mAddonManager
;
289 RefPtr
<webgpu::Instance
> mWebGpu
;
290 RefPtr
<Promise
> mSharePromise
; // Web Share API related
291 RefPtr
<dom::LockManager
> mLocks
;
294 } // namespace mozilla::dom
296 #endif // mozilla_dom_Navigator_h