diff options
author | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 12:01:45 +0000 |
---|---|---|
committer | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 12:01:45 +0000 |
commit | 298f3975f4861aea491f9c3939cee7d54e6c3c6c (patch) | |
tree | ea9def7c3a5aaaa5d503e00aeb865cc5302d4ef5 /chrome | |
parent | 8b3e1646d50026a5c9a2326e22c6156a9a4b9a3a (diff) | |
download | chromium_src-298f3975f4861aea491f9c3939cee7d54e6c3c6c.zip chromium_src-298f3975f4861aea491f9c3939cee7d54e6c3c6c.tar.gz chromium_src-298f3975f4861aea491f9c3939cee7d54e6c3c6c.tar.bz2 |
Limiting the "Cookies and site data" form to valid Browsing Data schemes.
This change will prevent extension and devtools (as well as data from any other
internal `chrome-*` URL schemes) from showing up in the list of browsing data.
BUG=121441
TEST=unit_test
Review URL: https://chromiumcodereview.appspot.com/9958107
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130598 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
12 files changed, 137 insertions, 35 deletions
diff --git a/chrome/browser/browsing_data_appcache_helper.cc b/chrome/browser/browsing_data_appcache_helper.cc index 153fa40..7417a19 100644 --- a/chrome/browser/browsing_data_appcache_helper.cc +++ b/chrome/browser/browsing_data_appcache_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "chrome/browser/browsing_data_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" @@ -74,15 +75,15 @@ BrowsingDataAppCacheHelper::~BrowsingDataAppCacheHelper() {} void BrowsingDataAppCacheHelper::OnFetchComplete(int rv) { if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { - // Filter out appcache info entries for extensions. Extension state is not - // considered browsing data. + // Filter out appcache info entries for non-websafe schemes. Extension state + // and DevTools, for example, are not considered browsing data. typedef std::map<GURL, appcache::AppCacheInfoVector> InfoByOrigin; InfoByOrigin& origin_map = info_collection_->infos_by_origin; for (InfoByOrigin::iterator origin = origin_map.begin(); origin != origin_map.end();) { InfoByOrigin::iterator current = origin; ++origin; - if (current->first.SchemeIs(chrome::kExtensionScheme)) + if (!BrowsingDataHelper::HasValidScheme(current->first)) origin_map.erase(current); } @@ -118,6 +119,9 @@ CannedBrowsingDataAppCacheHelper* CannedBrowsingDataAppCacheHelper::Clone() { } void CannedBrowsingDataAppCacheHelper::AddAppCache(const GURL& manifest_url) { + if (!BrowsingDataHelper::HasValidScheme(manifest_url)) + return; // Ignore non-websafe schemes. + typedef std::map<GURL, appcache::AppCacheInfoVector> InfoByOrigin; InfoByOrigin& origin_map = info_collection_->infos_by_origin; appcache::AppCacheInfoVector& appcache_infos_ = diff --git a/chrome/browser/browsing_data_appcache_helper_unittest.cc b/chrome/browser/browsing_data_appcache_helper_unittest.cc index 80b4df7c..cafe50e 100644 --- a/chrome/browser/browsing_data_appcache_helper_unittest.cc +++ b/chrome/browser/browsing_data_appcache_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -104,3 +104,19 @@ TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) { helper->Reset(); ASSERT_TRUE(helper->empty()); } + +TEST_F(CannedBrowsingDataAppCacheHelperTest, IgnoreExtensionsAndDevTools) { + TestingProfile profile; + + GURL manifest1("chrome-extension://abcdefghijklmnopqrstuvwxyz/manifest.xml"); + GURL manifest2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/manifest.xml"); + + scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( + new CannedBrowsingDataAppCacheHelper(&profile)); + + ASSERT_TRUE(helper->empty()); + helper->AddAppCache(manifest1); + ASSERT_TRUE(helper->empty()); + helper->AddAppCache(manifest2); + ASSERT_TRUE(helper->empty()); +} diff --git a/chrome/browser/browsing_data_database_helper.cc b/chrome/browser/browsing_data_database_helper.cc index 0bc331f..ccd89e1 100644 --- a/chrome/browser/browsing_data_database_helper.cc +++ b/chrome/browser/browsing_data_database_helper.cc @@ -9,13 +9,14 @@ #include "base/file_util.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browsing_data_helper.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" #include "net/base/completion_callback.h" #include "net/base/net_errors.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" using content::BrowserContext; using content::BrowserThread; @@ -87,11 +88,9 @@ void BrowsingDataDatabaseHelper::FetchDatabaseInfoOnFileThread() { if (tracker_.get() && tracker_->GetAllOriginsInfo(&origins_info)) { for (std::vector<webkit_database::OriginInfo>::const_iterator ori = origins_info.begin(); ori != origins_info.end(); ++ori) { - const std::string origin_identifier(UTF16ToUTF8(ori->GetOrigin())); - if (StartsWithASCII(origin_identifier, - std::string(chrome::kExtensionScheme), - true)) { - // Extension state is not considered browsing data. + const GURL origin(UTF16ToUTF8(ori->GetOrigin())); + if (!BrowsingDataHelper::HasValidScheme(origin)) { + // Non-websafe state is not considered browsing data. continue; } WebSecurityOrigin web_security_origin = @@ -107,7 +106,7 @@ void BrowsingDataDatabaseHelper::FetchDatabaseInfoOnFileThread() { database_info_.push_back(DatabaseInfo( web_security_origin.host().utf8(), UTF16ToUTF8(*db), - origin_identifier, + UTF16ToUTF8(ori->GetOrigin()), UTF16ToUTF8(ori->GetDatabaseDescription(*db)), web_security_origin.toString().utf8(), file_info.size, @@ -180,8 +179,10 @@ void CannedBrowsingDataDatabaseHelper::AddDatabase( const std::string& name, const std::string& description) { base::AutoLock auto_lock(lock_); - pending_database_info_.push_back(PendingDatabaseInfo( - origin, name, description)); + if (BrowsingDataHelper::HasValidScheme(origin)) { + pending_database_info_.push_back(PendingDatabaseInfo( + origin, name, description)); + } } void CannedBrowsingDataDatabaseHelper::Reset() { diff --git a/chrome/browser/browsing_data_database_helper_unittest.cc b/chrome/browser/browsing_data_database_helper_unittest.cc index cda7591..01dc3e3 100644 --- a/chrome/browser/browsing_data_database_helper_unittest.cc +++ b/chrome/browser/browsing_data_database_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,9 +10,9 @@ namespace { -typedef testing::Test CannedBrowsingDataDatabaseTest; +typedef testing::Test CannedBrowsingDataDatabaseHelperTest; -TEST_F(CannedBrowsingDataDatabaseTest, Empty) { +TEST_F(CannedBrowsingDataDatabaseHelperTest, Empty) { TestingProfile profile; const GURL origin("http://host1:1/"); @@ -28,4 +28,23 @@ TEST_F(CannedBrowsingDataDatabaseTest, Empty) { ASSERT_TRUE(helper->empty()); } +TEST_F(CannedBrowsingDataDatabaseHelperTest, IgnoreExtensionsAndDevTools) { + TestingProfile profile; + + const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/"); + const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/"); + const char db[] = "db1"; + + scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( + new CannedBrowsingDataDatabaseHelper(&profile)); + + ASSERT_TRUE(helper->empty()); + helper->AddDatabase(origin1, db, ""); + ASSERT_TRUE(helper->empty()); + helper->AddDatabase(origin2, db, ""); + ASSERT_TRUE(helper->empty()); + helper->Reset(); + ASSERT_TRUE(helper->empty()); +} + } // namespace diff --git a/chrome/browser/browsing_data_file_system_helper.cc b/chrome/browser/browsing_data_file_system_helper.cc index 9cde505..417ce0ca 100644 --- a/chrome/browser/browsing_data_file_system_helper.cc +++ b/chrome/browser/browsing_data_file_system_helper.cc @@ -11,6 +11,7 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browsing_data_helper.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" #include "webkit/fileapi/file_system_context.h" @@ -124,11 +125,11 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { fileapi::kFileSystemTypeTemporary); GURL current; + while (!(current = origin_enumerator->Next()).is_empty()) { - if (current.SchemeIs(chrome::kExtensionScheme)) { - // Extension state is not considered browsing data. - continue; - } + if (!BrowsingDataHelper::HasValidScheme(current)) + continue; // Non-websafe state is not considered browsing data. + // We can call these synchronous methods as we've already verified that // we're running on the FILE thread. int64 persistent_usage = quota_util->GetOriginUsageOnFileThread(current, @@ -242,6 +243,9 @@ void CannedBrowsingDataFileSystemHelper::AddFileSystem( if (duplicate_origin) return; + if (!BrowsingDataHelper::HasValidScheme(origin)) + return; // Non-websafe state is not considered browsing data. + file_system_info_.push_back(FileSystemInfo( origin, (type == fileapi::kFileSystemTypePersistent), diff --git a/chrome/browser/browsing_data_file_system_helper_unittest.cc b/chrome/browser/browsing_data_file_system_helper_unittest.cc index 8ed961b..5aae870 100644 --- a/chrome/browser/browsing_data_file_system_helper_unittest.cc +++ b/chrome/browser/browsing_data_file_system_helper_unittest.cc @@ -33,9 +33,15 @@ const char kTestOrigin1[] = "http://host1:1/"; const char kTestOrigin2[] = "http://host2:2/"; const char kTestOrigin3[] = "http://host3:3/"; +// Extensions and Devtools should be ignored. +const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; +const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; + const GURL kOrigin1(kTestOrigin1); const GURL kOrigin2(kTestOrigin2); const GURL kOrigin3(kTestOrigin3); +const GURL kOriginExt(kTestOriginExt); +const GURL kOriginDevTools(kTestOriginDevTools); // TODO(mkwst): Update this size once the discussion in http://crbug.com/86114 // is concluded. @@ -298,4 +304,14 @@ TEST_F(BrowsingDataFileSystemHelperTest, CannedAddFileSystem) { EXPECT_EQ(100, info->usage_temporary); } +// Verifies that the CannedBrowsingDataFileSystemHelper correctly ignores +// extension and devtools schemes. +TEST_F(BrowsingDataFileSystemHelperTest, IgnoreExtensionsAndDevTools) { + ASSERT_TRUE(canned_helper_->empty()); + canned_helper_->AddFileSystem(kOriginExt, kTemporary, 0); + ASSERT_TRUE(canned_helper_->empty()); + canned_helper_->AddFileSystem(kOriginDevTools, kTemporary, 0); + ASSERT_TRUE(canned_helper_->empty()); +} + } // namespace diff --git a/chrome/browser/browsing_data_indexed_db_helper.cc b/chrome/browser/browsing_data_indexed_db_helper.cc index fea3b26..5794a62 100644 --- a/chrome/browser/browsing_data_indexed_db_helper.cc +++ b/chrome/browser/browsing_data_indexed_db_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +12,7 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browsing_data_helper.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/indexed_db_context.h" @@ -108,8 +109,9 @@ void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { for (std::vector<GURL>::const_iterator iter = origins.begin(); iter != origins.end(); ++iter) { const GURL& origin = *iter; - if (origin.SchemeIs(chrome::kExtensionScheme)) - continue; // Extension state is not considered browsing data. + if (!BrowsingDataHelper::HasValidScheme(origin)) + continue; // Non-websafe state is not considered browsing data. + indexed_db_info_.push_back(IndexedDBInfo( origin, indexed_db_context_->GetOriginDiskUsage(origin), @@ -190,6 +192,9 @@ CannedBrowsingDataIndexedDBHelper* CannedBrowsingDataIndexedDBHelper::Clone() { void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( const GURL& origin, const string16& description) { + if (!BrowsingDataHelper::HasValidScheme(origin)) + return; // Non-websafe state is not considered browsing data. + base::AutoLock auto_lock(lock_); pending_indexed_db_info_.push_back(PendingIndexedDBInfo(origin, description)); } diff --git a/chrome/browser/browsing_data_indexed_db_helper_unittest.cc b/chrome/browser/browsing_data_indexed_db_helper_unittest.cc index da7aeb3..0d1fd76 100644 --- a/chrome/browser/browsing_data_indexed_db_helper_unittest.cc +++ b/chrome/browser/browsing_data_indexed_db_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -26,4 +26,19 @@ TEST_F(CannedBrowsingDataIndexedDBHelperTest, Empty) { ASSERT_TRUE(helper->empty()); } +TEST_F(CannedBrowsingDataIndexedDBHelperTest, IgnoreExtensionsAndDevTools) { + const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/"); + const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/"); + const string16 description(ASCIIToUTF16("description")); + + scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( + new CannedBrowsingDataIndexedDBHelper()); + + ASSERT_TRUE(helper->empty()); + helper->AddIndexedDB(origin1, description); + ASSERT_TRUE(helper->empty()); + helper->AddIndexedDB(origin2, description); + ASSERT_TRUE(helper->empty()); +} + } // namespace diff --git a/chrome/browser/browsing_data_local_storage_helper.cc b/chrome/browser/browsing_data_local_storage_helper.cc index 05b31c1..43bc237 100644 --- a/chrome/browser/browsing_data_local_storage_helper.cc +++ b/chrome/browser/browsing_data_local_storage_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,12 +9,13 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browsing_data_helper.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/dom_storage_context.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "webkit/glue/webkit_glue.h" using content::BrowserContext; @@ -101,10 +102,9 @@ void BrowsingDataLocalStorageHelper::FetchLocalStorageInfo( WebSecurityOrigin web_security_origin = WebSecurityOrigin::createFromDatabaseIdentifier( webkit_glue::FilePathToWebString(file_path.BaseName())); - if (EqualsASCII(web_security_origin.protocol(), chrome::kExtensionScheme)) { - // Extension state is not considered browsing data. - continue; - } + if (!BrowsingDataHelper::IsValidScheme(web_security_origin.protocol())) + continue; // Non-websafe state is not considered browsing data. + base::PlatformFileInfo file_info; bool ret = file_util::GetFileInfo(file_path, &file_info); if (ret) { @@ -158,7 +158,8 @@ CannedBrowsingDataLocalStorageHelper::Clone() { void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( const GURL& origin) { - pending_local_storage_info_.insert(origin); + if (BrowsingDataHelper::HasValidScheme(origin)) + pending_local_storage_info_.insert(origin); } void CannedBrowsingDataLocalStorageHelper::Reset() { diff --git a/chrome/browser/browsing_data_local_storage_helper_unittest.cc b/chrome/browser/browsing_data_local_storage_helper_unittest.cc index bbad720..64a7f93 100644 --- a/chrome/browser/browsing_data_local_storage_helper_unittest.cc +++ b/chrome/browser/browsing_data_local_storage_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -26,4 +26,20 @@ TEST_F(CannedBrowsingDataLocalStorageTest, Empty) { ASSERT_TRUE(helper->empty()); } +TEST_F(CannedBrowsingDataLocalStorageTest, IgnoreExtensionsAndDevTools) { + TestingProfile profile; + + const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/"); + const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/"); + + scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( + new CannedBrowsingDataLocalStorageHelper(&profile)); + + ASSERT_TRUE(helper->empty()); + helper->AddLocalStorage(origin1); + ASSERT_TRUE(helper->empty()); + helper->AddLocalStorage(origin2); + ASSERT_TRUE(helper->empty()); +} + } // namespace diff --git a/chrome/browser/browsing_data_quota_helper_impl.cc b/chrome/browser/browsing_data_quota_helper_impl.cc index 04a9a734..ed8bb71 100644 --- a/chrome/browser/browsing_data_quota_helper_impl.cc +++ b/chrome/browser/browsing_data_quota_helper_impl.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" +#include "chrome/browser/browsing_data_helper.h" #include "webkit/quota/quota_manager.h" using content::BrowserThread; @@ -88,7 +89,7 @@ void BrowsingDataQuotaHelperImpl::GotOrigins( for (std::set<GURL>::const_iterator itr = origins.begin(); itr != origins.end(); ++itr) - if (!itr->SchemeIs(chrome::kExtensionScheme)) + if (BrowsingDataHelper::HasValidScheme(*itr)) pending_hosts_.insert(std::make_pair(itr->host(), type)); DCHECK(type == quota::kStorageTypeTemporary || diff --git a/chrome/browser/browsing_data_quota_helper_unittest.cc b/chrome/browser/browsing_data_quota_helper_unittest.cc index 5203b88..41351d3 100644 --- a/chrome/browser/browsing_data_quota_helper_unittest.cc +++ b/chrome/browser/browsing_data_quota_helper_unittest.cc @@ -160,7 +160,7 @@ TEST_F(BrowsingDataQuotaHelperTest, FetchData) { EXPECT_TRUE(expected == actual); } -TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensions) { +TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensionsAndDevTools) { const quota::MockOriginData kOrigins[] = { {"http://example.com/", quota::kStorageTypeTemporary, 1}, {"https://example.com/", quota::kStorageTypeTemporary, 10}, @@ -170,6 +170,10 @@ TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensions) { quota::kStorageTypeTemporary, 10000}, {"chrome-extension://abcdefghijklmnopqrstuvwxyz/", quota::kStorageTypePersistent, 100000}, + {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/", + quota::kStorageTypeTemporary, 10000}, + {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/", + quota::kStorageTypePersistent, 100000}, }; RegisterClient(kOrigins, arraysize(kOrigins)); |