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 * @implements {SDK.TargetManager.Observer} | 5 * @implements {SDK.TargetManager.Observer} |
6 * @unrestricted | 6 * @unrestricted |
7 */ | 7 */ |
8 Console.ConsoleContextSelector = class { | 8 Console.ConsoleContextSelector = class { |
9 /** | 9 /** |
10 * @param {!SDK.ExecutionContext} executionContext | |
11 * @param {boolean} showStatus | |
12 * @return {string} | |
13 */ | |
14 static titleFor(executionContext, showStatus) { | |
allada
2017/01/19 02:38:08
I feel like this isn't very descriptive, I would s
luoe
2017/01/19 23:22:59
Done.
| |
15 var result; | |
16 if (executionContext.isDefault) { | |
allada
2017/01/19 02:38:08
I suggest something more like:
if (executionConte
| |
17 if (executionContext.frameId) { | |
18 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(executionContex t.target()); | |
19 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionC ontext.frameId); | |
20 result = frame ? frame.displayName() : executionContext.label(showStatus ); | |
21 } else { | |
22 result = executionContext.target().decorateLabel(executionContext.label( showStatus)); | |
23 } | |
24 } else { | |
25 result = executionContext.label(showStatus) || executionContext.origin; | |
26 } | |
27 | |
28 var maxLength = 50; | |
allada
2017/01/19 02:38:08
nit: inline or change this to const.
luoe
2017/01/19 23:22:59
Done.
| |
29 return result.trimMiddle(maxLength); | |
30 } | |
31 | |
32 /** | |
10 * @param {!Element} selectElement | 33 * @param {!Element} selectElement |
11 */ | 34 */ |
12 constructor(selectElement) { | 35 constructor(selectElement) { |
13 this._selectElement = selectElement; | 36 this._selectElement = selectElement; |
14 /** | 37 /** |
15 * @type {!Map.<!SDK.ExecutionContext, !Element>} | 38 * @type {!Map.<!SDK.ExecutionContext, !Element>} |
16 */ | 39 */ |
17 this._optionByExecutionContext = new Map(); | 40 this._optionByExecutionContext = new Map(); |
18 | 41 |
19 SDK.targetManager.observeTargets(this); | 42 SDK.targetManager.observeTargets(this); |
20 SDK.targetManager.addModelListener( | 43 SDK.targetManager.addModelListener( |
21 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this. _onExecutionContextCreated, this); | 44 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this. _onExecutionContextCreated, this); |
22 SDK.targetManager.addModelListener( | 45 SDK.targetManager.addModelListener( |
23 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this. _onExecutionContextChanged, this); | 46 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this. _onExecutionContextChanged, this); |
24 SDK.targetManager.addModelListener( | 47 SDK.targetManager.addModelListener( |
25 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, thi s._onExecutionContextDestroyed, this); | 48 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, thi s._onExecutionContextDestroyed, this); |
26 | 49 |
27 this._selectElement.addEventListener('change', this._executionContextChanged .bind(this), false); | 50 this._selectElement.addEventListener('change', this._executionContextChanged .bind(this), false); |
28 UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._executionCont extChangedExternally, this); | 51 UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._executionCont extChangedExternally, this); |
29 } | 52 } |
30 | 53 |
31 /** | 54 /** |
32 * @param {!SDK.ExecutionContext} executionContext | 55 * @param {!SDK.ExecutionContext} executionContext |
33 * @return {string} | |
34 */ | |
35 _titleFor(executionContext) { | |
36 var result; | |
37 if (executionContext.isDefault) { | |
38 if (executionContext.frameId) { | |
39 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(executionContex t.target()); | |
40 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionC ontext.frameId); | |
41 result = frame ? frame.displayName() : executionContext.label(); | |
42 } else { | |
43 result = executionContext.target().decorateLabel(executionContext.label( )); | |
44 } | |
45 } else { | |
46 result = '\u00a0\u00a0\u00a0\u00a0' + (executionContext.label() || executi onContext.origin); | |
allada
2017/01/19 02:38:08
Looks like this unicode stuff was used for indenti
| |
47 } | |
48 | |
49 var maxLength = 50; | |
50 return result.trimMiddle(maxLength); | |
51 } | |
52 | |
53 /** | |
54 * @param {!SDK.ExecutionContext} executionContext | |
55 */ | 56 */ |
56 _executionContextCreated(executionContext) { | 57 _executionContextCreated(executionContext) { |
57 // FIXME(413886): We never want to show execution context for the main threa d of shadow page in service/shared worker frontend. | 58 // FIXME(413886): We never want to show execution context for the main threa d of shadow page in service/shared worker frontend. |
58 // This check could be removed once we do not send this context to frontend. | 59 // This check could be removed once we do not send this context to frontend. |
59 if (!executionContext.target().hasJSCapability()) | 60 if (!executionContext.target().hasJSCapability()) |
60 return; | 61 return; |
61 | 62 |
62 var newOption = createElement('option'); | 63 var newOption = createElement('option'); |
63 newOption.__executionContext = executionContext; | 64 newOption.__executionContext = executionContext; |
64 newOption.text = this._titleFor(executionContext); | 65 newOption.text = Console.ConsoleContextSelector.titleFor(executionContext, t rue /* showStatus */); |
65 this._optionByExecutionContext.set(executionContext, newOption); | 66 this._optionByExecutionContext.set(executionContext, newOption); |
66 var options = this._selectElement.options; | 67 var options = this._selectElement.options; |
67 var contexts = Array.prototype.map.call(options, mapping); | 68 var contexts = Array.prototype.map.call(options, mapping); |
68 var index = contexts.lowerBound(executionContext, executionContext.runtimeMo del.executionContextComparator()); | 69 var index = contexts.lowerBound(executionContext, executionContext.runtimeMo del.executionContextComparator()); |
69 this._selectElement.insertBefore(newOption, options[index]); | 70 this._selectElement.insertBefore(newOption, options[index]); |
70 | 71 |
71 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) | 72 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) |
72 this._select(newOption); | 73 this._select(newOption); |
73 | 74 |
74 /** | 75 /** |
(...skipping 14 matching lines...) Loading... | |
89 this._updateSelectionWarning(); | 90 this._updateSelectionWarning(); |
90 } | 91 } |
91 | 92 |
92 /** | 93 /** |
93 * @param {!Common.Event} event | 94 * @param {!Common.Event} event |
94 */ | 95 */ |
95 _onExecutionContextChanged(event) { | 96 _onExecutionContextChanged(event) { |
96 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); | 97 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
97 var option = this._optionByExecutionContext.get(executionContext); | 98 var option = this._optionByExecutionContext.get(executionContext); |
98 if (option) | 99 if (option) |
99 option.text = this._titleFor(executionContext); | 100 option.text = Console.ConsoleContextSelector.titleFor(executionContext, tr ue /* showStatus */); |
100 this._updateSelectionWarning(); | 101 this._updateSelectionWarning(); |
101 } | 102 } |
102 | 103 |
103 /** | 104 /** |
104 * @param {!SDK.ExecutionContext} executionContext | 105 * @param {!SDK.ExecutionContext} executionContext |
105 */ | 106 */ |
106 _executionContextDestroyed(executionContext) { | 107 _executionContextDestroyed(executionContext) { |
107 var option = this._optionByExecutionContext.remove(executionContext); | 108 var option = this._optionByExecutionContext.remove(executionContext); |
108 option.remove(); | 109 option.remove(); |
109 } | 110 } |
(...skipping 91 matching lines...) Loading... | |
201 | 202 |
202 /** | 203 /** |
203 * @return {?Element} | 204 * @return {?Element} |
204 */ | 205 */ |
205 _selectedOption() { | 206 _selectedOption() { |
206 if (this._selectElement.selectedIndex >= 0) | 207 if (this._selectElement.selectedIndex >= 0) |
207 return this._selectElement[this._selectElement.selectedIndex]; | 208 return this._selectElement[this._selectElement.selectedIndex]; |
208 return null; | 209 return null; |
209 } | 210 } |
210 }; | 211 }; |
OLD | NEW |