Bug 1314361: Part 3 - Stop using origin attributes for add-on ID in console filtering. r=baku draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 26 Feb 2017 13:13:45 -0800
changeset 489860 f66ee3c535ed051b89c110ce09dadca22a48996d
parent 489859 abaffcc44d5653e6e479940302d0aae71b0bb880
child 489861 40f79359653caf1aa6e2d26fb82cb50d16989a20
push id46924
push usermaglione.k@gmail.com
push dateSun, 26 Feb 2017 21:23:01 +0000
reviewersbaku
bugs1314361
milestone54.0a1
Bug 1314361: Part 3 - Stop using origin attributes for add-on ID in console filtering. r=baku MozReview-Commit-ID: KTRU2zfm1ye
devtools/client/aboutdebugging/test/browser_addons_debug_webextension.js
devtools/client/aboutdebugging/test/browser_addons_debug_webextension_popup.js
devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js
devtools/server/actors/utils/webconsole-listeners.js
devtools/shared/tests/unit/test_console_filtering.js
dom/console/Console.cpp
dom/tests/browser/browser_ConsoleAPI_originAttributes.js
dom/webidl/Console.webidl
--- a/devtools/client/aboutdebugging/test/browser_addons_debug_webextension.js
+++ b/devtools/client/aboutdebugging/test/browser_addons_debug_webextension.js
@@ -23,18 +23,17 @@ add_task(function* testWebExtensionsTool
     tab, document, debugBtn,
   } = yield setupTestAboutDebuggingWebExtension(ADDON_NAME, ADDON_MANIFEST_PATH);
 
   // Wait for a notification sent by a script evaluated the test addon via
   // the web console.
   let onCustomMessage = new Promise(done => {
     Services.obs.addObserver(function listener(message, topic) {
       let apiMessage = message.wrappedJSObject;
-      if (!apiMessage.originAttributes ||
-          apiMessage.originAttributes.addonId != ADDON_ID) {
+      if (apiMessage.addonId != ADDON_ID) {
         return;
       }
       Services.obs.removeObserver(listener, "console-api-log-event");
       done(apiMessage.arguments);
     }, "console-api-log-event", false);
   });
 
   // Be careful, this JS function is going to be executed in the addon toolbox,
--- a/devtools/client/aboutdebugging/test/browser_addons_debug_webextension_popup.js
+++ b/devtools/client/aboutdebugging/test/browser_addons_debug_webextension_popup.js
@@ -39,18 +39,17 @@ function makeWidgetId(id) {
 add_task(function* testWebExtensionsToolboxSwitchToPopup() {
   let {
     tab, document, debugBtn,
   } = yield setupTestAboutDebuggingWebExtension(ADDON_NAME, ADDON_MANIFEST_PATH);
 
   let onReadyForOpenPopup = new Promise(done => {
     Services.obs.addObserver(function listener(message, topic) {
       let apiMessage = message.wrappedJSObject;
-      if (!apiMessage.originAttributes ||
-          apiMessage.originAttributes.addonId != ADDON_ID) {
+      if (apiMessage.addonId != ADDON_ID) {
         return;
       }
 
       if (apiMessage.arguments[0] == "readyForOpenPopup") {
         Services.obs.removeObserver(listener, "console-api-log-event");
         done();
       }
     }, "console-api-log-event", false);
@@ -144,18 +143,17 @@ add_task(function* testWebExtensionsTool
     env.set("MOZ_TOOLBOX_TEST_SCRIPT", "");
   });
 
   // Wait for a notification sent by a script evaluated the test addon via
   // the web console.
   let onPopupCustomMessage = new Promise(done => {
     Services.obs.addObserver(function listener(message, topic) {
       let apiMessage = message.wrappedJSObject;
-      if (!apiMessage.originAttributes ||
-          apiMessage.originAttributes.addonId != ADDON_ID) {
+      if (apiMessage.addonId != ADDON_ID) {
         return;
       }
 
       if (apiMessage.arguments[0] == "Popup page function called") {
         Services.obs.removeObserver(listener, "console-api-log-event");
         done(apiMessage.arguments);
       }
     }, "console-api-log-event", false);
--- a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js
+++ b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js
@@ -683,16 +683,17 @@ stubPreparedMessages.set("console.log(%c
   ],
   "notes": null
 }));
 
 stubPackets.set("console.log('foobar', 'test')", {
   "from": "server1.conn0.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "foobar",
       "test"
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
@@ -707,16 +708,17 @@ stubPackets.set("console.log('foobar', '
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log(undefined)", {
   "from": "server1.conn1.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       {
         "type": "undefined"
       }
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
@@ -732,16 +734,17 @@ stubPackets.set("console.log(undefined)"
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.warn('danger, will robinson!')", {
   "from": "server1.conn2.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "danger, will robinson!"
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -755,16 +758,17 @@ stubPackets.set("console.warn('danger, w
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log(NaN)", {
   "from": "server1.conn3.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       {
         "type": "NaN"
       }
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
@@ -780,16 +784,17 @@ stubPackets.set("console.log(NaN)", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log(null)", {
   "from": "server1.conn4.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       {
         "type": "null"
       }
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
@@ -805,16 +810,17 @@ stubPackets.set("console.log(null)", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log('鼬')", {
   "from": "server1.conn5.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "鼬"
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -828,16 +834,17 @@ stubPackets.set("console.log('鼬')", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.clear()", {
   "from": "server1.conn6.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "clear",
     "lineNumber": 1,
@@ -849,16 +856,17 @@ stubPackets.set("console.clear()", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.count('bar')", {
   "from": "server1.conn7.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "bar"
     ],
     "columnNumber": 27,
     "counter": {
       "count": 1,
       "label": "bar"
     },
@@ -875,16 +883,17 @@ stubPackets.set("console.count('bar')", 
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.assert(false, {message: 'foobar'})", {
   "from": "server1.conn8.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       {
         "type": "object",
         "actor": "server1.conn8.child1/obj31",
         "class": "Object",
         "extensible": true,
         "frozen": false,
         "sealed": false,
@@ -928,16 +937,17 @@ stubPackets.set("console.assert(false, {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log('hello \nfrom \rthe \"string world!')", {
   "from": "server1.conn9.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "hello \nfrom \rthe \"string world!"
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -951,16 +961,17 @@ stubPackets.set("console.log('hello \nfr
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log('úṇĩçödê țĕșť')", {
   "from": "server1.conn10.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "úṇĩçödê țĕșť"
     ],
     "columnNumber": 27,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -974,16 +985,17 @@ stubPackets.set("console.log('úṇĩçödê țĕșť')", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.dirxml(window)", {
   "from": "server1.conn11.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       {
         "type": "object",
         "actor": "server1.conn11.child1/obj31",
         "class": "Window",
         "extensible": true,
         "frozen": false,
         "sealed": false,
@@ -1009,16 +1021,17 @@ stubPackets.set("console.dirxml(window)"
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.trace()", {
   "from": "server1.conn12.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [],
     "columnNumber": 3,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "testStacktraceFiltering",
     "groupName": "",
     "level": "trace",
     "lineNumber": 3,
@@ -1053,16 +1066,17 @@ stubPackets.set("console.trace()", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.time('bar')", {
   "from": "server1.conn13.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "bar"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -1078,16 +1092,17 @@ stubPackets.set("console.time('bar')", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.timeEnd('bar')", {
   "from": "server1.conn13.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "bar"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -1104,16 +1119,17 @@ stubPackets.set("console.timeEnd('bar')"
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.table('bar')", {
   "from": "server1.conn14.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "bar"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
@@ -1127,16 +1143,17 @@ stubPackets.set("console.table('bar')", 
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.table(['a', 'b', 'c'])", {
   "from": "server1.conn15.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       {
         "type": "object",
         "actor": "server1.conn15.child1/obj31",
         "class": "Array",
         "extensible": true,
         "frozen": false,
         "sealed": false,
@@ -1167,16 +1184,17 @@ stubPackets.set("console.table(['a', 'b'
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.group('bar')", {
   "from": "server1.conn16.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "bar"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "bar",
@@ -1190,16 +1208,17 @@ stubPackets.set("console.group('bar')", 
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.groupEnd('bar')", {
   "from": "server1.conn16.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "bar"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "bar",
@@ -1213,16 +1232,17 @@ stubPackets.set("console.groupEnd('bar')
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.groupCollapsed('foo')", {
   "from": "server1.conn17.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "foo"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo",
@@ -1236,16 +1256,17 @@ stubPackets.set("console.groupCollapsed(
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.groupEnd('foo')", {
   "from": "server1.conn17.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "foo"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "foo",
@@ -1259,16 +1280,17 @@ stubPackets.set("console.groupEnd('foo')
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.group()", {
   "from": "server1.conn18.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "group",
     "lineNumber": 2,
@@ -1280,16 +1302,17 @@ stubPackets.set("console.group()", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.groupEnd()", {
   "from": "server1.conn18.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
     "groupName": "",
     "level": "groupEnd",
     "lineNumber": 3,
@@ -1301,16 +1324,17 @@ stubPackets.set("console.groupEnd()", {
     "category": "webdev"
   }
 });
 
 stubPackets.set("console.log(%cfoobar)", {
   "from": "server1.conn19.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
+    "addonId": "",
     "arguments": [
       "foo",
       "bar"
     ],
     "columnNumber": 1,
     "counter": null,
     "filename": "http://example.com/browser/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/test-console-api.html",
     "functionName": "triggerPacket",
--- a/devtools/server/actors/utils/webconsole-listeners.js
+++ b/devtools/server/actors/utils/webconsole-listeners.js
@@ -296,18 +296,17 @@ ConsoleAPIListener.prototype =
     if (this.addonId) {
       // ConsoleAPI.jsm messages contains a consoleID, (and it is currently
       // used in Addon SDK add-ons), the standard 'console' object
       // (which is used in regular webpages and in WebExtensions pages)
       // contains the originAttributes of the source document principal.
 
       // Filtering based on the originAttributes used by
       // the Console API object.
-      if (message.originAttributes &&
-          message.originAttributes.addonId == this.addonId) {
+      if (message.addonId == this.addonId) {
         return true;
       }
 
       // Filtering based on the old-style consoleID property used by
       // the legacy Console JSM module.
       if (message.consoleID && message.consoleID == `addon/${this.addonId}`) {
         return true;
       }
--- a/devtools/shared/tests/unit/test_console_filtering.js
+++ b/devtools/shared/tests/unit/test_console_filtering.js
@@ -2,58 +2,67 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { console, ConsoleAPI } = require("resource://gre/modules/Console.jsm");
 const { ConsoleAPIListener } = require("devtools/server/actors/utils/webconsole-listeners");
 const Services = require("Services");
 
+// FIXME: This test shouldn't need to rely on low-level internals.
+const {Service} = Cu.import("resource://gre/modules/ExtensionManagement.jsm", {});
+
 var seenMessages = 0;
 var seenTypes = 0;
 
 var callback = {
   onConsoleAPICall: function (message) {
     if (message.consoleID && message.consoleID == "addon/foo") {
       do_check_eq(message.level, "warn");
       do_check_eq(message.arguments[0], "Warning from foo");
       seenTypes |= 1;
-    } else if (message.originAttributes &&
-              message.originAttributes.addonId == "bar") {
+    } else if (message.addonId == "bar") {
       do_check_eq(message.level, "error");
       do_check_eq(message.arguments[0], "Error from bar");
       seenTypes |= 2;
     } else {
       do_check_eq(message.level, "log");
       do_check_eq(message.arguments[0], "Hello from default console");
       seenTypes |= 4;
     }
     seenMessages++;
   }
 };
 
 function createFakeAddonWindow({addonId} = {}) {
-  let baseURI = Services.io.newURI("about:blank");
-  let originAttributes = {addonId};
+  const uuidGen = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
+  const uuid = uuidGen.generateUUID().number.slice(1, -1);
+
+  const url = `moz-extension://${uuid}/`;
+  Service.uuidMap.set(uuid, {id: addonId});
+
+  let baseURI = Services.io.newURI(url);
   let principal = Services.scriptSecurityManager
-        .createCodebasePrincipal(baseURI, originAttributes);
+        .createCodebasePrincipal(baseURI, {});
   let chromeWebNav = Services.appShell.createWindowlessBrowser(true);
   let docShell = chromeWebNav.QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsIDocShell);
   docShell.createAboutBlankContentViewer(principal);
   let addonWindow = docShell.contentViewer.DOMDocument.defaultView;
 
   return {addonWindow, chromeWebNav};
 }
 
 /**
  * Tests that the consoleID property of the ConsoleAPI options gets passed
  * through to console messages.
  */
 function run_test() {
+  Service.init();
+
   // console1 Test Console.jsm messages tagged by the Addon SDK
   // are still filtered correctly.
   let console1 = new ConsoleAPI({
     consoleID: "addon/foo"
   });
 
   // console2 - WebExtension page's console messages tagged
   // by 'originAttributes.addonId' are filtered correctly.
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -152,16 +152,25 @@ public:
   }
 
   void
   SetOriginAttributes(const OriginAttributes& aOriginAttributes)
   {
     mOriginAttributes = aOriginAttributes;
   }
 
+  void
+  SetAddonId(nsIPrincipal* aPrincipal)
+  {
+    nsAutoString addonId;
+    aPrincipal->GetAddonId(addonId);
+
+    mAddonId = addonId;
+  }
+
   bool
   PopulateArgumentsSequence(Sequence<JS::Value>& aSequence) const
   {
     AssertIsOnOwningThread();
 
     for (uint32_t i = 0; i < mCopiedArguments.Length(); ++i) {
       if (NS_WARN_IF(!aSequence.AppendElement(mCopiedArguments[i],
                                               fallible))) {
@@ -245,16 +254,18 @@ public:
   uint64_t mOuterIDNumber;
   nsString mOuterIDString;
 
   uint64_t mInnerIDNumber;
   nsString mInnerIDString;
 
   OriginAttributes mOriginAttributes;
 
+  nsString mAddonId;
+
   nsString mMethodString;
 
   // Stack management is complicated, because we want to do it as
   // lazily as possible.  Therefore, we have the following behavior:
   // 1)  mTopStackFrame is initialized whenever we have any JS on the stack
   // 2)  mReifiedStack is initialized if we're created in a worker.
   // 3)  mStack is set (possibly to null if there is no JS on the stack) if
   //     we're created on main thread.
@@ -1212,16 +1223,17 @@ Console::MethodInternal(JSContext* aCx, 
     }
 
     nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
     if (NS_WARN_IF(!principal)) {
       return;
     }
 
     oa = principal->OriginAttributesRef();
+    callData->SetAddonId(principal);
 
 #ifdef DEBUG
     if (!nsContentUtils::IsSystemPrincipal(principal)) {
       nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
       if (webNav) {
         nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
         MOZ_ASSERT(loadContext);
 
@@ -1495,16 +1507,18 @@ Console::PopulateConsoleNotificationInTh
 
   // Save the principal's OriginAttributes in the console event data
   // so that we will be able to filter messages by origin attributes.
   JS::Rooted<JS::Value> originAttributesValue(aCx);
   if (ToJSValue(aCx, aData->mOriginAttributes, &originAttributesValue)) {
     event.mOriginAttributes = originAttributesValue;
   }
 
+  event.mAddonId = aData->mAddonId;
+
   event.mID.Construct();
   event.mInnerID.Construct();
 
   if (aData->mIDType == ConsoleCallData::eString) {
     event.mID.Value().SetAsString() = aData->mOuterIDString;
     event.mInnerID.Value().SetAsString() = aData->mInnerIDString;
   } else if (aData->mIDType == ConsoleCallData::eNumber) {
     event.mID.Value().SetAsUnsignedLongLong() = aData->mOuterIDNumber;
--- a/dom/tests/browser/browser_ConsoleAPI_originAttributes.js
+++ b/dom/tests/browser/browser_ConsoleAPI_originAttributes.js
@@ -1,14 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
       .getService(Ci.nsIConsoleAPIStorage);
 
+// FIXME: This test shouldn't need to rely on low-level internals.
+const {Service} = Cu.import("resource://gre/modules/ExtensionManagement.jsm", {});
+
 const FAKE_ADDON_ID = "test-webext-addon@mozilla.org";
 const EXPECTED_CONSOLE_ID = `addon/${FAKE_ADDON_ID}`;
 const EXPECTED_CONSOLE_MESSAGE_CONTENT = "fake-webext-addon-test-log-message";
 const ConsoleObserver = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   init() {
     Services.obs.addObserver(this, "console-api-log-event", false);
@@ -20,46 +23,49 @@ const ConsoleObserver = {
 
   observe(aSubject, aTopic, aData) {
     if (aTopic == "console-api-log-event") {
       let consoleAPIMessage = aSubject.wrappedJSObject;
 
       is(consoleAPIMessage.arguments[0], EXPECTED_CONSOLE_MESSAGE_CONTENT,
          "the consoleAPIMessage contains the expected message");
 
-      ok(consoleAPIMessage.originAttributes, "the consoleAPImessage contains originattributes");
-      is(consoleAPIMessage.originAttributes.addonId, FAKE_ADDON_ID,
-         "the consoleAPImessage's originAttributes contains the expected addonId");
+      is(consoleAPIMessage.addonId, FAKE_ADDON_ID,
+         "the consoleAPImessage originAttributes contains the expected addonId");
 
       let cachedMessages = ConsoleAPIStorage.getEvents().filter((msg) => {
-        return msg.originAttributes && msg.originAttributes.addonId == FAKE_ADDON_ID;
+        return msg.addonId == FAKE_ADDON_ID;
       });
 
       is(cachedMessages.length, 1, "found the expected cached console messages from the addon");
-      is(cachedMessages[0] && cachedMessages[0].originAttributes.addonId, FAKE_ADDON_ID,
-         "the cached message's originAttributes contains the expected addonId");
+      is(cachedMessages[0] && cachedMessages[0].addonId, FAKE_ADDON_ID,
+         "the cached message originAttributes contains the expected addonId");
 
       finish();
     }
   }
 };
 
 function test()
 {
+  Service.init();
   ConsoleObserver.init();
 
   waitForExplicitFinish();
 
   let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
   let uuid = uuidGenerator.generateUUID().number;
   uuid = uuid.slice(1, -1); // Strip { and } off the UUID.
-  let baseURI = Services.io.newURI("about:blank");
-  let originAttributes = {addonId: FAKE_ADDON_ID};
+
+  const url = `moz-extension://${uuid}/`;
+  Service.uuidMap.set(uuid, {id: FAKE_ADDON_ID});
+
+  let baseURI = Services.io.newURI(url);
   let principal = Services.scriptSecurityManager
-        .createCodebasePrincipal(baseURI, originAttributes);
+        .createCodebasePrincipal(baseURI, {});
 
   let chromeWebNav = Services.appShell.createWindowlessBrowser(true);
   let interfaceRequestor = chromeWebNav.QueryInterface(Ci.nsIInterfaceRequestor);
   let docShell = interfaceRequestor.getInterface(Ci.nsIDocShell);
   docShell.createAboutBlankContentViewer(principal);
 
   info("fake webextension docShell created");
 
--- a/dom/webidl/Console.webidl
+++ b/dom/webidl/Console.webidl
@@ -44,16 +44,17 @@ namespace console {
   const boolean IS_NATIVE_CONSOLE = true;
 };
 
 // This is used to propagate console events to the observers.
 dictionary ConsoleEvent {
   (unsigned long long or DOMString) ID;
   (unsigned long long or DOMString) innerID;
   any originAttributes = null;
+  DOMString addonId = "";
   DOMString level = "";
   DOMString filename = "";
   unsigned long lineNumber = 0;
   unsigned long columnNumber = 0;
   DOMString functionName = "";
   double timeStamp = 0;
   sequence<any> arguments;
   sequence<DOMString?> styles;