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

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

Issue 2122353002: [DevTools] Make resource tree model optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 4 years, 3 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 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 var executionContexts = newTarget.runtimeModel.executionContexts(); 95 var executionContexts = newTarget.runtimeModel.executionContexts();
96 if (!executionContexts.length) 96 if (!executionContexts.length)
97 return; 97 return;
98 98
99 var newContext = null; 99 var newContext = null;
100 for (var i = 0; i < executionContexts.length && !newContext; ++i) { 100 for (var i = 0; i < executionContexts.length && !newContext; ++i) {
101 if (this._shouldSwitchToContext(executionContexts[i])) 101 if (this._shouldSwitchToContext(executionContexts[i]))
102 newContext = executionContexts[i]; 102 newContext = executionContexts[i];
103 } 103 }
104 for (var i = 0; i < executionContexts.length && !newContext; ++i) { 104 for (var i = 0; i < executionContexts.length && !newContext; ++i) {
105 if (this._isMainFrameContext(executionContexts[i])) 105 if (this._isDefaultContext(executionContexts[i]))
106 newContext = executionContexts[i]; 106 newContext = executionContexts[i];
107 } 107 }
108 this._ignoreContextChanged = true; 108 this._ignoreContextChanged = true;
109 this._context.setFlavor(WebInspector.ExecutionContext, newContext || exe cutionContexts[0]); 109 this._context.setFlavor(WebInspector.ExecutionContext, newContext || exe cutionContexts[0]);
110 this._ignoreContextChanged = false; 110 this._ignoreContextChanged = false;
111 }, 111 },
112 112
113 /** 113 /**
114 * @param {!WebInspector.ExecutionContext} executionContext 114 * @param {!WebInspector.ExecutionContext} executionContext
115 * @return {boolean} 115 * @return {boolean}
116 */ 116 */
117 _shouldSwitchToContext: function(executionContext) 117 _shouldSwitchToContext: function(executionContext)
118 { 118 {
119 if (this._lastSelectedContextId && this._lastSelectedContextId === this. _contextPersistentId(executionContext)) 119 if (this._lastSelectedContextId && this._lastSelectedContextId === this. _contextPersistentId(executionContext))
120 return true; 120 return true;
121 if (!this._lastSelectedContextId && this._isMainFrameContext(executionCo ntext)) 121 if (!this._lastSelectedContextId && this._isDefaultContext(executionCont ext))
122 return true; 122 return true;
123 return false; 123 return false;
124 }, 124 },
125 125
126 /** 126 /**
127 * @param {!WebInspector.ExecutionContext} executionContext 127 * @param {!WebInspector.ExecutionContext} executionContext
128 * @return {boolean} 128 * @return {boolean}
129 */ 129 */
130 _isMainFrameContext: function(executionContext) 130 _isDefaultContext: function(executionContext)
131 { 131 {
132 if (!executionContext.isDefault) 132 if (!executionContext.isDefault || !executionContext.frameId)
133 return false; 133 return false;
134 var frame = executionContext.target().resourceTreeModel.frameForId(execu tionContext.frameId); 134 if (executionContext.target().parentTarget())
135 return false;
136 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(execut ionContext.target());
137 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionC ontext.frameId);
135 if (frame && frame.isMainFrame()) 138 if (frame && frame.isMainFrame())
136 return true; 139 return true;
137 return false; 140 return false;
138 }, 141 },
139 142
140 /** 143 /**
141 * @param {!WebInspector.Event} event 144 * @param {!WebInspector.Event} event
142 */ 145 */
143 _onExecutionContextCreated: function(event) 146 _onExecutionContextCreated: function(event)
144 { 147 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return false; 186 return false;
184 }, 187 },
185 188
186 _currentExecutionContextGone: function() 189 _currentExecutionContextGone: function()
187 { 190 {
188 var targets = this._targetManager.targets(WebInspector.Target.Capability .JS); 191 var targets = this._targetManager.targets(WebInspector.Target.Capability .JS);
189 var newContext = null; 192 var newContext = null;
190 for (var i = 0; i < targets.length && !newContext; ++i) { 193 for (var i = 0; i < targets.length && !newContext; ++i) {
191 var executionContexts = targets[i].runtimeModel.executionContexts(); 194 var executionContexts = targets[i].runtimeModel.executionContexts();
192 for (var executionContext of executionContexts) { 195 for (var executionContext of executionContexts) {
193 if (this._isMainFrameContext(executionContext)) { 196 if (this._isDefaultContext(executionContext)) {
194 newContext = executionContext; 197 newContext = executionContext;
195 break; 198 break;
196 } 199 }
197 } 200 }
198 } 201 }
199 if (!newContext) { 202 if (!newContext) {
200 for (var i = 0; i < targets.length && !newContext; ++i) { 203 for (var i = 0; i < targets.length && !newContext; ++i) {
201 var executionContexts = targets[i].runtimeModel.executionContext s(); 204 var executionContexts = targets[i].runtimeModel.executionContext s();
202 if (executionContexts.length) { 205 if (executionContexts.length) {
203 newContext = executionContexts[0]; 206 newContext = executionContexts[0];
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 bracketCount--; 260 bracketCount--;
258 if (bracketCount < 0) 261 if (bracketCount < 0)
259 break; 262 break;
260 } 263 }
261 index--; 264 index--;
262 } 265 }
263 clippedExpression = clippedExpression.substring(index + 1); 266 clippedExpression = clippedExpression.substring(index + 1);
264 267
265 executionContext.completionsForExpression(clippedExpression, completionsPref ix, force, completionsReadyCallback); 268 executionContext.completionsForExpression(clippedExpression, completionsPref ix, force, completionsReadyCallback);
266 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698