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

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

Issue 338283004: DevTools: Use TargetsToolbar instead of ThreadToolbar (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address vsevik's comments Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/console/ConsoleView.js » ('j') | 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 */ 8 */
9 WebInspector.ExecutionContextSelector = function() { 9 WebInspector.ExecutionContextSelector = function()
10 {
10 WebInspector.targetManager.observeTargets(this); 11 WebInspector.targetManager.observeTargets(this);
12 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this);
13 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChanged, this);
11 } 14 }
12 15
13 WebInspector.ExecutionContextSelector.prototype = { 16 WebInspector.ExecutionContextSelector.prototype = {
14 17
15 /** 18 /**
16 * @param {!WebInspector.Target} target 19 * @param {!WebInspector.Target} target
17 */ 20 */
18 targetAdded: function(target) 21 targetAdded: function(target)
19 { 22 {
23 if (!WebInspector.context.flavor(WebInspector.Target))
24 WebInspector.context.setFlavor(WebInspector.Target, target);
25
20 target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.Ex ecutionContextCreated, this._onExecutionContextCreated, this); 26 target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.Ex ecutionContextCreated, this._onExecutionContextCreated, this);
21 target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.Ex ecutionContextDestroyed, this._onExecutionContextDestroyed, this); 27 target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.Ex ecutionContextDestroyed, this._onExecutionContextDestroyed, this);
22 }, 28 },
23 29
24 /** 30 /**
25 * @param {!WebInspector.Target} target 31 * @param {!WebInspector.Target} target
26 */ 32 */
27 targetRemoved: function(target) 33 targetRemoved: function(target)
28 { 34 {
29 target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events .ExecutionContextCreated, this._onExecutionContextCreated, this); 35 target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events .ExecutionContextCreated, this._onExecutionContextCreated, this);
30 target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events .ExecutionContextDestroyed, this._onExecutionContextDestroyed, this); 36 target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events .ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
31 if (WebInspector.context.flavor(WebInspector.ExecutionContext).target() === target) 37 var currentExecutionContext = WebInspector.context.flavor(WebInspector.T arget);
38 if (currentExecutionContext && currentExecutionContext.target() === targ et)
32 this._currentExecutionContextGone(); 39 this._currentExecutionContextGone();
40
41 var targets = WebInspector.targetManager.targets();
42 if (WebInspector.context.flavor(WebInspector.Target) === target && targe ts.length)
43 WebInspector.context.setFlavor(WebInspector.Target, targets[0]);
33 }, 44 },
34 45
35 /** 46 /**
47 * @param {!WebInspector.Event} event
48 */
49 _executionContextChanged: function(event)
50 {
51 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da ta);
52 if (newContext)
53 WebInspector.context.setFlavor(WebInspector.Target, newContext.targe t());
54 },
55
56 /**
57 * @param {!WebInspector.Event} event
58 */
59 _targetChanged: function(event)
60 {
61 var newTarget = /** @type {?WebInspector.Target} */(event.data);
62 var currentContext = WebInspector.context.flavor(WebInspector.ExecutionC ontext);
63
64 if (!newTarget || (currentContext && currentContext.target() === newTarg et))
65 return;
66
67 var executionContexts = newTarget.runtimeModel.executionContexts();
68 if (!executionContexts.length)
69 return;
70
71 var newContext = executionContexts[0];
72 for (var i = 1; i < executionContexts.length; ++i) {
73 if (executionContexts[i].isMainWorldContext)
74 newContext = executionContexts[i];
75 }
76 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext );
77 },
78
79 /**
36 * @param {!WebInspector.Event} event 80 * @param {!WebInspector.Event} event
37 */ 81 */
38 _onExecutionContextCreated: function(event) 82 _onExecutionContextCreated: function(event)
39 { 83 {
40 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve nt.data); 84 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve nt.data);
41 if (!WebInspector.context.flavor(WebInspector.ExecutionContext)) 85 if (!WebInspector.context.flavor(WebInspector.ExecutionContext))
42 WebInspector.context.setFlavor(WebInspector.ExecutionContext, execut ionContext); 86 WebInspector.context.setFlavor(WebInspector.ExecutionContext, execut ionContext);
43 }, 87 },
44 88
45 /** 89 /**
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 completionsReadyCallback([]); 125 completionsReadyCallback([]);
82 return; 126 return;
83 } 127 }
84 128
85 // Pass less stop characters to rangeOfWord so the range will be a more comp lete expression. 129 // Pass less stop characters to rangeOfWord so the range will be a more comp lete expression.
86 var expressionRange = wordRange.startContainer.rangeOfWord(wordRange.startOf fset, " =:[({;,!+-*/&|^<>", proxyElement, "backward"); 130 var expressionRange = wordRange.startContainer.rangeOfWord(wordRange.startOf fset, " =:[({;,!+-*/&|^<>", proxyElement, "backward");
87 var expressionString = expressionRange.toString(); 131 var expressionString = expressionRange.toString();
88 var prefix = wordRange.toString(); 132 var prefix = wordRange.toString();
89 executionContext.completionsForExpression(expressionString, prefix, force, c ompletionsReadyCallback); 133 executionContext.completionsForExpression(expressionString, prefix, force, c ompletionsReadyCallback);
90 } 134 }
OLDNEW
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/console/ConsoleView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698