2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
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
+
5
9
/**
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>}
8
12
*/
9
13
export class ConsoleContextSelector {
10
14
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 ) ;
15
19
this . _dropDown . setRowHeight ( 36 ) ;
16
- this . _toolbarItem = new UI . ToolbarItem ( this . _dropDown . element ) ;
20
+ this . _toolbarItem = new UI . Toolbar . ToolbarItem ( this . _dropDown . element ) ;
17
21
this . _toolbarItem . setEnabled ( false ) ;
18
22
this . _toolbarItem . setTitle ( ls `JavaScript context: Not selected` ) ;
19
23
this . _items . addEventListener (
@@ -22,39 +26,45 @@ export class ConsoleContextSelector {
22
26
this . _toolbarItem . element . classList . add ( 'toolbar-has-dropdown' ) ;
23
27
24
28
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 ) ;
26
31
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 ) ;
28
34
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 ) ;
30
37
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 ) ;
32
40
33
- self . UI . context . addFlavorChangeListener ( SDK . ExecutionContext , this . _executionContextChangedExternally , this ) ;
41
+ self . UI . context . addFlavorChangeListener (
42
+ SDK . RuntimeModel . ExecutionContext , this . _executionContextChangedExternally , this ) ;
34
43
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 ) ;
36
45
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 ) ;
38
48
}
39
49
40
50
/**
41
- * @return {!UI.ToolbarItem }
51
+ * @return {!UI.Toolbar. ToolbarItem }
42
52
*/
43
53
toolbarItem ( ) {
44
54
return this . _toolbarItem ;
45
55
}
46
56
47
57
/**
48
58
* @override
49
- * @param {?SDK.ExecutionContext } from
50
- * @param {?SDK.ExecutionContext } to
59
+ * @param {?SDK.RuntimeModel. ExecutionContext } from
60
+ * @param {?SDK.RuntimeModel. ExecutionContext } to
51
61
* @param {?Element } fromElement
52
62
* @param {?Element } toElement
53
63
*/
54
64
highlightedItemChanged ( from , to , fromElement , toElement ) {
55
- SDK . OverlayModel . hideDOMNodeHighlight ( ) ;
65
+ SDK . OverlayModel . OverlayModel . hideDOMNodeHighlight ( ) ;
56
66
if ( to && to . frameId ) {
57
- const overlayModel = to . target ( ) . model ( SDK . OverlayModel ) ;
67
+ const overlayModel = to . target ( ) . model ( SDK . OverlayModel . OverlayModel ) ;
58
68
if ( overlayModel ) {
59
69
overlayModel . highlightFrame ( to . frameId ) ;
60
70
}
@@ -69,14 +79,14 @@ export class ConsoleContextSelector {
69
79
70
80
/**
71
81
* @override
72
- * @param {!SDK.ExecutionContext } executionContext
82
+ * @param {!SDK.RuntimeModel. ExecutionContext } executionContext
73
83
* @return {string }
74
84
*/
75
85
titleFor ( executionContext ) {
76
86
const target = executionContext . target ( ) ;
77
87
let label = executionContext . label ( ) ? target . decorateLabel ( executionContext . label ( ) ) : '' ;
78
88
if ( executionContext . frameId ) {
79
- const resourceTreeModel = target . model ( SDK . ResourceTreeModel ) ;
89
+ const resourceTreeModel = target . model ( SDK . ResourceTreeModel . ResourceTreeModel ) ;
80
90
const frame = resourceTreeModel && resourceTreeModel . frameForId ( executionContext . frameId ) ;
81
91
if ( frame ) {
82
92
label = label || frame . displayName ( ) ;
@@ -88,7 +98,7 @@ export class ConsoleContextSelector {
88
98
}
89
99
90
100
/**
91
- * @param {!SDK.ExecutionContext } executionContext
101
+ * @param {!SDK.RuntimeModel. ExecutionContext } executionContext
92
102
* @return {number }
93
103
*/
94
104
_depthFor ( executionContext ) {
@@ -98,7 +108,7 @@ export class ConsoleContextSelector {
98
108
depth ++ ;
99
109
}
100
110
if ( executionContext . frameId ) {
101
- const resourceTreeModel = target . model ( SDK . ResourceTreeModel ) ;
111
+ const resourceTreeModel = target . model ( SDK . ResourceTreeModel . ResourceTreeModel ) ;
102
112
let frame = resourceTreeModel && resourceTreeModel . frameForId ( executionContext . frameId ) ;
103
113
while ( frame ) {
104
114
frame = frame . parentFrame || frame . crossTargetParentFrame ( ) ;
@@ -110,7 +120,7 @@ export class ConsoleContextSelector {
110
120
}
111
121
let targetDepth = 0 ;
112
122
// 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 ) {
114
124
targetDepth ++ ;
115
125
target = target . parentTarget ( ) ;
116
126
}
@@ -119,12 +129,12 @@ export class ConsoleContextSelector {
119
129
}
120
130
121
131
/**
122
- * @param {!SDK.ExecutionContext } executionContext
132
+ * @param {!SDK.RuntimeModel. ExecutionContext } executionContext
123
133
*/
124
134
_executionContextCreated ( executionContext ) {
125
135
this . _items . insertWithComparator ( executionContext , executionContext . runtimeModel . executionContextComparator ( ) ) ;
126
136
127
- if ( executionContext === self . UI . context . flavor ( SDK . ExecutionContext ) ) {
137
+ if ( executionContext === self . UI . context . flavor ( SDK . RuntimeModel . ExecutionContext ) ) {
128
138
this . _dropDown . selectItem ( executionContext ) ;
129
139
}
130
140
}
@@ -133,15 +143,15 @@ export class ConsoleContextSelector {
133
143
* @param {!Common.Event } event
134
144
*/
135
145
_onExecutionContextCreated ( event ) {
136
- const executionContext = /** @type {!SDK.ExecutionContext } */ ( event . data ) ;
146
+ const executionContext = /** @type {!SDK.RuntimeModel. ExecutionContext } */ ( event . data ) ;
137
147
this . _executionContextCreated ( executionContext ) ;
138
148
}
139
149
140
150
/**
141
151
* @param {!Common.Event } event
142
152
*/
143
153
_onExecutionContextChanged ( event ) {
144
- const executionContext = /** @type {!SDK.ExecutionContext } */ ( event . data ) ;
154
+ const executionContext = /** @type {!SDK.RuntimeModel. ExecutionContext } */ ( event . data ) ;
145
155
if ( this . _items . indexOf ( executionContext ) === - 1 ) {
146
156
return ;
147
157
}
@@ -150,7 +160,7 @@ export class ConsoleContextSelector {
150
160
}
151
161
152
162
/**
153
- * @param {!SDK.ExecutionContext } executionContext
163
+ * @param {!SDK.RuntimeModel. ExecutionContext } executionContext
154
164
*/
155
165
_executionContextDestroyed ( executionContext ) {
156
166
const index = this . _items . indexOf ( executionContext ) ;
@@ -164,27 +174,27 @@ export class ConsoleContextSelector {
164
174
* @param {!Common.Event } event
165
175
*/
166
176
_onExecutionContextDestroyed ( event ) {
167
- const executionContext = /** @type {!SDK.ExecutionContext } */ ( event . data ) ;
177
+ const executionContext = /** @type {!SDK.RuntimeModel. ExecutionContext } */ ( event . data ) ;
168
178
this . _executionContextDestroyed ( executionContext ) ;
169
179
}
170
180
171
181
/**
172
182
* @param {!Common.Event } event
173
183
*/
174
184
_executionContextChangedExternally ( event ) {
175
- const executionContext = /** @type {?SDK.ExecutionContext } */ ( event . data ) ;
185
+ const executionContext = /** @type {?SDK.RuntimeModel. ExecutionContext } */ ( event . data ) ;
176
186
this . _dropDown . selectItem ( executionContext ) ;
177
187
}
178
188
179
189
/**
180
- * @param {?SDK.ExecutionContext } executionContext
190
+ * @param {?SDK.RuntimeModel. ExecutionContext } executionContext
181
191
* @return {boolean }
182
192
*/
183
193
_isTopContext ( executionContext ) {
184
194
if ( ! executionContext || ! executionContext . isDefault ) {
185
195
return false ;
186
196
}
187
- const resourceTreeModel = executionContext . target ( ) . model ( SDK . ResourceTreeModel ) ;
197
+ const resourceTreeModel = executionContext . target ( ) . model ( SDK . ResourceTreeModel . ResourceTreeModel ) ;
188
198
const frame =
189
199
executionContext . frameId && resourceTreeModel && resourceTreeModel . frameForId ( executionContext . frameId ) ;
190
200
if ( ! frame ) {
@@ -202,15 +212,15 @@ export class ConsoleContextSelector {
202
212
203
213
/**
204
214
* @override
205
- * @param {!SDK.RuntimeModel } runtimeModel
215
+ * @param {!SDK.RuntimeModel.RuntimeModel } runtimeModel
206
216
*/
207
217
modelAdded ( runtimeModel ) {
208
218
runtimeModel . executionContexts ( ) . forEach ( this . _executionContextCreated , this ) ;
209
219
}
210
220
211
221
/**
212
222
* @override
213
- * @param {!SDK.RuntimeModel } runtimeModel
223
+ * @param {!SDK.RuntimeModel.RuntimeModel } runtimeModel
214
224
*/
215
225
modelRemoved ( runtimeModel ) {
216
226
for ( let i = this . _items . length - 1 ; i >= 0 ; i -- ) {
@@ -222,12 +232,12 @@ export class ConsoleContextSelector {
222
232
223
233
/**
224
234
* @override
225
- * @param {!SDK.ExecutionContext } item
235
+ * @param {!SDK.RuntimeModel. ExecutionContext } item
226
236
* @return {!Element }
227
237
*/
228
238
createElementForItem ( item ) {
229
239
const element = createElementWithClass ( 'div' ) ;
230
- const shadowRoot = UI . createShadowRootWithCoreStyles ( element , 'console/consoleContextSelector.css' ) ;
240
+ const shadowRoot = UI . Utils . createShadowRootWithCoreStyles ( element , 'console/consoleContextSelector.css' ) ;
231
241
const title = shadowRoot . createChild ( 'div' , 'title' ) ;
232
242
title . createTextChild ( this . titleFor ( item ) . trimEndWithMaxLength ( 100 ) ) ;
233
243
const subTitle = shadowRoot . createChild ( 'div' , 'subtitle' ) ;
@@ -237,21 +247,21 @@ export class ConsoleContextSelector {
237
247
}
238
248
239
249
/**
240
- * @param {!SDK.ExecutionContext } executionContext
250
+ * @param {!SDK.RuntimeModel. ExecutionContext } executionContext
241
251
* @return {string }
242
252
*/
243
253
_subtitleFor ( executionContext ) {
244
254
const target = executionContext . target ( ) ;
245
255
let frame ;
246
256
if ( executionContext . frameId ) {
247
- const resourceTreeModel = target . model ( SDK . ResourceTreeModel ) ;
257
+ const resourceTreeModel = target . model ( SDK . ResourceTreeModel . ResourceTreeModel ) ;
248
258
frame = resourceTreeModel && resourceTreeModel . frameForId ( executionContext . frameId ) ;
249
259
}
250
260
if ( executionContext . origin . startsWith ( 'chrome-extension://' ) ) {
251
- return Common . UIString ( 'Extension' ) ;
261
+ return Common . UIString . UIString ( 'Extension' ) ;
252
262
}
253
263
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 ) ;
255
265
if ( url ) {
256
266
return url . domain ( ) ;
257
267
}
@@ -260,16 +270,16 @@ export class ConsoleContextSelector {
260
270
if ( frame ) {
261
271
const callFrame = frame . findCreationCallFrame ( callFrame => ! ! callFrame . url ) ;
262
272
if ( callFrame ) {
263
- return new Common . ParsedURL ( callFrame . url ) . domain ( ) ;
273
+ return new Common . ParsedURL . ParsedURL ( callFrame . url ) . domain ( ) ;
264
274
}
265
- return Common . UIString ( 'IFrame' ) ;
275
+ return Common . UIString . UIString ( 'IFrame' ) ;
266
276
}
267
277
return '' ;
268
278
}
269
279
270
280
/**
271
281
* @override
272
- * @param {!SDK.ExecutionContext } item
282
+ * @param {!SDK.RuntimeModel. ExecutionContext } item
273
283
* @return {boolean }
274
284
*/
275
285
isItemSelectable ( item ) {
@@ -280,28 +290,28 @@ export class ConsoleContextSelector {
280
290
281
291
/**
282
292
* @override
283
- * @param {?SDK.ExecutionContext } item
293
+ * @param {?SDK.RuntimeModel. ExecutionContext } item
284
294
*/
285
295
itemSelected ( item ) {
286
296
this . _toolbarItem . element . classList . toggle ( 'warning' , ! this . _isTopContext ( item ) && this . _hasTopContext ( ) ) ;
287
297
const title = item ? ls `JavaScript context: ${ this . titleFor ( item ) } ` : ls `JavaScript context: Not selected` ;
288
298
this . _toolbarItem . setTitle ( title ) ;
289
- self . UI . context . setFlavor ( SDK . ExecutionContext , item ) ;
299
+ self . UI . context . setFlavor ( SDK . RuntimeModel . ExecutionContext , item ) ;
290
300
}
291
301
292
302
_callFrameSelectedInUI ( ) {
293
303
const callFrame = self . UI . context . flavor ( SDK . DebuggerModel . CallFrame ) ;
294
304
const callFrameContext = callFrame && callFrame . script . executionContext ( ) ;
295
305
if ( callFrameContext ) {
296
- self . UI . context . setFlavor ( SDK . ExecutionContext , callFrameContext ) ;
306
+ self . UI . context . setFlavor ( SDK . RuntimeModel . ExecutionContext , callFrameContext ) ;
297
307
}
298
308
}
299
309
300
310
/**
301
311
* @param {!Common.Event } event
302
312
*/
303
313
_callFrameSelectedInModel ( event ) {
304
- const debuggerModel = /** @type {!SDK.DebuggerModel } */ ( event . data ) ;
314
+ const debuggerModel = /** @type {!SDK.DebuggerModel.DebuggerModel } */ ( event . data ) ;
305
315
for ( const executionContext of this . _items ) {
306
316
if ( executionContext . debuggerModel === debuggerModel ) {
307
317
this . _dropDown . refreshItem ( executionContext ) ;
@@ -313,8 +323,8 @@ export class ConsoleContextSelector {
313
323
* @param {!Common.Event } event
314
324
*/
315
325
_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 ) ;
318
328
if ( ! runtimeModel ) {
319
329
return ;
320
330
}
0 commit comments