michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_Navigator_h michael@0: #define mozilla_dom_Navigator_h michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/dom/Nullable.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "nsIDOMNavigator.h" michael@0: #include "nsIMozNavigatorNetwork.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsHashKeys.h" michael@0: #include "nsInterfaceHashtable.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: michael@0: class nsPluginArray; michael@0: class nsMimeTypeArray; michael@0: class nsPIDOMWindow; michael@0: class nsIDOMMozMobileMessageManager; michael@0: class nsIDOMNavigatorSystemMessages; michael@0: class nsDOMCameraManager; michael@0: class nsDOMDeviceStorage; michael@0: class nsIDOMBlob; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class Geolocation; michael@0: class systemMessageCallback; michael@0: class MediaStreamConstraints; michael@0: class WakeLock; michael@0: class ArrayBufferViewOrBlobOrStringOrFormData; michael@0: } michael@0: } michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: class nsIDOMMozIccManager; michael@0: #endif // MOZ_B2G_RIL michael@0: michael@0: //***************************************************************************** michael@0: // Navigator: Script "navigator" object michael@0: //***************************************************************************** michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: namespace battery { michael@0: class BatteryManager; michael@0: } // namespace battery michael@0: michael@0: #ifdef MOZ_B2G_FM michael@0: class FMRadio; michael@0: #endif michael@0: michael@0: class Promise; michael@0: michael@0: class DesktopNotificationCenter; michael@0: class MobileMessageManager; michael@0: class MozIdleObserver; michael@0: #ifdef MOZ_GAMEPAD michael@0: class Gamepad; michael@0: #endif // MOZ_GAMEPAD michael@0: #ifdef MOZ_MEDIA_NAVIGATOR michael@0: class NavigatorUserMediaSuccessCallback; michael@0: class NavigatorUserMediaErrorCallback; michael@0: class MozGetUserMediaDevicesSuccessCallback; michael@0: #endif // MOZ_MEDIA_NAVIGATOR michael@0: michael@0: namespace network { michael@0: class Connection; michael@0: } // namespace Connection; michael@0: michael@0: #ifdef MOZ_B2G_BT michael@0: namespace bluetooth { michael@0: class BluetoothManager; michael@0: } // namespace bluetooth michael@0: #endif // MOZ_B2G_BT michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: class CellBroadcast; michael@0: class IccManager; michael@0: class MobileConnectionArray; michael@0: class Voicemail; michael@0: #endif michael@0: michael@0: class PowerManager; michael@0: class Telephony; michael@0: michael@0: namespace time { michael@0: class TimeManager; michael@0: } // namespace time michael@0: michael@0: namespace system { michael@0: #ifdef MOZ_AUDIO_CHANNEL_MANAGER michael@0: class AudioChannelManager; michael@0: #endif michael@0: } // namespace system michael@0: michael@0: class Navigator : public nsIDOMNavigator michael@0: , public nsIMozNavigatorNetwork michael@0: , public nsWrapperCache michael@0: { michael@0: public: michael@0: Navigator(nsPIDOMWindow *aInnerWindow); michael@0: virtual ~Navigator(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Navigator, michael@0: nsIDOMNavigator) michael@0: NS_DECL_NSIDOMNAVIGATOR michael@0: NS_DECL_NSIMOZNAVIGATORNETWORK michael@0: michael@0: static void Init(); michael@0: michael@0: void Invalidate(); michael@0: nsPIDOMWindow *GetWindow() const michael@0: { michael@0: return mWindow; michael@0: } michael@0: michael@0: void RefreshMIMEArray(); michael@0: michael@0: static bool HasDesktopNotificationSupport(); michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: /** michael@0: * For use during document.write where our inner window changes. michael@0: */ michael@0: void SetWindow(nsPIDOMWindow *aInnerWindow); michael@0: michael@0: /** michael@0: * Called when the inner window navigates to a new page. michael@0: */ michael@0: void OnNavigation(); michael@0: michael@0: // Helper to initialize mMessagesManager. michael@0: nsresult EnsureMessagesManager(); michael@0: michael@0: // The XPCOM GetProduct is OK michael@0: // The XPCOM GetLanguage is OK michael@0: bool OnLine(); michael@0: void RegisterProtocolHandler(const nsAString& aScheme, const nsAString& aURL, michael@0: const nsAString& aTitle, ErrorResult& aRv); michael@0: void RegisterContentHandler(const nsAString& aMIMEType, const nsAString& aURL, michael@0: const nsAString& aTitle, ErrorResult& aRv); michael@0: nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv); michael@0: nsPluginArray* GetPlugins(ErrorResult& aRv); michael@0: // The XPCOM GetDoNotTrack is ok michael@0: Geolocation* GetGeolocation(ErrorResult& aRv); michael@0: battery::BatteryManager* GetBattery(ErrorResult& aRv); michael@0: michael@0: static void AppName(nsAString& aAppName, bool aUsePrefOverriddenValue); michael@0: michael@0: static nsresult GetPlatform(nsAString& aPlatform, michael@0: bool aUsePrefOverriddenValue); michael@0: michael@0: static nsresult GetAppVersion(nsAString& aAppVersion, michael@0: bool aUsePrefOverriddenValue); michael@0: michael@0: already_AddRefed GetDataStores(const nsAString &aName, michael@0: ErrorResult& aRv); michael@0: bool Vibrate(uint32_t aDuration); michael@0: bool Vibrate(const nsTArray& aDuration); michael@0: uint32_t MaxTouchPoints(); michael@0: void GetAppCodeName(nsString& aAppCodeName, ErrorResult& aRv) michael@0: { michael@0: aRv = GetAppCodeName(aAppCodeName); michael@0: } michael@0: void GetOscpu(nsString& aOscpu, ErrorResult& aRv) michael@0: { michael@0: aRv = GetOscpu(aOscpu); michael@0: } michael@0: // The XPCOM GetVendor is OK michael@0: // The XPCOM GetVendorSub is OK michael@0: // The XPCOM GetProductSub is OK michael@0: bool CookieEnabled(); michael@0: void GetBuildID(nsString& aBuildID, ErrorResult& aRv) michael@0: { michael@0: aRv = GetBuildID(aBuildID); michael@0: } michael@0: PowerManager* GetMozPower(ErrorResult& aRv); michael@0: bool JavaEnabled(ErrorResult& aRv); michael@0: bool TaintEnabled() michael@0: { michael@0: return false; michael@0: } michael@0: void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); michael@0: void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); michael@0: already_AddRefed RequestWakeLock(const nsAString &aTopic, michael@0: ErrorResult& aRv); michael@0: nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType, michael@0: ErrorResult& aRv); michael@0: void GetDeviceStorages(const nsAString& aType, michael@0: nsTArray >& aStores, michael@0: ErrorResult& aRv); michael@0: DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv); michael@0: bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline, michael@0: ErrorResult& aRv); michael@0: nsIDOMMozMobileMessageManager* GetMozMobileMessage(); michael@0: Telephony* GetMozTelephony(ErrorResult& aRv); michael@0: network::Connection* GetConnection(ErrorResult& aRv); michael@0: nsDOMCameraManager* GetMozCameras(ErrorResult& aRv); michael@0: void MozSetMessageHandler(const nsAString& aType, michael@0: systemMessageCallback* aCallback, michael@0: ErrorResult& aRv); michael@0: bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv); michael@0: #ifdef MOZ_B2G_RIL michael@0: MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv); michael@0: CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv); michael@0: Voicemail* GetMozVoicemail(ErrorResult& aRv); michael@0: IccManager* GetMozIccManager(ErrorResult& aRv); michael@0: #endif // MOZ_B2G_RIL michael@0: #ifdef MOZ_GAMEPAD michael@0: void GetGamepads(nsTArray >& aGamepads, ErrorResult& aRv); michael@0: #endif // MOZ_GAMEPAD michael@0: #ifdef MOZ_B2G_FM michael@0: FMRadio* GetMozFMRadio(ErrorResult& aRv); michael@0: #endif michael@0: #ifdef MOZ_B2G_BT michael@0: bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv); michael@0: #endif // MOZ_B2G_BT michael@0: #ifdef MOZ_TIME_MANAGER michael@0: time::TimeManager* GetMozTime(ErrorResult& aRv); michael@0: #endif // MOZ_TIME_MANAGER michael@0: #ifdef MOZ_AUDIO_CHANNEL_MANAGER michael@0: system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv); michael@0: #endif // MOZ_AUDIO_CHANNEL_MANAGER michael@0: michael@0: bool SendBeacon(const nsAString& aUrl, michael@0: const Nullable& aData, michael@0: ErrorResult& aRv); michael@0: michael@0: #ifdef MOZ_MEDIA_NAVIGATOR michael@0: void MozGetUserMedia(const MediaStreamConstraints& aConstraints, michael@0: NavigatorUserMediaSuccessCallback& aOnSuccess, michael@0: NavigatorUserMediaErrorCallback& aOnError, michael@0: ErrorResult& aRv); michael@0: void MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints, michael@0: MozGetUserMediaDevicesSuccessCallback& aOnSuccess, michael@0: NavigatorUserMediaErrorCallback& aOnError, michael@0: uint64_t aInnerWindowID, michael@0: ErrorResult& aRv); michael@0: #endif // MOZ_MEDIA_NAVIGATOR michael@0: bool DoNewResolve(JSContext* aCx, JS::Handle aObject, michael@0: JS::Handle aId, michael@0: JS::MutableHandle aDesc); michael@0: void GetOwnPropertyNames(JSContext* aCx, nsTArray& aNames, michael@0: ErrorResult& aRv); michael@0: michael@0: // WebIDL helper methods michael@0: static bool HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */); michael@0: static bool HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: static bool HasPhoneNumberSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: static bool HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */); michael@0: static bool HasDesktopNotificationSupport(JSContext* /* unused*/, michael@0: JSObject* /*unused */) michael@0: { michael@0: return HasDesktopNotificationSupport(); michael@0: } michael@0: static bool HasMobileMessageSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: static bool HasTelephonySupport(JSContext* cx, michael@0: JSObject* aGlobal); michael@0: static bool HasCameraSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: #ifdef MOZ_B2G_RIL michael@0: static bool HasMobileConnectionSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: static bool HasCellBroadcastSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: static bool HasVoicemailSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: static bool HasIccManagerSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: #endif // MOZ_B2G_RIL michael@0: static bool HasWifiManagerSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: #ifdef MOZ_B2G_BT michael@0: static bool HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: #endif // MOZ_B2G_BT michael@0: #ifdef MOZ_B2G_FM michael@0: static bool HasFMRadioSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: #endif // MOZ_B2G_FM michael@0: #ifdef MOZ_NFC michael@0: static bool HasNfcSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: static bool HasNfcPeerSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: static bool HasNfcManagerSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: #endif // MOZ_NFC michael@0: #ifdef MOZ_TIME_MANAGER michael@0: static bool HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: #endif // MOZ_TIME_MANAGER michael@0: #ifdef MOZ_MEDIA_NAVIGATOR michael@0: static bool HasUserMediaSupport(JSContext* /* unused */, michael@0: JSObject* /* unused */); michael@0: #endif // MOZ_MEDIA_NAVIGATOR michael@0: michael@0: static bool HasPushNotificationsSupport(JSContext* /* unused */, michael@0: JSObject* aGlobal); michael@0: michael@0: static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal); michael@0: michael@0: static bool HasDataStoreSupport(JSContext* cx, JSObject* aGlobal); michael@0: michael@0: static bool HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal); michael@0: michael@0: static bool HasPermissionSettingsSupport(JSContext* aCx, JSObject* aGlobal); michael@0: michael@0: nsPIDOMWindow* GetParentObject() const michael@0: { michael@0: return GetWindow(); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: bool CheckPermission(const char* type); michael@0: static bool CheckPermission(nsPIDOMWindow* aWindow, const char* aType); michael@0: // GetWindowFromGlobal returns the inner window for this global, if michael@0: // any, else null. michael@0: static already_AddRefed GetWindowFromGlobal(JSObject* aGlobal); michael@0: michael@0: nsRefPtr mMimeTypes; michael@0: nsRefPtr mPlugins; michael@0: nsRefPtr mGeolocation; michael@0: nsRefPtr mNotification; michael@0: nsRefPtr mBatteryManager; michael@0: #ifdef MOZ_B2G_FM michael@0: nsRefPtr mFMRadio; michael@0: #endif michael@0: nsRefPtr mPowerManager; michael@0: nsRefPtr mMobileMessageManager; michael@0: nsRefPtr mTelephony; michael@0: nsRefPtr mConnection; michael@0: #ifdef MOZ_B2G_RIL michael@0: nsRefPtr mMobileConnections; michael@0: nsRefPtr mCellBroadcast; michael@0: nsRefPtr mIccManager; michael@0: nsRefPtr mVoicemail; michael@0: #endif michael@0: #ifdef MOZ_B2G_BT michael@0: nsRefPtr mBluetooth; michael@0: #endif michael@0: #ifdef MOZ_AUDIO_CHANNEL_MANAGER michael@0: nsRefPtr mAudioChannelManager; michael@0: #endif michael@0: nsRefPtr mCameraManager; michael@0: nsCOMPtr mMessagesManager; michael@0: nsTArray > mDeviceStorageStores; michael@0: nsRefPtr mTimeManager; michael@0: nsCOMPtr mWindow; michael@0: michael@0: // Hashtable for saving cached objects newresolve created, so we don't create michael@0: // the object twice if asked for it twice, whether due to use of "delete" or michael@0: // due to Xrays. We could probably use a nsJSThingHashtable here, but then michael@0: // we'd need to figure out exactly how to trace that, and that seems to be michael@0: // rocket science. :( michael@0: nsInterfaceHashtable mCachedResolveResults; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: nsresult NS_GetNavigatorUserAgent(nsAString& aUserAgent); michael@0: michael@0: #endif // mozilla_dom_Navigator_h