Bug 1750871 - run mochitest-remote on fission everywhere. r=releng-reviewers,aki
[gecko.git] / dom / base / Navigator.h
blobe36cd43b76fd09596f6ccc1e0d70848b3d4ab7c0
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"
18 #include "nsString.h"
19 #include "nsTArray.h"
20 #include "mozilla/dom/MediaKeySystemAccessManager.h"
22 class nsPluginArray;
23 class nsMimeTypeArray;
24 class nsPIDOMWindowInner;
25 class nsIDOMNavigatorSystemMessages;
26 class nsIPrincipal;
27 class nsIURI;
29 namespace mozilla {
30 class ErrorResult;
32 namespace dom {
33 class AddonManager;
34 class BodyExtractorBase;
35 class Geolocation;
36 class systemMessageCallback;
37 class MediaDevices;
38 struct MediaStreamConstraints;
39 class WakeLock;
40 class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
41 class ServiceWorkerContainer;
42 class DOMRequest;
43 class CredentialsContainer;
44 class Clipboard;
45 class LockManager;
46 } // namespace dom
47 namespace webgpu {
48 class Instance;
49 } // namespace webgpu
50 } // namespace mozilla
52 //*****************************************************************************
53 // Navigator: Script "navigator" object
54 //*****************************************************************************
56 namespace mozilla::dom {
58 class Permissions;
60 namespace battery {
61 class BatteryManager;
62 } // namespace battery
64 class Promise;
66 class Gamepad;
67 class GamepadServiceTest;
68 class NavigatorUserMediaSuccessCallback;
69 class NavigatorUserMediaErrorCallback;
71 struct MIDIOptions;
73 nsTArray<uint32_t> SanitizeVibratePattern(const nsTArray<uint32_t>& aPattern);
75 namespace network {
76 class Connection;
77 } // namespace network
79 class LegacyMozTCPSocket;
80 class VRDisplay;
81 class VRServiceTest;
82 class XRSystem;
83 class StorageManager;
84 class MediaCapabilities;
85 class MediaSession;
86 struct ShareData;
87 class WindowGlobalChild;
89 class Navigator final : public nsISupports, public nsWrapperCache {
90 public:
91 explicit Navigator(nsPIDOMWindowInner* aInnerWindow);
93 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
94 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Navigator)
96 void Invalidate();
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.
109 void OnNavigation();
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;
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 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,
195 ErrorResult& aRv);
197 bool SendBeacon(const nsAString& aUrl, const Nullable<fetch::BodyInit>& aData,
198 ErrorResult& aRv);
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
236 // any, else null.
237 static already_AddRefed<nsPIDOMWindowInner> GetWindowFromGlobal(
238 JSObject* aGlobal);
240 already_AddRefed<Promise> RequestMediaKeySystemAccess(
241 const nsAString& aKeySystem,
242 const Sequence<MediaKeySystemConfiguration>& aConfig, ErrorResult& aRv);
244 bool HasCreatedMediaSession() const;
246 private:
247 void ValidateShareData(const ShareData& aData, ErrorResult& aRv);
248 RefPtr<MediaKeySystemAccessManager> mMediaKeySystemAccessManager;
250 public:
251 void NotifyVRDisplaysUpdated();
252 void NotifyActiveVRDisplaysChanged();
254 private:
255 virtual ~Navigator();
257 // This enum helps SendBeaconInternal to apply different behaviors to body
258 // types.
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