OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 chrome/common/extensions/api/extension_api.json. | 6 // cookies, as specified in chrome/common/extensions/api/extension_api.json. |
7 | 7 |
8 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_COOKIES_API_H_ | 8 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_COOKIES_API_H_ |
9 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_COOKIES_API_H_ | 9 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_COOKIES_API_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "chrome/browser/extensions/extension_function.h" | 16 #include "chrome/browser/extensions/extension_function.h" |
17 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
18 #include "content/common/notification_observer.h" | 18 #include "content/common/notification_observer.h" |
19 #include "content/common/notification_registrar.h" | 19 #include "content/common/notification_registrar.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "net/base/cookie_monster.h" | 21 #include "net/base/cookie_monster.h" |
22 | 22 |
| 23 namespace base { |
23 class DictionaryValue; | 24 class DictionaryValue; |
| 25 } |
24 | 26 |
25 namespace net { | 27 namespace net { |
26 class URLRequestContextGetter; | 28 class URLRequestContextGetter; |
27 } | 29 } |
28 | 30 |
29 // Observes CookieMonster notifications and routes them as events to the | 31 // Observes CookieMonster notifications and routes them as events to the |
30 // extension system. | 32 // extension system. |
31 class ExtensionCookiesEventRouter : public NotificationObserver { | 33 class ExtensionCookiesEventRouter : public NotificationObserver { |
32 public: | 34 public: |
33 explicit ExtensionCookiesEventRouter(Profile* profile); | 35 explicit ExtensionCookiesEventRouter(Profile* profile); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // concurrently accessed from multiple threads. They modify |result_| and other | 69 // concurrently accessed from multiple threads. They modify |result_| and other |
68 // member variables directly. | 70 // member variables directly. |
69 // See chrome/browser/extensions/extension_function.h for more information. | 71 // See chrome/browser/extensions/extension_function.h for more information. |
70 class CookiesFunction : public AsyncExtensionFunction { | 72 class CookiesFunction : public AsyncExtensionFunction { |
71 protected: | 73 protected: |
72 // Looks for a 'url' value in the given details dictionary and constructs a | 74 // Looks for a 'url' value in the given details dictionary and constructs a |
73 // GURL from it. Returns false and assigns the internal error_ value if the | 75 // GURL from it. Returns false and assigns the internal error_ value if the |
74 // URL is invalid or isn't found in the dictionary. If check_host_permissions | 76 // URL is invalid or isn't found in the dictionary. If check_host_permissions |
75 // is true, the URL is also checked against the extension's host permissions, | 77 // is true, the URL is also checked against the extension's host permissions, |
76 // and if there is no permission for the URL, this function returns false. | 78 // and if there is no permission for the URL, this function returns false. |
77 bool ParseUrl(const DictionaryValue* details, GURL* url, | 79 bool ParseUrl(const base::DictionaryValue* details, GURL* url, |
78 bool check_host_permissions); | 80 bool check_host_permissions); |
79 | 81 |
80 // Checks the given details dictionary for a 'storeId' value, and retrieves | 82 // Checks the given details dictionary for a 'storeId' value, and retrieves |
81 // the cookie store context and the store ID associated with it. If the | 83 // the cookie store context and the store ID associated with it. If the |
82 // 'storeId' value isn't found in the dictionary, the current execution | 84 // 'storeId' value isn't found in the dictionary, the current execution |
83 // context's cookie store context is retrieved. Returns false on error and | 85 // context's cookie store context is retrieved. Returns false on error and |
84 // assigns the internal error_ value if that occurs. | 86 // assigns the internal error_ value if that occurs. |
85 // At least one of the output parameters store and store_id should be | 87 // At least one of the output parameters store and store_id should be |
86 // non-NULL. | 88 // non-NULL. |
87 bool ParseStoreContext(const DictionaryValue* details, | 89 bool ParseStoreContext(const base::DictionaryValue* details, |
88 net::URLRequestContextGetter** context, | 90 net::URLRequestContextGetter** context, |
89 std::string* store_id); | 91 std::string* store_id); |
90 }; | 92 }; |
91 | 93 |
92 // Implements the cookies.get() extension function. | 94 // Implements the cookies.get() extension function. |
93 class GetCookieFunction : public CookiesFunction { | 95 class GetCookieFunction : public CookiesFunction { |
94 public: | 96 public: |
95 GetCookieFunction(); | 97 GetCookieFunction(); |
96 virtual ~GetCookieFunction(); | 98 virtual ~GetCookieFunction(); |
97 virtual bool RunImpl(); | 99 virtual bool RunImpl(); |
(...skipping 14 matching lines...) Expand all Loading... |
112 public: | 114 public: |
113 GetAllCookiesFunction(); | 115 GetAllCookiesFunction(); |
114 virtual ~GetAllCookiesFunction(); | 116 virtual ~GetAllCookiesFunction(); |
115 virtual bool RunImpl(); | 117 virtual bool RunImpl(); |
116 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAll") | 118 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAll") |
117 | 119 |
118 private: | 120 private: |
119 void GetAllCookiesOnIOThread(); | 121 void GetAllCookiesOnIOThread(); |
120 void RespondOnUIThread(); | 122 void RespondOnUIThread(); |
121 | 123 |
122 DictionaryValue* details_; | 124 base::DictionaryValue* details_; |
123 GURL url_; | 125 GURL url_; |
124 std::string store_id_; | 126 std::string store_id_; |
125 scoped_refptr<net::URLRequestContextGetter> store_context_; | 127 scoped_refptr<net::URLRequestContextGetter> store_context_; |
126 }; | 128 }; |
127 | 129 |
128 // Implements the cookies.set() extension function. | 130 // Implements the cookies.set() extension function. |
129 class SetCookieFunction : public CookiesFunction { | 131 class SetCookieFunction : public CookiesFunction { |
130 public: | 132 public: |
131 SetCookieFunction(); | 133 SetCookieFunction(); |
132 virtual ~SetCookieFunction(); | 134 virtual ~SetCookieFunction(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Implements the cookies.getAllCookieStores() extension function. | 174 // Implements the cookies.getAllCookieStores() extension function. |
173 class GetAllCookieStoresFunction : public CookiesFunction { | 175 class GetAllCookieStoresFunction : public CookiesFunction { |
174 public: | 176 public: |
175 virtual bool RunImpl(); | 177 virtual bool RunImpl(); |
176 // GetAllCookieStoresFunction is sync. | 178 // GetAllCookieStoresFunction is sync. |
177 virtual void Run(); | 179 virtual void Run(); |
178 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAllCookieStores") | 180 DECLARE_EXTENSION_FUNCTION_NAME("cookies.getAllCookieStores") |
179 }; | 181 }; |
180 | 182 |
181 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_COOKIES_API_H_ | 183 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_COOKIES_API_H_ |
OLD | NEW |