Bug 811414 - nsISettingsServiceCallback shouldn't use [implicit_jscontext]. r=bholley
authorGregor Wagner <anygregor@gmail.com>
Wed, 14 Nov 2012 13:00:51 -0800
changeset 113281 d6f4b5d48c73c681a860f9bc4631c46ea1ace7c1
parent 113280 4789d67c601738d05935747991ae157b2385d03e
child 113282 da25394a8b5524956813c8831cd1e75a893d78f1
push id1997
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 21:25:26 +0000
treeherdermozilla-esr52@cf8750abee06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs811414
milestone19.0a1
Bug 811414 - nsISettingsServiceCallback shouldn't use [implicit_jscontext]. r=bholley
dom/bluetooth/BluetoothService.cpp
dom/interfaces/settings/nsISettingsService.idl
dom/src/geolocation/nsGeolocation.cpp
dom/system/gonk/AutoMounterSetting.cpp
dom/system/gonk/GonkGPSGeolocationProvider.cpp
dom/system/gonk/TimeZoneSettingObserver.cpp
xpcom/tests/TestSettingsAPI.cpp
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -190,17 +190,17 @@ private:
   bool mEnabled;
 };
 
 class BluetoothService::StartupTask : public nsISettingsServiceCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
-  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult, JSContext* aCx)
+  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     if (!aResult.isBoolean()) {
       NS_WARNING("Setting for '" BLUETOOTH_ENABLED_SETTING "' is not a boolean!");
       return NS_OK;
     }
 
@@ -208,17 +208,17 @@ public:
     // has completed (though extremely unlikely).
     if (gBluetoothService) {
       return gBluetoothService->HandleStartupSettingsCheck(aResult.toBoolean());
     }
 
     return NS_OK;
   }
 
-  NS_IMETHOD HandleError(const nsAString& aName, JSContext* aCx)
+  NS_IMETHOD HandleError(const nsAString& aName)
   {
     NS_WARNING("Unable to get value for '" BLUETOOTH_ENABLED_SETTING "'");
     return NS_OK;
   }
 };
 
 NS_IMPL_ISUPPORTS1(BluetoothService::StartupTask, nsISettingsServiceCallback);
 
--- a/dom/interfaces/settings/nsISettingsService.idl
+++ b/dom/interfaces/settings/nsISettingsService.idl
@@ -1,20 +1,18 @@
 /* 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/. */
 
 #include "domstubs.idl"
 
-[scriptable, uuid(83d67430-8516-11e1-b0c4-0800200c9a66)]
+[scriptable, uuid(aad47850-2e87-11e2-81c1-0800200c9a66)]
 interface nsISettingsServiceCallback : nsISupports
 {
-  [implicit_jscontext]
   void handle(in DOMString aName, in jsval aResult);
-  [implicit_jscontext]
   void handleError(in DOMString aErrorMessage);
 };
 
 [scriptable, uuid(d7a395a0-e292-11e1-834e-1761d57f5f99)]
 interface nsISettingsServiceLock : nsISupports
 {
   void set(in string aName,
            in jsval aValue,
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -84,31 +84,31 @@ public:
   GeolocationSettingsCallback() {
     MOZ_COUNT_CTOR(GeolocationSettingsCallback);
   }
 
   virtual ~GeolocationSettingsCallback() {
     MOZ_COUNT_DTOR(GeolocationSettingsCallback);
   }
 
-  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult, JSContext* aCx)
+  NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     // The geolocation is enabled by default:
     bool value = true;
     if (aResult.isBoolean()) {
       value = aResult.toBoolean();
     }
 
     MozSettingValue(value);
     return NS_OK;
   }
 
-  NS_IMETHOD HandleError(const nsAString& aName, JSContext* aCx)
+  NS_IMETHOD HandleError(const nsAString& aName)
   {
     NS_WARNING("Unable to get value for '" GEO_SETINGS_ENABLED "'");
 
     // Default it's enabled:
     MozSettingValue(true);
     return NS_OK;
   }
 
