Chromium Code Reviews| 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 24aecf7f4e6bd6428b5615c1dca724e647c92e19..f19eadea1dd97ef43125263f14b48a3b2d1e5824 100644 |
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc |
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc |
| @@ -144,8 +144,9 @@ WebRequestConditionAttributeResourceType::GetType() const { |
| WebRequestConditionAttributeContentType:: |
| WebRequestConditionAttributeContentType( |
| - const std::vector<std::string>& content_types) |
| - : content_types_(content_types) {} |
| + const std::vector<std::string>& content_types, |
| + bool inclusive) |
| + : content_types_(content_types), inclusive_(inclusive) {} |
|
battre
2012/08/07 08:45:09
nit: I think the inclusive_ should go into the nex
Yoyo Zhou
2012/08/07 19:32:35
I think the style guide can be construed either wa
|
| WebRequestConditionAttributeContentType:: |
| ~WebRequestConditionAttributeContentType() {} |
| @@ -153,7 +154,8 @@ WebRequestConditionAttributeContentType:: |
| // static |
| bool WebRequestConditionAttributeContentType::IsMatchingType( |
| const std::string& instance_type) { |
| - return instance_type == keys::kContentTypeKey; |
| + return instance_type == keys::kContentTypeKey || |
| + instance_type == keys::kExcludeContentTypeKey; |
| } |
| // static |
| @@ -162,27 +164,27 @@ WebRequestConditionAttributeContentType::Create( |
| const std::string& name, |
| const base::Value* value, |
| std::string* error) { |
| - std::vector<std::string> content_types; |
| + DCHECK(IsMatchingType(name)); |
| const ListValue* value_as_list = NULL; |
| if (!value->GetAsList(&value_as_list)) { |
| - *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidValue, |
| - keys::kContentTypeKey); |
| + *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidValue, name); |
| return scoped_ptr<WebRequestConditionAttribute>(NULL); |
| } |
| - |
| + std::vector<std::string> content_types; |
| for (ListValue::const_iterator it = value_as_list->begin(); |
| it != value_as_list->end(); ++it) { |
| std::string content_type; |
| if (!(*it)->GetAsString(&content_type)) { |
| - *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidValue, |
| - keys::kContentTypeKey); |
| + *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidValue, name); |
| return scoped_ptr<WebRequestConditionAttribute>(NULL); |
| } |
| content_types.push_back(content_type); |
| } |
| + |
| return scoped_ptr<WebRequestConditionAttribute>( |
| - new WebRequestConditionAttributeContentType(content_types)); |
| + new WebRequestConditionAttributeContentType( |
| + content_types, name == keys::kContentTypeKey)); |
| } |
| int WebRequestConditionAttributeContentType::GetStages() const { |
| @@ -202,8 +204,13 @@ bool WebRequestConditionAttributeContentType::IsFulfilled( |
| net::HttpUtil::ParseContentType( |
| content_type, &mime_type, &charset, &had_charset, NULL); |
| - return std::find(content_types_.begin(), content_types_.end(), |
| - mime_type) != content_types_.end(); |
| + if (inclusive_) { |
| + return std::find(content_types_.begin(), content_types_.end(), |
| + mime_type) != content_types_.end(); |
| + } else { |
| + return std::find(content_types_.begin(), content_types_.end(), |
| + mime_type) == content_types_.end(); |
| + } |
| } |
| WebRequestConditionAttribute::Type |