• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML>
2<html>
3<head>
4  <title>Preferences Test</title>
5
6  <!-- When using the mode "code" it's important to specify charset utf-8 -->
7  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
8
9  <!-- jsoneditor project from https://github.com/josdejong/jsoneditor/
10       script hosting from http://cdnjs.com/libraries/jsoneditor -->
11  <link href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/4.2.1/jsoneditor.min.css" rel="stylesheet" type="text/css">
12  <script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/4.2.1/jsoneditor.min.js"></script>
13
14  <script>
15    function setup() {
16      if (location.hostname == 'tests' || location.hostname == 'localhost')
17        return;
18
19      alert('This page can only be run from tests or localhost.');
20
21      // Disable all elements.
22      var elements = document.getElementById("form").elements;
23      for (var i = 0, element; element = elements[i++]; ) {
24        element.disabled = true;
25      }
26    }
27  </script>
28</head>
29<body bgcolor="white" onload="setup()">
30  <!-- Header -->
31  <div id="simple_links">
32    [ <b>Simple</b> ]
33    [ <a href="#" onClick="toggleView(); return false;">Advanced</a> ]
34  </div>
35  <div id="advanced_links" style="display:none">
36    [ <a href="#" onClick="toggleView(); return false;">Simple</a> ]
37    [ <b>Advanced</b> ]
38  </div>
39
40  <form id="form">
41
42  <!-- Simple view -->
43  <div id="simple">
44    <p>
45      This page supports display and configuration of a few sample preferences.
46      <table width="100%" style="border: 1px solid #97B0F8">
47        <tr>
48          <td>
49            <input type="checkbox" id="enable_spellchecking"/> Enable spell checking
50          </td>
51        </tr>
52        <tr>
53          <td>
54            <br/>
55            <input type="checkbox" id="allow_running_insecure_content"/> Allow running insecure content
56          </td>
57        </tr>
58        <tr>
59          <td>
60            <br/>
61            Proxy type:
62            <select id="proxy_type" onChange="proxyTypeChange()">
63              <option value="direct">Direct</option>
64              <option value="auto_detect">Auto-Detect</option>
65              <option value="pac_script">PAC Script</option>
66              <option value="fixed_servers">Fixed Servers</option>
67              <option value="system">System</option>
68            </select>
69            <input id="proxy_value" type="text" size="80" disabled/>
70          </td>
71        </tr>
72      </table>
73      <table border="0" width="100%">
74        <tr>
75          <td align="left">
76            <input type="button" value="Refresh" onClick="refreshSimple()"/>
77          </td>
78          <td align="right">
79            <input type="button" value="Apply Changes" onClick="applySimpleChanges()"/>
80          </td>
81        </tr>
82      </table>
83    </p>
84  </div>
85
86  <!-- Advanced view -->
87  <div id="advanced" style="display:none">
88    <p>
89      This page displays all preferences organized in a tree structure. Arbitrary changes are
90      allowed, however <b>changing preferences in arbitrary ways may result in crashes</b>. If you
91      experience a crash while setting preferences then run a Debug build of CEF/Chromium and watch
92      for DCHECKs in the Chromium code to figure out what went wrong.
93    </p>
94    <div id="jsoneditor" style="width: 100%; height: 100%;"></div>
95    <table border="0" width="100%">
96      <tr>
97        <td align="left">
98          <input type="button" value="Refresh" onClick="refreshEditor()"/>
99          <input type="checkbox" id="hide_defaults"/> Show modified preferences only
100        </td>
101        <td align="right">
102          <input type="button" value="Apply Changes" onClick="applyEditorChanges()"/>
103        </td>
104      </tr>
105    </table>
106  </div>
107
108  </form>
109
110  <script>
111    // Reference to the JSONEditor.
112    var editor = null;
113
114    // Preferences state information.
115    var preferences_state = null;
116
117    // Toggle between the simple and advanced views.
118    function toggleView() {
119      var simple = document.getElementById("simple");
120      var advanced = document.getElementById("advanced");
121      var simple_links = document.getElementById("simple_links");
122      var advanced_links = document.getElementById("advanced_links");
123
124      if (simple.style.display == "none") {
125        // Show the simple view.
126        simple.style.display = "";
127        simple_links.style.display = "";
128        advanced.style.display = "none";
129        advanced_links.style.display = "none";
130
131        // Refresh the simple view contents.
132        refreshSimple();
133      } else {
134        // Show the advanced view.
135        simple.style.display = "none";
136        simple_links.style.display = "none";
137        advanced.style.display = "";
138        advanced_links.style.display = "";
139
140        if (editor == null) {
141          // Create the editor.
142          editor = new JSONEditor(document.getElementById("jsoneditor"));
143        }
144
145        // Refesh the editor contents.
146        refreshEditor();
147      }
148    }
149
150    // Send a request to C++.
151    function sendRequest(request, onSuccessCallback) {
152      // Results in a call to the OnQuery method in preferences_test.cpp.
153      window.cefQuery({
154        request: JSON.stringify(request),
155        onSuccess: onSuccessCallback,
156        onFailure: function(error_code, error_message) {
157          alert(error_message + ' (' + error_code + ')');
158        }
159      });
160    }
161
162    // Get the preferences and execute |onSuccessCallback| with the resulting
163    // JSON object.
164    function getPreferences(include_defaults, onSuccessCallback) {
165      // Create the request object.
166      var request = {};
167      request.name = "preferences_get";
168      request.include_defaults = include_defaults;
169
170      // Send the request to C++.
171      sendRequest(
172        request,
173        function(response) {
174          onSuccessCallback(JSON.parse(response));
175        }
176      );
177    }
178
179    // Set the preferences.
180    function setPreferences(preferences) {
181      // Create the request object.
182      var request = {};
183      request.name = "preferences_set";
184      request.preferences = preferences;
185
186      // Send the request to C++.
187      sendRequest(
188        request,
189        function(response) {
190          // Show the informative response message.
191          alert(response);
192        }
193      );
194    }
195
196    // Get the global preference state.
197    function getPreferenceState() {
198      // Create the request object.
199      var request = {};
200      request.name = "preferences_state";
201
202      // Send the request to C++.
203      sendRequest(
204        request,
205        function(response) {
206          // Populate the global state object.
207          preferences_state = JSON.parse(response);
208
209          // Refresh the simple view contents.
210          refreshSimple();
211        }
212      );
213    }
214
215    // Refresh the editor view contents.
216    function refreshEditor() {
217      include_defaults = !document.getElementById("hide_defaults").checked;
218      getPreferences(include_defaults, function(response) {
219        // Set the JSON in the editor.
220        editor.set(response);
221      });
222    }
223
224    // Apply changes from the editor view.
225    function applyEditorChanges() {
226      setPreferences(editor.get());
227    }
228
229    // Refresh the simple view contents.
230    function refreshSimple() {
231      getPreferences(true, function(response) {
232        // Spellcheck settings.
233        if (preferences_state.spellcheck_disabled) {
234          // Cannot enable spell checking when disabled via the command-line.
235          document.getElementById("enable_spellchecking").checked = false;
236          document.getElementById("enable_spellchecking").disabled = true;
237        } else {
238          document.getElementById("enable_spellchecking").checked =
239              response.browser.enable_spellchecking;
240        }
241
242        // Web content settings.
243        if (preferences_state.allow_running_insecure_content) {
244          // Cannot disable running insecure content when enabled via the
245          // command-line.
246          document.getElementById("allow_running_insecure_content").checked =
247              true;
248          document.getElementById("allow_running_insecure_content").disabled =
249              true;
250        } else {
251          document.getElementById("allow_running_insecure_content").checked =
252              response.webkit.webprefs.allow_running_insecure_content;
253        }
254
255        // Proxy settings.
256        document.getElementById("proxy_type").value = response.proxy.mode;
257
258        // Some proxy modes have associated values.
259        if (response.proxy.mode == "pac_script")
260          proxy_value = response.proxy.pac_url;
261        else if (response.proxy.mode == "fixed_servers")
262          proxy_value = response.proxy.server;
263        else
264          proxy_value = null;
265
266        if (proxy_value != null)
267          document.getElementById("proxy_value").value = proxy_value;
268        document.getElementById("proxy_value").disabled = (proxy_value == null);
269
270        if (preferences_state.proxy_configured) {
271          // Cannot modify proxy settings that are configured via the command-
272          // line.
273          document.getElementById("proxy_type").disabled = true;
274          document.getElementById("proxy_value").disabled = true;
275        }
276      });
277    }
278
279    // Apply changes from the simple view.
280    function applySimpleChanges() {
281      has_preferences = false;
282      preferences = {};
283
284      // Spellcheck settings.
285      if (!preferences_state.spellcheck_disabled) {
286        has_preferences = true;
287
288        preferences.browser = {};
289        preferences.browser.enable_spellchecking =
290            document.getElementById("enable_spellchecking").checked;
291      }
292
293      // Web content settings.
294      if (!preferences_state.allow_running_insecure_content) {
295        has_preferences = true;
296
297        preferences.webkit = {};
298        preferences.webkit.webprefs = {};
299        preferences.webkit.webprefs.allow_running_insecure_content =
300            document.getElementById("allow_running_insecure_content").checked;
301      }
302
303      // Proxy settings.
304      if (!preferences_state.proxy_configured) {
305        has_preferences = true;
306
307        preferences.proxy = {};
308        preferences.proxy.mode = document.getElementById("proxy_type").value;
309
310        // Some proxy modes have associated values.
311        if (preferences.proxy.mode == "pac_script") {
312          preferences.proxy.pac_script =
313              document.getElementById("proxy_value").value;
314        } else  if (preferences.proxy.mode == "fixed_servers") {
315          preferences.proxy.server =
316              document.getElementById("proxy_value").value;
317        }
318      }
319
320      if (has_preferences)
321        setPreferences(preferences);
322    }
323
324    // Called when the proxy type is changed.
325    function proxyTypeChange() {
326      proxy_type = document.getElementById("proxy_type").value;
327      document.getElementById("proxy_value").value = "";
328
329      // Only enable the value field for the proxy modes that require it.
330      document.getElementById("proxy_value").disabled =
331          (proxy_type != "pac_script" && proxy_type != "fixed_servers");
332    }
333
334    // Retrieve global preferences state.
335    getPreferenceState();
336  </script>
337</body>
338</html>
339