| 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 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" | 5 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 9 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 10 #include "chrome/browser/chromeos/ui_proxy_config.h" |
| 11 #include "chrome/browser/chromeos/ui_proxy_config_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 11 | 13 |
| 12 namespace chromeos { | 14 namespace chromeos { |
| 13 | 15 |
| 14 // Common prefix of all proxy prefs. | 16 // Common prefix of all proxy prefs. |
| 15 const char kProxyPrefsPrefix[] = "cros.session.proxy"; | 17 const char kProxyPrefsPrefix[] = "cros.session.proxy"; |
| 16 | 18 |
| 17 // Names of proxy preferences. | 19 // Names of proxy preferences. |
| 18 const char kProxyPacUrl[] = "cros.session.proxy.pacurl"; | 20 const char kProxyPacUrl[] = "cros.session.proxy.pacurl"; |
| 19 const char kProxySingleHttp[] = "cros.session.proxy.singlehttp"; | 21 const char kProxySingleHttp[] = "cros.session.proxy.singlehttp"; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 kProxyIgnoreList, | 50 kProxyIgnoreList, |
| 49 kProxyUsePacUrl, | 51 kProxyUsePacUrl, |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 // We have to explicitly export this because the arraysize macro doesn't like | 54 // We have to explicitly export this because the arraysize macro doesn't like |
| 53 // extern arrays as their size is not known on compile time. | 55 // extern arrays as their size is not known on compile time. |
| 54 const size_t kProxySettingsCount = arraysize(kProxySettings); | 56 const size_t kProxySettingsCount = arraysize(kProxySettings); |
| 55 | 57 |
| 56 namespace { | 58 namespace { |
| 57 | 59 |
| 58 base::Value* CreateServerHostValue( | 60 base::Value* CreateServerHostValue(const UIProxyConfig::ManualProxy& proxy) { |
| 59 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) { | |
| 60 return proxy.server.is_valid() ? | 61 return proxy.server.is_valid() ? |
| 61 new base::StringValue(proxy.server.host_port_pair().host()) : | 62 new base::StringValue(proxy.server.host_port_pair().host()) : |
| 62 NULL; | 63 NULL; |
| 63 } | 64 } |
| 64 | 65 |
| 65 base::Value* CreateServerPortValue( | 66 base::Value* CreateServerPortValue(const UIProxyConfig::ManualProxy& proxy) { |
| 66 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) { | |
| 67 return proxy.server.is_valid() ? | 67 return proxy.server.is_valid() ? |
| 68 base::Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : | 68 base::Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : |
| 69 NULL; | 69 NULL; |
| 70 } | 70 } |
| 71 | 71 |
| 72 net::ProxyServer CreateProxyServer(std::string host, | 72 net::ProxyServer CreateProxyServer(std::string host, |
| 73 uint16 port, | 73 uint16 port, |
| 74 net::ProxyServer::Scheme scheme) { | 74 net::ProxyServer::Scheme scheme) { |
| 75 if (host.empty() && port == 0) | 75 if (host.empty() && port == 0) |
| 76 return net::ProxyServer(); | 76 return net::ProxyServer(); |
| 77 uint16 default_port = net::ProxyServer::GetDefaultPortForScheme(scheme); | 77 uint16 default_port = net::ProxyServer::GetDefaultPortForScheme(scheme); |
| 78 net::HostPortPair host_port_pair; | 78 net::HostPortPair host_port_pair; |
| 79 // Check if host is a valid URL or a string of valid format <server>::<port>. | 79 // Check if host is a valid URL or a string of valid format <server>::<port>. |
| 80 GURL url(host); | 80 GURL url(host); |
| 81 if (url.is_valid()) // See if host is URL. | 81 if (url.is_valid()) // See if host is URL. |
| 82 host_port_pair = net::HostPortPair::FromURL(url); | 82 host_port_pair = net::HostPortPair::FromURL(url); |
| 83 if (host_port_pair.host().empty()) // See if host is <server>::<port>. | 83 if (host_port_pair.host().empty()) // See if host is <server>::<port>. |
| 84 host_port_pair = net::HostPortPair::FromString(host); | 84 host_port_pair = net::HostPortPair::FromString(host); |
| 85 if (host_port_pair.host().empty()) // Host is not URL or <server>::<port>. | 85 if (host_port_pair.host().empty()) // Host is not URL or <server>::<port>. |
| 86 host_port_pair = net::HostPortPair(host, port); | 86 host_port_pair = net::HostPortPair(host, port); |
| 87 if (host_port_pair.port() == 0) // No port in host, use default. | 87 if (host_port_pair.port() == 0) // No port in host, use default. |
| 88 host_port_pair.set_port(default_port); | 88 host_port_pair.set_port(default_port); |
| 89 return net::ProxyServer(scheme, host_port_pair); | 89 return net::ProxyServer(scheme, host_port_pair); |
| 90 } | 90 } |
| 91 | 91 |
| 92 net::ProxyServer CreateProxyServerFromHost( | 92 net::ProxyServer CreateProxyServerFromHost( |
| 93 const std::string& host, | 93 const std::string& host, |
| 94 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, | 94 const UIProxyConfig::ManualProxy& proxy, |
| 95 net::ProxyServer::Scheme scheme) { | 95 net::ProxyServer::Scheme scheme) { |
| 96 uint16 port = 0; | 96 uint16 port = 0; |
| 97 if (proxy.server.is_valid()) | 97 if (proxy.server.is_valid()) |
| 98 port = proxy.server.host_port_pair().port(); | 98 port = proxy.server.host_port_pair().port(); |
| 99 return CreateProxyServer(host, port, scheme); | 99 return CreateProxyServer(host, port, scheme); |
| 100 } | 100 } |
| 101 | 101 |
| 102 net::ProxyServer CreateProxyServerFromPort( | 102 net::ProxyServer CreateProxyServerFromPort( |
| 103 uint16 port, | 103 uint16 port, |
| 104 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, | 104 const UIProxyConfig::ManualProxy& proxy, |
| 105 net::ProxyServer::Scheme scheme) { | 105 net::ProxyServer::Scheme scheme) { |
| 106 std::string host; | 106 std::string host; |
| 107 if (proxy.server.is_valid()) | 107 if (proxy.server.is_valid()) |
| 108 host = proxy.server.host_port_pair().host(); | 108 host = proxy.server.host_port_pair().host(); |
| 109 return CreateProxyServer(host, port, scheme); | 109 return CreateProxyServer(host, port, scheme); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 namespace proxy_cros_settings_parser { | 114 namespace proxy_cros_settings_parser { |
| 115 | 115 |
| 116 bool IsProxyPref(const std::string& path) { | 116 bool IsProxyPref(const std::string& path) { |
| 117 return StartsWithASCII(path, kProxyPrefsPrefix, true); | 117 return StartsWithASCII(path, kProxyPrefsPrefix, true); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SetProxyPrefValue(Profile* profile, | 120 void SetProxyPrefValue(Profile* profile, |
| 121 const std::string& path, | 121 const std::string& path, |
| 122 const base::Value* in_value) { | 122 const base::Value* in_value) { |
| 123 if (!in_value) { | 123 if (!in_value) { |
| 124 NOTREACHED(); | 124 NOTREACHED(); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 | 127 |
| 128 chromeos::ProxyConfigServiceImpl* config_service = | 128 UIProxyConfigService* config_service = |
| 129 profile->GetProxyConfigTracker(); | 129 &profile->GetProxyConfigTracker()->GetUIService(); |
| 130 // Retrieve proxy config. | 130 // Retrieve proxy config. |
| 131 chromeos::ProxyConfigServiceImpl::ProxyConfig config; | 131 UIProxyConfig config; |
| 132 config_service->UIGetProxyConfig(&config); | 132 config_service->GetProxyConfig(&config); |
| 133 | 133 |
| 134 if (path == kProxyPacUrl) { | 134 if (path == kProxyPacUrl) { |
| 135 std::string val; | 135 std::string val; |
| 136 if (in_value->GetAsString(&val)) { | 136 if (in_value->GetAsString(&val)) { |
| 137 GURL url(val); | 137 GURL url(val); |
| 138 if (url.is_valid()) | 138 if (url.is_valid()) |
| 139 config_service->UISetProxyConfigToPACScript(url); | 139 config.SetPacUrl(url); |
| 140 else | 140 else |
| 141 config_service->UISetProxyConfigToAutoDetect(); | 141 config.mode = UIProxyConfig::MODE_AUTO_DETECT; |
| 142 } | 142 } |
| 143 } else if (path == kProxySingleHttp) { | 143 } else if (path == kProxySingleHttp) { |
| 144 std::string val; | 144 std::string val; |
| 145 if (in_value->GetAsString(&val)) { | 145 if (in_value->GetAsString(&val)) { |
| 146 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromHost( | 146 config.SetSingleProxy(CreateProxyServerFromHost( |
| 147 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); | 147 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 148 } | 148 } |
| 149 } else if (path == kProxySingleHttpPort) { | 149 } else if (path == kProxySingleHttpPort) { |
| 150 int val; | 150 int val; |
| 151 if (in_value->GetAsInteger(&val)) { | 151 if (in_value->GetAsInteger(&val)) { |
| 152 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromPort( | 152 config.SetSingleProxy(CreateProxyServerFromPort( |
| 153 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); | 153 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 154 } | 154 } |
| 155 } else if (path == kProxyHttpUrl) { | 155 } else if (path == kProxyHttpUrl) { |
| 156 std::string val; | 156 std::string val; |
| 157 if (in_value->GetAsString(&val)) { | 157 if (in_value->GetAsString(&val)) { |
| 158 config_service->UISetProxyConfigToProxyPerScheme("http", | 158 config.SetProxyForScheme( |
| 159 CreateProxyServerFromHost( | 159 "http", CreateProxyServerFromHost( |
| 160 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); | 160 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 161 } | 161 } |
| 162 } else if (path == kProxyHttpPort) { | 162 } else if (path == kProxyHttpPort) { |
| 163 int val; | 163 int val; |
| 164 if (in_value->GetAsInteger(&val)) { | 164 if (in_value->GetAsInteger(&val)) { |
| 165 config_service->UISetProxyConfigToProxyPerScheme("http", | 165 config.SetProxyForScheme( |
| 166 CreateProxyServerFromPort( | 166 "http", CreateProxyServerFromPort( |
| 167 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); | 167 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 168 } | 168 } |
| 169 } else if (path == kProxyHttpsUrl) { | 169 } else if (path == kProxyHttpsUrl) { |
| 170 std::string val; | 170 std::string val; |
| 171 if (in_value->GetAsString(&val)) { | 171 if (in_value->GetAsString(&val)) { |
| 172 config_service->UISetProxyConfigToProxyPerScheme("https", | 172 config.SetProxyForScheme( |
| 173 CreateProxyServerFromHost( | 173 "https", CreateProxyServerFromHost( |
| 174 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP)); | 174 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 175 } | 175 } |
| 176 } else if (path == kProxyHttpsPort) { | 176 } else if (path == kProxyHttpsPort) { |
| 177 int val; | 177 int val; |
| 178 if (in_value->GetAsInteger(&val)) { | 178 if (in_value->GetAsInteger(&val)) { |
| 179 config_service->UISetProxyConfigToProxyPerScheme("https", | 179 config.SetProxyForScheme( |
| 180 CreateProxyServerFromPort( | 180 "https", CreateProxyServerFromPort( |
| 181 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP)); | 181 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 182 } | 182 } |
| 183 } else if (path == kProxyType) { | 183 } else if (path == kProxyType) { |
| 184 int val; | 184 int val; |
| 185 if (in_value->GetAsInteger(&val)) { | 185 if (in_value->GetAsInteger(&val)) { |
| 186 if (val == 3) { | 186 if (val == 3) { |
| 187 if (config.automatic_proxy.pac_url.is_valid()) | 187 if (config.automatic_proxy.pac_url.is_valid()) |
| 188 config_service->UISetProxyConfigToPACScript( | 188 config.SetPacUrl(config.automatic_proxy.pac_url); |
| 189 config.automatic_proxy.pac_url); | |
| 190 else | 189 else |
| 191 config_service->UISetProxyConfigToAutoDetect(); | 190 config.mode = UIProxyConfig::MODE_AUTO_DETECT; |
| 192 } else if (val == 2) { | 191 } else if (val == 2) { |
| 193 if (config.single_proxy.server.is_valid()) { | 192 if (config.single_proxy.server.is_valid()) { |
| 194 config_service->UISetProxyConfigToSingleProxy( | 193 config.SetSingleProxy(config.single_proxy.server); |
| 195 config.single_proxy.server); | |
| 196 } else { | 194 } else { |
| 197 bool set_config = false; | 195 bool set_config = false; |
| 198 if (config.http_proxy.server.is_valid()) { | 196 if (config.http_proxy.server.is_valid()) { |
| 199 config_service->UISetProxyConfigToProxyPerScheme("http", | 197 config.SetProxyForScheme("http", config.http_proxy.server); |
| 200 config.http_proxy.server); | |
| 201 set_config = true; | 198 set_config = true; |
| 202 } | 199 } |
| 203 if (config.https_proxy.server.is_valid()) { | 200 if (config.https_proxy.server.is_valid()) { |
| 204 config_service->UISetProxyConfigToProxyPerScheme("https", | 201 config.SetProxyForScheme("https", config.https_proxy.server); |
| 205 config.https_proxy.server); | |
| 206 set_config = true; | 202 set_config = true; |
| 207 } | 203 } |
| 208 if (config.ftp_proxy.server.is_valid()) { | 204 if (config.ftp_proxy.server.is_valid()) { |
| 209 config_service->UISetProxyConfigToProxyPerScheme("ftp", | 205 config.SetProxyForScheme("ftp", config.ftp_proxy.server); |
| 210 config.ftp_proxy.server); | |
| 211 set_config = true; | 206 set_config = true; |
| 212 } | 207 } |
| 213 if (config.socks_proxy.server.is_valid()) { | 208 if (config.socks_proxy.server.is_valid()) { |
| 214 config_service->UISetProxyConfigToProxyPerScheme("socks", | 209 config.SetProxyForScheme("socks", config.socks_proxy.server); |
| 215 config.socks_proxy.server); | |
| 216 set_config = true; | 210 set_config = true; |
| 217 } | 211 } |
| 218 if (!set_config) { | 212 if (!set_config) |
| 219 config_service->UISetProxyConfigToProxyPerScheme("http", | 213 config.SetProxyForScheme("http", net::ProxyServer()); |
| 220 net::ProxyServer()); | |
| 221 } | |
| 222 } | 214 } |
| 223 } else { | 215 } else { |
| 224 config_service->UISetProxyConfigToDirect(); | 216 config.mode = UIProxyConfig::MODE_DIRECT; |
| 225 } | 217 } |
| 226 } | 218 } |
| 227 } else if (path == kProxySingle) { | 219 } else if (path == kProxySingle) { |
| 228 bool val; | 220 bool val; |
| 229 if (in_value->GetAsBoolean(&val)) { | 221 if (in_value->GetAsBoolean(&val)) { |
| 230 if (val) | 222 if (val) |
| 231 config_service->UISetProxyConfigToSingleProxy( | 223 config.SetSingleProxy(config.single_proxy.server); |
| 232 config.single_proxy.server); | |
| 233 else | 224 else |
| 234 config_service->UISetProxyConfigToProxyPerScheme("http", | 225 config.SetProxyForScheme("http", config.http_proxy.server); |
| 235 config.http_proxy.server); | |
| 236 } | 226 } |
| 237 } else if (path == kProxyUsePacUrl) { | 227 } else if (path == kProxyUsePacUrl) { |
| 238 bool use_pac_url; | 228 bool use_pac_url; |
| 239 if (in_value->GetAsBoolean(&use_pac_url)) { | 229 if (in_value->GetAsBoolean(&use_pac_url)) { |
| 240 if (use_pac_url && config.automatic_proxy.pac_url.is_valid()) { | 230 if (use_pac_url && config.automatic_proxy.pac_url.is_valid()) |
| 241 config_service->UISetProxyConfigToPACScript( | 231 config.SetPacUrl(config.automatic_proxy.pac_url); |
| 242 config.automatic_proxy.pac_url); | 232 else |
| 243 } else { | 233 config.mode = UIProxyConfig::MODE_AUTO_DETECT; |
| 244 config_service->UISetProxyConfigToAutoDetect(); | |
| 245 } | |
| 246 } | 234 } |
| 247 } else if (path == kProxyFtpUrl) { | 235 } else if (path == kProxyFtpUrl) { |
| 248 std::string val; | 236 std::string val; |
| 249 if (in_value->GetAsString(&val)) { | 237 if (in_value->GetAsString(&val)) { |
| 250 config_service->UISetProxyConfigToProxyPerScheme("ftp", | 238 config.SetProxyForScheme( |
| 251 CreateProxyServerFromHost( | 239 "ftp", CreateProxyServerFromHost( |
| 252 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); | 240 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 253 } | 241 } |
| 254 } else if (path == kProxyFtpPort) { | 242 } else if (path == kProxyFtpPort) { |
| 255 int val; | 243 int val; |
| 256 if (in_value->GetAsInteger(&val)) { | 244 if (in_value->GetAsInteger(&val)) { |
| 257 config_service->UISetProxyConfigToProxyPerScheme("ftp", | 245 config.SetProxyForScheme( |
| 258 CreateProxyServerFromPort( | 246 "ftp", CreateProxyServerFromPort( |
| 259 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); | 247 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); |
| 260 } | 248 } |
| 261 } else if (path == kProxySocks) { | 249 } else if (path == kProxySocks) { |
| 262 std::string val; | 250 std::string val; |
| 263 if (in_value->GetAsString(&val)) { | 251 if (in_value->GetAsString(&val)) { |
| 264 config_service->UISetProxyConfigToProxyPerScheme("socks", | 252 config.SetProxyForScheme( |
| 265 CreateProxyServerFromHost(val, config.socks_proxy, | 253 "socks", CreateProxyServerFromHost( |
| 266 StartsWithASCII(val, "socks5://", false) ? | 254 val, |
| 267 net::ProxyServer::SCHEME_SOCKS5 : | 255 config.socks_proxy, |
| 268 net::ProxyServer::SCHEME_SOCKS4)); | 256 StartsWithASCII(val, "socks5://", false) ? |
| 257 net::ProxyServer::SCHEME_SOCKS5 : |
| 258 net::ProxyServer::SCHEME_SOCKS4)); |
| 269 } | 259 } |
| 270 } else if (path == kProxySocksPort) { | 260 } else if (path == kProxySocksPort) { |
| 271 int val; | 261 int val; |
| 272 if (in_value->GetAsInteger(&val)) { | 262 if (in_value->GetAsInteger(&val)) { |
| 273 std::string host = config.socks_proxy.server.host_port_pair().host(); | 263 std::string host = config.socks_proxy.server.host_port_pair().host(); |
| 274 config_service->UISetProxyConfigToProxyPerScheme("socks", | 264 config.SetProxyForScheme( |
| 275 CreateProxyServerFromPort(val, config.socks_proxy, | 265 "socks", CreateProxyServerFromPort( |
| 276 StartsWithASCII(host, "socks5://", false) ? | 266 val, |
| 277 net::ProxyServer::SCHEME_SOCKS5 : | 267 config.socks_proxy, |
| 278 net::ProxyServer::SCHEME_SOCKS4)); | 268 StartsWithASCII(host, "socks5://", false) ? |
| 269 net::ProxyServer::SCHEME_SOCKS5 : |
| 270 net::ProxyServer::SCHEME_SOCKS4)); |
| 279 } | 271 } |
| 280 } else if (path == kProxyIgnoreList) { | 272 } else if (path == kProxyIgnoreList) { |
| 281 net::ProxyBypassRules bypass_rules; | 273 net::ProxyBypassRules bypass_rules; |
| 282 if (in_value->GetType() == base::Value::TYPE_LIST) { | 274 if (in_value->GetType() == base::Value::TYPE_LIST) { |
| 283 const ListValue* list_value = static_cast<const ListValue*>(in_value); | 275 const ListValue* list_value = static_cast<const ListValue*>(in_value); |
| 284 for (size_t x = 0; x < list_value->GetSize(); x++) { | 276 for (size_t x = 0; x < list_value->GetSize(); x++) { |
| 285 std::string val; | 277 std::string val; |
| 286 if (list_value->GetString(x, &val)) { | 278 if (list_value->GetString(x, &val)) |
| 287 bypass_rules.AddRuleFromString(val); | 279 bypass_rules.AddRuleFromString(val); |
| 288 } | |
| 289 } | 280 } |
| 290 config_service->UISetProxyConfigBypassRules(bypass_rules); | 281 config.SetBypassRules(bypass_rules); |
| 291 } | 282 } |
| 283 } else { |
| 284 LOG(WARNING) << "Unknown proxy settings path " << path; |
| 285 return; |
| 292 } | 286 } |
| 287 |
| 288 config_service->SetProxyConfig(config); |
| 293 } | 289 } |
| 294 | 290 |
| 295 bool GetProxyPrefValue(Profile* profile, | 291 bool GetProxyPrefValue(Profile* profile, |
| 296 const std::string& path, | 292 const std::string& path, |
| 297 base::Value** out_value) { | 293 base::Value** out_value) { |
| 298 std::string controlled_by; | 294 std::string controlled_by; |
| 299 base::Value* data = NULL; | 295 base::Value* data = NULL; |
| 300 chromeos::ProxyConfigServiceImpl* config_service = | 296 UIProxyConfigService& config_service = |
| 301 profile->GetProxyConfigTracker(); | 297 profile->GetProxyConfigTracker()->GetUIService(); |
| 302 chromeos::ProxyConfigServiceImpl::ProxyConfig config; | 298 UIProxyConfig config; |
| 303 config_service->UIGetProxyConfig(&config); | 299 config_service.GetProxyConfig(&config); |
| 304 | 300 |
| 305 if (path == kProxyPacUrl) { | 301 if (path == kProxyPacUrl) { |
| 306 // Only show pacurl for pac-script mode. | 302 // Only show pacurl for pac-script mode. |
| 307 if (config.mode == | 303 if (config.mode == UIProxyConfig::MODE_PAC_SCRIPT && |
| 308 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && | |
| 309 config.automatic_proxy.pac_url.is_valid()) { | 304 config.automatic_proxy.pac_url.is_valid()) { |
| 310 data = new base::StringValue(config.automatic_proxy.pac_url.spec()); | 305 data = new base::StringValue(config.automatic_proxy.pac_url.spec()); |
| 311 } | 306 } |
| 312 } else if (path == kProxySingleHttp) { | 307 } else if (path == kProxySingleHttp) { |
| 313 data = CreateServerHostValue(config.single_proxy); | 308 data = CreateServerHostValue(config.single_proxy); |
| 314 } else if (path == kProxySingleHttpPort) { | 309 } else if (path == kProxySingleHttpPort) { |
| 315 data = CreateServerPortValue(config.single_proxy); | 310 data = CreateServerPortValue(config.single_proxy); |
| 316 } else if (path == kProxyHttpUrl) { | 311 } else if (path == kProxyHttpUrl) { |
| 317 data = CreateServerHostValue(config.http_proxy); | 312 data = CreateServerHostValue(config.http_proxy); |
| 318 } else if (path == kProxyHttpsUrl) { | 313 } else if (path == kProxyHttpsUrl) { |
| 319 data = CreateServerHostValue(config.https_proxy); | 314 data = CreateServerHostValue(config.https_proxy); |
| 320 } else if (path == kProxyType) { | 315 } else if (path == kProxyType) { |
| 321 if (config.mode == | 316 if (config.mode == UIProxyConfig::MODE_AUTO_DETECT || |
| 322 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT || | 317 config.mode == UIProxyConfig::MODE_PAC_SCRIPT) { |
| 323 config.mode == | |
| 324 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { | |
| 325 data = base::Value::CreateIntegerValue(3); | 318 data = base::Value::CreateIntegerValue(3); |
| 326 } else if (config.mode == | 319 } else if (config.mode == UIProxyConfig::MODE_SINGLE_PROXY || |
| 327 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || | 320 config.mode == UIProxyConfig::MODE_PROXY_PER_SCHEME) { |
| 328 config.mode == | |
| 329 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { | |
| 330 data = base::Value::CreateIntegerValue(2); | 321 data = base::Value::CreateIntegerValue(2); |
| 331 } else { | 322 } else { |
| 332 data = base::Value::CreateIntegerValue(1); | 323 data = base::Value::CreateIntegerValue(1); |
| 333 } | 324 } |
| 334 switch (config.state) { | 325 switch (config.state) { |
| 335 case ProxyPrefs::CONFIG_POLICY: | 326 case ProxyPrefs::CONFIG_POLICY: |
| 336 controlled_by = "policy"; | 327 controlled_by = "policy"; |
| 337 break; | 328 break; |
| 338 case ProxyPrefs::CONFIG_EXTENSION: | 329 case ProxyPrefs::CONFIG_EXTENSION: |
| 339 controlled_by = "extension"; | 330 controlled_by = "extension"; |
| 340 break; | 331 break; |
| 341 case ProxyPrefs::CONFIG_OTHER_PRECEDE: | 332 case ProxyPrefs::CONFIG_OTHER_PRECEDE: |
| 342 controlled_by = "other"; | 333 controlled_by = "other"; |
| 343 break; | 334 break; |
| 344 default: | 335 default: |
| 345 if (!config.user_modifiable) | 336 if (!config.user_modifiable) |
| 346 controlled_by = "shared"; | 337 controlled_by = "shared"; |
| 347 break; | 338 break; |
| 348 } | 339 } |
| 349 } else if (path == kProxySingle) { | 340 } else if (path == kProxySingle) { |
| 350 data = base::Value::CreateBooleanValue(config.mode == | 341 data = base::Value::CreateBooleanValue( |
| 351 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); | 342 config.mode == UIProxyConfig::MODE_SINGLE_PROXY); |
| 352 } else if (path == kProxyUsePacUrl) { | 343 } else if (path == kProxyUsePacUrl) { |
| 353 data = base::Value::CreateBooleanValue(config.mode == | 344 data = base::Value::CreateBooleanValue( |
| 354 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT); | 345 config.mode == UIProxyConfig::MODE_PAC_SCRIPT); |
| 355 } else if (path == kProxyFtpUrl) { | 346 } else if (path == kProxyFtpUrl) { |
| 356 data = CreateServerHostValue(config.ftp_proxy); | 347 data = CreateServerHostValue(config.ftp_proxy); |
| 357 } else if (path == kProxySocks) { | 348 } else if (path == kProxySocks) { |
| 358 data = CreateServerHostValue(config.socks_proxy); | 349 data = CreateServerHostValue(config.socks_proxy); |
| 359 } else if (path == kProxyHttpPort) { | 350 } else if (path == kProxyHttpPort) { |
| 360 data = CreateServerPortValue(config.http_proxy); | 351 data = CreateServerPortValue(config.http_proxy); |
| 361 } else if (path == kProxyHttpsPort) { | 352 } else if (path == kProxyHttpsPort) { |
| 362 data = CreateServerPortValue(config.https_proxy); | 353 data = CreateServerPortValue(config.https_proxy); |
| 363 } else if (path == kProxyFtpPort) { | 354 } else if (path == kProxyFtpPort) { |
| 364 data = CreateServerPortValue(config.ftp_proxy); | 355 data = CreateServerPortValue(config.ftp_proxy); |
| 365 } else if (path == kProxySocksPort) { | 356 } else if (path == kProxySocksPort) { |
| 366 data = CreateServerPortValue(config.socks_proxy); | 357 data = CreateServerPortValue(config.socks_proxy); |
| 367 } else if (path == kProxyIgnoreList) { | 358 } else if (path == kProxyIgnoreList) { |
| 368 ListValue* list = new ListValue(); | 359 ListValue* list = new ListValue(); |
| 369 net::ProxyBypassRules::RuleList bypass_rules = config.bypass_rules.rules(); | 360 net::ProxyBypassRules::RuleList bypass_rules = config.bypass_rules.rules(); |
| 370 for (size_t x = 0; x < bypass_rules.size(); x++) { | 361 for (size_t x = 0; x < bypass_rules.size(); x++) |
| 371 list->Append(new base::StringValue(bypass_rules[x]->ToString())); | 362 list->Append(new base::StringValue(bypass_rules[x]->ToString())); |
| 372 } | |
| 373 data = list; | 363 data = list; |
| 374 } else { | 364 } else { |
| 375 *out_value = NULL; | 365 *out_value = NULL; |
| 376 return false; | 366 return false; |
| 377 } | 367 } |
| 378 | 368 |
| 379 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. | 369 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. |
| 380 DictionaryValue* dict = new DictionaryValue; | 370 DictionaryValue* dict = new DictionaryValue; |
| 381 if (!data) | 371 if (!data) |
| 382 data = new base::StringValue(""); | 372 data = new base::StringValue(""); |
| 383 dict->Set("value", data); | 373 dict->Set("value", data); |
| 384 if (path == kProxyType) { | 374 if (path == kProxyType) { |
| 385 dict->SetString("controlledBy", controlled_by); | 375 dict->SetString("controlledBy", controlled_by); |
| 386 dict->SetBoolean("disabled", !config.user_modifiable); | 376 dict->SetBoolean("disabled", !config.user_modifiable); |
| 387 } else { | 377 } else { |
| 388 dict->SetBoolean("disabled", false); | 378 dict->SetBoolean("disabled", false); |
| 389 } | 379 } |
| 390 *out_value = dict; | 380 *out_value = dict; |
| 391 return true; | 381 return true; |
| 392 } | 382 } |
| 393 | 383 |
| 394 } // namespace proxy_cros_settings_parser | 384 } // namespace proxy_cros_settings_parser |
| 395 | 385 |
| 396 } // namespace chromeos | 386 } // namespace chromeos |
| OLD | NEW |