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

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc

Issue 10825212: Support also excluding content types in declarative webrequest conditions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ' Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698