Bumping manifests a=b2g-bump
[gecko.git] / dom / base / Navigator.h
blob02614c62ebac0656f2ff615764bb285d6cdf21bb
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"
22 class nsPluginArray;
23 class nsMimeTypeArray;
24 class nsPIDOMWindow;
25 class nsIDOMNavigatorSystemMessages;
26 class nsDOMCameraManager;
27 class nsDOMDeviceStorage;
28 class nsIDOMBlob;
29 class nsIPrincipal;
30 class nsIURI;
32 namespace mozilla {
33 namespace dom {
34 class Geolocation;
35 class systemMessageCallback;
36 struct MediaStreamConstraints;
37 class WakeLock;
38 class ArrayBufferViewOrBlobOrStringOrFormData;
39 struct MobileIdOptions;
40 class ServiceWorkerContainer;
44 #ifdef MOZ_B2G_RIL
45 class nsIDOMMozIccManager;
46 #endif // MOZ_B2G_RIL
48 //*****************************************************************************
49 // Navigator: Script "navigator" object
50 //*****************************************************************************
52 namespace mozilla {
53 namespace dom {
55 namespace battery {
56 class BatteryManager;
57 } // namespace battery
59 #ifdef MOZ_B2G_FM
60 class FMRadio;
61 #endif
63 class Promise;
65 class DesktopNotificationCenter;
66 class MobileMessageManager;
67 class MozIdleObserver;
68 #ifdef MOZ_GAMEPAD
69 class Gamepad;
70 #endif // MOZ_GAMEPAD
71 #ifdef MOZ_MEDIA_NAVIGATOR
72 class NavigatorUserMediaSuccessCallback;
73 class NavigatorUserMediaErrorCallback;
74 class MozGetUserMediaDevicesSuccessCallback;
75 #endif // MOZ_MEDIA_NAVIGATOR
77 namespace network {
78 class Connection;
79 } // namespace Connection;
81 #ifdef MOZ_B2G_BT
82 namespace bluetooth {
83 class BluetoothManager;
84 } // namespace bluetooth
85 #endif // MOZ_B2G_BT
87 #ifdef MOZ_B2G_RIL
88 class CellBroadcast;
89 class IccManager;
90 class MobileConnectionArray;
91 class Voicemail;
92 #endif
94 class PowerManager;
95 class Telephony;
97 namespace time {
98 class TimeManager;
99 } // namespace time
101 namespace system {
102 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
103 class AudioChannelManager;
104 #endif
105 } // namespace system
107 class Navigator MOZ_FINAL : public nsIDOMNavigator
108 , public nsIMozNavigatorNetwork
109 , public nsWrapperCache
111 public:
112 explicit Navigator(nsPIDOMWindow* aInnerWindow);
114 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
115 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator,
116 nsIDOMNavigator)
117 NS_DECL_NSIDOMNAVIGATOR
118 NS_DECL_NSIMOZNAVIGATORNETWORK
120 static void Init();
122 void Invalidate();
123 nsPIDOMWindow *GetWindow() const
125 return mWindow;
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.
140 void OnNavigation();
142 // Helper to initialize mMessagesManager.
143 nsresult EnsureMessagesManager();
145 // The XPCOM GetProduct is OK
146 // The XPCOM GetLanguage is OK
147 bool OnLine();
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,
161 ErrorResult& aRv);
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,
172 nsIURI* aURI,
173 bool aIsCallerChrome,
174 nsAString& aUserAgent);
176 already_AddRefed<Promise> GetDataStores(const nsAString& aName,
177 const nsAString& aOwner,
178 ErrorResult& aRv);
180 // Feature Detection API
181 already_AddRefed<Promise> GetFeature(const nsAString& aName,
182 ErrorResult& aRv);
184 already_AddRefed<Promise> HasFeature(const nsAString &aName,
185 ErrorResult& aRv);
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);
208 bool TaintEnabled()
210 return false;
212 void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
213 void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
214 already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
215 ErrorResult& aRv);
216 nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType,
217 ErrorResult& aRv);
218 void GetDeviceStorages(const nsAString& aType,
219 nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
220 ErrorResult& aRv);
221 DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
222 bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline,
223 ErrorResult& aRv);
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,
230 ErrorResult& aRv);
231 bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv);
232 #ifdef MOZ_B2G
233 already_AddRefed<Promise> GetMobileIdAssertion(const MobileIdOptions& options,
234 ErrorResult& aRv);
235 #endif
236 #ifdef MOZ_B2G_RIL
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
242 #ifdef MOZ_GAMEPAD
243 void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
244 #endif // MOZ_GAMEPAD
245 #ifdef MOZ_B2G_FM
246 FMRadio* GetMozFMRadio(ErrorResult& aRv);
247 #endif
248 #ifdef MOZ_B2G_BT
249 bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
250 #endif // MOZ_B2G_BT
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,
260 ErrorResult& aRv);
262 #ifdef MOZ_MEDIA_NAVIGATOR
263 void MozGetUserMedia(const MediaStreamConstraints& aConstraints,
264 NavigatorUserMediaSuccessCallback& aOnSuccess,
265 NavigatorUserMediaErrorCallback& aOnError,
266 ErrorResult& aRv);
267 void MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
268 MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
269 NavigatorUserMediaErrorCallback& aOnError,
270 uint64_t aInnerWindowID,
271 ErrorResult& aRv);
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,
280 ErrorResult& aRv);
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 */,
287 JSObject* aGlobal);
288 static bool HasWifiManagerSupport(JSContext* /* unused */,
289 JSObject* aGlobal);
290 #ifdef MOZ_NFC
291 static bool HasNFCSupport(JSContext* /* unused */, JSObject* aGlobal);
292 #endif // MOZ_NFC
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);
304 #ifdef MOZ_B2G
305 static bool HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal);
306 #endif
308 nsPIDOMWindow* GetParentObject() const
310 return GetWindow();
313 virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
315 private:
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
321 // any, else null.
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;
329 #ifdef MOZ_B2G_FM
330 nsRefPtr<FMRadio> mFMRadio;
331 #endif
332 nsRefPtr<PowerManager> mPowerManager;
333 nsRefPtr<MobileMessageManager> mMobileMessageManager;
334 nsRefPtr<Telephony> mTelephony;
335 nsRefPtr<network::Connection> mConnection;
336 #ifdef MOZ_B2G_RIL
337 nsRefPtr<MobileConnectionArray> mMobileConnections;
338 nsRefPtr<CellBroadcast> mCellBroadcast;
339 nsRefPtr<IccManager> mIccManager;
340 nsRefPtr<Voicemail> mVoicemail;
341 #endif
342 #ifdef MOZ_B2G_BT
343 nsRefPtr<bluetooth::BluetoothManager> mBluetooth;
344 #endif
345 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
346 nsRefPtr<system::AudioChannelManager> mAudioChannelManager;
347 #endif
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;
363 } // namespace dom
364 } // namespace mozilla
366 #endif // mozilla_dom_Navigator_h