summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 09:07:42 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 09:07:42 +0000
commitaa4a86078a2c70b072396e3d913cda077c9d4fc2 (patch)
tree119a2e1b6d3668ebe30ffbdd84ea60b5f990a97e /chrome
parent712b963929cf9eae60f475a35e21ed180d1bdbf7 (diff)
downloadchromium_src-aa4a86078a2c70b072396e3d913cda077c9d4fc2.zip
chromium_src-aa4a86078a2c70b072396e3d913cda077c9d4fc2.tar.gz
chromium_src-aa4a86078a2c70b072396e3d913cda077c9d4fc2.tar.bz2
Introduce exception filter rules.
Allow for patterns to start with a - to mark exceptions. A URL matches a filter, if it matches at least one pattern and no exception. BUG=16932 TEST=covered by unit_tests Review URL: http://codereview.chromium.org/541009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/privacy_blacklist/blacklist.cc8
-rw-r--r--chrome/browser/privacy_blacklist/blacklist.h8
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_io.cc21
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_store.cc10
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_store.h2
-rw-r--r--chrome/test/data/blacklist_small.pbrbin262 -> 282 bytes
6 files changed, 41 insertions, 8 deletions
diff --git a/chrome/browser/privacy_blacklist/blacklist.cc b/chrome/browser/privacy_blacklist/blacklist.cc
index 1bec742..581f65a 100644
--- a/chrome/browser/privacy_blacklist/blacklist.cc
+++ b/chrome/browser/privacy_blacklist/blacklist.cc
@@ -112,8 +112,12 @@ bool Blacklist::Entry::IsBlocked(const GURL& url) const {
((attributes_ & kBlockUnsecure) && !url.SchemeIsSecure());
}
-Blacklist::Entry::Entry(const std::string& pattern, const Provider* provider)
- : pattern_(pattern), attributes_(0), provider_(provider) {}
+Blacklist::Entry::Entry(const std::string& pattern, const Provider* provider,
+ bool is_exception)
+ : attributes_(0),
+ is_exception_(is_exception),
+ pattern_(pattern),
+ provider_(provider) {}
void Blacklist::Entry::AddAttributes(unsigned int attributes) {
attributes_ |= attributes;
diff --git a/chrome/browser/privacy_blacklist/blacklist.h b/chrome/browser/privacy_blacklist/blacklist.h
index 2fba5fb..b4d26d0 100644
--- a/chrome/browser/privacy_blacklist/blacklist.h
+++ b/chrome/browser/privacy_blacklist/blacklist.h
@@ -75,7 +75,8 @@ class Blacklist {
class Entry {
public:
// Construct with given pattern.
- Entry(const std::string& pattern, const Provider* provider);
+ Entry(const std::string& pattern, const Provider* provider,
+ bool is_exception);
// Returns the pattern which this entry matches.
const std::string& pattern() const { return pattern_; }
@@ -108,8 +109,11 @@ class Blacklist {
// Merge the attributes and types of the given entry with this one.
void Merge(const Entry& entry);
- std::string pattern_;
unsigned int attributes_;
+
+ // True if this entry is an exception to the blacklist.
+ bool is_exception_;
+ std::string pattern_;
std::vector<std::string> types_;
// Points to the provider of this entry, the providers are all
diff --git a/chrome/browser/privacy_blacklist/blacklist_io.cc b/chrome/browser/privacy_blacklist/blacklist_io.cc
index 10f09dc..5567202 100644
--- a/chrome/browser/privacy_blacklist/blacklist_io.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_io.cc
@@ -18,6 +18,7 @@ namespace {
const char header[] = "[Chromium::PrivacyBlacklist]";
const char name_tag[] = "Name:";
const char url_tag[] = "URL:";
+const char whitelist_tag[] = "-";
const char arrow_tag[] = "=>";
const char eol[] = "\n\r";
@@ -106,6 +107,16 @@ bool BlacklistIO::ReadText(Blacklist* blacklist,
continue;
}
+ bool is_exception = false;
+ if (StartsWith(cur, end, whitelist_tag, arraysize(whitelist_tag))) {
+ is_exception = true;
+ cur++;
+ if (IsAsciiWhitespace(*cur)) {
+ *error_string = "Dash followed by white space.";
+ return false;
+ }
+ }
+
const char* skip = std::find_if(cur, end, IsWhiteSpace());
std::string pattern(cur, skip);
@@ -115,7 +126,8 @@ bool BlacklistIO::ReadText(Blacklist* blacklist,
return false;
}
- linked_ptr<Blacklist::Entry> entry(new Blacklist::Entry(pattern, provider));
+ linked_ptr<Blacklist::Entry> entry(new Blacklist::Entry(pattern, provider,
+ is_exception));
cur = std::find_if(cur + arraysize(arrow_tag), end, IsNotWhiteSpace());
skip = std::find_first_of(cur, end, eol, eol + 2);
@@ -211,13 +223,15 @@ bool BlacklistIO::ReadBinary(Blacklist* blacklist, const FilePath& path) {
std::string pattern;
unsigned int attributes, provider;
+ bool is_exception;
std::vector<std::string> types;
for (size_t i = 0; i < num_entries; ++i) {
- if (!input.ReadEntry(&pattern, &attributes, &types, &provider))
+ if (!input.ReadEntry(&pattern, &attributes, &types, &is_exception,
+ &provider))
return false;
Blacklist::Entry* entry =
- new Blacklist::Entry(pattern, provider_map[provider]);
+ new Blacklist::Entry(pattern, provider_map[provider], is_exception);
entry->AddAttributes(attributes);
entry->SwapTypes(&types);
entries.push_back(linked_ptr<Blacklist::Entry>(entry));
@@ -269,6 +283,7 @@ bool BlacklistIO::WriteBinary(const Blacklist* blacklist,
if (!output.StoreEntry((*i)->pattern_,
(*i)->attributes_,
(*i)->types_,
+ (*i)->is_exception_,
index[(*i)->provider_])) {
return false;
}
diff --git a/chrome/browser/privacy_blacklist/blacklist_store.cc b/chrome/browser/privacy_blacklist/blacklist_store.cc
index 327b255..87f5f1d 100644
--- a/chrome/browser/privacy_blacklist/blacklist_store.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_store.cc
@@ -13,7 +13,7 @@
namespace {
-const char cookie[] = "GCPBL100";
+const char cookie[] = "GCPBL200";
const size_t kMaxBlockedTypes = 256;
const size_t kMaxStringSize = 8192;
@@ -55,9 +55,11 @@ bool BlacklistStoreOutput::ReserveEntries(uint32 num) {
bool BlacklistStoreOutput::StoreEntry(const std::string& pattern,
uint32 attributes,
const std::vector<std::string>& types,
+ bool is_exception,
uint32 provider) {
if (WriteString(pattern) &&
WriteUInt(attributes) &&
+ WriteUInt(is_exception ? 1 : 0) &&
WriteUInt(types.size())) {
for (uint32 i = 0; i < types.size(); ++i) {
if (!WriteString(types[i]))
@@ -117,6 +119,7 @@ uint32 BlacklistStoreInput::ReadNumEntries() {
bool BlacklistStoreInput::ReadEntry(std::string* pattern,
uint32* attributes,
std::vector<std::string>* types,
+ bool* is_exception,
uint32* provider) {
*pattern = ReadString();
if (pattern->empty())
@@ -126,6 +129,11 @@ bool BlacklistStoreInput::ReadEntry(std::string* pattern,
if (*attributes == std::numeric_limits<uint32>::max())
return false;
+ uint32 exception = ReadUInt();
+ if (exception == std::numeric_limits<uint32>::max())
+ return false;
+ *is_exception = (exception == 1);
+
if (uint32 n = ReadUInt()) {
if (n >= kMaxBlockedTypes)
return false;
diff --git a/chrome/browser/privacy_blacklist/blacklist_store.h b/chrome/browser/privacy_blacklist/blacklist_store.h
index 5907fb7..63f7c12 100644
--- a/chrome/browser/privacy_blacklist/blacklist_store.h
+++ b/chrome/browser/privacy_blacklist/blacklist_store.h
@@ -44,6 +44,7 @@ class BlacklistStoreOutput {
bool StoreEntry(const std::string& pattern,
uint32 attributes,
const std::vector<std::string>& types,
+ bool is_exception,
uint32 provider);
private:
@@ -87,6 +88,7 @@ class BlacklistStoreInput {
bool ReadEntry(std::string* pattern,
uint32* attributes,
std::vector<std::string>* types,
+ bool* is_exception,
uint32* provider);
private:
diff --git a/chrome/test/data/blacklist_small.pbr b/chrome/test/data/blacklist_small.pbr
index c3f8571..2c0417a 100644
--- a/chrome/test/data/blacklist_small.pbr
+++ b/chrome/test/data/blacklist_small.pbr
Binary files differ