| 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 view displays information on the proxy setup: | 6 * This view displays information on the proxy setup: |
| 7 * | 7 * |
| 8 * - Shows the current proxy settings. | 8 * - Shows the current proxy settings. |
| 9 * - Has a button to reload these settings. | 9 * - Has a button to reload these settings. |
| 10 * - Shows the list of proxy hostnames that are cached as "bad". | 10 * - Shows the list of proxy hostnames that are cached as "bad". |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // ID for special HTML element in category_tabs.html | 39 // ID for special HTML element in category_tabs.html |
| 40 ProxyView.TAB_HANDLE_ID = 'tab-handle-proxy'; | 40 ProxyView.TAB_HANDLE_ID = 'tab-handle-proxy'; |
| 41 | 41 |
| 42 // IDs for special HTML elements in proxy_view.html | 42 // IDs for special HTML elements in proxy_view.html |
| 43 ProxyView.MAIN_BOX_ID = 'proxy-view-tab-content'; | 43 ProxyView.MAIN_BOX_ID = 'proxy-view-tab-content'; |
| 44 ProxyView.ORIGINAL_SETTINGS_DIV_ID = 'proxy-view-original-settings'; | 44 ProxyView.ORIGINAL_SETTINGS_DIV_ID = 'proxy-view-original-settings'; |
| 45 ProxyView.EFFECTIVE_SETTINGS_DIV_ID = 'proxy-view-effective-settings'; | 45 ProxyView.EFFECTIVE_SETTINGS_DIV_ID = 'proxy-view-effective-settings'; |
| 46 ProxyView.RELOAD_SETTINGS_BUTTON_ID = 'proxy-view-reload-settings'; | 46 ProxyView.RELOAD_SETTINGS_BUTTON_ID = 'proxy-view-reload-settings'; |
| 47 ProxyView.BAD_PROXIES_TBODY_ID = 'proxy-view-bad-proxies-tbody'; | 47 ProxyView.BAD_PROXIES_TBODY_ID = 'proxy-view-bad-proxies-tbody'; |
| 48 ProxyView.CLEAR_BAD_PROXIES_BUTTON_ID = 'proxy-view-clear-bad-proxies'; | 48 ProxyView.CLEAR_BAD_PROXIES_BUTTON_ID = 'proxy-view-clear-bad-proxies'; |
| 49 ProxyView.SOCKS_HINTS_DIV_ID = 'proxy-view-socks-hints'; |
| 50 ProxyView.SOCKS_HINTS_FLAG_DIV_ID = 'proxy-view-socks-hints-flag'; |
| 49 | 51 |
| 50 cr.addSingletonGetter(ProxyView); | 52 cr.addSingletonGetter(ProxyView); |
| 51 | 53 |
| 52 ProxyView.prototype = { | 54 ProxyView.prototype = { |
| 53 // Inherit the superclass's methods. | 55 // Inherit the superclass's methods. |
| 54 __proto__: superClass.prototype, | 56 __proto__: superClass.prototype, |
| 55 | 57 |
| 56 onLoadLogFinish: function(data) { | 58 onLoadLogFinish: function(data) { |
| 57 return this.onProxySettingsChanged(data.proxySettings) && | 59 return this.onProxySettingsChanged(data.proxySettings) && |
| 58 this.onBadProxiesChanged(data.badProxies); | 60 this.onBadProxiesChanged(data.badProxies); |
| 59 }, | 61 }, |
| 60 | 62 |
| 61 onProxySettingsChanged: function(proxySettings) { | 63 onProxySettingsChanged: function(proxySettings) { |
| 62 // Both |original| and |effective| are dictionaries describing the | |
| 63 // settings. | |
| 64 $(ProxyView.ORIGINAL_SETTINGS_DIV_ID).innerHTML = ''; | 64 $(ProxyView.ORIGINAL_SETTINGS_DIV_ID).innerHTML = ''; |
| 65 $(ProxyView.EFFECTIVE_SETTINGS_DIV_ID).innerHTML = ''; | 65 $(ProxyView.EFFECTIVE_SETTINGS_DIV_ID).innerHTML = ''; |
| 66 this.updateSocksHints_(null); |
| 66 | 67 |
| 67 if (!proxySettings) | 68 if (!proxySettings) |
| 68 return false; | 69 return false; |
| 69 | 70 |
| 71 // Both |original| and |effective| are dictionaries describing the |
| 72 // settings. |
| 70 var original = proxySettings.original; | 73 var original = proxySettings.original; |
| 71 var effective = proxySettings.effective; | 74 var effective = proxySettings.effective; |
| 72 | 75 |
| 73 $(ProxyView.ORIGINAL_SETTINGS_DIV_ID).innerText = | 76 $(ProxyView.ORIGINAL_SETTINGS_DIV_ID).innerText = |
| 74 proxySettingsToString(original); | 77 proxySettingsToString(original); |
| 75 $(ProxyView.EFFECTIVE_SETTINGS_DIV_ID).innerText = | 78 $(ProxyView.EFFECTIVE_SETTINGS_DIV_ID).innerText = |
| 76 proxySettingsToString(effective); | 79 proxySettingsToString(effective); |
| 80 |
| 81 this.updateSocksHints_(effective); |
| 82 |
| 77 return true; | 83 return true; |
| 78 }, | 84 }, |
| 79 | 85 |
| 80 onBadProxiesChanged: function(badProxies) { | 86 onBadProxiesChanged: function(badProxies) { |
| 81 $(ProxyView.BAD_PROXIES_TBODY_ID).innerHTML = ''; | 87 $(ProxyView.BAD_PROXIES_TBODY_ID).innerHTML = ''; |
| 82 | 88 |
| 83 if (!badProxies) | 89 if (!badProxies) |
| 84 return false; | 90 return false; |
| 85 | 91 |
| 86 // Add a table row for each bad proxy entry. | 92 // Add a table row for each bad proxy entry. |
| 87 for (var i = 0; i < badProxies.length; ++i) { | 93 for (var i = 0; i < badProxies.length; ++i) { |
| 88 var entry = badProxies[i]; | 94 var entry = badProxies[i]; |
| 89 var badUntilDate = timeutil.convertTimeTicksToDate(entry.bad_until); | 95 var badUntilDate = timeutil.convertTimeTicksToDate(entry.bad_until); |
| 90 | 96 |
| 91 var tr = addNode($(ProxyView.BAD_PROXIES_TBODY_ID), 'tr'); | 97 var tr = addNode($(ProxyView.BAD_PROXIES_TBODY_ID), 'tr'); |
| 92 | 98 |
| 93 var nameCell = addNode(tr, 'td'); | 99 var nameCell = addNode(tr, 'td'); |
| 94 var badUntilCell = addNode(tr, 'td'); | 100 var badUntilCell = addNode(tr, 'td'); |
| 95 | 101 |
| 96 addTextNode(nameCell, entry.proxy_uri); | 102 addTextNode(nameCell, entry.proxy_uri); |
| 97 timeutil.addNodeWithDate(badUntilCell, badUntilDate); | 103 timeutil.addNodeWithDate(badUntilCell, badUntilDate); |
| 98 } | 104 } |
| 99 return true; | 105 return true; |
| 106 }, |
| 107 |
| 108 updateSocksHints_: function(proxySettings) { |
| 109 setNodeDisplay($(ProxyView.SOCKS_HINTS_DIV_ID), false); |
| 110 |
| 111 if (!proxySettings) |
| 112 return; |
| 113 |
| 114 var socksProxy = getSocks5Proxy_(proxySettings.single_proxy); |
| 115 if (!socksProxy) |
| 116 return; |
| 117 |
| 118 // Suggest a recommended --host-resolver-rules. |
| 119 // NOTE: This does not compensate for any proxy bypass rules. If the |
| 120 // proxy settings include proxy bypasses the user may need to expand the |
| 121 // exclusions for host resolving. |
| 122 var hostResolverRules = 'MAP * ~NOTFOUND , EXCLUDE ' + socksProxy.host; |
| 123 var hostResolverRulesFlag = '--host-resolver-rules="' + |
| 124 hostResolverRules + '"'; |
| 125 |
| 126 // TODO(eroman): On Linux the ClientInfo.command_line is wrong in that it |
| 127 // doesn't include any quotes around the parameters. This means the |
| 128 // string search above is going to fail :( |
| 129 if (ClientInfo.command_line && |
| 130 ClientInfo.command_line.indexOf(hostResolverRulesFlag) != -1) { |
| 131 // Chrome is already using the suggested resolver rules. |
| 132 return; |
| 133 } |
| 134 |
| 135 $(ProxyView.SOCKS_HINTS_FLAG_DIV_ID).innerText = hostResolverRulesFlag; |
| 136 setNodeDisplay($(ProxyView.SOCKS_HINTS_DIV_ID), true); |
| 100 } | 137 } |
| 101 }; | 138 }; |
| 102 | 139 |
| 140 function getSocks5Proxy_(proxyString) { |
| 141 var pattern = /^socks5:\/\/(.*)$/; |
| 142 var matches = pattern.exec(proxyString); |
| 143 |
| 144 if (!matches) |
| 145 return null; |
| 146 |
| 147 var hostPortString = matches[1]; |
| 148 |
| 149 matches = /^(.*):(\d+)$/.exec(hostPortString); |
| 150 if (!matches) |
| 151 return null; |
| 152 |
| 153 var result = {host: matches[1], port: matches[2]}; |
| 154 |
| 155 // Strip brackets off of IPv6 literals. |
| 156 matches = /^\[(.*)\]$/.exec(result.host); |
| 157 if (matches) |
| 158 result.host = matches[1]; |
| 159 |
| 160 return result; |
| 161 } |
| 162 |
| 103 return ProxyView; | 163 return ProxyView; |
| 104 })(); | 164 })(); |
| OLD | NEW |