Commit 1079b28e authored by cjamcl@google.com's avatar cjamcl@google.com Committed by Commit Bot

DevTools: [Audits] Send messages from child targets to proxy connections.

Related: https://github.com/GoogleChrome/lighthouse/pull/9783

Bug: 1011228
Change-Id: I8c232c8f440df72d3780dc66a03166cddc9f5287
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1838310
Commit-Queue: Connor Clark <cjamcl@google.com>
Reviewed-by: default avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704425}
parent 80616a80
...@@ -413,32 +413,55 @@ export class SessionRouter { ...@@ -413,32 +413,55 @@ export class SessionRouter {
const messageObject = /** @type {!Object} */ ((typeof message === 'string') ? JSON.parse(message) : message); const messageObject = /** @type {!Object} */ ((typeof message === 'string') ? JSON.parse(message) : message);
const sessionId = messageObject.sessionId || ''; // Send all messages to proxy connections.
const session = this._sessions.get(sessionId); let proxyConnectionIsActive = false;
if (!session) { for (const session of this._sessions.values()) {
Protocol.InspectorBackend.reportProtocolError('Protocol Error: the message with wrong session id', messageObject); if (!session.proxyConnection) {
return; continue;
} }
if (session.target._needsNodeJSPatching) { // Only the Audits panel has use proxy connections. If it is ever possible to have multiple active at the
Protocol.NodeURL.patch(messageObject); // same time, it should be test thoroughly.
} if (proxyConnectionIsActive) {
Protocol.InspectorBackend.reportProtocolError(
'Protocol Error: multiple proxy connections are not explicitly supported right now', messageObject);
}
if (session.proxyConnection) {
if (session.proxyConnection._onMessage) { if (session.proxyConnection._onMessage) {
session.proxyConnection._onMessage(messageObject); session.proxyConnection._onMessage(messageObject);
proxyConnectionIsActive = true;
} else { } else {
Protocol.InspectorBackend.reportProtocolError( Protocol.InspectorBackend.reportProtocolError(
'Protocol Error: the message has a proxyConnection with no _onMessage', messageObject); 'Protocol Error: the session has a proxyConnection with no _onMessage', messageObject);
} }
}
const sessionId = messageObject.sessionId || '';
const session = this._sessions.get(sessionId);
if (!session) {
if (!proxyConnectionIsActive) {
Protocol.InspectorBackend.reportProtocolError(
'Protocol Error: the message with wrong session id', messageObject);
}
return;
}
// If this message is directly for the target controlled by the proxy connection, don't handle it.
if (session.proxyConnection) {
return; return;
} }
if (session.target._needsNodeJSPatching) {
Protocol.NodeURL.patch(messageObject);
}
if ('id' in messageObject) { // just a response for some request if ('id' in messageObject) { // just a response for some request
const callback = session.callbacks.get(messageObject.id); const callback = session.callbacks.get(messageObject.id);
session.callbacks.delete(messageObject.id); session.callbacks.delete(messageObject.id);
if (!callback) { if (!callback) {
Protocol.InspectorBackend.reportProtocolError('Protocol Error: the message with wrong id', messageObject); if (!proxyConnectionIsActive) {
Protocol.InspectorBackend.reportProtocolError('Protocol Error: the message with wrong id', messageObject);
}
return; return;
} }
......
...@@ -216,8 +216,8 @@ export default class ChildTargetManager extends SDK.SDKModel { ...@@ -216,8 +216,8 @@ export default class ChildTargetManager extends SDK.SDKModel {
const sessionId = /** @type {string} */ (await targetAgent.attachToTarget(targetId, true /* flatten */)); const sessionId = /** @type {string} */ (await targetAgent.attachToTarget(targetId, true /* flatten */));
const connection = new SDK.ParallelConnection(targetRouter.connection(), sessionId); const connection = new SDK.ParallelConnection(targetRouter.connection(), sessionId);
targetRouter.registerSession(target, sessionId, connection); targetRouter.registerSession(target, sessionId, connection);
connection.setOnDisconnect(async () => { connection.setOnDisconnect(() => {
await targetAgent.detachFromTarget(sessionId); targetAgent.detachFromTarget(sessionId);
targetRouter.unregisterSession(sessionId); targetRouter.unregisterSession(sessionId);
}); });
return {connection, sessionId}; return {connection, sessionId};
......
...@@ -294,7 +294,10 @@ export class ParallelConnection { ...@@ -294,7 +294,10 @@ export class ParallelConnection {
*/ */
sendRawMessage(message) { sendRawMessage(message) {
const messageObject = JSON.parse(message); const messageObject = JSON.parse(message);
messageObject.sessionId = this._sessionId; // If the message isn't for a specific session, it must be for the root session.
if (!messageObject.sessionId) {
messageObject.sessionId = this._sessionId;
}
this._connection.sendRawMessage(JSON.stringify(messageObject)); this._connection.sendRawMessage(JSON.stringify(messageObject));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment