Finish backing out bug 631225
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 07 Feb 2011 14:44:50 -0800
changeset 62368 a312e5730b2d2fa6a07c1ba8019f85b16db36c2b
parent 62366 c05d5ba43182b34abda034c1f81c48eda639c1dc (current diff)
parent 62367 b490110146ad9ca3f8ea7cfee3c201489da54ef2 (diff)
child 62369 985782685741285a144c42603dbc4b2845425308
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
bugs631225
milestone2.0b12pre
Finish backing out bug 631225
--- a/dom/base/ConsoleAPI.js
+++ b/dom/base/ConsoleAPI.js
@@ -57,55 +57,34 @@ ConsoleAPI.prototype = {
       id = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                   .getInterface(Ci.nsIDOMWindowUtils)
                   .outerWindowID;
     } catch (ex) {
       Cu.reportError(ex);
     }
 
     let self = this;
-    let chromeObject = {
+    return {
       // window.console API
       log: function CA_log() {
         self.notifyObservers(id, "log", arguments);
       },
       info: function CA_info() {
         self.notifyObservers(id, "info", arguments);
       },
       warn: function CA_warn() {
         self.notifyObservers(id, "warn", arguments);
       },
       error: function CA_error() {
         self.notifyObservers(id, "error", arguments);
       },
-      __exposedProps__: {
-        log: "r",
-        info: "r",
-        warn: "r",
-        error: "r"
-      }
+      // many flavors of console objects exist on the web, so calling
+      // unimplemented methods shouldn't be fatal. See bug 614350
+      __noSuchMethod__: function CA_nsm() {}
     };
-
-    // We need to return an actual content object here, instead of a wrapped
-    // chrome object. This allows things like console.log.bind() to work.
-    let sandbox = Cu.Sandbox(aWindow);
-    let contentObject = Cu.evalInSandbox(
-        "(function(x) {\
-          var bind = Function.bind;\
-          return {\
-            log: bind.call(x.log, x),\
-            info: bind.call(x.info, x),\
-            warn: bind.call(x.warn, x),\
-            error: bind.call(x.error, x),\
-            __mozillaConsole__: true,\
-            __noSuchMethod__: function() {}\
-          };\
-        })", sandbox)(chromeObject);
-
-      return contentObject;
   },
 
   /**
    * Notify all observers of any console API call
    **/
   notifyObservers: function CA_notifyObservers(aID, aLevel, aArguments) {
     if (!aID)
       return;
--- a/toolkit/components/console/hudservice/HUDService.jsm
+++ b/toolkit/components/console/hudservice/HUDService.jsm
@@ -2691,19 +2691,30 @@ HUD_SERVICE.prototype =
     else {
       hud = this.hudReferences[hudId];
       if (aContentWindow == aContentWindow.top) {
         // TODO: name change?? doesn't actually re-attach the console
         hud.reattachConsole(aContentWindow);
       }
     }
 
-    // Need to detect that the console component has been paved over.
+    // Need to detect that the console component has been paved over. Do this by
+    // checking whether its global object is equal to that of an object
+    // returned by our native ConsoleAPI nsIDOMGlobalPropertyInitializer.
     let consoleObject = unwrap(aContentWindow).console;
-    if (!("__mozillaConsole__" in consoleObject))
+    let consoleGlobal = Cu.getGlobalForObject(consoleObject);
+
+    let nativeConsoleObj = Cc["@mozilla.org/console-api;1"].
+                           createInstance(Ci.nsIDOMGlobalPropertyInitializer).
+                           init(aContentWindow);
+    let nativeConsoleGlobal = Cu.getGlobalForObject(nativeConsoleObj);
+
+    // Need a "===" comparison because backstagepass objects have strange
+    // behavior with ==
+    if (consoleGlobal !== nativeConsoleGlobal)
       this.logWarningAboutReplacedAPI(hudId);
 
     // register the controller to handle "select all" properly
     this.createController(xulWindow);
   },
 
   /**
    * Adds the command controller to the XUL window if it's not already present.
--- a/toolkit/mozapps/extensions/content/extensions-content.js
+++ b/toolkit/mozapps/extensions/content/extensions-content.js
@@ -44,29 +44,31 @@ const Cu = Components.utils;
 const MSG_INSTALL_ENABLED  = "WebInstallerIsInstallEnabled";
 const MSG_INSTALL_ADDONS   = "WebInstallerInstallAddonsFromWebpage";
 const MSG_INSTALL_CALLBACK = "WebInstallerInstallCallback";
 
 var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
                            .getService(Components.interfaces.nsIIOService);
 
 function createInstallTrigger(window) {
-  let chromeObject = {
+  return {
     window: window,
 
     __exposedProps__: {
       SKIN: "r",
       LOCALE: "r",
       CONTENT: "r",
       PACKAGE: "r",
       enabled: "r",
       updateEnabled: "r",
       install: "r",
       installChrome: "r",
-      startSoftwareUpdate: "r"
+      startSoftwareUpdate: "r",
+      toString: "r",
+      toSource: "r", // XXX workaround for bug 582100
     },
 
     // == Public interface ==
 
     SKIN: Ci.amIInstallTrigger.SKIN,
     LOCALE: Ci.amIInstallTrigger.LOCALE,
     CONTENT: Ci.amIInstallTrigger.CONTENT,
     PACKAGE: Ci.amIInstallTrigger.PACKAGE,
@@ -181,36 +183,16 @@ function createInstallTrigger(window) {
           Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
         return true;
       }
       catch(e) {
         return false;
       }
     }
   };
-
-  let sandbox = Cu.Sandbox(window);
-  let obj = Cu.evalInSandbox(
-    "(function (x) {\
-       var bind = Function.bind;\
-       return {\
-         enabled: bind.call(x.enabled, x);\
-         updateEnabled: bind.call(x.updateEnabled, x);\
-         install: bind.call(x.install, x);\
-         installChrome: bind.call(x.installChrome, x);\
-         startSoftwareUpdate: bind.call(x.startSoftwareUpdate, x);\
-       };\
-     })", sandbox)(chromeObject);
-
-  obj.SKIN = chromeObject.SKIN;
-  obj.LOCALE = chromeObject.LOCALE;
-  obj.CONTENT = chromeObject.CONTENT;
-  obj.PACKAGE = chromeObject.PACKAGE;
-
-  return obj;
 };
 
 /**
  * Child part of InstallTrigger e10s handling.
  *
  * Sets up InstallTrigger for newly-created windows,
  * that will relay messages for InstallTrigger
  * activity. We also process the parameters for