| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 {!Element} selectElement | 8 * @param {!Element} selectElement |
| 9 */ | 9 */ |
| 10 WebInspector.ConsoleContextSelector = function(selectElement) | 10 WebInspector.ConsoleContextSelector = function(selectElement) |
| 11 { | 11 { |
| 12 this._selectElement = selectElement; | 12 this._selectElement = selectElement; |
| 13 /** | 13 /** |
| 14 * @type {!Map.<!WebInspector.ExecutionContext, !Element>} | 14 * @type {!Map.<!WebInspector.ExecutionContext, !Element>} |
| 15 */ | 15 */ |
| 16 this._optionByExecutionContext = new Map(); | 16 this._optionByExecutionContext = new Map(); |
| 17 | 17 |
| 18 WebInspector.targetManager.observeTargets(this); | 18 WebInspector.targetManager.observeTargets(this); |
| 19 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCre
ated, this); | 19 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCre
ated, this); |
| 20 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextCha
nged, this); | 20 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextCha
nged, this); |
| 21 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextD
estroyed, this); | 21 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextD
estroyed, this); |
| 22 | 22 |
| 23 this._selectElement.addEventListener("change", this._executionContextChanged
.bind(this), false); | 23 this._selectElement.addEventListener("change", this._executionContextChanged
.bind(this), false); |
| 24 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext,
this._executionContextChangedExternally, this); | 24 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext,
this._executionContextChangedExternally, this); |
| 25 } | 25 }; |
| 26 | 26 |
| 27 WebInspector.ConsoleContextSelector.prototype = { | 27 WebInspector.ConsoleContextSelector.prototype = { |
| 28 /** | 28 /** |
| 29 * @param {!WebInspector.ExecutionContext} executionContext | 29 * @param {!WebInspector.ExecutionContext} executionContext |
| 30 * @return {string} | 30 * @return {string} |
| 31 */ | 31 */ |
| 32 _titleFor: function(executionContext) | 32 _titleFor: function(executionContext) |
| 33 { | 33 { |
| 34 var result; | 34 var result; |
| 35 if (executionContext.isDefault) { | 35 if (executionContext.isDefault) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 // This check could be removed once we do not send this context to front
end. | 57 // This check could be removed once we do not send this context to front
end. |
| 58 if (!executionContext.target().hasJSCapability()) | 58 if (!executionContext.target().hasJSCapability()) |
| 59 return; | 59 return; |
| 60 | 60 |
| 61 var newOption = createElement("option"); | 61 var newOption = createElement("option"); |
| 62 newOption.__executionContext = executionContext; | 62 newOption.__executionContext = executionContext; |
| 63 newOption.text = this._titleFor(executionContext); | 63 newOption.text = this._titleFor(executionContext); |
| 64 this._optionByExecutionContext.set(executionContext, newOption); | 64 this._optionByExecutionContext.set(executionContext, newOption); |
| 65 var options = this._selectElement.options; | 65 var options = this._selectElement.options; |
| 66 var contexts = Array.prototype.map.call(options, mapping); | 66 var contexts = Array.prototype.map.call(options, mapping); |
| 67 var index = contexts.lowerBound(executionContext, executionContext.runti
meModel.executionContextComparator()) | 67 var index = contexts.lowerBound(executionContext, executionContext.runti
meModel.executionContextComparator()); |
| 68 this._selectElement.insertBefore(newOption, options[index]); | 68 this._selectElement.insertBefore(newOption, options[index]); |
| 69 | 69 |
| 70 if (executionContext === WebInspector.context.flavor(WebInspector.Execut
ionContext)) | 70 if (executionContext === WebInspector.context.flavor(WebInspector.Execut
ionContext)) |
| 71 this._select(newOption); | 71 this._select(newOption); |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @param {!Element} option | 74 * @param {!Element} option |
| 75 * @return {!WebInspector.ExecutionContext} | 75 * @return {!WebInspector.ExecutionContext} |
| 76 */ | 76 */ |
| 77 function mapping(option) | 77 function mapping(option) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 { | 141 { |
| 142 var option = this._selectedOption(); | 142 var option = this._selectedOption(); |
| 143 var newContext = option ? option.__executionContext : null; | 143 var newContext = option ? option.__executionContext : null; |
| 144 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); | 144 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); |
| 145 this._updateSelectionWarning(); | 145 this._updateSelectionWarning(); |
| 146 }, | 146 }, |
| 147 | 147 |
| 148 _updateSelectionWarning: function() | 148 _updateSelectionWarning: function() |
| 149 { | 149 { |
| 150 var executionContext = WebInspector.context.flavor(WebInspector.Executio
nContext); | 150 var executionContext = WebInspector.context.flavor(WebInspector.Executio
nContext); |
| 151 this._selectElement.parentElement.classList.toggle("warning", !this._isT
opContext(executionContext) && this._hasTopContext()) | 151 this._selectElement.parentElement.classList.toggle("warning", !this._isT
opContext(executionContext) && this._hasTopContext()); |
| 152 }, | 152 }, |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * @param {?WebInspector.ExecutionContext} executionContext | 155 * @param {?WebInspector.ExecutionContext} executionContext |
| 156 * @return {boolean} | 156 * @return {boolean} |
| 157 */ | 157 */ |
| 158 _isTopContext: function(executionContext) | 158 _isTopContext: function(executionContext) |
| 159 { | 159 { |
| 160 if (!executionContext || !executionContext.isDefault) | 160 if (!executionContext || !executionContext.isDefault) |
| 161 return false; | 161 return false; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 /** | 213 /** |
| 214 * @return {?Element} | 214 * @return {?Element} |
| 215 */ | 215 */ |
| 216 _selectedOption: function() | 216 _selectedOption: function() |
| 217 { | 217 { |
| 218 if (this._selectElement.selectedIndex >= 0) | 218 if (this._selectElement.selectedIndex >= 0) |
| 219 return this._selectElement[this._selectElement.selectedIndex]; | 219 return this._selectElement[this._selectElement.selectedIndex]; |
| 220 return null; | 220 return null; |
| 221 } | 221 } |
| 222 } | 222 }; |
| OLD | NEW |