Bug 1070083 - Part 1: Use the right compartment in MobileConnection code. r=bholley
authorEdgar Chen <echen@mozilla.com>
Tue, 23 Sep 2014 15:25:54 +0800
changeset 230445 90fc951b321c0d4c07835859c7522b34bfec4f68
parent 230444 a310fa4efd9c0da39b83ea695ad54b7a7f04af61
child 230446 10346199c21b5c5b33d979dbd6044951aea9c3cf
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1070083
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1070083 - Part 1: Use the right compartment in MobileConnection code. r=bholley
dom/mobileconnection/MobileConnectionCallback.cpp
dom/mobileconnection/interfaces/nsIMobileConnectionService.idl
dom/mobileconnection/ipc/MobileConnectionChild.cpp
dom/mobileconnection/ipc/MobileConnectionParent.cpp
--- a/dom/mobileconnection/MobileConnectionCallback.cpp
+++ b/dom/mobileconnection/MobileConnectionCallback.cpp
@@ -226,23 +226,25 @@ MobileConnectionCallback::NotifyGetNetwo
     JS_ClearPendingException(cx);
     return NS_ERROR_TYPE_ERR;
   }
 
   return NotifySuccess(jsResult);
 }
 
 NS_IMETHODIMP
-MobileConnectionCallback::NotifySendCancelMmiSuccess(JS::Handle<JS::Value> aResult)
+MobileConnectionCallback::NotifySendCancelMmiSuccess(JS::Handle<JS::Value> aResult,
+                                                     JSContext* aCx)
 {
   return NotifySuccess(aResult);
 }
 
 NS_IMETHODIMP
-MobileConnectionCallback::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults)
+MobileConnectionCallback::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults,
+                                                         JSContext* aCx)
 {
   return NotifySuccess(aResults);
 }
 
 NS_IMETHODIMP
 MobileConnectionCallback::NotifyGetCallBarringSuccess(uint16_t aProgram,
                                                       bool aEnabled,
                                                       uint16_t aServiceClass)
--- a/dom/mobileconnection/interfaces/nsIMobileConnectionService.idl
+++ b/dom/mobileconnection/interfaces/nsIMobileConnectionService.idl
@@ -119,33 +119,35 @@ interface nsIMobileConnectionListener : 
    */
   void notifyNetworkSelectionModeChanged();
 };
 
 %{C++
 #define NO_ADDITIONAL_INFORMATION 0
 %}
 
