| 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 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 980 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
| 981 | 981 |
| 982 DoCookieTaskForURL(task, url); | 982 DoCookieTaskForURL(task, url); |
| 983 } | 983 } |
| 984 | 984 |
| 985 void CookieMonster::GetAllCookiesForURLAsync( | 985 void CookieMonster::GetAllCookiesForURLAsync( |
| 986 const GURL& url, | 986 const GURL& url, |
| 987 const GetCookieListCallback& callback) { | 987 const GetCookieListCallback& callback) { |
| 988 CookieOptions options; | 988 CookieOptions options; |
| 989 options.set_include_httponly(); | 989 options.set_include_httponly(); |
| 990 options.set_include_first_party_only(); | 990 options.set_include_first_party_only_cookies(); |
| 991 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 991 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
| 992 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 992 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
| 993 | 993 |
| 994 DoCookieTaskForURL(task, url); | 994 DoCookieTaskForURL(task, url); |
| 995 } | 995 } |
| 996 | 996 |
| 997 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { | 997 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { |
| 998 scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); | 998 scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); |
| 999 | 999 |
| 1000 DoCookieTask(task); | 1000 DoCookieTask(task); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 scoped_ptr<CanonicalCookie> cc; | 1156 scoped_ptr<CanonicalCookie> cc; |
| 1157 cc.reset(CanonicalCookie::Create( | 1157 cc.reset(CanonicalCookie::Create( |
| 1158 url, name, value, domain, path, creation_time, expiration_time, secure, | 1158 url, name, value, domain, path, creation_time, expiration_time, secure, |
| 1159 http_only, first_party_only, enforce_strict_secure, priority)); | 1159 http_only, first_party_only, enforce_strict_secure, priority)); |
| 1160 | 1160 |
| 1161 if (!cc.get()) | 1161 if (!cc.get()) |
| 1162 return false; | 1162 return false; |
| 1163 | 1163 |
| 1164 CookieOptions options; | 1164 CookieOptions options; |
| 1165 options.set_include_httponly(); | 1165 options.set_include_httponly(); |
| 1166 options.set_include_first_party_only(); | 1166 options.set_include_first_party_only_cookies(); |
| 1167 if (enforce_strict_secure) | 1167 if (enforce_strict_secure) |
| 1168 options.set_enforce_strict_secure(); | 1168 options.set_enforce_strict_secure(); |
| 1169 return SetCanonicalCookie(&cc, creation_time, options); | 1169 return SetCanonicalCookie(&cc, creation_time, options); |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 bool CookieMonster::ImportCookies(const CookieList& list) { | 1172 bool CookieMonster::ImportCookies(const CookieList& list) { |
| 1173 base::AutoLock autolock(lock_); | 1173 base::AutoLock autolock(lock_); |
| 1174 MarkCookieStoreAsInitialized(); | 1174 MarkCookieStoreAsInitialized(); |
| 1175 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) | 1175 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) |
| 1176 FetchAllCookiesIfNecessary(); | 1176 FetchAllCookiesIfNecessary(); |
| 1177 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); | 1177 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); |
| 1178 ++iter) { | 1178 ++iter) { |
| 1179 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); | 1179 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); |
| 1180 CookieOptions options; | 1180 CookieOptions options; |
| 1181 options.set_include_httponly(); | 1181 options.set_include_httponly(); |
| 1182 options.set_include_first_party_only(); | 1182 options.set_include_first_party_only_cookies(); |
| 1183 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) | 1183 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) |
| 1184 return false; | 1184 return false; |
| 1185 } | 1185 } |
| 1186 return true; | 1186 return true; |
| 1187 } | 1187 } |
| 1188 | 1188 |
| 1189 CookieList CookieMonster::GetAllCookies() { | 1189 CookieList CookieMonster::GetAllCookies() { |
| 1190 base::AutoLock autolock(lock_); | 1190 base::AutoLock autolock(lock_); |
| 1191 | 1191 |
| 1192 // This function is being called to scrape the cookie list for management UI | 1192 // 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... |
| 1385 | 1385 |
| 1386 void CookieMonster::DeleteCookie(const GURL& url, | 1386 void CookieMonster::DeleteCookie(const GURL& url, |
| 1387 const std::string& cookie_name) { | 1387 const std::string& cookie_name) { |
| 1388 base::AutoLock autolock(lock_); | 1388 base::AutoLock autolock(lock_); |
| 1389 | 1389 |
| 1390 if (!HasCookieableScheme(url)) | 1390 if (!HasCookieableScheme(url)) |
| 1391 return; | 1391 return; |
| 1392 | 1392 |
| 1393 CookieOptions options; | 1393 CookieOptions options; |
| 1394 options.set_include_httponly(); | 1394 options.set_include_httponly(); |
| 1395 options.set_include_first_party_only(); | 1395 options.set_include_first_party_only_cookies(); |
| 1396 // Get the cookies for this host and its domain(s). | 1396 // Get the cookies for this host and its domain(s). |
| 1397 std::vector<CanonicalCookie*> cookies; | 1397 std::vector<CanonicalCookie*> cookies; |
| 1398 FindCookiesForHostAndDomain(url, options, true, &cookies); | 1398 FindCookiesForHostAndDomain(url, options, true, &cookies); |
| 1399 std::set<CanonicalCookie*> matching_cookies; | 1399 std::set<CanonicalCookie*> matching_cookies; |
| 1400 | 1400 |
| 1401 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); | 1401 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); |
| 1402 it != cookies.end(); ++it) { | 1402 it != cookies.end(); ++it) { |
| 1403 if ((*it)->Name() != cookie_name) | 1403 if ((*it)->Name() != cookie_name) |
| 1404 continue; | 1404 continue; |
| 1405 if (url.path().find((*it)->Path())) | 1405 if (url.path().find((*it)->Path())) |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 : kDefaultCookieableSchemesCount - 1; | 2477 : kDefaultCookieableSchemesCount - 1; |
| 2478 | 2478 |
| 2479 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); | 2479 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); |
| 2480 } | 2480 } |
| 2481 #endif | 2481 #endif |
| 2482 | 2482 |
| 2483 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { | 2483 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { |
| 2484 lock_.AssertAcquired(); | 2484 lock_.AssertAcquired(); |
| 2485 CookieOptions opts; | 2485 CookieOptions opts; |
| 2486 opts.set_include_httponly(); | 2486 opts.set_include_httponly(); |
| 2487 opts.set_include_first_party_only(); | 2487 opts.set_include_first_party_only_cookies(); |
| 2488 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they | 2488 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they |
| 2489 // are guaranteed to not take long - they just post a RunAsync task back to | 2489 // are guaranteed to not take long - they just post a RunAsync task back to |
| 2490 // the appropriate thread's message loop and return. It is important that this | 2490 // the appropriate thread's message loop and return. It is important that this |
| 2491 // method not run user-supplied callbacks directly, since the CookieMonster | 2491 // method not run user-supplied callbacks directly, since the CookieMonster |
| 2492 // lock is held and it is easy to accidentally introduce deadlocks. | 2492 // lock is held and it is easy to accidentally introduce deadlocks. |
| 2493 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2493 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
| 2494 it != hook_map_.end(); ++it) { | 2494 it != hook_map_.end(); ++it) { |
| 2495 std::pair<GURL, std::string> key = it->first; | 2495 std::pair<GURL, std::string> key = it->first; |
| 2496 if (cookie.IncludeForRequestURL(key.first, opts) && | 2496 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2497 cookie.Name() == key.second) { | 2497 cookie.Name() == key.second) { |
| 2498 it->second->Notify(cookie, removed); | 2498 it->second->Notify(cookie, removed); |
| 2499 } | 2499 } |
| 2500 } | 2500 } |
| 2501 } | 2501 } |
| 2502 | 2502 |
| 2503 } // namespace net | 2503 } // namespace net |
| OLD | NEW |