Skip to content

Commit 6f20416

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[protocol] Rename 'Connection' to 'ConnectionTransport'
This aligns nomenclature with puppeteer and frees up the name so we can add a 'CDPConnection' class that operates on CDP messages rather then raw strings. [email protected] Bug: 453469270 Change-Id: I1c5cf1f217d2f3cdef62f534b987fec5493aee91 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7071006 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent 084ccb6 commit 6f20416

File tree

16 files changed

+74
-61
lines changed

16 files changed

+74
-61
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ grd_files_unbundled_sources = [
894894
"front_end/core/platform/TypescriptUtilities.js",
895895
"front_end/core/platform/UIString.js",
896896
"front_end/core/platform/UserVisibleError.js",
897+
"front_end/core/protocol_client/ConnectionTransport.js",
897898
"front_end/core/protocol_client/InspectorBackend.js",
898899
"front_end/core/protocol_client/NodeURL.js",
899900
"front_end/core/root/Runtime.js",

front_end/core/protocol_client/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import("../../../scripts/build/typescript/typescript.gni")
88

99
devtools_module("protocol_client") {
1010
sources = [
11+
"ConnectionTransport.ts",
1112
"InspectorBackend.ts",
1213
"NodeURL.ts",
1314
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
let connectionFactory: () => ConnectionTransport;
6+
7+
export abstract class ConnectionTransport {
8+
declare onMessage: ((arg0: Object) => void)|null;
9+
10+
// on message from browser
11+
abstract setOnMessage(onMessage: (arg0: Object|string) => void): void;
12+
abstract setOnDisconnect(onDisconnect: (arg0: string) => void): void;
13+
14+
// send raw CDP message to browser
15+
abstract sendRawMessage(message: string): void;
16+
17+
abstract disconnect(): Promise<void>;
18+
19+
static setFactory(factory: () => ConnectionTransport): void {
20+
connectionFactory = factory;
21+
}
22+
23+
static getFactory(): () => ConnectionTransport {
24+
return connectionFactory;
25+
}
26+
}

front_end/core/protocol_client/InspectorBackend.ts

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
77
import type * as Protocol from '../../generated/protocol.js';
88
import type * as Platform from '../platform/platform.js';
99

10+
import {ConnectionTransport} from './ConnectionTransport.js';
1011
import {NodeURL} from './NodeURL.js';
1112

1213
export const DevToolsStubErrorCode = -32015;
@@ -160,35 +161,6 @@ export class InspectorBackend {
160161
}
161162
}
162163

163-
let connectionFactory: () => Connection;
164-
165-
export class Connection {
166-
declare onMessage: ((arg0: Object) => void)|null;
167-
168-
// on message from browser
169-
setOnMessage(_onMessage: (arg0: Object|string) => void): void {
170-
}
171-
172-
setOnDisconnect(_onDisconnect: (arg0: string) => void): void {
173-
}
174-
175-
// send raw CDP message to browser
176-
sendRawMessage(_message: string): void {
177-
}
178-
179-
disconnect(): Promise<void> {
180-
throw new Error('not implemented');
181-
}
182-
183-
static setFactory(factory: () => Connection): void {
184-
connectionFactory = factory;
185-
}
186-
187-
static getFactory(): () => Connection {
188-
return connectionFactory;
189-
}
190-
}
191-
192164
type SendRawMessageCallback = (...args: unknown[]) => void;
193165

194166
export const test = {
@@ -232,18 +204,18 @@ export const test = {
232204
const LongPollingMethods = new Set<string>(['CSS.takeComputedStyleUpdates']);
233205

234206
export class SessionRouter {
235-
readonly #connection: Connection;
207+
readonly #connection: ConnectionTransport;
236208
#lastMessageId = 1;
237209
#pendingResponsesCount = 0;
238210
readonly #pendingLongPollingMessageIds = new Set<number>();
239211
readonly #sessions = new Map<string, {
240212
target: TargetBase,
241213
callbacks: Map<number, CallbackWithDebugInfo>,
242-
proxyConnection: Connection|undefined|null,
214+
proxyConnection: ConnectionTransport|undefined|null,
243215
}>();
244216
#pendingScripts: Array<() => void> = [];
245217

246-
constructor(connection: Connection) {
218+
constructor(connection: ConnectionTransport) {
247219
this.#connection = connection;
248220

249221
test.deprecatedRunAfterPendingDispatches = this.deprecatedRunAfterPendingDispatches.bind(this);
@@ -259,7 +231,7 @@ export class SessionRouter {
259231
});
260232
}
261233

262-
registerSession(target: TargetBase, sessionId: string, proxyConnection?: Connection|null): void {
234+
registerSession(target: TargetBase, sessionId: string, proxyConnection?: ConnectionTransport|null): void {
263235
// Only the Audits panel uses proxy connections. If it is ever possible to have multiple active at the
264236
// same time, it should be tested thoroughly.
265237
if (proxyConnection) {
@@ -297,7 +269,7 @@ export class SessionRouter {
297269
return this.#lastMessageId++;
298270
}
299271

300-
connection(): Connection {
272+
connection(): ConnectionTransport {
301273
return this.#connection;
302274
}
303275

@@ -497,7 +469,8 @@ export class TargetBase {
497469
#dispatchers: DispatcherMap = new Map();
498470

499471
constructor(
500-
needsNodeJSPatching: boolean, parentTarget: TargetBase|null, sessionId: string, connection: Connection|null) {
472+
needsNodeJSPatching: boolean, parentTarget: TargetBase|null, sessionId: string,
473+
connection: ConnectionTransport|null) {
501474
this.needsNodeJSPatching = needsNodeJSPatching;
502475
this.sessionId = sessionId;
503476

@@ -511,7 +484,7 @@ export class TargetBase {
511484
} else if (connection) {
512485
router = new SessionRouter(connection);
513486
} else {
514-
router = new SessionRouter(connectionFactory());
487+
router = new SessionRouter(ConnectionTransport.getFactory()());
515488
}
516489

517490
this.#router = router;

front_end/core/protocol_client/protocol_client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import * as ConnectionTransport from './ConnectionTransport.js';
56
import * as InspectorBackend from './InspectorBackend.js';
67
import * as NodeURL from './NodeURL.js';
78

89
export {
10+
ConnectionTransport,
911
InspectorBackend,
1012
NodeURL,
1113
};

front_end/core/sdk/ChildTargetManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ChildTargetManager extends SDKModel<EventTypes> implements Protocol
3636
readonly #targetInfos = new Map<Protocol.Target.TargetID, Protocol.Target.TargetInfo>();
3737
readonly #childTargetsBySessionId = new Map<Protocol.Target.SessionID, Target>();
3838
readonly #childTargetsById = new Map<Protocol.Target.TargetID|'main', Target>();
39-
readonly #parallelConnections = new Map<string, ProtocolClient.InspectorBackend.Connection>();
39+
readonly #parallelConnections = new Map<string, ProtocolClient.ConnectionTransport.ConnectionTransport>();
4040
#parentTargetId: Protocol.Target.TargetID|null = null;
4141

4242
constructor(parentTarget: Target) {
@@ -261,7 +261,7 @@ export class ChildTargetManager extends SDKModel<EventTypes> implements Protocol
261261
}
262262

263263
async createParallelConnection(onMessage: (arg0: Object|string) => void):
264-
Promise<{connection: ProtocolClient.InspectorBackend.Connection, sessionId: string}> {
264+
Promise<{connection: ProtocolClient.ConnectionTransport.ConnectionTransport, sessionId: string}> {
265265
// The main Target id is actually just `main`, instead of the real targetId.
266266
// Get the real id (requires an async operation) so that it can be used synchronously later.
267267
const targetId = await this.getParentTargetId();
@@ -274,7 +274,7 @@ export class ChildTargetManager extends SDKModel<EventTypes> implements Protocol
274274

275275
private async createParallelConnectionAndSessionForTarget(target: Target, targetId: Protocol.Target.TargetID):
276276
Promise<{
277-
connection: ProtocolClient.InspectorBackend.Connection,
277+
connection: ProtocolClient.ConnectionTransport.ConnectionTransport,
278278
sessionId: string,
279279
}> {
280280
const targetAgent = target.targetAgent();

front_end/core/sdk/Connections.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const UIStrings = {
1919
} as const;
2020
const str_ = i18n.i18n.registerUIStrings('core/sdk/Connections.ts', UIStrings);
2121
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
22-
export class MainConnection implements ProtocolClient.InspectorBackend.Connection {
22+
export class MainConnection implements ProtocolClient.ConnectionTransport.ConnectionTransport {
2323
onMessage: ((arg0: Object|string) => void)|null = null;
2424
#onDisconnect: ((arg0: string) => void)|null = null;
2525
#messageBuffer = '';
@@ -81,7 +81,7 @@ export class MainConnection implements ProtocolClient.InspectorBackend.Connectio
8181
}
8282
}
8383

84-
export class WebSocketConnection implements ProtocolClient.InspectorBackend.Connection {
84+
export class WebSocketConnection implements ProtocolClient.ConnectionTransport.ConnectionTransport {
8585
#socket: WebSocket|null;
8686
onMessage: ((arg0: Object|string) => void)|null = null;
8787
#onDisconnect: ((arg0: string) => void)|null = null;
@@ -176,7 +176,7 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
176176
}
177177
}
178178

179-
export class StubConnection implements ProtocolClient.InspectorBackend.Connection {
179+
export class StubConnection implements ProtocolClient.ConnectionTransport.ConnectionTransport {
180180
onMessage: ((arg0: Object|string) => void)|null = null;
181181
#onDisconnect: ((arg0: string) => void)|null = null;
182182

@@ -213,17 +213,17 @@ export class StubConnection implements ProtocolClient.InspectorBackend.Connectio
213213
}
214214
}
215215

216-
export interface ParallelConnectionInterface extends ProtocolClient.InspectorBackend.Connection {
216+
export interface ParallelConnectionInterface extends ProtocolClient.ConnectionTransport.ConnectionTransport {
217217
getSessionId: () => string;
218218
getOnDisconnect: () => ((arg0: string) => void) | null;
219219
}
220220

221221
export class ParallelConnection implements ParallelConnectionInterface {
222-
readonly #connection: ProtocolClient.InspectorBackend.Connection;
222+
readonly #connection: ProtocolClient.ConnectionTransport.ConnectionTransport;
223223
#sessionId: string;
224224
onMessage: ((arg0: Object) => void)|null = null;
225225
#onDisconnect: ((arg0: string) => void)|null = null;
226-
constructor(connection: ProtocolClient.InspectorBackend.Connection, sessionId: string) {
226+
constructor(connection: ProtocolClient.ConnectionTransport.ConnectionTransport, sessionId: string) {
227227
this.#connection = connection;
228228
this.#sessionId = sessionId;
229229
}
@@ -265,13 +265,13 @@ export class ParallelConnection implements ParallelConnectionInterface {
265265
export async function initMainConnection(
266266
createRootTarget: () => Promise<void>,
267267
onConnectionLost: (message: Platform.UIString.LocalizedString) => void): Promise<void> {
268-
ProtocolClient.InspectorBackend.Connection.setFactory(createMainConnection.bind(null, onConnectionLost));
268+
ProtocolClient.ConnectionTransport.ConnectionTransport.setFactory(createMainConnection.bind(null, onConnectionLost));
269269
await createRootTarget();
270270
Host.InspectorFrontendHost.InspectorFrontendHostInstance.connectionReady();
271271
}
272272

273273
function createMainConnection(onConnectionLost: (message: Platform.UIString.LocalizedString) => void):
274-
ProtocolClient.InspectorBackend.Connection {
274+
ProtocolClient.ConnectionTransport.ConnectionTransport {
275275
if (Root.Runtime.Runtime.isTraceApp()) {
276276
return new RehydratingConnection(onConnectionLost);
277277
}

front_end/core/sdk/RehydratingConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const enum RehydratingConnectionState {
6363
REHYDRATED = 3,
6464
}
6565

66-
export class RehydratingConnection implements ProtocolClient.InspectorBackend.Connection {
66+
export class RehydratingConnection implements ProtocolClient.ConnectionTransport.ConnectionTransport {
6767
rehydratingConnectionState: RehydratingConnectionState = RehydratingConnectionState.UNINITIALIZED;
6868
onDisconnect: ((arg0: string) => void)|null = null;
6969
onMessage: ((arg0: Object) => void)|null = null;

front_end/core/sdk/Target.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export class Target extends ProtocolClient.InspectorBackend.TargetBase {
3939
constructor(
4040
targetManager: TargetManager, id: Protocol.Target.TargetID|'main', name: string, type: Type,
4141
parentTarget: Target|null, sessionId: string, suspended: boolean,
42-
connection: ProtocolClient.InspectorBackend.Connection|null, targetInfo?: Protocol.Target.TargetInfo) {
42+
connection: ProtocolClient.ConnectionTransport.ConnectionTransport|null,
43+
targetInfo?: Protocol.Target.TargetInfo) {
4344
const needsNodeJSPatching = type === Type.NODE;
4445
super(needsNodeJSPatching, parentTarget, sessionId, connection);
4546
this.#targetManager = targetManager;

front_end/core/sdk/TargetManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ export class TargetManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes
209209

210210
createTarget(
211211
id: Protocol.Target.TargetID|'main', name: string, type: TargetType, parentTarget: Target|null,
212-
sessionId?: string, waitForDebuggerInPage?: boolean, connection?: ProtocolClient.InspectorBackend.Connection,
212+
sessionId?: string, waitForDebuggerInPage?: boolean,
213+
connection?: ProtocolClient.ConnectionTransport.ConnectionTransport,
213214
targetInfo?: Protocol.Target.TargetInfo): Target {
214215
const target = new Target(
215216
this, id, name, type, parentTarget, sessionId || '', this.#isSuspended, connection || null, targetInfo);

0 commit comments

Comments
 (0)