proxyview.js revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 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.
4
5/**
6 * This view displays information on the proxy setup:
7 *
8 *   - Shows the current proxy settings.
9 *   - Has a button to reload these settings.
10 *   - Shows the list of proxy hostnames that are cached as "bad".
11 *   - Has a button to clear the cached bad proxies.
12 *
13 *  @constructor
14 */
15function ProxyView(mainBoxId,
16                   originalSettingsDivId,
17                   effectiveSettingsDivId,
18                   reloadSettingsButtonId,
19                   badProxiesTbodyId,
20                   clearBadProxiesButtonId) {
21  DivView.call(this, mainBoxId);
22
23  // Hook up the UI components.
24  this.originalSettingsDiv_ = document.getElementById(originalSettingsDivId);
25  this.effectiveSettingsDiv_ =
26      document.getElementById(effectiveSettingsDivId);
27  this.badProxiesTbody_ = document.getElementById(badProxiesTbodyId);
28
29  var reloadSettingsButton = document.getElementById(reloadSettingsButtonId);
30  var clearBadProxiesButton = document.getElementById(clearBadProxiesButtonId);
31
32  clearBadProxiesButton.onclick = g_browser.sendClearBadProxies.bind(g_browser);
33  reloadSettingsButton.onclick =
34      g_browser.sendReloadProxySettings.bind(g_browser);
35
36  // Register to receive proxy information as it changes.
37  g_browser.addProxySettingsObserver(this);
38  g_browser.addBadProxiesObserver(this);
39}
40
41inherits(ProxyView, DivView);
42
43ProxyView.prototype.onProxySettingsChanged = function(proxySettings) {
44  var original = proxySettings.original;
45  var effective = proxySettings.effective;
46
47  // Both |original| and |effective| are dictionaries describing the settings.
48  this.originalSettingsDiv_.innerHTML = ''
49  this.effectiveSettingsDiv_.innerHTML = ''
50
51  addTextNode(this.originalSettingsDiv_, proxySettingsToString(original));
52  addTextNode(this.effectiveSettingsDiv_, proxySettingsToString(effective));
53};
54
55ProxyView.prototype.onBadProxiesChanged = function(badProxies) {
56  this.badProxiesTbody_.innerHTML = '';
57
58  // Add a table row for each bad proxy entry.
59  for (var i = 0; i < badProxies.length; ++i) {
60    var entry = badProxies[i];
61    var badUntilDate = g_browser.convertTimeTicksToDate(entry.bad_until);
62
63    var tr = addNode(this.badProxiesTbody_, 'tr');
64
65    var nameCell = addNode(tr, 'td');
66    var badUntilCell = addNode(tr, 'td');
67
68    addTextNode(nameCell, entry.proxy_uri);
69    addTextNode(badUntilCell, badUntilDate.toLocaleString());
70  }
71};
72