| 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 // Helper classes and functions used for the WebRequest API. | 5 // Helper classes and functions used for the WebRequest API. |
| 6 | 6 |
| 7 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ | 7 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ |
| 8 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ | 8 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <memory> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <string> | 13 #include <string> |
| 13 | 14 |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "content/public/common/resource_type.h" | 19 #include "content/public/common/resource_type.h" |
| 20 #include "extensions/browser/warning_set.h" | 20 #include "extensions/browser/warning_set.h" |
| 21 #include "net/base/auth.h" | 21 #include "net/base/auth.h" |
| 22 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
| 23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 class ListValue; | 27 class ListValue; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 static bool InitFromValue(const base::ListValue& value, int* extra_info_spec); | 61 static bool InitFromValue(const base::ListValue& value, int* extra_info_spec); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // Data container for RequestCookies as defined in the declarative WebRequest | 64 // Data container for RequestCookies as defined in the declarative WebRequest |
| 65 // API definition. | 65 // API definition. |
| 66 struct RequestCookie { | 66 struct RequestCookie { |
| 67 RequestCookie(); | 67 RequestCookie(); |
| 68 ~RequestCookie(); | 68 ~RequestCookie(); |
| 69 scoped_ptr<std::string> name; | 69 std::unique_ptr<std::string> name; |
| 70 scoped_ptr<std::string> value; | 70 std::unique_ptr<std::string> value; |
| 71 |
| 71 private: | 72 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(RequestCookie); | 73 DISALLOW_COPY_AND_ASSIGN(RequestCookie); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 bool NullableEquals(const RequestCookie* a, const RequestCookie* b); | 76 bool NullableEquals(const RequestCookie* a, const RequestCookie* b); |
| 76 | 77 |
| 77 // Data container for ResponseCookies as defined in the declarative WebRequest | 78 // Data container for ResponseCookies as defined in the declarative WebRequest |
| 78 // API definition. | 79 // API definition. |
| 79 struct ResponseCookie { | 80 struct ResponseCookie { |
| 80 ResponseCookie(); | 81 ResponseCookie(); |
| 81 ~ResponseCookie(); | 82 ~ResponseCookie(); |
| 82 scoped_ptr<std::string> name; | 83 std::unique_ptr<std::string> name; |
| 83 scoped_ptr<std::string> value; | 84 std::unique_ptr<std::string> value; |
| 84 scoped_ptr<std::string> expires; | 85 std::unique_ptr<std::string> expires; |
| 85 scoped_ptr<int> max_age; | 86 std::unique_ptr<int> max_age; |
| 86 scoped_ptr<std::string> domain; | 87 std::unique_ptr<std::string> domain; |
| 87 scoped_ptr<std::string> path; | 88 std::unique_ptr<std::string> path; |
| 88 scoped_ptr<bool> secure; | 89 std::unique_ptr<bool> secure; |
| 89 scoped_ptr<bool> http_only; | 90 std::unique_ptr<bool> http_only; |
| 91 |
| 90 private: | 92 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(ResponseCookie); | 93 DISALLOW_COPY_AND_ASSIGN(ResponseCookie); |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 bool NullableEquals(const ResponseCookie* a, const ResponseCookie* b); | 96 bool NullableEquals(const ResponseCookie* a, const ResponseCookie* b); |
| 95 | 97 |
| 96 // Data container for FilterResponseCookies as defined in the declarative | 98 // Data container for FilterResponseCookies as defined in the declarative |
| 97 // WebRequest API definition. | 99 // WebRequest API definition. |
| 98 struct FilterResponseCookie : ResponseCookie { | 100 struct FilterResponseCookie : ResponseCookie { |
| 99 FilterResponseCookie(); | 101 FilterResponseCookie(); |
| 100 ~FilterResponseCookie(); | 102 ~FilterResponseCookie(); |
| 101 scoped_ptr<int> age_lower_bound; | 103 std::unique_ptr<int> age_lower_bound; |
| 102 scoped_ptr<int> age_upper_bound; | 104 std::unique_ptr<int> age_upper_bound; |
| 103 scoped_ptr<bool> session_cookie; | 105 std::unique_ptr<bool> session_cookie; |
| 106 |
| 104 private: | 107 private: |
| 105 DISALLOW_COPY_AND_ASSIGN(FilterResponseCookie); | 108 DISALLOW_COPY_AND_ASSIGN(FilterResponseCookie); |
| 106 }; | 109 }; |
| 107 | 110 |
| 108 bool NullableEquals(const FilterResponseCookie* a, | 111 bool NullableEquals(const FilterResponseCookie* a, |
| 109 const FilterResponseCookie* b); | 112 const FilterResponseCookie* b); |
| 110 | 113 |
| 111 enum CookieModificationType { | 114 enum CookieModificationType { |
| 112 ADD, | 115 ADD, |
| 113 EDIT, | 116 EDIT, |
| 114 REMOVE, | 117 REMOVE, |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 struct RequestCookieModification { | 120 struct RequestCookieModification { |
| 118 RequestCookieModification(); | 121 RequestCookieModification(); |
| 119 ~RequestCookieModification(); | 122 ~RequestCookieModification(); |
| 120 CookieModificationType type; | 123 CookieModificationType type; |
| 121 // Used for EDIT and REMOVE. NULL for ADD. | 124 // Used for EDIT and REMOVE. NULL for ADD. |
| 122 scoped_ptr<RequestCookie> filter; | 125 std::unique_ptr<RequestCookie> filter; |
| 123 // Used for ADD and EDIT. NULL for REMOVE. | 126 // Used for ADD and EDIT. NULL for REMOVE. |
| 124 scoped_ptr<RequestCookie> modification; | 127 std::unique_ptr<RequestCookie> modification; |
| 128 |
| 125 private: | 129 private: |
| 126 DISALLOW_COPY_AND_ASSIGN(RequestCookieModification); | 130 DISALLOW_COPY_AND_ASSIGN(RequestCookieModification); |
| 127 }; | 131 }; |
| 128 | 132 |
| 129 bool NullableEquals(const RequestCookieModification* a, | 133 bool NullableEquals(const RequestCookieModification* a, |
| 130 const RequestCookieModification* b); | 134 const RequestCookieModification* b); |
| 131 | 135 |
| 132 struct ResponseCookieModification { | 136 struct ResponseCookieModification { |
| 133 ResponseCookieModification(); | 137 ResponseCookieModification(); |
| 134 ~ResponseCookieModification(); | 138 ~ResponseCookieModification(); |
| 135 CookieModificationType type; | 139 CookieModificationType type; |
| 136 // Used for EDIT and REMOVE. | 140 // Used for EDIT and REMOVE. |
| 137 scoped_ptr<FilterResponseCookie> filter; | 141 std::unique_ptr<FilterResponseCookie> filter; |
| 138 // Used for ADD and EDIT. | 142 // Used for ADD and EDIT. |
| 139 scoped_ptr<ResponseCookie> modification; | 143 std::unique_ptr<ResponseCookie> modification; |
| 144 |
| 140 private: | 145 private: |
| 141 DISALLOW_COPY_AND_ASSIGN(ResponseCookieModification); | 146 DISALLOW_COPY_AND_ASSIGN(ResponseCookieModification); |
| 142 }; | 147 }; |
| 143 | 148 |
| 144 bool NullableEquals(const ResponseCookieModification* a, | 149 bool NullableEquals(const ResponseCookieModification* a, |
| 145 const ResponseCookieModification* b); | 150 const ResponseCookieModification* b); |
| 146 | 151 |
| 147 typedef std::vector<linked_ptr<RequestCookieModification> > | 152 typedef std::vector<linked_ptr<RequestCookieModification> > |
| 148 RequestCookieModifications; | 153 RequestCookieModifications; |
| 149 typedef std::vector<linked_ptr<ResponseCookieModification> > | 154 typedef std::vector<linked_ptr<ResponseCookieModification> > |
| (...skipping 20 matching lines...) Expand all Loading... |
| 170 std::vector<std::string> deleted_request_headers; | 175 std::vector<std::string> deleted_request_headers; |
| 171 | 176 |
| 172 // Headers that were added to the response. A modification of a header | 177 // Headers that were added to the response. A modification of a header |
| 173 // corresponds to a deletion and subsequent addition of the new header. | 178 // corresponds to a deletion and subsequent addition of the new header. |
| 174 ResponseHeaders added_response_headers; | 179 ResponseHeaders added_response_headers; |
| 175 | 180 |
| 176 // Headers that were deleted from the response. | 181 // Headers that were deleted from the response. |
| 177 ResponseHeaders deleted_response_headers; | 182 ResponseHeaders deleted_response_headers; |
| 178 | 183 |
| 179 // Authentication Credentials to use. | 184 // Authentication Credentials to use. |
| 180 scoped_ptr<net::AuthCredentials> auth_credentials; | 185 std::unique_ptr<net::AuthCredentials> auth_credentials; |
| 181 | 186 |
| 182 // Modifications to cookies in request headers. | 187 // Modifications to cookies in request headers. |
| 183 RequestCookieModifications request_cookie_modifications; | 188 RequestCookieModifications request_cookie_modifications; |
| 184 | 189 |
| 185 // Modifications to cookies in response headers. | 190 // Modifications to cookies in response headers. |
| 186 ResponseCookieModifications response_cookie_modifications; | 191 ResponseCookieModifications response_cookie_modifications; |
| 187 | 192 |
| 188 // Messages that shall be sent to the background/event/... pages of the | 193 // Messages that shall be sent to the background/event/... pages of the |
| 189 // extension. | 194 // extension. |
| 190 std::set<std::string> messages_to_extension; | 195 std::set<std::string> messages_to_extension; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 bool cancel, | 241 bool cancel, |
| 237 const GURL& new_url, | 242 const GURL& new_url, |
| 238 const net::HttpResponseHeaders* old_response_headers, | 243 const net::HttpResponseHeaders* old_response_headers, |
| 239 ResponseHeaders* new_response_headers); | 244 ResponseHeaders* new_response_headers); |
| 240 // Destructively moves the auth credentials from |auth_credentials| to the | 245 // Destructively moves the auth credentials from |auth_credentials| to the |
| 241 // returned EventResponseDelta. | 246 // returned EventResponseDelta. |
| 242 EventResponseDelta* CalculateOnAuthRequiredDelta( | 247 EventResponseDelta* CalculateOnAuthRequiredDelta( |
| 243 const std::string& extension_id, | 248 const std::string& extension_id, |
| 244 const base::Time& extension_install_time, | 249 const base::Time& extension_install_time, |
| 245 bool cancel, | 250 bool cancel, |
| 246 scoped_ptr<net::AuthCredentials>* auth_credentials); | 251 std::unique_ptr<net::AuthCredentials>* auth_credentials); |
| 247 | 252 |
| 248 // These functions merge the responses (the |deltas|) of request handlers. | 253 // These functions merge the responses (the |deltas|) of request handlers. |
| 249 // The |deltas| need to be sorted in decreasing order of precedence of | 254 // The |deltas| need to be sorted in decreasing order of precedence of |
| 250 // extensions. In case extensions had |deltas| that could not be honored, their | 255 // extensions. In case extensions had |deltas| that could not be honored, their |
| 251 // IDs are reported in |conflicting_extensions|. NetLog events that shall be | 256 // IDs are reported in |conflicting_extensions|. NetLog events that shall be |
| 252 // reported will be stored in |event_log_entries|. | 257 // reported will be stored in |event_log_entries|. |
| 253 | 258 |
| 254 // Stores in |canceled| whether any extension wanted to cancel the request. | 259 // Stores in |canceled| whether any extension wanted to cancel the request. |
| 255 void MergeCancelOfResponses( | 260 void MergeCancelOfResponses( |
| 256 const EventResponseDeltas& deltas, | 261 const EventResponseDeltas& deltas, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 356 |
| 352 // Stores a |content::ResourceType| representation in |types| if |type_str| is | 357 // Stores a |content::ResourceType| representation in |types| if |type_str| is |
| 353 // a resource type handled by the web request API. Returns true in case of | 358 // a resource type handled by the web request API. Returns true in case of |
| 354 // success. | 359 // success. |
| 355 bool ParseResourceType(const std::string& type_str, | 360 bool ParseResourceType(const std::string& type_str, |
| 356 std::vector<content::ResourceType>* types); | 361 std::vector<content::ResourceType>* types); |
| 357 | 362 |
| 358 } // namespace extension_web_request_api_helpers | 363 } // namespace extension_web_request_api_helpers |
| 359 | 364 |
| 360 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ | 365 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ |
| OLD | NEW |