Bumping manifests a=b2g-bump
[gecko.git] / dom / base / Navigator.h
blob7d7daff15ad1466207c8ab2a7a8da74e1aa6f890
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et 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/Nullable.h"
12 #include "mozilla/ErrorResult.h"
13 #include "nsIDOMNavigator.h"
14 #include "nsIMozNavigatorNetwork.h"
15 #include "nsAutoPtr.h"
16 #include "nsWrapperCache.h"
17 #include "nsHashKeys.h"
18 #include "nsInterfaceHashtable.h"
19 #include "nsString.h"
20 #include "nsTArray.h"
21 #ifdef MOZ_EME
22 #include "mozilla/dom/MediaKeySystemAccess.h"
23 #endif
25 class nsPluginArray;
26 class nsMimeTypeArray;
27 class nsPIDOMWindow;
28 class nsIDOMNavigatorSystemMessages;
29 class nsDOMCameraManager;
30 class nsDOMDeviceStorage;
31 class nsIPrincipal;
32 class nsIURI;
34 namespace mozilla {
35 namespace dom {
36 class Geolocation;
37 class systemMessageCallback;
38 class MediaDevices;
39 struct MediaStreamConstraints;
40 class WakeLock;
41 class ArrayBufferViewOrBlobOrStringOrFormData;
42 struct MobileIdOptions;
43 class ServiceWorkerContainer;
47 #ifdef MOZ_B2G_RIL
48 class nsIDOMMozIccManager;
49 #endif // MOZ_B2G_RIL
51 //*****************************************************************************
52 // Navigator: Script "navigator" object
53 //*****************************************************************************
55 namespace mozilla {
56 namespace dom {
58 namespace battery {
59 class BatteryManager;
60 } // namespace battery
62 #ifdef MOZ_B2G_FM
63 class FMRadio;
64 #endif
66 class Promise;
68 class DesktopNotificationCenter;
69 class MobileMessageManager;
70 class MozIdleObserver;
71 #ifdef MOZ_GAMEPAD
72 class Gamepad;
73 #endif // MOZ_GAMEPAD
74 #ifdef MOZ_MEDIA_NAVIGATOR
75 class NavigatorUserMediaSuccessCallback;
76 class NavigatorUserMediaErrorCallback;
77 class MozGetUserMediaDevicesSuccessCallback;
78 #endif // MOZ_MEDIA_NAVIGATOR
80 namespace network {
81 class Connection;
82 } // namespace Connection;
84 #ifdef MOZ_B2G_BT
85 namespace bluetooth {
86 class BluetoothManager;
87 } // namespace bluetooth
88 #endif // MOZ_B2G_BT
90 #ifdef MOZ_B2G_RIL
91 class IccManager;
92 class MobileConnectionArray;
93 #endif
95 class PowerManager;
96 class CellBroadcast;
97 class Telephony;
98 class Voicemail;
99 class TVManager;
101 namespace time {
102 class TimeManager;
103 } // namespace time
105 namespace system {
106 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
107 class AudioChannelManager;
108 #endif
109 } // namespace system
111 class Navigator MOZ_FINAL : public nsIDOMNavigator
112 , public nsIMozNavigatorNetwork
113 , public nsWrapperCache
115 public:
116 explicit Navigator(nsPIDOMWindow* aInnerWindow);
118 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
119 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator,
120 nsIDOMNavigator)
121 NS_DECL_NSIDOMNAVIGATOR
122 NS_DECL_NSIMOZNAVIGATORNETWORK
124 static void Init();
126 void Invalidate();
127 nsPIDOMWindow *GetWindow() const
129 return mWindow;
132 void RefreshMIMEArray();
134 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
137 * For use during document.write where our inner window changes.
139 void SetWindow(nsPIDOMWindow *aInnerWindow);
142 * Called when the inner window navigates to a new page.
144 void OnNavigation();
146 // Helper to initialize mMessagesManager.
147 nsresult EnsureMessagesManager();
149 // The XPCOM GetProduct is OK
150 // The XPCOM GetLanguage is OK
151 bool OnLine();
152 void RegisterProtocolHandler(const nsAString& aScheme, const nsAString& aURL,
153 const nsAString& aTitle, ErrorResult& aRv);
154 void RegisterContentHandler(const nsAString& aMIMEType, const nsAString& aURL,
155 const nsAString& aTitle, ErrorResult& aRv);
156 nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv);
157 nsPluginArray* GetPlugins(ErrorResult& aRv);
158 // The XPCOM GetDoNotTrack is ok
159 Geolocation* GetGeolocation(ErrorResult& aRv);
160 battery::BatteryManager* GetBattery(ErrorResult& aRv);
162 static already_AddRefed<Promise> GetDataStores(nsPIDOMWindow* aWindow,
163 const nsAString& aName,
164 const nsAString& aOwner,
165 ErrorResult& aRv);
167 static void AppName(nsAString& aAppName, bool aUsePrefOverriddenValue);
169 static nsresult GetPlatform(nsAString& aPlatform,
170 bool aUsePrefOverriddenValue);
172 static nsresult GetAppVersion(nsAString& aAppVersion,
173 bool aUsePrefOverriddenValue);
175 static nsresult GetUserAgent(nsPIDOMWindow* aWindow,
176 nsIURI* aURI,
177 bool aIsCallerChrome,
178 nsAString& aUserAgent);
180 already_AddRefed<Promise> GetDataStores(const nsAString& aName,
181 const nsAString& aOwner,
182 ErrorResult& aRv);
184 // Feature Detection API
185 already_AddRefed<Promise> GetFeature(const nsAString& aName,
186 ErrorResult& aRv);
188 already_AddRefed<Promise> HasFeature(const nsAString &aName,
189 ErrorResult& aRv);
191 bool Vibrate(uint32_t aDuration);
192 bool Vibrate(const nsTArray<uint32_t>& aDuration);
193 uint32_t MaxTouchPoints();
194 void GetAppCodeName(nsString& aAppCodeName, ErrorResult& aRv)
196 aRv = GetAppCodeName(aAppCodeName);
198 void GetOscpu(nsString& aOscpu, ErrorResult& aRv)
200 aRv = GetOscpu(aOscpu);
202 // The XPCOM GetVendor is OK
203 // The XPCOM GetVendorSub is OK
204 // The XPCOM GetProductSub is OK
205 bool CookieEnabled();
206 void GetBuildID(nsString& aBuildID, ErrorResult& aRv)
208 aRv = GetBuildID(aBuildID);
210 PowerManager* GetMozPower(ErrorResult& aRv);
211 bool JavaEnabled(ErrorResult& aRv);
212 bool TaintEnabled()
214 return false;
216 void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
217 void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
218 already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
219 ErrorResult& aRv);
220 nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType,
221 ErrorResult& aRv);
222 void GetDeviceStorages(const nsAString& aType,
223 nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
224 ErrorResult& aRv);
225 DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
226 CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv);
227 MobileMessageManager* GetMozMobileMessage();
228 Telephony* GetMozTelephony(ErrorResult& aRv);
229 Voicemail* GetMozVoicemail(ErrorResult& aRv);
230 TVManager* GetTv();
231 network::Connection* GetConnection(ErrorResult& aRv);
232 nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);
233 MediaDevices* GetMediaDevices(ErrorResult& aRv);
234 void MozSetMessageHandler(const nsAString& aType,
235 systemMessageCallback* aCallback,
236 ErrorResult& aRv);
237 bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv);
238 void MozSetMessageHandlerPromise(Promise& aPromise, ErrorResult& aRv);
240 #ifdef MOZ_B2G
241 already_AddRefed<Promise> GetMobileIdAssertion(const MobileIdOptions& options,
242 ErrorResult& aRv);
243 #endif
244 #ifdef MOZ_B2G_RIL
245 MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv);
246 IccManager* GetMozIccManager(ErrorResult& aRv);
247 #endif // MOZ_B2G_RIL
248 #ifdef MOZ_GAMEPAD
249 void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
250 #endif // MOZ_GAMEPAD
251 already_AddRefed<Promise> GetVRDevices(ErrorResult& aRv);
252 #ifdef MOZ_B2G_FM
253 FMRadio* GetMozFMRadio(ErrorResult& aRv);
254 #endif
255 #ifdef MOZ_B2G_BT
256 bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
257 #endif // MOZ_B2G_BT
258 #ifdef MOZ_TIME_MANAGER
259 time::TimeManager* GetMozTime(ErrorResult& aRv);
260 #endif // MOZ_TIME_MANAGER
261 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
262 system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv);
263 #endif // MOZ_AUDIO_CHANNEL_MANAGER
265 bool SendBeacon(const nsAString& aUrl,
266 const Nullable<ArrayBufferViewOrBlobOrStringOrFormData>& aData,
267 ErrorResult& aRv);
269 #ifdef MOZ_MEDIA_NAVIGATOR
270 void MozGetUserMedia(const MediaStreamConstraints& aConstraints,
271 NavigatorUserMediaSuccessCallback& aOnSuccess,
272 NavigatorUserMediaErrorCallback& aOnError,
273 ErrorResult& aRv);
274 void MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
275 MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
276 NavigatorUserMediaErrorCallback& aOnError,
277 uint64_t aInnerWindowID,
278 ErrorResult& aRv);
279 #endif // MOZ_MEDIA_NAVIGATOR
281 already_AddRefed<ServiceWorkerContainer> ServiceWorker();
283 bool DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
284 JS::Handle<jsid> aId,
285 JS::MutableHandle<JSPropertyDescriptor> aDesc);
286 void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames,
287 ErrorResult& aRv);
288 void GetLanguages(nsTArray<nsString>& aLanguages);
290 static void GetAcceptLanguages(nsTArray<nsString>& aLanguages);
292 // WebIDL helper methods
293 static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */);
294 static bool HasCameraSupport(JSContext* /* unused */,
295 JSObject* aGlobal);
296 static bool HasWifiManagerSupport(JSContext* /* unused */,
297 JSObject* aGlobal);
298 #ifdef MOZ_NFC
299 static bool HasNFCSupport(JSContext* /* unused */, JSObject* aGlobal);
300 #endif // MOZ_NFC
301 #ifdef MOZ_MEDIA_NAVIGATOR
302 static bool HasUserMediaSupport(JSContext* /* unused */,
303 JSObject* /* unused */);
304 #endif // MOZ_MEDIA_NAVIGATOR
306 static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal);
308 static bool HasDataStoreSupport(nsIPrincipal* aPrincipal);
310 static bool HasDataStoreSupport(JSContext* cx, JSObject* aGlobal);
312 #ifdef MOZ_B2G
313 static bool HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal);
314 #endif
316 static bool HasTVSupport(JSContext* aCx, JSObject* aGlobal);
318 nsPIDOMWindow* GetParentObject() const
320 return GetWindow();
323 virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
325 #ifdef MOZ_EME
326 already_AddRefed<Promise>
327 RequestMediaKeySystemAccess(const nsAString& aKeySystem,
328 const Optional<Sequence<MediaKeySystemOptions>>& aOptions,
329 ErrorResult& aRv);
330 #endif
332 private:
333 virtual ~Navigator();
335 bool CheckPermission(const char* type);
336 static bool CheckPermission(nsPIDOMWindow* aWindow, const char* aType);
337 // GetWindowFromGlobal returns the inner window for this global, if
338 // any, else null.
339 static already_AddRefed<nsPIDOMWindow> GetWindowFromGlobal(JSObject* aGlobal);
341 nsRefPtr<nsMimeTypeArray> mMimeTypes;
342 nsRefPtr<nsPluginArray> mPlugins;
343 nsRefPtr<Geolocation> mGeolocation;
344 nsRefPtr<DesktopNotificationCenter> mNotification;
345 nsRefPtr<battery::BatteryManager> mBatteryManager;
346 #ifdef MOZ_B2G_FM
347 nsRefPtr<FMRadio> mFMRadio;
348 #endif
349 nsRefPtr<PowerManager> mPowerManager;
350 nsRefPtr<CellBroadcast> mCellBroadcast;
351 nsRefPtr<MobileMessageManager> mMobileMessageManager;
352 nsRefPtr<Telephony> mTelephony;
353 nsRefPtr<Voicemail> mVoicemail;
354 nsRefPtr<TVManager> mTVManager;
355 nsRefPtr<network::Connection> mConnection;
356 #ifdef MOZ_B2G_RIL
357 nsRefPtr<MobileConnectionArray> mMobileConnections;
358 nsRefPtr<IccManager> mIccManager;
359 #endif
360 #ifdef MOZ_B2G_BT
361 nsRefPtr<bluetooth::BluetoothManager> mBluetooth;
362 #endif
363 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
364 nsRefPtr<system::AudioChannelManager> mAudioChannelManager;
365 #endif
366 nsRefPtr<nsDOMCameraManager> mCameraManager;
367 nsRefPtr<MediaDevices> mMediaDevices;
368 nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager;
369 nsTArray<nsRefPtr<nsDOMDeviceStorage> > mDeviceStorageStores;
370 nsRefPtr<time::TimeManager> mTimeManager;
371 nsRefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
372 nsCOMPtr<nsPIDOMWindow> mWindow;
374 // Hashtable for saving cached objects DoResolve created, so we don't create
375 // the object twice if asked for it twice, whether due to use of "delete" or
376 // due to Xrays. We could probably use a nsJSThingHashtable here, but then
377 // we'd need to figure out exactly how to trace that, and that seems to be
378 // rocket science. :(
379 nsInterfaceHashtable<nsStringHashKey, nsISupports> mCachedResolveResults;
382 } // namespace dom
383 } // namespace mozilla
385 #endif // mozilla_dom_Navigator_h