| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 14 #include "chrome/browser/extensions/extensions_service.h" | 14 #include "chrome/browser/extensions/extensions_service.h" |
| 15 #include "chrome/browser/extensions/user_script_master.h" | 15 #include "chrome/browser/extensions/user_script_master.h" |
| 16 #include "chrome/browser/io_thread.h" | 16 #include "chrome/browser/io_thread.h" |
| 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 18 #include "chrome/browser/net/chrome_net_log.h" | 18 #include "chrome/browser/net/chrome_net_log.h" |
| 19 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 19 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 20 #include "chrome/browser/net/predictor_api.h" | 20 #include "chrome/browser/net/predictor_api.h" |
| 21 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 21 #include "chrome/browser/profile.h" | 22 #include "chrome/browser/profile.h" |
| 22 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 #include "net/base/static_cookie_policy.h" | 29 #include "net/base/static_cookie_policy.h" |
| 29 #include "net/ftp/ftp_network_layer.h" | 30 #include "net/ftp/ftp_network_layer.h" |
| 30 #include "net/http/http_cache.h" | 31 #include "net/http/http_cache.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 61 | 62 |
| 62 // ---------------------------------------------------------------------------- | 63 // ---------------------------------------------------------------------------- |
| 63 // Helper methods to initialize proxy | 64 // Helper methods to initialize proxy |
| 64 // ---------------------------------------------------------------------------- | 65 // ---------------------------------------------------------------------------- |
| 65 | 66 |
| 66 net::ProxyConfigService* CreateProxyConfigService(Profile* profile) { | 67 net::ProxyConfigService* CreateProxyConfigService(Profile* profile) { |
| 67 // The linux gconf-based proxy settings getter relies on being initialized | 68 // The linux gconf-based proxy settings getter relies on being initialized |
| 68 // from the UI thread. | 69 // from the UI thread. |
| 69 CheckCurrentlyOnMainThread(); | 70 CheckCurrentlyOnMainThread(); |
| 70 | 71 |
| 71 scoped_ptr<net::ProxyConfig> proxy_config(CreateProxyConfig( | 72 // Create a baseline service that provides proxy configuration in case nothing |
| 72 profile->GetPrefs())); | 73 // is configured through prefs (Note: prefs include command line and |
| 74 // configuration policy). |
| 75 net::ProxyConfigService* base_service = NULL; |
| 73 | 76 |
| 74 if (!proxy_config.get()) { | 77 // TODO(port): the IO and FILE message loops are only used by Linux. Can |
| 75 // Use system settings. | 78 // that code be moved to chrome/browser instead of being in net, so that it |
| 76 // TODO(port): the IO and FILE message loops are only used by Linux. Can | 79 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. |
| 77 // that code be moved to chrome/browser instead of being in net, so that it | |
| 78 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. | |
| 79 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) |
| 80 return new chromeos::ProxyConfigService( | 81 base_service = new chromeos::ProxyConfigService( |
| 81 profile->GetChromeOSProxyConfigServiceImpl()); | 82 profile->GetChromeOSProxyConfigServiceImpl()); |
| 82 #else | 83 #else |
| 83 return net::ProxyService::CreateSystemProxyConfigService( | 84 base_service = net::ProxyService::CreateSystemProxyConfigService( |
| 84 g_browser_process->io_thread()->message_loop(), | 85 g_browser_process->io_thread()->message_loop(), |
| 85 g_browser_process->file_thread()->message_loop()); | 86 g_browser_process->file_thread()->message_loop()); |
| 86 #endif // defined(OS_CHROMEOS) | 87 #endif // defined(OS_CHROMEOS) |
| 87 } | |
| 88 | 88 |
| 89 // Otherwise use the fixed settings from the command line. | 89 return new PrefProxyConfigService(profile->GetProxyConfigTracker(), |
| 90 return new net::ProxyConfigServiceFixed(*proxy_config.get()); | 90 base_service); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Create a proxy service according to the options on command line. | 93 // Create a proxy service according to the options on command line. |
| 94 net::ProxyService* CreateProxyService( | 94 net::ProxyService* CreateProxyService( |
| 95 net::NetLog* net_log, | 95 net::NetLog* net_log, |
| 96 URLRequestContext* context, | 96 URLRequestContext* context, |
| 97 net::ProxyConfigService* proxy_config_service, | 97 net::ProxyConfigService* proxy_config_service, |
| 98 const CommandLine& command_line, | 98 const CommandLine& command_line, |
| 99 IOThread* io_thread) { | 99 IOThread* io_thread) { |
| 100 CheckCurrentlyOnIOThread(); | 100 CheckCurrentlyOnIOThread(); |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 context->set_host_zoom_map(host_zoom_map_); | 975 context->set_host_zoom_map(host_zoom_map_); |
| 976 context->set_transport_security_state( | 976 context->set_transport_security_state( |
| 977 transport_security_state_); | 977 transport_security_state_); |
| 978 context->set_ssl_config_service(ssl_config_service_); | 978 context->set_ssl_config_service(ssl_config_service_); |
| 979 context->set_appcache_service(appcache_service_); | 979 context->set_appcache_service(appcache_service_); |
| 980 context->set_database_tracker(database_tracker_); | 980 context->set_database_tracker(database_tracker_); |
| 981 context->set_blob_storage_context(blob_storage_context_); | 981 context->set_blob_storage_context(blob_storage_context_); |
| 982 context->set_browser_file_system_context(browser_file_system_context_); | 982 context->set_browser_file_system_context(browser_file_system_context_); |
| 983 context->set_extension_info_map(extension_info_map_); | 983 context->set_extension_info_map(extension_info_map_); |
| 984 } | 984 } |
| 985 | |
| 986 // ---------------------------------------------------------------------------- | |
| 987 | |
| 988 net::ProxyConfig* CreateProxyConfig(const PrefService* pref_service) { | |
| 989 // Scan for all "enable" type proxy switches. | |
| 990 static const char* proxy_prefs[] = { | |
| 991 prefs::kProxyPacUrl, | |
| 992 prefs::kProxyServer, | |
| 993 prefs::kProxyBypassList, | |
| 994 prefs::kProxyAutoDetect | |
| 995 }; | |
| 996 | |
| 997 // Check whether the preference system holds a valid proxy configuration. Note | |
| 998 // that preferences coming from a lower-priority source than the user settings | |
| 999 // are ignored. That's because chrome treats the system settings as the | |
| 1000 // default values, which should apply if there's no explicit value forced by | |
| 1001 // policy or the user. | |
| 1002 bool found_enable_proxy_pref = false; | |
| 1003 for (size_t i = 0; i < arraysize(proxy_prefs); i++) { | |
| 1004 const PrefService::Preference* pref = | |
| 1005 pref_service->FindPreference(proxy_prefs[i]); | |
| 1006 DCHECK(pref); | |
| 1007 if (pref && (!pref->IsUserModifiable() || pref->HasUserSetting())) { | |
| 1008 found_enable_proxy_pref = true; | |
| 1009 break; | |
| 1010 } | |
| 1011 } | |
| 1012 | |
| 1013 if (!found_enable_proxy_pref && | |
| 1014 !pref_service->GetBoolean(prefs::kNoProxyServer)) { | |
| 1015 return NULL; | |
| 1016 } | |
| 1017 | |
| 1018 net::ProxyConfig* proxy_config = new net::ProxyConfig(); | |
| 1019 if (pref_service->GetBoolean(prefs::kNoProxyServer)) { | |
| 1020 // Ignore all the other proxy config preferences if the use of a proxy | |
| 1021 // has been explicitly disabled. | |
| 1022 return proxy_config; | |
| 1023 } | |
| 1024 | |
| 1025 if (pref_service->HasPrefPath(prefs::kProxyServer)) { | |
| 1026 std::string proxy_server = pref_service->GetString(prefs::kProxyServer); | |
| 1027 proxy_config->proxy_rules().ParseFromString(proxy_server); | |
| 1028 } | |
| 1029 | |
| 1030 if (pref_service->HasPrefPath(prefs::kProxyPacUrl)) { | |
| 1031 std::string proxy_pac = pref_service->GetString(prefs::kProxyPacUrl); | |
| 1032 proxy_config->set_pac_url(GURL(proxy_pac)); | |
| 1033 } | |
| 1034 | |
| 1035 proxy_config->set_auto_detect(pref_service->GetBoolean( | |
| 1036 prefs::kProxyAutoDetect)); | |
| 1037 | |
| 1038 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { | |
| 1039 std::string proxy_bypass = | |
| 1040 pref_service->GetString(prefs::kProxyBypassList); | |
| 1041 proxy_config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass); | |
| 1042 } | |
| 1043 | |
| 1044 return proxy_config; | |
| 1045 } | |
| OLD | NEW |