--- a/dom/system/gonk/AutoMounterSetting.cpp
+++ b/dom/system/gonk/AutoMounterSetting.cpp
@@ -30,25 +30,25 @@ namespace system {
 
 class SettingsServiceCallback MOZ_FINAL : public nsISettingsServiceCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
   SettingsServiceCallback() {}
 
-  NS_IMETHOD Handle(const nsAString &aName, const JS::Value &aResult, JSContext *aContext) {
+  NS_IMETHOD Handle(const nsAString &aName, const JS::Value &aResult) {
     if (JSVAL_IS_INT(aResult)) {
       int32_t mode = JSVAL_TO_INT(aResult);
       SetAutoMounterMode(mode);
     }
     return NS_OK;
   }
 
-  NS_IMETHOD HandleError(const nsAString &aName, JSContext *aContext) {
+  NS_IMETHOD HandleError(const nsAString &aName) {
     ERR("SettingsCallback::HandleError: %s\n", NS_LossyConvertUTF16toASCII(aName).get());
     return NS_OK;
   }
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(SettingsServiceCallback, nsISettingsServiceCallback)
 
 AutoMounterSetting::AutoMounterSetting()
--- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp
@@ -23,16 +23,17 @@
 #include "nsGeoPosition.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsINetworkManager.h"
 #include "nsIRadioInterfaceLayer.h"
 #include "nsIDOMMobileConnection.h"
 #include "nsJSUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
+#include "nsContentUtils.h"
 
 #ifdef AGPS_TYPE_INVALID
 #define AGPS_HAVE_DUAL_APN
 #endif
 
 #define DEBUG_GPS 0
 
 using namespace mozilla;
@@ -654,30 +655,32 @@ GonkGPSGeolocationProvider::ReceiveDataC
 {
   return NS_OK;
 }
 
 /** nsISettingsServiceCallback **/
 
 NS_IMETHODIMP
 GonkGPSGeolocationProvider::Handle(const nsAString& aName,
-                                   const JS::Value& aResult,
-                                   JSContext* cx)
+                                   const JS::Value& aResult)
 {
   if (aName.EqualsLiteral("ril.supl.apn")) {
+    JSContext *cx = nsContentUtils::GetSafeJSContext();
+    NS_ENSURE_TRUE(cx, NS_OK);
+    JSAutoRequest ar(cx);
+    JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(aResult));
     // When we get the APN, we attempt to call data_call_open of AGPS.
     if (aResult.isString()) {
       nsDependentJSString apn;
       apn.init(cx, aResult.toString());
       if (!apn.IsEmpty()) {
         SetAGpsDataConn(apn);
       }
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-GonkGPSGeolocationProvider::HandleError(const nsAString& aErrorMessage,
-                                        JSContext* cx)
+GonkGPSGeolocationProvider::HandleError(const nsAString& aErrorMessage)
 {
   return NS_OK;
 }
--- a/dom/system/gonk/TimeZoneSettingObserver.cpp
+++ b/dom/system/gonk/TimeZoneSettingObserver.cpp
@@ -15,16 +15,17 @@
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsISettingsService.h"
 #include "nsJSUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "TimeZoneSettingObserver.h"
 #include "xpcpublic.h"
+#include "nsContentUtils.h"
 
 #undef LOG
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Time Zone Setting" , ## args)
 #define ERR(args...)  __android_log_print(ANDROID_LOG_ERROR, "Time Zone Setting" , ## args)
 
 #define TIME_TIMEZONE       "time.timezone"
 #define MOZSETTINGS_CHANGED "mozsettings-changed"
 
@@ -45,49 +46,55 @@ public:
 
 class TimeZoneSettingCb MOZ_FINAL : public nsISettingsServiceCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
   TimeZoneSettingCb() {}
 
-  NS_IMETHOD Handle(const nsAString &aName, const JS::Value &aResult, JSContext *aContext) {
+  NS_IMETHOD Handle(const nsAString &aName, const JS::Value &aResult) {
+
+    JSContext *cx = nsContentUtils::GetSafeJSContext();
+    NS_ENSURE_TRUE(cx, NS_OK);
+    JSAutoRequest ar(cx);
+    JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(aResult));
+
     // If we don't have time.timezone value in the settings, we need
     // to initialize the settings based on the current system timezone
     // to make settings consistent with system. This usually happens
     // at the very first boot. After that, settings must have a value.
     if (aResult.isNull()) {
       // Get the current system timezone and convert it to a JS string.
       nsCString curTimezone = hal::GetTimezone();
       NS_ConvertUTF8toUTF16 utf16Str(curTimezone);
-      JSString *jsStr = JS_NewUCStringCopyN(aContext, utf16Str.get(), utf16Str.Length());
+      JSString *jsStr = JS_NewUCStringCopyN(cx, utf16Str.get(), utf16Str.Length());
 
       // Set the settings based on the current system timezone.
       nsCOMPtr<nsISettingsServiceLock> lock;
       nsCOMPtr<nsISettingsService> settingsService =
         do_GetService("@mozilla.org/settingsService;1");
       if (!settingsService) {
         ERR("Failed to get settingsLock service!");
         return NS_OK;
       }
       settingsService->CreateLock(getter_AddRefs(lock));
       lock->Set(TIME_TIMEZONE, STRING_TO_JSVAL(jsStr), nullptr, nullptr);
       return NS_OK;
     }
 
     // Set the system timezone based on the current settings.
     if (aResult.isString()) {
-      return TimeZoneSettingObserver::SetTimeZone(aResult, aContext);
+      return TimeZoneSettingObserver::SetTimeZone(aResult, cx);
     }
 
     return NS_OK;
   }
 
-  NS_IMETHOD HandleError(const nsAString &aName, JSContext *aContext) {
+  NS_IMETHOD HandleError(const nsAString &aName) {
     ERR("TimeZoneSettingCb::HandleError: %s\n", NS_LossyConvertUTF16toASCII(aName).get());
     return NS_OK;
   }
 };
 
 NS_IMPL_ISUPPORTS1(TimeZoneSettingCb, nsISettingsServiceCallback)
 
 TimeZoneSettingObserver::TimeZoneSettingObserver()
--- a/xpcom/tests/TestSettingsAPI.cpp
+++ b/xpcom/tests/TestSettingsAPI.cpp
@@ -53,17 +53,17 @@ typedef nsresult(*TestFuncPtr)();
 
 class SettingsServiceCallback MOZ_FINAL : public nsISettingsServiceCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
   SettingsServiceCallback() { }
 
-  NS_IMETHOD Handle(const nsAString &name, const JS::Value &result, JSContext *cx) {
+  NS_IMETHOD Handle(const nsAString &name, const JS::Value &result) {
     if (callbackCount == 9) {
       CHECK(JSVAL_IS_BOOLEAN(result));
       CHECK(JSVAL_TO_BOOLEAN(result) == true);
       passed("boolean");
     } else if (callbackCount == 7) {
       CHECK(JSVAL_IS_BOOLEAN(result));
       CHECK(JSVAL_TO_BOOLEAN(result) == false);
       passed("Lock order");
@@ -82,17 +82,17 @@ public:
     } else if (callbackCount == 1) {
       CHECK(JSVAL_IS_NULL(result));
       passed("null");
     }
     callbackCount--;
     return NS_OK;
   };
 
-  NS_IMETHOD HandleError(const nsAString &name, JSContext *cx) {
+  NS_IMETHOD HandleError(const nsAString &name) {
     fprintf(stderr, "HANDLE Error! %s\n", NS_LossyConvertUTF16toASCII(name).get());
     errors++;
     return NS_OK;
   };
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(SettingsServiceCallback, nsISettingsServiceCallback)