| 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) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 }, | 81 }, |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * @param {!WebInspector.Event} event | 84 * @param {!WebInspector.Event} event |
| 85 */ | 85 */ |
| 86 _onExecutionContextCreated: function(event) | 86 _onExecutionContextCreated: function(event) |
| 87 { | 87 { |
| 88 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); | 88 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); |
| 89 this._executionContextCreated(executionContext); | 89 this._executionContextCreated(executionContext); |
| 90 this._updateSelectionWarning(); |
| 90 }, | 91 }, |
| 91 | 92 |
| 92 /** | 93 /** |
| 93 * @param {!WebInspector.Event} event | 94 * @param {!WebInspector.Event} event |
| 94 */ | 95 */ |
| 95 _onExecutionContextChanged: function(event) | 96 _onExecutionContextChanged: function(event) |
| 96 { | 97 { |
| 97 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); | 98 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); |
| 98 var option = this._optionByExecutionContext.get(executionContext); | 99 var option = this._optionByExecutionContext.get(executionContext); |
| 99 if (option) | 100 if (option) |
| 100 option.text = this._titleFor(executionContext); | 101 option.text = this._titleFor(executionContext); |
| 102 this._updateSelectionWarning(); |
| 101 }, | 103 }, |
| 102 | 104 |
| 103 /** | 105 /** |
| 104 * @param {!WebInspector.ExecutionContext} executionContext | 106 * @param {!WebInspector.ExecutionContext} executionContext |
| 105 */ | 107 */ |
| 106 _executionContextDestroyed: function(executionContext) | 108 _executionContextDestroyed: function(executionContext) |
| 107 { | 109 { |
| 108 var option = this._optionByExecutionContext.remove(executionContext); | 110 var option = this._optionByExecutionContext.remove(executionContext); |
| 109 option.remove(); | 111 option.remove(); |
| 110 }, | 112 }, |
| 111 | 113 |
| 112 /** | 114 /** |
| 113 * @param {!WebInspector.Event} event | 115 * @param {!WebInspector.Event} event |
| 114 */ | 116 */ |
| 115 _onExecutionContextDestroyed: function(event) | 117 _onExecutionContextDestroyed: function(event) |
| 116 { | 118 { |
| 117 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); | 119 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); |
| 118 this._executionContextDestroyed(executionContext); | 120 this._executionContextDestroyed(executionContext); |
| 121 this._updateSelectionWarning(); |
| 119 }, | 122 }, |
| 120 | 123 |
| 121 /** | 124 /** |
| 122 * @param {!WebInspector.Event} event | 125 * @param {!WebInspector.Event} event |
| 123 */ | 126 */ |
| 124 _executionContextChangedExternally: function(event) | 127 _executionContextChangedExternally: function(event) |
| 125 { | 128 { |
| 126 var executionContext = /** @type {?WebInspector.ExecutionContext} */ (e
vent.data); | 129 var executionContext = /** @type {?WebInspector.ExecutionContext} */ (e
vent.data); |
| 127 if (!executionContext) | 130 if (!executionContext) |
| 128 return; | 131 return; |
| 129 | 132 |
| 130 var options = this._selectElement.options; | 133 var options = this._selectElement.options; |
| 131 for (var i = 0; i < options.length; ++i) { | 134 for (var i = 0; i < options.length; ++i) { |
| 132 if (options[i].__executionContext === executionContext) | 135 if (options[i].__executionContext === executionContext) |
| 133 this._select(options[i]); | 136 this._select(options[i]); |
| 134 } | 137 } |
| 135 }, | 138 }, |
| 136 | 139 |
| 137 _executionContextChanged: function() | 140 _executionContextChanged: function() |
| 138 { | 141 { |
| 139 var option = this._selectedOption(); | 142 var option = this._selectedOption(); |
| 140 var newContext = option ? option.__executionContext : null; | 143 var newContext = option ? option.__executionContext : null; |
| 141 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); | 144 WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext
); |
| 145 this._updateSelectionWarning(); |
| 146 }, |
| 147 |
| 148 _updateSelectionWarning: function() |
| 149 { |
| 150 var executionContext = WebInspector.context.flavor(WebInspector.Executio
nContext); |
| 151 this._selectElement.parentElement.classList.toggle("warning", !this._isT
opContext(executionContext) && this._hasTopContext()) |
| 142 }, | 152 }, |
| 143 | 153 |
| 144 /** | 154 /** |
| 155 * @param {?WebInspector.ExecutionContext} executionContext |
| 156 * @return {boolean} |
| 157 */ |
| 158 _isTopContext: function(executionContext) |
| 159 { |
| 160 if (!executionContext || !executionContext.isDefault) |
| 161 return false; |
| 162 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(execut
ionContext.target()); |
| 163 var frame = executionContext.frameId && resourceTreeModel && resourceTre
eModel.frameForId(executionContext.frameId); |
| 164 if (!frame) |
| 165 return false; |
| 166 return frame.isMainFrame(); |
| 167 }, |
| 168 |
| 169 /** |
| 170 * @return {boolean} |
| 171 */ |
| 172 _hasTopContext: function() |
| 173 { |
| 174 var options = this._selectElement.options; |
| 175 for (var i = 0; i < options.length; i++){ |
| 176 if (this._isTopContext(options[i].__executionContext)) |
| 177 return true; |
| 178 } |
| 179 return false; |
| 180 }, |
| 181 |
| 182 /** |
| 145 * @override | 183 * @override |
| 146 * @param {!WebInspector.Target} target | 184 * @param {!WebInspector.Target} target |
| 147 */ | 185 */ |
| 148 targetAdded: function(target) | 186 targetAdded: function(target) |
| 149 { | 187 { |
| 150 target.runtimeModel.executionContexts().forEach(this._executionContextCr
eated, this); | 188 target.runtimeModel.executionContexts().forEach(this._executionContextCr
eated, this); |
| 151 }, | 189 }, |
| 152 | 190 |
| 153 /** | 191 /** |
| 154 * @override | 192 * @override |
| (...skipping 19 matching lines...) Expand all Loading... |
| 174 /** | 212 /** |
| 175 * @return {?Element} | 213 * @return {?Element} |
| 176 */ | 214 */ |
| 177 _selectedOption: function() | 215 _selectedOption: function() |
| 178 { | 216 { |
| 179 if (this._selectElement.selectedIndex >= 0) | 217 if (this._selectElement.selectedIndex >= 0) |
| 180 return this._selectElement[this._selectElement.selectedIndex]; | 218 return this._selectElement[this._selectElement.selectedIndex]; |
| 181 return null; | 219 return null; |
| 182 } | 220 } |
| 183 } | 221 } |
| OLD | NEW |