|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_Navigator_h |
|
8 #define mozilla_dom_Navigator_h |
|
9 |
|
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 |
|
22 class nsPluginArray; |
|
23 class nsMimeTypeArray; |
|
24 class nsPIDOMWindow; |
|
25 class nsIDOMMozMobileMessageManager; |
|
26 class nsIDOMNavigatorSystemMessages; |
|
27 class nsDOMCameraManager; |
|
28 class nsDOMDeviceStorage; |
|
29 class nsIDOMBlob; |
|
30 |
|
31 namespace mozilla { |
|
32 namespace dom { |
|
33 class Geolocation; |
|
34 class systemMessageCallback; |
|
35 class MediaStreamConstraints; |
|
36 class WakeLock; |
|
37 class ArrayBufferViewOrBlobOrStringOrFormData; |
|
38 } |
|
39 } |
|
40 |
|
41 #ifdef MOZ_B2G_RIL |
|
42 class nsIDOMMozIccManager; |
|
43 #endif // MOZ_B2G_RIL |
|
44 |
|
45 //***************************************************************************** |
|
46 // Navigator: Script "navigator" object |
|
47 //***************************************************************************** |
|
48 |
|
49 namespace mozilla { |
|
50 namespace dom { |
|
51 |
|
52 namespace battery { |
|
53 class BatteryManager; |
|
54 } // namespace battery |
|
55 |
|
56 #ifdef MOZ_B2G_FM |
|
57 class FMRadio; |
|
58 #endif |
|
59 |
|
60 class Promise; |
|
61 |
|
62 class DesktopNotificationCenter; |
|
63 class MobileMessageManager; |
|
64 class MozIdleObserver; |
|
65 #ifdef MOZ_GAMEPAD |
|
66 class Gamepad; |
|
67 #endif // MOZ_GAMEPAD |
|
68 #ifdef MOZ_MEDIA_NAVIGATOR |
|
69 class NavigatorUserMediaSuccessCallback; |
|
70 class NavigatorUserMediaErrorCallback; |
|
71 class MozGetUserMediaDevicesSuccessCallback; |
|
72 #endif // MOZ_MEDIA_NAVIGATOR |
|
73 |
|
74 namespace network { |
|
75 class Connection; |
|
76 } // namespace Connection; |
|
77 |
|
78 #ifdef MOZ_B2G_BT |
|
79 namespace bluetooth { |
|
80 class BluetoothManager; |
|
81 } // namespace bluetooth |
|
82 #endif // MOZ_B2G_BT |
|
83 |
|
84 #ifdef MOZ_B2G_RIL |
|
85 class CellBroadcast; |
|
86 class IccManager; |
|
87 class MobileConnectionArray; |
|
88 class Voicemail; |
|
89 #endif |
|
90 |
|
91 class PowerManager; |
|
92 class Telephony; |
|
93 |
|
94 namespace time { |
|
95 class TimeManager; |
|
96 } // namespace time |
|
97 |
|
98 namespace system { |
|
99 #ifdef MOZ_AUDIO_CHANNEL_MANAGER |
|
100 class AudioChannelManager; |
|
101 #endif |
|
102 } // namespace system |
|
103 |
|
104 class Navigator : public nsIDOMNavigator |
|
105 , public nsIMozNavigatorNetwork |
|
106 , public nsWrapperCache |
|
107 { |
|
108 public: |
|
109 Navigator(nsPIDOMWindow *aInnerWindow); |
|
110 virtual ~Navigator(); |
|
111 |
|
112 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
113 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator, |
|
114 nsIDOMNavigator) |
|
115 NS_DECL_NSIDOMNAVIGATOR |
|
116 NS_DECL_NSIMOZNAVIGATORNETWORK |
|
117 |
|
118 static void Init(); |
|
119 |
|
120 void Invalidate(); |
|
121 nsPIDOMWindow *GetWindow() const |
|
122 { |
|
123 return mWindow; |
|
124 } |
|
125 |
|
126 void RefreshMIMEArray(); |
|
127 |
|
128 static bool HasDesktopNotificationSupport(); |
|
129 |
|
130 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
|
131 |
|
132 /** |
|
133 * For use during document.write where our inner window changes. |
|
134 */ |
|
135 void SetWindow(nsPIDOMWindow *aInnerWindow); |
|
136 |
|
137 /** |
|
138 * Called when the inner window navigates to a new page. |
|
139 */ |
|
140 void OnNavigation(); |
|
141 |
|
142 // Helper to initialize mMessagesManager. |
|
143 nsresult EnsureMessagesManager(); |
|
144 |
|
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); |
|
157 |
|
158 static void AppName(nsAString& aAppName, bool aUsePrefOverriddenValue); |
|
159 |
|
160 static nsresult GetPlatform(nsAString& aPlatform, |
|
161 bool aUsePrefOverriddenValue); |
|
162 |
|
163 static nsresult GetAppVersion(nsAString& aAppVersion, |
|
164 bool aUsePrefOverriddenValue); |
|
165 |
|
166 already_AddRefed<Promise> GetDataStores(const nsAString &aName, |
|
167 ErrorResult& aRv); |
|
168 bool Vibrate(uint32_t aDuration); |
|
169 bool Vibrate(const nsTArray<uint32_t>& aDuration); |
|
170 uint32_t MaxTouchPoints(); |
|
171 void GetAppCodeName(nsString& aAppCodeName, ErrorResult& aRv) |
|
172 { |
|
173 aRv = GetAppCodeName(aAppCodeName); |
|
174 } |
|
175 void GetOscpu(nsString& aOscpu, ErrorResult& aRv) |
|
176 { |
|
177 aRv = GetOscpu(aOscpu); |
|
178 } |
|
179 // The XPCOM GetVendor is OK |
|
180 // The XPCOM GetVendorSub is OK |
|
181 // The XPCOM GetProductSub is OK |
|
182 bool CookieEnabled(); |
|
183 void GetBuildID(nsString& aBuildID, ErrorResult& aRv) |
|
184 { |
|
185 aRv = GetBuildID(aBuildID); |
|
186 } |
|
187 PowerManager* GetMozPower(ErrorResult& aRv); |
|
188 bool JavaEnabled(ErrorResult& aRv); |
|
189 bool TaintEnabled() |
|
190 { |
|
191 return false; |
|
192 } |
|
193 void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); |
|
194 void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); |
|
195 already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic, |
|
196 ErrorResult& aRv); |
|
197 nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType, |
|
198 ErrorResult& aRv); |
|
199 void GetDeviceStorages(const nsAString& aType, |
|
200 nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores, |
|
201 ErrorResult& aRv); |
|
202 DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv); |
|
203 bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline, |
|
204 ErrorResult& aRv); |
|
205 nsIDOMMozMobileMessageManager* GetMozMobileMessage(); |
|
206 Telephony* GetMozTelephony(ErrorResult& aRv); |
|
207 network::Connection* GetConnection(ErrorResult& aRv); |
|
208 nsDOMCameraManager* GetMozCameras(ErrorResult& aRv); |
|
209 void MozSetMessageHandler(const nsAString& aType, |
|
210 systemMessageCallback* aCallback, |
|
211 ErrorResult& aRv); |
|
212 bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv); |
|
213 #ifdef MOZ_B2G_RIL |
|
214 MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv); |
|
215 CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv); |
|
216 Voicemail* GetMozVoicemail(ErrorResult& aRv); |
|
217 IccManager* GetMozIccManager(ErrorResult& aRv); |
|
218 #endif // MOZ_B2G_RIL |
|
219 #ifdef MOZ_GAMEPAD |
|
220 void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv); |
|
221 #endif // MOZ_GAMEPAD |
|
222 #ifdef MOZ_B2G_FM |
|
223 FMRadio* GetMozFMRadio(ErrorResult& aRv); |
|
224 #endif |
|
225 #ifdef MOZ_B2G_BT |
|
226 bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv); |
|
227 #endif // MOZ_B2G_BT |
|
228 #ifdef MOZ_TIME_MANAGER |
|
229 time::TimeManager* GetMozTime(ErrorResult& aRv); |
|
230 #endif // MOZ_TIME_MANAGER |
|
231 #ifdef MOZ_AUDIO_CHANNEL_MANAGER |
|
232 system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv); |
|
233 #endif // MOZ_AUDIO_CHANNEL_MANAGER |
|
234 |
|
235 bool SendBeacon(const nsAString& aUrl, |
|
236 const Nullable<ArrayBufferViewOrBlobOrStringOrFormData>& aData, |
|
237 ErrorResult& aRv); |
|
238 |
|
239 #ifdef MOZ_MEDIA_NAVIGATOR |
|
240 void MozGetUserMedia(const MediaStreamConstraints& aConstraints, |
|
241 NavigatorUserMediaSuccessCallback& aOnSuccess, |
|
242 NavigatorUserMediaErrorCallback& aOnError, |
|
243 ErrorResult& aRv); |
|
244 void MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints, |
|
245 MozGetUserMediaDevicesSuccessCallback& aOnSuccess, |
|
246 NavigatorUserMediaErrorCallback& aOnError, |
|
247 uint64_t aInnerWindowID, |
|
248 ErrorResult& aRv); |
|
249 #endif // MOZ_MEDIA_NAVIGATOR |
|
250 bool DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject, |
|
251 JS::Handle<jsid> aId, |
|
252 JS::MutableHandle<JSPropertyDescriptor> aDesc); |
|
253 void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames, |
|
254 ErrorResult& aRv); |
|
255 |
|
256 // WebIDL helper methods |
|
257 static bool HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */); |
|
258 static bool HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
259 static bool HasPhoneNumberSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
260 static bool HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
261 static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */); |
|
262 static bool HasDesktopNotificationSupport(JSContext* /* unused*/, |
|
263 JSObject* /*unused */) |
|
264 { |
|
265 return HasDesktopNotificationSupport(); |
|
266 } |
|
267 static bool HasMobileMessageSupport(JSContext* /* unused */, |
|
268 JSObject* aGlobal); |
|
269 static bool HasTelephonySupport(JSContext* cx, |
|
270 JSObject* aGlobal); |
|
271 static bool HasCameraSupport(JSContext* /* unused */, |
|
272 JSObject* aGlobal); |
|
273 #ifdef MOZ_B2G_RIL |
|
274 static bool HasMobileConnectionSupport(JSContext* /* unused */, |
|
275 JSObject* aGlobal); |
|
276 static bool HasCellBroadcastSupport(JSContext* /* unused */, |
|
277 JSObject* aGlobal); |
|
278 static bool HasVoicemailSupport(JSContext* /* unused */, |
|
279 JSObject* aGlobal); |
|
280 static bool HasIccManagerSupport(JSContext* /* unused */, |
|
281 JSObject* aGlobal); |
|
282 #endif // MOZ_B2G_RIL |
|
283 static bool HasWifiManagerSupport(JSContext* /* unused */, |
|
284 JSObject* aGlobal); |
|
285 #ifdef MOZ_B2G_BT |
|
286 static bool HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
287 #endif // MOZ_B2G_BT |
|
288 #ifdef MOZ_B2G_FM |
|
289 static bool HasFMRadioSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
290 #endif // MOZ_B2G_FM |
|
291 #ifdef MOZ_NFC |
|
292 static bool HasNfcSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
293 static bool HasNfcPeerSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
294 static bool HasNfcManagerSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
295 #endif // MOZ_NFC |
|
296 #ifdef MOZ_TIME_MANAGER |
|
297 static bool HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
298 #endif // MOZ_TIME_MANAGER |
|
299 #ifdef MOZ_MEDIA_NAVIGATOR |
|
300 static bool HasUserMediaSupport(JSContext* /* unused */, |
|
301 JSObject* /* unused */); |
|
302 #endif // MOZ_MEDIA_NAVIGATOR |
|
303 |
|
304 static bool HasPushNotificationsSupport(JSContext* /* unused */, |
|
305 JSObject* aGlobal); |
|
306 |
|
307 static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal); |
|
308 |
|
309 static bool HasDataStoreSupport(JSContext* cx, JSObject* aGlobal); |
|
310 |
|
311 static bool HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal); |
|
312 |
|
313 static bool HasPermissionSettingsSupport(JSContext* aCx, JSObject* aGlobal); |
|
314 |
|
315 nsPIDOMWindow* GetParentObject() const |
|
316 { |
|
317 return GetWindow(); |
|
318 } |
|
319 |
|
320 virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE; |
|
321 |
|
322 private: |
|
323 bool CheckPermission(const char* type); |
|
324 static bool CheckPermission(nsPIDOMWindow* aWindow, const char* aType); |
|
325 // GetWindowFromGlobal returns the inner window for this global, if |
|
326 // any, else null. |
|
327 static already_AddRefed<nsPIDOMWindow> GetWindowFromGlobal(JSObject* aGlobal); |
|
328 |
|
329 nsRefPtr<nsMimeTypeArray> mMimeTypes; |
|
330 nsRefPtr<nsPluginArray> mPlugins; |
|
331 nsRefPtr<Geolocation> mGeolocation; |
|
332 nsRefPtr<DesktopNotificationCenter> mNotification; |
|
333 nsRefPtr<battery::BatteryManager> mBatteryManager; |
|
334 #ifdef MOZ_B2G_FM |
|
335 nsRefPtr<FMRadio> mFMRadio; |
|
336 #endif |
|
337 nsRefPtr<PowerManager> mPowerManager; |
|
338 nsRefPtr<MobileMessageManager> mMobileMessageManager; |
|
339 nsRefPtr<Telephony> mTelephony; |
|
340 nsRefPtr<network::Connection> mConnection; |
|
341 #ifdef MOZ_B2G_RIL |
|
342 nsRefPtr<MobileConnectionArray> mMobileConnections; |
|
343 nsRefPtr<CellBroadcast> mCellBroadcast; |
|
344 nsRefPtr<IccManager> mIccManager; |
|
345 nsRefPtr<Voicemail> mVoicemail; |
|
346 #endif |
|
347 #ifdef MOZ_B2G_BT |
|
348 nsRefPtr<bluetooth::BluetoothManager> mBluetooth; |
|
349 #endif |
|
350 #ifdef MOZ_AUDIO_CHANNEL_MANAGER |
|
351 nsRefPtr<system::AudioChannelManager> mAudioChannelManager; |
|
352 #endif |
|
353 nsRefPtr<nsDOMCameraManager> mCameraManager; |
|
354 nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager; |
|
355 nsTArray<nsRefPtr<nsDOMDeviceStorage> > mDeviceStorageStores; |
|
356 nsRefPtr<time::TimeManager> mTimeManager; |
|
357 nsCOMPtr<nsPIDOMWindow> mWindow; |
|
358 |
|
359 // Hashtable for saving cached objects newresolve created, so we don't create |
|
360 // the object twice if asked for it twice, whether due to use of "delete" or |
|
361 // due to Xrays. We could probably use a nsJSThingHashtable here, but then |
|
362 // we'd need to figure out exactly how to trace that, and that seems to be |
|
363 // rocket science. :( |
|
364 nsInterfaceHashtable<nsStringHashKey, nsISupports> mCachedResolveResults; |
|
365 }; |
|
366 |
|
367 } // namespace dom |
|
368 } // namespace mozilla |
|
369 |
|
370 nsresult NS_GetNavigatorUserAgent(nsAString& aUserAgent); |
|
371 |
|
372 #endif // mozilla_dom_Navigator_h |