1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/Navigator.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,372 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_Navigator_h 1.11 +#define mozilla_dom_Navigator_h 1.12 + 1.13 +#include "mozilla/MemoryReporting.h" 1.14 +#include "mozilla/dom/Nullable.h" 1.15 +#include "mozilla/ErrorResult.h" 1.16 +#include "nsIDOMNavigator.h" 1.17 +#include "nsIMozNavigatorNetwork.h" 1.18 +#include "nsAutoPtr.h" 1.19 +#include "nsWrapperCache.h" 1.20 +#include "nsHashKeys.h" 1.21 +#include "nsInterfaceHashtable.h" 1.22 +#include "nsString.h" 1.23 +#include "nsTArray.h" 1.24 + 1.25 +class nsPluginArray; 1.26 +class nsMimeTypeArray; 1.27 +class nsPIDOMWindow; 1.28 +class nsIDOMMozMobileMessageManager; 1.29 +class nsIDOMNavigatorSystemMessages; 1.30 +class nsDOMCameraManager; 1.31 +class nsDOMDeviceStorage; 1.32 +class nsIDOMBlob; 1.33 + 1.34 +namespace mozilla { 1.35 +namespace dom { 1.36 +class Geolocation; 1.37 +class systemMessageCallback; 1.38 +class MediaStreamConstraints; 1.39 +class WakeLock; 1.40 +class ArrayBufferViewOrBlobOrStringOrFormData; 1.41 +} 1.42 +} 1.43 + 1.44 +#ifdef MOZ_B2G_RIL 1.45 +class nsIDOMMozIccManager; 1.46 +#endif // MOZ_B2G_RIL 1.47 + 1.48 +//***************************************************************************** 1.49 +// Navigator: Script "navigator" object 1.50 +//***************************************************************************** 1.51 + 1.52 +namespace mozilla { 1.53 +namespace dom { 1.54 + 1.55 +namespace battery { 1.56 +class BatteryManager; 1.57 +} // namespace battery 1.58 + 1.59 +#ifdef MOZ_B2G_FM 1.60 +class FMRadio; 1.61 +#endif 1.62 + 1.63 +class Promise; 1.64 + 1.65 +class DesktopNotificationCenter; 1.66 +class MobileMessageManager; 1.67 +class MozIdleObserver; 1.68 +#ifdef MOZ_GAMEPAD 1.69 +class Gamepad; 1.70 +#endif // MOZ_GAMEPAD 1.71 +#ifdef MOZ_MEDIA_NAVIGATOR 1.72 +class NavigatorUserMediaSuccessCallback; 1.73 +class NavigatorUserMediaErrorCallback; 1.74 +class MozGetUserMediaDevicesSuccessCallback; 1.75 +#endif // MOZ_MEDIA_NAVIGATOR 1.76 + 1.77 +namespace network { 1.78 +class Connection; 1.79 +} // namespace Connection; 1.80 + 1.81 +#ifdef MOZ_B2G_BT 1.82 +namespace bluetooth { 1.83 +class BluetoothManager; 1.84 +} // namespace bluetooth 1.85 +#endif // MOZ_B2G_BT 1.86 + 1.87 +#ifdef MOZ_B2G_RIL 1.88 +class CellBroadcast; 1.89 +class IccManager; 1.90 +class MobileConnectionArray; 1.91 +class Voicemail; 1.92 +#endif 1.93 + 1.94 +class PowerManager; 1.95 +class Telephony; 1.96 + 1.97 +namespace time { 1.98 +class TimeManager; 1.99 +} // namespace time 1.100 + 1.101 +namespace system { 1.102 +#ifdef MOZ_AUDIO_CHANNEL_MANAGER 1.103 +class AudioChannelManager; 1.104 +#endif 1.105 +} // namespace system 1.106 + 1.107 +class Navigator : public nsIDOMNavigator 1.108 + , public nsIMozNavigatorNetwork 1.109 + , public nsWrapperCache 1.110 +{ 1.111 +public: 1.112 + Navigator(nsPIDOMWindow *aInnerWindow); 1.113 + virtual ~Navigator(); 1.114 + 1.115 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.116 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator, 1.117 + nsIDOMNavigator) 1.118 + NS_DECL_NSIDOMNAVIGATOR 1.119 + NS_DECL_NSIMOZNAVIGATORNETWORK 1.120 + 1.121 + static void Init(); 1.122 + 1.123 + void Invalidate(); 1.124 + nsPIDOMWindow *GetWindow() const 1.125 + { 1.126 + return mWindow; 1.127 + } 1.128 + 1.129 + void RefreshMIMEArray(); 1.130 + 1.131 + static bool HasDesktopNotificationSupport(); 1.132 + 1.133 + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 1.134 + 1.135 + /** 1.136 + * For use during document.write where our inner window changes. 1.137 + */ 1.138 + void SetWindow(nsPIDOMWindow *aInnerWindow); 1.139 + 1.140 + /** 1.141 + * Called when the inner window navigates to a new page. 1.142 + */ 1.143 + void OnNavigation(); 1.144 + 1.145 + // Helper to initialize mMessagesManager. 1.146 + nsresult EnsureMessagesManager(); 1.147 + 1.148 + // The XPCOM GetProduct is OK 1.149 + // The XPCOM GetLanguage is OK 1.150 + bool OnLine(); 1.151 + void RegisterProtocolHandler(const nsAString& aScheme, const nsAString& aURL, 1.152 + const nsAString& aTitle, ErrorResult& aRv); 1.153 + void RegisterContentHandler(const nsAString& aMIMEType, const nsAString& aURL, 1.154 + const nsAString& aTitle, ErrorResult& aRv); 1.155 + nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv); 1.156 + nsPluginArray* GetPlugins(ErrorResult& aRv); 1.157 + // The XPCOM GetDoNotTrack is ok 1.158 + Geolocation* GetGeolocation(ErrorResult& aRv); 1.159 + battery::BatteryManager* GetBattery(ErrorResult& aRv); 1.160 + 1.161 + static void AppName(nsAString& aAppName, bool aUsePrefOverriddenValue); 1.162 + 1.163 + static nsresult GetPlatform(nsAString& aPlatform, 1.164 + bool aUsePrefOverriddenValue); 1.165 + 1.166 + static nsresult GetAppVersion(nsAString& aAppVersion, 1.167 + bool aUsePrefOverriddenValue); 1.168 + 1.169 + already_AddRefed<Promise> GetDataStores(const nsAString &aName, 1.170 + ErrorResult& aRv); 1.171 + bool Vibrate(uint32_t aDuration); 1.172 + bool Vibrate(const nsTArray<uint32_t>& aDuration); 1.173 + uint32_t MaxTouchPoints(); 1.174 + void GetAppCodeName(nsString& aAppCodeName, ErrorResult& aRv) 1.175 + { 1.176 + aRv = GetAppCodeName(aAppCodeName); 1.177 + } 1.178 + void GetOscpu(nsString& aOscpu, ErrorResult& aRv) 1.179 + { 1.180 + aRv = GetOscpu(aOscpu); 1.181 + } 1.182 + // The XPCOM GetVendor is OK 1.183 + // The XPCOM GetVendorSub is OK 1.184 + // The XPCOM GetProductSub is OK 1.185 + bool CookieEnabled(); 1.186 + void GetBuildID(nsString& aBuildID, ErrorResult& aRv) 1.187 + { 1.188 + aRv = GetBuildID(aBuildID); 1.189 + } 1.190 + PowerManager* GetMozPower(ErrorResult& aRv); 1.191 + bool JavaEnabled(ErrorResult& aRv); 1.192 + bool TaintEnabled() 1.193 + { 1.194 + return false; 1.195 + } 1.196 + void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); 1.197 + void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); 1.198 + already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic, 1.199 + ErrorResult& aRv); 1.200 + nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType, 1.201 + ErrorResult& aRv); 1.202 + void GetDeviceStorages(const nsAString& aType, 1.203 + nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores, 1.204 + ErrorResult& aRv); 1.205 + DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv); 1.206 + bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline, 1.207 + ErrorResult& aRv); 1.208 + nsIDOMMozMobileMessageManager* GetMozMobileMessage(); 1.209 + Telephony* GetMozTelephony(ErrorResult& aRv); 1.210 + network::Connection* GetConnection(ErrorResult& aRv); 1.211 + nsDOMCameraManager* GetMozCameras(ErrorResult& aRv); 1.212 + void MozSetMessageHandler(const nsAString& aType, 1.213 + systemMessageCallback* aCallback, 1.214 + ErrorResult& aRv); 1.215 + bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv); 1.216 +#ifdef MOZ_B2G_RIL 1.217 + MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv); 1.218 + CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv); 1.219 + Voicemail* GetMozVoicemail(ErrorResult& aRv); 1.220 + IccManager* GetMozIccManager(ErrorResult& aRv); 1.221 +#endif // MOZ_B2G_RIL 1.222 +#ifdef MOZ_GAMEPAD 1.223 + void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv); 1.224 +#endif // MOZ_GAMEPAD 1.225 +#ifdef MOZ_B2G_FM 1.226 + FMRadio* GetMozFMRadio(ErrorResult& aRv); 1.227 +#endif 1.228 +#ifdef MOZ_B2G_BT 1.229 + bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv); 1.230 +#endif // MOZ_B2G_BT 1.231 +#ifdef MOZ_TIME_MANAGER 1.232 + time::TimeManager* GetMozTime(ErrorResult& aRv); 1.233 +#endif // MOZ_TIME_MANAGER 1.234 +#ifdef MOZ_AUDIO_CHANNEL_MANAGER 1.235 + system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv); 1.236 +#endif // MOZ_AUDIO_CHANNEL_MANAGER 1.237 + 1.238 + bool SendBeacon(const nsAString& aUrl, 1.239 + const Nullable<ArrayBufferViewOrBlobOrStringOrFormData>& aData, 1.240 + ErrorResult& aRv); 1.241 + 1.242 +#ifdef MOZ_MEDIA_NAVIGATOR 1.243 + void MozGetUserMedia(const MediaStreamConstraints& aConstraints, 1.244 + NavigatorUserMediaSuccessCallback& aOnSuccess, 1.245 + NavigatorUserMediaErrorCallback& aOnError, 1.246 + ErrorResult& aRv); 1.247 + void MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints, 1.248 + MozGetUserMediaDevicesSuccessCallback& aOnSuccess, 1.249 + NavigatorUserMediaErrorCallback& aOnError, 1.250 + uint64_t aInnerWindowID, 1.251 + ErrorResult& aRv); 1.252 +#endif // MOZ_MEDIA_NAVIGATOR 1.253 + bool DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject, 1.254 + JS::Handle<jsid> aId, 1.255 + JS::MutableHandle<JSPropertyDescriptor> aDesc); 1.256 + void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames, 1.257 + ErrorResult& aRv); 1.258 + 1.259 + // WebIDL helper methods 1.260 + static bool HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */); 1.261 + static bool HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal); 1.262 + static bool HasPhoneNumberSupport(JSContext* /* unused */, JSObject* aGlobal); 1.263 + static bool HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal); 1.264 + static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */); 1.265 + static bool HasDesktopNotificationSupport(JSContext* /* unused*/, 1.266 + JSObject* /*unused */) 1.267 + { 1.268 + return HasDesktopNotificationSupport(); 1.269 + } 1.270 + static bool HasMobileMessageSupport(JSContext* /* unused */, 1.271 + JSObject* aGlobal); 1.272 + static bool HasTelephonySupport(JSContext* cx, 1.273 + JSObject* aGlobal); 1.274 + static bool HasCameraSupport(JSContext* /* unused */, 1.275 + JSObject* aGlobal); 1.276 +#ifdef MOZ_B2G_RIL 1.277 + static bool HasMobileConnectionSupport(JSContext* /* unused */, 1.278 + JSObject* aGlobal); 1.279 + static bool HasCellBroadcastSupport(JSContext* /* unused */, 1.280 + JSObject* aGlobal); 1.281 + static bool HasVoicemailSupport(JSContext* /* unused */, 1.282 + JSObject* aGlobal); 1.283 + static bool HasIccManagerSupport(JSContext* /* unused */, 1.284 + JSObject* aGlobal); 1.285 +#endif // MOZ_B2G_RIL 1.286 + static bool HasWifiManagerSupport(JSContext* /* unused */, 1.287 + JSObject* aGlobal); 1.288 +#ifdef MOZ_B2G_BT 1.289 + static bool HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal); 1.290 +#endif // MOZ_B2G_BT 1.291 +#ifdef MOZ_B2G_FM 1.292 + static bool HasFMRadioSupport(JSContext* /* unused */, JSObject* aGlobal); 1.293 +#endif // MOZ_B2G_FM 1.294 +#ifdef MOZ_NFC 1.295 + static bool HasNfcSupport(JSContext* /* unused */, JSObject* aGlobal); 1.296 + static bool HasNfcPeerSupport(JSContext* /* unused */, JSObject* aGlobal); 1.297 + static bool HasNfcManagerSupport(JSContext* /* unused */, JSObject* aGlobal); 1.298 +#endif // MOZ_NFC 1.299 +#ifdef MOZ_TIME_MANAGER 1.300 + static bool HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal); 1.301 +#endif // MOZ_TIME_MANAGER 1.302 +#ifdef MOZ_MEDIA_NAVIGATOR 1.303 + static bool HasUserMediaSupport(JSContext* /* unused */, 1.304 + JSObject* /* unused */); 1.305 +#endif // MOZ_MEDIA_NAVIGATOR 1.306 + 1.307 + static bool HasPushNotificationsSupport(JSContext* /* unused */, 1.308 + JSObject* aGlobal); 1.309 + 1.310 + static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal); 1.311 + 1.312 + static bool HasDataStoreSupport(JSContext* cx, JSObject* aGlobal); 1.313 + 1.314 + static bool HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal); 1.315 + 1.316 + static bool HasPermissionSettingsSupport(JSContext* aCx, JSObject* aGlobal); 1.317 + 1.318 + nsPIDOMWindow* GetParentObject() const 1.319 + { 1.320 + return GetWindow(); 1.321 + } 1.322 + 1.323 + virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE; 1.324 + 1.325 +private: 1.326 + bool CheckPermission(const char* type); 1.327 + static bool CheckPermission(nsPIDOMWindow* aWindow, const char* aType); 1.328 + // GetWindowFromGlobal returns the inner window for this global, if 1.329 + // any, else null. 1.330 + static already_AddRefed<nsPIDOMWindow> GetWindowFromGlobal(JSObject* aGlobal); 1.331 + 1.332 + nsRefPtr<nsMimeTypeArray> mMimeTypes; 1.333 + nsRefPtr<nsPluginArray> mPlugins; 1.334 + nsRefPtr<Geolocation> mGeolocation; 1.335 + nsRefPtr<DesktopNotificationCenter> mNotification; 1.336 + nsRefPtr<battery::BatteryManager> mBatteryManager; 1.337 +#ifdef MOZ_B2G_FM 1.338 + nsRefPtr<FMRadio> mFMRadio; 1.339 +#endif 1.340 + nsRefPtr<PowerManager> mPowerManager; 1.341 + nsRefPtr<MobileMessageManager> mMobileMessageManager; 1.342 + nsRefPtr<Telephony> mTelephony; 1.343 + nsRefPtr<network::Connection> mConnection; 1.344 +#ifdef MOZ_B2G_RIL 1.345 + nsRefPtr<MobileConnectionArray> mMobileConnections; 1.346 + nsRefPtr<CellBroadcast> mCellBroadcast; 1.347 + nsRefPtr<IccManager> mIccManager; 1.348 + nsRefPtr<Voicemail> mVoicemail; 1.349 +#endif 1.350 +#ifdef MOZ_B2G_BT 1.351 + nsRefPtr<bluetooth::BluetoothManager> mBluetooth; 1.352 +#endif 1.353 +#ifdef MOZ_AUDIO_CHANNEL_MANAGER 1.354 + nsRefPtr<system::AudioChannelManager> mAudioChannelManager; 1.355 +#endif 1.356 + nsRefPtr<nsDOMCameraManager> mCameraManager; 1.357 + nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager; 1.358 + nsTArray<nsRefPtr<nsDOMDeviceStorage> > mDeviceStorageStores; 1.359 + nsRefPtr<time::TimeManager> mTimeManager; 1.360 + nsCOMPtr<nsPIDOMWindow> mWindow; 1.361 + 1.362 + // Hashtable for saving cached objects newresolve created, so we don't create 1.363 + // the object twice if asked for it twice, whether due to use of "delete" or 1.364 + // due to Xrays. We could probably use a nsJSThingHashtable here, but then 1.365 + // we'd need to figure out exactly how to trace that, and that seems to be 1.366 + // rocket science. :( 1.367 + nsInterfaceHashtable<nsStringHashKey, nsISupports> mCachedResolveResults; 1.368 +}; 1.369 + 1.370 +} // namespace dom 1.371 +} // namespace mozilla 1.372 + 1.373 +nsresult NS_GetNavigatorUserAgent(nsAString& aUserAgent); 1.374 + 1.375 +#endif // mozilla_dom_Navigator_h