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 the Chrome Extensions Cookies API functions for accessing internet | 5 // Defines the Chrome Extensions Cookies API functions for accessing internet |
6 // cookies, as specified in the extension API JSON. | 6 // cookies, as specified in the extension API JSON. |
7 | 7 |
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ | 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ |
9 #define CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ | 9 #define CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "chrome/browser/extensions/extension_function.h" | 17 #include "chrome/browser/extensions/extension_function.h" |
17 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 18 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 19 #include "chrome/common/extensions/api/cookies.h" |
18 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
20 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 class DictionaryValue; | 25 class DictionaryValue; |
24 } | 26 } |
25 | 27 |
26 namespace net { | 28 namespace net { |
27 class CookieList; | 29 class CookieList; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // common functionality for parsing cookies API function arguments. | 70 // common functionality for parsing cookies API function arguments. |
69 // Note that all of the functions in this file derive from | 71 // Note that all of the functions in this file derive from |
70 // AsyncExtensionFunction, and are not threadsafe, so they should not be | 72 // AsyncExtensionFunction, and are not threadsafe, so they should not be |
71 // concurrently accessed from multiple threads. They modify |result_| and other | 73 // concurrently accessed from multiple threads. They modify |result_| and other |
72 // member variables directly. | 74 // member variables directly. |
73 // See chrome/browser/extensions/extension_function.h for more information. | 75 // See chrome/browser/extensions/extension_function.h for more information. |
74 class CookiesFunction : public AsyncExtensionFunction { | 76 class CookiesFunction : public AsyncExtensionFunction { |
75 protected: | 77 protected: |
76 virtual ~CookiesFunction() {} | 78 virtual ~CookiesFunction() {} |
77 | 79 |
78 // Looks for a 'url' value in the given details dictionary and constructs a | 80 // Constructs a GURL from the given url string. Returns false and assigns the |
79 // GURL from it. Returns false and assigns the internal error_ value if the | 81 // internal error_ value if the URL is invalid. If |check_host_permissions| is |
80 // URL is invalid or isn't found in the dictionary. If check_host_permissions | 82 // true, the URL is also checked against the extension's host permissions, and |
81 // is true, the URL is also checked against the extension's host permissions, | 83 // if there is no permission for the URL, this function returns false. |
82 // and if there is no permission for the URL, this function returns false. | 84 bool ParseUrl(const std::string& url_string, GURL* url, |
83 bool ParseUrl(const base::DictionaryValue* details, GURL* url, | |
84 bool check_host_permissions); | 85 bool check_host_permissions); |
85 | 86 |
86 // Checks the given details dictionary for a 'storeId' value, and retrieves | 87 // Gets the store identified by |store_id| and returns it in |context|. |
87 // the cookie store context and the store ID associated with it. If the | 88 // If |store_id| contains an empty string, retrieves the current execution |
88 // 'storeId' value isn't found in the dictionary, the current execution | 89 // context's store. In this case, |store_id| is populated with the found |
89 // context's cookie store context is retrieved. Returns false on error and | 90 // store, and |context| can be NULL if the caller only wants |store_id|. |
90 // assigns the internal error_ value if that occurs. | 91 bool ParseStoreContext(std::string* store_id, |
91 // At least one of the output parameters store and store_id should be | 92 net::URLRequestContextGetter** context); |
92 // non-NULL. | |
93 bool ParseStoreContext(const base::DictionaryValue* details, | |
94 net::URLRequestContextGetter** context, | |
95 std::string* store_id); | |
96 }; | 93 }; |
97 | 94 |
98 // Implements the cookies.get() extension function. | 95 // Implements the cookies.get() extension function. |
99 class GetCookieFunction : public CookiesFunction { | 96 class GetCookieFunction : public CookiesFunction { |
100 public: | 97 public: |
101 DECLARE_EXTENSION_FUNCTION_NAME("cookies.get") | 98 DECLARE_EXTENSION_FUNCTION_NAME("cookies.get") |
102 | 99 |
103 GetCookieFunction(); | 100 GetCookieFunction(); |
104 | 101 |
105 protected: | 102 protected: |
106 virtual ~GetCookieFunction(); | 103 virtual ~GetCookieFunction(); |
107 | 104 |
108 // ExtensionFunction: | 105 // ExtensionFunction: |
109 virtual bool RunImpl() OVERRIDE; | 106 virtual bool RunImpl() OVERRIDE; |
110 | 107 |
111 private: | 108 private: |
112 void GetCookieOnIOThread(); | 109 void GetCookieOnIOThread(); |
113 void RespondOnUIThread(); | 110 void RespondOnUIThread(); |
114 void GetCookieCallback(const net::CookieList& cookie_list); | 111 void GetCookieCallback(const net::CookieList& cookie_list); |
115 | 112 |
116 std::string name_; | |
117 GURL url_; | 113 GURL url_; |
118 std::string store_id_; | |
119 scoped_refptr<net::URLRequestContextGetter> store_context_; | 114 scoped_refptr<net::URLRequestContextGetter> store_context_; |
| 115 scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_; |
120 }; | 116 }; |
121 | 117 |
122 // Implements the cookies.getAll() extension function. | 118 // Implements the cookies.getAll() extension function. |
123 class GetAllCookiesFunction : public CookiesFunction { | 119 class GetAllCookiesFunction : public CookiesFunction { |
124 public: | 120 public: |
125 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAll") | 121 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAll") |
126 | 122 |
127 GetAllCookiesFunction(); | 123 GetAllCookiesFunction(); |
128 | 124 |
129 protected: | 125 protected: |
130 virtual ~GetAllCookiesFunction(); | 126 virtual ~GetAllCookiesFunction(); |
131 | 127 |
132 // ExtensionFunction: | 128 // ExtensionFunction: |
133 virtual bool RunImpl() OVERRIDE; | 129 virtual bool RunImpl() OVERRIDE; |
134 | 130 |
135 private: | 131 private: |
136 void GetAllCookiesOnIOThread(); | 132 void GetAllCookiesOnIOThread(); |
137 void RespondOnUIThread(); | 133 void RespondOnUIThread(); |
138 void GetAllCookiesCallback(const net::CookieList& cookie_list); | 134 void GetAllCookiesCallback(const net::CookieList& cookie_list); |
139 | 135 |
140 base::DictionaryValue* details_; | |
141 GURL url_; | 136 GURL url_; |
142 std::string store_id_; | |
143 scoped_refptr<net::URLRequestContextGetter> store_context_; | 137 scoped_refptr<net::URLRequestContextGetter> store_context_; |
| 138 scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_; |
144 }; | 139 }; |
145 | 140 |
146 // Implements the cookies.set() extension function. | 141 // Implements the cookies.set() extension function. |
147 class SetCookieFunction : public CookiesFunction { | 142 class SetCookieFunction : public CookiesFunction { |
148 public: | 143 public: |
149 DECLARE_EXTENSION_FUNCTION_NAME("cookies.set") | 144 DECLARE_EXTENSION_FUNCTION_NAME("cookies.set") |
150 | 145 |
151 SetCookieFunction(); | 146 SetCookieFunction(); |
152 | 147 |
153 protected: | 148 protected: |
154 virtual ~SetCookieFunction(); | 149 virtual ~SetCookieFunction(); |
155 virtual bool RunImpl() OVERRIDE; | 150 virtual bool RunImpl() OVERRIDE; |
156 | 151 |
157 private: | 152 private: |
158 void SetCookieOnIOThread(); | 153 void SetCookieOnIOThread(); |
159 void RespondOnUIThread(); | 154 void RespondOnUIThread(); |
160 void PullCookie(bool set_cookie_); | 155 void PullCookie(bool set_cookie_); |
161 void PullCookieCallback(const net::CookieList& cookie_list); | 156 void PullCookieCallback(const net::CookieList& cookie_list); |
162 | 157 |
163 GURL url_; | 158 GURL url_; |
164 std::string name_; | |
165 std::string value_; | |
166 std::string domain_; | |
167 std::string path_; | |
168 bool secure_; | |
169 bool http_only_; | |
170 base::Time expiration_time_; | |
171 bool success_; | 159 bool success_; |
172 std::string store_id_; | |
173 scoped_refptr<net::URLRequestContextGetter> store_context_; | 160 scoped_refptr<net::URLRequestContextGetter> store_context_; |
| 161 scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_; |
174 }; | 162 }; |
175 | 163 |
176 // Implements the cookies.remove() extension function. | 164 // Implements the cookies.remove() extension function. |
177 class RemoveCookieFunction : public CookiesFunction { | 165 class RemoveCookieFunction : public CookiesFunction { |
178 public: | 166 public: |
179 DECLARE_EXTENSION_FUNCTION_NAME("cookies.remove") | 167 DECLARE_EXTENSION_FUNCTION_NAME("cookies.remove") |
180 | 168 |
181 RemoveCookieFunction(); | 169 RemoveCookieFunction(); |
182 | 170 |
183 protected: | 171 protected: |
184 virtual ~RemoveCookieFunction(); | 172 virtual ~RemoveCookieFunction(); |
185 | 173 |
186 // ExtensionFunction: | 174 // ExtensionFunction: |
187 virtual bool RunImpl() OVERRIDE; | 175 virtual bool RunImpl() OVERRIDE; |
188 | 176 |
189 private: | 177 private: |
190 void RemoveCookieOnIOThread(); | 178 void RemoveCookieOnIOThread(); |
191 void RespondOnUIThread(); | 179 void RespondOnUIThread(); |
192 void RemoveCookieCallback(); | 180 void RemoveCookieCallback(); |
193 | 181 |
194 GURL url_; | 182 GURL url_; |
195 std::string name_; | |
196 std::string store_id_; | |
197 scoped_refptr<net::URLRequestContextGetter> store_context_; | 183 scoped_refptr<net::URLRequestContextGetter> store_context_; |
| 184 scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_; |
198 }; | 185 }; |
199 | 186 |
200 // Implements the cookies.getAllCookieStores() extension function. | 187 // Implements the cookies.getAllCookieStores() extension function. |
201 class GetAllCookieStoresFunction : public CookiesFunction { | 188 class GetAllCookieStoresFunction : public CookiesFunction { |
202 public: | 189 public: |
203 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAllCookieStores") | 190 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAllCookieStores") |
204 | 191 |
205 protected: | 192 protected: |
206 virtual ~GetAllCookieStoresFunction() {} | 193 virtual ~GetAllCookieStoresFunction() {} |
207 | 194 |
208 // ExtensionFunction: | 195 // ExtensionFunction: |
209 // GetAllCookieStoresFunction is sync. | 196 // GetAllCookieStoresFunction is sync. |
210 virtual void Run() OVERRIDE; | 197 virtual void Run() OVERRIDE; |
211 virtual bool RunImpl() OVERRIDE; | 198 virtual bool RunImpl() OVERRIDE; |
212 }; | 199 }; |
213 | 200 |
214 } // namespace extensions | 201 } // namespace extensions |
215 | 202 |
216 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ | 203 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ |
OLD | NEW |