diff options
author | mmenke <mmenke@chromium.org> | 2016-02-01 10:42:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-01 18:43:52 +0000 |
commit | 18dd8baa0e72d8d144189094e206e672d6974379 (patch) | |
tree | c161c22f29848db74b5dd6ea82099be0c8eb07e7 /net/cookies | |
parent | 9313abf0d061aa68fd205bb22bf63bd5d039ae58 (diff) | |
download | chromium_src-18dd8baa0e72d8d144189094e206e672d6974379.zip chromium_src-18dd8baa0e72d8d144189094e206e672d6974379.tar.gz chromium_src-18dd8baa0e72d8d144189094e206e672d6974379.tar.bz2 |
Add an optional list of schemes to content::CookieConfig.
This reduces the number of components that have to call
GetCookieMonster to set the list.
Android Webview still depends on GetCookieMonster + setting
schemes. I'm thinking we'll eventually replace that by
lazily initializing the CookieStore on first access, with
a wrapper (We already need a cross-thread wrapper, so one
that also does lazy init isn't exactly a huge increase in
complexity).
Also removed CookieMonster::SetEnableFileScheme, which was
only declared on Android, for use by Webview. Webview now
explicitly sets all the schemes it wants instead.
TBR=phajdan.jr@chromium.org
BUG=579653
Review URL: https://codereview.chromium.org/1636383003
Cr-Commit-Position: refs/heads/master@{#372704}
Diffstat (limited to 'net/cookies')
-rw-r--r-- | net/cookies/cookie_monster.cc | 48 | ||||
-rw-r--r-- | net/cookies/cookie_monster.h | 18 | ||||
-rw-r--r-- | net/cookies/cookie_monster_unittest.cc | 5 |
3 files changed, 13 insertions, 58 deletions
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index 3d0dbad..18f26f8 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -356,8 +356,6 @@ void RunAsync(scoped_refptr<base::TaskRunner> proxy, CookieMonster::CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate) : CookieMonster(store, delegate, kDefaultAccessUpdateThresholdSeconds) { - InitializeHistograms(); - SetDefaultCookieableSchemes(); } CookieMonster::CookieMonster(PersistentCookieStore* store, @@ -375,7 +373,9 @@ CookieMonster::CookieMonster(PersistentCookieStore* store, keep_expired_cookies_(false), persist_session_cookies_(false) { InitializeHistograms(); - SetDefaultCookieableSchemes(); + cookieable_schemes_.insert( + cookieable_schemes_.begin(), kDefaultCookieableSchemes, + kDefaultCookieableSchemes + kDefaultCookieableSchemesCount); } bool CookieMonster::ImportCookies(const CookieList& list) { @@ -1102,19 +1102,16 @@ CookieMonster* CookieMonster::GetCookieMonster() { return this; } -void CookieMonster::SetCookieableSchemes(const char* const schemes[], - size_t num_schemes) { +void CookieMonster::SetCookieableSchemes( + const std::vector<std::string>& schemes) { base::AutoLock autolock(lock_); // Calls to this method will have no effect if made after a WebView or // CookieManager instance has been created. - if (initialized_) { + if (initialized_) return; - } - cookieable_schemes_.clear(); - cookieable_schemes_.insert(cookieable_schemes_.end(), schemes, - schemes + num_schemes); + cookieable_schemes_ = schemes; } void CookieMonster::SetKeepExpiredCookies() { @@ -1140,12 +1137,8 @@ bool CookieMonster::IsCookieableScheme(const std::string& scheme) { scheme) != cookieable_schemes_.end(); } -// Note: file must be the last scheme. -const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", - "https", - "ws", - "wss", - "file"}; +const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", "https", + "ws", "wss"}; const int CookieMonster::kDefaultCookieableSchemesCount = arraysize(kDefaultCookieableSchemes); @@ -1161,23 +1154,6 @@ CookieMonster::AddCallbackForCookie(const GURL& gurl, base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback)); } -#if defined(OS_ANDROID) -void CookieMonster::SetEnableFileScheme(bool accept) { - // This assumes "file" is always at the end of the array. See the comment - // above kDefaultCookieableSchemes. - // - // TODO(mkwst): We're keeping this method around to support the - // 'CookieManager::setAcceptFileSchemeCookies' method on Android's WebView; - // if/when we can deprecate and remove that method, we can remove this one - // as well. Until then, we'll just ensure that the method has no effect on - // non-android systems. - int num_schemes = accept ? kDefaultCookieableSchemesCount - : kDefaultCookieableSchemesCount - 1; - - SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); -} -#endif - CookieMonster::~CookieMonster() { DeleteAll(false); } @@ -1714,12 +1690,6 @@ void CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, DCHECK_EQ(num_duplicates, num_duplicates_found); } -void CookieMonster::SetDefaultCookieableSchemes() { - // Always disable file scheme unless SetEnableFileScheme(true) is called. - SetCookieableSchemes(kDefaultCookieableSchemes, - kDefaultCookieableSchemesCount - 1); -} - void CookieMonster::FindCookiesForHostAndDomain( const GURL& url, const CookieOptions& options, diff --git a/net/cookies/cookie_monster.h b/net/cookies/cookie_monster.h index b4feb9a..f41233c 100644 --- a/net/cookies/cookie_monster.h +++ b/net/cookies/cookie_monster.h @@ -230,7 +230,7 @@ class NET_EXPORT CookieMonster : public CookieStore { // Resets the list of cookieable schemes to the supplied schemes. Does // nothing if called after first use of the instance (i.e. after the // instance initialization process). - void SetCookieableSchemes(const char* const schemes[], size_t num_schemes); + void SetCookieableSchemes(const std::vector<std::string>& schemes); // Instructs the cookie monster to not delete expired cookies. This is used // in cases where the cookie monster is used as a data structure to keep @@ -258,22 +258,6 @@ class NET_EXPORT CookieMonster : public CookieStore { const std::string& name, const CookieChangedCallback& callback) override; -#if defined(OS_ANDROID) - // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or - // without 'file' being included. - // - // There are some unknowns about how to correctly handle file:// cookies, - // and our implementation for this is not robust enough (Bug 1157243). - // This allows you to enable support, and is exposed as a public WebView - // API ('CookieManager::setAcceptFileSchemeCookies'). - // - // TODO(mkwst): This method will be removed once we can deprecate and remove - // the Android WebView 'CookieManager::setAcceptFileSchemeCookies' method. - // Until then, this method only has effect on Android, and must not be used - // outside a WebView context. - void SetEnableFileScheme(bool accept); -#endif - private: // For queueing the cookie monster calls. class CookieMonsterTask; diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc index e862586..1361ae6 100644 --- a/net/cookies/cookie_monster_unittest.cc +++ b/net/cookies/cookie_monster_unittest.cc @@ -1331,8 +1331,9 @@ TEST_F(CookieMonsterTest, SetCookieableSchemes) { scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); // Only cm_foo should allow foo:// cookies. - const char* const kSchemes[] = {"foo"}; - cm_foo->SetCookieableSchemes(kSchemes, 1); + std::vector<std::string> schemes; + schemes.push_back("foo"); + cm_foo->SetCookieableSchemes(schemes); GURL foo_url("foo://host/path"); GURL http_url("http://host/path"); |