Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js b/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js |
| index 49c62adc6f2204eaf5a05111a01d4c3264bd10af..d98afa7cc71e3b194519e2f51a8fdbc4de93c737 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js |
| @@ -19,10 +19,23 @@ Console.ConsoleContextSelector = class { |
| SDK.targetManager.addModelListener( |
| SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this); |
| SDK.targetManager.addModelListener( |
| - SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextChanged, this); |
| + SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, |
| + event => this._refreshTitle(/** @type {!SDK.ExecutionContext} */ (event.data))); |
| SDK.targetManager.addModelListener( |
| SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this); |
| + /** |
| + * @type {?Console.ConsoleFrameNameLookupInterface} |
| + */ |
| + this._frameNameLookupInstance = null; |
| + var extension = self.runtime.extension(Console.ConsoleFrameNameLookupInterface); |
| + if (extension) { |
| + extension.instance().then(instance => { |
|
pfeldman
2017/04/04 19:03:15
That's super early. We are creating this all upon
allada
2017/04/05 01:49:45
Done.
|
| + this._frameNameLookupInstance = instance; |
| + this._optionByExecutionContext.keysArray().forEach(this._refreshTitle.bind(this)); |
| + }); |
| + } |
| + |
| this._selectElement.addEventListener('change', this._executionContextChanged.bind(this), false); |
| UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._executionContextChangedExternally, this); |
| SDK.targetManager.observeModels(SDK.RuntimeModel, this); |
| @@ -43,6 +56,11 @@ Console.ConsoleContextSelector = class { |
| var frame = resourceTreeModel && resourceTreeModel.frameForId(executionContext.frameId); |
| if (frame) { |
| label = label || frame.displayName(); |
| + if (this._frameNameLookupInstance) { |
| + var productName = this._frameNameLookupInstance.nameForFrame(frame); |
| + if (productName) |
| + label = productName.trimMiddle(15) + ' / ' + label; |
|
caseq
2017/04/04 18:59:40
Why not trimEnd()? Also,
label = Common.UIString('
allada
2017/04/05 01:49:45
We can trimEnd() I was playing around with it and
|
| + } |
| while (frame.parentFrame) { |
| depth++; |
| frame = frame.parentFrame; |
| @@ -71,6 +89,16 @@ Console.ConsoleContextSelector = class { |
| /** |
| * @param {!SDK.ExecutionContext} executionContext |
| */ |
| + _refreshTitle(executionContext) { |
| + var option = this._optionByExecutionContext.get(executionContext); |
| + if (option) |
| + option.text = this._titleFor(executionContext); |
| + this._updateSelectionWarning(); |
| + } |
| + |
| + /** |
| + * @param {!SDK.ExecutionContext} executionContext |
| + */ |
| _executionContextCreated(executionContext) { |
| // FIXME(413886): We never want to show execution context for the main thread of shadow page in service/shared worker frontend. |
| // This check could be removed once we do not send this context to frontend. |
| @@ -79,8 +107,8 @@ Console.ConsoleContextSelector = class { |
| var newOption = createElement('option'); |
| newOption.__executionContext = executionContext; |
| - newOption.text = this._titleFor(executionContext); |
| this._optionByExecutionContext.set(executionContext, newOption); |
| + this._refreshTitle(executionContext); |
| var options = this._selectElement.options; |
| var contexts = Array.prototype.map.call(options, mapping); |
| var index = contexts.lowerBound(executionContext, executionContext.runtimeModel.executionContextComparator()); |
| @@ -108,17 +136,6 @@ Console.ConsoleContextSelector = class { |
| } |
| /** |
| - * @param {!Common.Event} event |
| - */ |
| - _onExecutionContextChanged(event) { |
| - var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| - var option = this._optionByExecutionContext.get(executionContext); |
| - if (option) |
| - option.text = this._titleFor(executionContext); |
| - this._updateSelectionWarning(); |
| - } |
| - |
| - /** |
| * @param {!SDK.ExecutionContext} executionContext |
| */ |
| _executionContextDestroyed(executionContext) { |
| @@ -226,3 +243,16 @@ Console.ConsoleContextSelector = class { |
| return null; |
| } |
| }; |
| + |
| +/** |
| + * @interface |
| + */ |
| +Console.ConsoleFrameNameLookupInterface = function() {}; |
| + |
| +Console.ConsoleFrameNameLookupInterface.prototype = { |
| + /** |
| + * @param {!SDK.ResourceTreeFrame} frame |
| + * @return {?string} |
| + */ |
| + nameForFrame(frame) {} |
| +}; |