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"
22 #include "mozilla/dom/MediaKeySystemAccess.h"
26 class nsMimeTypeArray
;
28 class nsIDOMNavigatorSystemMessages
;
29 class nsDOMCameraManager
;
30 class nsDOMDeviceStorage
;
37 class systemMessageCallback
;
39 struct MediaStreamConstraints
;
41 class ArrayBufferViewOrBlobOrStringOrFormData
;
42 struct MobileIdOptions
;
43 class ServiceWorkerContainer
;
48 class nsIDOMMozIccManager
;
51 //*****************************************************************************
52 // Navigator: Script "navigator" object
53 //*****************************************************************************
60 } // namespace battery
68 class DesktopNotificationCenter
;
69 class MobileMessageManager
;
70 class MozIdleObserver
;
74 #ifdef MOZ_MEDIA_NAVIGATOR
75 class NavigatorUserMediaSuccessCallback
;
76 class NavigatorUserMediaErrorCallback
;
77 class MozGetUserMediaDevicesSuccessCallback
;
78 #endif // MOZ_MEDIA_NAVIGATOR
82 } // namespace Connection;
86 class BluetoothManager
;
87 } // namespace bluetooth
92 class MobileConnectionArray
;
106 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
107 class AudioChannelManager
;
109 } // namespace system
111 class Navigator MOZ_FINAL
: public nsIDOMNavigator
112 , public nsIMozNavigatorNetwork
113 , public nsWrapperCache
116 explicit Navigator(nsPIDOMWindow
* aInnerWindow
);
118 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
119 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator
,
121 NS_DECL_NSIDOMNAVIGATOR
122 NS_DECL_NSIMOZNAVIGATORNETWORK
127 nsPIDOMWindow
*GetWindow() const
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.
146 // Helper to initialize mMessagesManager.
147 nsresult
EnsureMessagesManager();
149 // The XPCOM GetProduct is OK
150 // The XPCOM GetLanguage is OK
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
,
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
,
177 bool aIsCallerChrome
,
178 nsAString
& aUserAgent
);
180 already_AddRefed
<Promise
> GetDataStores(const nsAString
& aName
,
181 const nsAString
& aOwner
,
184 // Feature Detection API
185 already_AddRefed
<Promise
> GetFeature(const nsAString
& aName
,
188 already_AddRefed
<Promise
> HasFeature(const nsAString
&aName
,
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
);
216 void AddIdleObserver(MozIdleObserver
& aObserver
, ErrorResult
& aRv
);
217 void RemoveIdleObserver(MozIdleObserver
& aObserver
, ErrorResult
& aRv
);
218 already_AddRefed
<WakeLock
> RequestWakeLock(const nsAString
&aTopic
,
220 nsDOMDeviceStorage
* GetDeviceStorage(const nsAString
& aType
,
222 void GetDeviceStorages(const nsAString
& aType
,
223 nsTArray
<nsRefPtr
<nsDOMDeviceStorage
> >& aStores
,
225 DesktopNotificationCenter
* GetMozNotification(ErrorResult
& aRv
);
226 CellBroadcast
* GetMozCellBroadcast(ErrorResult
& aRv
);
227 MobileMessageManager
* GetMozMobileMessage();
228 Telephony
* GetMozTelephony(ErrorResult
& aRv
);
229 Voicemail
* GetMozVoicemail(ErrorResult
& aRv
);
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
,
237 bool MozHasPendingMessage(const nsAString
& aType
, ErrorResult
& aRv
);
238 void MozSetMessageHandlerPromise(Promise
& aPromise
, ErrorResult
& aRv
);
241 already_AddRefed
<Promise
> GetMobileIdAssertion(const MobileIdOptions
& options
,
245 MobileConnectionArray
* GetMozMobileConnections(ErrorResult
& aRv
);
246 IccManager
* GetMozIccManager(ErrorResult
& aRv
);
247 #endif // MOZ_B2G_RIL
249 void GetGamepads(nsTArray
<nsRefPtr
<Gamepad
> >& aGamepads
, ErrorResult
& aRv
);
250 #endif // MOZ_GAMEPAD
251 already_AddRefed
<Promise
> GetVRDevices(ErrorResult
& aRv
);
253 FMRadio
* GetMozFMRadio(ErrorResult
& aRv
);
256 bluetooth::BluetoothManager
* GetMozBluetooth(ErrorResult
& aRv
);
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
,
269 #ifdef MOZ_MEDIA_NAVIGATOR
270 void MozGetUserMedia(const MediaStreamConstraints
& aConstraints
,
271 NavigatorUserMediaSuccessCallback
& aOnSuccess
,
272 NavigatorUserMediaErrorCallback
& aOnError
,
274 void MozGetUserMediaDevices(const MediaStreamConstraints
& aConstraints
,
275 MozGetUserMediaDevicesSuccessCallback
& aOnSuccess
,
276 NavigatorUserMediaErrorCallback
& aOnError
,
277 uint64_t aInnerWindowID
,
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
,
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 */,
296 static bool HasWifiManagerSupport(JSContext
* /* unused */,
299 static bool HasNFCSupport(JSContext
* /* unused */, JSObject
* aGlobal
);
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
);
313 static bool HasMobileIdSupport(JSContext
* aCx
, JSObject
* aGlobal
);
316 static bool HasTVSupport(JSContext
* aCx
, JSObject
* aGlobal
);
318 nsPIDOMWindow
* GetParentObject() const
323 virtual JSObject
* WrapObject(JSContext
* cx
) MOZ_OVERRIDE
;
326 already_AddRefed
<Promise
>
327 RequestMediaKeySystemAccess(const nsAString
& aKeySystem
,
328 const Optional
<Sequence
<MediaKeySystemOptions
>>& aOptions
,
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
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
;
347 nsRefPtr
<FMRadio
> mFMRadio
;
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
;
357 nsRefPtr
<MobileConnectionArray
> mMobileConnections
;
358 nsRefPtr
<IccManager
> mIccManager
;
361 nsRefPtr
<bluetooth::BluetoothManager
> mBluetooth
;
363 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
364 nsRefPtr
<system::AudioChannelManager
> mAudioChannelManager
;
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
;
383 } // namespace mozilla
385 #endif // mozilla_dom_Navigator_h