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

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

Issue 2796703002: [Devtools] Execution context in console shows product experiment (Closed)
Patch Set: changes Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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..9648ad567656eaf0fabe0f38c4914f1287ede201 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
@@ -19,15 +19,32 @@ 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;
+
+ this._selectElement.addEventListener('focus', this._loadFrameNameLookupInstanceIfNeeded.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);
}
+ _loadFrameNameLookupInstanceIfNeeded() {
+ if (this._frameNameLookupInstance)
+ return;
+ var extension = self.runtime.extension(Console.ConsoleFrameNameLookupInterface);
+ if (!extension)
+ return;
+ extension.instance().then(instance => {
+ this._frameNameLookupInstance = instance;
+ this._optionByExecutionContext.keysArray().forEach(this._refreshTitle.bind(this));
+ });
+ }
+
/**
* @param {!SDK.ExecutionContext} executionContext
* @return {string}
@@ -43,6 +60,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 = Common.UIString('%s / %s', productName.trimMiddle(15), label);
+ }
while (frame.parentFrame) {
depth++;
frame = frame.parentFrame;
@@ -71,6 +93,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 +111,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 +140,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 +247,16 @@ Console.ConsoleContextSelector = class {
return null;
}
};
+
+/**
+ * @interface
+ */
+Console.ConsoleFrameNameLookupInterface = function() {};
+
+Console.ConsoleFrameNameLookupInterface.prototype = {
+ /**
+ * @param {!SDK.ResourceTreeFrame} frame
+ * @return {?string}
+ */
+ nameForFrame(frame) {}
+};

Powered by Google App Engine
This is Rietveld 408576698