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 15 matching lines...) Expand all Loading... |
26 namespace net { | 26 namespace net { |
27 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
28 } | 28 } |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 // Observes CookieMonster notifications and routes them as events to the | 32 // Observes CookieMonster notifications and routes them as events to the |
33 // extension system. | 33 // extension system. |
34 class CookiesEventRouter : public content::NotificationObserver { | 34 class CookiesEventRouter : public content::NotificationObserver { |
35 public: | 35 public: |
36 explicit CookiesEventRouter(Profile* profile); | 36 explicit CookiesEventRouter(content::BrowserContext* context); |
37 virtual ~CookiesEventRouter(); | 37 virtual ~CookiesEventRouter(); |
38 | 38 |
39 private: | 39 private: |
40 // content::NotificationObserver implementation. | 40 // content::NotificationObserver implementation. |
41 virtual void Observe(int type, | 41 virtual void Observe(int type, |
42 const content::NotificationSource& source, | 42 const content::NotificationSource& source, |
43 const content::NotificationDetails& details) OVERRIDE; | 43 const content::NotificationDetails& details) OVERRIDE; |
44 | 44 |
45 // Handler for the COOKIE_CHANGED event. The method takes the details of such | 45 // Handler for the COOKIE_CHANGED event. The method takes the details of such |
46 // an event and constructs a suitable JSON formatted extension event from it. | 46 // an event and constructs a suitable JSON formatted extension event from it. |
47 void CookieChanged(Profile* profile, ChromeCookieDetails* details); | 47 void CookieChanged(Profile* profile, ChromeCookieDetails* details); |
48 | 48 |
49 // This method dispatches events to the extension message service. | 49 // This method dispatches events to the extension message service. |
50 void DispatchEvent(Profile* context, | 50 void DispatchEvent(content::BrowserContext* context, |
51 const std::string& event_name, | 51 const std::string& event_name, |
52 scoped_ptr<base::ListValue> event_args, | 52 scoped_ptr<base::ListValue> event_args, |
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); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 // ExtensionFunction: | 99 // ExtensionFunction: |
100 virtual bool RunImpl() OVERRIDE; | 100 virtual bool RunImpl() OVERRIDE; |
101 | 101 |
102 private: | 102 private: |
103 void GetCookieOnIOThread(); | 103 void GetCookieOnIOThread(); |
104 void RespondOnUIThread(); | 104 void RespondOnUIThread(); |
105 void GetCookieCallback(const net::CookieList& cookie_list); | 105 void GetCookieCallback(const net::CookieList& cookie_list); |
106 | 106 |
107 GURL url_; | 107 GURL url_; |
108 scoped_refptr<net::URLRequestContextGetter> store_context_; | 108 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
109 scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_; | 109 scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_; |
110 }; | 110 }; |
111 | 111 |
112 // Implements the cookies.getAll() extension function. | 112 // Implements the cookies.getAll() extension function. |
113 class CookiesGetAllFunction : public CookiesFunction { | 113 class CookiesGetAllFunction : public CookiesFunction { |
114 public: | 114 public: |
115 DECLARE_EXTENSION_FUNCTION("cookies.getAll", COOKIES_GETALL) | 115 DECLARE_EXTENSION_FUNCTION("cookies.getAll", COOKIES_GETALL) |
116 | 116 |
117 CookiesGetAllFunction(); | 117 CookiesGetAllFunction(); |
118 | 118 |
119 protected: | 119 protected: |
120 virtual ~CookiesGetAllFunction(); | 120 virtual ~CookiesGetAllFunction(); |
121 | 121 |
122 // ExtensionFunction: | 122 // ExtensionFunction: |
123 virtual bool RunImpl() OVERRIDE; | 123 virtual bool RunImpl() OVERRIDE; |
124 | 124 |
125 private: | 125 private: |
126 void GetAllCookiesOnIOThread(); | 126 void GetAllCookiesOnIOThread(); |
127 void RespondOnUIThread(); | 127 void RespondOnUIThread(); |
128 void GetAllCookiesCallback(const net::CookieList& cookie_list); | 128 void GetAllCookiesCallback(const net::CookieList& cookie_list); |
129 | 129 |
130 GURL url_; | 130 GURL url_; |
131 scoped_refptr<net::URLRequestContextGetter> store_context_; | 131 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
132 scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_; | 132 scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_; |
133 }; | 133 }; |
134 | 134 |
135 // Implements the cookies.set() extension function. | 135 // Implements the cookies.set() extension function. |
136 class CookiesSetFunction : public CookiesFunction { | 136 class CookiesSetFunction : public CookiesFunction { |
137 public: | 137 public: |
138 DECLARE_EXTENSION_FUNCTION("cookies.set", COOKIES_SET) | 138 DECLARE_EXTENSION_FUNCTION("cookies.set", COOKIES_SET) |
139 | 139 |
140 CookiesSetFunction(); | 140 CookiesSetFunction(); |
141 | 141 |
142 protected: | 142 protected: |
143 virtual ~CookiesSetFunction(); | 143 virtual ~CookiesSetFunction(); |
144 virtual bool RunImpl() OVERRIDE; | 144 virtual bool RunImpl() OVERRIDE; |
145 | 145 |
146 private: | 146 private: |
147 void SetCookieOnIOThread(); | 147 void SetCookieOnIOThread(); |
148 void RespondOnUIThread(); | 148 void RespondOnUIThread(); |
149 void PullCookie(bool set_cookie_); | 149 void PullCookie(bool set_cookie_); |
150 void PullCookieCallback(const net::CookieList& cookie_list); | 150 void PullCookieCallback(const net::CookieList& cookie_list); |
151 | 151 |
152 GURL url_; | 152 GURL url_; |
153 bool success_; | 153 bool success_; |
154 scoped_refptr<net::URLRequestContextGetter> store_context_; | 154 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
155 scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_; | 155 scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_; |
156 }; | 156 }; |
157 | 157 |
158 // Implements the cookies.remove() extension function. | 158 // Implements the cookies.remove() extension function. |
159 class CookiesRemoveFunction : public CookiesFunction { | 159 class CookiesRemoveFunction : public CookiesFunction { |
160 public: | 160 public: |
161 DECLARE_EXTENSION_FUNCTION("cookies.remove", COOKIES_REMOVE) | 161 DECLARE_EXTENSION_FUNCTION("cookies.remove", COOKIES_REMOVE) |
162 | 162 |
163 CookiesRemoveFunction(); | 163 CookiesRemoveFunction(); |
164 | 164 |
165 protected: | 165 protected: |
166 virtual ~CookiesRemoveFunction(); | 166 virtual ~CookiesRemoveFunction(); |
167 | 167 |
168 // ExtensionFunction: | 168 // ExtensionFunction: |
169 virtual bool RunImpl() OVERRIDE; | 169 virtual bool RunImpl() OVERRIDE; |
170 | 170 |
171 private: | 171 private: |
172 void RemoveCookieOnIOThread(); | 172 void RemoveCookieOnIOThread(); |
173 void RespondOnUIThread(); | 173 void RespondOnUIThread(); |
174 void RemoveCookieCallback(); | 174 void RemoveCookieCallback(); |
175 | 175 |
176 GURL url_; | 176 GURL url_; |
177 scoped_refptr<net::URLRequestContextGetter> store_context_; | 177 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
178 scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_; | 178 scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_; |
179 }; | 179 }; |
180 | 180 |
181 // Implements the cookies.getAllCookieStores() extension function. | 181 // Implements the cookies.getAllCookieStores() extension function. |
182 class CookiesGetAllCookieStoresFunction : public CookiesFunction { | 182 class CookiesGetAllCookieStoresFunction : public CookiesFunction { |
183 public: | 183 public: |
184 DECLARE_EXTENSION_FUNCTION("cookies.getAllCookieStores", | 184 DECLARE_EXTENSION_FUNCTION("cookies.getAllCookieStores", |
185 COOKIES_GETALLCOOKIESTORES) | 185 COOKIES_GETALLCOOKIESTORES) |
186 | 186 |
187 protected: | 187 protected: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 222 |
223 // Created lazily upon OnListenerAdded. | 223 // Created lazily upon OnListenerAdded. |
224 scoped_ptr<CookiesEventRouter> cookies_event_router_; | 224 scoped_ptr<CookiesEventRouter> cookies_event_router_; |
225 | 225 |
226 DISALLOW_COPY_AND_ASSIGN(CookiesAPI); | 226 DISALLOW_COPY_AND_ASSIGN(CookiesAPI); |
227 }; | 227 }; |
228 | 228 |
229 } // namespace extensions | 229 } // namespace extensions |
230 | 230 |
231 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ | 231 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ |
OLD | NEW |