Bug 1030997 - nsFrameMessageManager should serialize the principal object as nsIPrincipal. r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 05 Aug 2014 06:54:00 -0400
changeset 198052 ae218ffbbc9c598619ed55a5b80cfa8881d5055b
parent 198051 755f2612e6e364fb9300f1b402aa2e0a57d9728a
child 198053 aedf1212d6679b52d7643ff0fcb8a78987a8f988
push id27259
push useremorley@mozilla.com
push dateWed, 06 Aug 2014 12:42:12 +0000
treeherdermozilla-central@bdf301b20cab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1030997
milestone34.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 1030997 - nsFrameMessageManager should serialize the principal object as nsIPrincipal. r=smaug
content/base/src/nsFrameMessageManager.cpp
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -995,43 +995,21 @@ nsFrameMessageManager::ReceiveMessage(ns
       JS_DefineProperty(cx, param, "data", json, JSPROP_ENUMERATE);
       JS_DefineProperty(cx, param, "objects", cpowsv, JSPROP_ENUMERATE);
 
       // message.principal == null
       if (!aPrincipal) {
         JS_DefineProperty(cx, param, "principal", JS::UndefinedHandleValue, JSPROP_ENUMERATE);
       }
 
-      // message.principal = { appId: <id>, origin: <origin>, isInBrowserElement: <something> }
+      // message.principal = the principal
       else {
-        JS::Rooted<JSObject*> principalObj(cx,
-          JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
-
-        uint32_t appId;
-        nsresult rv = aPrincipal->GetAppId(&appId);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        JS_DefineProperty(cx, principalObj, "appId", appId, JSPROP_ENUMERATE);
-
-        nsCString origin;
-        rv = aPrincipal->GetOrigin(getter_Copies(origin));
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        JS::Rooted<JSString*> originStr(cx, JS_NewStringCopyN(cx, origin.get(), origin.Length()));
-        NS_ENSURE_TRUE(originStr, NS_ERROR_OUT_OF_MEMORY);
-        JS_DefineProperty(cx, principalObj, "origin", originStr, JSPROP_ENUMERATE);
-
-        bool browser;
-        rv = aPrincipal->GetIsInBrowserElement(&browser);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        JS::Rooted<JS::Value> browserValue(cx, JS::BooleanValue(browser));
-        JS_DefineProperty(cx, principalObj, "isInBrowserElement", browserValue, JSPROP_ENUMERATE);
-
-        JS_DefineProperty(cx, param, "principal", principalObj, JSPROP_ENUMERATE);
+        JS::Rooted<JS::Value> principalValue(cx);
+        rv = nsContentUtils::WrapNative(cx, aPrincipal, &NS_GET_IID(nsIPrincipal), &principalValue);
+        JS_DefineProperty(cx, param, "principal", principalValue, JSPROP_ENUMERATE);
       }
 
       JS::Rooted<JS::Value> thisValue(cx, JS::UndefinedValue());
 
       JS::Rooted<JS::Value> funval(cx);
       if (JS_ObjectIsCallable(cx, object)) {
         // If the listener is a JS function:
         funval.setObject(*object);