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:
Nicolas Chevobbe 2021-02-11 06:08:33 +00:00
parent 56d368a1ae
commit 15042471eb
8 changed files with 72 additions and 40 deletions

View file

@ -22,18 +22,10 @@ class WebConsoleConnectionProxy {
* A WebConsoleUI instance that owns this connection proxy.
* @param {RemoteTarget} target
* 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(
webConsoleUI,
target,
needContentProcessMessagesListener = false
) {
constructor(webConsoleUI, target) {
this.webConsoleUI = webConsoleUI;
this.target = target;
this.needContentProcessMessagesListener = needContentProcessMessagesListener;
this._connecter = null;
this._onTabNavigated = this._onTabNavigated.bind(this);
@ -66,8 +58,6 @@ class WebConsoleConnectionProxy {
this.client = this.target.client;
this.webConsoleFront = await this.target.getFront("console");
await this._attachConsole();
// There is no way to view response bodies from the Browser Console, so do
// not waste the memory.
const saveBodies =
@ -109,23 +99,6 @@ class WebConsoleConnectionProxy {
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.
*

View file

@ -349,6 +349,7 @@ class WebConsoleUI {
resourceWatcher.TYPES.PLATFORM_MESSAGE,
resourceWatcher.TYPES.NETWORK_EVENT,
resourceWatcher.TYPES.NETWORK_EVENT_STACKTRACE,
resourceWatcher.TYPES.CLONED_CONTENT_PROCESS_MESSAGE,
],
{
onAvailable: this._onResourceAvailable,
@ -433,15 +434,7 @@ class WebConsoleUI {
// This is a top level target. It may update on process switches
// when navigating to another domain.
if (targetFront.isTopLevel) {
const needContentProcessMessagesListener =
targetFront.isParentProcess &&
!targetFront.isAddon &&
!this.fissionSupport;
this.proxy = new WebConsoleConnectionProxy(
this,
targetFront,
needContentProcessMessagesListener
);
this.proxy = new WebConsoleConnectionProxy(this, targetFront);
await this.proxy.connect();
dispatchTargetAvailable();
return;

View file

@ -754,8 +754,8 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
break;
}
if (!this.contentProcessListener) {
this.contentProcessListener = new ContentProcessListener(
this.onConsoleAPICall
this.contentProcessListener = new ContentProcessListener(message =>
this.onConsoleAPICall(message, { clonedFromContentProcess: true })
);
}
startedListeners.push(event);
@ -1788,10 +1788,13 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
* @see ConsoleAPIListener
* @param object message
* 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", {
message: this.prepareConsoleMessageForRemote(message),
...extraProperties,
});
},

View file

@ -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]);
});
};

View file

@ -48,6 +48,12 @@ module.exports = async function({ targetList, targetFront, onAvailable }) {
// Forward new message events
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;
onAvailable([message]);
});

View file

@ -4,6 +4,7 @@
DevToolsModules(
"cache-storage.js",
"cloned-content-process-messages.js",
"console-messages.js",
"cookie.js",
"css-changes.js",

View file

@ -866,6 +866,8 @@ ResourceWatcher.TYPES = ResourceWatcher.prototype.TYPES = {
CSS_MESSAGE: "css-message",
ERROR_MESSAGE: "error-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",
ROOT_NODE: "root-node",
STYLESHEET: "stylesheet",
@ -898,6 +900,8 @@ const LegacyListeners = {
.ERROR_MESSAGE]: require("devtools/shared/resources/legacy-listeners/error-messages"),
[ResourceWatcher.TYPES
.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]({
targetList,
targetFront,

View file

@ -78,6 +78,7 @@ const webconsoleSpecPrototype = {
},
consoleAPICall: {
message: Option(0, "json"),
clonedFromContentProcess: Option(0, "nullable:boolean"),
},
reflowActivity: {
interruptible: Option(0, "boolean"),