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

Unified Diff: third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js

Issue 2009903002: [DevTools] Stick with top frame unless user selected something else. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more logic, and a test Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/last-execution-context-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js
diff --git a/third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js b/third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js
index 64ffac74f20663d48d235f4ce8176ce38fb6688d..442321322d2a0efb5c1c9d7d100a069045bed320 100644
--- a/third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js
+++ b/third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js
@@ -70,7 +70,7 @@ WebInspector.ExecutionContextSelector.prototype = {
var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.data);
if (newContext) {
this._context.setFlavor(WebInspector.Target, newContext.target());
- if (!this._contextIsGoingAway)
+ if (!this._ignoreContextChanged)
this._lastSelectedContextId = this._contextPersistentId(newContext);
}
},
@@ -99,12 +99,45 @@ WebInspector.ExecutionContextSelector.prototype = {
if (!executionContexts.length)
return;
- var newContext = executionContexts[0];
- for (var i = 1; i < executionContexts.length; ++i) {
- if (executionContexts[i].isDefault)
+ var newContext = null;
+ for (var i = 0; i < executionContexts.length && !newContext; ++i) {
+ if (this._shouldSwitchToContext(executionContexts[i]))
newContext = executionContexts[i];
}
- this._context.setFlavor(WebInspector.ExecutionContext, newContext);
+ for (var i = 0; i < executionContexts.length && !newContext; ++i) {
+ if (this._isMainFrameContext(executionContexts[i]))
+ newContext = executionContexts[i];
+ }
+ this._ignoreContextChanged = true;
+ this._context.setFlavor(WebInspector.ExecutionContext, newContext || executionContexts[0]);
+ this._ignoreContextChanged = false;
+ },
+
+ /**
+ * @param {!WebInspector.ExecutionContext} executionContext
+ * @return {boolean}
+ */
+ _shouldSwitchToContext: function(executionContext)
+ {
+ if (this._lastSelectedContextId && this._lastSelectedContextId === this._contextPersistentId(executionContext))
+ return true;
+ if (!this._lastSelectedContextId && this._isMainFrameContext(executionContext))
+ return true;
+ return false;
+ },
+
+ /**
+ * @param {!WebInspector.ExecutionContext} executionContext
+ * @return {boolean}
+ */
+ _isMainFrameContext: function(executionContext)
+ {
+ if (!executionContext.isDefault)
+ return false;
+ var frame = executionContext.target().resourceTreeModel.frameForId(executionContext.frameId);
+ if (frame && frame.isMainFrame())
+ return true;
+ return false;
},
/**
@@ -113,8 +146,11 @@ WebInspector.ExecutionContextSelector.prototype = {
_onExecutionContextCreated: function(event)
{
var executionContext = /** @type {!WebInspector.ExecutionContext} */ (event.data);
- if (!this._context.flavor(WebInspector.ExecutionContext) || (this._lastSelectedContextId && this._lastSelectedContextId === this._contextPersistentId(executionContext)))
+ if (!this._context.flavor(WebInspector.ExecutionContext) || this._shouldSwitchToContext(executionContext)) {
+ this._ignoreContextChanged = true;
this._context.setFlavor(WebInspector.ExecutionContext, executionContext);
+ this._ignoreContextChanged = false;
+ }
},
/**
@@ -131,18 +167,29 @@ WebInspector.ExecutionContextSelector.prototype = {
{
var targets = this._targetManager.targetsWithJSContext();
var newContext = null;
- for (var i = 0; i < targets.length; ++i) {
+ for (var i = 0; i < targets.length && !newContext; ++i) {
if (targets[i].isServiceWorker())
continue;
var executionContexts = targets[i].runtimeModel.executionContexts();
- if (executionContexts.length) {
- newContext = executionContexts[0];
- break;
+ for (var executionContext of executionContexts) {
+ if (this._isMainFrameContext(executionContext)) {
+ newContext = executionContext;
+ break;
+ }
+ }
+ }
+ if (!newContext) {
+ for (var i = 0; i < targets.length && !newContext; ++i) {
+ var executionContexts = targets[i].runtimeModel.executionContexts();
+ if (executionContexts.length) {
+ newContext = executionContexts[0];
+ break;
+ }
}
}
- this._contextIsGoingAway = true;
+ this._ignoreContextChanged = true;
this._context.setFlavor(WebInspector.ExecutionContext, newContext);
- this._contextIsGoingAway = false;
+ this._ignoreContextChanged = false;
}
}
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/last-execution-context-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698