Bug 1067576 - Make console.log work in frame scripts (r=Mossop)

This commit is contained in:
Bill McCloskey 2014-10-07 11:46:25 -07:00
parent c8f8625356
commit f94c252fa9
8 changed files with 144 additions and 2 deletions

View File

@ -444,6 +444,9 @@
@BINPATH@/components/addoncompat.manifest
@BINPATH@/components/multiprocessShims.js
@BINPATH@/components/pluginGlue.manifest
@BINPATH@/components/ProcessSingleton.manifest
@BINPATH@/components/MainProcessSingleton.js
@BINPATH@/components/ContentProcessSingleton.js
@BINPATH@/browser/components/nsSessionStore.manifest
@BINPATH@/browser/components/nsSessionStartup.js
@BINPATH@/browser/components/nsSessionStore.js

View File

@ -36,6 +36,7 @@ DIRS += [
'passwordmgr',
'perf',
'places',
'processsingleton',
'promiseworker',
'prompts',
'protobuf',

View File

@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Cu = Components.utils;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
"nsIMessageSender");
function ContentProcessSingleton() {}
ContentProcessSingleton.prototype = {
classID: Components.ID("{ca2a8470-45c7-11e4-916c-0800200c9a66}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
observe: function(subject, topic, data) {
switch (topic) {
case "app-startup": {
Services.obs.addObserver(this, "console-api-log-event", false);
Services.obs.addObserver(this, "xpcom-shutdown", false);
break;
}
case "console-api-log-event": {
let consoleMsg = subject.wrappedJSObject;
let msgData = {
level: consoleMsg.level,
filename: consoleMsg.filename,
lineNumber: consoleMsg.lineNumber,
functionName: consoleMsg.functionName,
timeStamp: consoleMsg.timeStamp,
arguments: [],
};
// We can't send objects over the message manager, so we sanitize
// them out.
for (let arg of consoleMsg.arguments) {
if ((typeof arg == "object" || typeof arg == "function") && arg !== null) {
msgData.arguments.push("<unavailable>");
} else {
msgData.arguments.push(arg);
}
}
cpmm.sendAsyncMessage("Console:Log", msgData);
break;
}
case "xpcom-shutdown":
Services.obs.removeObserver(this, "console-api-log-event");
Services.obs.removeObserver(this, "xpcom-shutdown");
break;
}
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentProcessSingleton]);

View File

@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Cu = Components.utils;
const Ci = Components.interfaces;
const Cc = Components.classes;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
"@mozilla.org/parentprocessmessagemanager;1",
"nsIMessageListenerManager");
XPCOMUtils.defineLazyServiceGetter(this, "globalmm",
"@mozilla.org/globalmessagemanager;1",
"nsIMessageBroadcaster");
function MainProcessSingleton() {}
MainProcessSingleton.prototype = {
classID: Components.ID("{0636a680-45cb-11e4-916c-0800200c9a66}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
receiveMessage: function(message) {
let logMsg = message.data;
logMsg.wrappedJSObject = logMsg;
Services.obs.notifyObservers(logMsg, "console-api-log-event", null);
},
observe: function(subject, topic, data) {
switch (topic) {
case "app-startup": {
Services.obs.addObserver(this, "xpcom-shutdown", false);
// Load this script early so that console.* is initialized
// before other frame scripts.
globalmm.loadFrameScript("chrome://global/content/browser-content.js", true);
ppmm.addMessageListener("Console:Log", this);
break;
}
case "xpcom-shutdown":
ppmm.removeMessageListener("Console:Log", this);
break;
}
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MainProcessSingleton]);

View File

@ -0,0 +1,7 @@
component {0636a680-45cb-11e4-916c-0800200c9a66} MainProcessSingleton.js process=main
contract @mozilla.org/main-process-singleton;1 {0636a680-45cb-11e4-916c-0800200c9a66} process=main
category app-startup MainProcessSingleton service,@mozilla.org/main-process-singleton;1 process=main
component {ca2a8470-45c7-11e4-916c-0800200c9a66} ContentProcessSingleton.js process=content
contract @mozilla.org/content-process-singleton;1 {ca2a8470-45c7-11e4-916c-0800200c9a66} process=content
category app-startup ContentProcessSingleton service,@mozilla.org/content-process-singleton;1 process=content

View File

@ -0,0 +1,11 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXTRA_COMPONENTS += [
'ContentProcessSingleton.js',
'MainProcessSingleton.js',
'ProcessSingleton.manifest',
]

View File

@ -348,4 +348,8 @@ let PopupBlocking = {
{blockedPopups: this.popupData, freshPopup: freshPopup});
},
};
PopupBlocking.init();
PopupBlocking.init();
// Set up console.* for frame scripts.
let Console = Components.utils.import("resource://gre/modules/devtools/Console.jsm", {});
this.console = new Console.ConsoleAPI();

View File

@ -790,7 +790,6 @@
this.messageManager.addMessageListener("PopupBlocking:UpdateBlockedPopups", this);
this.messageManager.addMessageListener("Autoscroll:Start", this);
this.messageManager.addMessageListener("Autoscroll:Cancel", this);
this.messageManager.loadFrameScript("chrome://global/content/browser-content.js", true);
}
]]>
</constructor>