diff --git a/dom/bluetooth/BluetoothService.cpp b/dom/bluetooth/BluetoothService.cpp index b535872044fb..93bbd1077be3 100644 --- a/dom/bluetooth/BluetoothService.cpp +++ b/dom/bluetooth/BluetoothService.cpp @@ -195,7 +195,7 @@ 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()); @@ -213,7 +213,7 @@ public: 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; diff --git a/dom/interfaces/settings/nsISettingsService.idl b/dom/interfaces/settings/nsISettingsService.idl index 77551dc8607a..e06739a059b6 100644 --- a/dom/interfaces/settings/nsISettingsService.idl +++ b/dom/interfaces/settings/nsISettingsService.idl @@ -4,12 +4,10 @@ #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); }; diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 014b4e7210ec..78d487a9e942 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -89,7 +89,7 @@ public: 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()); @@ -103,7 +103,7 @@ public: 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 "'"); diff --git a/dom/system/gonk/AutoMounterSetting.cpp b/dom/system/gonk/AutoMounterSetting.cpp index 3a824a358cba..373f328a1973 100644 --- a/dom/system/gonk/AutoMounterSetting.cpp +++ b/dom/system/gonk/AutoMounterSetting.cpp @@ -35,7 +35,7 @@ public: 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); @@ -43,7 +43,7 @@ public: 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; } diff --git a/dom/system/gonk/GonkGPSGeolocationProvider.cpp b/dom/system/gonk/GonkGPSGeolocationProvider.cpp index 3d7e552afde7..53da1a71d8f4 100644 --- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp +++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp @@ -28,6 +28,7 @@ #include "nsJSUtils.h" #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" +#include "nsContentUtils.h" #ifdef AGPS_TYPE_INVALID #define AGPS_HAVE_DUAL_APN @@ -659,10 +660,13 @@ GonkGPSGeolocationProvider::ReceiveDataCallList(nsIRILDataCallInfo** aDataCalls, 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; @@ -676,8 +680,7 @@ GonkGPSGeolocationProvider::Handle(const nsAString& aName, } NS_IMETHODIMP -GonkGPSGeolocationProvider::HandleError(const nsAString& aErrorMessage, - JSContext* cx) +GonkGPSGeolocationProvider::HandleError(const nsAString& aErrorMessage) { return NS_OK; } diff --git a/dom/system/gonk/TimeZoneSettingObserver.cpp b/dom/system/gonk/TimeZoneSettingObserver.cpp index d1c9443362e0..48cd78502137 100644 --- a/dom/system/gonk/TimeZoneSettingObserver.cpp +++ b/dom/system/gonk/TimeZoneSettingObserver.cpp @@ -20,6 +20,7 @@ #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) @@ -50,7 +51,13 @@ public: 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 @@ -59,7 +66,7 @@ public: // 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 lock; @@ -76,13 +83,13 @@ public: // 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; } diff --git a/xpcom/tests/TestSettingsAPI.cpp b/xpcom/tests/TestSettingsAPI.cpp index 178eba50380a..de6241bda9db 100644 --- a/xpcom/tests/TestSettingsAPI.cpp +++ b/xpcom/tests/TestSettingsAPI.cpp @@ -58,7 +58,7 @@ public: 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); @@ -87,7 +87,7 @@ public: 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;