summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 16:57:12 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 16:57:12 +0000
commit2c0e5236ef9c18c742be1591fcd310fa2a60e214 (patch)
treed074909266e839a45b6b25abe5f0827a017a0f61 /chrome
parenta956916ffd429577a979efa34af889801b8ed44e (diff)
downloadchromium_src-2c0e5236ef9c18c742be1591fcd310fa2a60e214.zip
chromium_src-2c0e5236ef9c18c742be1591fcd310fa2a60e214.tar.gz
chromium_src-2c0e5236ef9c18c742be1591fcd310fa2a60e214.tar.bz2
Take filter exceptions into account when matching against resource requests.
BUG=16932 TEST=BlacklistTest.Generic Review URL: http://codereview.chromium.org/541025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/privacy_blacklist/blacklist.cc28
-rw-r--r--chrome/browser/privacy_blacklist/blacklist.h20
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_io_unittest.cc4
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_unittest.cc44
-rw-r--r--chrome/test/data/blacklist_small.pbl6
-rw-r--r--chrome/test/data/blacklist_small.pbrbin343 -> 453 bytes
6 files changed, 89 insertions, 13 deletions
diff --git a/chrome/browser/privacy_blacklist/blacklist.cc b/chrome/browser/privacy_blacklist/blacklist.cc
index ea9dc19..732037e 100644
--- a/chrome/browser/privacy_blacklist/blacklist.cc
+++ b/chrome/browser/privacy_blacklist/blacklist.cc
@@ -141,24 +141,38 @@ void Blacklist::Entry::SwapTypes(std::vector<std::string>* types) {
}
bool Blacklist::Match::MatchType(const std::string& type) const {
- for (std::vector<const Entry*>::const_iterator i = entries_.begin();
- i != entries_.end(); ++i) {
+ // No match if any exception matches.
+ for (std::vector<const Entry*>::const_iterator i = exception_entries_.begin();
+ i != exception_entries_.end(); ++i) {
+ if ((*i)->MatchesType(type))
+ return false;
+ }
+
+ // Otherwise, match if any blacklist entry matches.
+ for (std::vector<const Entry*>::const_iterator i = matching_entries_.begin();
+ i != matching_entries_.end(); ++i) {
if ((*i)->MatchesType(type))
return true;
}
+
return false;
}
bool Blacklist::Match::IsBlocked(const GURL& url) const {
- return (attributes_ & kBlockAll) ||
- ((attributes_ & kBlockUnsecure) && !url.SchemeIsSecure());
+ return (attributes() & kBlockAll) ||
+ ((attributes() & kBlockUnsecure) && !url.SchemeIsSecure());
}
-Blacklist::Match::Match() : attributes_(0) {}
+Blacklist::Match::Match() : matching_attributes_(0), exception_attributes_(0) {}
void Blacklist::Match::AddEntry(const Entry* entry) {
- attributes_ |= entry->attributes();
- entries_.push_back(entry);
+ if (entry->is_exception()) {
+ exception_attributes_ |= entry->attributes();
+ exception_entries_.push_back(entry);
+ } else {
+ matching_attributes_ |= entry->attributes();
+ matching_entries_.push_back(entry);
+ }
}
Blacklist::Blacklist() {
diff --git a/chrome/browser/privacy_blacklist/blacklist.h b/chrome/browser/privacy_blacklist/blacklist.h
index 44df410..96112f6 100644
--- a/chrome/browser/privacy_blacklist/blacklist.h
+++ b/chrome/browser/privacy_blacklist/blacklist.h
@@ -84,6 +84,9 @@ class Blacklist {
// Bitfield of filter-attributes matching the pattern.
unsigned int attributes() const { return attributes_; }
+ // True if this entry is an exception to the blacklist.
+ bool is_exception() const { return is_exception_; }
+
// Provider of this blacklist entry, used for assigning blame ;)
const Provider* provider() const { return provider_; }
@@ -130,18 +133,27 @@ class Blacklist {
class Match : public URLRequest::UserData {
public:
// Functions that return combined results from all entries.
- unsigned int attributes() const { return attributes_; }
+ unsigned int attributes() const {
+ return (matching_attributes_ & (~exception_attributes_));
+ }
bool MatchType(const std::string&) const;
bool IsBlocked(const GURL&) const;
// Access to individual entries, mostly for display/logging purposes.
- const std::vector<const Entry*>& entries() const { return entries_; }
+ const std::vector<const Entry*>& entries() const {
+ return matching_entries_;
+ }
private:
Match();
void AddEntry(const Entry* entry);
- std::vector<const Entry*> entries_;
- unsigned int attributes_; // Precomputed ORed attributes of entries.
+
+ std::vector<const Entry*> matching_entries_;
+ std::vector<const Entry*> exception_entries_;
+
+ // Precomputed ORed attributes of matching/exception entries.
+ unsigned int matching_attributes_;
+ unsigned int exception_attributes_;
friend class Blacklist; // Only blacklist constructs and sets these.
};
diff --git a/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc
index e92e120..096966b 100644
--- a/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc
@@ -28,7 +28,7 @@ TEST(BlacklistIOTest, Generic) {
const Blacklist::EntryList entries(blacklist.entries_begin(),
blacklist.entries_end());
- ASSERT_EQ(7U, entries.size());
+ ASSERT_EQ(9U, entries.size());
EXPECT_EQ("@", entries[0]->pattern());
EXPECT_EQ("@poor-security-site.com", entries[1]->pattern());
@@ -37,6 +37,8 @@ TEST(BlacklistIOTest, Generic) {
EXPECT_EQ("www.site.com/bad/url", entries[4]->pattern());
EXPECT_EQ("@/script?@", entries[5]->pattern());
EXPECT_EQ("@?badparam@", entries[6]->pattern());
+ EXPECT_EQ("www.site.com/bad/url/good", entries[7]->pattern());
+ EXPECT_EQ("www.good.com", entries[8]->pattern());
const Blacklist::ProviderList providers(blacklist.providers_begin(),
blacklist.providers_end());
diff --git a/chrome/browser/privacy_blacklist/blacklist_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_unittest.cc
index 1a237e2..1202629 100644
--- a/chrome/browser/privacy_blacklist/blacklist_unittest.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_unittest.cc
@@ -24,12 +24,13 @@ TEST(BlacklistTest, Generic) {
Blacklist::EntryList entries(blacklist.entries_begin(),
blacklist.entries_end());
- ASSERT_EQ(7U, entries.size());
+ ASSERT_EQ(9U, entries.size());
EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
entries[0]->attributes());
EXPECT_TRUE(entries[0]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[0]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[0]->is_exception());
EXPECT_EQ("@", entries[0]->pattern());
// All entries include global attributes.
@@ -37,38 +38,59 @@ TEST(BlacklistTest, Generic) {
EXPECT_EQ(Blacklist::kBlockUnsecure|0, entries[1]->attributes());
EXPECT_FALSE(entries[1]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[1]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[1]->is_exception());
EXPECT_EQ("@poor-security-site.com", entries[1]->pattern());
EXPECT_EQ(Blacklist::kDontSendCookies|Blacklist::kDontStoreCookies,
entries[2]->attributes());
EXPECT_FALSE(entries[2]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[2]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[2]->is_exception());
EXPECT_EQ("@.ad-serving-place.com", entries[2]->pattern());
EXPECT_EQ(Blacklist::kDontSendUserAgent|Blacklist::kDontSendReferrer,
entries[3]->attributes());
EXPECT_FALSE(entries[3]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[3]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[3]->is_exception());
EXPECT_EQ("www.site.com/anonymous/folder/@", entries[3]->pattern());
// NOTE: Silly bitwise-or with zero to workaround a Mac compiler bug.
EXPECT_EQ(Blacklist::kBlockAll|0, entries[4]->attributes());
EXPECT_FALSE(entries[4]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[4]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[4]->is_exception());
EXPECT_EQ("www.site.com/bad/url", entries[4]->pattern());
// NOTE: Silly bitwise-or with zero to workaround a Mac compiler bug.
EXPECT_EQ(Blacklist::kBlockAll|0, entries[5]->attributes());
EXPECT_FALSE(entries[5]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[5]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[5]->is_exception());
EXPECT_EQ("@/script?@", entries[5]->pattern());
// NOTE: Silly bitwise-or with zero to workaround a Mac compiler bug.
EXPECT_EQ(Blacklist::kBlockAll|0, entries[6]->attributes());
EXPECT_FALSE(entries[6]->MatchesType("application/x-shockwave-flash"));
EXPECT_FALSE(entries[6]->MatchesType("image/jpeg"));
+ EXPECT_FALSE(entries[6]->is_exception());
EXPECT_EQ("@?badparam@", entries[6]->pattern());
+ // NOTE: Silly bitwise-or with zero to workaround a Mac compiler bug.
+ EXPECT_EQ(Blacklist::kBlockAll|0, entries[7]->attributes());
+ EXPECT_FALSE(entries[7]->MatchesType("application/x-shockwave-flash"));
+ EXPECT_FALSE(entries[7]->MatchesType("image/jpeg"));
+ EXPECT_TRUE(entries[7]->is_exception());
+ EXPECT_EQ("www.site.com/bad/url/good", entries[7]->pattern());
+
+ // NOTE: Silly bitwise-or with zero to workaround a Mac compiler bug.
+ EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ entries[8]->attributes());
+ EXPECT_TRUE(entries[8]->MatchesType("application/x-shockwave-flash"));
+ EXPECT_FALSE(entries[8]->MatchesType("image/jpeg"));
+ EXPECT_TRUE(entries[8]->is_exception());
+ EXPECT_EQ("www.good.com", entries[8]->pattern());
+
Blacklist::ProviderList providers(blacklist.providers_begin(),
blacklist.providers_end());
@@ -89,6 +111,7 @@ TEST(BlacklistTest, Generic) {
EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
match->attributes());
EXPECT_EQ(1U, match->entries().size());
+ EXPECT_TRUE(match->MatchType("application/x-shockwave-flash"));
delete match;
}
@@ -171,6 +194,25 @@ TEST(BlacklistTest, Generic) {
delete match;
}
+ // Whitelisting tests.
+ match = blacklist.FindMatch(GURL("http://www.site.com/bad/url/good"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(2U, match->entries().size());
+ EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ match->attributes());
+ delete match;
+ }
+
+ match = blacklist.FindMatch(GURL("http://www.good.com"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(1U, match->entries().size());
+ EXPECT_EQ(0U, match->attributes());
+ EXPECT_FALSE(match->MatchType("application/x-shockwave-flash"));
+ delete match;
+ }
+
// StripCookieExpiry Tests
std::string cookie1(
"PREF=ID=14a549990453e42a:TM=1245183232:LM=1245183232:S=Occ7khRVIEE36Ao5;"
diff --git a/chrome/test/data/blacklist_small.pbl b/chrome/test/data/blacklist_small.pbl
index be32c9b..5d25b7b 100644
--- a/chrome/test/data/blacklist_small.pbl
+++ b/chrome/test/data/blacklist_small.pbl
@@ -23,3 +23,9 @@ www.site.com/bad/url => kBlockAll
# Affect queries with a specific parameter
@?badparam@ => kBlockAll
+
+# Whitelist a specific URL
+-www.site.com/bad/url/good => kBlockAll
+
+# Whitelist attributes
+-www.good.com => kBlockByType(application/x-shockwave-flash), kDontPersistCookies
diff --git a/chrome/test/data/blacklist_small.pbr b/chrome/test/data/blacklist_small.pbr
index f6268808..b4fb030 100644
--- a/chrome/test/data/blacklist_small.pbr
+++ b/chrome/test/data/blacklist_small.pbr
Binary files differ