From c618a3cb48ab3f5d8fffff24c5ac7c6485c41364 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Fri, 12 Jul 2013 18:15:10 -0400 Subject: [PATCH] Backed out 9 changesets (bug 838146) for suspected B2G Mn orange on a CLOSED TREE. Backed out changeset 955a14e3c181 (bug 838146) Backed out changeset fddccc5fce6e (bug 838146) Backed out changeset 7cddfebc261c (bug 838146) Backed out changeset fd3a62dd3910 (bug 838146) Backed out changeset f06b420e0dfa (bug 838146) Backed out changeset e0c3d84965cf (bug 838146) Backed out changeset d3b135e58350 (bug 838146) Backed out changeset 1bc7f2167503 (bug 838146) Backed out changeset 483fbc6878a8 (bug 838146) --- dom/base/Navigator.cpp | 1156 ++++------------- dom/base/Navigator.h | 194 +-- dom/base/nsDOMClassInfo.cpp | 98 +- dom/bindings/Bindings.conf | 13 - dom/bindings/Codegen.py | 2 +- dom/bindings/Makefile.in | 19 +- dom/bluetooth/BluetoothManager.cpp | 19 +- dom/bluetooth/BluetoothManager.h | 7 +- dom/camera/DOMCameraManager.cpp | 16 +- dom/camera/DOMCameraManager.h | 3 +- dom/media/MediaManager.cpp | 6 +- dom/media/tests/crashtests/802982.html | 2 +- .../test_getUserMedia_exceptions.html | 14 +- dom/mobilemessage/src/SmsManager.cpp | 24 +- dom/mobilemessage/src/SmsManager.h | 5 +- dom/mobilemessage/tests/test_sms_basics.html | 5 +- dom/power/PowerManager.cpp | 20 +- dom/power/PowerManager.h | 5 +- dom/telephony/Telephony.cpp | 64 +- dom/telephony/Telephony.h | 7 +- dom/telephony/TelephonyFactory.h | 18 + .../general/test_idleapi_permissions.html | 25 +- .../mochitest/general/test_vibrator.html | 8 +- dom/webidl/Navigator.webidl | 353 ----- dom/webidl/WebIDL.mk | 4 - dom/workers/RuntimeService.cpp | 4 +- dom/workers/test/test_navigator.html | 3 +- js/xpconnect/tests/chrome/test_weakmaps.xul | 12 +- .../file_crosscompartment_weakmap.html | 1 - .../test_crosscompartment_weakmap.html | 8 +- 30 files changed, 443 insertions(+), 1672 deletions(-) create mode 100644 dom/telephony/TelephonyFactory.h delete mode 100644 dom/webidl/Navigator.webidl diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 61e7c4209851..ab23388b2858 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -58,7 +58,7 @@ #include "MediaManager.h" #endif #ifdef MOZ_B2G_RIL -#include "Telephony.h" +#include "TelephonyFactory.h" #endif #ifdef MOZ_B2G_BT #include "nsIDOMBluetoothManager.h" @@ -72,11 +72,6 @@ #endif #include "nsIDOMGlobalPropertyInitializer.h" -#include "nsJSUtils.h" - -#include "nsScriptNameSpaceManager.h" - -#include "mozilla/dom/NavigatorBinding.h" using namespace mozilla::dom::power; @@ -111,7 +106,6 @@ Navigator::Navigator(nsPIDOMWindow* aWindow) { NS_ASSERTION(aWindow->IsInnerWindow(), "Navigator must get an inner window!"); - SetIsDOMBinding(); } Navigator::~Navigator() @@ -368,8 +362,7 @@ Navigator::GetAppVersion(nsAString& aAppVersion) NS_IMETHODIMP Navigator::GetAppName(nsAString& aAppName) { - NS_GetNavigatorAppName(aAppName); - return NS_OK; + return NS_GetNavigatorAppName(aAppName); } /** @@ -491,49 +484,31 @@ Navigator::GetProductSub(nsAString& aProductSub) NS_IMETHODIMP Navigator::GetMimeTypes(nsISupports** aMimeTypes) -{ - ErrorResult rv; - NS_IF_ADDREF(*aMimeTypes = GetMimeTypes(rv)); - return rv.ErrorCode(); -} - -nsMimeTypeArray* -Navigator::GetMimeTypes(ErrorResult& aRv) { if (!mMimeTypes) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + NS_ENSURE_STATE(mWindow); nsWeakPtr win = do_GetWeakReference(mWindow); mMimeTypes = new nsMimeTypeArray(win); } - return mMimeTypes; + NS_ADDREF(*aMimeTypes = mMimeTypes); + + return NS_OK; } NS_IMETHODIMP Navigator::GetPlugins(nsISupports** aPlugins) -{ - ErrorResult rv; - NS_IF_ADDREF(*aPlugins = static_cast(GetPlugins(rv))); - return rv.ErrorCode(); -} - -nsPluginArray* -Navigator::GetPlugins(ErrorResult& aRv) { if (!mPlugins) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + NS_ENSURE_STATE(mWindow); nsWeakPtr win = do_GetWeakReference(mWindow); mPlugins = new nsPluginArray(win); mPlugins->Init(); } - return mPlugins; + NS_ADDREF(*aPlugins = static_cast(mPlugins.get())); + + return NS_OK; } // Values for the network.cookie.cookieBehavior pref are documented in @@ -543,14 +518,7 @@ Navigator::GetPlugins(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetCookieEnabled(bool* aCookieEnabled) { - *aCookieEnabled = CookieEnabled(); - return NS_OK; -} - -bool -Navigator::CookieEnabled() -{ - bool cookieEnabled = + *aCookieEnabled = (Preferences::GetInt("network.cookie.cookieBehavior", COOKIE_BEHAVIOR_REJECT) != COOKIE_BEHAVIOR_REJECT); @@ -558,12 +526,12 @@ Navigator::CookieEnabled() // Note that the code for getting the URI here matches that in // nsHTMLDocument::SetCookie. if (!mWindow || !mWindow->GetDocShell()) { - return cookieEnabled; + return NS_OK; } nsCOMPtr doc = mWindow->GetExtantDoc(); if (!doc) { - return cookieEnabled; + return NS_OK; } nsCOMPtr codebaseURI; @@ -572,23 +540,23 @@ Navigator::CookieEnabled() if (!codebaseURI) { // Not a codebase, so technically can't set cookies, but let's // just return the default value. - return cookieEnabled; + return NS_OK; } nsCOMPtr permMgr = do_GetService(NS_COOKIEPERMISSION_CONTRACTID); - NS_ENSURE_TRUE(permMgr, cookieEnabled); + NS_ENSURE_TRUE(permMgr, NS_OK); // Pass null for the channel, just like the cookie service does. nsCookieAccess access; nsresult rv = permMgr->CanAccess(codebaseURI, nullptr, &access); - NS_ENSURE_SUCCESS(rv, cookieEnabled); + NS_ENSURE_SUCCESS(rv, NS_OK); if (access != nsICookiePermission::ACCESS_DEFAULT) { - cookieEnabled = access != nsICookiePermission::ACCESS_DENY; + *aCookieEnabled = access != nsICookiePermission::ACCESS_DENY; } - return cookieEnabled; + return NS_OK; } NS_IMETHODIMP @@ -596,16 +564,10 @@ Navigator::GetOnLine(bool* aOnline) { NS_PRECONDITION(aOnline, "Null out param"); - *aOnline = OnLine(); + *aOnline = !NS_IsOffline(); return NS_OK; } -bool -Navigator::OnLine() -{ - return !NS_IsOffline(); -} - NS_IMETHODIMP Navigator::GetBuildID(nsAString& aBuildID) { @@ -650,23 +612,14 @@ Navigator::GetDoNotTrack(nsAString &aResult) NS_IMETHODIMP Navigator::JavaEnabled(bool* aReturn) -{ - ErrorResult rv; - *aReturn = JavaEnabled(rv); - return rv.ErrorCode(); -} - -bool -Navigator::JavaEnabled(ErrorResult& aRv) { Telemetry::AutoTimer telemetryTimer; // Return true if we have a handler for "application/x-java-vm", // otherwise return false. + *aReturn = false; + if (!mMimeTypes) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return false; - } + NS_ENSURE_STATE(mWindow); nsWeakPtr win = do_GetWeakReference(mWindow); mMimeTypes = new nsMimeTypeArray(win); } @@ -676,13 +629,15 @@ Navigator::JavaEnabled(ErrorResult& aRv) nsMimeType *mimeType = mMimeTypes->NamedItem(NS_LITERAL_STRING("application/x-java-vm")); - return mimeType && mimeType->GetEnabledPlugin(); + *aReturn = mimeType && mimeType->GetEnabledPlugin(); + + return NS_OK; } NS_IMETHODIMP Navigator::TaintEnabled(bool *aReturn) { - *aReturn = TaintEnabled(); + *aReturn = false; return NS_OK; } @@ -800,30 +755,11 @@ Navigator::AddIdleObserver(nsIIdleObserver* aIdleObserver) return NS_ERROR_DOM_SECURITY_ERR; } - AddIdleObserver(*aIdleObserver); - return NS_OK; -} - -void -Navigator::AddIdleObserver(nsIIdleObserver& aIdleObserver) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. - if (NS_FAILED(mWindow->RegisterIdleObserver(&aIdleObserver))) { + if (NS_FAILED(mWindow->RegisterIdleObserver(aIdleObserver))) { NS_WARNING("Failed to add idle observer."); } -} -void -Navigator::AddIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv) -{ - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return; - } - CallbackObjectHolder holder(&aIdleObserver); - nsCOMPtr obs = holder.ToXPCOMCallback(); - return AddIdleObserver(*obs); + return NS_OK; } NS_IMETHODIMP @@ -838,35 +774,24 @@ Navigator::RemoveIdleObserver(nsIIdleObserver* aIdleObserver) NS_ENSURE_ARG_POINTER(aIdleObserver); - RemoveIdleObserver(*aIdleObserver); - return NS_OK; -} - -void -Navigator::RemoveIdleObserver(nsIIdleObserver& aIdleObserver) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. - if (NS_FAILED(mWindow->UnregisterIdleObserver(&aIdleObserver))) { + if (NS_FAILED(mWindow->UnregisterIdleObserver(aIdleObserver))) { NS_WARNING("Failed to remove idle observer."); } -} - -void -Navigator::RemoveIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv) -{ - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return; - } - CallbackObjectHolder holder(&aIdleObserver); - nsCOMPtr obs = holder.ToXPCOMCallback(); - return RemoveIdleObserver(*obs); + return NS_OK; } NS_IMETHODIMP Navigator::Vibrate(const JS::Value& aPattern, JSContext* cx) { + NS_ENSURE_STATE(mWindow); + + nsCOMPtr doc = mWindow->GetExtantDoc(); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + if (doc->Hidden()) { + // Hidden documents cannot start or stop a vibration. + return NS_OK; + } + nsAutoTArray pattern; // null or undefined pattern is an error. @@ -904,54 +829,10 @@ Navigator::Vibrate(const JS::Value& aPattern, JSContext* cx) } } - ErrorResult rv; - Vibrate(pattern, rv); - return rv.ErrorCode(); -} - -void -Navigator::Vibrate(uint32_t aDuration, ErrorResult& aRv) -{ - nsAutoTArray pattern; - pattern.AppendElement(aDuration); - Vibrate(pattern, aRv); -} - -void -Navigator::Vibrate(const nsTArray& aPattern, ErrorResult& aRv) -{ - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return; - } - nsCOMPtr doc = mWindow->GetExtantDoc(); - if (!doc) { - aRv.Throw(NS_ERROR_FAILURE); - return; - } - if (doc->Hidden()) { - // Hidden documents cannot start or stop a vibration. - return; - } - - if (aPattern.Length() > sMaxVibrateListLen) { - // XXXbz this should be returning false instead - aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - - for (size_t i = 0; i < aPattern.Length(); ++i) { - if (aPattern[i] > sMaxVibrateMS) { - // XXXbz this should be returning false instead - aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - } - // The spec says we check sVibratorEnabled after we've done the sanity // checking on the pattern. if (!sVibratorEnabled) { - return; + return NS_OK; } // Add a listener to cancel the vibration if the document becomes hidden, @@ -968,7 +849,8 @@ Navigator::Vibrate(const nsTArray& aPattern, ErrorResult& aRv) } gVibrateWindowListener = new VibrateWindowListener(mWindow, doc); - hal::Vibrate(aPattern, mWindow); + hal::Vibrate(pattern, mWindow); + return NS_OK; } //***************************************************************************** @@ -1102,19 +984,8 @@ NS_IMETHODIMP Navigator::GetDeviceStorage(const nsAString &aType, nsIDOMDeviceSt return NS_OK; } - ErrorResult rv; - NS_IF_ADDREF(*_retval = GetDeviceStorage(aType, rv)); - return rv.ErrorCode(); -} - -nsDOMDeviceStorage* -Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the pref check here. if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; + return NS_ERROR_FAILURE; } nsRefPtr storage; @@ -1122,11 +993,12 @@ Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv) getter_AddRefs(storage)); if (!storage) { - return nullptr; + return NS_OK; } + NS_ADDREF(*_retval = storage.get()); mDeviceStorageStores.AppendElement(storage); - return storage; + return NS_OK; } NS_IMETHODIMP Navigator::GetDeviceStorages(const nsAString &aType, nsIVariant** _retval) @@ -1138,13 +1010,13 @@ NS_IMETHODIMP Navigator::GetDeviceStorages(const nsAString &aType, nsIVariant** return NS_OK; } - nsTArray > stores; - ErrorResult rv; - GetDeviceStorages(aType, stores, rv); - if (rv.Failed()) { - return rv.ErrorCode(); + if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) { + return NS_ERROR_FAILURE; } + nsTArray > stores; + nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, stores, false); + nsCOMPtr result = do_CreateInstance("@mozilla.org/variant;1"); NS_ENSURE_TRUE(result, NS_ERROR_FAILURE); @@ -1158,61 +1030,44 @@ NS_IMETHODIMP Navigator::GetDeviceStorages(const nsAString &aType, nsIVariant** } result.forget(_retval); + mDeviceStorageStores.AppendElements(stores); return NS_OK; } -void -Navigator::GetDeviceStorages(const nsAString& aType, - nsTArray >& aStores, - ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the pref check here. - if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) { - aRv.Throw(NS_ERROR_FAILURE); - return; - } - - nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores, false); - - mDeviceStorageStores.AppendElements(aStores); -} - //***************************************************************************** // Navigator::nsIDOMNavigatorGeolocation //***************************************************************************** NS_IMETHODIMP Navigator::GetGeolocation(nsIDOMGeoGeolocation** _retval) { - ErrorResult rv; - NS_IF_ADDREF(*_retval = GetGeolocation(rv)); - return rv.ErrorCode(); -} + NS_ENSURE_ARG_POINTER(_retval); + *_retval = nullptr; -Geolocation* -Navigator::GetGeolocation(ErrorResult& aRv) -{ if (!Preferences::GetBool("geo.enabled", true)) { - return nullptr; + return NS_OK; } if (mGeolocation) { - return mGeolocation; + NS_ADDREF(*_retval = mGeolocation); + return NS_OK; } if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; + return NS_ERROR_FAILURE; } mGeolocation = new Geolocation(); - if (NS_FAILED(mGeolocation->Init(mWindow->GetOuterWindow()))) { - mGeolocation = nullptr; - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; + if (!mGeolocation) { + return NS_ERROR_FAILURE; } - return mGeolocation; + if (NS_FAILED(mGeolocation->Init(mWindow->GetOuterWindow()))) { + mGeolocation = nullptr; + return NS_ERROR_FAILURE; + } + + NS_ADDREF(*_retval = mGeolocation); + return NS_OK; } //***************************************************************************** @@ -1230,48 +1085,16 @@ Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams, return NS_OK; } - ErrorResult rv; - MozGetUserMedia(aParams, aOnSuccess, aOnError, rv); - return rv.ErrorCode(); -} - -void -Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams, - MozDOMGetUserMediaSuccessCallback* aOnSuccess, - MozDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv) -{ - CallbackObjectHolder holder1(aOnSuccess); - nsCOMPtr onsucces = - holder1.ToXPCOMCallback(); - - CallbackObjectHolder holder2(aOnError); - nsCOMPtr onerror = holder2.ToXPCOMCallback(); - - MozGetUserMedia(aParams, onsucces, onerror, aRv); -} - -void -Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams, - nsIDOMGetUserMediaSuccessCallback* aOnSuccess, - nsIDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the pref check here. if (!mWindow || !mWindow->GetOuterWindow() || mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) { - aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return; + return NS_ERROR_NOT_AVAILABLE; } bool privileged = nsContentUtils::IsChromeDoc(mWindow->GetExtantDoc()); MediaManager* manager = MediaManager::Get(); - aRv = manager->GetUserMedia(privileged, mWindow, aParams, aOnSuccess, - aOnError); + return manager->GetUserMedia(privileged, mWindow, aParams, aOnSuccess, + aOnError); } //***************************************************************************** @@ -1281,48 +1104,18 @@ NS_IMETHODIMP Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess, nsIDOMGetUserMediaErrorCallback* aOnError) { + if (!mWindow || !mWindow->GetOuterWindow() || + mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) { + return NS_ERROR_NOT_AVAILABLE; + } + // Check if the caller is chrome privileged, bail if not if (!nsContentUtils::IsCallerChrome()) { return NS_ERROR_FAILURE; } - ErrorResult rv; - MozGetUserMediaDevices(aOnSuccess, aOnError, rv); - return rv.ErrorCode(); -} - -void -Navigator::MozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback* aOnSuccess, - MozDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv) -{ - CallbackObjectHolder holder1(aOnSuccess); - nsCOMPtr onsucces = - holder1.ToXPCOMCallback(); - - CallbackObjectHolder holder2(aOnError); - nsCOMPtr onerror = holder2.ToXPCOMCallback(); - - MozGetUserMediaDevices(onsucces, onerror, aRv); -} - -void -Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess, - nsIDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the chromeonly check here. - if (!mWindow || !mWindow->GetOuterWindow() || - mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) { - aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return; - } - MediaManager* manager = MediaManager::Get(); - aRv = manager->GetUserMediaDevices(mWindow, aOnSuccess, aOnError); + return manager->GetUserMediaDevices(mWindow, aOnSuccess, aOnError); } #endif @@ -1332,25 +1125,20 @@ Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSucc NS_IMETHODIMP Navigator::GetMozNotification(nsISupports** aRetVal) { - ErrorResult rv; - NS_IF_ADDREF(*aRetVal = GetMozNotification(rv)); - return rv.ErrorCode(); -} + NS_ENSURE_ARG_POINTER(aRetVal); + *aRetVal = nullptr; -DesktopNotificationCenter* -Navigator::GetMozNotification(ErrorResult& aRv) -{ if (mNotification) { - return mNotification; + NS_ADDREF(*aRetVal = mNotification); + return NS_OK; } - if (!mWindow || !mWindow->GetDocShell()) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + NS_ENSURE_TRUE(mWindow && mWindow->GetDocShell(), NS_ERROR_FAILURE); mNotification = new DesktopNotificationCenter(mWindow); - return mNotification; + + NS_ADDREF(*aRetVal = mNotification); + return NS_OK; } //***************************************************************************** @@ -1359,86 +1147,51 @@ Navigator::GetMozNotification(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetBattery(nsISupports** aBattery) -{ - ErrorResult rv; - NS_IF_ADDREF(*aBattery = GetBattery(rv)); - return rv.ErrorCode(); -} - -battery::BatteryManager* -Navigator::GetBattery(ErrorResult& aRv) { if (!mBatteryManager) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr); + *aBattery = nullptr; + + NS_ENSURE_STATE(mWindow); + NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK); mBatteryManager = new battery::BatteryManager(); mBatteryManager->Init(mWindow); } - return mBatteryManager; + NS_ADDREF(*aBattery = mBatteryManager); + + return NS_OK; } NS_IMETHODIMP Navigator::GetMozPower(nsIDOMMozPowerManager** aPower) { - if (!PowerManager::CheckPermission(mWindow)) { - *aPower = nullptr; - return NS_OK; - } - ErrorResult rv; - NS_IF_ADDREF(*aPower = GetMozPower(rv)); - return rv.ErrorCode(); -} + *aPower = nullptr; -nsIDOMMozPowerManager* -Navigator::GetMozPower(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mPowerManager) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - mPowerManager = PowerManager::CreateInstance(mWindow); - if (!mPowerManager) { - // We failed to get the power manager service? - aRv.Throw(NS_ERROR_UNEXPECTED); - } + NS_ENSURE_STATE(mWindow); + mPowerManager = PowerManager::CheckPermissionAndCreateInstance(mWindow); + NS_ENSURE_TRUE(mPowerManager, NS_OK); } - return mPowerManager; + nsCOMPtr power(mPowerManager); + power.forget(aPower); + + return NS_OK; } NS_IMETHODIMP Navigator::RequestWakeLock(const nsAString &aTopic, nsIDOMMozWakeLock **aWakeLock) { - ErrorResult rv; - *aWakeLock = RequestWakeLock(aTopic, rv).get(); - return rv.ErrorCode(); -} + NS_ENSURE_STATE(mWindow); -already_AddRefed -Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv) -{ - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + *aWakeLock = nullptr; nsCOMPtr pmService = do_GetService(POWERMANAGERSERVICE_CONTRACTID); - // Maybe it went away for some reason... Or maybe we're just called - // from our XPCOM method. - NS_ENSURE_TRUE(pmService, nullptr); + NS_ENSURE_TRUE(pmService, NS_OK); - nsCOMPtr wakelock; - aRv = pmService->NewWakeLock(aTopic, mWindow, getter_AddRefs(wakelock)); - return wakelock.forget(); + return pmService->NewWakeLock(aTopic, mWindow, aWakeLock); } //***************************************************************************** @@ -1448,32 +1201,21 @@ Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv) NS_IMETHODIMP Navigator::GetMozSms(nsIDOMMozSmsManager** aSmsManager) { + *aSmsManager = nullptr; + if (!mSmsManager) { - if (!mWindow || !SmsManager::CreationIsAllowed(mWindow)) { - *aSmsManager = nullptr; - return NS_OK; - } + NS_ENSURE_STATE(mWindow); + NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK); + + mSmsManager = SmsManager::CreateInstanceIfAllowed(mWindow); + NS_ENSURE_TRUE(mSmsManager, NS_OK); } - NS_IF_ADDREF(*aSmsManager = GetMozSms()); + NS_ADDREF(*aSmsManager = mSmsManager); + return NS_OK; } -nsIDOMMozSmsManager* -Navigator::GetMozSms() -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. - if (!mSmsManager) { - NS_ENSURE_TRUE(mWindow, nullptr); - NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr); - - mSmsManager = SmsManager::CreateInstance(mWindow); - } - - return mSmsManager; -} - //***************************************************************************** // Navigator::nsIDOMNavigatorMobileMessage //***************************************************************************** @@ -1481,30 +1223,32 @@ Navigator::GetMozSms() NS_IMETHODIMP Navigator::GetMozMobileMessage(nsIDOMMozMobileMessageManager** aMobileMessageManager) { - if (!HasMobileMessageSupport(mWindow)) { - *aMobileMessageManager = nullptr; - return NS_OK; - } + *aMobileMessageManager = nullptr; - NS_IF_ADDREF(*aMobileMessageManager = GetMozMobileMessage()); +#ifndef MOZ_WEBSMS_BACKEND return NS_OK; -} +#endif + + // First of all, the general pref has to be turned on. + bool enabled = false; + Preferences::GetBool("dom.sms.enabled", &enabled); + NS_ENSURE_TRUE(enabled, NS_OK); -nsIDOMMozMobileMessageManager* -Navigator::GetMozMobileMessage() -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mMobileMessageManager) { - // Check that our window has not gone away - NS_ENSURE_TRUE(mWindow, nullptr); - NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr); + NS_ENSURE_STATE(mWindow); + NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK); + + if (!CheckPermission("sms")) { + return NS_OK; + } mMobileMessageManager = new MobileMessageManager(); mMobileMessageManager->Init(mWindow); } - return mMobileMessageManager; + NS_ADDREF(*aMobileMessageManager = mMobileMessageManager); + + return NS_OK; } #ifdef MOZ_B2G_RIL @@ -1516,35 +1260,21 @@ Navigator::GetMozMobileMessage() NS_IMETHODIMP Navigator::GetMozCellBroadcast(nsIDOMMozCellBroadcast** aCellBroadcast) { - if (!mCellBroadcast && - !CheckPermission("cellbroadcast")) { - *aCellBroadcast = nullptr; - return NS_OK; - } + *aCellBroadcast = nullptr; - ErrorResult rv; - NS_IF_ADDREF(*aCellBroadcast = GetMozCellBroadcast(rv)); - return rv.ErrorCode(); -} - -nsIDOMMozCellBroadcast* -Navigator::GetMozCellBroadcast(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mCellBroadcast) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; + NS_ENSURE_STATE(mWindow); + + if (!CheckPermission("cellbroadcast")) { + return NS_OK; } - aRv = NS_NewCellBroadcast(mWindow, getter_AddRefs(mCellBroadcast)); - if (aRv.Failed()) { - return nullptr; - } + nsresult rv = NS_NewCellBroadcast(mWindow, getter_AddRefs(mCellBroadcast)); + NS_ENSURE_SUCCESS(rv, rv); } - return mCellBroadcast; + NS_ADDREF(*aCellBroadcast = mCellBroadcast); + return NS_OK; } //***************************************************************************** @@ -1554,33 +1284,19 @@ Navigator::GetMozCellBroadcast(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetMozTelephony(nsIDOMTelephony** aTelephony) { - if (!mTelephony) { + nsCOMPtr telephony = mTelephony; + + if (!telephony) { NS_ENSURE_STATE(mWindow); - if (!telephony::Telephony::CheckPermission(mWindow)) { - *aTelephony = nullptr; - return NS_OK; - } + nsresult rv = NS_NewTelephony(mWindow, getter_AddRefs(mTelephony)); + NS_ENSURE_SUCCESS(rv, rv); + + // mTelephony may be null here! + telephony = mTelephony; } - ErrorResult rv; - NS_IF_ADDREF(*aTelephony = GetMozTelephony(rv)); - return rv.ErrorCode(); -} - -nsIDOMTelephony* -Navigator::GetMozTelephony(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. - if (!mTelephony) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - mTelephony = telephony::Telephony::Create(mWindow, aRv); - } - - return mTelephony; + telephony.forget(aTelephony); + return NS_OK; } //***************************************************************************** @@ -1590,35 +1306,20 @@ Navigator::GetMozTelephony(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetMozVoicemail(nsIDOMMozVoicemail** aVoicemail) { - if (!mVoicemail && - !CheckPermission("voicemail")) { - *aVoicemail = nullptr; - return NS_OK; - } + *aVoicemail = nullptr; - ErrorResult rv; - NS_IF_ADDREF(*aVoicemail = GetMozVoicemail(rv)); - return rv.ErrorCode(); -} - -nsIDOMMozVoicemail* -Navigator::GetMozVoicemail(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mVoicemail) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; + NS_ENSURE_STATE(mWindow); + if (!CheckPermission("voicemail")) { + return NS_OK; } - aRv = NS_NewVoicemail(mWindow, getter_AddRefs(mVoicemail)); - if (aRv.Failed()) { - return nullptr; - } + nsresult rv = NS_NewVoicemail(mWindow, getter_AddRefs(mVoicemail)); + NS_ENSURE_SUCCESS(rv, rv); } - return mVoicemail; + NS_ADDREF(*aVoicemail = mVoicemail); + return NS_OK; } //***************************************************************************** @@ -1628,34 +1329,22 @@ Navigator::GetMozVoicemail(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetMozIccManager(nsIDOMMozIccManager** aIccManager) { - if (!mIccManager && - !CheckPermission("mobileconnection")) { - *aIccManager = nullptr; - return NS_OK; - } + *aIccManager = nullptr; - ErrorResult rv; - NS_IF_ADDREF(*aIccManager = GetMozIccManager(rv)); - return rv.ErrorCode(); -} - -nsIDOMMozIccManager* -Navigator::GetMozIccManager(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mIccManager) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; + NS_ENSURE_STATE(mWindow); + NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK); + + if (!CheckPermission("mobileconnection")) { + return NS_OK; } - NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr); mIccManager = new icc::IccManager(); mIccManager->Init(mWindow); } - return mIccManager; + NS_ADDREF(*aIccManager = mIccManager); + return NS_OK; } #endif // MOZ_B2G_RIL @@ -1668,12 +1357,15 @@ Navigator::GetMozIccManager(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetGamepads(nsIVariant** aRetVal) { - ErrorResult rv; + NS_ENSURE_ARG_POINTER(aRetVal); + *aRetVal = nullptr; + + NS_ENSURE_STATE(mWindow); + NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK); + nsGlobalWindow* win = static_cast(mWindow.get()); + nsAutoTArray, 2> gamepads; - GetGamepads(gamepads, rv); - if (rv.Failed()) { - return rv.ErrorCode(); - } + win->GetGamepads(gamepads); nsRefPtr out = new nsVariant(); NS_ENSURE_STATE(out); @@ -1691,19 +1383,6 @@ Navigator::GetGamepads(nsIVariant** aRetVal) return NS_OK; } - -void -Navigator::GetGamepads(nsTArray >& aGamepads, - ErrorResult& aRv) -{ - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return; - } - NS_ENSURE_TRUE_VOID(mWindow->GetDocShell()); - nsGlobalWindow* win = static_cast(mWindow.get()); - win->GetGamepads(aGamepads); -} #endif //***************************************************************************** @@ -1713,22 +1392,18 @@ Navigator::GetGamepads(nsTArray >& aGamepads, NS_IMETHODIMP Navigator::GetMozConnection(nsIDOMMozConnection** aConnection) { - NS_IF_ADDREF(*aConnection = GetMozConnection()); - return NS_OK; -} + *aConnection = nullptr; -nsIDOMMozConnection* -Navigator::GetMozConnection() -{ if (!mConnection) { - NS_ENSURE_TRUE(mWindow, nullptr); - NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr); + NS_ENSURE_STATE(mWindow); + NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK); mConnection = new network::Connection(); mConnection->Init(mWindow); } - return mConnection; + NS_ADDREF(*aConnection = mConnection); + return NS_OK; } #ifdef MOZ_B2G_RIL @@ -1738,32 +1413,21 @@ Navigator::GetMozConnection() NS_IMETHODIMP Navigator::GetMozMobileConnection(nsIDOMMozMobileConnection** aMobileConnection) { - if (!mMobileConnection && - !CheckPermission("mobileconnection") && - !CheckPermission("mobilenetwork")) { - return NS_OK; - } + *aMobileConnection = nullptr; - ErrorResult rv; - NS_IF_ADDREF(*aMobileConnection = GetMozMobileConnection(rv)); - return rv.ErrorCode(); -} - -nsIDOMMozMobileConnection* -Navigator::GetMozMobileConnection(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mMobileConnection) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; + NS_ENSURE_STATE(mWindow); + if (!CheckPermission("mobileconnection") && + !CheckPermission("mobilenetwork")) { + return NS_OK; } + mMobileConnection = new network::MobileConnection(); mMobileConnection->Init(mWindow); } - return mMobileConnection; + NS_ADDREF(*aMobileConnection = mMobileConnection); + return NS_OK; } #endif // MOZ_B2G_RIL @@ -1775,33 +1439,18 @@ Navigator::GetMozMobileConnection(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetMozBluetooth(nsIDOMBluetoothManager** aBluetooth) { - if (!mBluetooth) { + nsCOMPtr bluetooth = mBluetooth; + + if (!bluetooth) { NS_ENSURE_STATE(mWindow); - if (!bluetooth::BluetoothManager::CheckPermission(mWindow)) { - *aBluetooth = nullptr; - return NS_OK; - } + nsresult rv = NS_NewBluetoothManager(mWindow, getter_AddRefs(mBluetooth)); + NS_ENSURE_SUCCESS(rv, rv); + + bluetooth = mBluetooth; } - ErrorResult rv; - NS_IF_ADDREF(*aBluetooth = GetMozBluetooth(rv)); - return rv.ErrorCode(); -} - -nsIDOMBluetoothManager* -Navigator::GetMozBluetooth(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. - if (!mBluetooth) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - mBluetooth = bluetooth::BluetoothManager::Create(mWindow); - } - - return mBluetooth; + bluetooth.forget(aBluetooth); + return NS_OK; } #endif //MOZ_B2G_BT @@ -1843,28 +1492,11 @@ Navigator::MozHasPendingMessage(const nsAString& aType, bool *aResult) return NS_ERROR_NOT_IMPLEMENTED; } - ErrorResult rv; - *aResult = MozHasPendingMessage(aType, rv); - return rv.ErrorCode(); -} - -bool -Navigator::MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv) -{ - // The WebIDL binding is responsible for the pref check here. + *aResult = false; nsresult rv = EnsureMessagesManager(); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return false; - } + NS_ENSURE_SUCCESS(rv, rv); - bool result = false; - rv = mMessagesManager->MozHasPendingMessage(aType, &result); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return false; - } - return result; + return mMessagesManager->MozHasPendingMessage(aType, aResult); } NS_IMETHODIMP @@ -1881,28 +1513,6 @@ Navigator::MozSetMessageHandler(const nsAString& aType, return mMessagesManager->MozSetMessageHandler(aType, aCallback); } -void -Navigator::MozSetMessageHandler(const nsAString& aType, - systemMessageCallback* aCallback, - ErrorResult& aRv) -{ - // The WebIDL binding is responsible for the pref check here. - nsresult rv = EnsureMessagesManager(); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return; - } - - CallbackObjectHolder - holder(aCallback); - nsCOMPtr callback = holder.ToXPCOMCallback(); - - rv = mMessagesManager->MozSetMessageHandler(aType, callback); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - } -} - //***************************************************************************** // Navigator::nsIDOMNavigatorTime //***************************************************************************** @@ -1910,30 +1520,19 @@ Navigator::MozSetMessageHandler(const nsAString& aType, NS_IMETHODIMP Navigator::GetMozTime(nsISupports** aTime) { + *aTime = nullptr; + + NS_ENSURE_STATE(mWindow); if (!CheckPermission("time")) { return NS_ERROR_DOM_SECURITY_ERR; } - ErrorResult rv; - NS_IF_ADDREF(*aTime = GetMozTime(rv)); - return rv.ErrorCode(); -} - -time::TimeManager* -Navigator::GetMozTime(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - if (!mTimeManager) { mTimeManager = new time::TimeManager(mWindow); } - return mTimeManager; + NS_ADDREF(*aTime = mTimeManager); + return NS_OK; } #endif @@ -1944,36 +1543,22 @@ Navigator::GetMozTime(ErrorResult& aRv) NS_IMETHODIMP Navigator::GetMozCameras(nsISupports** aCameraManager) { - if (!mCameraManager) { - NS_ENSURE_STATE(mWindow); - if (!nsDOMCameraManager::CheckPermission(mWindow)) { - *aCameraManager = nullptr; - return NS_OK; - } - } - - ErrorResult rv; - NS_IF_ADDREF(*aCameraManager = static_cast(GetMozCameras(rv))); - return rv.ErrorCode(); -} - -nsDOMCameraManager* -Navigator::GetMozCameras(ErrorResult& aRv) -{ - // Callers (either the XPCOM method or the WebIDL binding) are responsible for - // the permission check here. if (!mCameraManager) { if (!mWindow || !mWindow->GetOuterWindow() || mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) { - aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return nullptr; + return NS_ERROR_NOT_AVAILABLE; } - mCameraManager = nsDOMCameraManager::CreateInstance(mWindow); + mCameraManager = + nsDOMCameraManager::CheckPermissionAndCreateInstance(mWindow); + NS_ENSURE_TRUE(mCameraManager, NS_OK); } - return mCameraManager; + nsCOMPtr cameraManager = mCameraManager.get(); + cameraManager.forget(aCameraManager); + + return NS_OK; } size_t @@ -2019,14 +1604,7 @@ Navigator::OnNavigation() bool Navigator::CheckPermission(const char* type) { - return CheckPermission(mWindow, type); -} - -/* static */ -bool -Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType) -{ - if (!aWindow) { + if (!mWindow) { return false; } @@ -2035,7 +1613,7 @@ Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType) NS_ENSURE_TRUE(permMgr, false); uint32_t permission = nsIPermissionManager::DENY_ACTION; - permMgr->TestPermissionFromWindow(aWindow, aType, &permission); + permMgr->TestPermissionFromWindow(mWindow, type, &permission); return permission == nsIPermissionManager::ALLOW_ACTION; } @@ -2046,317 +1624,19 @@ Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType) NS_IMETHODIMP Navigator::GetMozAudioChannelManager(nsISupports** aAudioChannelManager) { - ErrorResult rv; - NS_IF_ADDREF(*aAudioChannelManager = GetMozAudioChannelManager(rv)); - return rv.ErrorCode(); -} + *aAudioChannelManager = nullptr; -system::AudioChannelManager* -Navigator::GetMozAudioChannelManager(ErrorResult& aRv) -{ if (!mAudioChannelManager) { - if (!mWindow) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + NS_ENSURE_STATE(mWindow); mAudioChannelManager = new system::AudioChannelManager(); mAudioChannelManager->Init(mWindow); } - return mAudioChannelManager; + NS_ADDREF(*aAudioChannelManager = mAudioChannelManager); + return NS_OK; } #endif -bool -Navigator::DoNewResolve(JSContext* aCx, JS::Handle aObject, - JS::Handle aId, unsigned aFlags, - JS::MutableHandle aObjp) -{ - if (!JSID_IS_STRING(aId)) { - return true; - } - - nsScriptNameSpaceManager *nameSpaceManager = - nsJSRuntime::GetNameSpaceManager(); - if (!nameSpaceManager) { - return Throw(aCx, NS_ERROR_NOT_INITIALIZED); - } - - nsDependentJSString name(aId); - - const nsGlobalNameStruct* name_struct = - nameSpaceManager->LookupNavigatorName(name); - if (!name_struct) { - return true; - } - - if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding) { - ConstructNavigatorProperty construct = name_struct->mConstructNavigatorProperty; - MOZ_ASSERT(construct); - - JS::Rooted naviObj(aCx, - js::CheckedUnwrap(aObject, - /* stopAtOuter = */ false)); - if (!naviObj) { - return Throw(aCx, NS_ERROR_DOM_SECURITY_ERR); - } - - JS::Rooted domObject(aCx); - { - JSAutoCompartment ac(aCx, naviObj); - - // Check whether our constructor is enabled after we unwrap Xrays, since - // we don't want to define an interface on the Xray if it's disabled in - // the target global, even if it's enabled in the Xray's global. - if (name_struct->mConstructorEnabled && - !(*name_struct->mConstructorEnabled)(aCx, naviObj)) { - return true; - } - - domObject = construct(aCx, naviObj); - if (!domObject) { - return Throw(aCx, NS_ERROR_FAILURE); - } - } - - if (!JS_WrapObject(aCx, domObject.address()) || - !JS_DefinePropertyById(aCx, aObject, aId, - JS::ObjectValue(*domObject), - nullptr, nullptr, JSPROP_ENUMERATE)) { - return false; - } - - aObjp.set(aObject); - - return true; - } - - NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeNavigatorProperty, - "unexpected type"); - - nsresult rv = NS_OK; - - nsCOMPtr native(do_CreateInstance(name_struct->mCID, &rv)); - if (NS_FAILED(rv)) { - return Throw(aCx, rv); - } - - JS::Rooted prop_val(aCx, JS::UndefinedValue()); // Property value. - - nsCOMPtr gpi(do_QueryInterface(native)); - - if (gpi) { - if (!mWindow) { - return Throw(aCx, NS_ERROR_UNEXPECTED); - } - - rv = gpi->Init(mWindow, prop_val.address()); - if (NS_FAILED(rv)) { - return Throw(aCx, rv); - } - } - - if (JSVAL_IS_PRIMITIVE(prop_val) && !JSVAL_IS_NULL(prop_val)) { - nsCOMPtr holder; - rv = nsContentUtils::WrapNative(aCx, aObject, native, prop_val.address(), - getter_AddRefs(holder), true); - - if (NS_FAILED(rv)) { - return Throw(aCx, rv); - } - } - - if (!JS_WrapValue(aCx, prop_val.address())) { - return Throw(aCx, NS_ERROR_UNEXPECTED); - } - - JSBool ok = ::JS_DefinePropertyById(aCx, aObject, aId, prop_val, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_ENUMERATE); - - aObjp.set(aObject); - - return ok; -} - -JSObject* -Navigator::WrapObject(JSContext* cx, JS::Handle scope) -{ - return NavigatorBinding::Wrap(cx, scope, this); -} - -/* static */ -bool -Navigator::HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */) -{ - return battery::BatteryManager::HasSupport(); -} - -/* static */ -bool -Navigator::HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && PowerManager::CheckPermission(win); -} - -/* static */ -bool -Navigator::HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - if (!nsContentUtils::IsIdleObserverAPIEnabled()) { - return false; - } - - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return CheckPermission(win, "idle"); -} - -/* static */ -bool -Navigator::HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */) -{ - nsCOMPtr pmService = - do_GetService(POWERMANAGERSERVICE_CONTRACTID); - // No service means no wake lock support - return !!pmService; -} - -/* static */ -bool -Navigator::HasSmsSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && SmsManager::CreationIsAllowed(win); -} - -/* static */ -bool -Navigator::HasMobileMessageSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return HasMobileMessageSupport(win); -} - -/* static */ -bool -Navigator::HasMobileMessageSupport(nsPIDOMWindow* aWindow) -{ -#ifndef MOZ_WEBSMS_BACKEND - return false; -#endif - - // First of all, the general pref has to be turned on. - bool enabled = false; - Preferences::GetBool("dom.sms.enabled", &enabled); - NS_ENSURE_TRUE(enabled, false); - - NS_ENSURE_TRUE(aWindow, false); - NS_ENSURE_TRUE(aWindow->GetDocShell(), false); - - if (!CheckPermission(aWindow, "sms")) { - return false; - } - - return true; -} - -/* static */ -bool -Navigator::HasCameraSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && nsDOMCameraManager::CheckPermission(win); -} - -#ifdef MOZ_B2G_RIL -/* static */ -bool -Navigator::HasTelephonySupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && telephony::Telephony::CheckPermission(win); -} - -/* static */ -bool -Navigator::HasMobileConnectionSupport(JSContext* /* unused */, - JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && (CheckPermission(win, "mobileconnection") || - CheckPermission(win, "mobilenetwork")); -} - -/* static */ -bool -Navigator::HasCellBroadcastSupport(JSContext* /* unused */, - JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && CheckPermission(win, "cellbroadcast"); -} - -/* static */ -bool -Navigator::HasVoicemailSupport(JSContext* /* unused */, - JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && CheckPermission(win, "voicemail"); -} - -/* static */ -bool -Navigator::HasIccManagerSupport(JSContext* /* unused */, - JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && CheckPermission(win, "mobileconnection"); -} -#endif // MOZ_B2G_RIL - -#ifdef MOZ_B2G_BT -/* static */ -bool -Navigator::HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && bluetooth::BluetoothManager::CheckPermission(win); -} -#endif // MOZ_B2G_BT - -#ifdef MOZ_TIME_MANAGER -/* static */ -bool -Navigator::HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal) -{ - nsCOMPtr win = GetWindowFromGlobal(aGlobal); - return win && CheckPermission(win, "time"); -} -#endif // MOZ_TIME_MANAGER - -#ifdef MOZ_MEDIA_NAVIGATOR -/* static */ -bool Navigator::HasUserMediaSupport(JSContext* /* unused */, - JSObject* /* unused */) -{ - // Make enabling peerconnection enable getUserMedia() as well - return Preferences::GetBool("media.navigator.enabled", false) || - Preferences::GetBool("media.peerconnection.enabled", false); -} -#endif // MOZ_MEDIA_NAVIGATOR - -/* static */ -already_AddRefed -Navigator::GetWindowFromGlobal(JSObject* aGlobal) -{ - nsCOMPtr win = - do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal)); - MOZ_ASSERT(!win || win->IsInnerWindow()); - return win.forget(); -} - } // namespace dom } // namespace mozilla @@ -2455,7 +1735,7 @@ NS_GetNavigatorAppVersion(nsAString& aAppVersion) return rv; } -void +nsresult NS_GetNavigatorAppName(nsAString& aAppName) { if (!nsContentUtils::IsCallerChrome()) { @@ -2464,8 +1744,10 @@ NS_GetNavigatorAppName(nsAString& aAppName) if (override) { aAppName = override; + return NS_OK; } } aAppName.AssignLiteral("Netscape"); + return NS_OK; } diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index 1d1341c6e140..0646ac62c885 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -40,7 +40,6 @@ class nsIDOMMozConnection; namespace mozilla { namespace dom { class Geolocation; -class systemMessageCallback; } } @@ -70,8 +69,6 @@ class nsIDOMTelephony; // Navigator: Script "navigator" object //***************************************************************************** -void NS_GetNavigatorAppName(nsAString& aAppName); - namespace mozilla { namespace dom { @@ -82,15 +79,6 @@ class BatteryManager; class DesktopNotificationCenter; class SmsManager; class MobileMessageManager; -class MozIdleObserver; -#ifdef MOZ_GAMEPAD -class Gamepad; -#endif // MOZ_GAMEPAD -#ifdef MOZ_MEDIA_NAVIGATOR -class MozDOMGetUserMediaSuccessCallback; -class MozDOMGetUserMediaErrorCallback; -class MozGetUserMediaDevicesSuccessCallback; -#endif // MOZ_MEDIA_NAVIGATOR namespace icc { #ifdef MOZ_B2G_RIL @@ -204,7 +192,7 @@ public: static void Init(); void Invalidate(); - nsPIDOMWindow *GetWindow() const + nsPIDOMWindow *GetWindow() { return mWindow; } @@ -230,187 +218,8 @@ public: NS_DECL_NSIDOMNAVIGATORCAMERA - // WebIDL API - void GetAppName(nsString& aAppName) - { - NS_GetNavigatorAppName(aAppName); - } - void GetAppVersion(nsString& aAppVersion, ErrorResult& aRv) - { - aRv = GetAppVersion(aAppVersion); - } - void GetPlatform(nsString& aPlatform, ErrorResult& aRv) - { - aRv = GetPlatform(aPlatform); - } - void GetUserAgent(nsString& aUserAgent, ErrorResult& aRv) - { - aRv = GetUserAgent(aUserAgent); - } - // The XPCOM GetProduct is OK - // The XPCOM GetLanguage is OK - bool OnLine(); - void RegisterProtocolHandler(const nsAString& aScheme, const nsAString& aURL, - const nsAString& aTitle, ErrorResult& rv) - { - rv = RegisterProtocolHandler(aScheme, aURL, aTitle); - } - void RegisterContentHandler(const nsAString& aMIMEType, const nsAString& aURL, - const nsAString& aTitle, ErrorResult& rv) - { - rv = RegisterContentHandler(aMIMEType, aURL, aTitle); - } - nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv); - nsPluginArray* GetPlugins(ErrorResult& aRv); - // The XPCOM GetDoNotTrack is ok - Geolocation* GetGeolocation(ErrorResult& aRv); - battery::BatteryManager* GetBattery(ErrorResult& aRv); - void Vibrate(uint32_t aDuration, ErrorResult& aRv); - void Vibrate(const nsTArray& aDuration, ErrorResult& aRv); - void GetAppCodeName(nsString& aAppCodeName, ErrorResult& aRv) - { - aRv = GetAppCodeName(aAppCodeName); - } - void GetOscpu(nsString& aOscpu, ErrorResult& aRv) - { - aRv = GetOscpu(aOscpu); - } - // The XPCOM GetVendor is OK - // The XPCOM GetVendorSub is OK - // The XPCOM GetProductSub is OK - bool CookieEnabled(); - void GetBuildID(nsString& aBuildID, ErrorResult& aRv) - { - aRv = GetBuildID(aBuildID); - } - nsIDOMMozPowerManager* GetMozPower(ErrorResult& aRv); - bool JavaEnabled(ErrorResult& aRv); - bool TaintEnabled() - { - return false; - } - void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); - void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv); - already_AddRefed RequestWakeLock(const nsAString &aTopic, - ErrorResult& aRv); - nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType, - ErrorResult& aRv); - void GetDeviceStorages(const nsAString& aType, - nsTArray >& aStores, - ErrorResult& aRv); - DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv); - bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline, - ErrorResult& aRv) - { - bool available = false; - aRv = MozIsLocallyAvailable(aURI, aWhenOffline, &available); - return available; - } - nsIDOMMozSmsManager* GetMozSms(); - nsIDOMMozMobileMessageManager* GetMozMobileMessage(); - nsIDOMMozConnection* GetMozConnection(); - nsDOMCameraManager* GetMozCameras(ErrorResult& aRv); - void MozSetMessageHandler(const nsAString& aType, - systemMessageCallback* aCallback, - ErrorResult& aRv); - bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv); -#ifdef MOZ_B2G_RIL - nsIDOMTelephony* GetMozTelephony(ErrorResult& aRv); - nsIDOMMozMobileConnection* GetMozMobileConnection(ErrorResult& aRv); - nsIDOMMozCellBroadcast* GetMozCellBroadcast(ErrorResult& aRv); - nsIDOMMozVoicemail* GetMozVoicemail(ErrorResult& aRv); - nsIDOMMozIccManager* GetMozIccManager(ErrorResult& aRv); -#endif // MOZ_B2G_RIL -#ifdef MOZ_GAMEPAD - void GetGamepads(nsTArray >& aGamepads, ErrorResult& aRv); -#endif // MOZ_GAMEPAD -#ifdef MOZ_B2G_BT - nsIDOMBluetoothManager* GetMozBluetooth(ErrorResult& aRv); -#endif // MOZ_B2G_BT -#ifdef MOZ_TIME_MANAGER - time::TimeManager* GetMozTime(ErrorResult& aRv); -#endif // MOZ_TIME_MANAGER -#ifdef MOZ_AUDIO_CHANNEL_MANAGER - system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv); -#endif // MOZ_AUDIO_CHANNEL_MANAGER -#ifdef MOZ_MEDIA_NAVIGATOR - void MozGetUserMedia(nsIMediaStreamOptions* aParams, - MozDOMGetUserMediaSuccessCallback* aOnSuccess, - MozDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv); - void MozGetUserMedia(nsIMediaStreamOptions* aParams, - nsIDOMGetUserMediaSuccessCallback* aOnSuccess, - nsIDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv); - void MozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback* aOnSuccess, - MozDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv); - void MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess, - nsIDOMGetUserMediaErrorCallback* aOnError, - ErrorResult& aRv); -#endif // MOZ_MEDIA_NAVIGATOR - bool DoNewResolve(JSContext* aCx, JS::Handle aObject, - JS::Handle aId, unsigned aFlags, - JS::MutableHandle aObjp); - - // WebIDL helper methods - static bool HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */); - static bool HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal); - static bool HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal); - static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */); - static bool HasDesktopNotificationSupport(JSContext* /* unused*/, - JSObject* /*unused */) - { - return HasDesktopNotificationSupport(); - } - static bool HasSmsSupport(JSContext* /* unused */, JSObject* aGlobal); - static bool HasMobileMessageSupport(JSContext* /* unused */, - JSObject* aGlobal); - static bool HasCameraSupport(JSContext* /* unused */, - JSObject* aGlobal); -#ifdef MOZ_B2G_RIL - static bool HasTelephonySupport(JSContext* /* unused */, - JSObject* aGlobal); - static bool HasMobileConnectionSupport(JSContext* /* unused */, - JSObject* aGlobal); - static bool HasCellBroadcastSupport(JSContext* /* unused */, - JSObject* aGlobal); - static bool HasVoicemailSupport(JSContext* /* unused */, - JSObject* aGlobal); - static bool HasIccManagerSupport(JSContext* /* unused */, - JSObject* aGlobal); -#endif // MOZ_B2G_RIL -#ifdef MOZ_B2G_BT - static bool HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal); -#endif // MOZ_B2G_BT -#ifdef MOZ_TIME_MANAGER - static bool HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal); -#endif // MOZ_TIME_MANAGER -#ifdef MOZ_MEDIA_NAVIGATOR - static bool HasUserMediaSupport(JSContext* /* unused */, - JSObject* /* unused */); -#endif // MOZ_MEDIA_NAVIGATOR - - nsPIDOMWindow* GetParentObject() const - { - return GetWindow(); - } - - virtual JSObject* WrapObject(JSContext* cx, - JS::Handle scope) MOZ_OVERRIDE; - private: bool CheckPermission(const char* type); - static bool CheckPermission(nsPIDOMWindow* aWindow, const char* aType); - static bool HasMobileMessageSupport(nsPIDOMWindow* aWindow); - // GetWindowFromGlobal returns the inner window for this global, if - // any, else null. - static already_AddRefed GetWindowFromGlobal(JSObject* aGlobal); - - // Methods to common up the XPCOM and WebIDL implementations of - // Add/RemoveIdleObserver. - void AddIdleObserver(nsIIdleObserver& aIdleObserver); - void RemoveIdleObserver(nsIIdleObserver& aIdleObserver); nsRefPtr mMimeTypes; nsRefPtr mPlugins; @@ -449,5 +258,6 @@ private: nsresult NS_GetNavigatorUserAgent(nsAString& aUserAgent); nsresult NS_GetNavigatorPlatform(nsAString& aPlatform); nsresult NS_GetNavigatorAppVersion(nsAString& aAppVersion); +nsresult NS_GetNavigatorAppName(nsAString& aAppName); #endif // mozilla_dom_Navigator_h diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index a0c6b00ed008..a38525c42ef5 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -4660,15 +4660,101 @@ nsNavigatorSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, { JS::Rooted obj(cx, aObj); JS::Rooted id(cx, aId); - nsCOMPtr navigator = do_QueryWrappedNative(wrapper); - if (!static_cast(navigator.get())-> - DoNewResolve(cx, obj, id, flags, - JS::MutableHandle::fromMarkedLocation(objp))) { - return NS_ERROR_FAILURE; + if (!JSID_IS_STRING(id)) { + return NS_OK; } + nsScriptNameSpaceManager *nameSpaceManager = + nsJSRuntime::GetNameSpaceManager(); + NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED); + + nsDependentJSString name(id); + + const nsGlobalNameStruct* name_struct = + nameSpaceManager->LookupNavigatorName(name); + if (!name_struct) { + return NS_OK; + } + + if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding) { + mozilla::dom::ConstructNavigatorProperty construct = name_struct->mConstructNavigatorProperty; + MOZ_ASSERT(construct); + + JS::Rooted naviObj(cx, js::CheckedUnwrap(obj, /* stopAtOuter = */ false)); + NS_ENSURE_TRUE(naviObj, NS_ERROR_DOM_SECURITY_ERR); + + JS::Rooted domObject(cx); + { + JSAutoCompartment ac(cx, naviObj); + + // Check whether our constructor is enabled after we unwrap Xrays, since + // we don't want to define an interface on the Xray if it's disabled in + // the target global, even if it's enabled in the Xray's global. + if (name_struct->mConstructorEnabled && + !(*name_struct->mConstructorEnabled)(cx, naviObj)) { + return NS_OK; + } + + domObject = construct(cx, naviObj); + if (!domObject) { + return NS_ERROR_FAILURE; + } + } + + if (!JS_WrapObject(cx, domObject.address()) || + !JS_DefinePropertyById(cx, obj, id, + JS::ObjectValue(*domObject), + nullptr, nullptr, JSPROP_ENUMERATE)) { + return NS_ERROR_FAILURE; + } + + *_retval = true; + *objp = obj; + + return NS_OK; + } + + NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeNavigatorProperty, + "unexpected type"); + + nsresult rv = NS_OK; + + nsCOMPtr native(do_CreateInstance(name_struct->mCID, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + JS::Rooted prop_val(cx, JS::UndefinedValue()); // Property value. + + nsCOMPtr gpi(do_QueryInterface(native)); + + if (gpi) { + nsCOMPtr navigator = do_QueryWrappedNative(wrapper); + nsIDOMWindow *window = static_cast(navigator.get())->GetWindow(); + NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED); + + rv = gpi->Init(window, prop_val.address()); + NS_ENSURE_SUCCESS(rv, rv); + } + + if (JSVAL_IS_PRIMITIVE(prop_val) && !JSVAL_IS_NULL(prop_val)) { + nsCOMPtr holder; + rv = WrapNative(cx, obj, native, true, prop_val.address(), + getter_AddRefs(holder)); + + NS_ENSURE_SUCCESS(rv, rv); + } + + if (!JS_WrapValue(cx, prop_val.address())) { + return NS_ERROR_UNEXPECTED; + } + + JSBool ok = ::JS_DefinePropertyById(cx, obj, id, prop_val, + JS_PropertyStub, JS_StrictPropertyStub, + JSPROP_ENUMERATE); + *_retval = true; - return NS_OK; + *objp = obj; + + return ok ? NS_OK : NS_ERROR_FAILURE; } // static diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 66cbe8f28417..dcb8488af4c9 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -1702,30 +1702,17 @@ addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True) addExternalIface('LockedFile') addExternalIface('MediaList') addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True) -addExternalIface('MozBluetoothManager', nativeType='nsIDOMBluetoothManager') addExternalIface('MozBoxObject', nativeType='nsIBoxObject') -addExternalIface('MozCellBroadcast') -addExternalIface('MozConnection', headerFile='nsIDOMConnection.h') addExternalIface('MozControllers', nativeType='nsIControllers') addExternalIface('MozFrameLoader', nativeType='nsIFrameLoader', notflattened=True) -addExternalIface('MozIccManager', headerFile='nsIDOMIccManager.h') -addExternalIface('MozMediaStreamOptions', nativeType='nsIMediaStreamOptions', - headerFile='nsIDOMNavigatorUserMedia.h') -addExternalIface('MozMobileConnection', headerFile='nsIDOMMobileConnection.h') -addExternalIface('MozMobileMessageManager', headerFile='nsIDOMMobileMessageManager.h') addExternalIface('MozObserver', nativeType='nsIObserver', notflattened=True) -addExternalIface('MozPowerManager', headerFile='nsIDOMPowerManager.h') addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource', notflattened=True) addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True) -addExternalIface('MozSmsManager', headerFile='nsIDOMSmsManager.h') -addExternalIface('MozTelephony', nativeType='nsIDOMTelephony') addExternalIface('MozTreeBoxObject', nativeType='nsITreeBoxObject', notflattened=True) addExternalIface('MozTreeColumn', nativeType='nsITreeColumn', headerFile='nsITreeColumns.h') -addExternalIface('MozVoicemail') -addExternalIface('MozWakeLock', headerFile='nsIDOMWakeLock.h') addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder') addExternalIface('nsIControllers', nativeType='nsIControllers') addExternalIface('nsIInputStreamCallback', nativeType='nsIInputStreamCallback', diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index f6100b714c3d..ea9721dfeb04 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3732,7 +3732,7 @@ def convertConstIDLValueToJSVal(value): return "JSVAL_TRUE" if value.value else "JSVAL_FALSE" if tag in [IDLType.Tags.float, IDLType.Tags.double]: return "DOUBLE_TO_JSVAL(%s)" % (value.value) - raise TypeError("Const value of unhandled type: %s" % value.type) + raise TypeError("Const value of unhandled type: " + value.type) class CGArgumentConverter(CGThing): """ diff --git a/dom/bindings/Makefile.in b/dom/bindings/Makefile.in index 06777bb8be68..1edd2a5d7548 100644 --- a/dom/bindings/Makefile.in +++ b/dom/bindings/Makefile.in @@ -22,7 +22,7 @@ include $(topsrcdir)/dom/dom-config.mk include $(topsrcdir)/dom/webidl/WebIDL.mk binding_include_path := mozilla/dom -all_webidl_files = $(webidl_files) $(generated_webidl_files) $(preprocessed_webidl_files) +all_webidl_files = $(webidl_files) $(generated_webidl_files) # Set exported_binding_headers before adding the test IDL to the mix exported_binding_headers := $(subst .webidl,Binding.h,$(all_webidl_files)) # Set linked_binding_cpp_files before adding the test IDL to the mix @@ -142,23 +142,6 @@ $(webidl_files): %: $(webidl_base)/% $(test_webidl_files): %: $(srcdir)/test/% $(INSTALL) $(IFLAGS1) $(srcdir)/test/$* . -# We can't easily use PP_TARGETS here because it insists on outputting targets -# that look like "$(CURDIR)/foo" whereas we want our target to just be "foo". -# Make sure to include $(GLOBAL_DEPS) so we pick up changes to what symbols are -# defined. Also make sure to remove $@ before writing to it, because otherwise -# if a file goes from non-preprocessed to preprocessed we can end up writing to -# a symlink, which will clobber files in the srcdir, which is bad. -$(preprocessed_webidl_files): %: $(webidl_base)/% $(GLOBAL_DEPS) - $(RM) $@ - PYTHONDONTWRITEBYTECODE=1 $(PYTHON) \ - $(topsrcdir)/config/Preprocessor.py $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) $(webidl_base)/$* -o $@ - -# Make is dumb and can get confused between "foo" and "$(CURDIR)/foo". Make -# sure that the latter depends on the former, since the latter gets used in .pp -# files. -all_webidl_files_absolute = $(addprefix $(CURDIR)/,$(all_webidl_files)) -$(all_webidl_files_absolute): $(CURDIR)/%: % - $(binding_header_files): .BindingGen $(binding_cpp_files): .BindingGen diff --git a/dom/bluetooth/BluetoothManager.cpp b/dom/bluetooth/BluetoothManager.cpp index f3d726bfa726..e79b5c5bf5c4 100644 --- a/dom/bluetooth/BluetoothManager.cpp +++ b/dom/bluetooth/BluetoothManager.cpp @@ -168,23 +168,30 @@ BluetoothManager::Create(nsPIDOMWindow* aWindow) return manager.forget(); } -// static -bool -BluetoothManager::CheckPermission(nsPIDOMWindow* aWindow) +nsresult +NS_NewBluetoothManager(nsPIDOMWindow* aWindow, + nsIDOMBluetoothManager** aBluetoothManager) { NS_ASSERTION(aWindow, "Null pointer!"); nsCOMPtr permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); - NS_ENSURE_TRUE(permMgr, false); + NS_ENSURE_TRUE(permMgr, NS_ERROR_UNEXPECTED); uint32_t permission; nsresult rv = permMgr->TestPermissionFromWindow(aWindow, "bluetooth", &permission); - NS_ENSURE_SUCCESS(rv, false); + NS_ENSURE_SUCCESS(rv, rv); - return permission == nsIPermissionManager::ALLOW_ACTION; + nsRefPtr bluetoothManager; + + if (permission == nsIPermissionManager::ALLOW_ACTION) { + bluetoothManager = BluetoothManager::Create(aWindow); + } + + bluetoothManager.forget(aBluetoothManager); + return NS_OK; } void diff --git a/dom/bluetooth/BluetoothManager.h b/dom/bluetooth/BluetoothManager.h index e5bc301dc8b1..9e67306e8bb2 100644 --- a/dom/bluetooth/BluetoothManager.h +++ b/dom/bluetooth/BluetoothManager.h @@ -29,10 +29,8 @@ public: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper) - // Never returns null static already_AddRefed - Create(nsPIDOMWindow* aWindow); - static bool CheckPermission(nsPIDOMWindow* aWindow); + Create(nsPIDOMWindow* aWindow); void Notify(const BluetoothSignal& aData); virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE; private: @@ -42,4 +40,7 @@ private: END_BLUETOOTH_NAMESPACE +nsresult NS_NewBluetoothManager(nsPIDOMWindow* aWindow, + nsIDOMBluetoothManager** aBluetoothManager); + #endif diff --git a/dom/camera/DOMCameraManager.cpp b/dom/camera/DOMCameraManager.cpp index 1e9e6bb40661..15fbeb758452 100644 --- a/dom/camera/DOMCameraManager.cpp +++ b/dom/camera/DOMCameraManager.cpp @@ -71,27 +71,21 @@ nsDOMCameraManager::~nsDOMCameraManager() obs->RemoveObserver(this, "xpcom-shutdown"); } -bool -nsDOMCameraManager::CheckPermission(nsPIDOMWindow* aWindow) +// static creator +already_AddRefed +nsDOMCameraManager::CheckPermissionAndCreateInstance(nsPIDOMWindow* aWindow) { nsCOMPtr permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); - NS_ENSURE_TRUE(permMgr, false); + NS_ENSURE_TRUE(permMgr, nullptr); uint32_t permission = nsIPermissionManager::DENY_ACTION; permMgr->TestPermissionFromWindow(aWindow, "camera", &permission); if (permission != nsIPermissionManager::ALLOW_ACTION) { NS_WARNING("No permission to access camera"); - return false; + return nullptr; } - return true; -} - -// static creator -already_AddRefed -nsDOMCameraManager::CreateInstance(nsPIDOMWindow* aWindow) -{ // Initialize the shared active window tracker if (!sActiveWindowsInitialized) { sActiveWindows.Init(); diff --git a/dom/camera/DOMCameraManager.h b/dom/camera/DOMCameraManager.h index d22a679974d6..26498fee918e 100644 --- a/dom/camera/DOMCameraManager.h +++ b/dom/camera/DOMCameraManager.h @@ -45,9 +45,8 @@ public: nsIObserver) NS_DECL_NSIOBSERVER - static bool CheckPermission(nsPIDOMWindow* aWindow); static already_AddRefed - CreateInstance(nsPIDOMWindow* aWindow); + CheckPermissionAndCreateInstance(nsPIDOMWindow* aWindow); static bool IsWindowStillActive(uint64_t aWindowId); void Register(mozilla::nsDOMCameraControl* aDOMCameraControl); diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 5241495a63a7..13e7090cc40b 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1095,9 +1095,9 @@ MediaManager::GetUserMedia(bool aPrivileged, nsPIDOMWindow* aWindow, #ifdef MOZ_B2G_CAMERA if (mCameraManager == nullptr) { - aPrivileged = nsDOMCameraManager::CheckPermission(aWindow); - if (aPrivileged) { - mCameraManager = nsDOMCameraManager::CreateInstance(aWindow); + mCameraManager = nsDOMCameraManager::CheckPermissionAndCreateInstance(aWindow); + if (!mCameraManager) { + aPrivileged = false; } } #endif diff --git a/dom/media/tests/crashtests/802982.html b/dom/media/tests/crashtests/802982.html index 032f3085cd20..6047a391c392 100644 --- a/dom/media/tests/crashtests/802982.html +++ b/dom/media/tests/crashtests/802982.html @@ -15,7 +15,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=802982 function boom() { for (var j = 0; j < 100; ++j) { - navigator.mozGetUserMedia({}, function(){}, function(){}); + navigator.mozGetUserMedia({}, {}, {}); } finish(); // we're not waiting for success/error callbacks here } diff --git a/dom/media/tests/mochitest/test_getUserMedia_exceptions.html b/dom/media/tests/mochitest/test_getUserMedia_exceptions.html index d4927cbf23b5..ac842112aa5a 100644 --- a/dom/media/tests/mochitest/test_getUserMedia_exceptions.html +++ b/dom/media/tests/mochitest/test_getUserMedia_exceptions.html @@ -26,26 +26,26 @@ var exceptionTests = [ // Each test here verifies that a caller is required to have all // three arguments in order to call mozGetUserMedia { params: undefined, - error: "Not enough arguments to Navigator.mozGetUserMedia.", + error: Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS, message: "no arguments specified" }, { params: [{video: true, fake: true}], - error: "Not enough arguments to Navigator.mozGetUserMedia.", + error: Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS, message: "one argument specified" }, { params: [{video: true, fake: true}, unexpectedCall], - error: "Not enough arguments to Navigator.mozGetUserMedia.", + error: Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS, message: "two arguments specified" }, // Each test here verifies that providing an incorret object // type to any mozGetUserMedia parameter should throw // the correct exception specified { params: [1, unexpectedCall, unexpectedCall], - error: "Argument 1 of Navigator.mozGetUserMedia is not an object.", + error: Cr.NS_ERROR_XPC_BAD_CONVERT_JS, message: "wrong object type as first parameter" }, { params: [{video: true, fake: true}, 1, unexpectedCall], - error: "Argument 2 of Navigator.mozGetUserMedia is not an object.", + error: Cr.NS_ERROR_XPC_BAD_CONVERT_JS, message: "wrong object type as second parameter" }, { params: [{video: true, fake: true}, unexpectedCall, 1], - error: "Argument 3 of Navigator.mozGetUserMedia is not an object.", + error: Cr.NS_ERROR_XPC_BAD_CONVERT_JS, message: "wrong object type as third parameter" } ]; @@ -71,7 +71,7 @@ runTest(function () { try { navigator.mozGetUserMedia.apply(navigator, test.params); } catch (e) { - exception = (e.message === test.error); + exception = (e.result === test.error); } ok(exception, "Exception for " + test.message); }); diff --git a/dom/mobilemessage/src/SmsManager.cpp b/dom/mobilemessage/src/SmsManager.cpp index 1d73cb700cd2..2adb96048b29 100644 --- a/dom/mobilemessage/src/SmsManager.cpp +++ b/dom/mobilemessage/src/SmsManager.cpp @@ -54,49 +54,41 @@ NS_IMPL_EVENT_HANDLER(SmsManager, failed) NS_IMPL_EVENT_HANDLER(SmsManager, deliverysuccess) NS_IMPL_EVENT_HANDLER(SmsManager, deliveryerror) -/* static */ -bool -SmsManager::CreationIsAllowed(nsPIDOMWindow* aWindow) +/* static */already_AddRefed +SmsManager::CreateInstanceIfAllowed(nsPIDOMWindow* aWindow) { NS_ASSERTION(aWindow, "Null pointer!"); #ifndef MOZ_WEBSMS_BACKEND - return false; + return nullptr; #endif // First of all, the general pref has to be turned on. bool enabled = false; Preferences::GetBool("dom.sms.enabled", &enabled); - NS_ENSURE_TRUE(enabled, false); + NS_ENSURE_TRUE(enabled, nullptr); nsCOMPtr permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); - NS_ENSURE_TRUE(permMgr, false); + NS_ENSURE_TRUE(permMgr, nullptr); uint32_t permission = nsIPermissionManager::DENY_ACTION; permMgr->TestPermissionFromWindow(aWindow, "sms", &permission); if (permission != nsIPermissionManager::ALLOW_ACTION) { - return false; + return nullptr; } // Check the Sms Service: nsCOMPtr smsService = do_GetService(SMS_SERVICE_CONTRACTID); - NS_ENSURE_TRUE(smsService, false); + NS_ENSURE_TRUE(smsService, nullptr); bool result = false; smsService->HasSupport(&result); if (!result) { - return false; + return nullptr; } - return true; -} - -// static -already_AddRefed -SmsManager::CreateInstance(nsPIDOMWindow* aWindow) -{ nsRefPtr smsMgr = new SmsManager(); smsMgr->Init(aWindow); diff --git a/dom/mobilemessage/src/SmsManager.h b/dom/mobilemessage/src/SmsManager.h index 622092527130..d69c0c14746e 100644 --- a/dom/mobilemessage/src/SmsManager.h +++ b/dom/mobilemessage/src/SmsManager.h @@ -27,10 +27,7 @@ public: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper) static already_AddRefed - CreateInstance(nsPIDOMWindow *aWindow); - - static bool - CreationIsAllowed(nsPIDOMWindow *aWindow); + CreateInstanceIfAllowed(nsPIDOMWindow *aWindow); void Init(nsPIDOMWindow *aWindow); void Shutdown(); diff --git a/dom/mobilemessage/tests/test_sms_basics.html b/dom/mobilemessage/tests/test_sms_basics.html index 7927c808c068..5d0deb3a66d3 100644 --- a/dom/mobilemessage/tests/test_sms_basics.html +++ b/dom/mobilemessage/tests/test_sms_basics.html @@ -16,9 +16,8 @@ /** Test for WebSMS **/ function checkSmsDisabled() { - ok(!('mozSms' in frames[0].navigator), "navigator.mozSms should not exist"); - ok(frames[0].navigator.mozSms === undefined, - "navigator.mozSms should return undefined"); + ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist"); + is(frames[0].navigator.mozSms, null, "navigator.mozSms should return null"); } function checkSmsEnabled() { diff --git a/dom/power/PowerManager.cpp b/dom/power/PowerManager.cpp index e13f47862a8d..139a0f8639c5 100644 --- a/dom/power/PowerManager.cpp +++ b/dom/power/PowerManager.cpp @@ -179,27 +179,23 @@ PowerManager::SetCpuSleepAllowed(bool aAllowed) return NS_OK; } -bool -PowerManager::CheckPermission(nsPIDOMWindow* aWindow) +already_AddRefed +PowerManager::CheckPermissionAndCreateInstance(nsPIDOMWindow* aWindow) { nsCOMPtr permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); - NS_ENSURE_TRUE(permMgr, false); + NS_ENSURE_TRUE(permMgr, nullptr); uint32_t permission = nsIPermissionManager::DENY_ACTION; permMgr->TestPermissionFromWindow(aWindow, "power", &permission); - return permission == nsIPermissionManager::ALLOW_ACTION; -} - -already_AddRefed -PowerManager::CreateInstance(nsPIDOMWindow* aWindow) -{ - nsRefPtr powerManager = new PowerManager(); - if (NS_FAILED(powerManager->Init(aWindow))) { - powerManager = nullptr; + if (permission != nsIPermissionManager::ALLOW_ACTION) { + return nullptr; } + nsRefPtr powerManager = new PowerManager(); + powerManager->Init(aWindow); + return powerManager.forget(); } diff --git a/dom/power/PowerManager.h b/dom/power/PowerManager.h index a68456eb8cbd..4bec150a665b 100644 --- a/dom/power/PowerManager.h +++ b/dom/power/PowerManager.h @@ -33,9 +33,8 @@ public: nsresult Init(nsIDOMWindow *aWindow); nsresult Shutdown(); - static bool CheckPermission(nsPIDOMWindow*); - - static already_AddRefed CreateInstance(nsPIDOMWindow*); + static already_AddRefed + CheckPermissionAndCreateInstance(nsPIDOMWindow*); private: diff --git a/dom/telephony/Telephony.cpp b/dom/telephony/Telephony.cpp index f560918573ec..c37d384016d8 100644 --- a/dom/telephony/Telephony.cpp +++ b/dom/telephony/Telephony.cpp @@ -117,47 +117,29 @@ Telephony::~Telephony() // static already_AddRefed -Telephony::Create(nsPIDOMWindow* aOwner, ErrorResult& aRv) +Telephony::Create(nsPIDOMWindow* aOwner, nsITelephonyProvider* aProvider) { NS_ASSERTION(aOwner, "Null owner!"); - - nsCOMPtr ril = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); - if (!ril) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + NS_ASSERTION(aProvider, "Null provider!"); nsCOMPtr sgo = do_QueryInterface(aOwner); - if (!sgo) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + NS_ENSURE_TRUE(sgo, nullptr); nsCOMPtr scriptContext = sgo->GetContext(); - if (!scriptContext) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } + NS_ENSURE_TRUE(scriptContext, nullptr); nsRefPtr telephony = new Telephony(); telephony->BindToOwner(aOwner); - telephony->mProvider = ril; + telephony->mProvider = aProvider; telephony->mListener = new Listener(telephony); - nsresult rv = ril->EnumerateCalls(telephony->mListener); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return nullptr; - } + nsresult rv = aProvider->EnumerateCalls(telephony->mListener); + NS_ENSURE_SUCCESS(rv, nullptr); - rv = ril->RegisterTelephonyMsg(telephony->mListener); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return nullptr; - } + rv = aProvider->RegisterTelephonyMsg(telephony->mListener); + NS_ENSURE_SUCCESS(rv, nullptr); return telephony.forget(); } @@ -592,24 +574,36 @@ Telephony::EnqueueEnumerationAck() } } -/* static */ -bool -Telephony::CheckPermission(nsPIDOMWindow* aWindow) +nsresult +NS_NewTelephony(nsPIDOMWindow* aWindow, nsIDOMTelephony** aTelephony) { - MOZ_ASSERT(aWindow && aWindow->IsInnerWindow()); + NS_ASSERTION(aWindow, "Null pointer!"); + + nsPIDOMWindow* innerWindow = aWindow->IsInnerWindow() ? + aWindow : + aWindow->GetCurrentInnerWindow(); nsCOMPtr permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); - NS_ENSURE_TRUE(permMgr, false); + NS_ENSURE_TRUE(permMgr, NS_ERROR_UNEXPECTED); uint32_t permission; nsresult rv = permMgr->TestPermissionFromWindow(aWindow, "telephony", &permission); - NS_ENSURE_SUCCESS(rv, false); + NS_ENSURE_SUCCESS(rv, rv); if (permission != nsIPermissionManager::ALLOW_ACTION) { - return false; + *aTelephony = nullptr; + return NS_OK; } - return true; + nsCOMPtr ril = + do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + NS_ENSURE_TRUE(ril, NS_ERROR_UNEXPECTED); + + nsRefPtr telephony = Telephony::Create(innerWindow, ril); + NS_ENSURE_TRUE(telephony, NS_ERROR_UNEXPECTED); + + telephony.forget(aTelephony); + return NS_OK; } diff --git a/dom/telephony/Telephony.h b/dom/telephony/Telephony.h index 1062c2634f5d..957a1bc6f486 100644 --- a/dom/telephony/Telephony.h +++ b/dom/telephony/Telephony.h @@ -8,9 +8,6 @@ #define mozilla_dom_telephony_telephony_h__ #include "TelephonyCommon.h" -// Need to include TelephonyCall.h because we have inline methods that -// assume they see the definition of TelephonyCall. -#include "TelephonyCall.h" #include "nsIDOMTelephony.h" #include "nsIDOMTelephonyCall.h" @@ -59,9 +56,7 @@ public: nsDOMEventTargetHelper) static already_AddRefed - Create(nsPIDOMWindow* aOwner, ErrorResult& aRv); - - static bool CheckPermission(nsPIDOMWindow* aOwner); + Create(nsPIDOMWindow* aOwner, nsITelephonyProvider* aProvider); nsISupports* ToISupports() diff --git a/dom/telephony/TelephonyFactory.h b/dom/telephony/TelephonyFactory.h new file mode 100644 index 000000000000..1295e78bc74f --- /dev/null +++ b/dom/telephony/TelephonyFactory.h @@ -0,0 +1,18 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=2 et sw=2 tw=40: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_telephony_telephonyfactory_h__ +#define mozilla_dom_telephony_telephonyfactory_h__ + +#include "nsIDOMTelephony.h" +#include "nsPIDOMWindow.h" + +// Implemented in Telephony.cpp. + +nsresult +NS_NewTelephony(nsPIDOMWindow* aWindow, nsIDOMTelephony** aTelephony); + +#endif // mozilla_dom_telephony_telephonyfactory_h__ diff --git a/dom/tests/mochitest/general/test_idleapi_permissions.html b/dom/tests/mochitest/general/test_idleapi_permissions.html index fac100b55de3..e0ef7cbde79c 100644 --- a/dom/tests/mochitest/general/test_idleapi_permissions.html +++ b/dom/tests/mochitest/general/test_idleapi_permissions.html @@ -17,28 +17,23 @@ var idleObserver = { onactive: null }; -function doAddIdleObserver(obs) { - var i = document.createElement("iframe"); - document.body.appendChild(i); - var added = false; - try { - i.contentWindow.navigator.addIdleObserver(obs); - added = true; - } catch (e) { } - i.remove(); - return added; -} - function run_test() { // addIdleObserver checks whether time is > 0. this.idleObserver.time = 100; - var added = doAddIdleObserver(this.idleObserver, false); + var added = false; + try { + navigator.addIdleObserver(this.idleObserver); + added = true; + } catch (e) { } ok(!added, "Should not be able to add idle observer without permission"); SpecialPowers.addPermission("idle", true, document); - - added = doAddIdleObserver(this.idleObserver, true); + added = false; + try { + navigator.addIdleObserver(this.idleObserver); + added = true; + } catch (e) { } ok(added, "Should be able to add idle observer with permission."); SimpleTest.finish(); diff --git a/dom/tests/mochitest/general/test_vibrator.html b/dom/tests/mochitest/general/test_vibrator.html index 5b29fc1c1d05..36ffe1aa51ad 100644 --- a/dom/tests/mochitest/general/test_vibrator.html +++ b/dom/tests/mochitest/general/test_vibrator.html @@ -35,12 +35,12 @@ function expectSuccess(param) { } function testFailures() { - expectSuccess(null); - expectSuccess(undefined); + expectFailure(null); + expectFailure(undefined); expectFailure(-1); - expectSuccess('a'); + expectFailure('a'); expectFailure([100, -1]); - expectSuccess([100, 'a']); + expectFailure([100, 'a']); var maxVibrateMs = SpecialPowers.getIntPref('dom.vibrator.max_vibrate_ms'); var maxVibrateListLen = SpecialPowers.getIntPref('dom.vibrator.max_vibrate_list_len'); diff --git a/dom/webidl/Navigator.webidl b/dom/webidl/Navigator.webidl deleted file mode 100644 index 191b9f059914..000000000000 --- a/dom/webidl/Navigator.webidl +++ /dev/null @@ -1,353 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * The origin of this IDL file is - * http://www.whatwg.org/specs/web-apps/current-work/#the-navigator-object - * http://www.w3.org/TR/tracking-dnt/ - * http://www.w3.org/TR/geolocation-API/#geolocation_interface - * http://www.w3.org/TR/battery-status/#navigatorbattery-interface - * http://www.w3.org/TR/vibration/#vibration-interface - * http://www.w3.org/2012/sysapps/runtime/#extension-to-the-navigator-interface-1 - * https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#navigator-interface-extension - * - * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and - * Opera Software ASA. You are granted a license to use, reproduce - * and create derivative works of this document. - */ - -interface MozPowerManager; -interface MozWakeLock; - -// http://www.whatwg.org/specs/web-apps/current-work/#the-navigator-object -[HeaderFile="Navigator.h", NeedNewResolve] -interface Navigator { - // objects implementing this interface also implement the interfaces given below -}; -Navigator implements NavigatorID; -Navigator implements NavigatorLanguage; -Navigator implements NavigatorOnLine; -Navigator implements NavigatorContentUtils; -Navigator implements NavigatorStorageUtils; - -[NoInterfaceObject] -interface NavigatorID { - readonly attribute DOMString appName; - [Throws] - readonly attribute DOMString appVersion; - [Throws] - readonly attribute DOMString platform; - [Throws] - readonly attribute DOMString userAgent; - - // Spec has this as a const, but that's wrong because it should not - // be on the interface object. - //const DOMString product = "Gecko"; // for historical reasons - readonly attribute DOMString product; -}; - -[NoInterfaceObject] -interface NavigatorLanguage { - readonly attribute DOMString? language; -}; - -[NoInterfaceObject] -interface NavigatorOnLine { - readonly attribute boolean onLine; -}; - -[NoInterfaceObject] -interface NavigatorContentUtils { - // content handler registration - [Throws] - void registerProtocolHandler(DOMString scheme, DOMString url, DOMString title); - [Throws] - void registerContentHandler(DOMString mimeType, DOMString url, DOMString title); - // NOT IMPLEMENTED - //DOMString isProtocolHandlerRegistered(DOMString scheme, DOMString url); - //DOMString isContentHandlerRegistered(DOMString mimeType, DOMString url); - //void unregisterProtocolHandler(DOMString scheme, DOMString url); - //void unregisterContentHandler(DOMString mimeType, DOMString url); -}; - -[NoInterfaceObject] -interface NavigatorStorageUtils { - // NOT IMPLEMENTED - //void yieldForStorageUpdates(); -}; - -// Things that definitely need to be in the spec and and are not for some -// reason. See https://www.w3.org/Bugs/Public/show_bug.cgi?id=22406 -partial interface Navigator { - [Throws] - readonly attribute MimeTypeArray mimeTypes; - [Throws] - readonly attribute PluginArray plugins; -}; - -// http://www.w3.org/TR/tracking-dnt/ sort of -partial interface Navigator { - readonly attribute DOMString doNotTrack; -}; - -// http://www.w3.org/TR/geolocation-API/#geolocation_interface -[NoInterfaceObject] -interface NavigatorGeolocation { - // XXXbz This should perhaps be controleld by the "geo.enabled" pref, instead - // of checking it in the C++. Let's not for now to reduce risk. - // Also, we violate the spec as a result, since we can return null. See bug - // 884921. - [Throws] - readonly attribute Geolocation? geolocation; -}; -Navigator implements NavigatorGeolocation; - -// http://www.w3.org/TR/battery-status/#navigatorbattery-interface -[NoInterfaceObject] -interface NavigatorBattery { - // XXXbz Per spec this should be non-nullable, but we return null in - // torn-down windows. See bug 884925. - [Throws, Func="Navigator::HasBatterySupport"] - readonly attribute BatteryManager? battery; -}; -Navigator implements NavigatorBattery; - -// http://www.w3.org/TR/vibration/#vibration-interface -partial interface Navigator { - // We don't support sequences in unions yet - //boolean vibrate ((unsigned long or sequence) pattern); - // XXXbz also, per spec we should be returning a boolean, and we just don't. - // See bug 884935. - [Throws] - void vibrate(unsigned long duration); - [Throws] - void vibrate(sequence pattern); -}; - -// Mozilla-specific extensions - -callback interface MozIdleObserver { - // Time is in seconds and is read only when idle observers are added - // and removed. - readonly attribute unsigned long time; - void onidle(); - void onactive(); -}; - -// nsIDOMNavigator -partial interface Navigator { - // WebKit/Blink/Trident/Presto support this (hardcoded "Mozilla"). - [Throws] - readonly attribute DOMString appCodeName; - [Throws] - readonly attribute DOMString oscpu; - // WebKit/Blink support this; Trident/Presto do not. - readonly attribute DOMString vendor; - // WebKit/Blink supports this (hardcoded ""); Trident/Presto do not. - readonly attribute DOMString vendorSub; - // WebKit/Blink supports this (hardcoded "20030107"); Trident/Presto don't - readonly attribute DOMString productSub; - // WebKit/Blink/Trident/Presto support this. - readonly attribute boolean cookieEnabled; - [Throws] - readonly attribute DOMString buildID; - [Throws, Func="Navigator::HasPowerSupport"] - readonly attribute MozPowerManager mozPower; - - // WebKit/Blink/Trident/Presto support this. - [Throws] - boolean javaEnabled(); - // Everyone but WebKit/Blink supports this. See bug 679971. - boolean taintEnabled(); - - /** - * Navigator requests to add an idle observer to the existing window. - */ - [Throws, Func="Navigator::HasIdleSupport"] - void addIdleObserver(MozIdleObserver aIdleObserver); - - /** - * Navigator requests to remove an idle observer from the existing window. - */ - [Throws, Func="Navigator::HasIdleSupport"] - void removeIdleObserver(MozIdleObserver aIdleObserver); - - /** - * Request a wake lock for a resource. - * - * A page holds a wake lock to request that a resource not be turned - * off (or otherwise made unavailable). - * - * The topic is the name of a resource that might be made unavailable for - * various reasons. For example, on a mobile device the power manager might - * decide to turn off the screen after a period of idle time to save power. - * - * The resource manager checks the lock state of a topic before turning off - * the associated resource. For example, a page could hold a lock on the - * "screen" topic to prevent the screensaver from appearing or the screen - * from turning off. - * - * The resource manager defines what each topic means and sets policy. For - * example, the resource manager might decide to ignore 'screen' wake locks - * held by pages which are not visible. - * - * One topic can be locked multiple times; it is considered released only when - * all locks on the topic have been released. - * - * The returned nsIDOMMozWakeLock object is a token of the lock. You can - * unlock the lock via the object's |unlock| method. The lock is released - * automatically when its associated window is unloaded. - * - * @param aTopic resource name - */ - [Throws, Func="Navigator::HasWakeLockSupport"] - MozWakeLock requestWakeLock(DOMString aTopic); -}; - -// nsIDOMNavigatorDeviceStorage -partial interface Navigator { - [Throws, Pref="device.storage.enabled"] - DeviceStorage? getDeviceStorage(DOMString type); - [Throws, Pref="device.storage.enabled"] - sequence getDeviceStorages(DOMString type); -}; - -// nsIDOMNavigatorDesktopNotification -partial interface Navigator { - [Throws, Func="Navigator::HasDesktopNotificationSupport"] - readonly attribute DesktopNotificationCenter mozNotification; -}; - -// nsIDOMClientInformation -partial interface Navigator { - [Throws] - boolean mozIsLocallyAvailable(DOMString uri, boolean whenOffline); -}; - -// nsIDOMMozNavigatorSms -interface MozSmsManager; -partial interface Navigator { - [Func="Navigator::HasSmsSupport"] - readonly attribute MozSmsManager? mozSms; -}; - -// nsIDOMMozNavigatorMobileMessage -interface MozMobileMessageManager; -partial interface Navigator { - [Func="Navigator::HasMobileMessageSupport"] - readonly attribute MozMobileMessageManager? mozMobileMessage; -}; - -// nsIDOMMozNavigatorNetwork -interface MozConnection; -partial interface Navigator { - readonly attribute MozConnection? mozConnection; -}; - -// nsIDOMNavigatorCamera -partial interface Navigator { - [Throws, Func="Navigator::HasCameraSupport"] - readonly attribute CameraManager mozCameras; -}; - -// nsIDOMNavigatorSystemMessages and sort of maybe -// http://www.w3.org/2012/sysapps/runtime/#extension-to-the-navigator-interface-1 -callback systemMessageCallback = void (optional object message); -partial interface Navigator { - [Throws, Pref="dom.sysmsg.enabled"] - void mozSetMessageHandler (DOMString type, systemMessageCallback? callback); - [Throws, Pref="dom.sysmsg.enabled"] - boolean mozHasPendingMessage (DOMString type); -}; - -#ifdef MOZ_B2G_RIL -interface MozTelephony; -// nsIDOMNavigatorTelephony -partial interface Navigator { - [Throws, Func="Navigator::HasTelephonySupport"] - readonly attribute MozTelephony? mozTelephony; -}; - -// nsIMozNavigatorMobileConnection -interface MozMobileConnection; -partial interface Navigator { - [Throws, Func="Navigator::HasMobileConnectionSupport"] - readonly attribute MozMobileConnection mozMobileConnection; -}; - -// nsIMozNavigatorCellBroadcast -interface MozCellBroadcast; -partial interface Navigator { - [Throws, Func="Navigator::HasCellBroadcastSupport"] - readonly attribute MozCellBroadcast mozCellBroadcast; -}; - -// nsIMozNavigatorVoicemail -interface MozVoicemail; -partial interface Navigator { - [Throws, Func="Navigator::HasVoicemailSupport"] - readonly attribute MozVoicemail mozVoicemail; -}; - -// nsIMozNavigatorIccManager -interface MozIccManager; -partial interface Navigator { - [Throws, Func="Navigator::HasIccManagerSupport"] - readonly attribute MozIccManager? mozIccManager; -}; -#endif // MOZ_B2G_RIL - -#ifdef MOZ_GAMEPAD -// https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#navigator-interface-extension -partial interface Navigator { - [Throws, Pref="dom.gamepad.enabled"] - sequence getGamepads(); -}; -#endif // MOZ_GAMEPAD - -#ifdef MOZ_B2G_BT -// nsIDOMNavigatorBluetooth -interface MozBluetoothManager; -partial interface Navigator { - [Throws, Func="Navigator::HasBluetoothSupport"] - readonly attribute MozBluetoothManager mozBluetooth; -}; -#endif // MOZ_B2G_BT - -#ifdef MOZ_TIME_MANAGER -// nsIDOMMozNavigatorTime -partial interface Navigator { - [Throws, Func="Navigator::HasTimeSupport"] - readonly attribute MozTimeManager mozTime; -}; -#endif // MOZ_TIME_MANAGER - -#ifdef MOZ_AUDIO_CHANNEL_MANAGER -// nsIMozNavigatorAudioChannelManager -partial interface Navigator { - [Throws] - readonly attribute AudioChannelManager mozAudioChannelManager; -}; -#endif // MOZ_AUDIO_CHANNEL_MANAGER - -#ifdef MOZ_MEDIA_NAVIGATOR -// nsIDOMNavigatorUserMedia -callback MozDOMGetUserMediaSuccessCallback = void (nsISupports? value); -callback MozDOMGetUserMediaErrorCallback = void (DOMString error); -interface MozMediaStreamOptions; -partial interface Navigator { - [Throws, Func="Navigator::HasUserMediaSupport"] - void mozGetUserMedia(MozMediaStreamOptions? params, - MozDOMGetUserMediaSuccessCallback? onsuccess, - MozDOMGetUserMediaErrorCallback? onerror); -}; - -// nsINavigatorUserMedia -callback MozGetUserMediaDevicesSuccessCallback = void (nsIVariant? devices); -partial interface Navigator { - [Throws, ChromeOnly] - void mozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback? onsuccess, - MozDOMGetUserMediaErrorCallback? onerror); -}; -#endif // MOZ_MEDIA_NAVIGATOR diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 14815df22817..2763dce7fde4 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -8,10 +8,6 @@ generated_webidl_files = \ CSS2Properties.webidl \ $(NULL) -preprocessed_webidl_files = \ - Navigator.webidl \ - $(NULL) - webidl_files = \ AnalyserNode.webidl \ AnimationEvent.webidl \ diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 0ad7f4aba0e2..b9e6ff26ff8e 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -1158,8 +1158,8 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate) } else { if (!mNavigatorStringsLoaded) { - NS_GetNavigatorAppName(mNavigatorStrings.mAppName); - if (NS_FAILED(NS_GetNavigatorAppVersion(mNavigatorStrings.mAppVersion)) || + if (NS_FAILED(NS_GetNavigatorAppName(mNavigatorStrings.mAppName)) || + NS_FAILED(NS_GetNavigatorAppVersion(mNavigatorStrings.mAppVersion)) || NS_FAILED(NS_GetNavigatorPlatform(mNavigatorStrings.mPlatform)) || NS_FAILED(NS_GetNavigatorUserAgent(mNavigatorStrings.mUserAgent))) { JS_ReportError(aCx, "Failed to load navigator strings!"); diff --git a/dom/workers/test/test_navigator.html b/dom/workers/test/test_navigator.html index ccace0e446d1..689c1d9630a3 100644 --- a/dom/workers/test/test_navigator.html +++ b/dom/workers/test/test_navigator.html @@ -35,8 +35,7 @@ Tests of DOM Worker Navigator return; } - is(navigator[args.name], args.value, - "Mismatched navigator string for " + args.name + "!"); + is(navigator[args.name], args.value, "Mismatched navigator string!"); }; worker.onerror = function(event) { diff --git a/js/xpconnect/tests/chrome/test_weakmaps.xul b/js/xpconnect/tests/chrome/test_weakmaps.xul index 19dab9c6f2b7..714ac26705da 100644 --- a/js/xpconnect/tests/chrome/test_weakmaps.xul +++ b/js/xpconnect/tests/chrome/test_weakmaps.xul @@ -221,17 +221,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=668855 let dummy_test_map = new WeakMap; - let rule_fail = false; - let got_rule = false; + let navi_fail = false; try { - var rule = document.styleSheets[0].cssRules[0]; - got_rule = true; - dummy_test_map.set(rule, 1); + dummy_test_map.set(window.navigator, 1); } catch (e) { - rule_fail = true; + navi_fail = true; } - ok(got_rule, "Got the CSS rule"); - ok(rule_fail, "Using a CSS rule as a weak map key should produce an exception because it can't be wrapper preserved."); + ok(navi_fail, "Using window.navigator as a weak map key should produce an exception because it can't be wrapper preserved."); } diff --git a/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html b/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html index b25cdb2f90e1..127c479ebe0e 100644 --- a/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html +++ b/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html @@ -1,7 +1,6 @@ - Test Cross-Compartment DOM WeakMaps diff --git a/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html index 894b88569e57..3c12de4a896d 100644 --- a/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html +++ b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html @@ -16,13 +16,13 @@ function setup() { my_map.set(item, "success_string"); - var rule_fail = false; + var navi_fail = false; try { - my_map.set(window.frames[0].document.styleSheets[0].cssRules[0], 1); + my_map.set(window.frames[0].navigator, 1); } catch (e) { - rule_fail = true; + navi_fail = true; } - ok(rule_fail, "Using rule as a weak map key across compartments should produce an exception because it can't be wrapper preserved."); + ok(navi_fail, "Using window.navigator as a weak map key across compartments should produce an exception because it can't be wrapper preserved."); } function runTest() {