Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js

Issue 2889833003: DevTools: Show badges instead of products in ConsoleContextSelector (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>} 5 * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>}
6 * @implements {UI.ListDelegate<!SDK.ExecutionContext>} 6 * @implements {UI.ListDelegate<!SDK.ExecutionContext>}
7 */ 7 */
8 Console.ConsoleContextSelector = class { 8 Console.ConsoleContextSelector = class {
9 constructor() { 9 constructor() {
10 this._toolbarItem = new UI.ToolbarItem(createElementWithClass('button', 'con sole-context')); 10 this._toolbarItem = new UI.ToolbarItem(createElementWithClass('button', 'con sole-context'));
11 var shadowRoot = 11 var shadowRoot =
12 UI.createShadowRootWithCoreStyles(this._toolbarItem.element, 'console/co nsoleContextSelectorButton.css'); 12 UI.createShadowRootWithCoreStyles(this._toolbarItem.element, 'console/co nsoleContextSelectorButton.css');
13 this._titleElement = shadowRoot.createChild('span', 'title'); 13 this._titleElement = shadowRoot.createChild('span', 'title');
14 this._productRegistry = null;
15 14
16 ProductRegistry.instance().then(registry => { 15 // TODO (einbinder) this can leak elements when executionContexts are destro yed
17 this._productRegistry = registry; 16 this._badgePool = new ProductRegistry.BadgePool();
18 this._list.refreshAllItems();
19 });
20 this._toolbarItem.element.classList.add('toolbar-has-dropdown'); 17 this._toolbarItem.element.classList.add('toolbar-has-dropdown');
21 this._toolbarItem.element.tabIndex = 0; 18 this._toolbarItem.element.tabIndex = 0;
22 this._glassPane = new UI.GlassPane(); 19 this._glassPane = new UI.GlassPane();
23 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin); 20 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin);
24 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); 21 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom);
25 this._glassPane.setOutsideClickCallback(this._hide.bind(this)); 22 this._glassPane.setOutsideClickCallback(this._hide.bind(this));
26 this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior. BlockedByGlassPane); 23 this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior. BlockedByGlassPane);
27 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems); 24 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems);
28 this._list.element.classList.add('context-list'); 25 this._list.element.classList.add('context-list');
29 this._list.element.tabIndex = -1; 26 this._list.element.tabIndex = -1;
30 this._rowHeight = 34; 27 this._rowHeight = 36;
31 UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/c onsoleContextSelector.css') 28 UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/c onsoleContextSelector.css')
32 .appendChild(this._list.element); 29 .appendChild(this._list.element);
33 30
34 this._listWasShowing200msAgo = false; 31 this._listWasShowing200msAgo = false;
35 this._toolbarItem.element.addEventListener('mousedown', event => { 32 this._toolbarItem.element.addEventListener('mousedown', event => {
36 if (this._listWasShowing200msAgo) 33 if (this._listWasShowing200msAgo)
37 this._hide(event); 34 this._hide(event);
38 else 35 else
39 this._show(event); 36 this._show(event);
40 }, false); 37 }, false);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 78
82 /** 79 /**
83 * @param {!Event} event 80 * @param {!Event} event
84 */ 81 */
85 _show(event) { 82 _show(event) {
86 if (this._glassPane.isShowing()) 83 if (this._glassPane.isShowing())
87 return; 84 return;
88 this._glassPane.setContentAnchorBox(this._toolbarItem.element.boxInWindow()) ; 85 this._glassPane.setContentAnchorBox(this._toolbarItem.element.boxInWindow()) ;
89 this._glassPane.show(/** @type {!Document} **/ (this._toolbarItem.element.ow nerDocument)); 86 this._glassPane.show(/** @type {!Document} **/ (this._toolbarItem.element.ow nerDocument));
90 this._updateGlasspaneSize(); 87 this._updateGlasspaneSize();
91 var selectedItem = this._list.selectedItem(); 88 var selectedContext = UI.context.flavor(SDK.ExecutionContext);
pfeldman 2017/05/16 23:16:05 Why do we need this?
einbinder 2017/05/16 23:58:27 Trying to update selection in the list as late as
92 if (selectedItem) 89 if (selectedContext) {
93 this._list.scrollItemIntoView(selectedItem, true); 90 this._list.selectItem(selectedContext);
91 this._list.scrollItemIntoView(selectedContext, true);
92 }
94 this._toolbarItem.element.focus(); 93 this._toolbarItem.element.focus();
95 event.consume(true); 94 event.consume(true);
96 setTimeout(() => this._listWasShowing200msAgo = true, 200); 95 setTimeout(() => this._listWasShowing200msAgo = true, 200);
97 } 96 }
98 97
99 _updateGlasspaneSize() { 98 _updateGlasspaneSize() {
100 var maxHeight = this._rowHeight * (Math.min(this._list.length(), 9)); 99 var maxHeight = this._rowHeight * (Math.min(this._list.length(), 9));
101 this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight)); 100 this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight));
102 this._list.viewportResized(); 101 this._list.viewportResized();
103 } 102 }
104 103
105 /** 104 /**
106 * @param {!Event} event 105 * @param {!Event} event
107 */ 106 */
108 _hide(event) { 107 _hide(event) {
109 setTimeout(() => this._listWasShowing200msAgo = false, 200); 108 setTimeout(() => this._listWasShowing200msAgo = false, 200);
110 this._glassPane.hide(); 109 this._glassPane.hide();
111 SDK.OverlayModel.hideDOMNodeHighlight(); 110 SDK.OverlayModel.hideDOMNodeHighlight();
112 var selectedContext = UI.context.flavor(SDK.ExecutionContext);
113 if (selectedContext)
114 this._list.selectItem(selectedContext);
115 event.consume(true); 111 event.consume(true);
116 } 112 }
117 113
118 /** 114 /**
119 * @param {!Event} event 115 * @param {!Event} event
120 */ 116 */
121 _onKeyDown(event) { 117 _onKeyDown(event) {
122 var handled = false; 118 var handled = false;
123 switch (event.key) { 119 switch (event.key) {
124 case 'ArrowUp': 120 case 'ArrowUp':
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 break; 255 break;
260 } 256 }
261 target = target.parentTarget(); 257 target = target.parentTarget();
262 } 258 }
263 depth += targetDepth; 259 depth += targetDepth;
264 return depth; 260 return depth;
265 } 261 }
266 262
267 /** 263 /**
268 * @param {!SDK.ExecutionContext} executionContext 264 * @param {!SDK.ExecutionContext} executionContext
265 * @return {?Element}
266 */
267 _badgeFor(executionContext) {
268 if (!executionContext.frameId)
269 return null;
270 var resourceTreeModel = executionContext.target().model(SDK.ResourceTreeMode l);
pfeldman 2017/05/16 23:16:05 Do it for the main worlds only.
einbinder 2017/05/16 23:58:27 I don't follow.
pfeldman 2017/05/17 18:12:41 You are showing frame badges on the content script
einbinder 2017/05/17 20:45:31 Done. I think?
271 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionConte xt.frameId);
272 if (!frame)
273 return null;
274 return this._badgePool.badgeForFrame(frame, true);
275 }
276
277 /**
278 * @param {!SDK.ExecutionContext} executionContext
269 */ 279 */
270 _executionContextCreated(executionContext) { 280 _executionContextCreated(executionContext) {
271 // FIXME(413886): We never want to show execution context for the main threa d of shadow page in service/shared worker frontend. 281 // FIXME(413886): We never want to show execution context for the main threa d of shadow page in service/shared worker frontend.
272 // This check could be removed once we do not send this context to frontend. 282 // This check could be removed once we do not send this context to frontend.
273 if (!executionContext.target().hasJSCapability()) 283 if (!executionContext.target().hasJSCapability())
274 return; 284 return;
275 285
276 this._list.insertItemWithComparator(executionContext, executionContext.runti meModel.executionContextComparator()); 286 this._list.insertItemWithComparator(executionContext, executionContext.runti meModel.executionContextComparator());
277 287
278 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) { 288 if (executionContext === UI.context.flavor(SDK.ExecutionContext))
279 this._list.selectItem(executionContext); 289 this._updateSelectionTitle();
280 this._updateSelectedContext();
281 }
282 } 290 }
283 291
284 /** 292 /**
285 * @param {!Common.Event} event 293 * @param {!Common.Event} event
286 */ 294 */
287 _onExecutionContextCreated(event) { 295 _onExecutionContextCreated(event) {
288 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 296 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
289 this._executionContextCreated(executionContext); 297 this._executionContextCreated(executionContext);
290 this._updateSelectionWarning(); 298 this._updateSelectionTitle();
291 this._updateGlasspaneSize(); 299 this._updateGlasspaneSize();
292 } 300 }
293 301
294 /** 302 /**
295 * @param {!Common.Event} event 303 * @param {!Common.Event} event
296 */ 304 */
297 _onExecutionContextChanged(event) { 305 _onExecutionContextChanged(event) {
298 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 306 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
299 if (this._list.indexOfItem(executionContext) === -1) 307 if (this._list.indexOfItem(executionContext) === -1)
300 return; 308 return;
301 this._executionContextDestroyed(executionContext); 309 this._executionContextDestroyed(executionContext);
302 this._executionContextCreated(executionContext); 310 this._executionContextCreated(executionContext);
303 this._updateSelectionWarning(); 311 this._updateSelectionTitle();
304 } 312 }
305 313
306 /** 314 /**
307 * @param {!SDK.ExecutionContext} executionContext 315 * @param {!SDK.ExecutionContext} executionContext
308 */ 316 */
309 _executionContextDestroyed(executionContext) { 317 _executionContextDestroyed(executionContext) {
310 if (this._list.indexOfItem(executionContext) === -1) 318 if (this._list.indexOfItem(executionContext) === -1)
311 return; 319 return;
312 this._list.removeItem(executionContext); 320 this._list.removeItem(executionContext);
313 this._updateGlasspaneSize(); 321 this._updateGlasspaneSize();
314 } 322 }
315 323
316 /** 324 /**
317 * @param {!Common.Event} event 325 * @param {!Common.Event} event
318 */ 326 */
319 _onExecutionContextDestroyed(event) { 327 _onExecutionContextDestroyed(event) {
320 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 328 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
321 this._executionContextDestroyed(executionContext); 329 this._executionContextDestroyed(executionContext);
322 this._updateSelectionWarning(); 330 this._updateSelectionTitle();
323 } 331 }
324 332
325 /** 333 /**
326 * @param {!Common.Event} event 334 * @param {!Common.Event} event
327 */ 335 */
328 _executionContextChangedExternally(event) { 336 _executionContextChangedExternally(event) {
329 var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data); 337 var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data);
330 if (!executionContext || this._list.indexOfItem(executionContext) === -1) 338 if (!executionContext || this._list.indexOfItem(executionContext) === -1)
331 return; 339 return;
332 this._list.selectItem(executionContext); 340 this._list.selectItem(executionContext);
333 this._updateSelectedContext(); 341 this._updateSelectedContext();
334 } 342 }
335 343
336 _updateSelectionWarning() { 344 _updateSelectionTitle() {
337 var executionContext = UI.context.flavor(SDK.ExecutionContext); 345 var executionContext = UI.context.flavor(SDK.ExecutionContext);
346 if (executionContext)
347 this._titleElement.textContent = this._titleFor(executionContext);
348 else
349 this._titleElement.textContent = '';
338 this._toolbarItem.element.classList.toggle( 350 this._toolbarItem.element.classList.toggle(
339 'warning', !this._isTopContext(executionContext) && this._hasTopContext( )); 351 'warning', !this._isTopContext(executionContext) && this._hasTopContext( ));
340 } 352 }
341 353
342 /** 354 /**
343 * @param {?SDK.ExecutionContext} executionContext 355 * @param {?SDK.ExecutionContext} executionContext
344 * @return {boolean} 356 * @return {boolean}
345 */ 357 */
346 _isTopContext(executionContext) { 358 _isTopContext(executionContext) {
347 if (!executionContext || !executionContext.isDefault) 359 if (!executionContext || !executionContext.isDefault)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 396 }
385 397
386 /** 398 /**
387 * @override 399 * @override
388 * @param {!SDK.ExecutionContext} item 400 * @param {!SDK.ExecutionContext} item
389 * @return {!Element} 401 * @return {!Element}
390 */ 402 */
391 createElementForItem(item) { 403 createElementForItem(item) {
392 var element = createElementWithClass('div', 'context'); 404 var element = createElementWithClass('div', 'context');
393 element.style.paddingLeft = (8 + this._depthFor(item) * 15) + 'px'; 405 element.style.paddingLeft = (8 + this._depthFor(item) * 15) + 'px';
394 element.createChild('div', 'title').textContent = this._titleFor(item).trimE nd(100); 406 // var titleArea = element.createChild('div', 'title-area');
407 var title = element.createChild('div', 'title');
408 var badgeElement = this._badgeFor(item);
409 if (badgeElement) {
410 badgeElement.classList.add('badge');
411 title.appendChild(badgeElement);
pfeldman 2017/05/16 23:16:05 When you discard the list item, it would be helpfu
einbinder 2017/05/16 23:58:27 Done.
412 }
413 title.createTextChild(this._titleFor(item).trimEnd(100));
395 element.createChild('div', 'subtitle').textContent = this._subtitleFor(item) ; 414 element.createChild('div', 'subtitle').textContent = this._subtitleFor(item) ;
396 element.addEventListener('mousemove', e => { 415 element.addEventListener('mousemove', e => {
397 if ((e.movementX || e.movementY) && this.isItemSelectable(item)) 416 if ((e.movementX || e.movementY) && this.isItemSelectable(item))
398 this._list.selectItem(item, false, /* Don't scroll */ true); 417 this._list.selectItem(item, false, /* Don't scroll */ true);
399 }); 418 });
400 element.classList.toggle('disabled', !this.isItemSelectable(item)); 419 element.classList.toggle('disabled', !this.isItemSelectable(item));
401 return element; 420 return element;
402 } 421 }
403 422
404 /** 423 /**
405 * @param {!SDK.ExecutionContext} executionContext 424 * @param {!SDK.ExecutionContext} executionContext
406 * @return {string} 425 * @return {string}
407 */ 426 */
408 _subtitleFor(executionContext) { 427 _subtitleFor(executionContext) {
409 var target = executionContext.target(); 428 var target = executionContext.target();
410 if (executionContext.frameId) { 429 if (executionContext.frameId) {
411 var resourceTreeModel = target.model(SDK.ResourceTreeModel); 430 var resourceTreeModel = target.model(SDK.ResourceTreeModel);
412 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionCon text.frameId); 431 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionCon text.frameId);
413 } 432 }
414 if (executionContext.origin.startsWith('chrome-extension://')) 433 if (executionContext.origin.startsWith('chrome-extension://'))
415 return Common.UIString('Extension'); 434 return Common.UIString('Extension');
416 if (!frame || !frame.parentFrame || frame.parentFrame.securityOrigin !== exe cutionContext.origin) { 435 if (!frame || !frame.parentFrame || frame.parentFrame.securityOrigin !== exe cutionContext.origin) {
417 var url = executionContext.origin.asParsedURL(); 436 var url = executionContext.origin.asParsedURL();
418 if (url) { 437 if (url)
419 if (this._productRegistry) {
420 var product = this._productRegistry.nameForUrl(url);
421 if (product)
422 return product;
423 }
424 return url.domain(); 438 return url.domain();
425 }
426 } 439 }
427 440
428 if (frame) { 441 if (frame) {
429 var callFrame = frame.findCreationCallFrame(callFrame => !!callFrame.url); 442 var callFrame = frame.findCreationCallFrame(callFrame => !!callFrame.url);
430 if (callFrame) { 443 if (callFrame)
431 var url = new Common.ParsedURL(callFrame.url); 444 return new Common.ParsedURL(callFrame.url).domain();
432 if (this._productRegistry) {
433 var product = this._productRegistry.nameForUrl(url);
434 if (product)
435 return product;
436 }
437 return url.domain();
438 }
439 } 445 }
440 return ''; 446 return '';
441 } 447 }
442 448
443 /** 449 /**
444 * @override 450 * @override
445 * @param {!SDK.ExecutionContext} item 451 * @param {!SDK.ExecutionContext} item
446 * @return {number} 452 * @return {number}
447 */ 453 */
448 heightForItem(item) { 454 heightForItem(item) {
449 return 0; 455 return this._rowHeight;
450 } 456 }
451 457
452 /** 458 /**
453 * @override 459 * @override
454 * @param {!SDK.ExecutionContext} item 460 * @param {!SDK.ExecutionContext} item
455 * @return {boolean} 461 * @return {boolean}
456 */ 462 */
457 isItemSelectable(item) { 463 isItemSelectable(item) {
458 var callFrame = item.debuggerModel.selectedCallFrame(); 464 var callFrame = item.debuggerModel.selectedCallFrame();
459 var callFrameContext = callFrame && callFrame.script.executionContext(); 465 var callFrameContext = callFrame && callFrame.script.executionContext();
(...skipping 15 matching lines...) Expand all
475 SDK.OverlayModel.hideDOMNodeHighlight(); 481 SDK.OverlayModel.hideDOMNodeHighlight();
476 if (to && to.frameId) { 482 if (to && to.frameId) {
477 var resourceTreeModel = to.target().model(SDK.ResourceTreeModel); 483 var resourceTreeModel = to.target().model(SDK.ResourceTreeModel);
478 if (resourceTreeModel) 484 if (resourceTreeModel)
479 resourceTreeModel.domModel().overlayModel().highlightFrame(to.frameId); 485 resourceTreeModel.domModel().overlayModel().highlightFrame(to.frameId);
480 } 486 }
481 } 487 }
482 488
483 _updateSelectedContext() { 489 _updateSelectedContext() {
484 var context = this._list.selectedItem(); 490 var context = this._list.selectedItem();
485 if (context)
486 this._titleElement.textContent = this._titleFor(context);
487 else
488 this._titleElement.textContent = '';
489 UI.context.setFlavor(SDK.ExecutionContext, context); 491 UI.context.setFlavor(SDK.ExecutionContext, context);
490 this._updateSelectionWarning(); 492 this._updateSelectionTitle();
491 } 493 }
492 494
493 _callFrameSelectedInUI() { 495 _callFrameSelectedInUI() {
494 var callFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); 496 var callFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame);
495 var callFrameContext = callFrame && callFrame.script.executionContext(); 497 var callFrameContext = callFrame && callFrame.script.executionContext();
496 if (callFrameContext) 498 if (callFrameContext)
497 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext); 499 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext);
498 } 500 }
499 501
500 /** 502 /**
(...skipping 11 matching lines...) Expand all
512 * @param {!Common.Event} event 514 * @param {!Common.Event} event
513 */ 515 */
514 _frameNavigated(event) { 516 _frameNavigated(event) {
515 var frameId = event.data.id; 517 var frameId = event.data.id;
516 for (var i = 0; i < this._list.length(); i++) { 518 for (var i = 0; i < this._list.length(); i++) {
517 if (frameId === this._list.itemAtIndex(i).frameId) 519 if (frameId === this._list.itemAtIndex(i).frameId)
518 this._list.refreshItemsInRange(i, i + 1); 520 this._list.refreshItemsInRange(i, i + 1);
519 } 521 }
520 } 522 }
521 }; 523 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698