DevTools: Warn on multiple proxy connections on registration. Instead of in _onMessage. Bug: 1011228 Change-Id: I56699d605ed2cae36361031f1ecf071ee3110e91 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1854642 Commit-Queue: Connor Clark <cjamcl@google.com> Reviewed-by: Paul Irish <paulirish@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#707097} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 5648a3eb962d84a65a626cf88ddea7b5f80c0eb0
diff --git a/front_end/protocol/InspectorBackend.js b/front_end/protocol/InspectorBackend.js index 943fc16..e3cc3a6 100644 --- a/front_end/protocol/InspectorBackend.js +++ b/front_end/protocol/InspectorBackend.js
@@ -312,6 +312,17 @@ * @param {?Connection} proxyConnection */ registerSession(target, sessionId, proxyConnection) { + // Only the Audits panel uses proxy connections. If it is ever possible to have multiple active at the + // same time, it should be tested thoroughly. + if (proxyConnection) { + for (const session of this._sessions.values()) { + if (session.proxyConnection) { + console.error('Multiple simultaneous proxy connections are currently unsupported'); + break; + } + } + } + this._sessions.set(sessionId, {target, callbacks: new Map(), proxyConnection}); } @@ -414,32 +425,26 @@ const messageObject = /** @type {!Object} */ ((typeof message === 'string') ? JSON.parse(message) : message); // Send all messages to proxy connections. - let proxyConnectionIsActive = false; + let suppressUnknownMessageErrors = false; for (const session of this._sessions.values()) { if (!session.proxyConnection) { continue; } - // Only the Audits panel has use proxy connections. If it is ever possible to have multiple active at the - // 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._onMessage) { - session.proxyConnection._onMessage(messageObject); - proxyConnectionIsActive = true; - } else { + if (!session.proxyConnection._onMessage) { Protocol.InspectorBackend.reportProtocolError( 'Protocol Error: the session has a proxyConnection with no _onMessage', messageObject); + continue; } + + session.proxyConnection._onMessage(messageObject); + suppressUnknownMessageErrors = true; } const sessionId = messageObject.sessionId || ''; const session = this._sessions.get(sessionId); if (!session) { - if (!proxyConnectionIsActive) { + if (!suppressUnknownMessageErrors) { Protocol.InspectorBackend.reportProtocolError( 'Protocol Error: the message with wrong session id', messageObject); } @@ -459,7 +464,7 @@ const callback = session.callbacks.get(messageObject.id); session.callbacks.delete(messageObject.id); if (!callback) { - if (!proxyConnectionIsActive) { + if (!suppressUnknownMessageErrors) { Protocol.InspectorBackend.reportProtocolError('Protocol Error: the message with wrong id', messageObject); } return;