Skip to content

Commit 9b2f871

Browse files
TimvdLippeCommit Bot
authored and
Commit Bot
committed
Migrate console/ to import cross-module
Bug: 1006759 Change-Id: I685b1c819e17acab6db5f440cdf8e4b173712649 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2051961 Reviewed-by: Paul Lewis <[email protected]> Commit-Queue: Tim van der Lippe <[email protected]>
1 parent 97e4a75 commit 9b2f871

10 files changed

+459
-388
lines changed

front_end/console/ConsoleContextSelector.js

+60-50
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
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 Common from '../common/common.js';
6+
import * as SDK from '../sdk/sdk.js';
7+
import * as UI from '../ui/ui.js';
8+
59
/**
6-
* @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>}
7-
* @implements {UI.SoftDropDown.Delegate<!SDK.ExecutionContext>}
10+
* @implements {SDK.SDKModel.SDKModelObserver<!SDK.RuntimeModel.RuntimeModel>}
11+
* @implements {UI.SoftDropDown.Delegate<!SDK.RuntimeModel.ExecutionContext>}
812
*/
913
export class ConsoleContextSelector {
1014
constructor() {
11-
/** @type {!UI.ListModel<!SDK.ExecutionContext>} */
12-
this._items = new UI.ListModel();
13-
/** @type {!UI.SoftDropDown<!SDK.ExecutionContext>} */
14-
this._dropDown = new UI.SoftDropDown(this._items, this);
15+
/** @type {!UI.ListModel.ListModel<!SDK.RuntimeModel.ExecutionContext>} */
16+
this._items = new UI.ListModel.ListModel();
17+
/** @type {!UI.SoftDropDown.SoftDropDown<!SDK.RuntimeModel.ExecutionContext>} */
18+
this._dropDown = new UI.SoftDropDown.SoftDropDown(this._items, this);
1519
this._dropDown.setRowHeight(36);
16-
this._toolbarItem = new UI.ToolbarItem(this._dropDown.element);
20+
this._toolbarItem = new UI.Toolbar.ToolbarItem(this._dropDown.element);
1721
this._toolbarItem.setEnabled(false);
1822
this._toolbarItem.setTitle(ls`JavaScript context: Not selected`);
1923
this._items.addEventListener(
@@ -22,39 +26,45 @@ export class ConsoleContextSelector {
2226
this._toolbarItem.element.classList.add('toolbar-has-dropdown');
2327

2428
self.SDK.targetManager.addModelListener(
25-
SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
29+
SDK.RuntimeModel.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated,
30+
this);
2631
self.SDK.targetManager.addModelListener(
27-
SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextChanged, this);
32+
SDK.RuntimeModel.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextChanged,
33+
this);
2834
self.SDK.targetManager.addModelListener(
29-
SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
35+
SDK.RuntimeModel.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed,
36+
this._onExecutionContextDestroyed, this);
3037
self.SDK.targetManager.addModelListener(
31-
SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this._frameNavigated, this);
38+
SDK.ResourceTreeModel.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this._frameNavigated,
39+
this);
3240

33-
self.UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._executionContextChangedExternally, this);
41+
self.UI.context.addFlavorChangeListener(
42+
SDK.RuntimeModel.ExecutionContext, this._executionContextChangedExternally, this);
3443
self.UI.context.addFlavorChangeListener(SDK.DebuggerModel.CallFrame, this._callFrameSelectedInUI, this);
35-
self.SDK.targetManager.observeModels(SDK.RuntimeModel, this);
44+
self.SDK.targetManager.observeModels(SDK.RuntimeModel.RuntimeModel, this);
3645
self.SDK.targetManager.addModelListener(
37-
SDK.DebuggerModel, SDK.DebuggerModel.Events.CallFrameSelected, this._callFrameSelectedInModel, this);
46+
SDK.DebuggerModel.DebuggerModel, SDK.DebuggerModel.Events.CallFrameSelected, this._callFrameSelectedInModel,
47+
this);
3848
}
3949

