Chromium Code Reviews| 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_condit ion_attribute.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 | 45 |
| 46 WebRequestConditionAttribute::~WebRequestConditionAttribute() {} | 46 WebRequestConditionAttribute::~WebRequestConditionAttribute() {} |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 bool WebRequestConditionAttribute::IsKnownType( | 49 bool WebRequestConditionAttribute::IsKnownType( |
| 50 const std::string& instance_type) { | 50 const std::string& instance_type) { |
| 51 return | 51 return |
| 52 WebRequestConditionAttributeResourceType::IsMatchingType(instance_type) || | 52 WebRequestConditionAttributeResourceType::IsMatchingType(instance_type) || |
| 53 WebRequestConditionAttributeContentType::IsMatchingType(instance_type) || | 53 WebRequestConditionAttributeContentType::IsMatchingType(instance_type) || |
| 54 WebRequestConditionAttributeResponseHeaders::IsMatchingType( | 54 WebRequestConditionAttributeResponseHeaders::IsMatchingType( |
| 55 instance_type); | 55 instance_type) || |
| 56 WebRequestConditionAttributeThirdParty::IsMatchingType(instance_type); | |
| 56 } | 57 } |
| 57 | 58 |
| 58 // static | 59 // static |
| 59 scoped_ptr<WebRequestConditionAttribute> | 60 scoped_ptr<WebRequestConditionAttribute> |
| 60 WebRequestConditionAttribute::Create( | 61 WebRequestConditionAttribute::Create( |
| 61 const std::string& name, | 62 const std::string& name, |
| 62 const base::Value* value, | 63 const base::Value* value, |
| 63 std::string* error) { | 64 std::string* error) { |
| 64 CHECK(value != NULL && error != NULL); | 65 CHECK(value != NULL && error != NULL); |
| 65 if (WebRequestConditionAttributeResourceType::IsMatchingType(name)) { | 66 if (WebRequestConditionAttributeResourceType::IsMatchingType(name)) { |
| 66 return WebRequestConditionAttributeResourceType::Create(name, value, error); | 67 return WebRequestConditionAttributeResourceType::Create(name, value, error); |
| 67 } else if (WebRequestConditionAttributeContentType::IsMatchingType(name)) { | 68 } else if (WebRequestConditionAttributeContentType::IsMatchingType(name)) { |
| 68 return WebRequestConditionAttributeContentType::Create(name, value, error); | 69 return WebRequestConditionAttributeContentType::Create(name, value, error); |
| 69 } else if (WebRequestConditionAttributeResponseHeaders::IsMatchingType( | 70 } else if (WebRequestConditionAttributeResponseHeaders::IsMatchingType( |
| 70 name)) { | 71 name)) { |
| 71 return WebRequestConditionAttributeResponseHeaders::Create( | 72 return WebRequestConditionAttributeResponseHeaders::Create( |
| 72 name, value, error); | 73 name, value, error); |
| 74 } else if (WebRequestConditionAttributeThirdParty::IsMatchingType(name)) { | |
| 75 return WebRequestConditionAttributeThirdParty::Create(name, value, error); | |
| 73 } | 76 } |
| 74 | 77 |
| 75 *error = ExtensionErrorUtils::FormatErrorMessage(kUnknownConditionAttribute, | 78 *error = ExtensionErrorUtils::FormatErrorMessage(kUnknownConditionAttribute, |
| 76 name); | 79 name); |
| 77 return scoped_ptr<WebRequestConditionAttribute>(NULL); | 80 return scoped_ptr<WebRequestConditionAttribute>(NULL); |
| 78 } | 81 } |
| 79 | 82 |
| 80 // | 83 // |
| 81 // WebRequestConditionAttributeResourceType | 84 // WebRequestConditionAttributeResourceType |
| 82 // | 85 // |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 } | 560 } |
| 558 | 561 |
| 559 return (positive_ ? passed : !passed); | 562 return (positive_ ? passed : !passed); |
| 560 } | 563 } |
| 561 | 564 |
| 562 WebRequestConditionAttribute::Type | 565 WebRequestConditionAttribute::Type |
| 563 WebRequestConditionAttributeResponseHeaders::GetType() const { | 566 WebRequestConditionAttributeResponseHeaders::GetType() const { |
| 564 return CONDITION_RESPONSE_HEADERS; | 567 return CONDITION_RESPONSE_HEADERS; |
| 565 } | 568 } |
| 566 | 569 |
| 570 // | |
| 571 // WebRequestConditionAttributeThirdParty | |
| 572 // | |
| 573 | |
| 574 WebRequestConditionAttributeThirdParty:: | |
| 575 WebRequestConditionAttributeThirdParty(bool match_third_party) | |
| 576 : match_third_party_(match_third_party) {} | |
| 577 | |
| 578 WebRequestConditionAttributeThirdParty:: | |
| 579 ~WebRequestConditionAttributeThirdParty() {} | |
| 580 | |
| 581 // static | |
| 582 bool WebRequestConditionAttributeThirdParty::IsMatchingType( | |
| 583 const std::string& instance_type) { | |
| 584 return instance_type == keys::kThirdPartyKey; | |
| 585 } | |
| 586 | |
| 587 // static | |
| 588 scoped_ptr<WebRequestConditionAttribute> | |
| 589 WebRequestConditionAttributeThirdParty::Create( | |
| 590 const std::string& name, | |
| 591 const base::Value* value, | |
| 592 std::string* error) { | |
| 593 DCHECK(IsMatchingType(name)); | |
| 594 | |
| 595 bool third_party = false; // Dummy value, gets overwritten. | |
| 596 if (!value->GetAsBoolean(&third_party)) { | |
| 597 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidValue, | |
| 598 keys::kThirdPartyKey); | |
| 599 return scoped_ptr<WebRequestConditionAttribute>(NULL); | |
| 600 } | |
| 601 | |
| 602 return scoped_ptr<WebRequestConditionAttribute>( | |
| 603 new WebRequestConditionAttributeThirdParty(third_party)); | |
| 604 } | |
| 605 | |
| 606 int WebRequestConditionAttributeThirdParty::GetStages() const { | |
| 607 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | | |
| 608 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT | | |
| 609 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR; | |
| 610 } | |
| 611 | |
| 612 bool WebRequestConditionAttributeThirdParty::IsFulfilled( | |
| 613 const WebRequestRule::RequestData& request_data) const { | |
| 614 if (!(request_data.stage & GetStages())) | |
| 615 return false; | |
| 616 | |
| 617 DCHECK(request_data.request->first_party_for_cookies().is_valid()); | |
|
jochen (gone - plz use gerrit)
2012/09/26 19:50:19
first_party_for_cookies() is not necessarily valid
vabr (Chromium)
2012/10/04 11:20:41
OK, I no longer check it and pass it directly to R
| |
| 618 const GURL first_party_origin = | |
| 619 request_data.request->first_party_for_cookies().GetOrigin(); | |
|
jochen (gone - plz use gerrit)
2012/09/26 19:50:19
why are you looking at the origin only?
vabr (Chromium)
2012/10/04 11:20:41
Looking no more, using RegistryControlledDomainSer
| |
| 620 | |
| 621 const bool is_first_party = | |
| 622 first_party_origin == request_data.request->url().GetOrigin(); | |
|
jochen (gone - plz use gerrit)
2012/09/26 19:50:19
You should use RegistryControlledDomainService::Sa
vabr (Chromium)
2012/10/04 11:20:41
Done.
| |
| 623 return match_third_party_ ? !is_first_party : is_first_party; | |
| 624 } | |
| 625 | |
| 626 WebRequestConditionAttribute::Type | |
| 627 WebRequestConditionAttributeThirdParty::GetType() const { | |
| 628 return CONDITION_THIRD_PARTY; | |
| 629 } | |
| 630 | |
| 567 } // namespace extensions | 631 } // namespace extensions |
| OLD | NEW |