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

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

Issue 2137773002: [DevTools] Replace the target type with capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing the code review comments 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 */
11 WebInspector.ExecutionContextSelector = function(targetManager, context) 11 WebInspector.ExecutionContextSelector = function(targetManager, context)
12 { 12 {
13 targetManager.observeTargets(this); 13 targetManager.observeTargets(this, WebInspector.Target.Capability.JS);
14 context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executi onContextChanged, this); 14 context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executi onContextChanged, this);
15 context.addFlavorChangeListener(WebInspector.Target, this._targetChanged, th is); 15 context.addFlavorChangeListener(WebInspector.Target, this._targetChanged, th is);
16 16
17 targetManager.addModelListener(WebInspector.RuntimeModel, WebInspector.Runti meModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this); 17 targetManager.addModelListener(WebInspector.RuntimeModel, WebInspector.Runti meModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
18 targetManager.addModelListener(WebInspector.RuntimeModel, WebInspector.Runti meModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, thi s); 18 targetManager.addModelListener(WebInspector.RuntimeModel, WebInspector.Runti meModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, thi s);
19 this._targetManager = targetManager; 19 this._targetManager = targetManager;
20 this._context = context; 20 this._context = context;
21 } 21 }
22 22
23 WebInspector.ExecutionContextSelector.prototype = { 23 WebInspector.ExecutionContextSelector.prototype = {
24 24
25 /** 25 /**
26 * @override 26 * @override
27 * @param {!WebInspector.Target} target 27 * @param {!WebInspector.Target} target
28 */ 28 */
29 targetAdded: function(target) 29 targetAdded: function(target)
30 { 30 {
31 if (!target.hasJSContext())
32 return;
33 // Defer selecting default target since we need all clients to get their 31 // Defer selecting default target since we need all clients to get their
34 // targetAdded notifications first. 32 // targetAdded notifications first.
35 setImmediate(deferred.bind(this)); 33 setImmediate(deferred.bind(this));
36 34
37 /** 35 /**
38 * @this {WebInspector.ExecutionContextSelector} 36 * @this {WebInspector.ExecutionContextSelector}
39 */ 37 */
40 function deferred() 38 function deferred()
41 { 39 {
42 // We always want the second context for the service worker targets. 40 // We always want the second context for the service worker targets.
43 if (!this._context.flavor(WebInspector.Target)) 41 if (!this._context.flavor(WebInspector.Target))
44 this._context.setFlavor(WebInspector.Target, target); 42 this._context.setFlavor(WebInspector.Target, target);
45 } 43 }
46 }, 44 },
47 45
48 /** 46 /**
49 * @override 47 * @override
50 * @param {!WebInspector.Target} target 48 * @param {!WebInspector.Target} target
51 */ 49 */
52 targetRemoved: function(target) 50 targetRemoved: function(target)
53 { 51 {
54 if (!target.hasJSContext())
55 return;
56 var currentExecutionContext = this._context.flavor(WebInspector.Executio nContext); 52 var currentExecutionContext = this._context.flavor(WebInspector.Executio nContext);
57 if (currentExecutionContext && currentExecutionContext.target() === targ et) 53 if (currentExecutionContext && currentExecutionContext.target() === targ et)
58 this._currentExecutionContextGone(); 54 this._currentExecutionContextGone();
59 55
60 var targets = this._targetManager.targetsWithJSContext(); 56 var targets = this._targetManager.targets(WebInspector.Target.Capability .JS);
61 if (this._context.flavor(WebInspector.Target) === target && targets.leng th) 57 if (this._context.flavor(WebInspector.Target) === target && targets.leng th)
62 this._context.setFlavor(WebInspector.Target, targets[0]); 58 this._context.setFlavor(WebInspector.Target, targets[0]);
63 }, 59 },
64 60
65 /** 61 /**
66 * @param {!WebInspector.Event} event 62 * @param {!WebInspector.Event} event
67 */ 63 */
68 _executionContextChanged: function(event) 64 _executionContextChanged: function(event)
69 { 65 {
70 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da ta); 66 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da ta);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 */ 154 */
159 _onExecutionContextDestroyed: function(event) 155 _onExecutionContextDestroyed: function(event)
160 { 156 {
161 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve nt.data); 157 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve nt.data);
162 if (this._context.flavor(WebInspector.ExecutionContext) === executionCon text) 158 if (this._context.flavor(WebInspector.ExecutionContext) === executionCon text)
163 this._currentExecutionContextGone(); 159 this._currentExecutionContextGone();
164 }, 160 },
165 161
166 _currentExecutionContextGone: function() 162 _currentExecutionContextGone: function()
167 { 163 {
168 var targets = this._targetManager.targetsWithJSContext(); 164 var targets = this._targetManager.targets(WebInspector.Target.Capability .JS);
169 var newContext = null; 165 var newContext = null;
170 for (var i = 0; i < targets.length && !newContext; ++i) { 166 for (var i = 0; i < targets.length && !newContext; ++i) {
171 if (targets[i].isServiceWorker()) 167 if (!targets[i].hasJSCapability())
dgozman 2016/07/13 00:08:29 It should have it due to parameter passed to targe
eostroukhov-old 2016/07/13 00:36:29 Done.
172 continue; 168 continue;
173 var executionContexts = targets[i].runtimeModel.executionContexts(); 169 var executionContexts = targets[i].runtimeModel.executionContexts();
174 for (var executionContext of executionContexts) { 170 for (var executionContext of executionContexts) {
175 if (this._isMainFrameContext(executionContext)) { 171 if (this._isMainFrameContext(executionContext)) {
176 newContext = executionContext; 172 newContext = executionContext;
177 break; 173 break;
178 } 174 }
179 } 175 }
180 } 176 }
181 if (!newContext) { 177 if (!newContext) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 var expressionString = expressionRange.toString(); 210 var expressionString = expressionRange.toString();
215 211
216 // The "[" is also a stop character, except when it's the last character of the expression. 212 // The "[" is also a stop character, except when it's the last character of the expression.
217 var pos = expressionString.lastIndexOf("[", expressionString.length - 2); 213 var pos = expressionString.lastIndexOf("[", expressionString.length - 2);
218 if (pos !== -1) 214 if (pos !== -1)
219 expressionString = expressionString.substr(pos + 1); 215 expressionString = expressionString.substr(pos + 1);
220 216
221 var prefix = wordRange.toString(); 217 var prefix = wordRange.toString();
222 executionContext.completionsForExpression(expressionString, text, cursorOffs et, prefix, force, completionsReadyCallback); 218 executionContext.completionsForExpression(expressionString, text, cursorOffs et, prefix, force, completionsReadyCallback);
223 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698