| 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 | 14 |
| 15 #include "net/cookies/cookie_monster.h" | 15 #include "net/cookies/cookie_monster.h" |
| 16 | 16 |
| 17 class Browser; | 17 class Browser; |
| 18 class Profile; | 18 class Profile; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 class ListValue; | 22 class ListValue; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace net { |
| 26 class CanonicalCookie; |
| 27 } |
| 28 |
| 25 namespace extensions { | 29 namespace extensions { |
| 26 | 30 |
| 27 class Extension; | 31 class Extension; |
| 28 | 32 |
| 29 namespace cookies_helpers { | 33 namespace cookies_helpers { |
| 30 | 34 |
| 31 // Returns either the original profile or the incognito profile, based on the | 35 // Returns either the original profile or the incognito profile, based on the |
| 32 // given store ID. Returns NULL if the profile doesn't exist or is not allowed | 36 // given store ID. Returns NULL if the profile doesn't exist or is not allowed |
| 33 // (e.g. if incognito mode is not enabled for the extension). | 37 // (e.g. if incognito mode is not enabled for the extension). |
| 34 Profile* ChooseProfileFromStoreId(const std::string& store_id, | 38 Profile* ChooseProfileFromStoreId(const std::string& store_id, |
| 35 Profile* profile, | 39 Profile* profile, |
| 36 bool include_incognito); | 40 bool include_incognito); |
| 37 | 41 |
| 38 // Returns the store ID for a particular user profile. | 42 // Returns the store ID for a particular user profile. |
| 39 const char* GetStoreIdFromProfile(Profile* profile); | 43 const char* GetStoreIdFromProfile(Profile* profile); |
| 40 | 44 |
| 41 // Constructs a Cookie object as defined by the cookies API. This function | 45 // Constructs a Cookie object as defined by the cookies API. This function |
| 42 // allocates a new DictionaryValue object; the caller is responsible for | 46 // allocates a new DictionaryValue object; the caller is responsible for |
| 43 // freeing it. | 47 // freeing it. |
| 44 base::DictionaryValue* CreateCookieValue( | 48 base::DictionaryValue* CreateCookieValue(const net::CanonicalCookie& cookie, |
| 45 const net::CookieMonster::CanonicalCookie& cookie, | 49 const std::string& store_id); |
| 46 const std::string& store_id); | |
| 47 | 50 |
| 48 // Constructs a CookieStore object as defined by the cookies API. This function | 51 // Constructs a CookieStore object as defined by the cookies API. This function |
| 49 // allocates a new DictionaryValue object; the caller is responsible for | 52 // allocates a new DictionaryValue object; the caller is responsible for |
| 50 // freeing it. | 53 // freeing it. |
| 51 base::DictionaryValue* CreateCookieStoreValue(Profile* profile, | 54 base::DictionaryValue* CreateCookieStoreValue(Profile* profile, |
| 52 base::ListValue* tab_ids); | 55 base::ListValue* tab_ids); |
| 53 | 56 |
| 54 // Retrieves all cookies from the given cookie store corresponding to the given | 57 // Retrieves all cookies from the given cookie store corresponding to the given |
| 55 // URL. If the URL is empty, all cookies in the cookie store are retrieved. | 58 // URL. If the URL is empty, all cookies in the cookie store are retrieved. |
| 56 // This can only be called on the IO thread. | 59 // This can only be called on the IO thread. |
| 57 void GetCookieListFromStore( | 60 void GetCookieListFromStore( |
| 58 net::CookieStore* cookie_store, const GURL& url, | 61 net::CookieStore* cookie_store, const GURL& url, |
| 59 const net::CookieMonster::GetCookieListCallback& callback); | 62 const net::CookieMonster::GetCookieListCallback& callback); |
| 60 | 63 |
| 61 // Constructs a URL from a cookie's information for use in checking | 64 // Constructs a URL from a cookie's information for use in checking |
| 62 // a cookie against the extension's host permissions. The Secure | 65 // a cookie against the extension's host permissions. The Secure |
| 63 // property of the cookie defines the URL scheme, and the cookie's | 66 // property of the cookie defines the URL scheme, and the cookie's |
| 64 // domain becomes the URL host. | 67 // domain becomes the URL host. |
| 65 GURL GetURLFromCanonicalCookie( | 68 GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie); |
| 66 const net::CookieMonster::CanonicalCookie& cookie); | |
| 67 | 69 |
| 68 // Looks through all cookies in the given cookie store, and appends to the | 70 // Looks through all cookies in the given cookie store, and appends to the |
| 69 // match list all the cookies that both match the given URL and cookie details | 71 // match list all the cookies that both match the given URL and cookie details |
| 70 // and are allowed by extension host permissions. | 72 // and are allowed by extension host permissions. |
| 71 void AppendMatchingCookiesToList( | 73 void AppendMatchingCookiesToList( |
| 72 const net::CookieList& all_cookies, | 74 const net::CookieList& all_cookies, |
| 73 const std::string& store_id, | 75 const std::string& store_id, |
| 74 const GURL& url, const base::DictionaryValue* details, | 76 const GURL& url, const base::DictionaryValue* details, |
| 75 const Extension* extension, | 77 const Extension* extension, |
| 76 base::ListValue* match_list); | 78 base::ListValue* match_list); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 // match all cookies. | 89 // match all cookies. |
| 88 class MatchFilter { | 90 class MatchFilter { |
| 89 public: | 91 public: |
| 90 // Takes the details dictionary argument given by the user as input. | 92 // Takes the details dictionary argument given by the user as input. |
| 91 // This class does not take ownership of the lifetime of the DictionaryValue | 93 // This class does not take ownership of the lifetime of the DictionaryValue |
| 92 // object. | 94 // object. |
| 93 explicit MatchFilter(const base::DictionaryValue* details); | 95 explicit MatchFilter(const base::DictionaryValue* details); |
| 94 | 96 |
| 95 // Returns true if the given cookie matches the properties in the match | 97 // Returns true if the given cookie matches the properties in the match |
| 96 // filter. | 98 // filter. |
| 97 bool MatchesCookie(const net::CookieMonster::CanonicalCookie& cookie); | 99 bool MatchesCookie(const net::CanonicalCookie& cookie); |
| 98 | 100 |
| 99 private: | 101 private: |
| 100 // Returns true if the details dictionary contains a string with the given | 102 // Returns true if the details dictionary contains a string with the given |
| 101 // key and value. Also returns true if the dictionary doesn't contain the | 103 // key and value. Also returns true if the dictionary doesn't contain the |
| 102 // given key at all (trival match). | 104 // given key at all (trival match). |
| 103 bool MatchesString(const char* key, const std::string& value); | 105 bool MatchesString(const char* key, const std::string& value); |
| 104 | 106 |
| 105 // Returns true if the details dictionary contains a boolean with the given | 107 // Returns true if the details dictionary contains a boolean with the given |
| 106 // key and value. Also returns true if the dictionary doesn't contain the | 108 // key and value. Also returns true if the dictionary doesn't contain the |
| 107 // given key at all (trival match). | 109 // given key at all (trival match). |
| 108 bool MatchesBoolean(const char* key, bool value); | 110 bool MatchesBoolean(const char* key, bool value); |
| 109 | 111 |
| 110 // Returns true if the given cookie domain string matches the filter's | 112 // 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 | 113 // domain. Any cookie domain which is equal to or is a subdomain of the |
| 112 // filter's domain will be matched; leading '.' characters indicating | 114 // filter's domain will be matched; leading '.' characters indicating |
| 113 // host-only domains have no meaning in the match filter domain (for | 115 // 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 | 116 // 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 | 117 // 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'. | 118 // 'foo.bar.com', '.foo.bar.com', and 'baz.foo.bar.com'. |
| 117 bool MatchesDomain(const std::string& domain); | 119 bool MatchesDomain(const std::string& domain); |
| 118 | 120 |
| 119 const base::DictionaryValue* details_; | 121 const base::DictionaryValue* details_; |
| 120 }; | 122 }; |
| 121 | 123 |
| 122 } // namespace cookies_helpers | 124 } // namespace cookies_helpers |
| 123 } // namespace extensions | 125 } // namespace extensions |
| 124 | 126 |
| 125 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ | 127 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_ |
| OLD | NEW |