Chromium Code Reviews| 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 // Defines common functionality used by the implementation of the Chrome | 5 // Defines common functionality used by the implementation of the Chrome |
| 6 // Extensions Cookies API implemented in | 6 // Extensions Cookies API implemented in |
| 7 // chrome/browser/extensions/api/cookies/cookies_api.cc. This separate interface | 7 // chrome/browser/extensions/api/cookies/cookies_api.cc. This separate interface |
| 8 // exposes pieces of the API implementation mainly for unit testing purposes. | 8 // exposes pieces of the API implementation mainly for unit testing purposes. |
| 9 | 9 |
| 10 #ifndef CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ | 10 #ifndef CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ |
| 11 #define CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ | 11 #define CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/memory/linked_ptr.h" | |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "chrome/common/extensions/api/cookies.h" | 16 #include "chrome/common/extensions/api/cookies.h" |
| 19 #include "net/cookies/cookie_monster.h" | 17 #include "net/cookies/cookie_monster.h" |
| 20 #include "net/cookies/canonical_cookie.h" | 18 #include "net/cookies/canonical_cookie.h" |
| 21 | 19 |
| 22 class Browser; | 20 class Browser; |
| 23 class Profile; | 21 class Profile; |
| 24 | 22 |
| 25 namespace base { | 23 namespace base { |
| 26 class DictionaryValue; | 24 class DictionaryValue; |
| 27 class ListValue; | 25 class ListValue; |
| 28 } | 26 } |
| 29 | 27 |
| 30 namespace net { | 28 namespace net { |
| 31 class CanonicalCookie; | 29 class CanonicalCookie; |
| 32 } | 30 } |
| 33 | 31 |
| 34 namespace extensions { | 32 namespace extensions { |
| 35 | 33 |
| 36 class Extension; | 34 class Extension; |
| 37 | 35 |
| 38 namespace cookies_helpers { | 36 namespace cookies_helpers { |
| 39 | 37 |
| 40 typedef std::vector<linked_ptr<extensions::api::cookies::Cookie> > | |
| 41 LinkedCookieVec; | |
| 42 | |
| 43 // Returns either the original profile or the incognito profile, based on the | 38 // Returns either the original profile or the incognito profile, based on the |
| 44 // given store ID. Returns NULL if the profile doesn't exist or is not allowed | 39 // given store ID. Returns NULL if the profile doesn't exist or is not allowed |
| 45 // (e.g. if incognito mode is not enabled for the extension). | 40 // (e.g. if incognito mode is not enabled for the extension). |
| 46 Profile* ChooseProfileFromStoreId(const std::string& store_id, | 41 Profile* ChooseProfileFromStoreId(const std::string& store_id, |
| 47 Profile* profile, | 42 Profile* profile, |
| 48 bool include_incognito); | 43 bool include_incognito); |
| 49 | 44 |
| 50 // Returns the store ID for a particular user profile. | 45 // Returns the store ID for a particular user profile. |
| 51 const char* GetStoreIdFromProfile(Profile* profile); | 46 const char* GetStoreIdFromProfile(Profile* profile); |
| 52 | 47 |
| 53 // Allocates and construct a new Cookie object representing a cookie as defined | 48 // Allocates and construct a new Cookie object representing a cookie as defined |
|
asargent_no_longer_on_chrome
2016/03/23 19:54:25
"construct" should be "constructs", and I suppose
Devlin
2016/03/24 19:57:57
Done.
| |
| 54 // by the cookies API. | 49 // by the cookies API. |
| 55 scoped_ptr<extensions::api::cookies::Cookie> CreateCookie( | 50 api::cookies::Cookie CreateCookie(const net::CanonicalCookie& cookie, |
| 56 const net::CanonicalCookie& cookie, | 51 const std::string& store_id); |
| 57 const std::string& store_id); | |
| 58 | 52 |
| 59 // Allocates and constructs a new CookieStore object as defined by the cookies | 53 // Allocates and constructs a new CookieStore object as defined by the cookies |
|
asargent_no_longer_on_chrome
2016/03/23 19:54:25
same thing here re:Allocates
Devlin
2016/03/24 19:57:57
Done.
| |
| 60 // API. | 54 // API. |
| 61 scoped_ptr<extensions::api::cookies::CookieStore> CreateCookieStore( | 55 api::cookies::CookieStore CreateCookieStore(Profile* profile, |
| 62 Profile* profile, | 56 base::ListValue* tab_ids); |
| 63 base::ListValue* tab_ids); | |
| 64 | 57 |
| 65 // Retrieves all cookies from the given cookie store corresponding to the given | 58 // Retrieves all cookies from the given cookie store corresponding to the given |
| 66 // URL. If the URL is empty, all cookies in the cookie store are retrieved. | 59 // URL. If the URL is empty, all cookies in the cookie store are retrieved. |
| 67 // This can only be called on the IO thread. | 60 // This can only be called on the IO thread. |
| 68 void GetCookieListFromStore( | 61 void GetCookieListFromStore( |
| 69 net::CookieStore* cookie_store, const GURL& url, | 62 net::CookieStore* cookie_store, |
| 63 const GURL& url, | |
| 70 const net::CookieMonster::GetCookieListCallback& callback); | 64 const net::CookieMonster::GetCookieListCallback& callback); |
| 71 | 65 |
| 72 // Constructs a URL from a cookie's information for use in checking | 66 // Constructs a URL from a cookie's information for use in checking |
| 73 // a cookie against the extension's host permissions. The Secure | 67 // a cookie against the extension's host permissions. The Secure |
| 74 // property of the cookie defines the URL scheme, and the cookie's | 68 // property of the cookie defines the URL scheme, and the cookie's |
| 75 // domain becomes the URL host. | 69 // domain becomes the URL host. |
| 76 GURL GetURLFromCanonicalCookie( | 70 GURL GetURLFromCanonicalCookie( |
| 77 const net::CanonicalCookie& cookie); | 71 const net::CanonicalCookie& cookie); |
| 78 | 72 |
| 79 // Looks through all cookies in the given cookie store, and appends to the | 73 // Looks through all cookies in the given cookie store, and appends to the |
| 80 // match vector all the cookies that both match the given URL and cookie details | 74 // match vector all the cookies that both match the given URL and cookie details |
| 81 // and are allowed by extension host permissions. | 75 // and are allowed by extension host permissions. |
| 82 void AppendMatchingCookiesToVector( | 76 void AppendMatchingCookiesToVector( |
| 83 const net::CookieList& all_cookies, const GURL& url, | 77 const net::CookieList& all_cookies, |
| 84 const extensions::api::cookies::GetAll::Params::Details* details, | 78 const GURL& url, |
| 85 const Extension* extension, LinkedCookieVec* match_vector); | 79 const api::cookies::GetAll::Params::Details* details, |
| 80 const Extension* extension, | |
| 81 std::vector<api::cookies::Cookie>* match_vector); | |
| 86 | 82 |
| 87 // Appends the IDs of all tabs belonging to the given browser to the | 83 // Appends the IDs of all tabs belonging to the given browser to the |
| 88 // given list. | 84 // given list. |
| 89 void AppendToTabIdList(Browser* browser, base::ListValue* tab_ids); | 85 void AppendToTabIdList(Browser* browser, base::ListValue* tab_ids); |
| 90 | 86 |
| 91 // A class representing the cookie filter parameters passed into | 87 // A class representing the cookie filter parameters passed into |
| 92 // cookies.getAll(). | 88 // cookies.getAll(). |
| 93 // This class is essentially a convenience wrapper for the details dictionary | 89 // This class is essentially a convenience wrapper for the details dictionary |
| 94 // passed into the cookies.getAll() API by the user. If the dictionary contains | 90 // passed into the cookies.getAll() API by the user. If the dictionary contains |
| 95 // no filter parameters, the MatchFilter will always trivially | 91 // no filter parameters, the MatchFilter will always trivially |
| 96 // match all cookies. | 92 // match all cookies. |
| 97 class MatchFilter { | 93 class MatchFilter { |
| 98 public: | 94 public: |
| 99 // Takes the details dictionary argument given by the user as input. | 95 // Takes the details dictionary argument given by the user as input. |
| 100 // This class does not take ownership of the lifetime of the Details | 96 // This class does not take ownership of the lifetime of the Details |
| 101 // object. | 97 // object. |
| 102 explicit MatchFilter( | 98 explicit MatchFilter(const api::cookies::GetAll::Params::Details* details); |
| 103 const extensions::api::cookies::GetAll::Params::Details* details); | |
| 104 | 99 |
| 105 // Returns true if the given cookie matches the properties in the match | 100 // Returns true if the given cookie matches the properties in the match |
| 106 // filter. | 101 // filter. |
| 107 bool MatchesCookie(const net::CanonicalCookie& cookie); | 102 bool MatchesCookie(const net::CanonicalCookie& cookie); |
| 108 | 103 |
| 109 private: | 104 private: |
| 110 // Returns true if the given cookie domain string matches the filter's | 105 // Returns true if the given cookie domain string matches the filter's |
| 111 // domain. Any cookie domain which is equal to or is a subdomain of the | 106 // domain. Any cookie domain which is equal to or is a subdomain of the |
| 112 // filter's domain will be matched; leading '.' characters indicating | 107 // filter's domain will be matched; leading '.' characters indicating |
| 113 // host-only domains have no meaning in the match filter domain (for | 108 // host-only domains have no meaning in the match filter domain (for |
| 114 // instance, a match filter domain of 'foo.bar.com' will be treated the same | 109 // instance, a match filter domain of 'foo.bar.com' will be treated the same |
| 115 // as '.foo.bar.com', and both will match cookies with domain values of | 110 // as '.foo.bar.com', and both will match cookies with domain values of |
| 116 // 'foo.bar.com', '.foo.bar.com', and 'baz.foo.bar.com'. | 111 // 'foo.bar.com', '.foo.bar.com', and 'baz.foo.bar.com'. |
| 117 bool MatchesDomain(const std::string& domain); | 112 bool MatchesDomain(const std::string& domain); |
| 118 | 113 |
| 119 const extensions::api::cookies::GetAll::Params::Details* details_; | 114 const api::cookies::GetAll::Params::Details* details_; |
| 120 }; | 115 }; |
| 121 | 116 |
| 122 } // namespace cookies_helpers | 117 } // namespace cookies_helpers |
| 123 } // namespace extensions | 118 } // namespace extensions |
| 124 | 119 |
| 125 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ | 120 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ |
| OLD | NEW |