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