| 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 { |
| 11 WebInspector.targetManager.observeTargets(this); | 11 WebInspector.targetManager.observeTargets(this); |
| 12 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext,
this._executionContextChanged, this); | 12 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext,
this._executionContextChanged, this); |
| 13 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ
etChanged, this); | 13 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ
etChanged, this); |
| 14 | 14 |
| 15 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCre
ated, this); | 15 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCre
ated, this); |
| 16 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextD
estroyed, this); | 16 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextD
estroyed, this); |
| 17 } | 17 } |
| 18 | 18 |
| 19 WebInspector.ExecutionContextSelector.prototype = { | 19 WebInspector.ExecutionContextSelector.prototype = { |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * @param {!WebInspector.Target} target | 22 * @param {!WebInspector.Target} target |
| 23 */ | 23 */ |
| 24 targetAdded: function(target) | 24 targetAdded: function(target) |
| 25 { | 25 { |
| 26 // Defer selecting default target since we need all clients to get their | 26 // Defer selecting default target since we need all clients to get their |
| 27 // targetAdded notifications first. | 27 // targetAdded notifications first. |
| 28 setImmediate(function() { | 28 setImmediate(function() { |
| 29 // FIXME(413886): Execution context for the main thread on the servi
ce/shared worker shadow page | |
| 30 // should never be sent to frontend. The worker forntend check below
could be removed once this is fixed. | |
| 31 if (!WebInspector.context.flavor(WebInspector.Target) || WebInspecto
r.isWorkerFrontend()) | 29 if (!WebInspector.context.flavor(WebInspector.Target) || WebInspecto
r.isWorkerFrontend()) |
| 32 WebInspector.context.setFlavor(WebInspector.Target, target); | 30 WebInspector.context.setFlavor(WebInspector.Target, target); |
| 33 }); | 31 }); |
| 34 }, | 32 }, |
| 35 | 33 |
| 36 /** | 34 /** |
| 37 * @param {!WebInspector.Target} target | 35 * @param {!WebInspector.Target} target |
| 38 */ | 36 */ |
| 39 targetRemoved: function(target) | 37 targetRemoved: function(target) |
| 40 { | 38 { |
| 41 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E
xecutionContext); | 39 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E
xecutionContext); |
| 42 if (currentExecutionContext && currentExecutionContext.target() === targ
et) | 40 if (currentExecutionContext && currentExecutionContext.target() === targ
et) |
| 43 this._currentExecutionContextGone(); | 41 this._currentExecutionContextGone(); |
| 44 | 42 |
| 45 var targets = WebInspector.targetManager.targets(); | 43 var targets = WebInspector.targetManager.targets(); |
| 46 if (WebInspector.context.flavor(WebInspector.Target) === target && targe
ts.length) | 44 if (WebInspector.context.flavor(WebInspector.Target) === target && targe
ts.length && !WebInspector.isWorkerFrontend()) |
| 47 WebInspector.context.setFlavor(WebInspector.Target, targets[0]); | 45 WebInspector.context.setFlavor(WebInspector.Target, targets[0]); |
| 48 }, | 46 }, |
| 49 | 47 |
| 50 /** | 48 /** |
| 51 * @param {!WebInspector.Event} event | 49 * @param {!WebInspector.Event} event |
| 52 */ | 50 */ |
| 53 _executionContextChanged: function(event) | 51 _executionContextChanged: function(event) |
| 54 { | 52 { |
| 55 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da
ta); | 53 var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.da
ta); |
| 56 if (newContext) | 54 if (newContext) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 78 newContext = executionContexts[i]; | 76 newContext = executionContexts[i]; |
| 79 } | 77 } |
| 80 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); | 78 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); |
| 81 }, | 79 }, |
| 82 | 80 |
| 83 /** | 81 /** |
| 84 * @param {!WebInspector.Event} event | 82 * @param {!WebInspector.Event} event |
| 85 */ | 83 */ |
| 86 _onExecutionContextCreated: function(event) | 84 _onExecutionContextCreated: function(event) |
| 87 { | 85 { |
| 88 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve
nt.data); | 86 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); |
| 89 if (!WebInspector.context.flavor(WebInspector.ExecutionContext)) | 87 |
| 90 WebInspector.context.setFlavor(WebInspector.ExecutionContext, execut
ionContext); | 88 if (!WebInspector.context.flavor(WebInspector.ExecutionContext)) { |
| 89 // FIXME(413886): Execution context for the main thread on the servi
ce/shared worker shadow page |
| 90 // should never be sent to frontend. The worker frontend check below
could be removed once this is fixed. |
| 91 if (!WebInspector.isWorkerFrontend() || executionContext.target() !=
= WebInspector.targetManager.mainTarget()) |
| 92 WebInspector.context.setFlavor(WebInspector.ExecutionContext, ex
ecutionContext); |
| 93 } |
| 91 }, | 94 }, |
| 92 | 95 |
| 93 /** | 96 /** |
| 94 * @param {!WebInspector.Event} event | 97 * @param {!WebInspector.Event} event |
| 95 */ | 98 */ |
| 96 _onExecutionContextDestroyed: function(event) | 99 _onExecutionContextDestroyed: function(event) |
| 97 { | 100 { |
| 98 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve
nt.data); | 101 var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (eve
nt.data); |
| 99 if (WebInspector.context.flavor(WebInspector.ExecutionContext) === execu
tionContext) | 102 if (WebInspector.context.flavor(WebInspector.ExecutionContext) === execu
tionContext) |
| 100 this._currentExecutionContextGone(); | 103 this._currentExecutionContextGone(); |
| 101 }, | 104 }, |
| 102 | 105 |
| 103 _currentExecutionContextGone: function() | 106 _currentExecutionContextGone: function() |
| 104 { | 107 { |
| 105 var targets = WebInspector.targetManager.targets(); | 108 var targets = WebInspector.targetManager.targets(); |
| 106 var newContext = null; | 109 var newContext = null; |
| 107 for (var i = 0; i < targets.length; ++i) { | 110 for (var i = 0; i < targets.length; ++i) { |
| 111 if (WebInspector.isWorkerFrontend() && targets[i] === WebInspector.t
argetManager.mainTarget()) |
| 112 continue; |
| 108 var executionContexts = targets[i].runtimeModel.executionContexts(); | 113 var executionContexts = targets[i].runtimeModel.executionContexts(); |
| 109 if (executionContexts.length) { | 114 if (executionContexts.length) { |
| 110 newContext = executionContexts[0]; | 115 newContext = executionContexts[0]; |
| 111 break; | 116 break; |
| 112 } | 117 } |
| 113 } | 118 } |
| 114 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); | 119 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); |
| 115 } | 120 } |
| 116 | 121 |
| 117 } | 122 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 completionsReadyCallback([]); | 134 completionsReadyCallback([]); |
| 130 return; | 135 return; |
| 131 } | 136 } |
| 132 | 137 |
| 133 // Pass less stop characters to rangeOfWord so the range will be a more comp
lete expression. | 138 // Pass less stop characters to rangeOfWord so the range will be a more comp
lete expression. |
| 134 var expressionRange = wordRange.startContainer.rangeOfWord(wordRange.startOf
fset, " =:[({;,!+-*/&|^<>", proxyElement, "backward"); | 139 var expressionRange = wordRange.startContainer.rangeOfWord(wordRange.startOf
fset, " =:[({;,!+-*/&|^<>", proxyElement, "backward"); |
| 135 var expressionString = expressionRange.toString(); | 140 var expressionString = expressionRange.toString(); |
| 136 var prefix = wordRange.toString(); | 141 var prefix = wordRange.toString(); |
| 137 executionContext.completionsForExpression(expressionString, prefix, force, c
ompletionsReadyCallback); | 142 executionContext.completionsForExpression(expressionString, prefix, force, c
ompletionsReadyCallback); |
| 138 } | 143 } |
| OLD | NEW |