Chromium Code Reviews| OLD | NEW |
|---|---|
| 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() === newTarge t) | |
|
vsevik
2014/06/19 07:52:42
I don't know what "A || B && C" actually does.
Do
sergeyv
2014/06/19 10:54:44
Yep :)
Done.
| |
| 65 return; | |
|
vsevik
2014/06/19 07:52:42
shouldn't we remove execution context in case ther
| |
| 66 | |
| 67 var executionContexts = newTarget.runtimeModel.executionContexts(); | |
| 68 if (!executionContexts.length) | |
|
vsevik
2014/06/19 07:52:42
Shouldn't we reset execution context?
| |
| 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 Loading... | |
| 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 } |
| OLD | NEW |