summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoridanan@chromium.org <idanan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 15:18:24 +0000
committeridanan@chromium.org <idanan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 15:18:24 +0000
commit653aa54bd4a87008873f5d3154eb6d82f222f029 (patch)
tree684bafb0fcd5d665b45c94b1a3b145f6bd3c3d19
parent48d8e47acc6f19fd9785ef0bcc697d0ca9ac4172 (diff)
downloadchromium_src-653aa54bd4a87008873f5d3154eb6d82f222f029.zip
chromium_src-653aa54bd4a87008873f5d3154eb6d82f222f029.tar.gz
chromium_src-653aa54bd4a87008873f5d3154eb6d82f222f029.tar.bz2
Load Multiple Blacklists
Add the ability to load multiple text blacklists into the binary blacklist representation. NOTE: Included Binary file means this change expects to fail on the trybots in blacklist_io_test.cc:103. All other checks must pass. BUG=16932 TEST=BlacklistIO* Review URL: http://codereview.chromium.org/159199 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21841 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/privacy_blacklist/blacklist.cc17
-rw-r--r--chrome/browser/privacy_blacklist/blacklist.h29
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_io.h1
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_io_unittest.cc76
-rw-r--r--chrome/test/data/blacklist_samples/annoying_ads.pbl12
-rw-r--r--chrome/test/data/blacklist_samples/block_flash.pbl5
-rw-r--r--chrome/test/data/blacklist_samples/combine3.pbrbin0 -> 305 bytes
-rw-r--r--chrome/test/data/blacklist_samples/session_cookies.pbl6
-rw-r--r--chrome/tools/pbl_tool/pbl_tool.cc26
9 files changed, 134 insertions, 38 deletions
diff --git a/chrome/browser/privacy_blacklist/blacklist.cc b/chrome/browser/privacy_blacklist/blacklist.cc
index a234bf2..0be3931 100644
--- a/chrome/browser/privacy_blacklist/blacklist.cc
+++ b/chrome/browser/privacy_blacklist/blacklist.cc
@@ -22,6 +22,23 @@ const char* const cookie_headers[2] = { "cookie", "set-cookie" };
} // namespace
+const unsigned int Blacklist::kBlockAll = 1;
+const unsigned int Blacklist::kDontSendCookies = 1 << 1;
+const unsigned int Blacklist::kDontStoreCookies = 1 << 2;
+const unsigned int Blacklist::kDontPersistCookies = 1 << 3;
+const unsigned int Blacklist::kDontSendReferrer = 1 << 4;
+const unsigned int Blacklist::kDontSendUserAgent = 1 << 5;
+const unsigned int Blacklist::kBlockByType = 1 << 6;
+const unsigned int Blacklist::kBlockUnsecure = 1 << 7;
+const unsigned int Blacklist::kBlockRequest = kBlockAll | kBlockUnsecure;
+const unsigned int Blacklist::kBlockResponse = kBlockByType;
+const unsigned int Blacklist::kModifySentHeaders =
+ kDontSendCookies | kDontSendUserAgent | kDontSendReferrer;
+const unsigned int Blacklist::kModifyReceivedHeaders =
+ kDontPersistCookies | kDontStoreCookies;
+const unsigned int Blacklist::kFilterByHeaders =
+ kModifyReceivedHeaders | kBlockByType;
+
// Value is not important, here just that the object has an address.
const void* const Blacklist::kRequestDataKey = 0;
diff --git a/chrome/browser/privacy_blacklist/blacklist.h b/chrome/browser/privacy_blacklist/blacklist.h
index 4c36d08..a4b6b9ba 100644
--- a/chrome/browser/privacy_blacklist/blacklist.h
+++ b/chrome/browser/privacy_blacklist/blacklist.h
@@ -32,24 +32,21 @@ class FilePath;
class Blacklist {
public:
// Filter attributes (more to come):
- static const unsigned int kBlockAll = 1;
- static const unsigned int kDontSendCookies = 1 << 1;
- static const unsigned int kDontStoreCookies = 1 << 2;
- static const unsigned int kDontPersistCookies = 1 << 3;
- static const unsigned int kDontSendReferrer = 1 << 4;
- static const unsigned int kDontSendUserAgent = 1 << 5;
- static const unsigned int kBlockByType = 1 << 6;
- static const unsigned int kBlockUnsecure = 1 << 7;
+ static const unsigned int kBlockAll;
+ static const unsigned int kDontSendCookies;
+ static const unsigned int kDontStoreCookies;
+ static const unsigned int kDontPersistCookies;
+ static const unsigned int kDontSendReferrer;
+ static const unsigned int kDontSendUserAgent;
+ static const unsigned int kBlockByType;
+ static const unsigned int kBlockUnsecure;
// Aggregate filter types:
- static const unsigned int kBlockRequest = kBlockAll | kBlockUnsecure;
- static const unsigned int kBlockResponse = kBlockByType;
- static const unsigned int kModifySentHeaders =
- kDontSendCookies | kDontSendUserAgent | kDontSendReferrer;
- static const unsigned int kModifyReceivedHeaders =
- kDontPersistCookies | kDontStoreCookies;
- static const unsigned int kFilterByHeaders = kModifyReceivedHeaders |
- kBlockByType;
+ static const unsigned int kBlockRequest;
+ static const unsigned int kBlockResponse;
+ static const unsigned int kModifySentHeaders;
+ static const unsigned int kModifyReceivedHeaders;
+ static const unsigned int kFilterByHeaders;
// Key used to access data attached to URLRequest objects.
static const void* const kRequestDataKey;
diff --git a/chrome/browser/privacy_blacklist/blacklist_io.h b/chrome/browser/privacy_blacklist/blacklist_io.h
index fd19ae6..4971d35 100644
--- a/chrome/browser/privacy_blacklist/blacklist_io.h
+++ b/chrome/browser/privacy_blacklist/blacklist_io.h
@@ -37,6 +37,7 @@ class BlacklistIO {
std::list<Blacklist::Provider*> providers_;
FRIEND_TEST(BlacklistIOTest, Generic);
+ FRIEND_TEST(BlacklistIOTest, Combine);
DISALLOW_COPY_AND_ASSIGN(BlacklistIO);
};
diff --git a/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc
index 6899321..cd43449 100644
--- a/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_io_unittest.cc
@@ -13,17 +13,17 @@
TEST(BlacklistIOTest, Generic) {
// Testing data path.
- std::wstring data_dir;
+ FilePath data_dir;
PathService::Get(chrome::DIR_TEST_DATA, &data_dir);
- std::wstring input(data_dir);
- file_util::AppendToPath(&input, L"blacklist_small.pbl");
+ FilePath input =
+ data_dir.Append(FilePath::FromWStringHack(L"blacklist_small.pbl"));
- std::wstring expected(data_dir);
- file_util::AppendToPath(&expected, L"blacklist_small.pbr");
+ FilePath expected =
+ data_dir.Append(FilePath::FromWStringHack(L"blacklist_small.pbr"));
BlacklistIO io;
- EXPECT_TRUE(io.Read(FilePath::FromWStringHack(input)));
+ EXPECT_TRUE(io.Read(input));
const std::list<Blacklist::Entry*>& blacklist = io.blacklist();
EXPECT_EQ(5U, blacklist.size());
@@ -38,10 +38,68 @@ TEST(BlacklistIOTest, Generic) {
EXPECT_EQ("Sample", io.providers().front()->name());
EXPECT_EQ("http://www.google.com", io.providers().front()->url());
- std::wstring output;
+ FilePath output;
PathService::Get(base::DIR_TEMP, &output);
- file_util::AppendToPath(&output, L"blacklist_small.pbr");
- CHECK(io.Write(FilePath::FromWStringHack(output)));
+ output = output.Append(FilePath::FromWStringHack(L"blacklist_small.pbr"));
+ CHECK(io.Write(output));
+ EXPECT_TRUE(file_util::ContentsEqual(output, expected));
+ EXPECT_TRUE(file_util::Delete(output, false));
+}
+
+TEST(BlacklistIOTest, Combine) {
+ // Testing data path.
+ FilePath data_dir;
+ PathService::Get(chrome::DIR_TEST_DATA, &data_dir);
+ data_dir = data_dir.Append(FilePath::FromWStringHack(L"blacklist_samples"));
+
+ FilePath input1 =
+ data_dir.Append(FilePath::FromWStringHack(L"annoying_ads.pbl"));
+
+ FilePath input2 =
+ data_dir.Append(FilePath::FromWStringHack(L"block_flash.pbl"));
+
+ FilePath input3 =
+ data_dir.Append(FilePath::FromWStringHack(L"session_cookies.pbl"));
+
+ BlacklistIO io;
+ EXPECT_TRUE(io.Read(input1));
+ EXPECT_TRUE(io.Read(input2));
+ EXPECT_TRUE(io.Read(input3));
+
+ const std::list<Blacklist::Entry*>& blacklist = io.blacklist();
+ EXPECT_EQ(5U, blacklist.size());
+
+ std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin();
+ EXPECT_EQ(Blacklist::kBlockAll, (*i)->attributes());
+ EXPECT_EQ("annoying.ads.tv/@", (*i++)->pattern());
+ EXPECT_EQ(Blacklist::kBlockAll, (*i)->attributes());
+ EXPECT_EQ("@/annoying/120x600.jpg", (*i++)->pattern());
+ EXPECT_EQ(Blacklist::kBlockAll, (*i)->attributes());
+ EXPECT_EQ("@/annoying_ads/@", (*i++)->pattern());
+ EXPECT_EQ(Blacklist::kBlockByType, (*i)->attributes());
+ EXPECT_EQ("@", (*i++)->pattern());
+ EXPECT_EQ(Blacklist::kDontPersistCookies, (*i)->attributes());
+ EXPECT_EQ("@", (*i++)->pattern());
+
+ const std::list<Blacklist::Provider*>& providers = io.providers();
+ EXPECT_EQ(3U, providers.size());
+
+ std::list<Blacklist::Provider*>::const_iterator j = providers.begin();
+ EXPECT_EQ("AnnoyingAds", (*j)->name());
+ EXPECT_EQ("http://www.ads.tv", (*j++)->url());
+ EXPECT_EQ("BlockFlash", (*j)->name());
+ EXPECT_EQ("http://www.google.com", (*j++)->url());
+ EXPECT_EQ("SessionCookies", (*j)->name());
+ EXPECT_EQ("http://www.google.com", (*j++)->url());
+
+ FilePath output;
+ PathService::Get(base::DIR_TEMP, &output);
+ output = output.Append(FilePath::FromWStringHack(L"combine3.pbr"));
+
+ FilePath expected =
+ data_dir.Append(FilePath::FromWStringHack(L"combine3.pbr"));
+
+ CHECK(io.Write(output));
EXPECT_TRUE(file_util::ContentsEqual(output, expected));
EXPECT_TRUE(file_util::Delete(output, false));
}
diff --git a/chrome/test/data/blacklist_samples/annoying_ads.pbl b/chrome/test/data/blacklist_samples/annoying_ads.pbl
new file mode 100644
index 0000000..b9dc8d2
--- /dev/null
+++ b/chrome/test/data/blacklist_samples/annoying_ads.pbl
@@ -0,0 +1,12 @@
+[Chromium::PrivacyBlacklist]
+|Name: AnnoyingAds
+|URL: http://www.ads.tv
+
+# Block Ads by servers
+annoying.ads.tv/@ => kBlockAll
+
+# Block Ads by name
+@/annoying/120x600.jpg => kBlockAll
+
+# Block Ads by path
+@/annoying_ads/@ => kBlockAll
diff --git a/chrome/test/data/blacklist_samples/block_flash.pbl b/chrome/test/data/blacklist_samples/block_flash.pbl
new file mode 100644
index 0000000..2373f30
--- /dev/null
+++ b/chrome/test/data/blacklist_samples/block_flash.pbl
@@ -0,0 +1,5 @@
+[Chromium::PrivacyBlacklist]
+|Name: BlockFlash
+|URL: http://www.google.com
+
+@ => kBlockByType(application/x-shockwave-flash)
diff --git a/chrome/test/data/blacklist_samples/combine3.pbr b/chrome/test/data/blacklist_samples/combine3.pbr
new file mode 100644
index 0000000..30ef556
--- /dev/null
+++ b/chrome/test/data/blacklist_samples/combine3.pbr
Binary files differ
diff --git a/chrome/test/data/blacklist_samples/session_cookies.pbl b/chrome/test/data/blacklist_samples/session_cookies.pbl
new file mode 100644
index 0000000..f83727b
--- /dev/null
+++ b/chrome/test/data/blacklist_samples/session_cookies.pbl
@@ -0,0 +1,6 @@
+[Chromium::PrivacyBlacklist]
+|Name: SessionCookies
+|URL: http://www.google.com
+
+# Block all Flash media everywhere.
+@ => kDontPersistCookies
diff --git a/chrome/tools/pbl_tool/pbl_tool.cc b/chrome/tools/pbl_tool/pbl_tool.cc
index 355c7ea..2e8c037 100644
--- a/chrome/tools/pbl_tool/pbl_tool.cc
+++ b/chrome/tools/pbl_tool/pbl_tool.cc
@@ -24,8 +24,8 @@
namespace {
int PrintUsage(int argc, ICHAR* argv[]) {
- ICERR << "Usage: " << argv[0] << " <source> <target>\n"
- " <source> is the text blacklist (.pbl) to load.\n"
+ ICERR << "Usage: " << argv[0] << " <source>... <target>\n"
+ " <source> are text blacklists (.pbl) to load.\n"
" <target> is the binary output blacklist repository.\n\n"
"Adds all entries from <source> to <target>.\n"
"Creates <target> if it does not exist.\n";
@@ -40,18 +40,18 @@ int IMAIN(int argc, ICHAR* argv[]) {
if (argc < 3)
return PrintUsage(argc, argv);
- FilePath input(argv[1]);
- FilePath output(argv[2]);
-
BlacklistIO io;
- if (io.Read(input)) {
- if (io.Write(output)) {
- return 0;
- } else {
- ICERR << "Error writing output file " << argv[2] << "\n";
+ for (int current = 1; current < argc-1; ++current) {
+ FilePath input(argv[current]);
+ if (!io.Read(input)) {
+ ICERR << "Error reading input file " << argv[current] << "\n";
+ return -1;
}
- } else {
- ICERR << "Error reading input file " << argv[1] << "\n";
}
- return -1;
+
+ FilePath output(argv[argc-1]);
+ if (!io.Write(output))
+ ICERR << "Error writing output file " << argv[2] << "\n";
+
+ return 0;
}