diff options
author | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-02 16:37:19 +0000 |
---|---|---|
committer | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-02 16:37:19 +0000 |
commit | 0ff16aec015bea373b87832d76ed25a50750a33d (patch) | |
tree | 54eb4cdfd9c797e784416e969e2c1cc5dd227248 | |
parent | e1ddd8c46f262419b0f217efe22ab589d85a6f56 (diff) | |
download | chromium_src-0ff16aec015bea373b87832d76ed25a50750a33d.zip chromium_src-0ff16aec015bea373b87832d76ed25a50750a33d.tar.gz chromium_src-0ff16aec015bea373b87832d76ed25a50750a33d.tar.bz2 |
Change for proxy stuff.
BUG=3370
TEST=none
Review URL: http://codereview.chromium.org/3113021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58370 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/cros_settings_provider_proxy.cc | 282 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros_settings_provider_proxy.h | 29 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/proxy_handler.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/proxy_handler.h | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/resources/options.html | 8 | ||||
-rw-r--r-- | chrome/browser/resources/options/chromeos_proxy.html | 129 | ||||
-rw-r--r-- | chrome/browser/resources/options/chromeos_proxy_options.js | 161 | ||||
-rw-r--r-- | chrome/browser/resources/options/chromeos_proxy_rules_list.js | 140 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
10 files changed, 700 insertions, 70 deletions
diff --git a/chrome/browser/chromeos/cros_settings_provider_proxy.cc b/chrome/browser/chromeos/cros_settings_provider_proxy.cc new file mode 100644 index 0000000..6021db4 --- /dev/null +++ b/chrome/browser/chromeos/cros_settings_provider_proxy.cc @@ -0,0 +1,282 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/cros_settings_provider_proxy.h" + +#include "base/string_util.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/chromeos/proxy_config_service.h" +#include "chrome/browser/chromeos/proxy_config_service_impl.h" +#include "chrome/browser/profile.h" +#include "net/proxy/proxy_config.h" + +namespace chromeos { + +CrosSettingsProviderProxy::CrosSettingsProviderProxy() { } + +void CrosSettingsProviderProxy::Set(const std::string& path, + Value* in_value) { + Browser* browser = BrowserList::GetLastActive(); + if (!browser || !in_value) { + return; + } + chromeos::ProxyConfigServiceImpl* config_service = + browser->profile()->GetChromeOSProxyConfigServiceImpl(); + chromeos::ProxyConfigServiceImpl::ProxyConfig config; + config_service->UIGetProxyConfig(&config); + + if (path == "cros.proxy.pacurl") { + std::string val; + if (in_value->GetAsString(&val)) { + GURL url(val); + config_service->UISetProxyConfigToPACScript(url); + } + } else if (path == "cros.proxy.singlehttp") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = val; + uri += ":"; + uri += config.single_proxy.server.host_port_pair().port(); + config_service->UISetProxyConfigToSingleProxy( + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); + } + } else if (path == "cros.proxy.singlehttpport") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = config.single_proxy.server.host_port_pair().host(); + uri += ":"; + uri += val; + config_service->UISetProxyConfigToSingleProxy( + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); + } + } else if (path == "cros.proxy.httpurl") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = val; + uri += ":"; + uri += config.http_proxy.server.host_port_pair().port(); + config_service->UISetProxyConfigToProxyPerScheme("http", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); + } + } else if (path == "cros.proxy.httpsurl") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = val; + uri += config.https_proxy.server.host_port_pair().port(); + config_service->UISetProxyConfigToProxyPerScheme("https", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTPS)); + } + } else if (path == "cros.proxy.type") { + int val; + if (in_value->GetAsInteger(&val)) { + if (val == 3) { + if (config.automatic_proxy.pac_url.is_valid()) + config_service->UISetProxyConfigToPACScript( + config.automatic_proxy.pac_url); + else + config_service->UISetProxyConfigToAutoDetect(); + } else if (val == 2) { + config_service->UISetProxyConfigToProxyPerScheme("http", + net::ProxyServer()); + } else { + config_service->UISetProxyConfigToDirect(); + } + } + } else if (path == "cros.proxy.single") { + bool val; + if (in_value->GetAsBoolean(&val)) { + if (val) + config_service->UISetProxyConfigToSingleProxy(config.http_proxy.server); + else + config_service->UISetProxyConfigToProxyPerScheme("http", + config.http_proxy.server); + } + } else if (path == "cros.proxy.ftp") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = val; + uri += config.ftp_proxy.server.host_port_pair().port(); + config_service->UISetProxyConfigToProxyPerScheme("ftp", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); + } + } else if (path == "cros.proxy.socks") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = val; + uri += config.socks_proxy.server.host_port_pair().port(); + config_service->UISetProxyConfigToProxyPerScheme("socks", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_SOCKS4)); + } + } else if (path == "cros.proxy.httpport") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = config.http_proxy.server.host_port_pair().host() + + ":" + val; + config_service->UISetProxyConfigToProxyPerScheme("http", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); + } + } else if (path == "cros.proxy.httpsport") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = config.https_proxy.server.host_port_pair().host(); + uri += ":"; + uri += val; + config_service->UISetProxyConfigToProxyPerScheme("https", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTPS)); + } + } else if (path == "cros.proxy.ftpport") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = config.ftp_proxy.server.host_port_pair().host(); + uri += ":"; + uri += val; + config_service->UISetProxyConfigToProxyPerScheme("ftp", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); + } + } else if (path == "cros.proxy.socksport") { + std::string val; + if (in_value->GetAsString(&val)) { + std::string uri = config.socks_proxy.server.host_port_pair().host(); + uri += ":"; + uri += val; + config_service->UISetProxyConfigToProxyPerScheme("socks", + net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_SOCKS5)); + } + } else if (path == "cros.proxy.ignorelist") { + net::ProxyBypassRules bypass_rules; + if (in_value->GetType() == Value::TYPE_LIST) { + const ListValue* list_value = static_cast<const ListValue*>(in_value); + for (size_t x = 0; x < list_value->GetSize(); x++) { + std::string val; + if (list_value->GetString(x, &val)) { + bypass_rules.AddRuleFromString(val); + } + } + config_service->UISetProxyConfigBypassRules(bypass_rules); + } + } +} + +bool CrosSettingsProviderProxy::Get(const std::string& path, + Value** out_value) const { + Browser* browser = BrowserList::GetLastActive(); + bool found = false; + bool managed = false; + Value* data; + if (!browser) { + return false; + } + chromeos::ProxyConfigServiceImpl* config_service = + browser->profile()->GetChromeOSProxyConfigServiceImpl(); + chromeos::ProxyConfigServiceImpl::ProxyConfig config; + config_service->UIGetProxyConfig(&config); + + if (path == "cros.proxy.pacurl") { + if (config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { + data = Value::CreateStringValue( + config.automatic_proxy.pac_url.spec()); + found = true; + } + } else if (path == "cros.proxy.singlehttp") { + data = Value::CreateStringValue( + config.single_proxy.server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.singlehttpport") { + data = Value::CreateIntegerValue( + config.single_proxy.server.host_port_pair().port()); + found = true; + } else if (path == "cros.proxy.httpurl") { + data = Value::CreateStringValue( + config.http_proxy.server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.httpsurl") { + data = Value::CreateStringValue( + config.https_proxy.server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.type") { + if (config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT || + config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { + data = Value::CreateIntegerValue(3); + } else if (config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || + config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { + data = Value::CreateIntegerValue(2); + } else { + data = Value::CreateIntegerValue(1); + } + found = true; + } else if (path == "cros.proxy.single") { + if (config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY) { + data = Value::CreateBooleanValue(true); + } else { + data = Value::CreateBooleanValue(false); + } + found = true; + } else if (path == "cros.proxy.http") { + net::ProxyServer& server = config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY ? + config.single_proxy.server : config.http_proxy.server; + data = Value::CreateStringValue(server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.https") { + data = Value::CreateStringValue( + config.https_proxy.server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.ftp") { + data = Value::CreateStringValue( + config.ftp_proxy.server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.socks") { + data = Value::CreateStringValue( + config.socks_proxy.server.host_port_pair().host()); + found = true; + } else if (path == "cros.proxy.httpport") { + net::ProxyServer& server = config.mode == + chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY ? + config.single_proxy.server : config.http_proxy.server; + data = Value::CreateIntegerValue(server.host_port_pair().port()); + found = true; + } else if (path == "cros.proxy.httpsport") { + data = Value::CreateIntegerValue( + config.https_proxy.server.host_port_pair().port()); + found = true; + } else if (path == "cros.proxy.ftpport") { + data = Value::CreateIntegerValue( + config.ftp_proxy.server.host_port_pair().port()); + found = true; + } else if (path == "cros.proxy.socksport") { + data = Value::CreateIntegerValue( + config.socks_proxy.server.host_port_pair().port()); + found = true; + } else if (path == "cros.proxy.ignorelist") { + ListValue* list = new ListValue(); + net::ProxyBypassRules::RuleList bypass_rules = config.bypass_rules.rules(); + for (size_t x = 0; x < bypass_rules.size(); x++) { + list->Append(Value::CreateStringValue(bypass_rules[x]->ToString())); + } + *out_value = list; + return true; + } + if (found) { + DictionaryValue* dict = new DictionaryValue; + dict->Set("value", data); + dict->SetBoolean("managed", managed); + *out_value = dict; + return true; + } else { + *out_value = NULL; + return false; + } +} + +bool CrosSettingsProviderProxy::HandlesSetting(const std::string& path) { + return ::StartsWithASCII(path, "cros.proxy", true); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/cros_settings_provider_proxy.h b/chrome/browser/chromeos/cros_settings_provider_proxy.h new file mode 100644 index 0000000..118db18 --- /dev/null +++ b/chrome/browser/chromeos/cros_settings_provider_proxy.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_PROXY_H_ +#define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_PROXY_H_ +#pragma once + +#include "base/singleton.h" +#include "base/values.h" +#include "chrome/browser/chromeos/cros_settings_provider.h" + +namespace chromeos { + +class CrosSettingsProviderProxy : public CrosSettingsProvider { + public: + CrosSettingsProviderProxy(); + virtual void Set(const std::string& path, Value* in_value); + virtual bool Get(const std::string& path, Value** out_value) const; + virtual bool HandlesSetting(const std::string& path); + + private: + + DISALLOW_COPY_AND_ASSIGN(CrosSettingsProviderProxy); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_PROXY_H_ diff --git a/chrome/browser/chromeos/dom_ui/proxy_handler.cc b/chrome/browser/chromeos/dom_ui/proxy_handler.cc index b9cd1cb..2ca89be 100644 --- a/chrome/browser/chromeos/dom_ui/proxy_handler.cc +++ b/chrome/browser/chromeos/dom_ui/proxy_handler.cc @@ -12,6 +12,7 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/chromeos/cros_settings_provider_proxy.h" #include "chrome/common/notification_service.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" @@ -19,7 +20,10 @@ #include "grit/locale_settings.h" #include "grit/theme_resources.h" -ProxyHandler::ProxyHandler() { +namespace chromeos { + +ProxyHandler::ProxyHandler() + : CrosOptionsPageUIHandler(new CrosSettingsProviderProxy()) { } ProxyHandler::~ProxyHandler() { @@ -33,7 +37,7 @@ void ProxyHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_OPTIONS_PROXY_TAB_LABEL)); localized_strings->SetString("proxy_config_title", l10n_util::GetStringUTF16(IDS_PROXY_CONFIG_TITLE)); - localized_strings->SetString("proxyDirectIternetConnection", + localized_strings->SetString("proxyDirectInternetConnection", l10n_util::GetStringUTF16(IDS_PROXY_DIRECT_CONNECTION)); localized_strings->SetString("proxyManual", @@ -62,3 +66,5 @@ void ProxyHandler::GetLocalizedValues( localized_strings->SetString("proxyPort", l10n_util::GetStringUTF16(IDS_PROXY_PORT)); } + +} // namespace chromeos diff --git a/chrome/browser/chromeos/dom_ui/proxy_handler.h b/chrome/browser/chromeos/dom_ui/proxy_handler.h index 667bcbd8..f0a196c 100644 --- a/chrome/browser/chromeos/dom_ui/proxy_handler.h +++ b/chrome/browser/chromeos/dom_ui/proxy_handler.h @@ -5,10 +5,11 @@ #ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_PROXY_HANDLER_H_ #define CHROME_BROWSER_CHROMEOS_DOM_UI_PROXY_HANDLER_H_ -#include "chrome/browser/dom_ui/options_ui.h" +#include "chrome/browser/chromeos/dom_ui/cros_options_page_ui_handler.h" +namespace chromeos { // ChromeOS proxy options page UI handler. -class ProxyHandler : public OptionsPageUIHandler { +class ProxyHandler : public CrosOptionsPageUIHandler { public: ProxyHandler(); virtual ~ProxyHandler(); @@ -20,5 +21,5 @@ class ProxyHandler : public OptionsPageUIHandler { DISALLOW_COPY_AND_ASSIGN(ProxyHandler); }; - +} // namespace chromeos #endif // CHROME_BROWSER_CHROMEOS_DOM_UI_PROXY_HANDLER_H_ diff --git a/chrome/browser/dom_ui/options_ui.cc b/chrome/browser/dom_ui/options_ui.cc index b0293c5..430e9f8 100644 --- a/chrome/browser/dom_ui/options_ui.cc +++ b/chrome/browser/dom_ui/options_ui.cc @@ -165,7 +165,7 @@ OptionsUI::OptionsUI(TabContents* contents) : DOMUI(contents) { new chromeos::LanguageOptionsHandler()); AddOptionsPageUIHandler(localized_strings, new chromeos::LanguagePinyinOptionsHandler()); - AddOptionsPageUIHandler(localized_strings, new ProxyHandler()); + AddOptionsPageUIHandler(localized_strings, new chromeos::ProxyHandler()); AddOptionsPageUIHandler(localized_strings, new SystemOptionsHandler()); #endif diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html index fa4ee62..80040b7 100644 --- a/chrome/browser/resources/options.html +++ b/chrome/browser/resources/options.html @@ -60,6 +60,8 @@ <script src="options/chromeos_language_options.js"></script> <script src="options/chromeos_system_options.js"></script> <script src="options/chromeos_accounts_options.js"></script> + <script src="options/chromeos_proxy_options.js"></script> + <script src="options/chromeos_proxy_rules_list.js"></script> <script src="options/chromeos_accounts_user_list.js"></script> <script src="options/chromeos_accounts_user_name_edit.js"></script> <script> @@ -117,6 +119,7 @@ var PersonalOptions = options.PersonalOptions; var Preferences = options.Preferences; var SearchEngineManager = options.SearchEngineManager; var StopSyncingOverlay = options.StopSyncingOverlay; +var ProxyOptions = options.ProxyOptions; var PasswordsRemoveAllOverlay = options.PasswordsRemoveAllOverlay; /** @@ -175,10 +178,7 @@ function load() { 'languagePinyin', localStrings.getString('languagePinyinPage'), 'languagePinyinPage')); - var proxy = new OptionsPage('proxy', - localStrings.getString('proxyPage'), - 'proxyPage'); - OptionsPage.registerSubPage(proxy); + OptionsPage.registerSubPage(ProxyOptions.getInstance()); } var syncSettings = new OptionsPage('sync', diff --git a/chrome/browser/resources/options/chromeos_proxy.html b/chrome/browser/resources/options/chromeos_proxy.html index 3fd799b..4c0afba 100644 --- a/chrome/browser/resources/options/chromeos_proxy.html +++ b/chrome/browser/resources/options/chromeos_proxy.html @@ -2,75 +2,84 @@ <h1 i18n-content="proxyPage"></h1> <section> <h3 i18n-content="proxy_config_title"></h3> - <table class="option-control-table"> - <tr><td> - <label><input type="radio" name="proxytype" - value=""><span - i18n-content="proxyDirectIternetConnection"></span> + <div> + <label><input type="radio" id="directProxy" name="proxytype" + pref="cros.proxy.type" value="1"><span + i18n-content="proxyDirectInternetConnection"></span> </label> - </td></tr> - <tr><td> - <label><input type="radio" name="proxytype" - value=""><span + <label><input type="radio" id="manualProxy" name="proxytype" + pref="cros.proxy.type" value="2"><span i18n-content="proxyManual"></span></label> - </td></tr> - <tr><td> <label><input id="proxyAllProtocols" - type="checkbox"><span - i18n-content="sameProxyProtocols"></span></label><br> - <label><span - i18n-content="httpProxy"></span> - <input id="proxyHostName" type="text" size="30" disabled> - </label> - <label><span - i18n-content="proxyPort"></span> - <input id="proxyHostPort" type="text" size="5" disabled> - </label> - <br> - <label><span - i18n-content="secureHttpProxy"></span> - <input id="secureProxyHostName" type="text" size="30" disabled> - </label> - <label><span - i18n-content="proxyPort"></span> - <input id="secureProxyHostNamePort" type="text" size="5" disabled> - </label> - <br> - <label><span - i18n-content="ftpProxy"></span> - <input id="ftpProxy" type="text" size="30" disabled> - </label> - <label><span - i18n-content="proxyPort"></span> - <input id="ftpProxyPort" type="text" size="5" disabled> - </label> - <br> - <label><span - i18n-content="socksHost"></span> - <input id="socksHost" type="text" size="30" disabled> - </label> - <label><span - i18n-content="proxyPort"></span> - <input id="socksPort" type="text" size="5" disabled> - </label> - <br> - </td></tr> - <tr><td> - <label><input type="radio" name="proxytype" - value=""><span - i18n-content="proxyAutomatic"></span></label><br> + type="checkbox" pref="cros.proxy.single"><span + i18n-content="sameProxyProtocols"></span></label> + <div id="singleProxy"> + <table> + <tr><td><span + i18n-content="httpProxy"></span> + <input id="proxyHostSingleName" type="text" size="30" pref="cros.proxy.singlehttp" disabled> + </td><td> + <span + i18n-content="proxyPort"></span> + <input id="proxyHostSinglePort" type="text" size="5" pref="cros.proxy.singlehttpport" disabled> + </td></tr> + </table> + </div> + <div id="multiProxy"> + <table> + <tr> + <td><span + i18n-content="httpProxy"></span></td><td> + <input id="proxyHostName" type="text" size="30" pref="cros.proxy.httpurl" disabled> + </td><td> + <span + i18n-content="proxyPort"></span></td><td> + <input id="proxyHostPort" type="text" size="5" pref="cros.proxy.httpport" disabled> + </td></tr> + <tr> + <td><span + i18n-content="secureHttpProxy"></span></td><td> + <input id="secureProxyHostName" type="text" size="30" pref="cros.proxy.httpsurl" disabled> + </td><td> + <span + i18n-content="proxyPort"></span></td><td> + <input id="secureProxyPort" type="text" size="5" pref="cros.proxy.httpsport" disabled> + </td></tr> + <tr> + <td><span + i18n-content="ftpProxy"></span></td><td> + <input id="ftpProxy" type="text" size="30" pref="cros.proxy.ftpurl" disabled> + </td><td> + <span + i18n-content="proxyPort"></span></td><td> + <input id="ftpProxyPort" type="text" size="5" pref="cros.proxy.ftpport" disabled> + </td></tr> + <tr> + <td><span + i18n-content="socksHost"></span></td><td> + <input id="socksHost" type="text" size="30" pref="cros.proxy.socks" disabled> + </td><td> + <span + i18n-content="proxyPort"></span></td><td> + <input id="socksPort" type="text" size="5" pref="cros.proxy.socksport" disabled> + </td></tr> + </table> + </div> + <label><input type="radio" id="autoProxy" name="proxytype" + pref="cros.proxy.type" value="3"><span + i18n-content="proxyAutomatic"></span></label> <label><span i18n-content="proxyConfigUrl"></span> - <input id="proxyConfig" type="url" size="60" disabled> + <input id="proxyConfig" type="url" size="60" pref="cros.proxy.pacurl"> </label> - </td></tr> - </table> + </div> </section> - <section> + <section id="advancedConfig"> <h3 i18n-content="advanced_proxy_config"></h3> <div class="option"> - <td class="option-name"><list id="ignoredHostList"></list></td> - <br> + <list id="ignoredHostList"></list> + <br> + <input id="newHost" type="url" size="30"><br> <button id="addHost" i18n-content="addHost"></button> <button id="removeHost" diff --git a/chrome/browser/resources/options/chromeos_proxy_options.js b/chrome/browser/resources/options/chromeos_proxy_options.js new file mode 100644 index 0000000..d2fcef7 --- /dev/null +++ b/chrome/browser/resources/options/chromeos_proxy_options.js @@ -0,0 +1,161 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +cr.define('options', function() { + + var OptionsPage = options.OptionsPage; + + ///////////////////////////////////////////////////////////////////////////// + // ProxyOptions class: + + /** + * Encapsulated handling of ChromeOS accounts options page. + * @constructor + */ + function ProxyOptions(model) { + OptionsPage.call(this, 'proxy', localStrings.getString('proxyPage'), + 'proxyPage'); + } + + ProxyOptions.getInstance = function() { + if (!ProxyOptions.instance_) { + ProxyOptions.instance_ = new ProxyOptions(null); + } + return ProxyOptions.instance_; + }; + + ProxyOptions.prototype = { + // Inherit ProxyOptions from OptionsPage. + __proto__: OptionsPage.prototype, + + /** + * Initializes ProxyOptions page. + */ + initializePage: function() { + // Call base class implementation to starts preference initialization. + OptionsPage.prototype.initializePage.call(this); + + // Set up ignored page. + options.proxyexceptions.ProxyExceptions.decorate($('ignoredHostList')); + + this.addEventListener('visibleChange', this.handleVisibleChange_); + $('removeHost').addEventListener('click', this.handleRemoveExceptions_); + $('addHost').addEventListener('click', this.handleAddException_); + $('directProxy').addEventListener('click', this.disableManual_); + $('manualProxy').addEventListener('click', this.enableManual_); + $('autoProxy').addEventListener('click', this.disableManual_); + $('proxyAllProtocols').addEventListener('click', this.toggleSingle_); + }, + + proxyListInitalized_: false, + + /** + * Handler for OptionsPage's visible property change event. + * @private + * @param {Event} e Property change event. + */ + handleVisibleChange_: function(e) { + this.toggleSingle_(); + if ($('manualProxy').checked) { + this.enableManual_(); + } else { + this.disableManual_(); + } + if (!this.proxyListInitalized_ && this.visible) { + this.proxyListInitalized_ = true; + $('ignoredHostList').redraw(); + } + }, + + /** + * Handler for when the user clicks on the checkbox to allow a + * single proxy usage. + * @private + * @param {Event} e Click Event. + */ + toggleSingle_: function(e) { + if($('proxyAllProtocols').value) { + $('multiProxy').style.display = 'none'; + $('singleProxy').style.display = 'block'; + } else { + $('multiProxy').style.display = 'block'; + $('singleProxy').style.display = 'none'; + } + }, + + /** + * Handler for selecting a radio button that will disable the manual + * controls. + * @private + * @param {Event} e Click event. + */ + disableManual_: function(e) { + $('proxyHostName').disabled = true; + $('proxyHostPort').disabled = true; + $('proxyHostSingleName').disabled = true; + $('proxyHostSinglePort').disabled = true; + $('secureProxyHostName').disabled = true; + $('secureProxyPort').disabled = true; + $('ftpProxy').disabled = true; + $('ftpProxyPort').disabled = true; + $('socksHost').disabled = true; + $('socksPort').disabled = true; + $('newHost').disabled = true; + $('removeHost').disabled = true; + $('addHost').disabled = true; + $('advancedConfig').style.display = 'none'; + }, + + /** + * Handler for selecting a radio button that will enable the manual + * controls. + * @private + * @param {Event} e Click event. + */ + enableManual_: function(e) { + $('proxyHostName').disabled = false; + $('proxyHostPort').disabled = false; + $('proxyHostSingleName').disabled = false; + $('proxyHostSinglePort').disabled = false; + $('secureProxyHostName').disabled = false; + $('secureProxyPort').disabled = false; + $('ftpProxy').disabled = false; + $('ftpProxyPort').disabled = false; + $('socksHost').disabled = false; + $('socksPort').disabled = false; + $('newHost').disabled = false; + $('removeHost').disabled = false; + $('addHost').disabled = false; + $('advancedConfig').style.display = '-webkit-box'; + }, + + /** + * Handler for "add" event fired from userNameEdit. + * @private + * @param {Event} e Add event fired from userNameEdit. + */ + handleAddException_: function(e) { + var exception = $('newHost').value; + $('newHost').value = ''; + $('ignoredHostList').addException(exception); + }, + + /** + * Handler for when the remove button is clicked + * @private + */ + handleRemoveExceptions_: function(e) { + var selectedItems = $('ignoredHostList').selectedItems; + for (var x = 0; x < selectedItems.length; x++) { + $('ignoredHostList').removeException(selectedItems[x]); + } + } + }; + + // Export + return { + ProxyOptions: ProxyOptions + }; + +}); diff --git a/chrome/browser/resources/options/chromeos_proxy_rules_list.js b/chrome/browser/resources/options/chromeos_proxy_rules_list.js new file mode 100644 index 0000000..feef79d --- /dev/null +++ b/chrome/browser/resources/options/chromeos_proxy_rules_list.js @@ -0,0 +1,140 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +cr.define('options.proxyexceptions', function() { + const List = cr.ui.List; + const ListItem = cr.ui.ListItem; + const ArrayDataModel = cr.ui.ArrayDataModel; + + /** + * Creates a new exception list. + * @param {Object=} opt_propertyBag Optional properties. + * @constructor + * @extends {cr.ui.List} + */ + var ProxyExceptions = cr.ui.define('list'); + + ProxyExceptions.prototype = { + __proto__: List.prototype, + + pref: 'cros.proxy.ignorelist', + + /** @inheritDoc */ + decorate: function() { + List.prototype.decorate.call(this); + + // HACK(arv): http://crbug.com/40902 + window.addEventListener('resize', cr.bind(this.redraw, this)); + + this.addEventListener('click', this.handleClick_); + + var self = this; + + // Listens to pref changes. + Preferences.getInstance().addEventListener(this.pref, + function(event) { + self.load_(event.value); + }); + }, + + createItem: function(exception) { + return new ProxyExceptionsItem(exception); + }, + + /** + * Adds given exception to model and update backend. + * @param {Object} exception A exception to be added to exception list. + */ + addException: function(exception) { + this.dataModel.push(exception); + this.updateBackend_(); + }, + + /** + * Removes given exception from model and update backend. + */ + removeException: function(exception) { + var dataModel = this.dataModel; + + var index = dataModel.indexOf(exception); + if (index >= 0) { + dataModel.splice(index, 1); + this.updateBackend_(); + } + }, + + /** + * Handles the clicks on the list and triggers exception removal if the + * click is on the remove exception button. + * @private + * @param {!Event} e The click event object. + */ + handleClick_: function(e) { + // Handle left button click + if (e.button == 0) { + var el = e.target; + if (el.className == 'remove-exception-button') { + this.removeException(el.parentNode.exception); + } + } + }, + + /** + * Loads given exception list. + * @param {Array} exceptions An array of exception object. + */ + load_: function(exceptions) { + this.dataModel = new ArrayDataModel(exceptions); + }, + + /** + * Updates backend. + */ + updateBackend_: function() { + Preferences.setObjectPref(this.pref, this.dataModel.slice()); + } + }; + + /** + * Creates a new exception list item. + * @param exception The exception account this represents. + * @constructor + * @extends {cr.ui.ListItem} + */ + function ProxyExceptionsItem(exception) { + var el = cr.doc.createElement('div'); + el.exception = exception; + ProxyExceptionsItem.decorate(el); + return el; + } + + /** + * Decorates an element as a exception account item. + * @param {!HTMLElement} el The element to decorate. + */ + ProxyExceptionsItem.decorate = function(el) { + el.__proto__ = ProxyExceptionsItem.prototype; + el.decorate(); + }; + + ProxyExceptionsItem.prototype = { + __proto__: ListItem.prototype, + + /** @inheritDoc */ + decorate: function() { + ListItem.prototype.decorate.call(this); + console.log('in exceptions decorate'); + this.className = 'exception-list-item'; + + var labelException = this.ownerDocument.createElement('span'); + labelException.className = ''; + labelException.textContent = this.exception; + this.appendChild(labelException); + } + }; + + return { + ProxyExceptions: ProxyExceptions + }; +}); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 0967503..5aa9251 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -379,6 +379,8 @@ 'browser/chromeos/cros_settings_names.cc', 'browser/chromeos/cros_settings_names.h', 'browser/chromeos/cros_settings_provider.h', + 'browser/chromeos/cros_settings_provider_proxy.cc', + 'browser/chromeos/cros_settings_provider_proxy.h', 'browser/chromeos/cros_settings_provider_user.cc', 'browser/chromeos/cros_settings_provider_user.h', 'browser/chromeos/cros/burn_library.cc', |