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"
23 class nsMimeTypeArray
;
25 class nsIDOMNavigatorSystemMessages
;
26 class nsDOMCameraManager
;
27 class nsDOMDeviceStorage
;
35 class systemMessageCallback
;
36 struct MediaStreamConstraints
;
38 class ArrayBufferViewOrBlobOrStringOrFormData
;
39 struct MobileIdOptions
;
40 class ServiceWorkerContainer
;
45 class nsIDOMMozIccManager
;
48 //*****************************************************************************
49 // Navigator: Script "navigator" object
50 //*****************************************************************************
57 } // namespace battery
65 class DesktopNotificationCenter
;
66 class MobileMessageManager
;
67 class MozIdleObserver
;
71 #ifdef MOZ_MEDIA_NAVIGATOR
72 class NavigatorUserMediaSuccessCallback
;
73 class NavigatorUserMediaErrorCallback
;
74 class MozGetUserMediaDevicesSuccessCallback
;
75 #endif // MOZ_MEDIA_NAVIGATOR
79 } // namespace Connection;
83 class BluetoothManager
;
84 } // namespace bluetooth
90 class MobileConnectionArray
;
102 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
103 class AudioChannelManager
;
105 } // namespace system
107 class Navigator MOZ_FINAL
: public nsIDOMNavigator
108 , public nsIMozNavigatorNetwork
109 , public nsWrapperCache
112 explicit Navigator(nsPIDOMWindow
* aInnerWindow
);
114 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
115 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator
,
117 NS_DECL_NSIDOMNAVIGATOR
118 NS_DECL_NSIMOZNAVIGATORNETWORK
123 nsPIDOMWindow
*GetWindow() const
128 void RefreshMIMEArray();
130 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
133 * For use during document.write where our inner window changes.
135 void SetWindow(nsPIDOMWindow
*aInnerWindow
);
138 * Called when the inner window navigates to a new page.
142 // Helper to initialize mMessagesManager.
143 nsresult
EnsureMessagesManager();
145 // The XPCOM GetProduct is OK
146 // The XPCOM GetLanguage is OK
148 void RegisterProtocolHandler(const nsAString
& aScheme
, const nsAString
& aURL
,
149 const nsAString
& aTitle
, ErrorResult
& aRv
);
150 void RegisterContentHandler(const nsAString
& aMIMEType
, const nsAString
& aURL
,
151 const nsAString
& aTitle
, ErrorResult
& aRv
);
152 nsMimeTypeArray
* GetMimeTypes(ErrorResult
& aRv
);
153 nsPluginArray
* GetPlugins(ErrorResult
& aRv
);
154 // The XPCOM GetDoNotTrack is ok
155 Geolocation
* GetGeolocation(ErrorResult
& aRv
);
156 battery::BatteryManager
* GetBattery(ErrorResult
& aRv
);
158 static already_AddRefed
<Promise
> GetDataStores(nsPIDOMWindow
* aWindow
,
159 const nsAString
& aName
,
160 const nsAString
& aOwner
,
163 static void AppName(nsAString
& aAppName
, bool aUsePrefOverriddenValue
);
165 static nsresult
GetPlatform(nsAString
& aPlatform
,
166 bool aUsePrefOverriddenValue
);
168 static nsresult
GetAppVersion(nsAString
& aAppVersion
,
169 bool aUsePrefOverriddenValue
);
171 static nsresult
GetUserAgent(nsPIDOMWindow
* aWindow
,
173 bool aIsCallerChrome
,
174 nsAString
& aUserAgent
);
176 already_AddRefed
<Promise
> GetDataStores(const nsAString
& aName
,
177 const nsAString
& aOwner
,
180 // Feature Detection API
181 already_AddRefed
<Promise
> GetFeature(const nsAString
& aName
,
184 already_AddRefed
<Promise
> HasFeature(const nsAString
&aName
,
187 bool Vibrate(uint32_t aDuration
);
188 bool Vibrate(const nsTArray
<uint32_t>& aDuration
);
189 uint32_t MaxTouchPoints();
190 void GetAppCodeName(nsString
& aAppCodeName
, ErrorResult
& aRv
)
192 aRv
= GetAppCodeName(aAppCodeName
);
194 void GetOscpu(nsString
& aOscpu
, ErrorResult
& aRv
)
196 aRv
= GetOscpu(aOscpu
);
198 // The XPCOM GetVendor is OK
199 // The XPCOM GetVendorSub is OK
200 // The XPCOM GetProductSub is OK
201 bool CookieEnabled();
202 void GetBuildID(nsString
& aBuildID
, ErrorResult
& aRv
)
204 aRv
= GetBuildID(aBuildID
);
206 PowerManager
* GetMozPower(ErrorResult
& aRv
);
207 bool JavaEnabled(ErrorResult
& aRv
);
212 void AddIdleObserver(MozIdleObserver
& aObserver
, ErrorResult
& aRv
);
213 void RemoveIdleObserver(MozIdleObserver
& aObserver
, ErrorResult
& aRv
);
214 already_AddRefed
<WakeLock
> RequestWakeLock(const nsAString
&aTopic
,
216 nsDOMDeviceStorage
* GetDeviceStorage(const nsAString
& aType
,
218 void GetDeviceStorages(const nsAString
& aType
,
219 nsTArray
<nsRefPtr
<nsDOMDeviceStorage
> >& aStores
,
221 DesktopNotificationCenter
* GetMozNotification(ErrorResult
& aRv
);
222 bool MozIsLocallyAvailable(const nsAString
& aURI
, bool aWhenOffline
,
224 MobileMessageManager
* GetMozMobileMessage();
225 Telephony
* GetMozTelephony(ErrorResult
& aRv
);
226 network::Connection
* GetConnection(ErrorResult
& aRv
);
227 nsDOMCameraManager
* GetMozCameras(ErrorResult
& aRv
);
228 void MozSetMessageHandler(const nsAString
& aType
,
229 systemMessageCallback
* aCallback
,
231 bool MozHasPendingMessage(const nsAString
& aType
, ErrorResult
& aRv
);
233 already_AddRefed
<Promise
> GetMobileIdAssertion(const MobileIdOptions
& options
,
237 MobileConnectionArray
* GetMozMobileConnections(ErrorResult
& aRv
);
238 CellBroadcast
* GetMozCellBroadcast(ErrorResult
& aRv
);
239 Voicemail
* GetMozVoicemail(ErrorResult
& aRv
);
240 IccManager
* GetMozIccManager(ErrorResult
& aRv
);
241 #endif // MOZ_B2G_RIL
243 void GetGamepads(nsTArray
<nsRefPtr
<Gamepad
> >& aGamepads
, ErrorResult
& aRv
);
244 #endif // MOZ_GAMEPAD
246 FMRadio
* GetMozFMRadio(ErrorResult
& aRv
);
249 bluetooth::BluetoothManager
* GetMozBluetooth(ErrorResult
& aRv
);
251 #ifdef MOZ_TIME_MANAGER
252 time::TimeManager
* GetMozTime(ErrorResult
& aRv
);
253 #endif // MOZ_TIME_MANAGER
254 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
255 system::AudioChannelManager
* GetMozAudioChannelManager(ErrorResult
& aRv
);
256 #endif // MOZ_AUDIO_CHANNEL_MANAGER
258 bool SendBeacon(const nsAString
& aUrl
,
259 const Nullable
<ArrayBufferViewOrBlobOrStringOrFormData
>& aData
,
262 #ifdef MOZ_MEDIA_NAVIGATOR
263 void MozGetUserMedia(const MediaStreamConstraints
& aConstraints
,
264 NavigatorUserMediaSuccessCallback
& aOnSuccess
,
265 NavigatorUserMediaErrorCallback
& aOnError
,
267 void MozGetUserMediaDevices(const MediaStreamConstraints
& aConstraints
,
268 MozGetUserMediaDevicesSuccessCallback
& aOnSuccess
,
269 NavigatorUserMediaErrorCallback
& aOnError
,
270 uint64_t aInnerWindowID
,
272 #endif // MOZ_MEDIA_NAVIGATOR
274 already_AddRefed
<ServiceWorkerContainer
> ServiceWorker();
276 bool DoNewResolve(JSContext
* aCx
, JS::Handle
<JSObject
*> aObject
,
277 JS::Handle
<jsid
> aId
,
278 JS::MutableHandle
<JSPropertyDescriptor
> aDesc
);
279 void GetOwnPropertyNames(JSContext
* aCx
, nsTArray
<nsString
>& aNames
,
281 void GetLanguages(nsTArray
<nsString
>& aLanguages
);
282 void GetAcceptLanguages(nsTArray
<nsString
>& aLanguages
);
284 // WebIDL helper methods
285 static bool HasWakeLockSupport(JSContext
* /* unused*/, JSObject
* /*unused */);
286 static bool HasCameraSupport(JSContext
* /* unused */,
288 static bool HasWifiManagerSupport(JSContext
* /* unused */,
291 static bool HasNFCSupport(JSContext
* /* unused */, JSObject
* aGlobal
);
293 #ifdef MOZ_MEDIA_NAVIGATOR
294 static bool HasUserMediaSupport(JSContext
* /* unused */,
295 JSObject
* /* unused */);
296 #endif // MOZ_MEDIA_NAVIGATOR
298 static bool HasInputMethodSupport(JSContext
* /* unused */, JSObject
* aGlobal
);
300 static bool HasDataStoreSupport(nsIPrincipal
* aPrincipal
);
302 static bool HasDataStoreSupport(JSContext
* cx
, JSObject
* aGlobal
);
305 static bool HasMobileIdSupport(JSContext
* aCx
, JSObject
* aGlobal
);
308 nsPIDOMWindow
* GetParentObject() const
313 virtual JSObject
* WrapObject(JSContext
* cx
) MOZ_OVERRIDE
;
316 virtual ~Navigator();
318 bool CheckPermission(const char* type
);
319 static bool CheckPermission(nsPIDOMWindow
* aWindow
, const char* aType
);
320 // GetWindowFromGlobal returns the inner window for this global, if
322 static already_AddRefed
<nsPIDOMWindow
> GetWindowFromGlobal(JSObject
* aGlobal
);
324 nsRefPtr
<nsMimeTypeArray
> mMimeTypes
;
325 nsRefPtr
<nsPluginArray
> mPlugins
;
326 nsRefPtr
<Geolocation
> mGeolocation
;
327 nsRefPtr
<DesktopNotificationCenter
> mNotification
;
328 nsRefPtr
<battery::BatteryManager
> mBatteryManager
;
330 nsRefPtr
<FMRadio
> mFMRadio
;
332 nsRefPtr
<PowerManager
> mPowerManager
;
333 nsRefPtr
<MobileMessageManager
> mMobileMessageManager
;
334 nsRefPtr
<Telephony
> mTelephony
;
335 nsRefPtr
<network::Connection
> mConnection
;
337 nsRefPtr
<MobileConnectionArray
> mMobileConnections
;
338 nsRefPtr
<CellBroadcast
> mCellBroadcast
;
339 nsRefPtr
<IccManager
> mIccManager
;
340 nsRefPtr
<Voicemail
> mVoicemail
;
343 nsRefPtr
<bluetooth::BluetoothManager
> mBluetooth
;
345 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
346 nsRefPtr
<system::AudioChannelManager
> mAudioChannelManager
;
348 nsRefPtr
<nsDOMCameraManager
> mCameraManager
;
349 nsCOMPtr
<nsIDOMNavigatorSystemMessages
> mMessagesManager
;
350 nsTArray
<nsRefPtr
<nsDOMDeviceStorage
> > mDeviceStorageStores
;
351 nsRefPtr
<time::TimeManager
> mTimeManager
;
352 nsRefPtr
<ServiceWorkerContainer
> mServiceWorkerContainer
;
353 nsCOMPtr
<nsPIDOMWindow
> mWindow
;
355 // Hashtable for saving cached objects newresolve created, so we don't create
356 // the object twice if asked for it twice, whether due to use of "delete" or
357 // due to Xrays. We could probably use a nsJSThingHashtable here, but then
358 // we'd need to figure out exactly how to trace that, and that seems to be
359 // rocket science. :(
360 nsInterfaceHashtable
<nsStringHashKey
, nsISupports
> mCachedResolveResults
;
364 } // namespace mozilla
366 #endif // mozilla_dom_Navigator_h