From 8738f033d60fd24dbfb3ee6744a99ed676e853c0 Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Mon, 7 Feb 2011 14:44:31 -0800 Subject: [PATCH] Backed out changeset e706761cecfd due to mochitest orange. --- dom/base/ConsoleAPI.js | 29 +++---------------- .../console/hudservice/HUDService.jsm | 15 ++++++++-- .../extensions/content/extensions-content.js | 26 +++-------------- 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/dom/base/ConsoleAPI.js b/dom/base/ConsoleAPI.js index 066b1b239f3..3403d2ad9c5 100644 --- a/dom/base/ConsoleAPI.js +++ b/dom/base/ConsoleAPI.js @@ -62,7 +62,7 @@ ConsoleAPI.prototype = { } let self = this; - let chromeObject = { + return { // window.console API log: function CA_log() { self.notifyObservers(id, "log", arguments); @@ -76,31 +76,10 @@ ConsoleAPI.prototype = { 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; }, /** diff --git a/toolkit/components/console/hudservice/HUDService.jsm b/toolkit/components/console/hudservice/HUDService.jsm index eb230fd5140..ffd94a3dd1f 100644 --- a/toolkit/components/console/hudservice/HUDService.jsm +++ b/toolkit/components/console/hudservice/HUDService.jsm @@ -2696,9 +2696,20 @@ HUD_SERVICE.prototype = } } - // 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 diff --git a/toolkit/mozapps/extensions/content/extensions-content.js b/toolkit/mozapps/extensions/content/extensions-content.js index 41c09faefa5..bc065d323dc 100644 --- a/toolkit/mozapps/extensions/content/extensions-content.js +++ b/toolkit/mozapps/extensions/content/extensions-content.js @@ -49,7 +49,7 @@ var gIoService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); function createInstallTrigger(window) { - let chromeObject = { + return { window: window, __exposedProps__: { @@ -61,7 +61,9 @@ function createInstallTrigger(window) { updateEnabled: "r", install: "r", installChrome: "r", - startSoftwareUpdate: "r" + startSoftwareUpdate: "r", + toString: "r", + toSource: "r", // XXX workaround for bug 582100 }, // == Public interface == @@ -186,26 +188,6 @@ function createInstallTrigger(window) { } } }; - - 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; }; /**