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

Side by Side 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, 6 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @implements {WebInspector.TargetManager.Observer} 7 * @implements {WebInspector.TargetManager.Observer}
8 * @param {!WebInspector.TargetManager} targetManager 8 * @param {!WebInspector.TargetManager} targetManager
9 * @param {!WebInspector.Context} context 9 * @param {!WebInspector.Context} context
10 */ 10 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 }, 63 },
64 64
65 /** 65 /**
66 * @param {!WebInspector.Event} event 66 * @param {!WebInspector.Event} event
67 */ 67 */
68 _executionContextChanged: function(event) 68 _executionContextChanged: function(event)
69 { 69 {
70 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da ta); 70 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da ta);
71 if (newContext) { 71 if (newContext) {
72 this._context.setFlavor(WebInspector.Target, newContext.target()); 72 this._context.setFlavor(WebInspector.Target, newContext.target());
73 if (!this._contextIsGoingAway) 73 if (!this._ignoreContextChanged)
74 this._lastSelectedContextId = this._contextPersistentId(newConte xt); 74 this._lastSelectedContextId = this._contextPersistentId(newConte xt);
75 } 75 }
76 }, 76 },
77 77
78 /** 78 /**
79 * @param {!WebInspector.ExecutionContext} executionContext 79 * @param {!WebInspector.ExecutionContext} executionContext
80 * @return {string} 80 * @return {string}
81 */ 81 */
82 _contextPersistentId: function(executionContext) 82 _contextPersistentId: function(executionContext)
83 { 83 {
84 return executionContext.isDefault ? executionContext.target().name() + " :" + executionContext.frameId : ""; 84 return executionContext.isDefault ? executionContext.target().name() + " :" + executionContext.frameId : "";
85 }, 85 },
86 86
87 /** 87 /**
88 * @param {!WebInspector.Event} event 88 * @param {!WebInspector.Event} event
89 */ 89 */
90 _targetChanged: function(event) 90 _targetChanged: function(event)
91 { 91 {
92 var newTarget = /** @type {?WebInspector.Target} */(event.data); 92 var newTarget = /** @type {?WebInspector.Target} */(event.data);
93 var currentContext = this._context.flavor(WebInspector.ExecutionContext) ; 93 var currentContext = this._context.flavor(WebInspector.ExecutionContext) ;
94 94
95 if (!newTarget || (currentContext && currentContext.target() === newTarg et)) 95 if (!newTarget || (currentContext && currentContext.target() === newTarg et))
96 return; 96 return;
97 97
98 var executionContexts = newTarget.runtimeModel.executionContexts(); 98 var executionContexts = newTarget.runtimeModel.executionContexts();
99 if (!executionContexts.length) 99 if (!executionContexts.length)
100 return; 100 return;
101 101
102 var newContext = executionContexts[0]; 102 var newContext = null;
103 for (var i = 1; i < executionContexts.length; ++i) { 103 for (var i = 0; i < executionContexts.length && !newContext; ++i) {
104 if (executionContexts[i].isDefault) 104 if (this._shouldSwitchToContext(executionContexts[i]))
105 newContext = executionContexts[i]; 105 newContext = executionContexts[i];
106 } 106 }
107 this._context.setFlavor(WebInspector.ExecutionContext, newContext); 107 for (var i = 0; i < executionContexts.length && !newContext; ++i) {
108 if (this._isMainFrameContext(executionContexts[i]))
109 newContext = executionContexts[i];
110 }
111 this._ignoreContextChanged = true;
112 this._context.setFlavor(WebInspector.ExecutionContext, newContext || exe cutionContexts[0]);
113 this._ignoreContextChanged = false;
108 }, 114 },
109 115
110 /** 116 /**
117 * @param {!WebInspector.ExecutionContext} executionContext
118 * @return {boolean}
119 */
120 _shouldSwitchToContext: function(executionContext)
121 {
122 if (this._lastSelectedContextId && this._lastSelectedContextId === this. _contextPersistentId(executionContext))
123 return true;
124 if (!this._lastSelectedContextId && this._isMainFrameContext(executionCo ntext))
125 return true;
126 return false;
127 },
128
129 /**
130 * @param {!WebInspector.ExecutionContext} executionContext
131 * @return {boolean}
132 */
133 _isMainFrameContext: function(executionContext)
134 {
135 if (!executionContext.isDefault)
136 return false;
137 var frame = executionContext.target().resourceTreeModel.frameForId(execu tionContext.frameId);
138 if (frame && frame.isMainFrame())
139 return true;
140 return false;
141 },
142
143 /**
111 * @param {!WebInspector.Event} event 144 * @param {!WebInspector.Event} event
112 */ 145 */
113 _onExecutionContextCreated: function(event) 146 _onExecutionContextCreated: function(event)
114 { 147 {
115 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev ent.data); 148 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev ent.data);
116 if (!this._context.flavor(WebInspector.ExecutionContext) || (this._lastS electedContextId && this._lastSelectedContextId === this._contextPersistentId(ex ecutionContext))) 149 if (!this._context.flavor(WebInspector.ExecutionContext) || this._should SwitchToContext(executionContext)) {
150 this._ignoreContextChanged = true;
117 this._context.setFlavor(WebInspector.ExecutionContext, executionCont ext); 151 this._context.setFlavor(WebInspector.ExecutionContext, executionCont ext);
152 this._ignoreContextChanged = false;
153 }
118 }, 154 },
119 155
120 /** 156 /**
121 * @param {!WebInspector.Event} event 157 * @param {!WebInspector.Event} event
122 */ 158 */
123 _onExecutionContextDestroyed: function(event) 159 _onExecutionContextDestroyed: function(event)
124 { 160 {
125 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve nt.data); 161 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve nt.data);
126 if (this._context.flavor(WebInspector.ExecutionContext) === executionCon text) 162 if (this._context.flavor(WebInspector.ExecutionContext) === executionCon text)
127 this._currentExecutionContextGone(); 163 this._currentExecutionContextGone();
128 }, 164 },
129 165
130 _currentExecutionContextGone: function() 166 _currentExecutionContextGone: function()
131 { 167 {
132 var targets = this._targetManager.targetsWithJSContext(); 168 var targets = this._targetManager.targetsWithJSContext();
133 var newContext = null; 169 var newContext = null;
134 for (var i = 0; i < targets.length; ++i) { 170 for (var i = 0; i < targets.length && !newContext; ++i) {
135 if (targets[i].isServiceWorker()) 171 if (targets[i].isServiceWorker())
136 continue; 172 continue;
137 var executionContexts = targets[i].runtimeModel.executionContexts(); 173 var executionContexts = targets[i].runtimeModel.executionContexts();
138 if (executionContexts.length) { 174 for (var executionContext of executionContexts) {
139 newContext = executionContexts[0]; 175 if (this._isMainFrameContext(executionContext)) {
140 break; 176 newContext = executionContext;
177 break;
178 }
141 } 179 }
142 } 180 }
143 this._contextIsGoingAway = true; 181 if (!newContext) {
182 for (var i = 0; i < targets.length && !newContext; ++i) {
183 var executionContexts = targets[i].runtimeModel.executionContext s();
184 if (executionContexts.length) {
185 newContext = executionContexts[0];
186 break;
187 }
188 }
189 }
190 this._ignoreContextChanged = true;
144 this._context.setFlavor(WebInspector.ExecutionContext, newContext); 191 this._context.setFlavor(WebInspector.ExecutionContext, newContext);
145 this._contextIsGoingAway = false; 192 this._ignoreContextChanged = false;
146 } 193 }
147 } 194 }
148 195
149 /** 196 /**
150 * @param {!Element} proxyElement 197 * @param {!Element} proxyElement
151 * @param {string} text 198 * @param {string} text
152 * @param {number} cursorOffset 199 * @param {number} cursorOffset
153 * @param {!Range} wordRange 200 * @param {!Range} wordRange
154 * @param {boolean} force 201 * @param {boolean} force
155 * @param {function(!Array.<string>, number=)} completionsReadyCallback 202 * @param {function(!Array.<string>, number=)} completionsReadyCallback
(...skipping 11 matching lines...) Expand all
167 var expressionString = expressionRange.toString(); 214 var expressionString = expressionRange.toString();
168 215
169 // The "[" is also a stop character, except when it's the last character of the expression. 216 // The "[" is also a stop character, except when it's the last character of the expression.
170 var pos = expressionString.lastIndexOf("[", expressionString.length - 2); 217 var pos = expressionString.lastIndexOf("[", expressionString.length - 2);
171 if (pos !== -1) 218 if (pos !== -1)
172 expressionString = expressionString.substr(pos + 1); 219 expressionString = expressionString.substr(pos + 1);
173 220
174 var prefix = wordRange.toString(); 221 var prefix = wordRange.toString();
175 executionContext.completionsForExpression(expressionString, text, cursorOffs et, prefix, force, completionsReadyCallback); 222 executionContext.completionsForExpression(expressionString, text, cursorOffs et, prefix, force, completionsReadyCallback);
176 } 223 }
OLDNEW
« 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