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 "extensions/browser/api/declarative_webrequest/webrequest_condition_att
ribute.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition_att
ribute.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 const base::ListValue* value_as_list = NULL; | 229 const base::ListValue* value_as_list = NULL; |
230 if (!value->GetAsList(&value_as_list)) { | 230 if (!value->GetAsList(&value_as_list)) { |
231 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); | 231 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); |
232 return scoped_refptr<const WebRequestConditionAttribute>(NULL); | 232 return scoped_refptr<const WebRequestConditionAttribute>(NULL); |
233 } | 233 } |
234 std::vector<std::string> content_types; | 234 std::vector<std::string> content_types; |
235 for (base::ListValue::const_iterator it = value_as_list->begin(); | 235 for (base::ListValue::const_iterator it = value_as_list->begin(); |
236 it != value_as_list->end(); ++it) { | 236 it != value_as_list->end(); ++it) { |
237 std::string content_type; | 237 std::string content_type; |
238 if (!(*it)->GetAsString(&content_type)) { | 238 if (!it->GetAsString(&content_type)) { |
239 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); | 239 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); |
240 return scoped_refptr<const WebRequestConditionAttribute>(NULL); | 240 return scoped_refptr<const WebRequestConditionAttribute>(NULL); |
241 } | 241 } |
242 content_types.push_back(content_type); | 242 content_types.push_back(content_type); |
243 } | 243 } |
244 | 244 |
245 return scoped_refptr<const WebRequestConditionAttribute>( | 245 return scoped_refptr<const WebRequestConditionAttribute>( |
246 new WebRequestConditionAttributeContentType( | 246 new WebRequestConditionAttributeContentType( |
247 content_types, name == keys::kContentTypeKey)); | 247 content_types, name == keys::kContentTypeKey)); |
248 } | 248 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 377 |
378 HeaderMatcher::~HeaderMatcher() {} | 378 HeaderMatcher::~HeaderMatcher() {} |
379 | 379 |
380 // static | 380 // static |
381 std::unique_ptr<const HeaderMatcher> HeaderMatcher::Create( | 381 std::unique_ptr<const HeaderMatcher> HeaderMatcher::Create( |
382 const base::ListValue* tests) { | 382 const base::ListValue* tests) { |
383 std::vector<std::unique_ptr<const HeaderMatchTest>> header_tests; | 383 std::vector<std::unique_ptr<const HeaderMatchTest>> header_tests; |
384 for (base::ListValue::const_iterator it = tests->begin(); | 384 for (base::ListValue::const_iterator it = tests->begin(); |
385 it != tests->end(); ++it) { | 385 it != tests->end(); ++it) { |
386 const base::DictionaryValue* tests = NULL; | 386 const base::DictionaryValue* tests = NULL; |
387 if (!(*it)->GetAsDictionary(&tests)) | 387 if (!it->GetAsDictionary(&tests)) |
388 return std::unique_ptr<const HeaderMatcher>(); | 388 return std::unique_ptr<const HeaderMatcher>(); |
389 | 389 |
390 std::unique_ptr<const HeaderMatchTest> header_test( | 390 std::unique_ptr<const HeaderMatchTest> header_test( |
391 HeaderMatchTest::Create(tests)); | 391 HeaderMatchTest::Create(tests)); |
392 if (header_test.get() == NULL) | 392 if (header_test.get() == NULL) |
393 return std::unique_ptr<const HeaderMatcher>(); | 393 return std::unique_ptr<const HeaderMatcher>(); |
394 header_tests.push_back(std::move(header_test)); | 394 header_tests.push_back(std::move(header_test)); |
395 } | 395 } |
396 | 396 |
397 return std::unique_ptr<const HeaderMatcher>( | 397 return std::unique_ptr<const HeaderMatcher>( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 } | 502 } |
503 const base::Value* content = &it.value(); | 503 const base::Value* content = &it.value(); |
504 | 504 |
505 std::vector<std::unique_ptr<const StringMatchTest>>* tests = | 505 std::vector<std::unique_ptr<const StringMatchTest>>* tests = |
506 is_name ? &name_match : &value_match; | 506 is_name ? &name_match : &value_match; |
507 switch (content->GetType()) { | 507 switch (content->GetType()) { |
508 case base::Value::Type::LIST: { | 508 case base::Value::Type::LIST: { |
509 const base::ListValue* list = NULL; | 509 const base::ListValue* list = NULL; |
510 CHECK(content->GetAsList(&list)); | 510 CHECK(content->GetAsList(&list)); |
511 for (const auto& it : *list) { | 511 for (const auto& it : *list) { |
512 tests->push_back(StringMatchTest::Create(*it, match_type, !is_name)); | 512 tests->push_back(StringMatchTest::Create(it, match_type, !is_name)); |
513 } | 513 } |
514 break; | 514 break; |
515 } | 515 } |
516 case base::Value::Type::STRING: { | 516 case base::Value::Type::STRING: { |
517 tests->push_back( | 517 tests->push_back( |
518 StringMatchTest::Create(*content, match_type, !is_name)); | 518 StringMatchTest::Create(*content, match_type, !is_name)); |
519 break; | 519 break; |
520 } | 520 } |
521 default: { | 521 default: { |
522 NOTREACHED(); // JSON schema type checking should prevent this. | 522 NOTREACHED(); // JSON schema type checking should prevent this. |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 // success, false otherwise. | 803 // success, false otherwise. |
804 bool ParseListOfStages(const base::Value& value, int* out_stages) { | 804 bool ParseListOfStages(const base::Value& value, int* out_stages) { |
805 const base::ListValue* list = NULL; | 805 const base::ListValue* list = NULL; |
806 if (!value.GetAsList(&list)) | 806 if (!value.GetAsList(&list)) |
807 return false; | 807 return false; |
808 | 808 |
809 int stages = 0; | 809 int stages = 0; |
810 std::string stage_name; | 810 std::string stage_name; |
811 for (base::ListValue::const_iterator it = list->begin(); | 811 for (base::ListValue::const_iterator it = list->begin(); |
812 it != list->end(); ++it) { | 812 it != list->end(); ++it) { |
813 if (!((*it)->GetAsString(&stage_name))) | 813 if (!(it->GetAsString(&stage_name))) |
814 return false; | 814 return false; |
815 if (stage_name == keys::kOnBeforeRequestEnum) { | 815 if (stage_name == keys::kOnBeforeRequestEnum) { |
816 stages |= ON_BEFORE_REQUEST; | 816 stages |= ON_BEFORE_REQUEST; |
817 } else if (stage_name == keys::kOnBeforeSendHeadersEnum) { | 817 } else if (stage_name == keys::kOnBeforeSendHeadersEnum) { |
818 stages |= ON_BEFORE_SEND_HEADERS; | 818 stages |= ON_BEFORE_SEND_HEADERS; |
819 } else if (stage_name == keys::kOnHeadersReceivedEnum) { | 819 } else if (stage_name == keys::kOnHeadersReceivedEnum) { |
820 stages |= ON_HEADERS_RECEIVED; | 820 stages |= ON_HEADERS_RECEIVED; |
821 } else if (stage_name == keys::kOnAuthRequiredEnum) { | 821 } else if (stage_name == keys::kOnAuthRequiredEnum) { |
822 stages |= ON_AUTH_REQUIRED; | 822 stages |= ON_AUTH_REQUIRED; |
823 } else { | 823 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 bool WebRequestConditionAttributeStages::Equals( | 873 bool WebRequestConditionAttributeStages::Equals( |
874 const WebRequestConditionAttribute* other) const { | 874 const WebRequestConditionAttribute* other) const { |
875 if (!WebRequestConditionAttribute::Equals(other)) | 875 if (!WebRequestConditionAttribute::Equals(other)) |
876 return false; | 876 return false; |
877 const WebRequestConditionAttributeStages* casted_other = | 877 const WebRequestConditionAttributeStages* casted_other = |
878 static_cast<const WebRequestConditionAttributeStages*>(other); | 878 static_cast<const WebRequestConditionAttributeStages*>(other); |
879 return allowed_stages_ == casted_other->allowed_stages_; | 879 return allowed_stages_ == casted_other->allowed_stages_; |
880 } | 880 } |
881 | 881 |
882 } // namespace extensions | 882 } // namespace extensions |
OLD | NEW |