| 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 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action
.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action
.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const char kEmptyDocumentUrl[] = "data:text/html,"; | 39 const char kEmptyDocumentUrl[] = "data:text/html,"; |
| 40 | 40 |
| 41 #define INPUT_FORMAT_VALIDATE(test) do { \ | 41 #define INPUT_FORMAT_VALIDATE(test) do { \ |
| 42 if (!(test)) { \ | 42 if (!(test)) { \ |
| 43 *bad_message = true; \ | 43 *bad_message = true; \ |
| 44 return scoped_refptr<const WebRequestAction>(NULL); \ | 44 return scoped_refptr<const WebRequestAction>(NULL); \ |
| 45 } \ | 45 } \ |
| 46 } while (0) | 46 } while (0) |
| 47 | 47 |
| 48 scoped_ptr<helpers::RequestCookie> ParseRequestCookie( | 48 scoped_ptr<helpers::RequestCookie> ParseRequestCookie( |
| 49 const DictionaryValue* dict) { | 49 const base::DictionaryValue* dict) { |
| 50 scoped_ptr<helpers::RequestCookie> result(new helpers::RequestCookie); | 50 scoped_ptr<helpers::RequestCookie> result(new helpers::RequestCookie); |
| 51 std::string tmp; | 51 std::string tmp; |
| 52 if (dict->GetString(keys::kNameKey, &tmp)) | 52 if (dict->GetString(keys::kNameKey, &tmp)) |
| 53 result->name.reset(new std::string(tmp)); | 53 result->name.reset(new std::string(tmp)); |
| 54 if (dict->GetString(keys::kValueKey, &tmp)) | 54 if (dict->GetString(keys::kValueKey, &tmp)) |
| 55 result->value.reset(new std::string(tmp)); | 55 result->value.reset(new std::string(tmp)); |
| 56 return result.Pass(); | 56 return result.Pass(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void ParseResponseCookieImpl(const DictionaryValue* dict, | 59 void ParseResponseCookieImpl(const base::DictionaryValue* dict, |
| 60 helpers::ResponseCookie* cookie) { | 60 helpers::ResponseCookie* cookie) { |
| 61 std::string string_tmp; | 61 std::string string_tmp; |
| 62 int int_tmp = 0; | 62 int int_tmp = 0; |
| 63 bool bool_tmp = false; | 63 bool bool_tmp = false; |
| 64 if (dict->GetString(keys::kNameKey, &string_tmp)) | 64 if (dict->GetString(keys::kNameKey, &string_tmp)) |
| 65 cookie->name.reset(new std::string(string_tmp)); | 65 cookie->name.reset(new std::string(string_tmp)); |
| 66 if (dict->GetString(keys::kValueKey, &string_tmp)) | 66 if (dict->GetString(keys::kValueKey, &string_tmp)) |
| 67 cookie->value.reset(new std::string(string_tmp)); | 67 cookie->value.reset(new std::string(string_tmp)); |
| 68 if (dict->GetString(keys::kExpiresKey, &string_tmp)) | 68 if (dict->GetString(keys::kExpiresKey, &string_tmp)) |
| 69 cookie->expires.reset(new std::string(string_tmp)); | 69 cookie->expires.reset(new std::string(string_tmp)); |
| 70 if (dict->GetInteger(keys::kMaxAgeKey, &int_tmp)) | 70 if (dict->GetInteger(keys::kMaxAgeKey, &int_tmp)) |
| 71 cookie->max_age.reset(new int(int_tmp)); | 71 cookie->max_age.reset(new int(int_tmp)); |
| 72 if (dict->GetString(keys::kDomainKey, &string_tmp)) | 72 if (dict->GetString(keys::kDomainKey, &string_tmp)) |
| 73 cookie->domain.reset(new std::string(string_tmp)); | 73 cookie->domain.reset(new std::string(string_tmp)); |
| 74 if (dict->GetString(keys::kPathKey, &string_tmp)) | 74 if (dict->GetString(keys::kPathKey, &string_tmp)) |
| 75 cookie->path.reset(new std::string(string_tmp)); | 75 cookie->path.reset(new std::string(string_tmp)); |
| 76 if (dict->GetBoolean(keys::kSecureKey, &bool_tmp)) | 76 if (dict->GetBoolean(keys::kSecureKey, &bool_tmp)) |
| 77 cookie->secure.reset(new bool(bool_tmp)); | 77 cookie->secure.reset(new bool(bool_tmp)); |
| 78 if (dict->GetBoolean(keys::kHttpOnlyKey, &bool_tmp)) | 78 if (dict->GetBoolean(keys::kHttpOnlyKey, &bool_tmp)) |
| 79 cookie->http_only.reset(new bool(bool_tmp)); | 79 cookie->http_only.reset(new bool(bool_tmp)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 scoped_ptr<helpers::ResponseCookie> ParseResponseCookie( | 82 scoped_ptr<helpers::ResponseCookie> ParseResponseCookie( |
| 83 const DictionaryValue* dict) { | 83 const base::DictionaryValue* dict) { |
| 84 scoped_ptr<helpers::ResponseCookie> result(new helpers::ResponseCookie); | 84 scoped_ptr<helpers::ResponseCookie> result(new helpers::ResponseCookie); |
| 85 ParseResponseCookieImpl(dict, result.get()); | 85 ParseResponseCookieImpl(dict, result.get()); |
| 86 return result.Pass(); | 86 return result.Pass(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 scoped_ptr<helpers::FilterResponseCookie> ParseFilterResponseCookie( | 89 scoped_ptr<helpers::FilterResponseCookie> ParseFilterResponseCookie( |
| 90 const DictionaryValue* dict) { | 90 const base::DictionaryValue* dict) { |
| 91 scoped_ptr<helpers::FilterResponseCookie> result( | 91 scoped_ptr<helpers::FilterResponseCookie> result( |
| 92 new helpers::FilterResponseCookie); | 92 new helpers::FilterResponseCookie); |
| 93 ParseResponseCookieImpl(dict, result.get()); | 93 ParseResponseCookieImpl(dict, result.get()); |
| 94 | 94 |
| 95 int int_tmp = 0; | 95 int int_tmp = 0; |
| 96 bool bool_tmp = false; | 96 bool bool_tmp = false; |
| 97 if (dict->GetInteger(keys::kAgeUpperBoundKey, &int_tmp)) | 97 if (dict->GetInteger(keys::kAgeUpperBoundKey, &int_tmp)) |
| 98 result->age_upper_bound.reset(new int(int_tmp)); | 98 result->age_upper_bound.reset(new int(int_tmp)); |
| 99 if (dict->GetInteger(keys::kAgeLowerBoundKey, &int_tmp)) | 99 if (dict->GetInteger(keys::kAgeLowerBoundKey, &int_tmp)) |
| 100 result->age_lower_bound.reset(new int(int_tmp)); | 100 result->age_lower_bound.reset(new int(int_tmp)); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 else if (instance_type == keys::kEditRequestCookieType) | 259 else if (instance_type == keys::kEditRequestCookieType) |
| 260 modification->type = helpers::EDIT; | 260 modification->type = helpers::EDIT; |
| 261 else if (instance_type == keys::kRemoveRequestCookieType) | 261 else if (instance_type == keys::kRemoveRequestCookieType) |
| 262 modification->type = helpers::REMOVE; | 262 modification->type = helpers::REMOVE; |
| 263 else | 263 else |
| 264 INPUT_FORMAT_VALIDATE(false); | 264 INPUT_FORMAT_VALIDATE(false); |
| 265 | 265 |
| 266 // Get filter. | 266 // Get filter. |
| 267 if (modification->type == helpers::EDIT || | 267 if (modification->type == helpers::EDIT || |
| 268 modification->type == helpers::REMOVE) { | 268 modification->type == helpers::REMOVE) { |
| 269 const DictionaryValue* filter = NULL; | 269 const base::DictionaryValue* filter = NULL; |
| 270 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kFilterKey, &filter)); | 270 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kFilterKey, &filter)); |
| 271 modification->filter = ParseRequestCookie(filter); | 271 modification->filter = ParseRequestCookie(filter); |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Get new value. | 274 // Get new value. |
| 275 if (modification->type == helpers::ADD) { | 275 if (modification->type == helpers::ADD) { |
| 276 const DictionaryValue* value = NULL; | 276 const base::DictionaryValue* value = NULL; |
| 277 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kCookieKey, &value)); | 277 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kCookieKey, &value)); |
| 278 modification->modification = ParseRequestCookie(value); | 278 modification->modification = ParseRequestCookie(value); |
| 279 } else if (modification->type == helpers::EDIT) { | 279 } else if (modification->type == helpers::EDIT) { |
| 280 const DictionaryValue* value = NULL; | 280 const base::DictionaryValue* value = NULL; |
| 281 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kModificationKey, &value)); | 281 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kModificationKey, &value)); |
| 282 modification->modification = ParseRequestCookie(value); | 282 modification->modification = ParseRequestCookie(value); |
| 283 } | 283 } |
| 284 | 284 |
| 285 return scoped_refptr<const WebRequestAction>( | 285 return scoped_refptr<const WebRequestAction>( |
| 286 new WebRequestRequestCookieAction(modification)); | 286 new WebRequestRequestCookieAction(modification)); |
| 287 } | 287 } |
| 288 | 288 |
| 289 scoped_refptr<const WebRequestAction> CreateResponseCookieAction( | 289 scoped_refptr<const WebRequestAction> CreateResponseCookieAction( |
| 290 const std::string& instance_type, | 290 const std::string& instance_type, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 305 else if (instance_type == keys::kEditResponseCookieType) | 305 else if (instance_type == keys::kEditResponseCookieType) |
| 306 modification->type = helpers::EDIT; | 306 modification->type = helpers::EDIT; |
| 307 else if (instance_type == keys::kRemoveResponseCookieType) | 307 else if (instance_type == keys::kRemoveResponseCookieType) |
| 308 modification->type = helpers::REMOVE; | 308 modification->type = helpers::REMOVE; |
| 309 else | 309 else |
| 310 INPUT_FORMAT_VALIDATE(false); | 310 INPUT_FORMAT_VALIDATE(false); |
| 311 | 311 |
| 312 // Get filter. | 312 // Get filter. |
| 313 if (modification->type == helpers::EDIT || | 313 if (modification->type == helpers::EDIT || |
| 314 modification->type == helpers::REMOVE) { | 314 modification->type == helpers::REMOVE) { |
| 315 const DictionaryValue* filter = NULL; | 315 const base::DictionaryValue* filter = NULL; |
| 316 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kFilterKey, &filter)); | 316 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kFilterKey, &filter)); |
| 317 modification->filter = ParseFilterResponseCookie(filter); | 317 modification->filter = ParseFilterResponseCookie(filter); |
| 318 } | 318 } |
| 319 | 319 |
| 320 // Get new value. | 320 // Get new value. |
| 321 if (modification->type == helpers::ADD) { | 321 if (modification->type == helpers::ADD) { |
| 322 const DictionaryValue* value = NULL; | 322 const base::DictionaryValue* value = NULL; |
| 323 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kCookieKey, &value)); | 323 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kCookieKey, &value)); |
| 324 modification->modification = ParseResponseCookie(value); | 324 modification->modification = ParseResponseCookie(value); |
| 325 } else if (modification->type == helpers::EDIT) { | 325 } else if (modification->type == helpers::EDIT) { |
| 326 const DictionaryValue* value = NULL; | 326 const base::DictionaryValue* value = NULL; |
| 327 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kModificationKey, &value)); | 327 INPUT_FORMAT_VALIDATE(dict->GetDictionary(keys::kModificationKey, &value)); |
| 328 modification->modification = ParseResponseCookie(value); | 328 modification->modification = ParseResponseCookie(value); |
| 329 } | 329 } |
| 330 | 330 |
| 331 return scoped_refptr<const WebRequestAction>( | 331 return scoped_refptr<const WebRequestAction>( |
| 332 new WebRequestResponseCookieAction(modification)); | 332 new WebRequestResponseCookieAction(modification)); |
| 333 } | 333 } |
| 334 | 334 |
| 335 scoped_refptr<const WebRequestAction> CreateSendMessageToExtensionAction( | 335 scoped_refptr<const WebRequestAction> CreateSendMessageToExtensionAction( |
| 336 const std::string& name, | 336 const std::string& name, |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 const base::Time& extension_install_time) const { | 1112 const base::Time& extension_install_time) const { |
| 1113 CHECK(request_data.stage & stages()); | 1113 CHECK(request_data.stage & stages()); |
| 1114 LinkedPtrEventResponseDelta result( | 1114 LinkedPtrEventResponseDelta result( |
| 1115 new extension_web_request_api_helpers::EventResponseDelta( | 1115 new extension_web_request_api_helpers::EventResponseDelta( |
| 1116 extension_id, extension_install_time)); | 1116 extension_id, extension_install_time)); |
| 1117 result->messages_to_extension.insert(message_); | 1117 result->messages_to_extension.insert(message_); |
| 1118 return result; | 1118 return result; |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 } // namespace extensions | 1121 } // namespace extensions |
| OLD | NEW |