зеркало из https://github.com/mozilla/gecko-dev.git
Expose console and InstallTrigger as content objects (bug 631225, r=dtownsend).
This commit is contained in:
Родитель
12274da8f3
Коммит
0507dc7565
|
@ -62,7 +62,7 @@ ConsoleAPI.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
return {
|
let chromeObject = {
|
||||||
// window.console API
|
// window.console API
|
||||||
log: function CA_log() {
|
log: function CA_log() {
|
||||||
self.notifyObservers(id, "log", arguments);
|
self.notifyObservers(id, "log", arguments);
|
||||||
|
@ -76,10 +76,33 @@ ConsoleAPI.prototype = {
|
||||||
error: function CA_error() {
|
error: function CA_error() {
|
||||||
self.notifyObservers(id, "error", arguments);
|
self.notifyObservers(id, "error", arguments);
|
||||||
},
|
},
|
||||||
// many flavors of console objects exist on the web, so calling
|
__exposedProps__: {
|
||||||
// unimplemented methods shouldn't be fatal. See bug 614350
|
log: "r",
|
||||||
__noSuchMethod__: function CA_nsm() {}
|
info: "r",
|
||||||
|
warn: "r",
|
||||||
|
error: "r"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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;\
|
||||||
|
var obj = {\
|
||||||
|
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() {}\
|
||||||
|
};\
|
||||||
|
Object.defineProperty(obj, '__mozillaConsole__', { value: true });\
|
||||||
|
return obj;\
|
||||||
|
})", sandbox)(chromeObject);
|
||||||
|
|
||||||
|
return contentObject;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2696,20 +2696,9 @@ HUD_SERVICE.prototype =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to detect that the console component has been paved over. Do this by
|
// Need to detect that the console component has been paved over.
|
||||||
// checking whether its global object is equal to that of an object
|
|
||||||
// returned by our native ConsoleAPI nsIDOMGlobalPropertyInitializer.
|
|
||||||
let consoleObject = unwrap(aContentWindow).console;
|
let consoleObject = unwrap(aContentWindow).console;
|
||||||
let consoleGlobal = Cu.getGlobalForObject(consoleObject);
|
if (!("__mozillaConsole__" in 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);
|
this.logWarningAboutReplacedAPI(hudId);
|
||||||
|
|
||||||
// register the controller to handle "select all" properly
|
// register the controller to handle "select all" properly
|
||||||
|
|
|
@ -49,7 +49,7 @@ var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
.getService(Components.interfaces.nsIIOService);
|
.getService(Components.interfaces.nsIIOService);
|
||||||
|
|
||||||
function createInstallTrigger(window) {
|
function createInstallTrigger(window) {
|
||||||
return {
|
let chromeObject = {
|
||||||
window: window,
|
window: window,
|
||||||
|
|
||||||
__exposedProps__: {
|
__exposedProps__: {
|
||||||
|
@ -61,9 +61,7 @@ function createInstallTrigger(window) {
|
||||||
updateEnabled: "r",
|
updateEnabled: "r",
|
||||||
install: "r",
|
install: "r",
|
||||||
installChrome: "r",
|
installChrome: "r",
|
||||||
startSoftwareUpdate: "r",
|
startSoftwareUpdate: "r"
|
||||||
toString: "r",
|
|
||||||
toSource: "r", // XXX workaround for bug 582100
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// == Public interface ==
|
// == Public interface ==
|
||||||
|
@ -188,6 +186,26 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Загрузка…
Ссылка в новой задаче