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

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: Rebased Created 4 years, 5 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 var executionContexts = newTarget.runtimeModel.executionContexts(); 94 var executionContexts = newTarget.runtimeModel.executionContexts();
95 if (!executionContexts.length) 95 if (!executionContexts.length)
96 return; 96 return;
97 97
98 var newContext = null; 98 var newContext = null;
99 for (var i = 0; i < executionContexts.length && !newContext; ++i) { 99 for (var i = 0; i < executionContexts.length && !newContext; ++i) {
100 if (this._shouldSwitchToContext(executionContexts[i])) 100 if (this._shouldSwitchToContext(executionContexts[i]))
101 newContext = executionContexts[i]; 101 newContext = executionContexts[i];
102 } 102 }
103 for (var i = 0; i < executionContexts.length && !newContext; ++i) { 103 for (var i = 0; i < executionContexts.length && !newContext; ++i) {
104 if (this._isMainFrameContext(executionContexts[i])) 104 if (this._isDefaultContext(executionContexts[i]))
105 newContext = executionContexts[i]; 105 newContext = executionContexts[i];
106 } 106 }
107 this._ignoreContextChanged = true; 107 this._ignoreContextChanged = true;
108 this._context.setFlavor(WebInspector.ExecutionContext, newContext || exe cutionContexts[0]); 108 this._context.setFlavor(WebInspector.ExecutionContext, newContext || exe cutionContexts[0]);
109 this._ignoreContextChanged = false; 109 this._ignoreContextChanged = false;
110 }, 110 },
111 111
112 /** 112 /**
113 * @param {!WebInspector.ExecutionContext} executionContext 113 * @param {!WebInspector.ExecutionContext} executionContext
114 * @return {boolean} 114 * @return {boolean}
115 */ 115 */
116 _shouldSwitchToContext: function(executionContext) 116 _shouldSwitchToContext: function(executionContext)
117 { 117 {
118 if (this._lastSelectedContextId && this._lastSelectedContextId === this. _contextPersistentId(executionContext)) 118 if (this._lastSelectedContextId && this._lastSelectedContextId === this. _contextPersistentId(executionContext))
119 return true; 119 return true;
120 if (!this._lastSelectedContextId && this._isMainFrameContext(executionCo ntext)) 120 if (!this._lastSelectedContextId && this._isDefaultContext(executionCont ext))
121 return true; 121 return true;
122 return false; 122 return false;
123 }, 123 },
124 124
125 /** 125 /**
126 * @param {!WebInspector.ExecutionContext} executionContext 126 * @param {!WebInspector.ExecutionContext} executionContext
127 * @return {boolean} 127 * @return {boolean}
128 */ 128 */
129 _isMainFrameContext: function(executionContext) 129 _isDefaultContext: function(executionContext)
130 { 130 {
131 if (!executionContext.isDefault) 131 if (!executionContext.isDefault || !executionContext.frameId)
132 return false; 132 return false;
133 var frame = executionContext.target().resourceTreeModel.frameForId(execu tionContext.frameId); 133 if (executionContext.target().parentTarget())
134 return false;
135 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(execut ionContext.target());
pfeldman 2016/07/13 23:55:57 This will not compile once we split sdk into js_sd
eostroukhov-old 2016/07/20 23:46:15 I believe Joel is looking into it. I am not sure w
136 if (!resourceTreeModel)
137 return false;
138 var frame = resourceTreeModel.frameForId(executionContext.frameId);
134 if (frame && frame.isMainFrame()) 139 if (frame && frame.isMainFrame())
135 return true; 140 return true;
136 return false; 141 return false;
137 }, 142 },
138 143
139 /** 144 /**
140 * @param {!WebInspector.Event} event 145 * @param {!WebInspector.Event} event
141 */ 146 */
142 _onExecutionContextCreated: function(event) 147 _onExecutionContextCreated: function(event)
143 { 148 {
(...skipping 15 matching lines...) Expand all
159 this._currentExecutionContextGone(); 164 this._currentExecutionContextGone();
160 }, 165 },
161 166
162 _currentExecutionContextGone: function() 167 _currentExecutionContextGone: function()
163 { 168 {
164 var targets = this._targetManager.targets(WebInspector.Target.Capability .JS); 169 var targets = this._targetManager.targets(WebInspector.Target.Capability .JS);
165 var newContext = null; 170 var newContext = null;
166 for (var i = 0; i < targets.length && !newContext; ++i) { 171 for (var i = 0; i < targets.length && !newContext; ++i) {
167 var executionContexts = targets[i].runtimeModel.executionContexts(); 172 var executionContexts = targets[i].runtimeModel.executionContexts();
168 for (var executionContext of executionContexts) { 173 for (var executionContext of executionContexts) {
169 if (this._isMainFrameContext(executionContext)) { 174 if (this._isDefaultContext(executionContext)) {
170 newContext = executionContext; 175 newContext = executionContext;
171 break; 176 break;
172 } 177 }
173 } 178 }
174 } 179 }
175 if (!newContext) { 180 if (!newContext) {
176 for (var i = 0; i < targets.length && !newContext; ++i) { 181 for (var i = 0; i < targets.length && !newContext; ++i) {
177 var executionContexts = targets[i].runtimeModel.executionContext s(); 182 var executionContexts = targets[i].runtimeModel.executionContext s();
178 if (executionContexts.length) { 183 if (executionContexts.length) {
179 newContext = executionContexts[0]; 184 newContext = executionContexts[0];
(...skipping 28 matching lines...) Expand all
208 var expressionString = expressionRange.toString(); 213 var expressionString = expressionRange.toString();
209 214
210 // The "[" is also a stop character, except when it's the last character of the expression. 215 // The "[" is also a stop character, except when it's the last character of the expression.
211 var pos = expressionString.lastIndexOf("[", expressionString.length - 2); 216 var pos = expressionString.lastIndexOf("[", expressionString.length - 2);
212 if (pos !== -1) 217 if (pos !== -1)
213 expressionString = expressionString.substr(pos + 1); 218 expressionString = expressionString.substr(pos + 1);
214 219
215 var prefix = wordRange.toString(); 220 var prefix = wordRange.toString();
216 executionContext.completionsForExpression(expressionString, text, cursorOffs et, prefix, force, completionsReadyCallback); 221 executionContext.completionsForExpression(expressionString, text, cursorOffs et, prefix, force, completionsReadyCallback);
217 } 222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698