Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1471)

Side by Side Diff: extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 const WebRequestConditionAttribute* other) const { 106 const WebRequestConditionAttribute* other) const {
107 return GetType() == other->GetType(); 107 return GetType() == other->GetType();
108 } 108 }
109 109
110 // static 110 // static
111 scoped_refptr<const WebRequestConditionAttribute> 111 scoped_refptr<const WebRequestConditionAttribute>
112 WebRequestConditionAttribute::Create( 112 WebRequestConditionAttribute::Create(
113 const std::string& name, 113 const std::string& name,
114 const base::Value* value, 114 const base::Value* value,
115 std::string* error) { 115 std::string* error) {
116 CHECK(value != NULL && error != NULL); 116 CHECK(value != nullptr && error != nullptr);
117 bool bad_message = false; 117 bool bad_message = false;
118 return g_web_request_condition_attribute_factory.Get().factory.Instantiate( 118 return g_web_request_condition_attribute_factory.Get().factory.Instantiate(
119 name, value, error, &bad_message); 119 name, value, error, &bad_message);
120 } 120 }
121 121
122 // 122 //
123 // WebRequestConditionAttributeResourceType 123 // WebRequestConditionAttributeResourceType
124 // 124 //
125 125
126 WebRequestConditionAttributeResourceType:: 126 WebRequestConditionAttributeResourceType::
127 WebRequestConditionAttributeResourceType( 127 WebRequestConditionAttributeResourceType(
128 const std::vector<ResourceType>& types) 128 const std::vector<ResourceType>& types)
129 : types_(types) {} 129 : types_(types) {}
130 130
131 WebRequestConditionAttributeResourceType:: 131 WebRequestConditionAttributeResourceType::
132 ~WebRequestConditionAttributeResourceType() {} 132 ~WebRequestConditionAttributeResourceType() {}
133 133
134 // static 134 // static
135 scoped_refptr<const WebRequestConditionAttribute> 135 scoped_refptr<const WebRequestConditionAttribute>
136 WebRequestConditionAttributeResourceType::Create( 136 WebRequestConditionAttributeResourceType::Create(
137 const std::string& instance_type, 137 const std::string& instance_type,
138 const base::Value* value, 138 const base::Value* value,
139 std::string* error, 139 std::string* error,
140 bool* bad_message) { 140 bool* bad_message) {
141 DCHECK(instance_type == keys::kResourceTypeKey); 141 DCHECK(instance_type == keys::kResourceTypeKey);
142 const base::ListValue* value_as_list = NULL; 142 const base::ListValue* value_as_list = nullptr;
143 if (!value->GetAsList(&value_as_list)) { 143 if (!value->GetAsList(&value_as_list)) {
144 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, 144 *error = ErrorUtils::FormatErrorMessage(kInvalidValue,
145 keys::kResourceTypeKey); 145 keys::kResourceTypeKey);
146 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 146 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
147 } 147 }
148 148
149 size_t number_types = value_as_list->GetSize(); 149 size_t number_types = value_as_list->GetSize();
150 150
151 std::vector<ResourceType> passed_types; 151 std::vector<ResourceType> passed_types;
152 passed_types.reserve(number_types); 152 passed_types.reserve(number_types);
153 for (size_t i = 0; i < number_types; ++i) { 153 for (size_t i = 0; i < number_types; ++i) {
154 std::string resource_type_string; 154 std::string resource_type_string;
155 ResourceType type = content::RESOURCE_TYPE_LAST_TYPE; 155 ResourceType type = content::RESOURCE_TYPE_LAST_TYPE;
156 if (!value_as_list->GetString(i, &resource_type_string) || 156 if (!value_as_list->GetString(i, &resource_type_string) ||
157 !utils::ParseResourceType(resource_type_string, &type)) { 157 !utils::ParseResourceType(resource_type_string, &type)) {
158 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, 158 *error = ErrorUtils::FormatErrorMessage(kInvalidValue,
159 keys::kResourceTypeKey); 159 keys::kResourceTypeKey);
160 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 160 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
161 } 161 }
162 passed_types.push_back(type); 162 passed_types.push_back(type);
163 } 163 }
164 164
165 return scoped_refptr<const WebRequestConditionAttribute>( 165 return scoped_refptr<const WebRequestConditionAttribute>(
166 new WebRequestConditionAttributeResourceType(passed_types)); 166 new WebRequestConditionAttributeResourceType(passed_types));
167 } 167 }
168 168
169 int WebRequestConditionAttributeResourceType::GetStages() const { 169 int WebRequestConditionAttributeResourceType::GetStages() const {
170 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | 170 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 // static 219 // static
220 scoped_refptr<const WebRequestConditionAttribute> 220 scoped_refptr<const WebRequestConditionAttribute>
221 WebRequestConditionAttributeContentType::Create( 221 WebRequestConditionAttributeContentType::Create(
222 const std::string& name, 222 const std::string& name,
223 const base::Value* value, 223 const base::Value* value,
224 std::string* error, 224 std::string* error,
225 bool* bad_message) { 225 bool* bad_message) {
226 DCHECK(name == keys::kContentTypeKey || name == keys::kExcludeContentTypeKey); 226 DCHECK(name == keys::kContentTypeKey || name == keys::kExcludeContentTypeKey);
227 227
228 const base::ListValue* value_as_list = NULL; 228 const base::ListValue* value_as_list = nullptr;
229 if (!value->GetAsList(&value_as_list)) { 229 if (!value->GetAsList(&value_as_list)) {
230 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); 230 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name);
231 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 231 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
232 } 232 }
233 std::vector<std::string> content_types; 233 std::vector<std::string> content_types;
234 for (base::ListValue::const_iterator it = value_as_list->begin(); 234 for (base::ListValue::const_iterator it = value_as_list->begin();
235 it != value_as_list->end(); ++it) { 235 it != value_as_list->end(); ++it) {
236 std::string content_type; 236 std::string content_type;
237 if (!(*it)->GetAsString(&content_type)) { 237 if (!(*it)->GetAsString(&content_type)) {
238 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); 238 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name);
239 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 239 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
240 } 240 }
241 content_types.push_back(content_type); 241 content_types.push_back(content_type);
242 } 242 }
243 243
244 return scoped_refptr<const WebRequestConditionAttribute>( 244 return scoped_refptr<const WebRequestConditionAttribute>(
245 new WebRequestConditionAttributeContentType( 245 new WebRequestConditionAttributeContentType(
246 content_types, name == keys::kContentTypeKey)); 246 content_types, name == keys::kContentTypeKey));
247 } 247 }
248 248
249 int WebRequestConditionAttributeContentType::GetStages() const { 249 int WebRequestConditionAttributeContentType::GetStages() const {
250 return ON_HEADERS_RECEIVED; 250 return ON_HEADERS_RECEIVED;
251 } 251 }
252 252
253 bool WebRequestConditionAttributeContentType::IsFulfilled( 253 bool WebRequestConditionAttributeContentType::IsFulfilled(
254 const WebRequestData& request_data) const { 254 const WebRequestData& request_data) const {
255 if (!(request_data.stage & GetStages())) 255 if (!(request_data.stage & GetStages()))
256 return false; 256 return false;
257 std::string content_type; 257 std::string content_type;
258 request_data.original_response_headers->GetNormalizedHeader( 258 request_data.original_response_headers->GetNormalizedHeader(
259 net::HttpRequestHeaders::kContentType, &content_type); 259 net::HttpRequestHeaders::kContentType, &content_type);
260 std::string mime_type; 260 std::string mime_type;
261 std::string charset; 261 std::string charset;
262 bool had_charset = false; 262 bool had_charset = false;
263 net::HttpUtil::ParseContentType( 263 net::HttpUtil::ParseContentType(
264 content_type, &mime_type, &charset, &had_charset, NULL); 264 content_type, &mime_type, &charset, &had_charset, nullptr);
265 265
266 if (inclusive_) { 266 if (inclusive_) {
267 return std::find(content_types_.begin(), content_types_.end(), 267 return std::find(content_types_.begin(), content_types_.end(),
268 mime_type) != content_types_.end(); 268 mime_type) != content_types_.end();
269 } else { 269 } else {
270 return std::find(content_types_.begin(), content_types_.end(), 270 return std::find(content_types_.begin(), content_types_.end(),
271 mime_type) == content_types_.end(); 271 mime_type) == content_types_.end();
272 } 272 }
273 } 273 }
274 274
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // HeaderMatcher implementation. 370 // HeaderMatcher implementation.
371 371
372 HeaderMatcher::~HeaderMatcher() {} 372 HeaderMatcher::~HeaderMatcher() {}
373 373
374 // static 374 // static
375 scoped_ptr<const HeaderMatcher> HeaderMatcher::Create( 375 scoped_ptr<const HeaderMatcher> HeaderMatcher::Create(
376 const base::ListValue* tests) { 376 const base::ListValue* tests) {
377 ScopedVector<const HeaderMatchTest> header_tests; 377 ScopedVector<const HeaderMatchTest> header_tests;
378 for (base::ListValue::const_iterator it = tests->begin(); 378 for (base::ListValue::const_iterator it = tests->begin();
379 it != tests->end(); ++it) { 379 it != tests->end(); ++it) {
380 const base::DictionaryValue* tests = NULL; 380 const base::DictionaryValue* tests = nullptr;
381 if (!(*it)->GetAsDictionary(&tests)) 381 if (!(*it)->GetAsDictionary(&tests))
382 return scoped_ptr<const HeaderMatcher>(); 382 return scoped_ptr<const HeaderMatcher>();
383 383
384 scoped_ptr<const HeaderMatchTest> header_test( 384 scoped_ptr<const HeaderMatchTest> header_test(
385 HeaderMatchTest::Create(tests)); 385 HeaderMatchTest::Create(tests));
386 if (header_test.get() == NULL) 386 if (header_test.get() == nullptr)
387 return scoped_ptr<const HeaderMatcher>(); 387 return scoped_ptr<const HeaderMatcher>();
388 header_tests.push_back(header_test.release()); 388 header_tests.push_back(header_test.release());
389 } 389 }
390 390
391 return scoped_ptr<const HeaderMatcher>(new HeaderMatcher(&header_tests)); 391 return scoped_ptr<const HeaderMatcher>(new HeaderMatcher(&header_tests));
392 } 392 }
393 393
394 bool HeaderMatcher::TestNameValue(const std::string& name, 394 bool HeaderMatcher::TestNameValue(const std::string& name,
395 const std::string& value) const { 395 const std::string& value) const {
396 for (size_t i = 0; i < tests_.size(); ++i) { 396 for (size_t i = 0; i < tests_.size(); ++i) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } else { 491 } else {
492 NOTREACHED(); // JSON schema type checking should prevent this. 492 NOTREACHED(); // JSON schema type checking should prevent this.
493 return scoped_ptr<const HeaderMatchTest>(); 493 return scoped_ptr<const HeaderMatchTest>();
494 } 494 }
495 const base::Value* content = &it.value(); 495 const base::Value* content = &it.value();
496 496
497 ScopedVector<const StringMatchTest>* tests = 497 ScopedVector<const StringMatchTest>* tests =
498 is_name ? &name_match : &value_match; 498 is_name ? &name_match : &value_match;
499 switch (content->GetType()) { 499 switch (content->GetType()) {
500 case base::Value::TYPE_LIST: { 500 case base::Value::TYPE_LIST: {
501 const base::ListValue* list = NULL; 501 const base::ListValue* list = nullptr;
502 CHECK(content->GetAsList(&list)); 502 CHECK(content->GetAsList(&list));
503 for (base::ListValue::const_iterator it = list->begin(); 503 for (base::ListValue::const_iterator it = list->begin();
504 it != list->end(); ++it) { 504 it != list->end(); ++it) {
505 tests->push_back( 505 tests->push_back(
506 StringMatchTest::Create(*it, match_type, !is_name).release()); 506 StringMatchTest::Create(*it, match_type, !is_name).release());
507 } 507 }
508 break; 508 break;
509 } 509 }
510 case base::Value::TYPE_STRING: { 510 case base::Value::TYPE_STRING: {
511 tests->push_back( 511 tests->push_back(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 551
552 WebRequestConditionAttributeRequestHeaders:: 552 WebRequestConditionAttributeRequestHeaders::
553 ~WebRequestConditionAttributeRequestHeaders() {} 553 ~WebRequestConditionAttributeRequestHeaders() {}
554 554
555 namespace { 555 namespace {
556 556
557 scoped_ptr<const HeaderMatcher> PrepareHeaderMatcher( 557 scoped_ptr<const HeaderMatcher> PrepareHeaderMatcher(
558 const std::string& name, 558 const std::string& name,
559 const base::Value* value, 559 const base::Value* value,
560 std::string* error) { 560 std::string* error) {
561 const base::ListValue* value_as_list = NULL; 561 const base::ListValue* value_as_list = nullptr;
562 if (!value->GetAsList(&value_as_list)) { 562 if (!value->GetAsList(&value_as_list)) {
563 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); 563 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name);
564 return scoped_ptr<const HeaderMatcher>(); 564 return scoped_ptr<const HeaderMatcher>();
565 } 565 }
566 566
567 scoped_ptr<const HeaderMatcher> header_matcher( 567 scoped_ptr<const HeaderMatcher> header_matcher(
568 HeaderMatcher::Create(value_as_list)); 568 HeaderMatcher::Create(value_as_list));
569 if (header_matcher.get() == NULL) 569 if (header_matcher.get() == nullptr)
570 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); 570 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name);
571 return header_matcher.Pass(); 571 return header_matcher.Pass();
572 } 572 }
573 573
574 } // namespace 574 } // namespace
575 575
576 // static 576 // static
577 scoped_refptr<const WebRequestConditionAttribute> 577 scoped_refptr<const WebRequestConditionAttribute>
578 WebRequestConditionAttributeRequestHeaders::Create( 578 WebRequestConditionAttributeRequestHeaders::Create(
579 const std::string& name, 579 const std::string& name,
580 const base::Value* value, 580 const base::Value* value,
581 std::string* error, 581 std::string* error,
582 bool* bad_message) { 582 bool* bad_message) {
583 DCHECK(name == keys::kRequestHeadersKey || 583 DCHECK(name == keys::kRequestHeadersKey ||
584 name == keys::kExcludeRequestHeadersKey); 584 name == keys::kExcludeRequestHeadersKey);
585 585
586 scoped_ptr<const HeaderMatcher> header_matcher( 586 scoped_ptr<const HeaderMatcher> header_matcher(
587 PrepareHeaderMatcher(name, value, error)); 587 PrepareHeaderMatcher(name, value, error));
588 if (header_matcher.get() == NULL) 588 if (header_matcher.get() == nullptr)
589 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 589 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
590 590
591 return scoped_refptr<const WebRequestConditionAttribute>( 591 return scoped_refptr<const WebRequestConditionAttribute>(
592 new WebRequestConditionAttributeRequestHeaders( 592 new WebRequestConditionAttributeRequestHeaders(
593 header_matcher.Pass(), name == keys::kRequestHeadersKey)); 593 header_matcher.Pass(), name == keys::kRequestHeadersKey));
594 } 594 }
595 595
596 int WebRequestConditionAttributeRequestHeaders::GetStages() const { 596 int WebRequestConditionAttributeRequestHeaders::GetStages() const {
597 // Currently we only allow matching against headers in the before-send-headers 597 // Currently we only allow matching against headers in the before-send-headers
598 // stage. The headers are accessible in other stages as well, but before 598 // stage. The headers are accessible in other stages as well, but before
599 // allowing to match against them in further stages, we should consider 599 // allowing to match against them in further stages, we should consider
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 WebRequestConditionAttributeResponseHeaders::Create( 652 WebRequestConditionAttributeResponseHeaders::Create(
653 const std::string& name, 653 const std::string& name,
654 const base::Value* value, 654 const base::Value* value,
655 std::string* error, 655 std::string* error,
656 bool* bad_message) { 656 bool* bad_message) {
657 DCHECK(name == keys::kResponseHeadersKey || 657 DCHECK(name == keys::kResponseHeadersKey ||
658 name == keys::kExcludeResponseHeadersKey); 658 name == keys::kExcludeResponseHeadersKey);
659 659
660 scoped_ptr<const HeaderMatcher> header_matcher( 660 scoped_ptr<const HeaderMatcher> header_matcher(
661 PrepareHeaderMatcher(name, value, error)); 661 PrepareHeaderMatcher(name, value, error));
662 if (header_matcher.get() == NULL) 662 if (header_matcher.get() == nullptr)
663 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 663 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
664 664
665 return scoped_refptr<const WebRequestConditionAttribute>( 665 return scoped_refptr<const WebRequestConditionAttribute>(
666 new WebRequestConditionAttributeResponseHeaders( 666 new WebRequestConditionAttributeResponseHeaders(
667 header_matcher.Pass(), name == keys::kResponseHeadersKey)); 667 header_matcher.Pass(), name == keys::kResponseHeadersKey));
668 } 668 }
669 669
670 int WebRequestConditionAttributeResponseHeaders::GetStages() const { 670 int WebRequestConditionAttributeResponseHeaders::GetStages() const {
671 return ON_HEADERS_RECEIVED; 671 return ON_HEADERS_RECEIVED;
672 } 672 }
673 673
674 bool WebRequestConditionAttributeResponseHeaders::IsFulfilled( 674 bool WebRequestConditionAttributeResponseHeaders::IsFulfilled(
675 const WebRequestData& request_data) const { 675 const WebRequestData& request_data) const {
676 if (!(request_data.stage & GetStages())) 676 if (!(request_data.stage & GetStages()))
677 return false; 677 return false;
678 678
679 const net::HttpResponseHeaders* headers = 679 const net::HttpResponseHeaders* headers =
680 request_data.original_response_headers; 680 request_data.original_response_headers;
681 if (headers == NULL) { 681 if (headers == nullptr) {
682 // Each header of an empty set satisfies (the negation of) everything; 682 // Each header of an empty set satisfies (the negation of) everything;
683 // OTOH, there is no header to satisfy even the most permissive test. 683 // OTOH, there is no header to satisfy even the most permissive test.
684 return !positive_; 684 return !positive_;
685 } 685 }
686 686
687 bool passed = false; // Did some header pass TestNameValue? 687 bool passed = false; // Did some header pass TestNameValue?
688 std::string name; 688 std::string name;
689 std::string value; 689 std::string value;
690 void* iter = NULL; 690 void* iter = nullptr;
691 while (!passed && headers->EnumerateHeaderLines(&iter, &name, &value)) { 691 while (!passed && headers->EnumerateHeaderLines(&iter, &name, &value)) {
692 passed |= header_matcher_->TestNameValue(name, value); 692 passed |= header_matcher_->TestNameValue(name, value);
693 } 693 }
694 694
695 return (positive_ ? passed : !passed); 695 return (positive_ ? passed : !passed);
696 } 696 }
697 697
698 WebRequestConditionAttribute::Type 698 WebRequestConditionAttribute::Type
699 WebRequestConditionAttributeResponseHeaders::GetType() const { 699 WebRequestConditionAttributeResponseHeaders::GetType() const {
700 return CONDITION_RESPONSE_HEADERS; 700 return CONDITION_RESPONSE_HEADERS;
(...skipping 26 matching lines...) Expand all
727 const std::string& name, 727 const std::string& name,
728 const base::Value* value, 728 const base::Value* value,
729 std::string* error, 729 std::string* error,
730 bool* bad_message) { 730 bool* bad_message) {
731 DCHECK(name == keys::kThirdPartyKey); 731 DCHECK(name == keys::kThirdPartyKey);
732 732
733 bool third_party = false; // Dummy value, gets overwritten. 733 bool third_party = false; // Dummy value, gets overwritten.
734 if (!value->GetAsBoolean(&third_party)) { 734 if (!value->GetAsBoolean(&third_party)) {
735 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, 735 *error = ErrorUtils::FormatErrorMessage(kInvalidValue,
736 keys::kThirdPartyKey); 736 keys::kThirdPartyKey);
737 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 737 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
738 } 738 }
739 739
740 return scoped_refptr<const WebRequestConditionAttribute>( 740 return scoped_refptr<const WebRequestConditionAttribute>(
741 new WebRequestConditionAttributeThirdParty(third_party)); 741 new WebRequestConditionAttributeThirdParty(third_party));
742 } 742 }
743 743
744 int WebRequestConditionAttributeThirdParty::GetStages() const { 744 int WebRequestConditionAttributeThirdParty::GetStages() const {
745 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | 745 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS |
746 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT | 746 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT |
747 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR; 747 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 791
792 WebRequestConditionAttributeStages:: 792 WebRequestConditionAttributeStages::
793 ~WebRequestConditionAttributeStages() {} 793 ~WebRequestConditionAttributeStages() {}
794 794
795 namespace { 795 namespace {
796 796
797 // Reads strings stored in |value|, which is expected to be a ListValue, and 797 // Reads strings stored in |value|, which is expected to be a ListValue, and
798 // sets corresponding bits (see RequestStage) in |out_stages|. Returns true on 798 // sets corresponding bits (see RequestStage) in |out_stages|. Returns true on
799 // success, false otherwise. 799 // success, false otherwise.
800 bool ParseListOfStages(const base::Value& value, int* out_stages) { 800 bool ParseListOfStages(const base::Value& value, int* out_stages) {
801 const base::ListValue* list = NULL; 801 const base::ListValue* list = nullptr;
802 if (!value.GetAsList(&list)) 802 if (!value.GetAsList(&list))
803 return false; 803 return false;
804 804
805 int stages = 0; 805 int stages = 0;
806 std::string stage_name; 806 std::string stage_name;
807 for (base::ListValue::const_iterator it = list->begin(); 807 for (base::ListValue::const_iterator it = list->begin();
808 it != list->end(); ++it) { 808 it != list->end(); ++it) {
809 if (!((*it)->GetAsString(&stage_name))) 809 if (!((*it)->GetAsString(&stage_name)))
810 return false; 810 return false;
811 if (stage_name == keys::kOnBeforeRequestEnum) { 811 if (stage_name == keys::kOnBeforeRequestEnum) {
(...skipping 21 matching lines...) Expand all
833 WebRequestConditionAttributeStages::Create(const std::string& name, 833 WebRequestConditionAttributeStages::Create(const std::string& name,
834 const base::Value* value, 834 const base::Value* value,
835 std::string* error, 835 std::string* error,
836 bool* bad_message) { 836 bool* bad_message) {
837 DCHECK(name == keys::kStagesKey); 837 DCHECK(name == keys::kStagesKey);
838 838
839 int allowed_stages = 0; 839 int allowed_stages = 0;
840 if (!ParseListOfStages(*value, &allowed_stages)) { 840 if (!ParseListOfStages(*value, &allowed_stages)) {
841 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, 841 *error = ErrorUtils::FormatErrorMessage(kInvalidValue,
842 keys::kStagesKey); 842 keys::kStagesKey);
843 return scoped_refptr<const WebRequestConditionAttribute>(NULL); 843 return scoped_refptr<const WebRequestConditionAttribute>(nullptr);
844 } 844 }
845 845
846 return scoped_refptr<const WebRequestConditionAttribute>( 846 return scoped_refptr<const WebRequestConditionAttribute>(
847 new WebRequestConditionAttributeStages(allowed_stages)); 847 new WebRequestConditionAttributeStages(allowed_stages));
848 } 848 }
849 849
850 int WebRequestConditionAttributeStages::GetStages() const { 850 int WebRequestConditionAttributeStages::GetStages() const {
851 return allowed_stages_; 851 return allowed_stages_;
852 } 852 }
853 853
(...skipping 15 matching lines...) Expand all
869 bool WebRequestConditionAttributeStages::Equals( 869 bool WebRequestConditionAttributeStages::Equals(
870 const WebRequestConditionAttribute* other) const { 870 const WebRequestConditionAttribute* other) const {
871 if (!WebRequestConditionAttribute::Equals(other)) 871 if (!WebRequestConditionAttribute::Equals(other))
872 return false; 872 return false;
873 const WebRequestConditionAttributeStages* casted_other = 873 const WebRequestConditionAttributeStages* casted_other =
874 static_cast<const WebRequestConditionAttributeStages*>(other); 874 static_cast<const WebRequestConditionAttributeStages*>(other);
875 return allowed_stages_ == casted_other->allowed_stages_; 875 return allowed_stages_ == casted_other->allowed_stages_;
876 } 876 }
877 877
878 } // namespace extensions 878 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698