OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 962 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
963 | 963 |
964 DoCookieTaskForURL(task, url); | 964 DoCookieTaskForURL(task, url); |
965 } | 965 } |
966 | 966 |
967 void CookieMonster::GetAllCookiesForURLAsync( | 967 void CookieMonster::GetAllCookiesForURLAsync( |
968 const GURL& url, | 968 const GURL& url, |
969 const GetCookieListCallback& callback) { | 969 const GetCookieListCallback& callback) { |
970 CookieOptions options; | 970 CookieOptions options; |
971 options.set_include_httponly(); | 971 options.set_include_httponly(); |
972 options.set_include_first_party_only(); | 972 options.set_include_first_party_only_cookies(); |
973 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 973 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
974 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 974 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
975 | 975 |
976 DoCookieTaskForURL(task, url); | 976 DoCookieTaskForURL(task, url); |
977 } | 977 } |
978 | 978 |
979 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { | 979 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { |
980 scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); | 980 scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); |
981 | 981 |
982 DoCookieTask(task); | 982 DoCookieTask(task); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 scoped_ptr<CanonicalCookie> cc; | 1137 scoped_ptr<CanonicalCookie> cc; |
1138 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, | 1138 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, |
1139 creation_time, expiration_time, secure, | 1139 creation_time, expiration_time, secure, |
1140 http_only, first_party_only, priority)); | 1140 http_only, first_party_only, priority)); |
1141 | 1141 |
1142 if (!cc.get()) | 1142 if (!cc.get()) |
1143 return false; | 1143 return false; |
1144 | 1144 |
1145 CookieOptions options; | 1145 CookieOptions options; |
1146 options.set_include_httponly(); | 1146 options.set_include_httponly(); |
1147 options.set_include_first_party_only(); | 1147 options.set_include_first_party_only_cookies(); |
1148 if (enforce_prefixes) | 1148 if (enforce_prefixes) |
1149 options.set_enforce_prefixes(); | 1149 options.set_enforce_prefixes(); |
1150 return SetCanonicalCookie(&cc, creation_time, options); | 1150 return SetCanonicalCookie(&cc, creation_time, options); |
1151 } | 1151 } |
1152 | 1152 |
1153 bool CookieMonster::ImportCookies(const CookieList& list) { | 1153 bool CookieMonster::ImportCookies(const CookieList& list) { |
1154 base::AutoLock autolock(lock_); | 1154 base::AutoLock autolock(lock_); |
1155 MarkCookieStoreAsInitialized(); | 1155 MarkCookieStoreAsInitialized(); |
1156 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) | 1156 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) |
1157 FetchAllCookiesIfNecessary(); | 1157 FetchAllCookiesIfNecessary(); |
1158 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); | 1158 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); |
1159 ++iter) { | 1159 ++iter) { |
1160 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); | 1160 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); |
1161 CookieOptions options; | 1161 CookieOptions options; |
1162 options.set_include_httponly(); | 1162 options.set_include_httponly(); |
1163 options.set_include_first_party_only(); | 1163 options.set_include_first_party_only_cookies(); |
1164 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) | 1164 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) |
1165 return false; | 1165 return false; |
1166 } | 1166 } |
1167 return true; | 1167 return true; |
1168 } | 1168 } |
1169 | 1169 |
1170 CookieList CookieMonster::GetAllCookies() { | 1170 CookieList CookieMonster::GetAllCookies() { |
1171 base::AutoLock autolock(lock_); | 1171 base::AutoLock autolock(lock_); |
1172 | 1172 |
1173 // This function is being called to scrape the cookie list for management UI | 1173 // This function is being called to scrape the cookie list for management UI |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 | 1366 |
1367 void CookieMonster::DeleteCookie(const GURL& url, | 1367 void CookieMonster::DeleteCookie(const GURL& url, |
1368 const std::string& cookie_name) { | 1368 const std::string& cookie_name) { |
1369 base::AutoLock autolock(lock_); | 1369 base::AutoLock autolock(lock_); |
1370 | 1370 |
1371 if (!HasCookieableScheme(url)) | 1371 if (!HasCookieableScheme(url)) |
1372 return; | 1372 return; |
1373 | 1373 |
1374 CookieOptions options; | 1374 CookieOptions options; |
1375 options.set_include_httponly(); | 1375 options.set_include_httponly(); |
1376 options.set_include_first_party_only(); | 1376 options.set_include_first_party_only_cookies(); |
1377 // Get the cookies for this host and its domain(s). | 1377 // Get the cookies for this host and its domain(s). |
1378 std::vector<CanonicalCookie*> cookies; | 1378 std::vector<CanonicalCookie*> cookies; |
1379 FindCookiesForHostAndDomain(url, options, true, &cookies); | 1379 FindCookiesForHostAndDomain(url, options, true, &cookies); |
1380 std::set<CanonicalCookie*> matching_cookies; | 1380 std::set<CanonicalCookie*> matching_cookies; |
1381 | 1381 |
1382 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); | 1382 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); |
1383 it != cookies.end(); ++it) { | 1383 it != cookies.end(); ++it) { |
1384 if ((*it)->Name() != cookie_name) | 1384 if ((*it)->Name() != cookie_name) |
1385 continue; | 1385 continue; |
1386 if (url.path().find((*it)->Path())) | 1386 if (url.path().find((*it)->Path())) |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 : kDefaultCookieableSchemesCount - 1; | 2351 : kDefaultCookieableSchemesCount - 1; |
2352 | 2352 |
2353 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); | 2353 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); |
2354 } | 2354 } |
2355 #endif | 2355 #endif |
2356 | 2356 |
2357 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { | 2357 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { |
2358 lock_.AssertAcquired(); | 2358 lock_.AssertAcquired(); |
2359 CookieOptions opts; | 2359 CookieOptions opts; |
2360 opts.set_include_httponly(); | 2360 opts.set_include_httponly(); |
2361 opts.set_include_first_party_only(); | 2361 opts.set_include_first_party_only_cookies(); |
2362 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they | 2362 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they |
2363 // are guaranteed to not take long - they just post a RunAsync task back to | 2363 // are guaranteed to not take long - they just post a RunAsync task back to |
2364 // the appropriate thread's message loop and return. It is important that this | 2364 // the appropriate thread's message loop and return. It is important that this |
2365 // method not run user-supplied callbacks directly, since the CookieMonster | 2365 // method not run user-supplied callbacks directly, since the CookieMonster |
2366 // lock is held and it is easy to accidentally introduce deadlocks. | 2366 // lock is held and it is easy to accidentally introduce deadlocks. |
2367 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2367 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
2368 it != hook_map_.end(); ++it) { | 2368 it != hook_map_.end(); ++it) { |
2369 std::pair<GURL, std::string> key = it->first; | 2369 std::pair<GURL, std::string> key = it->first; |
2370 if (cookie.IncludeForRequestURL(key.first, opts) && | 2370 if (cookie.IncludeForRequestURL(key.first, opts) && |
2371 cookie.Name() == key.second) { | 2371 cookie.Name() == key.second) { |
2372 it->second->Notify(cookie, removed); | 2372 it->second->Notify(cookie, removed); |
2373 } | 2373 } |
2374 } | 2374 } |
2375 } | 2375 } |
2376 | 2376 |
2377 } // namespace net | 2377 } // namespace net |
OLD | NEW |