4050
/**
41-
* @return {!UI.ToolbarItem}
51+
* @return {!UI.Toolbar.ToolbarItem}
4252
*/
4353
toolbarItem() {
4454
return this._toolbarItem;
4555
}
4656

4757
/**
4858
* @override
49-
* @param {?SDK.ExecutionContext} from
50-
* @param {?SDK.ExecutionContext} to
59+
* @param {?SDK.RuntimeModel.ExecutionContext} from
60+
* @param {?SDK.RuntimeModel.ExecutionContext} to
5161
* @param {?Element} fromElement
5262
* @param {?Element} toElement
5363
*/
5464
highlightedItemChanged(from, to, fromElement, toElement) {
55-
SDK.OverlayModel.hideDOMNodeHighlight();
65+
SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight();
5666
if (to && to.frameId) {
57-
const overlayModel = to.target().model(SDK.OverlayModel);
67+
const overlayModel = to.target().model(SDK.OverlayModel.OverlayModel);
5868
if (overlayModel) {
5969
overlayModel.highlightFrame(to.frameId);
6070
}
@@ -69,14 +79,14 @@ export class ConsoleContextSelector {
6979

7080
/**
7181
* @override
72-
* @param {!SDK.ExecutionContext} executionContext
82+
* @param {!SDK.RuntimeModel.ExecutionContext} executionContext
7383
* @return {string}
7484
*/
7585
titleFor(executionContext) {
7686
const target = executionContext.target();
7787
let label = executionContext.label() ? target.decorateLabel(executionContext.label()) : '';
7888
if (executionContext.frameId) {
79-
const resourceTreeModel = target.model(SDK.ResourceTreeModel);
89+
const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
8090
const frame = resourceTreeModel && resourceTreeModel.frameForId(executionContext.frameId);
8191
if (frame) {
8292
label = label || frame.displayName();
@@ -88,7 +98,7 @@ export class ConsoleContextSelector {
8898
}
8999

90100
/**
91-
* @param {!SDK.ExecutionContext} executionContext
101+
* @param {!SDK.RuntimeModel.ExecutionContext} executionContext
92102
* @return {number}
93103
*/
94104
_depthFor(executionContext) {
@@ -98,7 +108,7 @@ export class ConsoleContextSelector {
98108
depth++;
99109
}
100110
if (executionContext.frameId) {
101-
const resourceTreeModel = target.model(SDK.ResourceTreeModel);
111+
const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
102112
let frame = resourceTreeModel && resourceTreeModel.frameForId(executionContext.frameId);
103113
while (frame) {
104114
frame = frame.parentFrame || frame.crossTargetParentFrame();
@@ -110,7 +120,7 @@ export class ConsoleContextSelector {
110120
}
111121
let targetDepth = 0;
112122
// Special casing service workers to be top-level.
113-
while (target.parentTarget() && target.type() !== SDK.Target.Type.ServiceWorker) {
123+
while (target.parentTarget() && target.type() !== SDK.SDKModel.Type.ServiceWorker) {
114124
targetDepth++;
115125
target = target.parentTarget();
116126
}
@@ -119,12 +129,12 @@ export class ConsoleContextSelector {
119129
}
120130

121131
/**
122-
* @param {!SDK.ExecutionContext} executionContext
132+
* @param {!SDK.RuntimeModel.ExecutionContext} executionContext
123133
*/
124134
_executionContextCreated(executionContext) {
125135
this._items.insertWithComparator(executionContext, executionContext.runtimeModel.executionContextComparator());
126136

127-
if (executionContext === self.UI.context.flavor(SDK.ExecutionContext)) {
137+
if (executionContext === self.UI.context.flavor(SDK.RuntimeModel.ExecutionContext)) {
128138
this._dropDown.selectItem(executionContext);
129139
}
130140
}
@@ -133,15 +143,15 @@ export class ConsoleContextSelector {
133143
* @param {!Common.Event} event
134144
*/
135145
_onExecutionContextCreated(event) {
136-
const executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
146+
const executionContext = /** @type {!SDK.RuntimeModel.ExecutionContext} */ (event.data);
137147
this._executionContextCreated(executionContext);
138148
}
139149

140150
/**
141151
* @param {!Common.Event} event
142152
*/
143153
_onExecutionContextChanged(event) {
144-
const executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
154+
const executionContext = /** @type {!SDK.RuntimeModel.ExecutionContext} */ (event.data);
145155
if (this._items.indexOf(executionContext) === -1) {
146156
return;
147157
}
@@ -150,7 +160,7 @@ export class ConsoleContextSelector {
150160
}
151161

152162
/**
153-
* @param {!SDK.ExecutionContext} executionContext
163+
* @param {!SDK.RuntimeModel.ExecutionContext} executionContext
154164
*/
155165
_executionContextDestroyed(executionContext) {
156166
const index = this._items.indexOf(executionContext);
@@ -164,27 +174,27 @@ export class ConsoleContextSelector {
164174
* @param {!Common.Event} event
165175
*/
166176
_onExecutionContextDestroyed(event) {
167-
const executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
177+
const executionContext = /** @type {!SDK.RuntimeModel.ExecutionContext} */ (event.data);
168178
this._executionContextDestroyed(executionContext);
169179
}
170180

171181
/**
172182
* @param {!Common.Event} event
173183
*/
174184
_executionContextChangedExternally(event) {
175-
const executionContext = /** @type {?SDK.ExecutionContext} */ (event.data);
185+
const executionContext = /** @type {?SDK.RuntimeModel.ExecutionContext} */ (event.data);
176186
this._dropDown.selectItem(executionContext);
177187
}
178188

179189
/**
180-
* @param {?SDK.ExecutionContext} executionContext
190+
* @param {?SDK.RuntimeModel.ExecutionContext} executionContext
181191
* @return {boolean}
182192
*/
183193
_isTopContext(executionContext) {
184194
if (!executionContext || !executionContext.isDefault) {
185195
return false;
186196
}
187-
const resourceTreeModel = executionContext.target().model(SDK.ResourceTreeModel);
197+
const resourceTreeModel = executionContext.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
188198
const frame =
189199
executionContext.frameId && resourceTreeModel && resourceTreeModel.frameForId(executionContext.frameId);
190200
if (!frame) {
@@ -202,15 +212,15 @@ export class ConsoleContextSelector {
202212

203213
/**
204214
* @override
205-
* @param {!SDK.RuntimeModel} runtimeModel
215+
* @param {!SDK.RuntimeModel.RuntimeModel} runtimeModel
206216
*/
207217
modelAdded(runtimeModel) {
208218
runtimeModel.executionContexts().forEach(this._executionContextCreated, this);
209219
}
210220

211221
/**
212222
* @override
213-
* @param {!SDK.RuntimeModel} runtimeModel
223+
* @param {!SDK.RuntimeModel.RuntimeModel} runtimeModel
214224
*/
215225
modelRemoved(runtimeModel) {
216226
for (let i = this._items.length - 1; i >= 0; i--) {
@@ -222,12 +232,12 @@ export class ConsoleContextSelector {
222232

223233
/**
224234
* @override
225-
* @param {!SDK.ExecutionContext} item
235+
* @param {!SDK.RuntimeModel.ExecutionContext} item
226236
* @return {!Element}
227237
*/
228238
createElementForItem(item) {
229239
const element = createElementWithClass('div');
230-
const shadowRoot = UI.createShadowRootWithCoreStyles(element, 'console/consoleContextSelector.css');
240+
const shadowRoot = UI.Utils.createShadowRootWithCoreStyles(element, 'console/consoleContextSelector.css');
231241
const title = shadowRoot.createChild('div', 'title');
232242
title.createTextChild(this.titleFor(item).trimEndWithMaxLength(100));
233243
const subTitle = shadowRoot.createChild('div', 'subtitle');
@@ -237,21 +247,21 @@ export class ConsoleContextSelector {
237247
}
238248

239249
/**
240-
* @param {!SDK.ExecutionContext} executionContext
250+
* @param {!SDK.RuntimeModel.ExecutionContext} executionContext
241251
* @return {string}
242252
*/
243253
_subtitleFor(executionContext) {
244254
const target = executionContext.target();
245255
let frame;
246256
if (executionContext.frameId) {
247-
const resourceTreeModel = target.model(SDK.ResourceTreeModel);
257+
const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
248258
frame = resourceTreeModel && resourceTreeModel.frameForId(executionContext.frameId);
249259
}
250260
if (executionContext.origin.startsWith('chrome-extension://')) {
251-
return Common.UIString('Extension');
261+
return Common.UIString.UIString('Extension');
252262
}
253263
if (!frame || !frame.parentFrame || frame.parentFrame.securityOrigin !== executionContext.origin) {
254-
const url = Common.ParsedURL.fromString(executionContext.origin);
264+
const url = Common.ParsedURL.ParsedURL.fromString(executionContext.origin);
255265
if (url) {
256266
return url.domain();
257267
}
@@ -260,16 +270,16 @@ export class ConsoleContextSelector {
260270
if (frame) {
261271
const callFrame = frame.findCreationCallFrame(callFrame => !!callFrame.url);
262272
if (callFrame) {
263-
return new Common.ParsedURL(callFrame.url).domain();
273+
return new Common.ParsedURL.ParsedURL(callFrame.url).domain();
264274
}
265-
return Common.UIString('IFrame');
275+
return Common.UIString.UIString('IFrame');
266276
}
267277
return '';
268278
}
269279

270280
/**
271281
* @override
272-
* @param {!SDK.ExecutionContext} item
282+
* @param {!SDK.RuntimeModel.ExecutionContext} item
273283
* @return {boolean}
274284
*/
275285
isItemSelectable(item) {
@@ -280,28 +290,28 @@ export class ConsoleContextSelector {
280290

281291
/**
282292
* @override
283-
* @param {?SDK.ExecutionContext} item
293+
* @param {?SDK.RuntimeModel.ExecutionContext} item
284294
*/
285295
itemSelected(item) {
286296
this._toolbarItem.element.classList.toggle('warning', !this._isTopContext(item) && this._hasTopContext());
287297
const title = item ? ls`JavaScript context: ${this.titleFor(item)}` : ls`JavaScript context: Not selected`;
288298
this._toolbarItem.setTitle(title);
289-
self.UI.context.setFlavor(SDK.ExecutionContext, item);
299+
self.UI.context.setFlavor(SDK.RuntimeModel.ExecutionContext, item);
290300
}
291301

292302
_callFrameSelectedInUI() {
293303
const callFrame = self.UI.context.flavor(SDK.DebuggerModel.CallFrame);
294304
const callFrameContext = callFrame && callFrame.script.executionContext();
295305
if (callFrameContext) {
296-
self.UI.context.setFlavor(SDK.ExecutionContext, callFrameContext);
306+
self.UI.context.setFlavor(SDK.RuntimeModel.ExecutionContext, callFrameContext);
297307
}
298308
}
299309

300310
/**
301311
* @param {!Common.Event} event
302312
*/
303313
_callFrameSelectedInModel(event) {
304-
const debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data);
314+
const debuggerModel = /** @type {!SDK.DebuggerModel.DebuggerModel} */ (event.data);
305315
for (const executionContext of this._items) {
306316
if (executionContext.debuggerModel === debuggerModel) {
307317
this._dropDown.refreshItem(executionContext);
@@ -313,8 +323,8 @@ export class ConsoleContextSelector {
313323
* @param {!Common.Event} event
314324
*/
315325
_frameNavigated(event) {
316-
const frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data);
317-
const runtimeModel = frame.resourceTreeModel().target().model(SDK.RuntimeModel);
326+
const frame = /** @type {!SDK.ResourceTreeModel.ResourceTreeFrame} */ (event.data);
327+
const runtimeModel = frame.resourceTreeModel().target().model(SDK.RuntimeModel.RuntimeModel);
318328
if (!runtimeModel) {
319329
return;
320330
}

0 commit comments

Comments
 (0)