forked from mirrors/gecko-dev
Bug 1689297 - [devtools] Add cloned content process message resource. r=ochameau,devtools-backward-compat-reviewers.
This is a legacy-listener-only resource that is required for us to receive the messages cloned from the content process in the browser console when the `devtools.browsertoolbox.fission` pref is not enabled. Since the messages are sent through the `consoleApiCall` event, we add a `clonedFromContentProcess` flag so we can ignore legit console api messages, which are handled as another resource. This let us remove the specific code in WebConnectionProxy. Differential Revision: https://phabricator.services.mozilla.com/D103284
This commit is contained in:
parent
56d368a1ae
commit
15042471eb
8 changed files with 72 additions and 40 deletions
|
|
@ -22,18 +22,10 @@ class WebConsoleConnectionProxy {
|
||||||
* A WebConsoleUI instance that owns this connection proxy.
|
* A WebConsoleUI instance that owns this connection proxy.
|
||||||
* @param {RemoteTarget} target
|
* @param {RemoteTarget} target
|
||||||
* The target that the console will connect to.
|
* The target that the console will connect to.
|
||||||
* @param {Boolean} needContentProcessMessagesListener
|
|
||||||
* Set to true to specifically add a ContentProcessMessages listener. This is
|
|
||||||
* needed for non-fission Browser Console for example.
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(webConsoleUI, target) {
|
||||||
webConsoleUI,
|
|
||||||
target,
|
|
||||||
needContentProcessMessagesListener = false
|
|
||||||
) {
|
|
||||||
this.webConsoleUI = webConsoleUI;
|
this.webConsoleUI = webConsoleUI;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.needContentProcessMessagesListener = needContentProcessMessagesListener;
|
|
||||||
this._connecter = null;
|
this._connecter = null;
|
||||||
|
|
||||||
this._onTabNavigated = this._onTabNavigated.bind(this);
|
this._onTabNavigated = this._onTabNavigated.bind(this);
|
||||||
|
|
@ -66,8 +58,6 @@ class WebConsoleConnectionProxy {
|
||||||
this.client = this.target.client;
|
this.client = this.target.client;
|
||||||
this.webConsoleFront = await this.target.getFront("console");
|
this.webConsoleFront = await this.target.getFront("console");
|
||||||
|
|
||||||
await this._attachConsole();
|
|
||||||
|
|
||||||
// There is no way to view response bodies from the Browser Console, so do
|
// There is no way to view response bodies from the Browser Console, so do
|
||||||
// not waste the memory.
|
// not waste the memory.
|
||||||
const saveBodies =
|
const saveBodies =
|
||||||
|
|
@ -109,23 +99,6 @@ class WebConsoleConnectionProxy {
|
||||||
return this._connecter;
|
return this._connecter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Attach to the Web Console actor.
|
|
||||||
* @private
|
|
||||||
* @returns Promise
|
|
||||||
*/
|
|
||||||
_attachConsole() {
|
|
||||||
if (!this.webConsoleFront || !this.needContentProcessMessagesListener) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable the forwarding of console messages to the parent process
|
|
||||||
// when we open the Browser Console or Toolbox without fission support. If Fission
|
|
||||||
// is enabled, we don't use the ContentProcessMessages listener, but attach to the
|
|
||||||
// content processes directly.
|
|
||||||
return this.webConsoleFront.startListeners(["ContentProcessMessages"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all the relevant event listeners on the webconsole client.
|
* Sets all the relevant event listeners on the webconsole client.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -349,6 +349,7 @@ class WebConsoleUI {
|
||||||
resourceWatcher.TYPES.PLATFORM_MESSAGE,
|
resourceWatcher.TYPES.PLATFORM_MESSAGE,
|
||||||
resourceWatcher.TYPES.NETWORK_EVENT,
|
resourceWatcher.TYPES.NETWORK_EVENT,
|
||||||
resourceWatcher.TYPES.NETWORK_EVENT_STACKTRACE,
|
resourceWatcher.TYPES.NETWORK_EVENT_STACKTRACE,
|
||||||
|
resourceWatcher.TYPES.CLONED_CONTENT_PROCESS_MESSAGE,
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
onAvailable: this._onResourceAvailable,
|
onAvailable: this._onResourceAvailable,
|
||||||
|
|
@ -433,15 +434,7 @@ class WebConsoleUI {
|
||||||
// This is a top level target. It may update on process switches
|
// This is a top level target. It may update on process switches
|
||||||
// when navigating to another domain.
|
// when navigating to another domain.
|
||||||
if (targetFront.isTopLevel) {
|
if (targetFront.isTopLevel) {
|
||||||
const needContentProcessMessagesListener =
|
this.proxy = new WebConsoleConnectionProxy(this, targetFront);
|
||||||
targetFront.isParentProcess &&
|
|
||||||
!targetFront.isAddon &&
|
|
||||||
!this.fissionSupport;
|
|
||||||
this.proxy = new WebConsoleConnectionProxy(
|
|
||||||
this,
|
|
||||||
targetFront,
|
|
||||||
needContentProcessMessagesListener
|
|
||||||
);
|
|
||||||
await this.proxy.connect();
|
await this.proxy.connect();
|
||||||
dispatchTargetAvailable();
|
dispatchTargetAvailable();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -754,8 +754,8 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!this.contentProcessListener) {
|
if (!this.contentProcessListener) {
|
||||||
this.contentProcessListener = new ContentProcessListener(
|
this.contentProcessListener = new ContentProcessListener(message =>
|
||||||
this.onConsoleAPICall
|
this.onConsoleAPICall(message, { clonedFromContentProcess: true })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
startedListeners.push(event);
|
startedListeners.push(event);
|
||||||
|
|
@ -1788,10 +1788,13 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
|
||||||
* @see ConsoleAPIListener
|
* @see ConsoleAPIListener
|
||||||
* @param object message
|
* @param object message
|
||||||
* The console API call we need to send to the remote client.
|
* The console API call we need to send to the remote client.
|
||||||
|
* @param object extraProperties
|
||||||
|
* an object whose properties will be folded in the packet that is emitted.
|
||||||
*/
|
*/
|
||||||
onConsoleAPICall: function(message) {
|
onConsoleAPICall: function(message, extraProperties = {}) {
|
||||||
this.emit("consoleAPICall", {
|
this.emit("consoleAPICall", {
|
||||||
message: this.prepareConsoleMessageForRemote(message),
|
message: this.prepareConsoleMessageForRemote(message),
|
||||||
|
...extraProperties,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* 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 {
|
||||||
|
ResourceWatcher,
|
||||||
|
} = require("devtools/shared/resources/resource-watcher");
|
||||||
|
|
||||||
|
const Services = require("Services");
|
||||||
|
|
||||||
|
// This legacy listener is used to retrieve content messages that are cloned from content
|
||||||
|
// process to the parent process for BrowserConsole and BrowserToolbox when multiprocess
|
||||||
|
// support is disabled.
|
||||||
|
module.exports = async function({ targetList, targetFront, onAvailable }) {
|
||||||
|
const browserToolboxFissionSupport = Services.prefs.getBoolPref(
|
||||||
|
"devtools.browsertoolbox.fission",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
// Content process messages should only be retrieved for top-level browser console and
|
||||||
|
// browser toolbox targets, when fission support is disabled.
|
||||||
|
const acceptTarget =
|
||||||
|
targetFront.isParentProcess &&
|
||||||
|
!targetFront.isAddon &&
|
||||||
|
!browserToolboxFissionSupport;
|
||||||
|
|
||||||
|
if (!acceptTarget) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const webConsoleFront = await targetFront.getFront("console");
|
||||||
|
if (webConsoleFront.isDestroyed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request notifying about new messages
|
||||||
|
await webConsoleFront.startListeners(["ContentProcessMessages"]);
|
||||||
|
|
||||||
|
// ContentProcessMessages are sent through the consoleAPICall event, and are seen as
|
||||||
|
// console api messages on the client.
|
||||||
|
webConsoleFront.on("consoleAPICall", packet => {
|
||||||
|
// Ignore console messages that aren't from the content process
|
||||||
|
if (!packet.clonedFromContentProcess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
packet.resourceType = ResourceWatcher.TYPES.CONSOLE_MESSAGE;
|
||||||
|
onAvailable([packet]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -48,6 +48,12 @@ module.exports = async function({ targetList, targetFront, onAvailable }) {
|
||||||
|
|
||||||
// Forward new message events
|
// Forward new message events
|
||||||
webConsoleFront.on("consoleAPICall", message => {
|
webConsoleFront.on("consoleAPICall", message => {
|
||||||
|
// Ignore console messages that are cloned from the content process (they're handled
|
||||||
|
// by the cloned-content-process-messages legacy listener).
|
||||||
|
if (message.clonedFromContentProcess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
message.resourceType = ResourceWatcher.TYPES.CONSOLE_MESSAGE;
|
message.resourceType = ResourceWatcher.TYPES.CONSOLE_MESSAGE;
|
||||||
onAvailable([message]);
|
onAvailable([message]);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
DevToolsModules(
|
DevToolsModules(
|
||||||
"cache-storage.js",
|
"cache-storage.js",
|
||||||
|
"cloned-content-process-messages.js",
|
||||||
"console-messages.js",
|
"console-messages.js",
|
||||||
"cookie.js",
|
"cookie.js",
|
||||||
"css-changes.js",
|
"css-changes.js",
|
||||||
|
|
|
||||||
|
|
@ -866,6 +866,8 @@ ResourceWatcher.TYPES = ResourceWatcher.prototype.TYPES = {
|
||||||
CSS_MESSAGE: "css-message",
|
CSS_MESSAGE: "css-message",
|
||||||
ERROR_MESSAGE: "error-message",
|
ERROR_MESSAGE: "error-message",
|
||||||
PLATFORM_MESSAGE: "platform-message",
|
PLATFORM_MESSAGE: "platform-message",
|
||||||
|
// Legacy listener only. Can be removed in Bug 1625937.
|
||||||
|
CLONED_CONTENT_PROCESS_MESSAGE: "cloned-content-process-message",
|
||||||
DOCUMENT_EVENT: "document-event",
|
DOCUMENT_EVENT: "document-event",
|
||||||
ROOT_NODE: "root-node",
|
ROOT_NODE: "root-node",
|
||||||
STYLESHEET: "stylesheet",
|
STYLESHEET: "stylesheet",
|
||||||
|
|
@ -898,6 +900,8 @@ const LegacyListeners = {
|
||||||
.ERROR_MESSAGE]: require("devtools/shared/resources/legacy-listeners/error-messages"),
|
.ERROR_MESSAGE]: require("devtools/shared/resources/legacy-listeners/error-messages"),
|
||||||
[ResourceWatcher.TYPES
|
[ResourceWatcher.TYPES
|
||||||
.PLATFORM_MESSAGE]: require("devtools/shared/resources/legacy-listeners/platform-messages"),
|
.PLATFORM_MESSAGE]: require("devtools/shared/resources/legacy-listeners/platform-messages"),
|
||||||
|
[ResourceWatcher.TYPES
|
||||||
|
.CLONED_CONTENT_PROCESS_MESSAGE]: require("devtools/shared/resources/legacy-listeners/cloned-content-process-messages"),
|
||||||
async [ResourceWatcher.TYPES.DOCUMENT_EVENT]({
|
async [ResourceWatcher.TYPES.DOCUMENT_EVENT]({
|
||||||
targetList,
|
targetList,
|
||||||
targetFront,
|
targetFront,
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ const webconsoleSpecPrototype = {
|
||||||
},
|
},
|
||||||
consoleAPICall: {
|
consoleAPICall: {
|
||||||
message: Option(0, "json"),
|
message: Option(0, "json"),
|
||||||
|
clonedFromContentProcess: Option(0, "nullable:boolean"),
|
||||||
},
|
},
|
||||||
reflowActivity: {
|
reflowActivity: {
|
||||||
interruptible: Option(0, "boolean"),
|
interruptible: Option(0, "boolean"),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue