Updated drag and drop thumbnails.
[chromium-blink-merge.git] / chrome / browser / resources / flags.js
bloba819b86485129ebd5c3a143e6d5a99154328d388
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
3 // found in the LICENSE file.
5 /**
6 * This variable structure is here to document the structure that the template
7 * expects to correctly populate the page.
8 */
10 /**
11 * Takes the |flagsExperimentsData| input argument which represents data about
12 * the currently available experiments and populates the html jstemplate
13 * with that data. It expects an object structure like the above.
14 * @param {Object} flagsExperimentsData Information about available experiments.
15 * See returnFlagsExperiments() for the structure of this object.
17 function renderTemplate(flagsExperimentsData) {
18 // This is the javascript code that processes the template:
19 var input = new JsEvalContext(flagsExperimentsData);
20 var output = $('flagsExperimentTemplate');
21 jstProcess(input, output);
23 // Add handlers to dynamically created HTML elements.
24 var elements = document.getElementsByClassName('experiment-select');
25 for (var i = 0; i < elements.length; ++i) {
26 elements[i].onchange = function() {
27 handleSelectChoiceExperiment(this, this.selectedIndex);
28 return false;
32 elements = document.getElementsByClassName('experiment-disable-link');
33 for (var i = 0; i < elements.length; ++i) {
34 elements[i].onclick = function() {
35 handleEnableExperiment(this, false);
36 return false;
40 elements = document.getElementsByClassName('experiment-enable-link');
41 for (var i = 0; i < elements.length; ++i) {
42 elements[i].onclick = function() {
43 handleEnableExperiment(this, true);
44 return false;
48 elements = document.getElementsByClassName('experiment-restart-button');
49 for (var i = 0; i < elements.length; ++i) {
50 elements[i].onclick = restartBrowser;
54 /**
55 * Asks the C++ FlagsDOMHandler to get details about the available experiments
56 * and return detailed data about the configuration. The FlagsDOMHandler
57 * should reply to returnFlagsExperiments() (below).
59 function requestFlagsExperimentsData() {
60 chrome.send('requestFlagsExperiments');
63 /**
64 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
66 function restartBrowser() {
67 chrome.send('restartBrowser');
70 /**
71 * Called by the WebUI to re-populate the page with data representing the
72 * current state of installed experiments.
73 * @param {Object} flagsExperimentsData Information about available experiments
74 * in the following format:
75 * {
76 * flagsExperiments: [
77 * {
78 * internal_name: 'Experiment ID string',
79 * name: 'Experiment Name',
80 * description: 'description',
81 * // enabled is only set if the experiment is single valued.
82 * enabled: true,
83 * // choices is only set if the experiment has multiple values.
84 * choices: [
85 * {
86 * internal_name: 'Experiment ID string',
87 * description: 'description',
88 * selected: true
89 * }
90 * ],
91 * supported: true,
92 * supported_platforms: [
93 * 'Mac',
94 * 'Linux'
95 * ],
96 * }
97 * ],
98 * needsRestart: false
99 * }
101 function returnFlagsExperiments(flagsExperimentsData) {
102 var bodyContainer = $('body-container');
103 renderTemplate(flagsExperimentsData);
104 bodyContainer.style.visibility = 'visible';
108 * Handles a 'enable' or 'disable' button getting clicked.
109 * @param {HTMLElement} node The node for the experiment being changed.
110 * @param {boolean} enable Whether to enable or disable the experiment.
112 function handleEnableExperiment(node, enable) {
113 // Tell the C++ FlagsDOMHandler to enable/disable the experiment.
114 chrome.send('enableFlagsExperiment', [String(node.internal_name),
115 String(enable)]);
116 requestFlagsExperimentsData();
120 * Invoked when the selection of a multi-value choice is changed to the
121 * specified index.
122 * @param {HTMLElement} node The node for the experiment being changed.
123 * @param {number} index The index of the option that was selected.
125 function handleSelectChoiceExperiment(node, index) {
126 // Tell the C++ FlagsDOMHandler to enable the selected choice.
127 chrome.send('enableFlagsExperiment',
128 [String(node.internal_name) + '@' + index, 'true']);
129 requestFlagsExperimentsData();
132 // Get data and have it displayed upon loading.
133 document.addEventListener('DOMContentLoaded', requestFlagsExperimentsData);