Bug 1070083 - Part 1: Use the right compartment in MobileConnection code. r=bholley

This commit is contained in:
Edgar Chen 2014-09-23 15:25:54 +08:00
Родитель 97865baec0
Коммит 0eab9c585e
4 изменённых файлов: 50 добавлений и 26 удалений

Просмотреть файл

@ -231,13 +231,15 @@ MobileConnectionCallback::NotifyGetNetworksSuccess(uint32_t aCount,
}
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);
}

Просмотреть файл

@ -124,7 +124,7 @@ interface nsIMobileConnectionListener : nsISupports
#define NO_ADDITIONAL_INFORMATION 0
%}
[scriptable, builtinclass, uuid(e9d7c247-34c6-42bf-875b-f99b19db394f)]
[scriptable, builtinclass, uuid(7f2dbbe0-42f2-11e4-916c-0800200c9a66)]
interface nsIMobileConnectionCallback : nsISupports
{
/**
@ -139,8 +139,10 @@ interface nsIMobileConnectionCallback : nsISupports
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,

Просмотреть файл

@ -242,7 +242,12 @@ 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;
@ -264,7 +269,12 @@ 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;
@ -278,7 +288,12 @@ 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;
@ -292,7 +307,12 @@ 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;

Просмотреть файл

@ -579,12 +579,12 @@ MobileConnectionRequestParent::NotifyGetNetworksSuccess(uint32_t aCount,
}
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;
}
@ -605,13 +605,13 @@ MobileConnectionRequestParent::NotifySendCancelMmiSuccess(JS::Handle<JS::Value>
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;
}
@ -620,12 +620,12 @@ MobileConnectionRequestParent::NotifySendCancelMmiSuccess(JS::Handle<JS::Value>
// 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);
@ -639,7 +639,7 @@ MobileConnectionRequestParent::NotifySendCancelMmiSuccess(JS::Handle<JS::Value>
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;
}
@ -656,23 +656,23 @@ MobileConnectionRequestParent::NotifySendCancelMmiSuccess(JS::Handle<JS::Value>
}
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;
}