Bug 688468 - Fix up nsIFrameMessageManager::sendAsyncMessage/nsISyncMessageSender::sendSyncMessage IDL signature; r=bz

This commit is contained in:
Ms2ger 2011-10-01 18:14:36 +02:00
Родитель bad4ab7474
Коммит b0decda264
5 изменённых файлов: 71 добавлений и 84 удалений

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

@ -64,24 +64,26 @@ interface nsIFrameMessageListener : nsISupports
void receiveMessage(); void receiveMessage();
}; };
[scriptable, uuid(6b736edb-863d-40bd-bca2-62f44da803c0)] [scriptable, uuid(a27d8fcd-8de9-4a51-87f4-2b83bba901d5)]
interface nsIFrameMessageManager : nsISupports interface nsIFrameMessageManager : nsISupports
{ {
void addMessageListener(in AString aMessage, in nsIFrameMessageListener aListener); void addMessageListener(in AString aMessage, in nsIFrameMessageListener aListener);
void removeMessageListener(in AString aMessage, in nsIFrameMessageListener aListener); void removeMessageListener(in AString aMessage, in nsIFrameMessageListener aListener);
void sendAsyncMessage(/*in messageName, in JSON*/); [implicit_jscontext,optional_argc]
void sendAsyncMessage([optional] in AString messageName, [optional] in jsval obj);
}; };
[scriptable, uuid(cdb1a40b-9862-426c-ae8a-f5ab84e20e32)] [scriptable, uuid(21e5d940-d457-4c0f-bb5e-35c159ed19e3)]
interface nsISyncMessageSender : nsIFrameMessageManager interface nsISyncMessageSender : nsIFrameMessageManager
{ {
/** /**
* Returns an array of JSON objects. * Returns an array of JSON objects.
*/ */
void sendSyncMessage(/*in messageName, in JSON*/); [implicit_jscontext,optional_argc]
jsval sendSyncMessage([optional] in AString messageName, [optional] in jsval obj);
}; };
[scriptable, uuid(6f23339f-2b5c-4f22-a03f-bb7ec101f83d)] [scriptable, uuid(78a1d024-60e3-4b7b-98cd-4c6b84b4f060)]
interface nsIContentFrameMessageManager : nsISyncMessageSender interface nsIContentFrameMessageManager : nsISyncMessageSender
{ {
/** /**
@ -112,20 +114,20 @@ interface nsIContentFrameMessageManager : nsISyncMessageSender
DOMString btoa(in DOMString aBase64Data); DOMString btoa(in DOMString aBase64Data);
}; };
[uuid(9c48d557-92fe-4edb-95fc-bfe97e77bdc3)] [uuid(1f7af930-a232-4a84-a049-73eaa45f2db5)]
interface nsIInProcessContentFrameMessageManager : nsIContentFrameMessageManager interface nsIInProcessContentFrameMessageManager : nsIContentFrameMessageManager
{ {
[notxpcom] nsIContent getOwnerContent(); [notxpcom] nsIContent getOwnerContent();
}; };
[scriptable, uuid(6331bbca-2c9f-4766-b3c7-ae75554bf1ec)] [scriptable, uuid(e91b0939-a74a-4c4f-8cfd-17dd42e8642a)]
interface nsITreeItemFrameMessageManager : nsIFrameMessageManager interface nsITreeItemFrameMessageManager : nsIFrameMessageManager
{ {
readonly attribute unsigned long childCount; readonly attribute unsigned long childCount;
nsITreeItemFrameMessageManager getChildAt(in unsigned long aIndex); nsITreeItemFrameMessageManager getChildAt(in unsigned long aIndex);
}; };
[scriptable, uuid(9e5c0526-aa4c-49f0-afbb-57f489cd9b59)] [scriptable, uuid(14e1f147-793d-4788-bbbb-ae806ecdddbb)]
interface nsIChromeFrameMessageManager : nsITreeItemFrameMessageManager interface nsIChromeFrameMessageManager : nsITreeItemFrameMessageManager
{ {
/** /**

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

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -15,11 +15,12 @@
* The Original Code is mozilla.org code. * The Original Code is mozilla.org code.
* *
* The Initial Developer of the Original Code is * The Initial Developer of the Original Code is
* Mozilla Corporation * the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010 * Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Ms2ger <ms2ger@gmail.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -188,91 +189,60 @@ static JSBool
JSONCreator(const jschar* aBuf, uint32 aLen, void* aData) JSONCreator(const jschar* aBuf, uint32 aLen, void* aData)
{ {
nsAString* result = static_cast<nsAString*>(aData); nsAString* result = static_cast<nsAString*>(aData);
result->Append((PRUnichar*)aBuf, (PRUint32)aLen); result->Append(static_cast<const PRUnichar*>(aBuf),
return JS_TRUE; static_cast<PRUint32>(aLen));
return true;
} }
nsresult void
nsFrameMessageManager::GetParamsForMessage(nsAString& aMessageName, nsFrameMessageManager::GetParamsForMessage(const jsval& aObject,
JSContext* aCx,
nsAString& aJSON) nsAString& aJSON)
{ {
aMessageName.Truncate();
aJSON.Truncate(); aJSON.Truncate();
nsAXPCNativeCallContext* ncc = nsnull; JSAutoRequest ar(aCx);
nsresult rv = nsContentUtils::XPConnect()->GetCurrentNativeCallContext(&ncc); jsval v = aObject;
NS_ENSURE_SUCCESS(rv, rv); JS_Stringify(aCx, &v, nsnull, JSVAL_NULL, JSONCreator, &aJSON);
NS_ENSURE_STATE(ncc);
JSContext* ctx = nsnull;
rv = ncc->GetJSContext(&ctx);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 argc;
jsval* argv = nsnull;
ncc->GetArgc(&argc);
ncc->GetArgvPtr(&argv);
JSAutoRequest ar(ctx);
JSString* str;
if (argc && (str = JS_ValueToString(ctx, argv[0])) && str) {
nsDependentJSString depStr;
if (!depStr.init(ctx, str)) {
return NS_ERROR_OUT_OF_MEMORY;
}
aMessageName.Assign(depStr);
}
if (argc >= 2) {
jsval v = argv[1];
JS_Stringify(ctx, &v, nsnull, JSVAL_NULL, JSONCreator, &aJSON);
}
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFrameMessageManager::SendSyncMessage() nsFrameMessageManager::SendSyncMessage(const nsAString& aMessageName,
const jsval& aObject,
JSContext* aCx,
PRUint8 aArgc,
jsval* aRetval)
{ {
NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome"); NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!IsWindowLevel(), "Should not call SendSyncMessage in chrome"); NS_ASSERTION(!IsWindowLevel(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!mParentManager, "Should not have parent manager in content!"); NS_ASSERTION(!mParentManager, "Should not have parent manager in content!");
*aRetval = JSVAL_VOID;
if (mSyncCallback) { if (mSyncCallback) {
NS_ENSURE_TRUE(mCallbackData, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mCallbackData, NS_ERROR_NOT_INITIALIZED);
nsString messageName;
nsString json; nsString json;
nsresult rv = GetParamsForMessage(messageName, json); if (aArgc >= 2) {
NS_ENSURE_SUCCESS(rv, rv); GetParamsForMessage(aObject, aCx, json);
}
InfallibleTArray<nsString> retval; InfallibleTArray<nsString> retval;
if (mSyncCallback(mCallbackData, messageName, json, &retval)) { if (mSyncCallback(mCallbackData, aMessageName, json, &retval)) {
nsAXPCNativeCallContext* ncc = nsnull; JSAutoRequest ar(aCx);
rv = nsContentUtils::XPConnect()->GetCurrentNativeCallContext(&ncc);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_STATE(ncc);
JSContext* ctx = nsnull;
rv = ncc->GetJSContext(&ctx);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(ctx);
PRUint32 len = retval.Length(); PRUint32 len = retval.Length();
JSObject* dataArray = JS_NewArrayObject(ctx, len, NULL); JSObject* dataArray = JS_NewArrayObject(aCx, len, NULL);
NS_ENSURE_TRUE(dataArray, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(dataArray, NS_ERROR_OUT_OF_MEMORY);
for (PRUint32 i = 0; i < len; ++i) { for (PRUint32 i = 0; i < len; ++i) {
if (retval[i].IsEmpty()) if (retval[i].IsEmpty()) {
continue; continue;
}
jsval ret = JSVAL_VOID; jsval ret = JSVAL_VOID;
if (!JS_ParseJSON(ctx, (jschar*)retval[i].get(), if (!JS_ParseJSON(aCx, static_cast<const jschar*>(retval[i].get()),
(uint32)retval[i].Length(), &ret)) { retval[i].Length(), &ret)) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
NS_ENSURE_TRUE(JS_SetElement(ctx, dataArray, i, &ret), NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(JS_SetElement(aCx, dataArray, i, &ret), NS_ERROR_OUT_OF_MEMORY);
} }
jsval* retvalPtr; *aRetval = OBJECT_TO_JSVAL(dataArray);
ncc->GetRetValPtr(&retvalPtr);
*retvalPtr = OBJECT_TO_JSVAL(dataArray);
ncc->SetReturnValueWasSet(PR_TRUE);
} }
} }
return NS_OK; return NS_OK;
@ -295,13 +265,16 @@ nsFrameMessageManager::SendAsyncMessageInternal(const nsAString& aMessage,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFrameMessageManager::SendAsyncMessage() nsFrameMessageManager::SendAsyncMessage(const nsAString& aMessageName,
const jsval& aObject,
JSContext* aCx,
PRUint8 aArgc)
{ {
nsString messageName;
nsString json; nsString json;
nsresult rv = GetParamsForMessage(messageName, json); if (aArgc >= 2) {
NS_ENSURE_SUCCESS(rv, rv); GetParamsForMessage(aObject, aCx, json);
return SendAsyncMessageInternal(messageName, json); }
return SendAsyncMessageInternal(aMessageName, json);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -428,14 +401,14 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
jsval json = JSVAL_NULL; jsval json = JSVAL_NULL;
if (!aJSON.IsEmpty()) { if (!aJSON.IsEmpty()) {
if (!JS_ParseJSON(ctx, (jschar*)nsString(aJSON).get(), if (!JS_ParseJSON(ctx, static_cast<const jschar*>(PromiseFlatString(aJSON).get()),
(uint32)aJSON.Length(), &json)) { aJSON.Length(), &json)) {
json = JSVAL_NULL; json = JSVAL_NULL;
} }
} }
JSString* jsMessage = JSString* jsMessage =
JS_NewUCStringCopyN(ctx, JS_NewUCStringCopyN(ctx,
reinterpret_cast<const jschar *>(nsString(aMessage).get()), static_cast<const jschar*>(PromiseFlatString(aMessage).get()),
aMessage.Length()); aMessage.Length());
NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY);
JS_DefineProperty(ctx, param, "target", targetv, NULL, NULL, JSPROP_ENUMERATE); JS_DefineProperty(ctx, param, "target", targetv, NULL, NULL, JSPROP_ENUMERATE);

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

@ -150,7 +150,9 @@ public:
void Disconnect(bool aRemoveFromParent = true); void Disconnect(bool aRemoveFromParent = true);
void SetCallbackData(void* aData, bool aLoadScripts = true); void SetCallbackData(void* aData, bool aLoadScripts = true);
nsresult GetParamsForMessage(nsAString& aMessageName, nsAString& aJSON); void GetParamsForMessage(const jsval& aObject,
JSContext* aCx,
nsAString& aJSON);
nsresult SendAsyncMessageInternal(const nsAString& aMessage, nsresult SendAsyncMessageInternal(const nsAString& aMessage,
const nsAString& aJSON); const nsAString& aJSON);
JSContext* GetJSContext() { return mContext; } JSContext* GetJSContext() { return mContext; }

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

@ -66,10 +66,15 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal, NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal,
nsDOMEventTargetHelper) nsDOMEventTargetHelper)
NS_FORWARD_SAFE_NSIFRAMEMESSAGEMANAGER(mMessageManager) NS_FORWARD_SAFE_NSIFRAMEMESSAGEMANAGER(mMessageManager)
NS_IMETHOD SendSyncMessage() NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
const jsval& aObject,
JSContext* aCx,
PRUint8 aArgc,
jsval* aRetval)
{ {
return mMessageManager ? mMessageManager->SendSyncMessage() return mMessageManager
: NS_ERROR_NULL_POINTER; ? mMessageManager->SendSyncMessage(aMessageName, aObject, aCx, aArgc, aRetval)
: NS_ERROR_NULL_POINTER;
} }
NS_IMETHOD GetContent(nsIDOMWindow** aContent); NS_IMETHOD GetContent(nsIDOMWindow** aContent);
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell); NS_IMETHOD GetDocShell(nsIDocShell** aDocShell);

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */ /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
/* vim: set sw=4 ts=8 et tw=80 : */ /* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -98,10 +98,15 @@ public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildGlobal, nsDOMEventTargetHelper) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildGlobal, nsDOMEventTargetHelper)
NS_FORWARD_SAFE_NSIFRAMEMESSAGEMANAGER(mMessageManager) NS_FORWARD_SAFE_NSIFRAMEMESSAGEMANAGER(mMessageManager)
NS_IMETHOD SendSyncMessage() NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
const jsval& aObject,
JSContext* aCx,
PRUint8 aArgc,
jsval* aRetval)
{ {
return mMessageManager ? mMessageManager->SendSyncMessage() return mMessageManager
: NS_ERROR_NULL_POINTER; ? mMessageManager->SendSyncMessage(aMessageName, aObject, aCx, aArgc, aRetval)
: NS_ERROR_NULL_POINTER;
} }
NS_IMETHOD GetContent(nsIDOMWindow** aContent); NS_IMETHOD GetContent(nsIDOMWindow** aContent);
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell); NS_IMETHOD GetDocShell(nsIDocShell** aDocShell);