OLD | NEW |
1 // Copyright (c) 2011 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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 | 11 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 } | 280 } |
281 config_service->UISetProxyConfigBypassRules(bypass_rules); | 281 config_service->UISetProxyConfigBypassRules(bypass_rules); |
282 } | 282 } |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 bool GetProxyPrefValue(Profile* profile, | 286 bool GetProxyPrefValue(Profile* profile, |
287 const std::string& path, | 287 const std::string& path, |
288 base::Value** out_value) { | 288 base::Value** out_value) { |
289 bool found = false; | |
290 bool managed = false; | |
291 std::string controlled_by; | 289 std::string controlled_by; |
292 base::Value* data = NULL; | 290 base::Value* data = NULL; |
293 chromeos::ProxyConfigServiceImpl* config_service = | 291 chromeos::ProxyConfigServiceImpl* config_service = |
294 profile->GetProxyConfigTracker(); | 292 profile->GetProxyConfigTracker(); |
295 chromeos::ProxyConfigServiceImpl::ProxyConfig config; | 293 chromeos::ProxyConfigServiceImpl::ProxyConfig config; |
296 config_service->UIGetProxyConfig(&config); | 294 config_service->UIGetProxyConfig(&config); |
297 | 295 |
298 if (path == kProxyPacUrl) { | 296 if (path == kProxyPacUrl) { |
299 // Only show pacurl for pac-script mode. | 297 // Only show pacurl for pac-script mode. |
300 if (config.mode == | 298 if (config.mode == |
301 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && | 299 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && |
302 config.automatic_proxy.pac_url.is_valid()) { | 300 config.automatic_proxy.pac_url.is_valid()) { |
303 data = | 301 data = |
304 base::Value::CreateStringValue(config.automatic_proxy.pac_url.spec()); | 302 base::Value::CreateStringValue(config.automatic_proxy.pac_url.spec()); |
305 } | 303 } |
306 found = true; | |
307 } else if (path == kProxySingleHttp) { | 304 } else if (path == kProxySingleHttp) { |
308 data = CreateServerHostValue(config.single_proxy); | 305 data = CreateServerHostValue(config.single_proxy); |
309 found = true; | |
310 } else if (path == kProxySingleHttpPort) { | 306 } else if (path == kProxySingleHttpPort) { |
311 data = CreateServerPortValue(config.single_proxy); | 307 data = CreateServerPortValue(config.single_proxy); |
312 found = true; | |
313 } else if (path == kProxyHttpUrl) { | 308 } else if (path == kProxyHttpUrl) { |
314 data = CreateServerHostValue(config.http_proxy); | 309 data = CreateServerHostValue(config.http_proxy); |
315 found = true; | |
316 } else if (path == kProxyHttpsUrl) { | 310 } else if (path == kProxyHttpsUrl) { |
317 data = CreateServerHostValue(config.https_proxy); | 311 data = CreateServerHostValue(config.https_proxy); |
318 found = true; | |
319 } else if (path == kProxyType) { | 312 } else if (path == kProxyType) { |
320 if (config.mode == | 313 if (config.mode == |
321 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT || | 314 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT || |
322 config.mode == | 315 config.mode == |
323 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { | 316 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { |
324 data = base::Value::CreateIntegerValue(3); | 317 data = base::Value::CreateIntegerValue(3); |
325 } else if (config.mode == | 318 } else if (config.mode == |
326 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || | 319 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || |
327 config.mode == | 320 config.mode == |
328 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { | 321 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { |
329 data = base::Value::CreateIntegerValue(2); | 322 data = base::Value::CreateIntegerValue(2); |
330 } else { | 323 } else { |
331 data = base::Value::CreateIntegerValue(1); | 324 data = base::Value::CreateIntegerValue(1); |
332 } | 325 } |
333 switch (config.state) { | 326 switch (config.state) { |
334 case ProxyPrefs::CONFIG_POLICY: | 327 case ProxyPrefs::CONFIG_POLICY: |
335 controlled_by = "policyManagedPrefsBannerText"; | 328 controlled_by = "policyManagedPrefsBannerText"; |
336 break; | 329 break; |
337 case ProxyPrefs::CONFIG_EXTENSION: | 330 case ProxyPrefs::CONFIG_EXTENSION: |
338 controlled_by = "extensionManagedPrefsBannerText"; | 331 controlled_by = "extensionManagedPrefsBannerText"; |
339 break; | 332 break; |
340 case ProxyPrefs::CONFIG_OTHER_PRECEDE: | 333 case ProxyPrefs::CONFIG_OTHER_PRECEDE: |
341 controlled_by = "unmodifiablePrefsBannerText"; | 334 controlled_by = "unmodifiablePrefsBannerText"; |
342 break; | 335 break; |
343 default: | 336 default: |
344 if (!config.user_modifiable) | 337 if (!config.user_modifiable) |
345 controlled_by = "enableSharedProxiesBannerText"; | 338 controlled_by = "enableSharedProxiesBannerText"; |
346 break; | 339 break; |
347 } | 340 } |
348 found = true; | |
349 } else if (path == kProxySingle) { | 341 } else if (path == kProxySingle) { |
350 data = base::Value::CreateBooleanValue(config.mode == | 342 data = base::Value::CreateBooleanValue(config.mode == |
351 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); | 343 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); |
352 found = true; | |
353 } else if (path == kProxyFtpUrl) { | 344 } else if (path == kProxyFtpUrl) { |
354 data = CreateServerHostValue(config.ftp_proxy); | 345 data = CreateServerHostValue(config.ftp_proxy); |
355 found = true; | |
356 } else if (path == kProxySocks) { | 346 } else if (path == kProxySocks) { |
357 data = CreateServerHostValue(config.socks_proxy); | 347 data = CreateServerHostValue(config.socks_proxy); |
358 found = true; | |
359 } else if (path == kProxyHttpPort) { | 348 } else if (path == kProxyHttpPort) { |
360 data = CreateServerPortValue(config.http_proxy); | 349 data = CreateServerPortValue(config.http_proxy); |
361 found = true; | |
362 } else if (path == kProxyHttpsPort) { | 350 } else if (path == kProxyHttpsPort) { |
363 data = CreateServerPortValue(config.https_proxy); | 351 data = CreateServerPortValue(config.https_proxy); |
364 found = true; | |
365 } else if (path == kProxyFtpPort) { | 352 } else if (path == kProxyFtpPort) { |
366 data = CreateServerPortValue(config.ftp_proxy); | 353 data = CreateServerPortValue(config.ftp_proxy); |
367 found = true; | |
368 } else if (path == kProxySocksPort) { | 354 } else if (path == kProxySocksPort) { |
369 data = CreateServerPortValue(config.socks_proxy); | 355 data = CreateServerPortValue(config.socks_proxy); |
370 found = true; | |
371 } else if (path == kProxyIgnoreList) { | 356 } else if (path == kProxyIgnoreList) { |
372 ListValue* list = new ListValue(); | 357 ListValue* list = new ListValue(); |
373 net::ProxyBypassRules::RuleList bypass_rules = config.bypass_rules.rules(); | 358 net::ProxyBypassRules::RuleList bypass_rules = config.bypass_rules.rules(); |
374 for (size_t x = 0; x < bypass_rules.size(); x++) { | 359 for (size_t x = 0; x < bypass_rules.size(); x++) { |
375 list->Append(base::Value::CreateStringValue(bypass_rules[x]->ToString())); | 360 list->Append(base::Value::CreateStringValue(bypass_rules[x]->ToString())); |
376 } | 361 } |
377 *out_value = list; | 362 data = list; |
378 return true; | |
379 } | |
380 if (found) { | |
381 DictionaryValue* dict = new DictionaryValue; | |
382 if (!data) | |
383 data = base::Value::CreateStringValue(""); | |
384 dict->Set("value", data); | |
385 dict->SetBoolean("managed", managed); | |
386 if (path == kProxyType) { | |
387 dict->SetString("controlledBy", controlled_by); | |
388 dict->SetBoolean("disabled", !config.user_modifiable); | |
389 } | |
390 *out_value = dict; | |
391 return true; | |
392 } else { | 363 } else { |
393 *out_value = NULL; | 364 *out_value = NULL; |
394 return false; | 365 return false; |
395 } | 366 } |
| 367 |
| 368 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. |
| 369 DictionaryValue* dict = new DictionaryValue; |
| 370 if (!data) |
| 371 data = base::Value::CreateStringValue(""); |
| 372 dict->Set("value", data); |
| 373 if (path == kProxyType) { |
| 374 dict->SetString("controlledBy", controlled_by); |
| 375 dict->SetBoolean("disabled", !config.user_modifiable); |
| 376 } else { |
| 377 dict->SetBoolean("disabled", false); |
| 378 } |
| 379 *out_value = dict; |
| 380 return true; |
396 } | 381 } |
397 | 382 |
398 } // namespace proxy_cros_settings_parser | 383 } // namespace proxy_cros_settings_parser |
399 | 384 |
400 } // namespace chromeos | 385 } // namespace chromeos |
OLD | NEW |