OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * This variable structure is here to document the structure that the template | 6 * This variable structure is here to document the structure that the template |
7 * expects to correctly populate the page. | 7 * expects to correctly populate the page. |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
11 * Takes the |experimentsData| input argument which represents data about all | 11 * Takes the |experimentalFeaturesData| input argument which represents data |
12 * the current experiments and populates the html jstemplate with that data. | 12 * about all the current feature entries and populates the html jstemplate with |
13 * with that data. It expects an object structure like the above. | 13 * that data. It expects an object structure like the above. |
14 * @param {Object} experimentsData Information about all experiments. | 14 * @param {Object} experimentalFeaturesData Information about all experiments. |
15 * See returnFlagsExperiments() for the structure of this object. | 15 * See returnFlagsExperiments() for the structure of this object. |
16 */ | 16 */ |
17 function renderTemplate(experimentsData) { | 17 function renderTemplate(experimentalFeaturesData) { |
18 // This is the javascript code that processes the template: | 18 // This is the javascript code that processes the template: |
19 jstProcess(new JsEvalContext(experimentsData), | 19 jstProcess(new JsEvalContext(experimentalFeaturesData), $('flagsTemplate')); |
20 $('flagsExperimentTemplate')); | |
21 | 20 |
22 // Add handlers to dynamically created HTML elements. | 21 // Add handlers to dynamically created HTML elements. |
23 var elements = document.getElementsByClassName('experiment-select'); | 22 var elements = document.getElementsByClassName('experiment-select'); |
24 for (var i = 0; i < elements.length; ++i) { | 23 for (var i = 0; i < elements.length; ++i) { |
25 elements[i].onchange = function() { | 24 elements[i].onchange = function() { |
26 handleSelectChoiceExperiment(this, this.selectedIndex); | 25 handleSelectExperimentalFeatureChoice(this, this.selectedIndex); |
27 return false; | 26 return false; |
28 }; | 27 }; |
29 } | 28 } |
30 | 29 |
31 elements = document.getElementsByClassName('experiment-disable-link'); | 30 elements = document.getElementsByClassName('experiment-disable-link'); |
32 for (var i = 0; i < elements.length; ++i) { | 31 for (var i = 0; i < elements.length; ++i) { |
33 elements[i].onclick = function() { | 32 elements[i].onclick = function() { |
34 handleEnableExperiment(this, false); | 33 handleEnableExperimentalFeature(this, false); |
35 return false; | 34 return false; |
36 }; | 35 }; |
37 } | 36 } |
38 | 37 |
39 elements = document.getElementsByClassName('experiment-enable-link'); | 38 elements = document.getElementsByClassName('experiment-enable-link'); |
40 for (var i = 0; i < elements.length; ++i) { | 39 for (var i = 0; i < elements.length; ++i) { |
41 elements[i].onclick = function() { | 40 elements[i].onclick = function() { |
42 handleEnableExperiment(this, true); | 41 handleEnableExperimentalFeature(this, true); |
43 return false; | 42 return false; |
44 }; | 43 }; |
45 } | 44 } |
46 | 45 |
47 elements = document.getElementsByClassName('experiment-restart-button'); | 46 elements = document.getElementsByClassName('experiment-restart-button'); |
48 for (var i = 0; i < elements.length; ++i) { | 47 for (var i = 0; i < elements.length; ++i) { |
49 elements[i].onclick = restartBrowser; | 48 elements[i].onclick = restartBrowser; |
50 } | 49 } |
51 | 50 |
52 $('experiment-reset-all').onclick = resetAllFlags; | 51 $('experiment-reset-all').onclick = resetAllFlags; |
(...skipping 15 matching lines...) Expand all Loading... |
68 if (document.querySelector('.referenced')) | 67 if (document.querySelector('.referenced')) |
69 document.querySelector('.referenced').classList.remove('referenced'); | 68 document.querySelector('.referenced').classList.remove('referenced'); |
70 // Highlight the referenced element. | 69 // Highlight the referenced element. |
71 el.classList.add('referenced'); | 70 el.classList.add('referenced'); |
72 el.scrollIntoView(); | 71 el.scrollIntoView(); |
73 } | 72 } |
74 } | 73 } |
75 } | 74 } |
76 | 75 |
77 /** | 76 /** |
78 * Asks the C++ FlagsDOMHandler to get details about the available experiments | 77 * Asks the C++ FlagsDOMHandler to get details about the available experimental |
79 * and return detailed data about the configuration. The FlagsDOMHandler | 78 * features and return detailed data about the configuration. The |
80 * should reply to returnFlagsExperiments() (below). | 79 * FlagsDOMHandler should reply to returnFlagsExperiments() (below). |
81 */ | 80 */ |
82 function requestFlagsExperimentsData() { | 81 function requestExperimentalFeaturesData() { |
83 chrome.send('requestFlagsExperiments'); | 82 chrome.send('requestExperimentalFeatures'); |
84 } | 83 } |
85 | 84 |
86 /** | 85 /** |
87 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs). | 86 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs). |
88 */ | 87 */ |
89 function restartBrowser() { | 88 function restartBrowser() { |
90 chrome.send('restartBrowser'); | 89 chrome.send('restartBrowser'); |
91 } | 90 } |
92 | 91 |
93 /** | 92 /** |
94 * Reset all flags to their default values and refresh the UI. | 93 * Reset all flags to their default values and refresh the UI. |
95 */ | 94 */ |
96 function resetAllFlags() { | 95 function resetAllFlags() { |
97 // Asks the C++ FlagsDOMHandler to reset all flags to default values. | 96 // Asks the C++ FlagsDOMHandler to reset all flags to default values. |
98 chrome.send('resetAllFlags'); | 97 chrome.send('resetAllFlags'); |
99 requestFlagsExperimentsData(); | 98 requestExperimentalFeaturesData(); |
100 } | 99 } |
101 | 100 |
102 /** | 101 /** |
103 * Called by the WebUI to re-populate the page with data representing the | 102 * Called by the WebUI to re-populate the page with data representing the |
104 * current state of all experiments. | 103 * current state of all experimental features. |
105 * @param {Object} experimentsData Information about all experiments. | 104 * @param {Object} experimentalFeaturesData Information about all experimental |
106 * in the following format: | 105 * features in the following format: |
107 * { | 106 * { |
108 * supportedExperiments: [ | 107 * supportedFeatures: [ |
109 * { | 108 * { |
110 * internal_name: 'Experiment ID string', | 109 * internal_name: 'Feature ID string', |
111 * name: 'Experiment Name', | 110 * name: 'Feature name', |
112 * description: 'description', | 111 * description: 'Description', |
113 * // enabled and default are only set if the experiment is single | 112 * // enabled and default are only set if the feature is single valued. |
114 * // valued. | 113 * // enabled is true if the feature is currently enabled. |
115 * // enabled is true if the experiment is currently enabled. | 114 * // is_default is true if the feature is in its default state. |
116 * // is_default is true if the experiment is in its default state. | |
117 * enabled: true, | 115 * enabled: true, |
118 * is_default: false, | 116 * is_default: false, |
119 * // choices is only set if the experiment has multiple values. | 117 * // choices is only set if the entry has multiple values. |
120 * choices: [ | 118 * choices: [ |
121 * { | 119 * { |
122 * internal_name: 'Experiment ID string', | 120 * internal_name: 'Experimental feature ID string', |
123 * description: 'description', | 121 * description: 'description', |
124 * selected: true | 122 * selected: true |
125 * } | 123 * } |
126 * ], | 124 * ], |
127 * supported_platforms: [ | 125 * supported_platforms: [ |
128 * 'Mac', | 126 * 'Mac', |
129 * 'Linux' | 127 * 'Linux' |
130 * ], | 128 * ], |
131 * } | 129 * } |
132 * ], | 130 * ], |
133 * unsupportedExperiments: [ | 131 * unsupportedFeatures: [ |
134 * // Mirrors the format of |supportedExperiments| above. | 132 * // Mirrors the format of |supportedFeatures| above. |
135 * ], | 133 * ], |
136 * needsRestart: false, | 134 * needsRestart: false, |
137 * showBetaChannelPromotion: false, | 135 * showBetaChannelPromotion: false, |
138 * showDevChannelPromotion: false, | 136 * showDevChannelPromotion: false, |
139 * showOwnerWarning: false | 137 * showOwnerWarning: false |
140 * } | 138 * } |
141 */ | 139 */ |
142 function returnFlagsExperiments(experimentsData) { | 140 function returnExperimentalFeatures(experimentalFeaturesData) { |
143 var bodyContainer = $('body-container'); | 141 var bodyContainer = $('body-container'); |
144 renderTemplate(experimentsData); | 142 renderTemplate(experimentalFeaturesData); |
145 | 143 |
146 if (experimentsData.showBetaChannelPromotion) | 144 if (experimentalFeaturesData.showBetaChannelPromotion) |
147 $('channel-promo-beta').hidden = false; | 145 $('channel-promo-beta').hidden = false; |
148 else if (experimentsData.showDevChannelPromotion) | 146 else if (experimentalFeaturesData.showDevChannelPromotion) |
149 $('channel-promo-dev').hidden = false; | 147 $('channel-promo-dev').hidden = false; |
150 | 148 |
151 bodyContainer.style.visibility = 'visible'; | 149 bodyContainer.style.visibility = 'visible'; |
152 var ownerWarningDiv = $('owner-warning'); | 150 var ownerWarningDiv = $('owner-warning'); |
153 if (ownerWarningDiv) | 151 if (ownerWarningDiv) |
154 ownerWarningDiv.hidden = !experimentsData.showOwnerWarning; | 152 ownerWarningDiv.hidden = !experimentalFeaturesData.showOwnerWarning; |
155 } | 153 } |
156 | 154 |
157 /** | 155 /** |
158 * Handles a 'enable' or 'disable' button getting clicked. | 156 * Handles a 'enable' or 'disable' button getting clicked. |
159 * @param {HTMLElement} node The node for the experiment being changed. | 157 * @param {HTMLElement} node The node for the experiment being changed. |
160 * @param {boolean} enable Whether to enable or disable the experiment. | 158 * @param {boolean} enable Whether to enable or disable the experiment. |
161 */ | 159 */ |
162 function handleEnableExperiment(node, enable) { | 160 function handleEnableExperimentalFeature(node, enable) { |
163 // Tell the C++ FlagsDOMHandler to enable/disable the experiment. | 161 // Tell the C++ FlagsDOMHandler to enable/disable the experiment. |
164 chrome.send('enableFlagsExperiment', [String(node.internal_name), | 162 chrome.send('enableExperimentalFeature', [String(node.internal_name), |
165 String(enable)]); | 163 String(enable)]); |
166 requestFlagsExperimentsData(); | 164 requestExperimentalFeaturesData(); |
167 } | 165 } |
168 | 166 |
169 /** | 167 /** |
170 * Invoked when the selection of a multi-value choice is changed to the | 168 * Invoked when the selection of a multi-value choice is changed to the |
171 * specified index. | 169 * specified index. |
172 * @param {HTMLElement} node The node for the experiment being changed. | 170 * @param {HTMLElement} node The node for the experiment being changed. |
173 * @param {number} index The index of the option that was selected. | 171 * @param {number} index The index of the option that was selected. |
174 */ | 172 */ |
175 function handleSelectChoiceExperiment(node, index) { | 173 function handleSelectExperimentalFeatureChoice(node, index) { |
176 // Tell the C++ FlagsDOMHandler to enable the selected choice. | 174 // Tell the C++ FlagsDOMHandler to enable the selected choice. |
177 chrome.send('enableFlagsExperiment', | 175 chrome.send('enableExperimentalFeature', |
178 [String(node.internal_name) + '@' + index, 'true']); | 176 [String(node.internal_name) + '@' + index, 'true']); |
179 requestFlagsExperimentsData(); | 177 requestExperimentalFeaturesData(); |
180 } | 178 } |
181 | 179 |
182 // Get data and have it displayed upon loading. | 180 // Get data and have it displayed upon loading. |
183 document.addEventListener('DOMContentLoaded', requestFlagsExperimentsData); | 181 document.addEventListener('DOMContentLoaded', requestExperimentalFeaturesData); |
184 | 182 |
185 // Update the highlighted flag when the hash changes. | 183 // Update the highlighted flag when the hash changes. |
186 window.addEventListener('hashchange', highlightReferencedFlag); | 184 window.addEventListener('hashchange', highlightReferencedFlag); |
OLD | NEW |