diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 18:46:21 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 18:46:21 +0000 |
commit | 47accfd64443e175562abc65769457ffef5d3322 (patch) | |
tree | 27d646d32565934449f56cb77982f7283851aca8 | |
parent | 351e70b561dfbf40350cf7607e6af0403e43e64c (diff) | |
download | chromium_src-47accfd64443e175562abc65769457ffef5d3322.zip chromium_src-47accfd64443e175562abc65769457ffef5d3322.tar.gz chromium_src-47accfd64443e175562abc65769457ffef5d3322.tar.bz2 |
Add a separate cookie store that's used for extensions.
Modify CookieMonster to support overriding the "cookieable schemes".
Review URL: http://codereview.chromium.org/115204
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16083 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_init.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 7 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 35 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 9 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 80 | ||||
-rw-r--r-- | chrome/browser/profile.h | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 14 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 2 | ||||
-rw-r--r-- | chrome/common/chrome_constants.cc | 1 | ||||
-rw-r--r-- | chrome/common/chrome_constants.h | 1 | ||||
-rw-r--r-- | chrome/test/testing_profile.h | 3 | ||||
-rw-r--r-- | net/base/cookie_monster.cc | 31 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 13 | ||||
-rw-r--r-- | net/base/cookie_monster_unittest.cc | 17 |
14 files changed, 175 insertions, 50 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index ba95e1f..a83bf12 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -45,7 +45,6 @@ #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "grit/theme_resources.h" -#include "net/base/cookie_monster.h" #include "webkit/glue/webkit_glue.h" #if defined(OS_WIN) @@ -404,9 +403,6 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, } } - if (command_line_.HasSwitch(switches::kEnableFileCookies)) - net::CookieMonster::EnableFileScheme(); - if (command_line_.HasSwitch(switches::kUserAgent)) { webkit_glue::SetUserAgent(WideToUTF8( command_line_.GetSwitchValue(switches::kUserAgent))); diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 8c9736c..6660a73 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -49,6 +49,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/net_resources.h" +#include "net/base/cookie_monster.h" #include "net/base/net_module.h" #include "net/http/http_network_session.h" @@ -365,6 +366,12 @@ int BrowserMain(const MainFunctionParams& parameters) { CheckForWin2000(); } + if (parsed_command_line.HasSwitch(switches::kEnableFileCookies)) { + // Enable cookie storage for file:// URLs. Must do this before the first + // Profile (and therefore the first CookieMonster) is created. + net::CookieMonster::EnableFileScheme(); + } + // Initialize histogram statistics gathering system. StatisticsRecorder statistics; diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 85a33c9..1c18ed4 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -16,6 +16,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" +#include "chrome/common/url_constants.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" #include "net/http/http_network_layer.h" @@ -155,6 +156,26 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( } // static +ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions( + Profile* profile, const FilePath& cookie_store_path) { + DCHECK(!profile->IsOffTheRecord()); + ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); + + // All we care about for extensions is the cookie store. + DCHECK(!cookie_store_path.empty()); + context->cookie_db_.reset(new SQLitePersistentCookieStore( + cookie_store_path.ToWStringHack(), + g_browser_process->db_thread()->message_loop())); + context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); + + // Enable cookies for extension URLs only. + const char* schemes[] = {chrome::kExtensionScheme}; + context->cookie_store_->SetCookieableSchemes(schemes, 1); + + return context; +} + +// static ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( Profile* profile) { DCHECK(profile->IsOffTheRecord()); @@ -184,6 +205,20 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( } // static +ChromeURLRequestContext* +ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { + DCHECK(profile->IsOffTheRecord()); + ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); + context->cookie_store_ = new net::CookieMonster; + + // Enable cookies for extension URLs only. + const char* schemes[] = {chrome::kExtensionScheme}; + context->cookie_store_->SetCookieableSchemes(schemes, 1); + + return context; +} + +// static ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( Profile* profile, const FilePath& disk_cache_path, bool off_the_record) { URLRequestContext* original_context = diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 6f392a7..55af609 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -38,6 +38,11 @@ class ChromeURLRequestContext : public URLRequestContext, static ChromeURLRequestContext* CreateOriginalForMedia(Profile *profile, const FilePath& disk_cache_path); + // Create an instance for an original profile for extensions. This is expected + // to get called on UI thread. + static ChromeURLRequestContext* CreateOriginalForExtensions(Profile *profile, + const FilePath& cookie_store_path); + // Create an instance for use with an OTR profile. This is expected to get // called on the UI thread. static ChromeURLRequestContext* CreateOffTheRecord(Profile* profile); @@ -46,6 +51,10 @@ class ChromeURLRequestContext : public URLRequestContext, static ChromeURLRequestContext* CreateOffTheRecordForMedia(Profile* profile, const FilePath& disk_cache_path); + // Create an instance of request context for OTR profile for extensions. + static ChromeURLRequestContext* CreateOffTheRecordForExtensions( + Profile* profile); + // Clean up UI thread resources. This is expected to get called on the UI // thread before the instance is deleted on the IO thread. void CleanupOnUIThread(); diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 9406216..1c76c49 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -34,6 +34,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/net/cookie_monster_sqlite.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -49,6 +50,16 @@ static const int kCreateSessionServiceDelayMS = 500; // Profile::GetDefaultRequestContext. URLRequestContext* Profile::default_request_context_; +static void CleanupRequestContext(ChromeURLRequestContext* context) { + if (context) { + context->CleanupOnUIThread(); + + // Clean up request context on IO thread. + g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, + context); + } +} + // static void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); @@ -89,6 +100,7 @@ class OffTheRecordProfileImpl : public Profile, explicit OffTheRecordProfileImpl(Profile* real_profile) : profile_(real_profile), media_request_context_(NULL), + extensions_request_context_(NULL), start_time_(Time::Now()) { request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); request_context_->AddRef(); @@ -105,15 +117,9 @@ class OffTheRecordProfileImpl : public Profile, } virtual ~OffTheRecordProfileImpl() { - if (request_context_) { - request_context_->CleanupOnUIThread(); - - // Clean up request context on IO thread. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(request_context_, - &base::RefCountedThreadSafe<URLRequestContext>::Release)); - request_context_ = NULL; - } + CleanupRequestContext(request_context_); + CleanupRequestContext(media_request_context_); + CleanupRequestContext(extensions_request_context_); NotificationService::current()->RemoveObserver( this, NotificationType::BROWSER_CLOSED, @@ -251,6 +257,18 @@ class OffTheRecordProfileImpl : public Profile, return media_request_context_; } + URLRequestContext* GetRequestContextForExtensions() { + if (!extensions_request_context_) { + extensions_request_context_ = + ChromeURLRequestContext::CreateOffTheRecordForExtensions(this); + extensions_request_context_->AddRef(); + + DCHECK(extensions_request_context_->cookie_store()); + } + + return extensions_request_context_; + } + virtual SessionService* GetSessionService() { // Don't save any sessions when off the record. return NULL; @@ -358,6 +376,8 @@ class OffTheRecordProfileImpl : public Profile, // The context for requests for media resources. ChromeURLRequestContext* media_request_context_; + ChromeURLRequestContext* extensions_request_context_; + // The download manager that only stores downloaded items in memory. scoped_refptr<DownloadManager> download_manager_; @@ -382,6 +402,7 @@ ProfileImpl::ProfileImpl(const FilePath& path) : path_(path), request_context_(NULL), media_request_context_(NULL), + extensions_request_context_(NULL), history_service_created_(false), created_web_data_service_(false), created_download_manager_(false), @@ -508,28 +529,12 @@ ProfileImpl::~ProfileImpl() { spellchecker_->Release(); } - if (request_context_) { - request_context_->CleanupOnUIThread(); - - if (default_request_context_ == request_context_) - default_request_context_ = NULL; - - // Clean up request context on IO thread. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(request_context_, - &base::RefCountedThreadSafe<URLRequestContext>::Release)); - request_context_ = NULL; - } - - if (media_request_context_) { - media_request_context_->CleanupOnUIThread(); + if (default_request_context_ == request_context_) + default_request_context_ = NULL; - // Clean up request context on IO thread. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(media_request_context_, - &base::RefCountedThreadSafe<URLRequestContext>::Release)); - media_request_context_ = NULL; - } + CleanupRequestContext(request_context_); + CleanupRequestContext(media_request_context_); + CleanupRequestContext(extensions_request_context_); // HistoryService may call into the BookmarkModel, as such we need to // delete HistoryService before the BookmarkModel. The destructor for @@ -709,6 +714,21 @@ URLRequestContext* ProfileImpl::GetRequestContextForMedia() { return media_request_context_; } +URLRequestContext* ProfileImpl::GetRequestContextForExtensions() { + if (!extensions_request_context_) { + FilePath cookie_path = GetPath(); + cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename); + + extensions_request_context_ = + ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path); + extensions_request_context_->AddRef(); + + DCHECK(extensions_request_context_->cookie_store()); + } + + return extensions_request_context_; +} + HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { if (!history_service_created_) { history_service_created_ = true; diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index a83d76a..6ec129c 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -32,6 +32,7 @@ class PrefService; class SessionService; class SpellChecker; class SSLHostState; +class SQLitePersistentCookieStore; class TabRestoreService; class TemplateURLFetcher; class TemplateURLModel; @@ -189,6 +190,10 @@ class Profile { // profile. virtual URLRequestContext* GetRequestContextForMedia() = 0; + // Returns the request context used for extension-related requests. This + // is only used for a separate cookie store currently. + virtual URLRequestContext* GetRequestContextForExtensions() = 0; + // Returns the session service for this profile. This may return NULL. If // this profile supports a session service (it isn't off the record), and // the session service hasn't yet been created, this forces creation of @@ -311,6 +316,7 @@ class ProfileImpl : public Profile, virtual bool HasCreatedDownloadManager() const; virtual URLRequestContext* GetRequestContext(); virtual URLRequestContext* GetRequestContextForMedia(); + virtual URLRequestContext* GetRequestContextForExtensions(); virtual SessionService* GetSessionService(); virtual void ShutdownSessionService(); virtual bool HasSessionService() const; @@ -378,6 +384,8 @@ class ProfileImpl : public Profile, ChromeURLRequestContext* media_request_context_; + ChromeURLRequestContext* extensions_request_context_; + scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<WebDataService> web_data_service_; diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 594163f..5d26559 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -27,6 +27,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" #include "net/base/cookie_monster.h" #include "net/base/mime_util.h" #include "net/base/load_flags.h" @@ -125,6 +126,7 @@ ResourceMessageFilter::ResourceMessageFilter( ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)), request_context_(profile->GetRequestContext()), media_request_context_(profile->GetRequestContextForMedia()), + extensions_request_context_(profile->GetRequestContextForExtensions()), profile_(profile), render_widget_helper_(render_widget_helper), audio_renderer_host_(audio_renderer_host), @@ -384,15 +386,19 @@ void ResourceMessageFilter::OnMsgCreateWidget(int opener_id, void ResourceMessageFilter::OnSetCookie(const GURL& url, const GURL& policy_url, const std::string& cookie) { - if (request_context_->cookie_policy()->CanSetCookie(url, policy_url)) - request_context_->cookie_store()->SetCookie(url, cookie); + URLRequestContext* context = url.SchemeIs(chrome::kExtensionScheme) ? + extensions_request_context_.get() : request_context_.get(); + if (context->cookie_policy()->CanSetCookie(url, policy_url)) + context->cookie_store()->SetCookie(url, cookie); } void ResourceMessageFilter::OnGetCookies(const GURL& url, const GURL& policy_url, std::string* cookies) { - if (request_context_->cookie_policy()->CanGetCookies(url, policy_url)) - *cookies = request_context_->cookie_store()->GetCookies(url); + URLRequestContext* context = url.SchemeIs(chrome::kExtensionScheme) ? + extensions_request_context_.get() : request_context_.get(); + if (context->cookie_policy()->CanGetCookies(url, policy_url)) + *cookies = context->cookie_store()->GetCookies(url); } void ResourceMessageFilter::OnGetDataDir(std::wstring* data_dir) { diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 8a406f0..2f6629d 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -255,6 +255,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, // A request context specific for media resources. scoped_refptr<URLRequestContext> media_request_context_; + scoped_refptr<URLRequestContext> extensions_request_context_; + // A pointer to the profile associated with this filter. // // DANGER! Do not dereference this pointer! This class lives on the I/O thread diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index 2ca8f0c..9f841da 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -60,6 +60,7 @@ const FilePath::CharType kOffTheRecordMediaCacheDirname[] = FPL("Incognito Media Cache"); const wchar_t kChromePluginDataDirname[] = L"Plugin Data"; const FilePath::CharType kCookieFilename[] = FPL("Cookies"); +const FilePath::CharType kExtensionsCookieFilename[] = FPL("Extension Cookies"); const FilePath::CharType kHistoryFilename[] = FPL("History"); const FilePath::CharType kLocalStateFilename[] = FPL("Local State"); const FilePath::CharType kPreferencesFilename[] = FPL("Preferences"); diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index 1a5e7c4..567b744 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -31,6 +31,7 @@ extern const FilePath::CharType kMediaCacheDirname[]; extern const FilePath::CharType kOffTheRecordMediaCacheDirname[]; extern const wchar_t kChromePluginDataDirname[]; extern const FilePath::CharType kCookieFilename[]; +extern const FilePath::CharType kExtensionsCookieFilename[]; extern const FilePath::CharType kHistoryFilename[]; extern const FilePath::CharType kLocalStateFilename[]; extern const FilePath::CharType kPreferencesFilename[]; diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 310eac8..533b12e 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -131,6 +131,9 @@ class TestingProfile : public Profile { virtual URLRequestContext* GetRequestContextForMedia() { return NULL; } + virtual URLRequestContext* GetRequestContextForExtensions() { + return NULL; + } void set_session_service(SessionService* session_service) { session_service_ = session_service; } diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 4b5d8e0..470bfc2 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -94,6 +94,7 @@ CookieMonster::CookieMonster() store_(NULL), last_access_threshold_( TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)) { + SetDefaultCookieableSchemes(); } CookieMonster::CookieMonster(PersistentCookieStore* store) @@ -101,6 +102,7 @@ CookieMonster::CookieMonster(PersistentCookieStore* store) store_(store), last_access_threshold_( TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)) { + SetDefaultCookieableSchemes(); } CookieMonster::~CookieMonster() { @@ -124,6 +126,13 @@ void CookieMonster::InitStore() { } } +void CookieMonster::SetDefaultCookieableSchemes() { + // Note: file must be the last scheme. + static const char* kDefaultCookieableSchemes[] = { "http", "https", "file" }; + int num_schemes = enable_file_scheme_ ? 3 : 2; + SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); +} + // The system resolution is not high enough, so we can have multiple // set cookies that result in the same system time. When this happens, we // increment by one Time unit. Let's hope computers don't get too fast. @@ -358,18 +367,11 @@ static Time CanonExpiration(const CookieMonster::ParsedCookie& pc, return Time(); } -static bool HasCookieableScheme(const GURL& url) { - static const char* kCookieableSchemes[] = { "http", "https", "file" }; - static const int kCookieableSchemesLen = arraysize(kCookieableSchemes); - static const int kCookieableSchemesFileIndex = 2; - +bool CookieMonster::HasCookieableScheme(const GURL& url) { // Make sure the request is on a cookie-able url scheme. - for (int i = 0; i < kCookieableSchemesLen; ++i) { + for (size_t i = 0; i < cookieable_schemes_.size(); ++i) { // We matched a scheme. - if (url.SchemeIs(kCookieableSchemes[i])) { - // This is file:// scheme - if (i == kCookieableSchemesFileIndex) - return CookieMonster::enable_file_scheme_; + if (url.SchemeIs(cookieable_schemes_[i].c_str())) { // We've matched a supported scheme. return true; } @@ -380,6 +382,13 @@ static bool HasCookieableScheme(const GURL& url) { return false; } +void CookieMonster::SetCookieableSchemes( + const char* schemes[], size_t num_schemes) { + cookieable_schemes_.clear(); + cookieable_schemes_.insert(cookieable_schemes_.end(), + schemes, schemes + num_schemes); +} + bool CookieMonster::SetCookie(const GURL& url, const std::string& cookie_line) { CookieOptions options; @@ -419,7 +428,6 @@ bool CookieMonster::SetCookieWithCreationTimeWithOptions( DCHECK(!creation_time.is_null()); if (!HasCookieableScheme(url)) { - DLOG(WARNING) << "Unsupported cookie scheme: " << url.scheme(); return false; } @@ -733,7 +741,6 @@ std::string CookieMonster::GetCookies(const GURL& url) { std::string CookieMonster::GetCookiesWithOptions(const GURL& url, const CookieOptions& options) { if (!HasCookieableScheme(url)) { - DLOG(WARNING) << "Unsupported cookie scheme: " << url.scheme(); return std::string(); } diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index 0bece15..24db893 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -76,6 +76,7 @@ class CookieMonster { store_(NULL), last_access_threshold_( base::TimeDelta::FromSeconds(last_access_threshold_seconds)) { + SetDefaultCookieableSchemes(); } #endif @@ -133,9 +134,15 @@ class CookieMonster { const CanonicalCookie& cookie, bool sync_to_store); + // Override the default list of schemes that are allowed to be set in + // this cookie store. Calling his overrides the value of + // "enable_file_scheme_". + void SetCookieableSchemes(const char* schemes[], size_t num_schemes); + // There are some unknowns about how to correctly handle file:// cookies, // and our implementation for this is not robust enough. This allows you // to enable support, but it should only be used for testing. Bug 1157243. + // Must be called before creating a CookieMonster instance. static void EnableFileScheme(); static bool enable_file_scheme_; @@ -156,6 +163,8 @@ class CookieMonster { // Should only be called by InitIfNecessary(). void InitStore(); + void SetDefaultCookieableSchemes(); + void FindCookiesForHostAndDomain(const GURL& url, const CookieOptions& options, std::vector<CanonicalCookie*>* cookies); @@ -210,6 +219,8 @@ class CookieMonster { const CookieMapItPair& itpair, std::vector<CookieMap::iterator>* cookie_its); + bool HasCookieableScheme(const GURL& url); + CookieMap cookies_; // Indicates whether the cookie store has been initialized. This happens @@ -227,6 +238,8 @@ class CookieMonster { // update it again. const base::TimeDelta last_access_threshold_; + std::vector<std::string> cookieable_schemes_; + // Lock for thread-safety Lock lock_; diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc index db76cdb..5ca3e76 100644 --- a/net/base/cookie_monster_unittest.cc +++ b/net/base/cookie_monster_unittest.cc @@ -928,4 +928,21 @@ TEST(CookieMonsterTest, TestDeleteSingleCookie) { EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); } +TEST(CookieMonsterTest, SetCookieableSchemes) { + net::CookieMonster cm; + net::CookieMonster cm_foo; + + // Only cm_foo should allow foo:// cookies. + const char* kSchemes[] = {"foo"}; + cm_foo.SetCookieableSchemes(kSchemes, 1); + + GURL foo_url("foo://host/path"); + GURL http_url("http://host/path"); + + EXPECT_TRUE(cm.SetCookie(http_url, "x=1")); + EXPECT_FALSE(cm.SetCookie(foo_url, "x=1")); + EXPECT_TRUE(cm_foo.SetCookie(foo_url, "x=1")); + EXPECT_FALSE(cm_foo.SetCookie(http_url, "x=1")); +} + // TODO test overwrite cookie |