-[scriptable, builtinclass, uuid(e9d7c247-34c6-42bf-875b-f99b19db394f)]
+[scriptable, builtinclass, uuid(7f2dbbe0-42f2-11e4-916c-0800200c9a66)]
 interface nsIMobileConnectionCallback : nsISupports
 {
   /**
    * notify*Success*() will be called, when request is succeed.
    */
   void notifySuccess();
 
   void notifySuccessWithString(in DOMString result);
 
   void notifySuccessWithBoolean(in boolean result);
 
   void notifyGetNetworksSuccess(in uint32_t count,
                                 [array, size_is(count)] in nsIMobileNetworkInfo networks);
 
+  [implicit_jscontext]
   void notifySendCancelMmiSuccess(in jsval result /* MozMMIResult */);
 
+  [implicit_jscontext]
   void notifyGetCallForwardingSuccess(in jsval results /* Array of MozCallForwardingOptions */);
 
   void notifyGetCallBarringSuccess(in unsigned short program,
                                    in boolean enabled,
                                    in unsigned short serviceClass);
 
   void notifyGetClirStatusSuccess(in unsigned short n, in unsigned short m);
 
--- a/dom/mobileconnection/ipc/MobileConnectionChild.cpp
+++ b/dom/mobileconnection/ipc/MobileConnectionChild.cpp
@@ -237,17 +237,22 @@ MobileConnectionChild::CancelMMI(nsIMobi
 {
   return SendRequest(CancelMmiRequest(), aCallback) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 MobileConnectionChild::SetCallForwarding(JS::Handle<JS::Value> aOptions,
                                          nsIMobileConnectionCallback* aCallback)
 {
-  AutoSafeJSContext cx;
+  AutoJSAPI jsapi;
+  if (!NS_WARN_IF(jsapi.Init(&aOptions.toObject()))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  JSContext* cx = jsapi.cx();
   IPC::MozCallForwardingOptions options;
   if(!options.Init(cx, aOptions)) {
     return NS_ERROR_TYPE_ERR;
   }
 
   return SendRequest(SetCallForwardingRequest(options), aCallback)
     ? NS_OK : NS_ERROR_FAILURE;
 }
@@ -259,45 +264,60 @@ MobileConnectionChild::GetCallForwarding
   return SendRequest(GetCallForwardingRequest(aReason), aCallback)
     ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 MobileConnectionChild::SetCallBarring(JS::Handle<JS::Value> aOptions,
                                       nsIMobileConnectionCallback* aCallback)
 {
-  AutoSafeJSContext cx;
+  AutoJSAPI jsapi;
+  if (!NS_WARN_IF(jsapi.Init(&aOptions.toObject()))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  JSContext* cx = jsapi.cx();
   IPC::MozCallBarringOptions options;
   if(!options.Init(cx, aOptions)) {
     return NS_ERROR_TYPE_ERR;
   }
 
   return SendRequest(SetCallBarringRequest(options), aCallback)
     ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 MobileConnectionChild::GetCallBarring(JS::Handle<JS::Value> aOptions,
                                       nsIMobileConnectionCallback* aCallback)
 {
-  AutoSafeJSContext cx;
+  AutoJSAPI jsapi;
+  if (!NS_WARN_IF(jsapi.Init(&aOptions.toObject()))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  JSContext* cx = jsapi.cx();
   IPC::MozCallBarringOptions options;
   if(!options.Init(cx, aOptions)) {
     return NS_ERROR_TYPE_ERR;
   }
 
   return SendRequest(GetCallBarringRequest(options), aCallback)
     ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 MobileConnectionChild::ChangeCallBarringPassword(JS::Handle<JS::Value> aOptions,
                                                  nsIMobileConnectionCallback* aCallback)
 {
-  AutoSafeJSContext cx;
+  AutoJSAPI jsapi;
+  if (!NS_WARN_IF(jsapi.Init(&aOptions.toObject()))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  JSContext* cx = jsapi.cx();
   IPC::MozCallBarringOptions options;
   if(!options.Init(cx, aOptions)) {
     return NS_ERROR_TYPE_ERR;
   }
 
   return SendRequest(ChangeCallBarringPasswordRequest(options), aCallback)
     ? NS_OK : NS_ERROR_FAILURE;
 }
--- a/dom/mobileconnection/ipc/MobileConnectionParent.cpp
+++ b/dom/mobileconnection/ipc/MobileConnectionParent.cpp
@@ -574,22 +574,22 @@ MobileConnectionRequestParent::NotifyGet
     // We release the ref after serializing process is finished in
     // MobileConnectionIPCSerializer.
     networks.AppendElement(network.forget().take());
   }
   return SendReply(MobileConnectionReplySuccessNetworks(networks));
 }
 
 NS_IMETHODIMP
-MobileConnectionRequestParent::NotifySendCancelMmiSuccess(JS::Handle<JS::Value> aResult)
+MobileConnectionRequestParent::NotifySendCancelMmiSuccess(JS::Handle<JS::Value> aResult,
+                                                          JSContext* aCx)
 {
-  AutoSafeJSContext cx;
-  RootedDictionary<MozMMIResult> result(cx);
+  RootedDictionary<MozMMIResult> result(aCx);
 
-  if (!result.Init(cx, aResult)) {
+  if (!result.Init(aCx, aResult)) {
     return NS_ERROR_TYPE_ERR;
   }
 
   // No additionInformation passed
   if (!result.mAdditionalInformation.WasPassed()) {
     return SendReply(MobileConnectionReplySuccessMmi(result.mServiceCode,
                                                      result.mStatusMessage,
                                                      AdditionalInformation(mozilla::void_t())));
@@ -600,84 +600,84 @@ MobileConnectionRequestParent::NotifySen
   if (additionInformation.IsUnsignedShort()) {
     return SendReply(MobileConnectionReplySuccessMmi(result.mServiceCode,
                                                      result.mStatusMessage,
                                                      AdditionalInformation(uint16_t(additionInformation.GetAsUnsignedShort()))));
   }
 
   if (additionInformation.IsObject()) {
     uint32_t length;
-    JS::Rooted<JS::Value> value(cx);
-    JS::Rooted<JSObject*> object(cx, additionInformation.GetAsObject());
+    JS::Rooted<JS::Value> value(aCx);
+    JS::Rooted<JSObject*> object(aCx, additionInformation.GetAsObject());
 
-    if (!JS_IsArrayObject(cx, object) ||
-        !JS_GetArrayLength(cx, object, &length) || length <= 0 ||
+    if (!JS_IsArrayObject(aCx, object) ||
+        !JS_GetArrayLength(aCx, object, &length) || length <= 0 ||
         // Check first element to decide the format of array.
-        !JS_GetElement(cx, object, 0, &value)) {
+        !JS_GetElement(aCx, object, 0, &value)) {
       return NS_ERROR_TYPE_ERR;
     }
 
     // Check first element to decide the format of array.
     if (value.isString()) {
       // String[]
       nsTArray<nsString> infos;
       for (uint32_t i = 0; i < length; i++) {
-        if (!JS_GetElement(cx, object, i, &value) || !value.isString()) {
+        if (!JS_GetElement(aCx, object, i, &value) || !value.isString()) {
           return NS_ERROR_TYPE_ERR;
         }
 
         nsAutoJSString str;
-        if (!str.init(cx, value.toString())) {
+        if (!str.init(aCx, value.toString())) {
           return NS_ERROR_FAILURE;
         }
         infos.AppendElement(str);
       }
 
       return SendReply(MobileConnectionReplySuccessMmi(result.mServiceCode,
                                                        result.mStatusMessage,
                                                        AdditionalInformation(infos)));
     } else {
       // IPC::MozCallForwardingOptions[]
       nsTArray<IPC::MozCallForwardingOptions> infos;
       for (uint32_t i = 0; i < length; i++) {
         IPC::MozCallForwardingOptions info;
-        if (!JS_GetElement(cx, object, i, &value) || !info.Init(cx, value)) {
+        if (!JS_GetElement(aCx, object, i, &value) || !info.Init(aCx, value)) {
           return NS_ERROR_TYPE_ERR;
         }
 
         infos.AppendElement(info);
       }
 
       return SendReply(MobileConnectionReplySuccessMmi(result.mServiceCode,
                                                        result.mStatusMessage,
                                                        AdditionalInformation(infos)));
     }
   }
 
   return NS_ERROR_TYPE_ERR;
 }
 
 NS_IMETHODIMP
-MobileConnectionRequestParent::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults)
+MobileConnectionRequestParent::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults,
+                                                              JSContext* aCx)
 {
   uint32_t length;
-  AutoSafeJSContext cx;
-  JS::Rooted<JSObject*> object(cx, &aResults.toObject());
+  JS::Rooted<JSObject*> object(aCx, &aResults.toObject());
   nsTArray<IPC::MozCallForwardingOptions> results;
 
-  if (!JS_IsArrayObject(cx, object) ||
-      !JS_GetArrayLength(cx, object, &length)) {
+  if (!JS_IsArrayObject(aCx, object) ||
+      !JS_GetArrayLength(aCx, object, &length)) {
     return NS_ERROR_TYPE_ERR;
   }
 
   for (uint32_t i = 0; i < length; i++) {
-    JS::Rooted<JS::Value> entry(cx);
+    JS::Rooted<JS::Value> entry(aCx);
     IPC::MozCallForwardingOptions info;
 
-    if (!JS_GetElement(cx, object, i, &entry) || !info.Init(cx, entry)) {
+    if (!JS_GetElement(aCx, object, i, &entry) || !info.Init(aCx, entry)) {
       return NS_ERROR_TYPE_ERR;
     }
 
     results.AppendElement(info);
   }
 
   return SendReply(MobileConnectionReplySuccessCallForwarding(results));
 }