diff options
24 files changed, 53 insertions, 362 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index a4e3a88..7ebead2 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1359,6 +1359,8 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kHomePage, ASCIIToWide(chrome::kChromeUINewTabURL)); prefs->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true); + prefs->RegisterIntegerPref(prefs::kCookieBehavior, + net::CookiePolicy::ALLOW_ALL_COOKIES); prefs->RegisterBooleanPref(prefs::kShowHomeButton, false); #if defined(OS_MACOSX) // This really belongs in platform code, but there's no good place to diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 23e7549..85f35a0 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -21,7 +21,6 @@ #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_cookie_policy.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/page_info_model.h" #include "chrome/browser/password_manager/password_manager.h" @@ -99,7 +98,6 @@ void RegisterUserPrefs(PrefService* user_prefs) { HostZoomMap::RegisterUserPrefs(user_prefs); DevToolsManager::RegisterUserPrefs(user_prefs); Blacklist::RegisterUserPrefs(user_prefs); - ChromeCookiePolicy::RegisterUserPrefs(user_prefs); #if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port. BrowserActionsContainer::RegisterUserPrefs(user_prefs); #if defined(OS_WIN) diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h index 9c59343..e29047e 100644 --- a/chrome/browser/cocoa/preferences_window_controller.h +++ b/chrome/browser/cocoa/preferences_window_controller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -38,7 +38,6 @@ class ProfileSyncService; // weak ref - Also obtained from profile_ for convenience. May be NULL. ProfileSyncService* syncService_; scoped_ptr<PrefObserverBridge> observer_; // Watches for pref changes. - bool pref_changing_; // Flag to ignore pref updates caused by ourselves. IBOutlet NSToolbar* toolbar_; diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index 6a378d2..19ad0f2 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -7,7 +7,6 @@ #include <algorithm> #include "app/l10n_util.h" #include "app/l10n_util_mac.h" -#include "base/auto_reset.h" #include "base/logging.h" #include "base/mac_util.h" #include "base/string16.h" @@ -26,7 +25,6 @@ #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/metrics/user_metrics.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/options_window.h" @@ -47,6 +45,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" +#include "net/base/cookie_policy.h" #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" @@ -457,7 +456,6 @@ class PrefObserverBridge : public NotificationObserver, // This needs to be done before awakeFromNib: because the bindings set up // in the nib rely on it. [self registerPrefObservers]; - pref_changing_ = false; // Use one animation so we can stop it if the user clicks quickly, and // start the new animation. @@ -816,7 +814,6 @@ class PrefObserverBridge : public NotificationObserver, // Cocoa Bindings. // Handles prefs for the "Basics" panel. - (void)basicsPrefChanged:(std::wstring*)prefName { - AutoReset auto_reset(&pref_changing_, true); if (*prefName == prefs::kRestoreOnStartup) { const SessionStartupPref startupPref = SessionStartupPref::GetStartupPref(prefs_); @@ -1132,7 +1129,6 @@ const int kDisabledIndex = 1; // initializing, that's handled by Cocoa Bindings. // Handles prefs for the "Personal Stuff" panel. - (void)userDataPrefChanged:(std::wstring*)prefName { - AutoReset auto_reset(&pref_changing_, true); if (*prefName == prefs::kPasswordManagerEnabled) { [self setPasswordManagerEnabledIndex:askSavePasswords_.GetValue() ? kEnabledIndex : kDisabledIndex]; @@ -1285,7 +1281,6 @@ const int kDisabledIndex = 1; // initializing, that's handled by Cocoa Bindings. // Handles prefs for the "Under the hood" panel. - (void)underHoodPrefChanged:(std::wstring*)prefName { - AutoReset auto_reset(&pref_changing_, true); if (*prefName == prefs::kAlternateErrorPagesEnabled) { [self setShowAlternateErrorPages: alternateErrorPages_.GetValue() ? YES : NO]; @@ -1476,8 +1471,6 @@ const int kDisabledIndex = 1; // Sets the backend pref for whether or not to accept cookies based on |index|. - (void)setCookieBehavior:(NSInteger)index { - if (pref_changing_) - return; net::CookiePolicy::Type policy = net::CookiePolicy::ALLOW_ALL_COOKIES; if (net::CookiePolicy::ValidType(index)) policy = net::CookiePolicy::FromInt(index); @@ -1488,7 +1481,7 @@ const int kDisabledIndex = 1; }; DCHECK(policy >= 0 && (unsigned int)policy < arraysize(kUserMetrics)); [self recordUserAction:kUserMetrics[policy]]; - profile_->GetCookiePolicy()->set_type(policy); + cookieBehavior_.SetValue(policy); } - (NSURL*)defaultDownloadLocation { diff --git a/chrome/browser/gtk/options/advanced_contents_gtk.cc b/chrome/browser/gtk/options/advanced_contents_gtk.cc index 2f7ed5b..d493a39 100644 --- a/chrome/browser/gtk/options/advanced_contents_gtk.cc +++ b/chrome/browser/gtk/options/advanced_contents_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -21,7 +21,6 @@ #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/options/cookies_view.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/options_page_base.h" #include "chrome/browser/options_util.h" @@ -36,6 +35,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" +#include "net/base/cookie_policy.h" namespace { @@ -754,7 +754,7 @@ void PrivacySection::OnCookieBehaviorChanged(GtkComboBox* combo_box, } privacy_section->UserMetricsRecordAction( kUserMetrics[cookie_policy], privacy_section->profile()->GetPrefs()); - privacy_section->profile()->GetCookiePolicy()->set_type(cookie_policy); + privacy_section->cookie_behavior_.SetValue(cookie_policy); } // static diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc deleted file mode 100644 index fccb737..0000000 --- a/chrome/browser/net/chrome_cookie_policy.cc +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/net/chrome_cookie_policy.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/profile.h" -#include "chrome/common/pref_service.h" -#include "chrome/common/pref_names.h" -#include "googleurl/src/gurl.h" -#include "net/base/registry_controlled_domain.h" - -ChromeCookiePolicy::ChromeCookiePolicy(Profile* profile) : profile_(profile) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - const DictionaryValue* cookie_exceptions_dict = - profile_->GetPrefs()->GetDictionary(prefs::kCookieExceptions); - // Careful: The returned value could be NULL if the pref has never been set. - if (cookie_exceptions_dict != NULL) { - for (DictionaryValue::key_iterator i(cookie_exceptions_dict->begin_keys()); - i != cookie_exceptions_dict->end_keys(); ++i) { - std::wstring wide_domain(*i); - int content_settings = 0; - bool success = cookie_exceptions_dict->GetIntegerWithoutPathExpansion( - wide_domain, &content_settings); - DCHECK(success); - per_domain_policy_[WideToUTF8(wide_domain)] = - static_cast<ContentPermissionType>(content_settings); - } - } - net::CookiePolicy::set_type(net::CookiePolicy::FromInt( - profile_->GetPrefs()->GetInteger(prefs::kCookieBehavior))); -} - -// static -void ChromeCookiePolicy::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterDictionaryPref(prefs::kCookieExceptions); - prefs->RegisterIntegerPref(prefs::kCookieBehavior, - net::CookiePolicy::ALLOW_ALL_COOKIES); -} - -void ChromeCookiePolicy::ResetToDefaults() { - net::CookiePolicy::set_type(net::CookiePolicy::ALLOW_ALL_COOKIES); - per_domain_policy_.clear(); - profile_->GetPrefs()->ClearPref(prefs::kCookieBehavior); - profile_->GetPrefs()->ClearPref(prefs::kCookieExceptions); -} - -bool ChromeCookiePolicy::CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies) { - AutoLock auto_lock(lock_); - ContentPermissionType permission = CheckPermissionForHost(url.host()); - switch (permission) { - case CONTENT_PERMISSION_TYPE_DEFAULT: - return net::CookiePolicy::CanGetCookies(url, first_party_for_cookies); - - case CONTENT_PERMISSION_TYPE_BLOCK: - return false; - - case CONTENT_PERMISSION_TYPE_ALLOW: - return true; - - case CONTENT_PERMISSION_TYPE_ASK: - // TODO(darin): ask the user. - - default: - NOTREACHED(); - } - return false; // To avoid compiler warnings. -} - -bool ChromeCookiePolicy::CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies) { - AutoLock auto_lock(lock_); - ContentPermissionType permission = CheckPermissionForHost(url.host()); - switch (permission) { - case CONTENT_PERMISSION_TYPE_DEFAULT: - return net::CookiePolicy::CanSetCookie(url, first_party_for_cookies); - - case CONTENT_PERMISSION_TYPE_BLOCK: - return false; - - case CONTENT_PERMISSION_TYPE_ALLOW: - return true; - - case CONTENT_PERMISSION_TYPE_ASK: - // TODO(darin): ask the user. - - default: - NOTREACHED(); - } - return false; // To avoid compiler warnings. -} - -void ChromeCookiePolicy::SetPerDomainPermission(const std::string& domain, - ContentPermissionType type) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - if (domain.empty()) - return; - - { - AutoLock auto_lock(lock_); - if (type == CONTENT_PERMISSION_TYPE_DEFAULT) - per_domain_policy_.erase(domain); - else - per_domain_policy_[domain] = type; - } - - DictionaryValue* cookie_exceptions_dict = - profile_->GetPrefs()->GetMutableDictionary(prefs::kCookieExceptions); - std::wstring wide_domain(UTF8ToWide(domain)); - if (type == CONTENT_PERMISSION_TYPE_DEFAULT) { - cookie_exceptions_dict->RemoveWithoutPathExpansion(wide_domain, NULL); - } else { - cookie_exceptions_dict->SetWithoutPathExpansion(wide_domain, - Value::CreateIntegerValue(type)); - } -} - -void ChromeCookiePolicy::set_type(Type type) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - AutoLock auto_lock(lock_); - net::CookiePolicy::set_type(type); - profile_->GetPrefs()->SetInteger(prefs::kCookieBehavior, type); -} - -ContentPermissionType ChromeCookiePolicy::CheckPermissionForHost( - const std::string& host) const { - std::string search_key(host); - while (!search_key.empty()) { - CookiePolicies::const_iterator i(per_domain_policy_.find(search_key)); - if (i != per_domain_policy_.end()) - return i->second; - size_t dot_pos = search_key.find_first_of('.'); - if (dot_pos == std::string::npos) - break; - search_key = search_key.substr(dot_pos+1); - } - return CONTENT_PERMISSION_TYPE_DEFAULT; -} diff --git a/chrome/browser/net/chrome_cookie_policy.h b/chrome/browser/net/chrome_cookie_policy.h deleted file mode 100644 index 88e698b..0000000 --- a/chrome/browser/net/chrome_cookie_policy.h +++ /dev/null @@ -1,81 +0,0 @@ -// 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_NET_CHROME_COOKIE_POLICY_H_ -#define CHROME_BROWSER_NET_CHROME_COOKIE_POLICY_H_ - -#include <map> -#include <string> - -#include "base/basictypes.h" -#include "base/lock.h" -#include "chrome/common/content_permission_types.h" -#include "net/base/cookie_policy.h" - -class GURL; -class PrefService; -class Profile; - -// The ChromeCookiePolicy class implements per-domain cookie policies. -class ChromeCookiePolicy : public net::CookiePolicy { - public: - typedef std::map<std::string, ContentPermissionType> CookiePolicies; - - explicit ChromeCookiePolicy(Profile* profile); - - virtual ~ChromeCookiePolicy() {} - - static void RegisterUserPrefs(PrefService* prefs); - - void ResetToDefaults(); - - // Consult the user's cookie blocking preferences to determine whether the - // URL's cookies can be read. - virtual bool CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies); - - // Consult the user's cookie blocking preferences to determine whether the - // URL's cookies can be set. - virtual bool CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies); - - // Sets per domain policies. A policy of type DEFAULT will erase the entry. - // - // This should be called only on the UI thread. - void SetPerDomainPermission(const std::string& domain, - ContentPermissionType type); - - // Returns all per domain policies. - // - // This can be called on any thread. - CookiePolicies GetAllPerDomainPermissions() const { - return per_domain_policy_; - } - - // Sets the current policy to enforce. - // - // This should be called only on the UI thread. - void set_type(Type type); - - // This can be called on any thread. - Type type() const { - AutoLock auto_lock(lock_); - return net::CookiePolicy::type(); - } - - protected: - ContentPermissionType CheckPermissionForHost(const std::string& host) const; - - Profile* profile_; - - mutable Lock lock_; - - // Local copy of prefs. - CookiePolicies per_domain_policy_; - - private: - DISALLOW_COPY_AND_ASSIGN(ChromeCookiePolicy); -}; - -#endif // CHROME_BROWSER_NET_CHROME_COOKIE_POLICY_H_ diff --git a/chrome/browser/net/chrome_cookie_policy_unittest.cc b/chrome/browser/net/chrome_cookie_policy_unittest.cc deleted file mode 100644 index 5bec23a..0000000 --- a/chrome/browser/net/chrome_cookie_policy_unittest.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/net/chrome_cookie_policy.h" - -#include "chrome/test/testing_profile.h" -#include "testing/gtest/include/gtest/gtest.h" - - -namespace { - -class ChromeCookiePolicyTest : public testing::Test { - public: - ChromeCookiePolicyTest() - : ui_thread_(ChromeThread::UI, &message_loop_) {} - - protected: - MessageLoop message_loop_; - ChromeThread ui_thread_; -}; - -TEST_F(ChromeCookiePolicyTest, DefaultValues) { - TestingProfile profile; - ChromeCookiePolicy* cookie_policy = profile.GetCookiePolicy(); - - // Check setting of default permissions. - cookie_policy->set_type(net::CookiePolicy::ALLOW_ALL_COOKIES); - EXPECT_EQ(net::CookiePolicy::ALLOW_ALL_COOKIES, cookie_policy->type()); - - // Check per host permissions returned. - EXPECT_TRUE(cookie_policy->CanSetCookie(GURL("http://www.example.com"), - GURL("http://www.example.com"))); - cookie_policy->SetPerDomainPermission("example.com", - CONTENT_PERMISSION_TYPE_BLOCK); - EXPECT_FALSE(cookie_policy->CanSetCookie(GURL("http://www.example.com"), - GURL("http://www.example.com"))); - EXPECT_TRUE(cookie_policy->CanSetCookie(GURL("http://other.com"), - GURL("http://other.com"))); - - // Check returning settings for a given resource. - ChromeCookiePolicy::CookiePolicies policies; - policies = cookie_policy->GetAllPerDomainPermissions(); - EXPECT_EQ(1U, policies.size()); - EXPECT_EQ("example.com", policies.begin()->first); - EXPECT_EQ(CONTENT_PERMISSION_TYPE_BLOCK, policies.begin()->second); -} - -} // namespace diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 88914dc..a50013d 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -544,6 +544,15 @@ void ChromeURLRequestContextGetter::Observe( this, &ChromeURLRequestContextGetter::OnAcceptLanguageChange, accept_language)); + } else if (*pref_name_in == prefs::kCookieBehavior) { + net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt( + prefs_->GetInteger(prefs::kCookieBehavior)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + this, + &ChromeURLRequestContextGetter::OnCookiePolicyChange, + policy_type)); } else if (*pref_name_in == prefs::kDefaultCharset) { std::string default_charset = WideToASCII(prefs->GetString(prefs::kDefaultCharset)); @@ -565,6 +574,7 @@ void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { prefs_ = profile->GetPrefs(); prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); + prefs_->AddPrefObserver(prefs::kCookieBehavior, this); prefs_->AddPrefObserver(prefs::kDefaultCharset, this); } @@ -586,6 +596,11 @@ void ChromeURLRequestContextGetter::OnAcceptLanguageChange( GetIOContext()->OnAcceptLanguageChange(accept_language); } +void ChromeURLRequestContextGetter::OnCookiePolicyChange( + net::CookiePolicy::Type type) { + GetIOContext()->OnCookiePolicyChange(type); +} + void ChromeURLRequestContextGetter::OnDefaultCharsetChange( const std::string& default_charset) { GetIOContext()->OnDefaultCharsetChange(default_charset); @@ -754,7 +769,7 @@ ChromeURLRequestContext::ChromeURLRequestContext( http_transaction_factory_ = other->http_transaction_factory_; ftp_transaction_factory_ = other->ftp_transaction_factory_; cookie_store_ = other->cookie_store_; - cookie_policy_ = other->cookie_policy_; + cookie_policy_.set_type(other->cookie_policy_.type()); transport_security_state_ = other->transport_security_state_; accept_language_ = other->accept_language_; accept_charset_ = other->accept_charset_; @@ -783,6 +798,12 @@ void ChromeURLRequestContext::OnAcceptLanguageChange( net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); } +void ChromeURLRequestContext::OnCookiePolicyChange( + net::CookiePolicy::Type type) { + CheckCurrentlyOnIOThread(); + cookie_policy_.set_type(type); +} + void ChromeURLRequestContext::OnDefaultCharsetChange( const std::string& default_charset) { CheckCurrentlyOnIOThread(); @@ -834,7 +855,8 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) // net_util::GetSuggestedFilename is unlikely to be taken. referrer_charset_ = default_charset; - cookie_policy_ = profile->GetCookiePolicy(); + cookie_policy_type_ = net::CookiePolicy::FromInt( + prefs->GetInteger(prefs::kCookieBehavior)); host_content_settings_map_ = profile->GetHostContentSettingsMap(); @@ -881,7 +903,7 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( context->set_accept_language(accept_language_); context->set_accept_charset(accept_charset_); context->set_referrer_charset(referrer_charset_); - context->set_cookie_policy(cookie_policy_); + context->set_cookie_policy_type(cookie_policy_type_); context->set_extension_info(extension_info_); context->set_user_script_dir_path(user_script_dir_path_); context->set_host_content_settings_map(host_content_settings_map_); diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index ae412ba..d1953ef 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -9,7 +9,6 @@ #include "base/linked_ptr.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/host_zoom_map.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/browser/net/url_request_context_getter.h" #include "chrome/common/appcache/chrome_appcache_service.h" #include "chrome/common/notification_registrar.h" @@ -137,8 +136,8 @@ class ChromeURLRequestContext : public URLRequestContext { void set_referrer_charset(const std::string& referrer_charset) { referrer_charset_ = referrer_charset; } - void set_cookie_policy(ChromeCookiePolicy* policy) { - cookie_policy_ = policy; + void set_cookie_policy_type(net::CookiePolicy::Type type) { + cookie_policy_.set_type(type); } void set_extension_info( const ChromeURLRequestContext::ExtensionInfoMap& info) { @@ -190,6 +189,9 @@ class ChromeURLRequestContext : public URLRequestContext { // Callback for when the accept language changes. void OnAcceptLanguageChange(const std::string& accept_language); + // Callback for when the cookie policy changes. + void OnCookiePolicyChange(net::CookiePolicy::Type type); + // Callback for when the default charset changes. void OnDefaultCharsetChange(const std::string& default_charset); @@ -312,6 +314,7 @@ class ChromeURLRequestContextGetter : public URLRequestContextGetter, // These methods simply forward to the corresponding method on // ChromeURLRequestContext. void OnAcceptLanguageChange(const std::string& accept_language); + void OnCookiePolicyChange(net::CookiePolicy::Type type); void OnDefaultCharsetChange(const std::string& default_charset); // Saves the cookie store to |result| and signals |completion|. @@ -365,7 +368,7 @@ class ChromeURLRequestContextFactory { std::string accept_language_; std::string accept_charset_; std::string referrer_charset_; - ChromeCookiePolicy* cookie_policy_; + net::CookiePolicy::Type cookie_policy_type_; ChromeURLRequestContext::ExtensionInfoMap extension_info_; // TODO(aa): I think this can go away now as we no longer support standalone // user scripts. diff --git a/chrome/browser/net/cookie_policy_browsertest.cc b/chrome/browser/net/cookie_policy_browsertest.cc index 9f4b1f4..7dbecf9 100644 --- a/chrome/browser/net/cookie_policy_browsertest.cc +++ b/chrome/browser/net/cookie_policy_browsertest.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "chrome/browser/browser.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" @@ -26,8 +25,8 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { ASSERT_TRUE(server != NULL); PrefService* prefs = browser()->profile()->GetPrefs(); - browser()->profile()->GetCookiePolicy()->set_type( - net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES); + prefs->SetInteger(prefs::kCookieBehavior, + net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES); net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt( prefs->GetInteger(prefs::kCookieBehavior)); ASSERT_EQ(net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES, policy_type); @@ -55,8 +54,8 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, ASSERT_TRUE(server != NULL); PrefService* prefs = browser()->profile()->GetPrefs(); - browser()->profile()->GetCookiePolicy()->set_type( - net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES); + prefs->SetInteger(prefs::kCookieBehavior, + net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES); net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt( prefs->GetInteger(prefs::kCookieBehavior)); ASSERT_EQ(net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES, policy_type); diff --git a/chrome/browser/options_util.cc b/chrome/browser/options_util.cc index abb8957..6562c3d 100644 --- a/chrome/browser/options_util.cc +++ b/chrome/browser/options_util.cc @@ -9,7 +9,6 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/metrics/metrics_service.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/installer/util/google_update_settings.h" @@ -23,6 +22,7 @@ void OptionsUtil::ResetToDefaults(Profile* profile) { const wchar_t* kUserPrefs[] = { prefs::kAcceptLanguages, prefs::kAlternateErrorPagesEnabled, + prefs::kCookieBehavior, prefs::kDefaultCharset, prefs::kDnsPrefetchingEnabled, #if defined(OS_LINUX) @@ -64,7 +64,6 @@ void OptionsUtil::ResetToDefaults(Profile* profile) { prefs::kWebKitSansSerifFontFamily, prefs::kWebKitSerifFontFamily, }; - profile->GetCookiePolicy()->ResetToDefaults(); profile->GetDownloadManager()->ResetAutoOpenFiles(); profile->GetHostContentSettingsMap()->ResetToDefaults(); for (size_t i = 0; i < arraysize(kUserPrefs); ++i) diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index acfeb61..c197a78 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -32,7 +32,6 @@ #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/in_process_webkit/webkit_context.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/ssl_config_service_manager.h" #include "chrome/browser/notifications/desktop_notification_service.h" @@ -432,10 +431,6 @@ class OffTheRecordProfileImpl : public Profile, return NULL; } - virtual ChromeCookiePolicy* GetCookiePolicy() { - return GetOriginalProfile()->GetCookiePolicy(); - } - virtual void ShutdownSessionService() { // We don't allow a session service, nothing to do. } @@ -1173,13 +1168,6 @@ SessionService* ProfileImpl::GetSessionService() { return session_service_.get(); } -ChromeCookiePolicy* ProfileImpl::GetCookiePolicy() { - if (!cookie_policy_.get()) - cookie_policy_.reset(new ChromeCookiePolicy(this)); - return cookie_policy_.get(); -} - - void ProfileImpl::ShutdownSessionService() { if (shutdown_session_service_) return; diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 3548a34..6f97fec 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -33,7 +33,6 @@ class DatabaseTracker; class Blacklist; class BookmarkModel; class BrowserThemeProvider; -class ChromeCookiePolicy; class ChromeURLRequestContextGetter; class DesktopNotificationService; class DownloadManager; @@ -309,9 +308,6 @@ class Profile { // should always check the return value for NULL. virtual SessionService* GetSessionService() = 0; - // Returns the cookie policy for this profile. - virtual ChromeCookiePolicy* GetCookiePolicy() = 0; - // If this profile has a session service, it is shut down. To properly record // the current state this forces creation of the session service, then shuts // it down. @@ -449,7 +445,6 @@ class ProfileImpl : public Profile, virtual HostZoomMap* GetHostZoomMap(); virtual Blacklist* GetPrivacyBlacklist(); virtual SessionService* GetSessionService(); - virtual ChromeCookiePolicy* GetCookiePolicy(); virtual void ShutdownSessionService(); virtual bool HasSessionService() const; virtual bool DidLastSessionExitCleanly(); @@ -534,7 +529,6 @@ class ProfileImpl : public Profile, scoped_ptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<HostZoomMap> host_zoom_map_; scoped_ptr<Blacklist> privacy_blacklist_; - scoped_ptr<ChromeCookiePolicy> cookie_policy_; scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<FaviconService> favicon_service_; diff --git a/chrome/browser/sync/glue/http_bridge.cc b/chrome/browser/sync/glue/http_bridge.cc index 511bbce2..95d95ac 100644 --- a/chrome/browser/sync/glue/http_bridge.cc +++ b/chrome/browser/sync/glue/http_bridge.cc @@ -67,8 +67,6 @@ HttpBridge::RequestContext::RequestContext(URLRequestContext* baseline_context) // Create empty, in-memory cookie store. cookie_store_ = new net::CookieMonster(); - cookie_policy_ = new net::CookiePolicy(); - // We don't use a cache for bridged loads, but we do want to share proxy info. host_resolver_ = baseline_context->host_resolver(); proxy_service_ = baseline_context->proxy_service(); @@ -99,7 +97,6 @@ HttpBridge::RequestContext::RequestContext(URLRequestContext* baseline_context) } HttpBridge::RequestContext::~RequestContext() { - delete cookie_policy_; delete http_transaction_factory_; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 84d9336..6adda93 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1217,8 +1217,6 @@ 'browser/modal_html_dialog_delegate.h', 'browser/net/browser_url_util.cc', 'browser/net/browser_url_util.h', - 'browser/net/chrome_cookie_policy.cc', - 'browser/net/chrome_cookie_policy.h', 'browser/net/chrome_url_request_context.cc', 'browser/net/chrome_url_request_context.h', 'browser/net/url_request_context_getter.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index cf5b784..3611dae3 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -739,7 +739,6 @@ 'browser/metrics/metrics_log_unittest.cc', 'browser/metrics/metrics_response_unittest.cc', 'browser/metrics/metrics_service_unittest.cc', - 'browser/net/chrome_cookie_policy_unittest.cc', 'browser/net/chrome_url_request_context_unittest.cc', 'browser/net/dns_host_info_unittest.cc', 'browser/net/dns_master_unittest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 664f5bd..ad07566 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -120,9 +120,6 @@ const wchar_t kSearchSuggestEnabled[] = L"search.suggest_enabled"; // 2 - block all cookies const wchar_t kCookieBehavior[] = L"security.cookie_behavior"; -// Dictionary of exceptions to the default cookie behavior. -const wchar_t kCookieExceptions[] = L"security.cookie_exceptions"; - // Boolean that is true if mixed content should be filtered. // TODO(jcampan): http://b/1084034: at some point this will become an enum // (int): don't filter, filter everything, filter images only. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 30cf464..2afb1e5 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -49,7 +49,6 @@ extern const wchar_t kFormAutofillEnabled[]; extern const wchar_t kSafeBrowsingEnabled[]; extern const wchar_t kSearchSuggestEnabled[]; extern const wchar_t kCookieBehavior[]; -extern const wchar_t kCookieExceptions[]; extern const wchar_t kMixedContentFiltering[]; extern const wchar_t kDefaultSearchProviderSearchURL[]; extern const wchar_t kDefaultSearchProviderSuggestURL[]; diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 1875010..86aa2dd 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -15,7 +15,6 @@ #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/history/history.h" #include "chrome/browser/in_process_webkit/webkit_context.h" -#include "chrome/browser/net/chrome_cookie_policy.h" #include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -189,11 +188,6 @@ class TestingProfile : public Profile { session_service_ = session_service; } virtual SessionService* GetSessionService() { return session_service_.get(); } - virtual ChromeCookiePolicy* GetCookiePolicy() { - if (!cookie_policy_.get()) - cookie_policy_.reset(new ChromeCookiePolicy(this)); - return cookie_policy_.get(); - } virtual void ShutdownSessionService() {} virtual bool HasSessionService() const { return (session_service_.get() != NULL); @@ -307,8 +301,6 @@ class TestingProfile : public Profile { scoped_refptr<WebKitContext> webkit_context_; scoped_ptr<HostContentSettingsMap> host_content_settings_map_; - - scoped_ptr<ChromeCookiePolicy> cookie_policy_; }; // A profile that derives from another profile. This does not actually diff --git a/net/base/cookie_policy.h b/net/base/cookie_policy.h index bf647fc..8efe998 100644 --- a/net/base/cookie_policy.h +++ b/net/base/cookie_policy.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2008 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. @@ -14,17 +14,13 @@ namespace net { // The CookiePolicy class implements third-party cookie blocking. class CookiePolicy { public: - virtual ~CookiePolicy() {} - // Consult the user's third-party cookie blocking preferences to determine // whether the URL's cookies can be read. - virtual bool CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies); + bool CanGetCookies(const GURL& url, const GURL& first_party_for_cookies); // Consult the user's third-party cookie blocking preferences to determine // whether the URL's cookies can be set. - virtual bool CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies); + bool CanSetCookie(const GURL& url, const GURL& first_party_for_cookies); enum Type { ALLOW_ALL_COOKIES = 0, // Do not perform any cookie blocking. @@ -50,10 +46,9 @@ class CookiePolicy { CookiePolicy(); - protected: + private: Type type_; - private: DISALLOW_COPY_AND_ASSIGN(CookiePolicy); }; diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index 978960e..b0204ce 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2008 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. @@ -35,7 +35,6 @@ class URLRequestContext : URLRequestContext() : http_transaction_factory_(NULL), ftp_transaction_factory_(NULL), - cookie_policy_(NULL), cookie_store_(NULL), transport_security_state_(NULL) { } @@ -68,12 +67,7 @@ class URLRequestContext : net::CookieStore* cookie_store() { return cookie_store_.get(); } // Gets the cookie policy for this context. - net::CookiePolicy* cookie_policy() const { - return cookie_policy_; - } - void set_cookie_policy(net::CookiePolicy* cookie_policy) { - cookie_policy_ = cookie_policy; - } + net::CookiePolicy* cookie_policy() { return &cookie_policy_; } net::TransportSecurityState* transport_security_state() { return transport_security_state_; } @@ -137,8 +131,8 @@ class URLRequestContext : scoped_refptr<net::SSLConfigService> ssl_config_service_; net::HttpTransactionFactory* http_transaction_factory_; net::FtpTransactionFactory* ftp_transaction_factory_; - net::CookiePolicy* cookie_policy_; scoped_refptr<net::CookieStore> cookie_store_; + net::CookiePolicy cookie_policy_; scoped_refptr<net::TransportSecurityState> transport_security_state_; net::FtpAuthCache ftp_auth_cache_; std::string accept_language_; diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 3f5a55a..abd94aa 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -65,7 +65,6 @@ class TestURLRequestContext : public URLRequestContext { virtual ~TestURLRequestContext() { delete ftp_transaction_factory_; delete http_transaction_factory_; - delete cookie_policy_; } private: @@ -79,7 +78,6 @@ class TestURLRequestContext : public URLRequestContext { disk_cache::CreateInMemoryCacheBackend(0)); // In-memory cookie store. cookie_store_ = new net::CookieMonster(); - cookie_policy_ = new net::CookiePolicy(); accept_language_ = "en-us,fr"; accept_charset_ = "iso-8859-1,*,utf-8"; } diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc index ef23908..0357e21 100644 --- a/webkit/tools/test_shell/test_shell_request_context.cc +++ b/webkit/tools/test_shell/test_shell_request_context.cc @@ -8,7 +8,6 @@ #include "base/file_path.h" #include "net/base/cookie_monster.h" -#include "net/base/cookie_policy.h" #include "net/base/host_resolver.h" #include "net/base/ssl_config_service.h" #include "net/ftp/ftp_network_layer.h" @@ -33,7 +32,6 @@ void TestShellRequestContext::Init( net::HttpCache::Mode cache_mode, bool no_proxy) { cookie_store_ = new net::CookieMonster(); - cookie_policy_ = new net::CookiePolicy(); // hard-code A-L and A-C for test shells accept_language_ = "en-us,en"; @@ -77,7 +75,6 @@ void TestShellRequestContext::Init( TestShellRequestContext::~TestShellRequestContext() { delete ftp_transaction_factory_; delete http_transaction_factory_; - delete cookie_policy_; } const std::string& TestShellRequestContext::GetUserAgent( |