| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc
|
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc
|
| index f5169f0d9e57de2c7886ecc521e7743f331ed5d9..68f216ac93ecf24f1fd5bc596fc493bcab883db8 100644
|
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc
|
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc
|
| @@ -15,6 +15,7 @@
|
| #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
|
| #include "chrome/common/extensions/extension_error_utils.h"
|
| #include "content/public/browser/resource_request_info.h"
|
| +#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
|
| #include "net/http/http_util.h"
|
| #include "net/http/http_request_headers.h"
|
| #include "net/url_request/url_request.h"
|
| @@ -52,7 +53,8 @@ bool WebRequestConditionAttribute::IsKnownType(
|
| WebRequestConditionAttributeResourceType::IsMatchingType(instance_type) ||
|
| WebRequestConditionAttributeContentType::IsMatchingType(instance_type) ||
|
| WebRequestConditionAttributeResponseHeaders::IsMatchingType(
|
| - instance_type);
|
| + instance_type) ||
|
| + WebRequestConditionAttributeThirdParty::IsMatchingType(instance_type);
|
| }
|
|
|
| // static
|
| @@ -70,6 +72,8 @@ WebRequestConditionAttribute::Create(
|
| name)) {
|
| return WebRequestConditionAttributeResponseHeaders::Create(
|
| name, value, error);
|
| + } else if (WebRequestConditionAttributeThirdParty::IsMatchingType(name)) {
|
| + return WebRequestConditionAttributeThirdParty::Create(name, value, error);
|
| }
|
|
|
| *error = ExtensionErrorUtils::FormatErrorMessage(kUnknownConditionAttribute,
|
| @@ -564,4 +568,63 @@ WebRequestConditionAttributeResponseHeaders::GetType() const {
|
| return CONDITION_RESPONSE_HEADERS;
|
| }
|
|
|
| +//
|
| +// WebRequestConditionAttributeThirdParty
|
| +//
|
| +
|
| +WebRequestConditionAttributeThirdParty::
|
| +WebRequestConditionAttributeThirdParty(bool match_third_party)
|
| + : match_third_party_(match_third_party) {}
|
| +
|
| +WebRequestConditionAttributeThirdParty::
|
| +~WebRequestConditionAttributeThirdParty() {}
|
| +
|
| +// static
|
| +bool WebRequestConditionAttributeThirdParty::IsMatchingType(
|
| + const std::string& instance_type) {
|
| + return instance_type == keys::kThirdPartyKey;
|
| +}
|
| +
|
| +// static
|
| +scoped_ptr<WebRequestConditionAttribute>
|
| +WebRequestConditionAttributeThirdParty::Create(
|
| + const std::string& name,
|
| + const base::Value* value,
|
| + std::string* error) {
|
| + DCHECK(IsMatchingType(name));
|
| +
|
| + bool third_party = false; // Dummy value, gets overwritten.
|
| + if (!value->GetAsBoolean(&third_party)) {
|
| + *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidValue,
|
| + keys::kThirdPartyKey);
|
| + return scoped_ptr<WebRequestConditionAttribute>(NULL);
|
| + }
|
| +
|
| + return scoped_ptr<WebRequestConditionAttribute>(
|
| + new WebRequestConditionAttributeThirdParty(third_party));
|
| +}
|
| +
|
| +int WebRequestConditionAttributeThirdParty::GetStages() const {
|
| + return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS |
|
| + ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT |
|
| + ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR;
|
| +}
|
| +
|
| +bool WebRequestConditionAttributeThirdParty::IsFulfilled(
|
| + const WebRequestRule::RequestData& request_data) const {
|
| + if (!(request_data.stage & GetStages()))
|
| + return false;
|
| +
|
| + const bool is_first_party =
|
| + net::RegistryControlledDomainService::SameDomainOrHost(
|
| + request_data.request->url(),
|
| + request_data.request->first_party_for_cookies());
|
| + return match_third_party_ ? !is_first_party : is_first_party;
|
| +}
|
| +
|
| +WebRequestConditionAttribute::Type
|
| +WebRequestConditionAttributeThirdParty::GetType() const {
|
| + return CONDITION_THIRD_PARTY;
|
| +}
|
| +
|
| } // namespace extensions
|
|
|