diff options
author | danno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 11:32:54 +0000 |
---|---|---|
committer | danno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 11:32:54 +0000 |
commit | aa4dc5e2e6917e9f3848adef838755e728c647e7 (patch) | |
tree | bbb70f33ce42ed94c24d6d017d3685d23df2238b /chrome | |
parent | 2ab5be46a52588cc0bd69bdd89de693bbac96f92 (diff) | |
download | chromium_src-aa4dc5e2e6917e9f3848adef838755e728c647e7.zip chromium_src-aa4dc5e2e6917e9f3848adef838755e728c647e7.tar.gz chromium_src-aa4dc5e2e6917e9f3848adef838755e728c647e7.tar.bz2 |
Add policy code for proxy configuration
Augment ProxyConfig to fetch its configuration from preferences that are initialized by settings and policy (rather than getting its config directly from settings). Add policies for everything that is needed to configure a ProxyConfig and wire the policies up to the corresponding preferences.
Also remove CookieMode policy, it's harder to get right than we naively thought.
BUG=43458
TEST=ChromeUrlRequestContextTest*:ConfigurationPolicyPrefStoreTest*
Review URL: http://codereview.chromium.org/2459001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_prefs.cc | 2 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_pref_store.cc | 218 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_pref_store.h | 37 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_pref_store_unittest.cc | 261 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_provider.cc | 12 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_provider_mac_unittest.cc | 23 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_provider_win_unittest.cc | 40 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_store.h | 10 | ||||
-rw-r--r-- | chrome/browser/mock_configuration_policy_provider.h | 42 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 80 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 10 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/pref_service.cc | 5 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 14 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 6 |
17 files changed, 633 insertions, 140 deletions
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 4452643..816c50b 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -25,6 +25,7 @@ #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/metrics/metrics_service.h" +#include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/page_info_model.h" @@ -115,6 +116,7 @@ void RegisterUserPrefs(PrefService* user_prefs) { GeolocationContentSettingsMap::RegisterUserPrefs(user_prefs); TranslatePrefs::RegisterUserPrefs(user_prefs); DesktopNotificationService::RegisterUserPrefs(user_prefs); + ChromeURLRequestContextGetter::RegisterUserPrefs(user_prefs); #if defined(TOOLKIT_VIEWS) BrowserActionsContainer::RegisterUserPrefs(user_prefs); #elif defined(TOOLKIT_GTK) diff --git a/chrome/browser/configuration_policy_pref_store.cc b/chrome/browser/configuration_policy_pref_store.cc index c591e20..d2ada7c 100644 --- a/chrome/browser/configuration_policy_pref_store.cc +++ b/chrome/browser/configuration_policy_pref_store.cc @@ -4,13 +4,15 @@ #include "chrome/browser/configuration_policy_pref_store.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/values.h" #include "chrome/browser/configuration_policy_provider.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry -ConfigurationPolicyPrefStore::simple_policy_map_[] = { + ConfigurationPolicyPrefStore::simple_policy_map_[] = { { Value::TYPE_STRING, kPolicyHomePage, prefs::kHomePage }, { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, prefs::kHomePageIsNewTabPage }, @@ -24,31 +26,225 @@ ConfigurationPolicyPrefStore::simple_policy_map_[] = { prefs::kSafeBrowsingEnabled }, { Value::TYPE_BOOLEAN, kPolicyMetricsReportingEnabled, prefs::kMetricsReportingEnabled }, - { Value::TYPE_INTEGER, kPolicyCookiesMode, prefs::kCookieBehavior } +}; + +const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry + ConfigurationPolicyPrefStore::proxy_policy_map_[] = { + { Value::TYPE_STRING, kPolicyProxyServer, prefs::kProxyServer }, + { Value::TYPE_STRING, kPolicyProxyPacUrl, prefs::kProxyPacUrl }, + { Value::TYPE_STRING, kPolicyProxyBypassList, prefs::kProxyBypassList } }; ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( + const CommandLine* command_line, ConfigurationPolicyProvider* provider) - : provider_(provider), - prefs_(new DictionaryValue()) { + : command_line_(command_line), + provider_(provider), + prefs_(new DictionaryValue()), + command_line_proxy_settings_cleared_(false), + proxy_disabled_(false), + proxy_configuration_specified_(false), + use_system_proxy_(false) { +} + +void ConfigurationPolicyPrefStore::ApplyProxySwitches() { + bool proxy_disabled = command_line_->HasSwitch(switches::kNoProxyServer); + if (proxy_disabled) { + prefs_->Set(prefs::kNoProxyServer, Value::CreateBooleanValue(true)); + } + bool has_explicit_proxy_config = false; + if (command_line_->HasSwitch(switches::kProxyAutoDetect)) { + has_explicit_proxy_config = true; + prefs_->Set(prefs::kProxyAutoDetect, Value::CreateBooleanValue(true)); + } + if (command_line_->HasSwitch(switches::kProxyServer)) { + has_explicit_proxy_config = true; + prefs_->Set(prefs::kProxyServer, Value::CreateStringValue( + command_line_->GetSwitchValue(switches::kProxyServer))); + } + if (command_line_->HasSwitch(switches::kProxyPacUrl)) { + has_explicit_proxy_config = true; + prefs_->Set(prefs::kProxyPacUrl, Value::CreateStringValue( + command_line_->GetSwitchValue(switches::kProxyPacUrl))); + } + if (command_line_->HasSwitch(switches::kProxyBypassList)) { + has_explicit_proxy_config = true; + prefs_->Set(prefs::kProxyBypassList, Value::CreateStringValue( + command_line_->GetSwitchValue(switches::kProxyBypassList))); + } + + // Warn about all the other proxy config switches we get if + // the --no-proxy-server command-line argument is present. + if (proxy_disabled && has_explicit_proxy_config) { + LOG(WARNING) << "Additional command-line proxy switches specified when --" + << switches::kNoProxyServer << " was also specified."; + } } PrefStore::PrefReadError ConfigurationPolicyPrefStore::ReadPrefs() { - return provider_->Provide(this) ? PrefStore::PREF_READ_ERROR_NONE : - PrefStore::PREF_READ_ERROR_OTHER; + // Initialize proxy preference values from command-line switches. This is done + // before calling Provide to allow the provider to overwrite proxy-related + // preferences that are specified by line settings. + ApplyProxySwitches(); + + proxy_disabled_ = false; + proxy_configuration_specified_ = false; + command_line_proxy_settings_cleared_ = false; + + return (provider_.get() == NULL || provider_->Provide(this)) ? + PrefStore::PREF_READ_ERROR_NONE : PrefStore::PREF_READ_ERROR_OTHER; } -void ConfigurationPolicyPrefStore::Apply(PolicyType policy, Value* value) { - const PolicyToPreferenceMapEntry* end = - simple_policy_map_ + arraysize(simple_policy_map_); - for (const PolicyToPreferenceMapEntry* current = simple_policy_map_; +bool ConfigurationPolicyPrefStore::ApplyProxyPolicy(PolicyType policy, + Value* value) { + bool result = false; + bool warn_about_proxy_disable_config = false; + bool warn_about_proxy_system_config = false; + + const PolicyToPreferenceMapEntry* match_entry_ = NULL; + for (const PolicyToPreferenceMapEntry* current = proxy_policy_map_; + current != proxy_policy_map_ + arraysize(proxy_policy_map_); ++current) { + if (current->policy_type == policy) { + match_entry_ = current; + } + } + + // When the first proxy-related policy is applied, ALL proxy-related + // preferences that have been set by command-line switches must be + // removed. Otherwise it's possible for a user to interfere with proxy + // policy by using proxy-related switches that are related to, but not + // identical, to the ones set through policy. + if ((match_entry_ || + policy == ConfigurationPolicyPrefStore::kPolicyProxyServerMode) && + !command_line_proxy_settings_cleared_) { + for (const PolicyToPreferenceMapEntry* i = proxy_policy_map_; + i != proxy_policy_map_ + arraysize(proxy_policy_map_); ++i) { + if (prefs_->Get(i->preference_path, NULL)) { + LOG(WARNING) << "proxy configuration options were specified on the" + << " command-line but will be ignored because an" + << " explicit proxy configuration has been specified" + << " through a centrally-administered policy."; + break; + } + } + + // Now actually do the preference removal. + for (const PolicyToPreferenceMapEntry* current = proxy_policy_map_; + current != proxy_policy_map_ + arraysize(proxy_policy_map_); ++current) + prefs_->Remove(current->preference_path, NULL); + prefs_->Remove(prefs::kNoProxyServer, NULL); + prefs_->Remove(prefs::kProxyAutoDetect, NULL); + + command_line_proxy_settings_cleared_ = true; + } + + // Translate the proxy policy into preferences. + if (policy == ConfigurationPolicyStore::kPolicyProxyServerMode) { + int int_value; + bool proxy_auto_detect = false; + if (value->GetAsInteger(&int_value)) { + result = true; + switch (int_value) { + case ConfigurationPolicyStore::kPolicyNoProxyServerMode: + if (!proxy_disabled_) { + if (proxy_configuration_specified_) + warn_about_proxy_disable_config = true; + proxy_disabled_ = true; + } + break; + case ConfigurationPolicyStore::kPolicyAutoDetectProxyMode: + proxy_auto_detect = true; + break; + case ConfigurationPolicyStore::kPolicyManuallyConfiguredProxyMode: + break; + case ConfigurationPolicyStore::kPolicyUseSystemProxyMode: + if (!use_system_proxy_) { + if (proxy_configuration_specified_) + warn_about_proxy_system_config = true; + use_system_proxy_ = true; + } + break; + default: + // Not a valid policy, don't assume ownership of |value| + result = false; + break; + } + + if (int_value != kPolicyUseSystemProxyMode) { + prefs_->Set(prefs::kNoProxyServer, + Value::CreateBooleanValue(proxy_disabled_)); + prefs_->Set(prefs::kProxyAutoDetect, + Value::CreateBooleanValue(proxy_auto_detect)); + } + + // No proxy and system proxy mode should ensure that no other + // proxy preferences are set. + if (int_value == ConfigurationPolicyStore::kPolicyNoProxyServerMode || + int_value == kPolicyUseSystemProxyMode) { + for (const PolicyToPreferenceMapEntry* current = proxy_policy_map_; + current != proxy_policy_map_ + arraysize(proxy_policy_map_); + ++current) + prefs_->Remove(current->preference_path, NULL); + } + } + } else if (match_entry_) { + // Determine if the applied proxy policy settings conflict and issue + // a corresponding warning if they do. + if (!proxy_configuration_specified_) { + if (proxy_disabled_) + warn_about_proxy_disable_config = true; + if (use_system_proxy_) + warn_about_proxy_system_config = true; + proxy_configuration_specified_ = true; + } + if (!use_system_proxy_ && !proxy_disabled_) { + prefs_->Set(match_entry_->preference_path, value); + // The ownership of value has been passed on to |prefs_|, + // don't clean it up later. + value = NULL; + } + result = true; + } + + if (warn_about_proxy_disable_config) { + LOG(WARNING) << "A centrally-administered policy disables the use of" + << " a proxy but also specifies an explicit proxy" + << " configuration."; + } + + if (warn_about_proxy_system_config) { + LOG(WARNING) << "A centrally-administered policy dictates that the" + << " system proxy settings should be used but also specifies" + << " an explicit proxy configuration."; + } + + // If the policy was a proxy policy, cleanup |value|. + if (result && value) + delete value; + return result; +} + +bool ConfigurationPolicyPrefStore::ApplyPolicyFromMap(PolicyType policy, + Value* value, const PolicyToPreferenceMapEntry map[], int size) { + const PolicyToPreferenceMapEntry* end = map + size; + for (const PolicyToPreferenceMapEntry* current = map; current != end; ++current) { if (current->policy_type == policy) { DCHECK(current->value_type == value->GetType()); prefs_->Set(current->preference_path, value); - return; + return true; } } + return false; +} + +void ConfigurationPolicyPrefStore::Apply(PolicyType policy, Value* value) { + if (ApplyProxyPolicy(policy, value)) + return; + + if (ApplyPolicyFromMap(policy, value, simple_policy_map_, + arraysize(simple_policy_map_))) + return; // Other policy implementations go here. NOTIMPLEMENTED(); diff --git a/chrome/browser/configuration_policy_pref_store.h b/chrome/browser/configuration_policy_pref_store.h index ef08eb6..b87f42176 100644 --- a/chrome/browser/configuration_policy_pref_store.h +++ b/chrome/browser/configuration_policy_pref_store.h @@ -15,6 +15,8 @@ #include "chrome/browser/configuration_policy_store.h" #include "chrome/common/pref_store.h" +class CommandLine; + // An implementation of the |PrefStore| that holds a Dictionary // created through applied policy. class ConfigurationPolicyPrefStore : public PrefStore, @@ -22,7 +24,8 @@ class ConfigurationPolicyPrefStore : public PrefStore, public: // The ConfigurationPolicyPrefStore takes the ownership of the passed // |provider|. - explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider); + ConfigurationPolicyPrefStore(const CommandLine* command_line, + ConfigurationPolicyProvider* provider); virtual ~ConfigurationPolicyPrefStore() { } // PrefStore methods: @@ -43,13 +46,45 @@ class ConfigurationPolicyPrefStore : public PrefStore, }; static const PolicyToPreferenceMapEntry simple_policy_map_[]; + static const PolicyToPreferenceMapEntry proxy_policy_map_[]; + const CommandLine* command_line_; scoped_ptr<ConfigurationPolicyProvider> provider_; scoped_ptr<DictionaryValue> prefs_; + // Set to false until the first proxy-relevant policy is applied. Allows + // the Apply method to erase all switch-specified proxy configuration before + // applying proxy policy configuration; + bool command_line_proxy_settings_cleared_; + + // The following are used to track what proxy-relevant policy has been applied + // accross calls to Apply to provide a warning if a policy specifies a + // contradictory proxy configuration. |proxy_disabled_| is set to true if and + // only if the kPolicyNoProxyServer has been applied, + // |proxy_configuration_specified_| is set to true if and only if any other + // proxy policy other than kPolicyNoProxyServer has been applied. + bool proxy_disabled_; + bool proxy_configuration_specified_; + + // Set to true if a the proxy mode policy has been set to force Chrome + // to use the system proxy. + bool use_system_proxy_; + // ConfigurationPolicyStore methods: virtual void Apply(PolicyType setting, Value* value); + // Initializes default preference values from proxy-related command-line + // switches in |command_line_|. + void ApplyProxySwitches(); + + bool ApplyPolicyFromMap(PolicyType policy, Value* value, + const PolicyToPreferenceMapEntry map[], int size); + + // Processes proxy-specific policies. Returns true if the specified policy + // is a proxy-related policy. ApplyProxyPolicy assumes the ownership + // of |value| in the case that the policy is proxy-specific. + bool ApplyProxyPolicy(PolicyType policy, Value* value); + DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); }; diff --git a/chrome/browser/configuration_policy_pref_store_unittest.cc b/chrome/browser/configuration_policy_pref_store_unittest.cc index 98fe48a..2311970 100644 --- a/chrome/browser/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/configuration_policy_pref_store_unittest.cc @@ -4,8 +4,11 @@ #include <gtest/gtest.h> +#include "base/command_line.h" #include "chrome/browser/configuration_policy_pref_store.h" +#include "chrome/browser/mock_configuration_policy_provider.h" #include "chrome/common/pref_names.h" +#include "chrome/common/chrome_switches.h" class ConfigurationPolicyPrefStoreTest : public testing::Test { public: @@ -45,7 +48,7 @@ class ConfigurationPolicyPrefStoreTest : public testing::Test { void ConfigurationPolicyPrefStoreTest::TestStringPolicyGetDefault( const wchar_t* pref_name) { - ConfigurationPolicyPrefStore store(0); + ConfigurationPolicyPrefStore store(NULL, NULL); std::wstring result; store.prefs()->GetString(pref_name, &result); EXPECT_EQ(result, L""); @@ -53,7 +56,7 @@ void ConfigurationPolicyPrefStoreTest::TestStringPolicyGetDefault( void ConfigurationPolicyPrefStoreTest::TestStringPolicySetValue( const wchar_t* pref_name, ConfigurationPolicyStore::PolicyType type) { - ConfigurationPolicyPrefStore store(0); + ConfigurationPolicyPrefStore store(NULL, NULL); store.Apply(type, Value::CreateStringValue("http://chromium.org")); std::wstring result; store.prefs()->GetString(pref_name, &result); @@ -68,7 +71,7 @@ void ConfigurationPolicyPrefStoreTest::TestStringPolicy( void ConfigurationPolicyPrefStoreTest::TestBooleanPolicyGetDefault( const wchar_t* pref_name) { - ConfigurationPolicyPrefStore store(0); + ConfigurationPolicyPrefStore store(NULL, NULL); bool result = false; store.prefs()->GetBoolean(pref_name, &result); EXPECT_FALSE(result); @@ -79,7 +82,7 @@ void ConfigurationPolicyPrefStoreTest::TestBooleanPolicyGetDefault( void ConfigurationPolicyPrefStoreTest::TestBooleanPolicySetValue( const wchar_t* pref_name, ConfigurationPolicyStore::PolicyType type) { - ConfigurationPolicyPrefStore store(0); + ConfigurationPolicyPrefStore store(NULL, NULL); store.Apply(type, Value::CreateBooleanValue(false)); bool result = true; store.prefs()->GetBoolean(pref_name, &result); @@ -99,7 +102,7 @@ void ConfigurationPolicyPrefStoreTest::TestBooleanPolicy( void ConfigurationPolicyPrefStoreTest::TestIntegerPolicyGetDefault( const wchar_t* pref_name) { - ConfigurationPolicyPrefStore store(0); + ConfigurationPolicyPrefStore store(NULL, NULL); int result = 0; store.prefs()->GetInteger(pref_name, &result); EXPECT_EQ(result, 0); @@ -107,7 +110,7 @@ void ConfigurationPolicyPrefStoreTest::TestIntegerPolicyGetDefault( void ConfigurationPolicyPrefStoreTest::TestIntegerPolicySetValue( const wchar_t* pref_name, ConfigurationPolicyStore::PolicyType type) { - ConfigurationPolicyPrefStore store(0); + ConfigurationPolicyPrefStore store(NULL, NULL); store.Apply(type, Value::CreateIntegerValue(2)); int result = 0; store.prefs()->GetInteger(pref_name, &result); @@ -122,7 +125,7 @@ void ConfigurationPolicyPrefStoreTest::TestIntegerPolicy( TEST_F(ConfigurationPolicyPrefStoreTest, TestSettingHomePageDefault) { TestStringPolicy(prefs::kHomePage, - ConfigurationPolicyPrefStore::kPolicyHomePage); + ConfigurationPolicyPrefStore::kPolicyHomePage); } TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyHomepageIsNewTabPage) { @@ -132,31 +135,259 @@ TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyHomepageIsNewTabPage) { TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyAlternateErrorPagesEnabled) { TestBooleanPolicy(prefs::kAlternateErrorPagesEnabled, - ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled); + ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled); } TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicySearchSuggestEnabled) { TestBooleanPolicy(prefs::kSearchSuggestEnabled, - ConfigurationPolicyStore::kPolicySearchSuggestEnabled); + ConfigurationPolicyStore::kPolicySearchSuggestEnabled); } TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyDnsPrefetchingEnabled) { TestBooleanPolicy(prefs::kDnsPrefetchingEnabled, - ConfigurationPolicyStore::kPolicyDnsPrefetchingEnabled); + ConfigurationPolicyStore::kPolicyDnsPrefetchingEnabled); } TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicySafeBrowsingEnabled) { TestBooleanPolicy(prefs::kSafeBrowsingEnabled, - ConfigurationPolicyStore::kPolicySafeBrowsingEnabled); + ConfigurationPolicyStore::kPolicySafeBrowsingEnabled); } TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyMetricsReportingEnabled) { TestBooleanPolicy(prefs::kMetricsReportingEnabled, - ConfigurationPolicyStore::kPolicyMetricsReportingEnabled); + ConfigurationPolicyStore::kPolicyMetricsReportingEnabled); } -TEST_F(ConfigurationPolicyPrefStoreTest, TestSettingCookiesEnabledDefault) { - TestIntegerPolicy(prefs::kCookieBehavior, - ConfigurationPolicyPrefStore::kPolicyCookiesMode); +TEST_F(ConfigurationPolicyPrefStoreTest, TestSettingProxyServer) { + TestStringPolicy(prefs::kProxyServer, + ConfigurationPolicyPrefStore::kPolicyProxyServer); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestSettingProxyPacUrl) { + TestStringPolicy(prefs::kProxyPacUrl, + ConfigurationPolicyPrefStore::kPolicyProxyPacUrl); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestSettingProxyBypassList) { + TestStringPolicy(prefs::kProxyBypassList, + ConfigurationPolicyPrefStore::kPolicyProxyBypassList); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestSettingsProxyConfig) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + command_line.AppendSwitch(switches::kNoProxyServer); + command_line.AppendSwitch(switches::kProxyAutoDetect); + command_line.AppendSwitchWithValue(switches::kProxyPacUrl, + L"http://chromium.org/test.pac"); + command_line.AppendSwitchWithValue(switches::kProxyServer, + L"http://chromium2.org"); + command_line.AppendSwitchWithValue(switches::kProxyBypassList, + L"http://chromium3.org"); + + ConfigurationPolicyPrefStore store(&command_line, NULL); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + // Ensure that all traces of the command-line specified proxy + // switches have been overriden. + std::wstring string_result; + EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + EXPECT_EQ(string_result, L"http://chromium3.org"); + + EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_EQ(string_result, L"http://chromium.org/test.pac"); + EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + EXPECT_EQ(string_result, L"http://chromium2.org"); + bool bool_result; + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_TRUE(bool_result); + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); + EXPECT_TRUE(bool_result); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyProxyConfigManualOverride) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + command_line.AppendSwitch(switches::kNoProxyServer); + command_line.AppendSwitch(switches::kProxyAutoDetect); + command_line.AppendSwitchWithValue(switches::kProxyPacUrl, + L"http://chromium.org/test.pac"); + command_line.AppendSwitchWithValue(switches::kProxyServer, + L"http://chromium.org"); + command_line.AppendSwitchWithValue(switches::kProxyBypassList, + L"http://chromium.org"); + + scoped_ptr<MockConfigurationPolicyProvider> provider( + new MockConfigurationPolicyProvider()); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::CreateIntegerValue( + ConfigurationPolicyStore::kPolicyManuallyConfiguredProxyMode)); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::CreateStringValue(L"http://chromium.org/override")); + + ConfigurationPolicyPrefStore store(&command_line, + provider.release()); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + // Ensure that all traces of the command-line specified proxy + // switches have been overriden. + std::wstring string_result; + EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + EXPECT_EQ(string_result, L"http://chromium.org/override"); + + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + bool bool_result; + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_FALSE(bool_result); + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); + EXPECT_FALSE(bool_result); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyProxyConfigNoProxy) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + scoped_ptr<MockConfigurationPolicyProvider> provider( + new MockConfigurationPolicyProvider()); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::CreateStringValue(L"http://chromium.org/override")); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::CreateIntegerValue( + ConfigurationPolicyStore::kPolicyNoProxyServerMode)); + + ConfigurationPolicyPrefStore store(&command_line, provider.release()); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + std::wstring string_result; + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + bool bool_result; + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_TRUE(bool_result); + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); + EXPECT_FALSE(bool_result); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, + TestPolicyProxyConfigNoProxyReversedApplyOrder) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + scoped_ptr<MockConfigurationPolicyProvider> provider( + new MockConfigurationPolicyProvider()); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::CreateIntegerValue( + ConfigurationPolicyStore::kPolicyNoProxyServerMode)); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::CreateStringValue(L"http://chromium.org/override")); + + ConfigurationPolicyPrefStore store(&command_line, provider.release()); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + std::wstring string_result; + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + bool bool_result; + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_TRUE(bool_result); + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); + EXPECT_FALSE(bool_result); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyProxyConfigAutoDetect) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + scoped_ptr<MockConfigurationPolicyProvider> provider( + new MockConfigurationPolicyProvider()); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::CreateStringValue(L"http://chromium.org/override")); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::CreateIntegerValue( + ConfigurationPolicyStore::kPolicyAutoDetectProxyMode)); + + ConfigurationPolicyPrefStore store(&command_line, provider.release()); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + // Ensure that all traces of the command-line specified proxy + // switches have been overriden. + std::wstring string_result; + EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + EXPECT_EQ(string_result, L"http://chromium.org/override"); + + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + bool bool_result; + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_FALSE(bool_result); + EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); + EXPECT_TRUE(bool_result); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, TestPolicyProxyConfiguseSystem) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + scoped_ptr<MockConfigurationPolicyProvider> provider( + new MockConfigurationPolicyProvider()); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::CreateStringValue(L"http://chromium.org/override")); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::CreateIntegerValue( + ConfigurationPolicyStore::kPolicyUseSystemProxyMode)); + + ConfigurationPolicyPrefStore store(&command_line, provider.release()); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + std::wstring string_result; + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + EXPECT_EQ(string_result, L""); + + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + bool bool_result; + EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); +} + +TEST_F(ConfigurationPolicyPrefStoreTest, + TestPolicyProxyConfiguseSystemReversedApplyOrder) { + FilePath unused_path(FILE_PATH_LITERAL("foo.exe")); + CommandLine command_line(unused_path); + scoped_ptr<MockConfigurationPolicyProvider> provider( + new MockConfigurationPolicyProvider()); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::CreateIntegerValue( + ConfigurationPolicyStore::kPolicyUseSystemProxyMode)); + provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::CreateStringValue(L"http://chromium.org/override")); + + ConfigurationPolicyPrefStore store(&command_line, provider.release()); + EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); + + std::wstring string_result; + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, + &string_result)); + EXPECT_EQ(string_result, L""); + + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); + EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); + bool bool_result; + EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); + EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, + &bool_result)); } diff --git a/chrome/browser/configuration_policy_provider.cc b/chrome/browser/configuration_policy_provider.cc index 3cb9721..6c83f45 100644 --- a/chrome/browser/configuration_policy_provider.cc +++ b/chrome/browser/configuration_policy_provider.cc @@ -22,6 +22,14 @@ const InternalPolicyValueMapEntry kPolicyValueMap[] = { Value::TYPE_STRING, "Homepage" }, { ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, "HomepageIsNewTabPage" }, + { ConfigurationPolicyStore::kPolicyProxyServerMode, + Value::TYPE_BOOLEAN, "ProxyServerMode" }, + { ConfigurationPolicyStore::kPolicyProxyServer, + Value::TYPE_STRING, "ProxyServer" }, + { ConfigurationPolicyStore::kPolicyProxyPacUrl, + Value::TYPE_STRING, "ProxyPacUrl" }, + { ConfigurationPolicyStore::kPolicyProxyBypassList, + Value::TYPE_STRING, "ProxyBypassList" }, { ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, "AlternateErrorPagesEnabled" }, { ConfigurationPolicyStore::kPolicySearchSuggestEnabled, @@ -31,9 +39,7 @@ const InternalPolicyValueMapEntry kPolicyValueMap[] = { { ConfigurationPolicyStore::kPolicySafeBrowsingEnabled, Value::TYPE_BOOLEAN, "SafeBrowsingEnabled" }, { ConfigurationPolicyStore::kPolicyMetricsReportingEnabled, - Value::TYPE_BOOLEAN, "MetricsReportingEnabled" }, - { ConfigurationPolicyStore::kPolicyCookiesMode, - Value::TYPE_INTEGER, "CookiesMode" } + Value::TYPE_BOOLEAN, "MetricsReportingEnabled" } }; } // namespace diff --git a/chrome/browser/configuration_policy_provider_mac_unittest.cc b/chrome/browser/configuration_policy_provider_mac_unittest.cc index d237891..4e6885d 100644 --- a/chrome/browser/configuration_policy_provider_mac_unittest.cc +++ b/chrome/browser/configuration_policy_provider_mac_unittest.cc @@ -117,26 +117,3 @@ TEST(ConfigurationPolicyProviderMacTest, TestHomepageIsNewTabPagePolicy) { EXPECT_EQ(true, value); } -TEST(ConfigurationPolicyProviderMacTest, TestCookiesModePolicy) { - MockConfigurationPolicyStore store; - TestConfigurationPolicyProviderMac provider; - int test_value = 2; - scoped_cftyperef<CFNumberRef> test_number( - CFNumberCreate(kCFAllocatorDefault, - kCFNumberIntType, - &test_value)); - provider.AddTestItem(ConfigurationPolicyStore::kPolicyCookiesMode, - test_number, - true); - - provider.Provide(&store); - - const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); - MockConfigurationPolicyStore::PolicyMap::const_iterator i = - map.find(ConfigurationPolicyStore::kPolicyCookiesMode); - ASSERT_TRUE(i != map.end()); - int value = 0; - i->second->GetAsInteger(&value); - EXPECT_EQ(2, value); -} - diff --git a/chrome/browser/configuration_policy_provider_win_unittest.cc b/chrome/browser/configuration_policy_provider_win_unittest.cc index cf3bc68..cefe646 100644 --- a/chrome/browser/configuration_policy_provider_win_unittest.cc +++ b/chrome/browser/configuration_policy_provider_win_unittest.cc @@ -91,17 +91,6 @@ void TestConfigurationPolicyProviderWin::SetBooleanPolicy( EXPECT_TRUE(key.WriteValue(NameForPolicy(type).c_str(), value)); } -void TestConfigurationPolicyProviderWin::SetCookiesMode( - HKEY hive, - uint32 value) { - RegKey key(hive, - ConfigurationPolicyProviderWin::kPolicyRegistrySubKey, - KEY_ALL_ACCESS); - EXPECT_TRUE(key.WriteValue( - NameForPolicy(ConfigurationPolicyStore::kPolicyCookiesMode).c_str(), - value)); -} - // This test class provides sandboxing and mocking for the parts of the // Windows Registry implementing Group Policy. The |SetUp| method prepares // two temporary sandbox keys in |kUnitTestRegistrySubKey|, one for HKLM and one @@ -319,32 +308,3 @@ TEST_F(ConfigurationPolicyProviderWinTest, TestBooleanPolicy(ConfigurationPolicyStore::kPolicyMetricsReportingEnabled); } -TEST_F(ConfigurationPolicyProviderWinTest, - TestCookiesModePolicyDefault) { - MockConfigurationPolicyStore store; - TestConfigurationPolicyProviderWin provider; - - provider.Provide(&store); - - const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); - EXPECT_FALSE(ContainsKey(map, - ConfigurationPolicyStore::kPolicyCookiesMode)); -} - -TEST_F(ConfigurationPolicyProviderWinTest, - TestCookiesModePolicyHKLM) { - MockConfigurationPolicyStore store; - TestConfigurationPolicyProviderWin provider; - provider.SetCookiesMode(HKEY_LOCAL_MACHINE, 2); - - provider.Provide(&store); - - const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); - MockConfigurationPolicyStore::PolicyMap::const_iterator i = - map.find(ConfigurationPolicyStore::kPolicyCookiesMode); - ASSERT_TRUE(i != map.end()); - int value = 0; - i->second->GetAsInteger(&value); - EXPECT_EQ(2, value); -} - diff --git a/chrome/browser/configuration_policy_store.h b/chrome/browser/configuration_policy_store.h index 6b6461e..20d0b36 100644 --- a/chrome/browser/configuration_policy_store.h +++ b/chrome/browser/configuration_policy_store.h @@ -17,14 +17,22 @@ class ConfigurationPolicyStore { enum PolicyType { kPolicyHomePage, kPolicyHomepageIsNewTabPage, + kPolicyProxyServerMode, + kPolicyProxyServer, + kPolicyProxyPacUrl, + kPolicyProxyBypassList, kPolicyAlternateErrorPagesEnabled, kPolicySearchSuggestEnabled, kPolicyDnsPrefetchingEnabled, kPolicySafeBrowsingEnabled, kPolicyMetricsReportingEnabled, - kPolicyCookiesMode }; + static const int kPolicyNoProxyServerMode = 0; + static const int kPolicyAutoDetectProxyMode = 1; + static const int kPolicyManuallyConfiguredProxyMode = 2; + static const int kPolicyUseSystemProxyMode = 3; + // A |ConfigurationPolicyProvider| specifes the value of a policy setting // through a call to |Apply|. // The configuration policy pref store takes over the ownership of |value|. diff --git a/chrome/browser/mock_configuration_policy_provider.h b/chrome/browser/mock_configuration_policy_provider.h new file mode 100644 index 0000000..8a78b24 --- /dev/null +++ b/chrome/browser/mock_configuration_policy_provider.h @@ -0,0 +1,42 @@ +// 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_MOCK_CONFIGURATION_POLICY_PROVIDER_H_ +#define CHROME_BROWSER_MOCK_CONFIGURATION_POLICY_PROVIDER_H_ + +#include <map> + +#include "base/stl_util-inl.h" +#include "chrome/browser/configuration_policy_provider.h" + +// Mock ConfigurationPolicyProvider implementation that supplies canned +// values for polices. +class MockConfigurationPolicyProvider : public ConfigurationPolicyProvider { + public: + MockConfigurationPolicyProvider() {} + ~MockConfigurationPolicyProvider() { + STLDeleteValues(&policy_map_); + } + + typedef std::map<ConfigurationPolicyStore::PolicyType, Value*> PolicyMap; + + void AddPolicy(ConfigurationPolicyStore::PolicyType policy, Value* value) { + policy_map_[policy] = value; + } + + // ConfigurationPolicyProvider method overrides. + virtual bool Provide(ConfigurationPolicyStore* store) { + for (PolicyMap::const_iterator current = policy_map_.begin(); + current != policy_map_.end(); ++current) { + store->Apply(current->first, current->second->DeepCopy()); + } + return true; + } + + private: + PolicyMap policy_map_; +}; + +#endif // CHROME_BROWSER_MOCK_CONFIGURATION_POLICY_PROVIDER_H_ + diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index ff90824..93cc09b 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -60,15 +60,14 @@ void CheckCurrentlyOnMainThread() { // ---------------------------------------------------------------------------- net::ProxyConfigService* CreateProxyConfigService( - const CommandLine& command_line) { + const PrefService* pref_service) { // The linux gconf-based proxy settings getter relies on being initialized // from the UI thread. CheckCurrentlyOnMainThread(); - scoped_ptr<net::ProxyConfig> proxy_config_from_cmd_line( - CreateProxyConfig(command_line)); + scoped_ptr<net::ProxyConfig> proxy_config(CreateProxyConfig(pref_service)); - if (!proxy_config_from_cmd_line.get()) { + if (!proxy_config.get()) { // Use system settings. // TODO(port): the IO and FILE message loops are only used by Linux. Can // that code be moved to chrome/browser instead of being in net, so that it @@ -79,7 +78,7 @@ net::ProxyConfigService* CreateProxyConfigService( } // Otherwise use the fixed settings from the command line. - return new net::ProxyConfigServiceFixed(*proxy_config_from_cmd_line.get()); + return new net::ProxyConfigServiceFixed(*proxy_config.get()); } // Create a proxy service according to the options on command line. @@ -213,9 +212,7 @@ class FactoryForOriginal : public ChromeURLRequestContextFactory { // We need to initialize the ProxyConfigService from the UI thread // because on linux it relies on initializing things through gconf, // and needs to be on the main thread. - proxy_config_service_( - CreateProxyConfigService( - *CommandLine::ForCurrentProcess())) { + proxy_config_service_(CreateProxyConfigService(profile->GetPrefs())) { } virtual ChromeURLRequestContext* Create(); @@ -549,6 +546,15 @@ URLRequestContext* ChromeURLRequestContextGetter::GetURLRequestContext() { return url_request_context_; } +void ChromeURLRequestContextGetter::RegisterUserPrefs( + PrefService* pref_service) { + pref_service->RegisterBooleanPref(prefs::kNoProxyServer, false); + pref_service->RegisterBooleanPref(prefs::kProxyAutoDetect, false); + pref_service->RegisterStringPref(prefs::kProxyServer, L""); + pref_service->RegisterStringPref(prefs::kProxyPacUrl, L""); + pref_service->RegisterStringPref(prefs::kProxyBypassList, L""); +} + net::CookieStore* ChromeURLRequestContextGetter::GetCookieStore() { // If we are running on the IO thread this is real easy. if (ChromeThread::CurrentlyOn(ChromeThread::IO)) @@ -1024,59 +1030,53 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( // ---------------------------------------------------------------------------- -net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) { +net::ProxyConfig* CreateProxyConfig(const PrefService* pref_service) { // Scan for all "enable" type proxy switches. - static const char* proxy_switches[] = { - switches::kProxyServer, - switches::kProxyPacUrl, - switches::kProxyAutoDetect, - switches::kProxyBypassList + static const wchar_t* proxy_prefs[] = { + prefs::kProxyPacUrl, + prefs::kProxyServer, + prefs::kProxyBypassList, + prefs::kProxyAutoDetect }; - bool found_enable_proxy_switch = false; - for (size_t i = 0; i < arraysize(proxy_switches); i++) { - if (command_line.HasSwitch(proxy_switches[i])) { - found_enable_proxy_switch = true; + bool found_enable_proxy_pref = false; + for (size_t i = 0; i < arraysize(proxy_prefs); i++) { + if (pref_service->HasPrefPath(proxy_prefs[i])) { + found_enable_proxy_pref = true; break; } } - if (!found_enable_proxy_switch && - !command_line.HasSwitch(switches::kNoProxyServer)) { + if (!found_enable_proxy_pref && + !pref_service->GetBoolean(prefs::kNoProxyServer)) { return NULL; } net::ProxyConfig* proxy_config = new net::ProxyConfig(); - if (command_line.HasSwitch(switches::kNoProxyServer)) { - // Ignore (and warn about) all the other proxy config switches we get if - // the --no-proxy-server command line argument is present. - if (found_enable_proxy_switch) { - LOG(WARNING) << "Additional command line proxy switches found when --" - << switches::kNoProxyServer << " was specified."; - } + if (pref_service->GetBoolean(prefs::kNoProxyServer)) { + // Ignore all the other proxy config preferences if the use of a proxy + // has been explicitly disabled. return proxy_config; } - if (command_line.HasSwitch(switches::kProxyServer)) { - const std::wstring& proxy_server = - command_line.GetSwitchValue(switches::kProxyServer); + if (pref_service->HasPrefPath(prefs::kProxyServer)) { + std::wstring proxy_server = pref_service->GetString(prefs::kProxyServer); proxy_config->proxy_rules().ParseFromString(WideToASCII(proxy_server)); } - if (command_line.HasSwitch(switches::kProxyPacUrl)) { - proxy_config->set_pac_url( - GURL(WideToASCII(command_line.GetSwitchValue( - switches::kProxyPacUrl)))); + if (pref_service->HasPrefPath(prefs::kProxyPacUrl)) { + std::wstring proxy_pac = pref_service->GetString(prefs::kProxyPacUrl); + proxy_config->set_pac_url(GURL(WideToASCII(proxy_pac))); } - if (command_line.HasSwitch(switches::kProxyAutoDetect)) { - proxy_config->set_auto_detect(true); - } + proxy_config->set_auto_detect(pref_service->GetBoolean( + prefs::kProxyAutoDetect)); - if (command_line.HasSwitch(switches::kProxyBypassList)) { + if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { + std::wstring proxy_bypass = + pref_service->GetString(prefs::kProxyBypassList); proxy_config->proxy_rules().bypass_rules.ParseFromString( - WideToASCII(command_line.GetSwitchValue( - switches::kProxyBypassList))); + WideToASCII(proxy_bypass)); } return proxy_config; diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 8f08d87..2b6d08d 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -26,6 +26,7 @@ #include "webkit/database/database_tracker.h" class CommandLine; +class PrefService; class Profile; namespace net { @@ -273,6 +274,8 @@ class ChromeURLRequestContextGetter : public URLRequestContextGetter, ChromeURLRequestContextGetter(Profile* profile, ChromeURLRequestContextFactory* factory); + static void RegisterUserPrefs(PrefService* user_prefs); + // Note that GetURLRequestContext() can only be called from the IO // thread (it will assert otherwise). GetCookieStore() and // GetIOMessageLoopProxy however can be called from any thread. @@ -416,8 +419,9 @@ class ChromeURLRequestContextFactory { DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); }; -// Creates a proxy configuration using the overrides specified on the command -// line. Returns NULL if the system defaults should be used instead. -net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line); +// Creates a proxy configuration from proxy-related preferences fetched +// from |pref_service|. The relevant preferences in |pref_service| are +// initialized from the process' command line or by applicable proxy policies. +net::ProxyConfig* CreateProxyConfig(const PrefService* pref_service); #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ diff --git a/chrome/browser/net/chrome_url_request_context_unittest.cc b/chrome/browser/net/chrome_url_request_context_unittest.cc index e8b610c..829be5a 100644 --- a/chrome/browser/net/chrome_url_request_context_unittest.cc +++ b/chrome/browser/net/chrome_url_request_context_unittest.cc @@ -6,6 +6,8 @@ #include "base/command_line.h" #include "base/format_macros.h" +#include "chrome/browser/configuration_policy_pref_store.h" +#include "chrome/browser/pref_value_store.h" #include "chrome/common/chrome_switches.h" #include "net/proxy/proxy_config.h" #include "net/proxy/proxy_config_service_common_unittest.h" @@ -155,8 +157,11 @@ TEST(ChromeURLRequestContextTest, CreateProxyConfigTest) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, tests[i].description.c_str())); - scoped_ptr<net::ProxyConfig> config(CreateProxyConfig( - CommandLine(tests[i].command_line))); + CommandLine command_line(tests[i].command_line); + PrefService prefs(new PrefValueStore( + new ConfigurationPolicyPrefStore(&command_line, NULL), NULL, NULL)); + ChromeURLRequestContextGetter::RegisterUserPrefs(&prefs); + scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(&prefs)); if (tests[i].is_null) { EXPECT_TRUE(config == NULL); @@ -168,3 +173,4 @@ TEST(ChromeURLRequestContextTest, CreateProxyConfigTest) { } } } + diff --git a/chrome/browser/pref_service.cc b/chrome/browser/pref_service.cc index 32aeda0..bb80c90 100644 --- a/chrome/browser/pref_service.cc +++ b/chrome/browser/pref_service.cc @@ -8,6 +8,7 @@ #include <string> #include "app/l10n_util.h" +#include "base/command_line.h" #include "base/histogram.h" #include "base/logging.h" #include "base/message_loop.h" @@ -104,7 +105,9 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) { // The ConfigurationPolicyPrefStore take the ownership of the passed // |provider|. - managed_prefs = new ConfigurationPolicyPrefStore(managed_prefs_provider); + managed_prefs = new ConfigurationPolicyPrefStore( + CommandLine::ForCurrentProcess(), + managed_prefs_provider); // The PrefValueStore takes to ownership of the parameters. PrefValueStore* value_store = new PrefValueStore( diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 97f3717..e6d57e8 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2049,6 +2049,8 @@ 'browser/sessions/session_types.h', 'browser/sessions/tab_restore_service.cc', 'browser/sessions/tab_restore_service.h', + 'browser/configuration_policy_provider.cc', + 'browser/configuration_policy_provider.h', 'browser/shell_dialogs.h', 'browser/shell_integration.cc', 'browser/shell_integration.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 5d496ed..0366c10 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -849,6 +849,7 @@ 'browser/metrics/metrics_log_unittest.cc', 'browser/metrics/metrics_response_unittest.cc', 'browser/metrics/metrics_service_unittest.cc', + 'browser/mock_configuration_policy_provider.h', 'browser/mock_configuration_policy_store.h', 'browser/net/chrome_url_request_context_unittest.cc', 'browser/net/connection_tester_unittest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index f66d0fa..c2fd03e 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -882,4 +882,18 @@ const wchar_t kCloudPrintXMPPAuthToken[] = L"cloud_print.xmpp_auth_token"; // server. extern const wchar_t kCloudPrintEmail[] = L"cloud_print.email"; +// Boolean to disable proxy altogether. If true, other proxy +// preferences are ignored. +const wchar_t kNoProxyServer[] = L"proxy.disabled"; +// Boolean specifying if proxy should be auto-detected. +const wchar_t kProxyAutoDetect[] = L"proxy.auto_detect"; +// String specifying the proxy server. For a specification of the expected +// syntax see net::ProxyConfig::ProxyRules::ParseFromString(). +const wchar_t kProxyServer[] = L"proxy.server"; +// URL to the proxy .pac file. +const wchar_t kProxyPacUrl[] = L"proxy.pac_url"; +// String containing proxy bypass rules. For a specification of the +// expected syntax see net::ProxyBypassRules::ParseFromString(). +const wchar_t kProxyBypassList[] = L"proxy.bypass_list"; + } // namespace prefs diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 2346981..0e91b2b 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -329,6 +329,12 @@ extern const wchar_t kCloudPrintAuthToken[]; extern const wchar_t kCloudPrintXMPPAuthToken[]; extern const wchar_t kCloudPrintEmail[]; +extern const wchar_t kNoProxyServer[]; +extern const wchar_t kProxyAutoDetect[]; +extern const wchar_t kProxyServer[]; +extern const wchar_t kProxyPacUrl[]; +extern const wchar_t kProxyBypassList[]; + } // namespace prefs #endif // CHROME_COMMON_PREF_NAMES_H_ |