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();
};
[scriptable, uuid(6b736edb-863d-40bd-bca2-62f44da803c0)]
[scriptable, uuid(a27d8fcd-8de9-4a51-87f4-2b83bba901d5)]
interface nsIFrameMessageManager : nsISupports
{
void addMessageListener(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
{
/**
* 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
{
/**
@ -112,20 +114,20 @@ interface nsIContentFrameMessageManager : nsISyncMessageSender
DOMString btoa(in DOMString aBase64Data);
};
[uuid(9c48d557-92fe-4edb-95fc-bfe97e77bdc3)]
[uuid(1f7af930-a232-4a84-a049-73eaa45f2db5)]
interface nsIInProcessContentFrameMessageManager : nsIContentFrameMessageManager
{
[notxpcom] nsIContent getOwnerContent();
};
[scriptable, uuid(6331bbca-2c9f-4766-b3c7-ae75554bf1ec)]
[scriptable, uuid(e91b0939-a74a-4c4f-8cfd-17dd42e8642a)]
interface nsITreeItemFrameMessageManager : nsIFrameMessageManager
{
readonly attribute unsigned long childCount;
nsITreeItemFrameMessageManager getChildAt(in unsigned long aIndex);
};
[scriptable, uuid(9e5c0526-aa4c-49f0-afbb-57f489cd9b59)]
[scriptable, uuid(14e1f147-793d-4788-bbbb-ae806ecdddbb)]
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 *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -15,11 +15,12 @@
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ms2ger <ms2ger@gmail.com>
*
* 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
@ -188,91 +189,60 @@ static JSBool
JSONCreator(const jschar* aBuf, uint32 aLen, void* aData)
{
nsAString* result = static_cast<nsAString*>(aData);
result->Append((PRUnichar*)aBuf, (PRUint32)aLen);
return JS_TRUE;
result->Append(static_cast<const PRUnichar*>(aBuf),
static_cast<PRUint32>(aLen));
return true;
}
nsresult
nsFrameMessageManager::GetParamsForMessage(nsAString& aMessageName,
void
nsFrameMessageManager::GetParamsForMessage(const jsval& aObject,
JSContext* aCx,
nsAString& aJSON)
{
aMessageName.Truncate();
aJSON.Truncate();
nsAXPCNativeCallContext* ncc = nsnull;
nsresult 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);
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;
JSAutoRequest ar(aCx);
jsval v = aObject;
JS_Stringify(aCx, &v, nsnull, JSVAL_NULL, JSONCreator, &aJSON);
}
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(!IsWindowLevel(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!mParentManager, "Should not have parent manager in content!");
*aRetval = JSVAL_VOID;
if (mSyncCallback) {
NS_ENSURE_TRUE(mCallbackData, NS_ERROR_NOT_INITIALIZED);
nsString messageName;
nsString json;
nsresult rv = GetParamsForMessage(messageName, json);
NS_ENSURE_SUCCESS(rv, rv);
if (aArgc >= 2) {
GetParamsForMessage(aObject, aCx, json);
}
InfallibleTArray<nsString> retval;
if (mSyncCallback(mCallbackData, messageName, json, &retval)) {
nsAXPCNativeCallContext* ncc = nsnull;
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);
if (mSyncCallback(mCallbackData, aMessageName, json, &retval)) {
JSAutoRequest ar(aCx);
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);
for (PRUint32 i = 0; i < len; ++i) {
if (retval[i].IsEmpty())
if (retval[i].IsEmpty()) {
continue;
}
jsval ret = JSVAL_VOID;
if (!JS_ParseJSON(ctx, (jschar*)retval[i].get(),
(uint32)retval[i].Length(), &ret)) {
if (!JS_ParseJSON(aCx, static_cast<const jschar*>(retval[i].get()),
retval[i].Length(), &ret)) {
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;
ncc->GetRetValPtr(&retvalPtr);
*retvalPtr = OBJECT_TO_JSVAL(dataArray);
ncc->SetReturnValueWasSet(PR_TRUE);
*aRetval = OBJECT_TO_JSVAL(dataArray);
}
}
return NS_OK;
@ -295,13 +265,16 @@ nsFrameMessageManager::SendAsyncMessageInternal(const nsAString& aMessage,
}
NS_IMETHODIMP
nsFrameMessageManager::SendAsyncMessage()
nsFrameMessageManager::SendAsyncMessage(const nsAString& aMessageName,
const jsval& aObject,
JSContext* aCx,
PRUint8 aArgc)
{
nsString messageName;
nsString json;
nsresult rv = GetParamsForMessage(messageName, json);
NS_ENSURE_SUCCESS(rv, rv);
return SendAsyncMessageInternal(messageName, json);
if (aArgc >= 2) {
GetParamsForMessage(aObject, aCx, json);
}
return SendAsyncMessageInternal(aMessageName, json);
}
NS_IMETHODIMP
@ -428,14 +401,14 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
jsval json = JSVAL_NULL;
if (!aJSON.IsEmpty()) {
if (!JS_ParseJSON(ctx, (jschar*)nsString(aJSON).get(),
(uint32)aJSON.Length(), &json)) {
if (!JS_ParseJSON(ctx, static_cast<const jschar*>(PromiseFlatString(aJSON).get()),
aJSON.Length(), &json)) {
json = JSVAL_NULL;
}
}
JSString* jsMessage =
JS_NewUCStringCopyN(ctx,
reinterpret_cast<const jschar *>(nsString(aMessage).get()),
static_cast<const jschar*>(PromiseFlatString(aMessage).get()),
aMessage.Length());
NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY);
JS_DefineProperty(ctx, param, "target", targetv, NULL, NULL, JSPROP_ENUMERATE);

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

@ -150,7 +150,9 @@ public:
void Disconnect(bool aRemoveFromParent = 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,
const nsAString& aJSON);
JSContext* GetJSContext() { return mContext; }

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

@ -66,10 +66,15 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal,
nsDOMEventTargetHelper)
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()
: NS_ERROR_NULL_POINTER;
return mMessageManager
? mMessageManager->SendSyncMessage(aMessageName, aObject, aCx, aArgc, aRetval)
: NS_ERROR_NULL_POINTER;
}
NS_IMETHOD GetContent(nsIDOMWindow** aContent);
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 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -98,10 +98,15 @@ public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildGlobal, nsDOMEventTargetHelper)
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()
: NS_ERROR_NULL_POINTER;
return mMessageManager
? mMessageManager->SendSyncMessage(aMessageName, aObject, aCx, aArgc, aRetval)
: NS_ERROR_NULL_POINTER;
}
NS_IMETHOD GetContent(nsIDOMWindow** aContent);
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell);