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 <memory> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "chrome/browser/extensions/chrome_extension_function.h" | 17 #include "chrome/browser/extensions/chrome_extension_function.h" |
18 #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" | 19 #include "chrome/common/extensions/api/cookies.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 #include "extensions/browser/browser_context_keyed_api_factory.h" | 22 #include "extensions/browser/browser_context_keyed_api_factory.h" |
23 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
24 #include "net/cookies/canonical_cookie.h" | 24 #include "net/cookies/canonical_cookie.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 | 26 |
(...skipping 17 matching lines...) Expand all Loading... |
44 const content::NotificationDetails& details) override; | 44 const content::NotificationDetails& details) override; |
45 | 45 |
46 // Handler for the COOKIE_CHANGED event. The method takes the details of such | 46 // Handler for the COOKIE_CHANGED event. The method takes the details of such |
47 // an event and constructs a suitable JSON formatted extension event from it. | 47 // an event and constructs a suitable JSON formatted extension event from it. |
48 void CookieChanged(Profile* profile, ChromeCookieDetails* details); | 48 void CookieChanged(Profile* profile, ChromeCookieDetails* details); |
49 | 49 |
50 // This method dispatches events to the extension message service. | 50 // This method dispatches events to the extension message service. |
51 void DispatchEvent(content::BrowserContext* context, | 51 void DispatchEvent(content::BrowserContext* context, |
52 events::HistogramValue histogram_value, | 52 events::HistogramValue histogram_value, |
53 const std::string& event_name, | 53 const std::string& event_name, |
54 scoped_ptr<base::ListValue> event_args, | 54 std::unique_ptr<base::ListValue> event_args, |
55 GURL& cookie_domain); | 55 GURL& cookie_domain); |
56 | 56 |
57 // Used for tracking registrations to CookieMonster notifications. | 57 // Used for tracking registrations to CookieMonster notifications. |
58 content::NotificationRegistrar registrar_; | 58 content::NotificationRegistrar registrar_; |
59 | 59 |
60 Profile* profile_; | 60 Profile* profile_; |
61 | 61 |
62 DISALLOW_COPY_AND_ASSIGN(CookiesEventRouter); | 62 DISALLOW_COPY_AND_ASSIGN(CookiesEventRouter); |
63 }; | 63 }; |
64 | 64 |
(...skipping 10 matching lines...) Expand all Loading... |
75 // ExtensionFunction: | 75 // ExtensionFunction: |
76 bool RunAsync() override; | 76 bool RunAsync() override; |
77 | 77 |
78 private: | 78 private: |
79 void GetCookieOnIOThread(); | 79 void GetCookieOnIOThread(); |
80 void RespondOnUIThread(); | 80 void RespondOnUIThread(); |
81 void GetCookieCallback(const net::CookieList& cookie_list); | 81 void GetCookieCallback(const net::CookieList& cookie_list); |
82 | 82 |
83 GURL url_; | 83 GURL url_; |
84 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 84 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
85 scoped_ptr<api::cookies::Get::Params> parsed_args_; | 85 std::unique_ptr<api::cookies::Get::Params> parsed_args_; |
86 }; | 86 }; |
87 | 87 |
88 // Implements the cookies.getAll() extension function. | 88 // Implements the cookies.getAll() extension function. |
89 class CookiesGetAllFunction : public ChromeAsyncExtensionFunction { | 89 class CookiesGetAllFunction : public ChromeAsyncExtensionFunction { |
90 public: | 90 public: |
91 DECLARE_EXTENSION_FUNCTION("cookies.getAll", COOKIES_GETALL) | 91 DECLARE_EXTENSION_FUNCTION("cookies.getAll", COOKIES_GETALL) |
92 | 92 |
93 CookiesGetAllFunction(); | 93 CookiesGetAllFunction(); |
94 | 94 |
95 protected: | 95 protected: |
96 ~CookiesGetAllFunction() override; | 96 ~CookiesGetAllFunction() override; |
97 | 97 |
98 // ExtensionFunction: | 98 // ExtensionFunction: |
99 bool RunAsync() override; | 99 bool RunAsync() override; |
100 | 100 |
101 private: | 101 private: |
102 void GetAllCookiesOnIOThread(); | 102 void GetAllCookiesOnIOThread(); |
103 void RespondOnUIThread(); | 103 void RespondOnUIThread(); |
104 void GetAllCookiesCallback(const net::CookieList& cookie_list); | 104 void GetAllCookiesCallback(const net::CookieList& cookie_list); |
105 | 105 |
106 GURL url_; | 106 GURL url_; |
107 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 107 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
108 scoped_ptr<api::cookies::GetAll::Params> parsed_args_; | 108 std::unique_ptr<api::cookies::GetAll::Params> parsed_args_; |
109 }; | 109 }; |
110 | 110 |
111 // Implements the cookies.set() extension function. | 111 // Implements the cookies.set() extension function. |
112 class CookiesSetFunction : public ChromeAsyncExtensionFunction { | 112 class CookiesSetFunction : public ChromeAsyncExtensionFunction { |
113 public: | 113 public: |
114 DECLARE_EXTENSION_FUNCTION("cookies.set", COOKIES_SET) | 114 DECLARE_EXTENSION_FUNCTION("cookies.set", COOKIES_SET) |
115 | 115 |
116 CookiesSetFunction(); | 116 CookiesSetFunction(); |
117 | 117 |
118 protected: | 118 protected: |
119 ~CookiesSetFunction() override; | 119 ~CookiesSetFunction() override; |
120 bool RunAsync() override; | 120 bool RunAsync() override; |
121 | 121 |
122 private: | 122 private: |
123 void SetCookieOnIOThread(); | 123 void SetCookieOnIOThread(); |
124 void RespondOnUIThread(); | 124 void RespondOnUIThread(); |
125 void PullCookie(bool set_cookie_); | 125 void PullCookie(bool set_cookie_); |
126 void PullCookieCallback(const net::CookieList& cookie_list); | 126 void PullCookieCallback(const net::CookieList& cookie_list); |
127 | 127 |
128 GURL url_; | 128 GURL url_; |
129 bool success_; | 129 bool success_; |
130 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 130 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
131 scoped_ptr<api::cookies::Set::Params> parsed_args_; | 131 std::unique_ptr<api::cookies::Set::Params> parsed_args_; |
132 }; | 132 }; |
133 | 133 |
134 // Implements the cookies.remove() extension function. | 134 // Implements the cookies.remove() extension function. |
135 class CookiesRemoveFunction : public ChromeAsyncExtensionFunction { | 135 class CookiesRemoveFunction : public ChromeAsyncExtensionFunction { |
136 public: | 136 public: |
137 DECLARE_EXTENSION_FUNCTION("cookies.remove", COOKIES_REMOVE) | 137 DECLARE_EXTENSION_FUNCTION("cookies.remove", COOKIES_REMOVE) |
138 | 138 |
139 CookiesRemoveFunction(); | 139 CookiesRemoveFunction(); |
140 | 140 |
141 protected: | 141 protected: |
142 ~CookiesRemoveFunction() override; | 142 ~CookiesRemoveFunction() override; |
143 | 143 |
144 // ExtensionFunction: | 144 // ExtensionFunction: |
145 bool RunAsync() override; | 145 bool RunAsync() override; |
146 | 146 |
147 private: | 147 private: |
148 void RemoveCookieOnIOThread(); | 148 void RemoveCookieOnIOThread(); |
149 void RespondOnUIThread(); | 149 void RespondOnUIThread(); |
150 void RemoveCookieCallback(); | 150 void RemoveCookieCallback(); |
151 | 151 |
152 GURL url_; | 152 GURL url_; |
153 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; | 153 scoped_refptr<net::URLRequestContextGetter> store_browser_context_; |
154 scoped_ptr<api::cookies::Remove::Params> parsed_args_; | 154 std::unique_ptr<api::cookies::Remove::Params> parsed_args_; |
155 }; | 155 }; |
156 | 156 |
157 // Implements the cookies.getAllCookieStores() extension function. | 157 // Implements the cookies.getAllCookieStores() extension function. |
158 class CookiesGetAllCookieStoresFunction : public ChromeSyncExtensionFunction { | 158 class CookiesGetAllCookieStoresFunction : public ChromeSyncExtensionFunction { |
159 public: | 159 public: |
160 DECLARE_EXTENSION_FUNCTION("cookies.getAllCookieStores", | 160 DECLARE_EXTENSION_FUNCTION("cookies.getAllCookieStores", |
161 COOKIES_GETALLCOOKIESTORES) | 161 COOKIES_GETALLCOOKIESTORES) |
162 | 162 |
163 protected: | 163 protected: |
164 ~CookiesGetAllCookieStoresFunction() override {} | 164 ~CookiesGetAllCookieStoresFunction() override {} |
(...skipping 21 matching lines...) Expand all Loading... |
186 | 186 |
187 content::BrowserContext* browser_context_; | 187 content::BrowserContext* browser_context_; |
188 | 188 |
189 // BrowserContextKeyedAPI implementation. | 189 // BrowserContextKeyedAPI implementation. |
190 static const char* service_name() { | 190 static const char* service_name() { |
191 return "CookiesAPI"; | 191 return "CookiesAPI"; |
192 } | 192 } |
193 static const bool kServiceIsNULLWhileTesting = true; | 193 static const bool kServiceIsNULLWhileTesting = true; |
194 | 194 |
195 // Created lazily upon OnListenerAdded. | 195 // Created lazily upon OnListenerAdded. |
196 scoped_ptr<CookiesEventRouter> cookies_event_router_; | 196 std::unique_ptr<CookiesEventRouter> cookies_event_router_; |
197 | 197 |
198 DISALLOW_COPY_AND_ASSIGN(CookiesAPI); | 198 DISALLOW_COPY_AND_ASSIGN(CookiesAPI); |
199 }; | 199 }; |
200 | 200 |
201 } // namespace extensions | 201 } // namespace extensions |
202 | 202 |
203 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ | 203 #endif // CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_API_H_ |
OLD | NEW |