Bug 1380449 - Do not clone when not in a Web Extension r=kmag draft
authorJulien Wajsberg <felash@gmail.com>
Thu, 20 Jul 2017 16:06:15 +0200
changeset 619015 196205d2cc9dc78f837ded303ef7636e4729c0d8
parent 618757 44121dbcac6a9d3ff18ed087a09b3205e5a04db1
child 640268 e0c81ddeaf491581c292c37e6c3acc4609baeac6
push id71543
push userbmo:felash@gmail.com
push dateTue, 01 Aug 2017 12:01:34 +0000
reviewerskmag
bugs1380449
milestone56.0a1
Bug 1380449 - Do not clone when not in a Web Extension r=kmag MozReview-Commit-ID: D1Ry7INxnYo
toolkit/components/processsingleton/ContentProcessSingleton.js
--- a/toolkit/components/processsingleton/ContentProcessSingleton.js
+++ b/toolkit/components/processsingleton/ContentProcessSingleton.js
@@ -11,16 +11,18 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetryController",
                                   "resource://gre/modules/TelemetryController.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
+                                  "resource:///modules/E10SUtils.jsm");
 
 /*
  * The message manager has an upper limit on message sizes that it can
  * reliably forward to the parent so we limit the size of console log event
  * messages that we forward here. The web console is local and receives the
  * full console message, but addons subscribed to console event messages
  * in the parent receive the truncated version. Due to fragmentation,
  * messages as small as 1MB have resulted in IPC allocation failures on
@@ -74,21 +76,28 @@ ContentProcessSingleton.prototype = {
       // When the sum of argument sizes reaches MSG_MGR_CONSOLE_MAX_SIZE,
       // replace all arguments with "<truncated>".
       let totalArgLength = 0;
 
       // Walk through the arguments, checking the type and size.
       for (let arg of consoleMsg.arguments) {
         if ((typeof arg == "object" || typeof arg == "function") &&
             arg !== null) {
-          try {
-            // If the argument is clonable, then send it as-is. If
-            // cloning fails, fall back to the unavailable string.
-            arg = Cu.cloneInto(arg, {});
-          } catch (e) {
+          if (Services.appinfo.remoteType === E10SUtils.EXTENSION_REMOTE_TYPE) {
+            // For OOP extensions: we want the developer to be able to see the
+            // logs in the Browser Console. When the Addon Toolbox will be more
+            // prominent we can revisit.
+            try {
+              // If the argument is clonable, then send it as-is. If
+              // cloning fails, fall back to the unavailable string.
+              arg = Cu.cloneInto(arg, {});
+            } catch (e) {
+              arg = unavailString;
+            }
+          } else {
             arg = unavailString;
           }
           totalArgLength += unavailStringLength;
         } else if (typeof arg == "string") {
           totalArgLength += arg.length * 2; // 2-bytes per char
         } else {
           totalArgLength += MSG_MGR_CONSOLE_VAR_SIZE;
         }