Commit 91cbac02 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Support origin filtering when clearing media licenses

Clearing browser data can be done with filters that specify origin
white lists or black lists, so update the code that clears media licenses
to handle a filter if one provided.

BUG=901993
TEST=new browser_test passes

Change-Id: I413703b456479fc8b85916c96eda6df7cbea2550
Reviewed-on: https://chromium-review.googlesource.com/c/1383308Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Commit-Queue: John Rummell <jrummell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#620007}
parent f73cead2
...@@ -1233,6 +1233,53 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, ...@@ -1233,6 +1233,53 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
EXPECT_EQ(0, GetMediaLicenseCount()); EXPECT_EQ(0, GetMediaLicenseCount());
ExpectCookieTreeModelCount(0); ExpectCookieTreeModelCount(0);
} }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
MediaLicenseDeletionWithFilter) {
const std::string kMediaLicenseType = "MediaLicense";
GURL url =
embedded_test_server()->GetURL("/browsing_data/media_license.html");
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(0, GetMediaLicenseCount());
EXPECT_FALSE(HasDataForType(kMediaLicenseType));
SetDataForType(kMediaLicenseType);
EXPECT_EQ(1, GetMediaLicenseCount());
EXPECT_TRUE(HasDataForType(kMediaLicenseType));
// Try to remove the Media Licenses using a whitelist that doesn't include
// the current URL. Media License should not be deleted.
std::unique_ptr<BrowsingDataFilterBuilder> filter_builder =
BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST);
filter_builder->AddOrigin(
url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443));
RemoveWithFilterAndWait(
content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES,
std::move(filter_builder));
EXPECT_EQ(1, GetMediaLicenseCount());
// Now try with a blacklist that includes the current URL. Media License
// should not be deleted.
filter_builder =
BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST);
filter_builder->AddOrigin(url::Origin::Create(url));
RemoveWithFilterAndWait(
content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES,
std::move(filter_builder));
EXPECT_EQ(1, GetMediaLicenseCount());
// Now try with a whitelist that includes the current URL. Media License
// should be deleted this time.
filter_builder =
BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST);
filter_builder->AddOrigin(url::Origin::Create(url));
RemoveWithFilterAndWait(
content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES,
std::move(filter_builder));
EXPECT_EQ(0, GetMediaLicenseCount());
}
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
const std::vector<std::string> kStorageTypes{ const std::vector<std::string> kStorageTypes{
......
...@@ -977,34 +977,42 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( ...@@ -977,34 +977,42 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
base::RecordAction(UserMetricsAction("ClearBrowsingData_ContentLicenses")); base::RecordAction(UserMetricsAction("ClearBrowsingData_ContentLicenses"));
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
// Will be completed in OnDeauthorizeFlashContentLicensesCompleted() // Flash does not support filtering by domain, so skip this if clearing only
num_pending_tasks_ += 1; // a specified set of sites.
if (!pepper_flash_settings_manager_.get()) { if (filter_builder.GetMode() != BrowsingDataFilterBuilder::WHITELIST) {
pepper_flash_settings_manager_.reset( // Will be completed in OnDeauthorizeFlashContentLicensesCompleted()
new PepperFlashSettingsManager(this, profile_)); num_pending_tasks_ += 1;
if (!pepper_flash_settings_manager_.get()) {
pepper_flash_settings_manager_.reset(
new PepperFlashSettingsManager(this, profile_));
}
deauthorize_flash_content_licenses_request_id_ =
pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
} }
deauthorize_flash_content_licenses_request_id_ =
pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
#endif // BUILDFLAG(ENABLE_PLUGINS) #endif // BUILDFLAG(ENABLE_PLUGINS)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// On Chrome OS, delete any content protection platform keys. // On Chrome OS, delete any content protection platform keys.
const user_manager::User* user = // Platform keys do not support filtering by domain, so skip this if
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); // clearing only a specified set of sites.
if (!user) { if (filter_builder.GetMode() != BrowsingDataFilterBuilder::WHITELIST) {
LOG(WARNING) << "Failed to find user for current profile."; const user_manager::User* user =
} else { chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
chromeos::DBusThreadManager::Get() if (!user) {
->GetCryptohomeClient() LOG(WARNING) << "Failed to find user for current profile.";
->TpmAttestationDeleteKeys( } else {
chromeos::attestation::KEY_USER, chromeos::DBusThreadManager::Get()
cryptohome::CreateAccountIdentifierFromAccountId( ->GetCryptohomeClient()
user->GetAccountId()), ->TpmAttestationDeleteKeys(
chromeos::attestation::kContentProtectionKeyPrefix, chromeos::attestation::KEY_USER,
base::BindOnce( cryptohome::CreateAccountIdentifierFromAccountId(
&ChromeBrowsingDataRemoverDelegate::OnClearPlatformKeys, user->GetAccountId()),
weak_ptr_factory_.GetWeakPtr(), chromeos::attestation::kContentProtectionKeyPrefix,
CreatePendingTaskCompletionClosure())); base::BindOnce(
&ChromeBrowsingDataRemoverDelegate::OnClearPlatformKeys,
weak_ptr_factory_.GetWeakPtr(),
CreatePendingTaskCompletionClosure()));
}
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
......
...@@ -99,9 +99,10 @@ class ChromeBrowsingDataRemoverDelegate ...@@ -99,9 +99,10 @@ class ChromeBrowsingDataRemoverDelegate
// Datatypes that can be deleted partially per URL / origin / domain, // Datatypes that can be deleted partially per URL / origin / domain,
// whichever makes sense. // whichever makes sense.
FILTERABLE_DATA_TYPES = DATA_TYPE_SITE_DATA | FILTERABLE_DATA_TYPES =
content::BrowsingDataRemover::DATA_TYPE_CACHE | DATA_TYPE_SITE_DATA | content::BrowsingDataRemover::DATA_TYPE_CACHE |
content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS, content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS |
content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES,
// Includes all the available remove options. Meant to be used by clients // Includes all the available remove options. Meant to be used by clients
// that wish to wipe as much data as possible from a Profile, to make it // that wish to wipe as much data as possible from a Profile, to make it
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_context.h"
#include "storage/browser/fileapi/isolated_context.h" #include "storage/browser/fileapi/isolated_context.h"
#include "storage/browser/fileapi/obfuscated_file_util.h" #include "storage/browser/fileapi/obfuscated_file_util.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "storage/common/fileapi/file_system_util.h" #include "storage/common/fileapi/file_system_util.h"
namespace content { namespace content {
...@@ -387,6 +388,8 @@ void PluginPrivateDataDeletionHelper::DecrementTaskCount( ...@@ -387,6 +388,8 @@ void PluginPrivateDataDeletionHelper::DecrementTaskCount(
void ClearPluginPrivateDataOnFileTaskRunner( void ClearPluginPrivateDataOnFileTaskRunner(
scoped_refptr<storage::FileSystemContext> filesystem_context, scoped_refptr<storage::FileSystemContext> filesystem_context,
const GURL& storage_origin, const GURL& storage_origin,
const StoragePartition::OriginMatcherFunction& origin_matcher,
const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
const base::Time begin, const base::Time begin,
const base::Time end, const base::Time end,
const base::Closure& callback) { const base::Closure& callback) {
...@@ -413,6 +416,8 @@ void ClearPluginPrivateDataOnFileTaskRunner( ...@@ -413,6 +416,8 @@ void ClearPluginPrivateDataOnFileTaskRunner(
// If a specific origin is provided, then check that it is in the list // If a specific origin is provided, then check that it is in the list
// returned and remove all the other origins. // returned and remove all the other origins.
if (!storage_origin.is_empty()) { if (!storage_origin.is_empty()) {
DCHECK(origin_matcher.is_null()) << "Only 1 of |storage_origin| and "
"|origin_matcher| should be specified.";
if (!base::ContainsKey(origins, storage_origin)) { if (!base::ContainsKey(origins, storage_origin)) {
// Nothing matches, so nothing to do. // Nothing matches, so nothing to do.
callback.Run(); callback.Run();
...@@ -424,6 +429,25 @@ void ClearPluginPrivateDataOnFileTaskRunner( ...@@ -424,6 +429,25 @@ void ClearPluginPrivateDataOnFileTaskRunner(
origins.insert(storage_origin); origins.insert(storage_origin);
} }
// If a filter is provided, determine which origins match.
if (!origin_matcher.is_null()) {
DCHECK(storage_origin.is_empty())
<< "Only 1 of |storage_origin| and |origin_matcher| should be "
"specified.";
std::set<GURL> origins_to_check;
origins_to_check.swap(origins);
for (const auto& origin : origins_to_check) {
if (origin_matcher.Run(origin, special_storage_policy.get()))
origins.insert(origin);
}
// If no origins matched, there is nothing to do.
if (origins.empty()) {
callback.Run();
return;
}
}
PluginPrivateDataDeletionHelper* helper = new PluginPrivateDataDeletionHelper( PluginPrivateDataDeletionHelper* helper = new PluginPrivateDataDeletionHelper(
std::move(filesystem_context), begin, end, callback); std::move(filesystem_context), begin, end, callback);
helper->CheckOriginsOnFileTaskRunner(origins); helper->CheckOriginsOnFileTaskRunner(origins);
......
...@@ -12,12 +12,14 @@ ...@@ -12,12 +12,14 @@
#endif #endif
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/public/browser/storage_partition.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace storage { namespace storage {
class FileSystemContext; class FileSystemContext;
class SpecialStoragePolicy;
} }
namespace content { namespace content {
...@@ -30,6 +32,8 @@ namespace content { ...@@ -30,6 +32,8 @@ namespace content {
void ClearPluginPrivateDataOnFileTaskRunner( void ClearPluginPrivateDataOnFileTaskRunner(
scoped_refptr<storage::FileSystemContext> filesystem_context, scoped_refptr<storage::FileSystemContext> filesystem_context,
const GURL& storage_origin, const GURL& storage_origin,
const StoragePartition::OriginMatcherFunction& origin_matcher,
const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
const base::Time begin, const base::Time begin,
const base::Time end, const base::Time end,
const base::Closure& callback); const base::Closure& callback);
......
...@@ -1205,10 +1205,11 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -1205,10 +1205,11 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
if (remove_mask_ & REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA) { if (remove_mask_ & REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA) {
IncrementTaskCountOnUI(); IncrementTaskCountOnUI();
filesystem_context->default_file_task_runner()->PostTask( filesystem_context->default_file_task_runner()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(&ClearPluginPrivateDataOnFileTaskRunner,
base::BindOnce(&ClearPluginPrivateDataOnFileTaskRunner, base::WrapRefCounted(filesystem_context),
base::WrapRefCounted(filesystem_context), storage_origin, storage_origin, origin_matcher,
begin, end, std::move(decrement_callback))); base::WrapRefCounted(special_storage_policy),
begin, end, std::move(decrement_callback)));
} }
#endif // BUILDFLAG(ENABLE_PLUGINS) #endif // BUILDFLAG(ENABLE_PLUGINS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment