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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 GURL& cookie_domain); | 53 GURL& cookie_domain); |
54 | 54 |
55 // Used for tracking registrations to CookieMonster notifications. | 55 // Used for tracking registrations to CookieMonster notifications. |
56 content::NotificationRegistrar registrar_; | 56 content::NotificationRegistrar registrar_; |
57 | 57 |
58 Profile* profile_; | 58 Profile* profile_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(CookiesEventRouter); | 60 DISALLOW_COPY_AND_ASSIGN(CookiesEventRouter); |
61 }; | 61 }; |
62 | 62 |
63 // Serves as a base class for all cookies API functions, and defines some | |
64 // common functionality for parsing cookies API function arguments. | |
65 // Note that all of the functions in this file derive from | |
66 // AsyncExtensionFunction, and are not threadsafe, so they should not be | |
67 // concurrently accessed from multiple threads. They modify |result_| and other | |
68 // member variables directly. | |
69 // See extensions/browser/extension_function.h for more information. | |
70 class CookiesFunction : public ChromeAsyncExtensionFunction { | |
71 protected: | |
72 virtual ~CookiesFunction() {} | |
73 | |
74 // Constructs a GURL from the given url string. Returns false and assigns the | |
75 // internal error_ value if the URL is invalid. If |check_host_permissions| is | |
76 // true, the URL is also checked against the extension's host permissions, and | |
77 // if there is no permission for the URL, this function returns false. | |
78 bool ParseUrl(const std::string& url_string, GURL* url, | |
79 bool check_host_permissions); | |
80 | |
81 // Gets the store identified by |store_id| and returns it in |context|. | |
82 // If |store_id| contains an empty string, retrieves the current execution | |
83 // context's store. In this case, |store_id| is populated with the found | |
84 // store, and |context| can be NULL if the caller only wants |store_id|. | |
85 bool ParseStoreContext(std::string* store_id, | |
86 net::URLRequestContextGetter** context); | |
87 }; | |
88 | |
89 // Implements the cookies.get() extension function. | 63 // Implements the cookies.get() extension function. |
90 class CookiesGetFunction : public CookiesFunction { | 64 class CookiesGetFunction : public ChromeAsyncExtensionFunction { |
91 public: | 65 public: |
92 DECLARE_EXTENSION_FUNCTION("cookies.get", COOKIES_GET) | 66 DECLARE_EXTENSION_FUNCTION("cookies.get", COOKIES_GET) |
93 | 67 |
94 CookiesGetFunction(); | 68 CookiesGetFunction(); |
95 | 69 |
96 protected: | 70 protected: |
97 virtual ~CookiesGetFunction(); | 71 virtual ~CookiesGetFunction(); |
98 | 72 |
99 // ExtensionFunction: | 73 // ExtensionFunction: |
100 virtual bool RunImpl() OVERRIDE; | 74 virtual bool RunImpl() OVERRIDE; |
101 | 75 |
102 private: | 76 private: |
103 void GetCookieOnIOThread(); | 77 void GetCookieOnIOThread(); |
104 void RespondOnUIThread(); | 78 void RespondOnUIThread(); |
105 void GetCookieCallback(const net::CookieList& cookie_list); | 79 void GetCookieCallback(const net::CookieList& cookie_list); |
106 | 80 |
107 GURL url_; | 81 GURL url_; |
108 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 82 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
109 scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_; | 83 scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_; |
110 }; | 84 }; |
111 | 85 |
112 // Implements the cookies.getAll() extension function. | 86 // Implements the cookies.getAll() extension function. |
113 class CookiesGetAllFunction : public CookiesFunction { | 87 class CookiesGetAllFunction : public ChromeAsyncExtensionFunction { |
114 public: | 88 public: |
115 DECLARE_EXTENSION_FUNCTION("cookies.getAll", COOKIES_GETALL) | 89 DECLARE_EXTENSION_FUNCTION("cookies.getAll", COOKIES_GETALL) |
116 | 90 |
117 CookiesGetAllFunction(); | 91 CookiesGetAllFunction(); |
118 | 92 |
119 protected: | 93 protected: |
120 virtual ~CookiesGetAllFunction(); | 94 virtual ~CookiesGetAllFunction(); |
121 | 95 |
122 // ExtensionFunction: | 96 // ExtensionFunction: |
123 virtual bool RunImpl() OVERRIDE; | 97 virtual bool RunImpl() OVERRIDE; |
124 | 98 |
125 private: | 99 private: |
126 void GetAllCookiesOnIOThread(); | 100 void GetAllCookiesOnIOThread(); |
127 void RespondOnUIThread(); | 101 void RespondOnUIThread(); |
128 void GetAllCookiesCallback(const net::CookieList& cookie_list); | 102 void GetAllCookiesCallback(const net::CookieList& cookie_list); |
129 | 103 |
130 GURL url_; | 104 GURL url_; |
131 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 105 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
132 scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_; | 106 scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_; |
133 }; | 107 }; |
134 | 108 |
135 // Implements the cookies.set() extension function. | 109 // Implements the cookies.set() extension function. |
136 class CookiesSetFunction : public CookiesFunction { | 110 class CookiesSetFunction : public ChromeAsyncExtensionFunction { |
137 public: | 111 public: |
138 DECLARE_EXTENSION_FUNCTION("cookies.set", COOKIES_SET) | 112 DECLARE_EXTENSION_FUNCTION("cookies.set", COOKIES_SET) |
139 | 113 |
140 CookiesSetFunction(); | 114 CookiesSetFunction(); |
141 | 115 |
142 protected: | 116 protected: |
143 virtual ~CookiesSetFunction(); | 117 virtual ~CookiesSetFunction(); |
144 virtual bool RunImpl() OVERRIDE; | 118 virtual bool RunImpl() OVERRIDE; |
145 | 119 |
146 private: | 120 private: |
147 void SetCookieOnIOThread(); | 121 void SetCookieOnIOThread(); |
148 void RespondOnUIThread(); | 122 void RespondOnUIThread(); |
149 void PullCookie(bool set_cookie_); | 123 void PullCookie(bool set_cookie_); |
150 void PullCookieCallback(const net::CookieList& cookie_list); | 124 void PullCookieCallback(const net::CookieList& cookie_list); |
151 | 125 |
152 GURL url_; | 126 GURL url_; |
153 bool success_; | 127 bool success_; |
154 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 128 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
155 scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_; | 129 scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_; |
156 }; | 130 }; |
157 | 131 |
158 // Implements the cookies.remove() extension function. | 132 // Implements the cookies.remove() extension function. |
159 class CookiesRemoveFunction : public CookiesFunction { | 133 class CookiesRemoveFunction : public ChromeAsyncExtensionFunction { |
160 public: | 134 public: |
161 DECLARE_EXTENSION_FUNCTION("cookies.remove", COOKIES_REMOVE) | 135 DECLARE_EXTENSION_FUNCTION("cookies.remove", COOKIES_REMOVE) |
162 | 136 |
163 CookiesRemoveFunction(); | 137 CookiesRemoveFunction(); |
164 | 138 |
165 protected: | 139 protected: |
166 virtual ~CookiesRemoveFunction(); | 140 virtual ~CookiesRemoveFunction(); |
167 | 141 |
168 // ExtensionFunction: | 142 // ExtensionFunction: |
169 virtual bool RunImpl() OVERRIDE; | 143 virtual bool RunImpl() OVERRIDE; |
170 | 144 |
171 private: | 145 private: |
172 void RemoveCookieOnIOThread(); | 146 void RemoveCookieOnIOThread(); |
173 void RespondOnUIThread(); | 147 void RespondOnUIThread(); |
174 void RemoveCookieCallback(); | 148 void RemoveCookieCallback(); |
175 | 149 |
176 GURL url_; | 150 GURL url_; |
177 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 151 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
178 scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_; | 152 scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_; |
179 }; | 153 }; |
180 | 154 |
181 // Implements the cookies.getAllCookieStores() extension function. | 155 // Implements the cookies.getAllCookieStores() extension function. |
182 class CookiesGetAllCookieStoresFunction : public CookiesFunction { | 156 class CookiesGetAllCookieStoresFunction : public ChromeSyncExtensionFunction { |
183 public: | 157 public: |
184 DECLARE_EXTENSION_FUNCTION("cookies.getAllCookieStores", | 158 DECLARE_EXTENSION_FUNCTION("cookies.getAllCookieStores", |
185 COOKIES_GETALLCOOKIESTORES) | 159 COOKIES_GETALLCOOKIESTORES) |
186 | 160 |
187 protected: | 161 protected: |
188 virtual ~CookiesGetAllCookieStoresFunction() {} | 162 virtual ~CookiesGetAllCookieStoresFunction() {} |
189 | 163 |
190 // ExtensionFunction: | 164 // ExtensionFunction: |
191 // CookiesGetAllCookieStoresFunction is sync. | 165 virtual bool RunSync() OVERRIDE; |
192 virtual void Run() OVERRIDE; | |
193 virtual bool RunImpl() OVERRIDE; | |
194 }; | 166 }; |
195 | 167 |
196 class CookiesAPI : public BrowserContextKeyedAPI, | 168 class CookiesAPI : public BrowserContextKeyedAPI, |
197 public extensions::EventRouter::Observer { | 169 public extensions::EventRouter::Observer { |
198 public: | 170 public: |
199 explicit CookiesAPI(content::BrowserContext* context); | 171 explicit CookiesAPI(content::BrowserContext* context); |
200 virtual ~CookiesAPI(); | 172 virtual ~CookiesAPI(); |
201 | 173 |
202 // KeyedService implementation. | 174 // KeyedService implementation. |
203 virtual void Shutdown() OVERRIDE; | 175 virtual void Shutdown() OVERRIDE; |
(...skipping 18 matching lines...) Expand all Loading... |
222 | 194 |
223 // Created lazily upon OnListenerAdded. | 195 // Created lazily upon OnListenerAdded. |
224 scoped_ptr<CookiesEventRouter> cookies_event_router_; | 196 scoped_ptr<CookiesEventRouter> cookies_event_router_; |
225 | 197 |
226 DISALLOW_COPY_AND_ASSIGN(CookiesAPI); | 198 DISALLOW_COPY_AND_ASSIGN(CookiesAPI); |
227 }; | 199 }; |
228 | 200 |
229 } // namespace extensions | 201 } // namespace extensions |
230 | 202 |
231 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ | 203 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ |
OLD | NEW |