From e55182470760e28d35054bbcfe26c16c735e668a Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Sat, 15 Feb 2020 12:40:53 +0900 Subject: [PATCH] Subclass ChromeBrowsingDataRemoverDelegate We don't need to subclass HostContentsSettingsMap to clear shields settings. BraveBrowsingDataRemoverDelegateTest is added. --- browser/browsing_data/BUILD.gn | 4 +- .../brave_browsing_data_remover_delegate.cc | 73 +++++++++++++++ .../brave_browsing_data_remover_delegate.h | 47 ++++++++++ ...browsing_data_remover_delegate_unittest.cc | 92 +++++++++++++++++++ .../counters/brave_site_settings_counter.cc | 10 +- .../counters/brave_site_settings_counter.h | 3 +- .../brave_site_settings_counter_unittest.cc | 9 +- .../chrome_browsing_data_remover_delegate.cc | 14 --- ..._browsing_data_remover_delegate_factory.cc | 8 ++ .../counters/browsing_data_counter_factory.cc | 2 +- .../host_content_settings_map_factory.cc | 3 +- .../core/browser/host_content_settings_map.h | 17 ---- .../content_settings/core/browser/BUILD.gn | 2 - .../brave_content_settings_pref_provider.cc | 7 +- .../brave_content_settings_pref_provider.h | 2 - .../brave_host_content_settings_map.cc | 50 ---------- .../browser/brave_host_content_settings_map.h | 38 -------- ...me_browsing_data_remover_delegate.cc.patch | 12 --- ...ing_data_remover_delegate_factory.cc.patch | 11 +++ ...host_content_settings_map_factory.cc.patch | 9 +- ...-browser-host_content_settings_map.h.patch | 12 --- test/BUILD.gn | 1 + 22 files changed, 252 insertions(+), 174 deletions(-) create mode 100644 browser/browsing_data/brave_browsing_data_remover_delegate.cc create mode 100644 browser/browsing_data/brave_browsing_data_remover_delegate.h create mode 100644 browser/browsing_data/brave_browsing_data_remover_delegate_unittest.cc delete mode 100644 chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc create mode 100644 chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc delete mode 100644 chromium_src/components/content_settings/core/browser/host_content_settings_map.h delete mode 100644 components/content_settings/core/browser/brave_host_content_settings_map.cc delete mode 100644 components/content_settings/core/browser/brave_host_content_settings_map.h delete mode 100644 patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate.cc.patch create mode 100644 patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate_factory.cc.patch delete mode 100644 patches/components-content_settings-core-browser-host_content_settings_map.h.patch diff --git a/browser/browsing_data/BUILD.gn b/browser/browsing_data/BUILD.gn index 060e57cca377..c7872933b554 100644 --- a/browser/browsing_data/BUILD.gn +++ b/browser/browsing_data/BUILD.gn @@ -1,5 +1,7 @@ source_set("browsing_data") { sources = [ + "brave_browsing_data_remover_delegate.cc", + "brave_browsing_data_remover_delegate.h", "brave_clear_browsing_data.cc", "brave_clear_browsing_data.h", "counters/brave_site_settings_counter.cc", @@ -9,10 +11,10 @@ source_set("browsing_data") { deps = [ "//base", "//chrome/common", - "//content/public/browser", "//components/browsing_data/core", "//components/content_settings/core/browser", "//components/content_settings/core/common", "//components/prefs", + "//content/public/browser", ] } diff --git a/browser/browsing_data/brave_browsing_data_remover_delegate.cc b/browser/browsing_data/brave_browsing_data_remover_delegate.cc new file mode 100644 index 000000000000..b6a7828661cc --- /dev/null +++ b/browser/browsing_data/brave_browsing_data_remover_delegate.cc @@ -0,0 +1,73 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/browsing_data/brave_browsing_data_remover_delegate.h" + +#include + +#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h" +#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" + +BraveBrowsingDataRemoverDelegate::BraveBrowsingDataRemoverDelegate( + content::BrowserContext* browser_context) + : ChromeBrowsingDataRemoverDelegate(browser_context), + profile_(Profile::FromBrowserContext(browser_context)) {} + +void BraveBrowsingDataRemoverDelegate::RemoveEmbedderData( + const base::Time& delete_begin, + const base::Time& delete_end, + int remove_mask, + content::BrowsingDataFilterBuilder* filter_builder, + int origin_type_mask, + base::OnceClosure callback) { + ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(delete_begin, + delete_end, + remove_mask, + filter_builder, + origin_type_mask, + std::move(callback)); + + // We do this because ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData() + // doesn't clear shields settings with non all time range. + // The reason is upstream assumes that plugins type only as empty string + // resource ids with plugins type. but we use plugins type to store our + // shields settings with non-empty resource ids. + if (remove_mask & DATA_TYPE_CONTENT_SETTINGS) + ClearShieldsSettings(delete_begin, delete_end); +} + +void BraveBrowsingDataRemoverDelegate::ClearShieldsSettings( + base::Time begin_time, + base::Time end_time) { + if (begin_time.is_null() && (end_time.is_null() || end_time.is_max())) { + // For all time range, we don't need to do anything here because + // ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData() nukes whole + // plugins type. + return; + } + + auto* map = HostContentSettingsMapFactory::GetForProfile(profile_); + auto* provider = + static_cast(map->GetPrefProvider()); + for (const auto& resource_id : content_settings::GetShieldsResourceIDs()) { + ContentSettingsForOneType settings; + ContentSettingsType content_type = ContentSettingsType::PLUGINS; + map->GetSettingsForOneType(content_type, resource_id, &settings); + for (const ContentSettingPatternSource& setting : settings) { + base::Time last_modified = provider->GetWebsiteSettingLastModified( + setting.primary_pattern, setting.secondary_pattern, content_type, + resource_id); + if (last_modified >= begin_time && + (last_modified < end_time || end_time.is_null())) { + provider->SetWebsiteSetting(setting.primary_pattern, + setting.secondary_pattern, content_type, + resource_id, nullptr); + } + } + } +} diff --git a/browser/browsing_data/brave_browsing_data_remover_delegate.h b/browser/browsing_data/brave_browsing_data_remover_delegate.h new file mode 100644 index 000000000000..0e765be554af --- /dev/null +++ b/browser/browsing_data/brave_browsing_data_remover_delegate.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_BROWSING_DATA_BRAVE_BROWSING_DATA_REMOVER_DELEGATE_H_ +#define BRAVE_BROWSER_BROWSING_DATA_BRAVE_BROWSING_DATA_REMOVER_DELEGATE_H_ + +#include "base/time/time.h" +#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" + +namespace content_settings { +class BravePrefProvider; +} // namespace content_settings + +class Profile; + +class BraveBrowsingDataRemoverDelegate + : public ChromeBrowsingDataRemoverDelegate { + public: + explicit BraveBrowsingDataRemoverDelegate( + content::BrowserContext* browser_context); + ~BraveBrowsingDataRemoverDelegate() override = default; + + BraveBrowsingDataRemoverDelegate( + const BraveBrowsingDataRemoverDelegate&) = delete; + BraveBrowsingDataRemoverDelegate operator=( + const BraveBrowsingDataRemoverDelegate&) = delete; + + private: + FRIEND_TEST_ALL_PREFIXES(BraveBrowsingDataRemoverDelegateTest, + ShieldsSettingsClearTest); + + // ChromeBrowsingDataRemoverDelegate overrides: + void RemoveEmbedderData(const base::Time& delete_begin, + const base::Time& delete_end, + int remove_mask, + content::BrowsingDataFilterBuilder* filter_builder, + int origin_type_mask, + base::OnceClosure callback) override; + + void ClearShieldsSettings(base::Time begin_time, base::Time end_time); + + Profile* profile_; +}; + +#endif // BRAVE_BROWSER_BROWSING_DATA_BRAVE_BROWSING_DATA_REMOVER_DELEGATE_H_ diff --git a/browser/browsing_data/brave_browsing_data_remover_delegate_unittest.cc b/browser/browsing_data/brave_browsing_data_remover_delegate_unittest.cc new file mode 100644 index 000000000000..b00b4495a14b --- /dev/null +++ b/browser/browsing_data/brave_browsing_data_remover_delegate_unittest.cc @@ -0,0 +1,92 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/browsing_data/brave_browsing_data_remover_delegate.h" + +#include +#include +#include + +#include "base/bind.h" +#include "brave/components/brave_shields/browser/brave_shields_util.h" +#include "brave/components/brave_shields/common/brave_shield_constants.h" +#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/test/base/testing_profile.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" +#include "content/public/test/browser_task_environment.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace { +const GURL kBraveURL("https://www.brave.com"); +const GURL kBatURL("https://basicattentiontoken.org"); +const GURL kGoogleURL("https://www.google.com"); +const GURL kAbcURL("https://www.abc.com"); +} // namespace + +class BraveBrowsingDataRemoverDelegateTest : public testing::Test { + public: + void SetUp() override { + profile_ = std::make_unique(); + map_ = HostContentSettingsMapFactory::GetForProfile(profile()); + } + + Profile* profile() { return profile_.get(); } + + HostContentSettingsMap* map() { return map_.get(); } + + BraveBrowsingDataRemoverDelegate* delegate() { + return static_cast( + profile()->GetBrowsingDataRemoverDelegate()); + } + + int GetShieldsSettingsCount() { + int shields_settings_count = 0; + for (const auto& resource_id : content_settings::GetShieldsResourceIDs()) { + ContentSettingsForOneType settings; + ContentSettingsType content_type = ContentSettingsType::PLUGINS; + map()->GetSettingsForOneType(content_type, resource_id, &settings); + shields_settings_count += settings.size(); + } + return shields_settings_count; + } + + private: + content::BrowserTaskEnvironment task_environment_; + + std::unique_ptr profile_; + scoped_refptr map_; +}; + +TEST_F(BraveBrowsingDataRemoverDelegateTest, ShieldsSettingsClearTest) { + // Four settings are added. + // First two settings are shields settings in PLUGINS type. + // Javascript is not counted as shields type because it's stored to + // JAVASCRIPT type instead of PLUGINS type. + // Last one is PLUGINS type but it's flash resource not shields resource. + map()->SetContentSettingDefaultScope( + kBraveURL, GURL(), ContentSettingsType::PLUGINS, + brave_shields::kHTTPUpgradableResources, CONTENT_SETTING_ALLOW); + map()->SetContentSettingDefaultScope( + kBatURL, GURL(), ContentSettingsType::PLUGINS, + brave_shields::kFingerprinting, CONTENT_SETTING_ALLOW); + map()->SetContentSettingCustomScope( + brave_shields::GetPatternFromURL(kGoogleURL, true), + ContentSettingsPattern::Wildcard(), + ContentSettingsType::JAVASCRIPT, "", CONTENT_SETTING_BLOCK); + map()->SetContentSettingDefaultScope( + kAbcURL, GURL(), ContentSettingsType::PLUGINS, + "", CONTENT_SETTING_ALLOW); + + const base::Time kNow = base::Time::Now(); + const base::Time k1DaysOld = kNow - base::TimeDelta::FromDays(1); + + // Check current shields settings count is 2 and zero after clearing 1 day + // time range. + EXPECT_EQ(2, GetShieldsSettingsCount()); + delegate()->ClearShieldsSettings(k1DaysOld, kNow); + EXPECT_EQ(0, GetShieldsSettingsCount()); +} diff --git a/browser/browsing_data/counters/brave_site_settings_counter.cc b/browser/browsing_data/counters/brave_site_settings_counter.cc index 66ca06853168..d974f10c7f46 100644 --- a/browser/browsing_data/counters/brave_site_settings_counter.cc +++ b/browser/browsing_data/counters/brave_site_settings_counter.cc @@ -8,6 +8,7 @@ #include #include +#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h" #include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" #include "components/browsing_data/core/pref_names.h" #include "components/content_settings/core/browser/content_settings_registry.h" @@ -18,9 +19,8 @@ BraveSiteSettingsCounter::BraveSiteSettingsCounter( content::HostZoomMap* zoom_map, ProtocolHandlerRegistry* handler_registry, PrefService* pref_service) - : SiteSettingsCounter(map, zoom_map, handler_registry, pref_service) { - map_ = static_cast(map); -} + : SiteSettingsCounter(map, zoom_map, handler_registry, pref_service), + map_(map) {} BraveSiteSettingsCounter::~BraveSiteSettingsCounter() = default; @@ -43,9 +43,11 @@ int BraveSiteSettingsCounter::CountShieldsSettings() { base::Time last_modified; DCHECK_EQ(ContentSettingsType::PLUGINS, content_type); // Fetching last time for specific resource ids. - last_modified = map_->GetShieldsSettingLastModifiedDate( + last_modified = + map_->GetPrefProvider()->GetWebsiteSettingLastModified( content_setting.primary_pattern, content_setting.secondary_pattern, + ContentSettingsType::PLUGINS, resource_identifier); if (last_modified >= period_start && last_modified < period_end) { if (content_setting.primary_pattern.GetHost().empty()) diff --git a/browser/browsing_data/counters/brave_site_settings_counter.h b/browser/browsing_data/counters/brave_site_settings_counter.h index 24c6ea060c6a..77c45357d292 100644 --- a/browser/browsing_data/counters/brave_site_settings_counter.h +++ b/browser/browsing_data/counters/brave_site_settings_counter.h @@ -6,7 +6,6 @@ #ifndef BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_ #define BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_ -#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" #include "chrome/browser/browsing_data/counters/site_settings_counter.h" // This class adds shieldss settings count @@ -26,7 +25,7 @@ class BraveSiteSettingsCounter : public SiteSettingsCounter { int CountShieldsSettings(); - scoped_refptr map_; + scoped_refptr map_; }; #endif // BRAVE_BROWSER_BROWSING_DATA_COUNTERS_BRAVE_SITE_SETTINGS_COUNTER_H_ diff --git a/browser/browsing_data/counters/brave_site_settings_counter_unittest.cc b/browser/browsing_data/counters/brave_site_settings_counter_unittest.cc index 120ecca8de8e..42a2640d5b2d 100644 --- a/browser/browsing_data/counters/brave_site_settings_counter_unittest.cc +++ b/browser/browsing_data/counters/brave_site_settings_counter_unittest.cc @@ -13,7 +13,6 @@ #include "base/test/simple_test_clock.h" #include "brave/components/brave_shields/browser/brave_shields_util.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" -#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" @@ -21,6 +20,7 @@ #include "chrome/test/base/testing_profile.h" #include "components/browsing_data/core/browsing_data_utils.h" #include "components/browsing_data/core/pref_names.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/prefs/pref_service.h" #include "content/public/test/browser_task_environment.h" #include "testing/gtest/include/gtest/gtest.h" @@ -41,8 +41,7 @@ class BraveSiteSettingsCounterTest : public testing::Test { public: void SetUp() override { profile_ = std::make_unique(); - map_ = static_cast( - HostContentSettingsMapFactory::GetForProfile(profile())); + map_ = HostContentSettingsMapFactory::GetForProfile(profile()); #if !defined(OS_ANDROID) auto* zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile()); @@ -61,7 +60,7 @@ class BraveSiteSettingsCounterTest : public testing::Test { Profile* profile() { return profile_.get(); } - BraveHostContentSettingsMap* map() { return map_.get(); } + HostContentSettingsMap* map() { return map_.get(); } BraveSiteSettingsCounter* counter() { return counter_.get(); } @@ -84,7 +83,7 @@ class BraveSiteSettingsCounterTest : public testing::Test { content::BrowserTaskEnvironment task_environment_; std::unique_ptr profile_; - scoped_refptr map_; + scoped_refptr map_; std::unique_ptr handler_registry_; std::unique_ptr counter_; bool finished_; diff --git a/chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc b/chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc deleted file mode 100644 index fd995d306882..000000000000 --- a/chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (c) 2020 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" -#include "components/content_settings/core/browser/content_settings_info.h" -#include "components/content_settings/core/browser/website_settings_info.h" - -#define CLEAR_SHIELDS_SETTINGS \ - static_cast(host_content_settings_map_)-> \ - ClearSettingsForPluginsType(delete_begin_, delete_end_); -#include "../../../../../chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc" -#undef CLEAR_SHIELDS_SETTINGS diff --git a/chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc b/chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc new file mode 100644 index 000000000000..88bd931b37e8 --- /dev/null +++ b/chromium_src/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc @@ -0,0 +1,8 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/browsing_data/brave_browsing_data_remover_delegate.h" + +#include "../../../../../chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc" diff --git a/chromium_src/chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc b/chromium_src/chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc index ada73b990dd5..d4a23af6a13e 100644 --- a/chromium_src/chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc +++ b/chromium_src/chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc @@ -6,5 +6,5 @@ #include "brave/browser/browsing_data/counters/brave_site_settings_counter.h" #define SiteSettingsCounter BraveSiteSettingsCounter -#include "../../../../../../chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc" // NOLINT +#include "../../../../../../chrome/browser/browsing_data/counters/browsing_data_counter_factory.cc" #undef SiteSettingsCounter diff --git a/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc index d464d4dfc263..92f006e1c83f 100644 --- a/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc +++ b/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc @@ -4,8 +4,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/browser/profiles/profile_util.h" -#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" #define BRAVE_BUILD_SERVICE_INSTANCE_FOR brave::IsSessionProfile(profile) || -#include "../../../../../chrome/browser/content_settings/host_content_settings_map_factory.cc" // NOLINT +#include "../../../../../chrome/browser/content_settings/host_content_settings_map_factory.cc" #undef BRAVE_BUILD_SERVICE_INSTANCE_FOR diff --git a/chromium_src/components/content_settings/core/browser/host_content_settings_map.h b/chromium_src/components/content_settings/core/browser/host_content_settings_map.h deleted file mode 100644 index 2976a4feec25..000000000000 --- a/chromium_src/components/content_settings/core/browser/host_content_settings_map.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Copyright (c) 2020 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ -#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ - -#define BRAVE_HOST_CONTENT_SETTINGS_MAP_H \ - private: \ - friend class BraveHostContentSettingsMap; - -#include "../../../../../../components/content_settings/core/browser/host_content_settings_map.h" - -#undef BRAVE_HOST_CONTENT_SETTINGS_MAP_H - -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ diff --git a/components/content_settings/core/browser/BUILD.gn b/components/content_settings/core/browser/BUILD.gn index 8abc5e6ee003..4f18290d41eb 100644 --- a/components/content_settings/core/browser/BUILD.gn +++ b/components/content_settings/core/browser/BUILD.gn @@ -7,8 +7,6 @@ source_set("browser") { "brave_content_settings_pref_provider.h", "brave_content_settings_utils.cc", "brave_content_settings_utils.h", - "brave_host_content_settings_map.cc", - "brave_host_content_settings_map.h", ] deps = [ diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index 54dfcb9b687b..ab77fc86f7e1 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -192,7 +192,7 @@ std::unique_ptr BravePrefProvider::GetRuleIterator( cookie_rules_.at(incognito).end()); } - // Earyl return. We don't store flash plugin setting in preference. + // Early return. We don't store flash plugin setting in preference. if (content_type == ContentSettingsType::PLUGINS && resource_identifier == "") return nullptr; @@ -364,9 +364,4 @@ void BravePrefProvider::OnContentSettingChanged( } } -void BravePrefProvider::ClearAllShieldsContentSettings() { - DCHECK(CalledOnValidThread()); - GetPref(ContentSettingsType::PLUGINS)->ClearAllContentSettingsRules(); -} - } // namespace content_settings diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.h b/components/content_settings/core/browser/brave_content_settings_pref_provider.h index 371a15c471c0..6b76b560fe89 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.h +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.h @@ -46,8 +46,6 @@ class BravePrefProvider : public PrefProvider, const ResourceIdentifier& resource_identifier, bool incognito) const override; - void ClearAllShieldsContentSettings(); - private: void UpdateCookieRules(ContentSettingsType content_type, bool incognito); void OnCookieSettingsChanged(ContentSettingsType content_type); diff --git a/components/content_settings/core/browser/brave_host_content_settings_map.cc b/components/content_settings/core/browser/brave_host_content_settings_map.cc deleted file mode 100644 index 20b92fb6e969..000000000000 --- a/components/content_settings/core/browser/brave_host_content_settings_map.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (c) 2020 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" -#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h" -#include "brave/components/content_settings/core/browser/brave_content_settings_utils.h" - -base::Time BraveHostContentSettingsMap::GetShieldsSettingLastModifiedDate( - const ContentSettingsPattern& primary_pattern, - const ContentSettingsPattern& secondary_pattern, - const std::string& resource_identifier) const { - return GetPrefProvider()->GetWebsiteSettingLastModified( - primary_pattern, secondary_pattern, - ContentSettingsType::PLUGINS, resource_identifier); -} - -void BraveHostContentSettingsMap::ClearSettingsForPluginsType() { - static_cast(GetPrefProvider())-> - ClearAllShieldsContentSettings(); - FlushLossyWebsiteSettings(); -} - -void BraveHostContentSettingsMap::ClearSettingsForPluginsType( - base::Time begin_time, - base::Time end_time) { - if (begin_time.is_null() && (end_time.is_null() || end_time.is_max())) { - ClearSettingsForPluginsType(); - return; - } - - auto* provider = GetPrefProvider(); - for (const auto& resource_id : content_settings::GetShieldsResourceIDs()) { - ContentSettingsForOneType settings; - ContentSettingsType content_type = ContentSettingsType::PLUGINS; - GetSettingsForOneType(content_type, resource_id, &settings); - for (const ContentSettingPatternSource& setting : settings) { - base::Time last_modified = provider->GetWebsiteSettingLastModified( - setting.primary_pattern, setting.secondary_pattern, content_type, - resource_id); - if (last_modified >= begin_time && - (last_modified < end_time || end_time.is_null())) { - provider->SetWebsiteSetting(setting.primary_pattern, - setting.secondary_pattern, content_type, - resource_id, nullptr); - } - } - } -} diff --git a/components/content_settings/core/browser/brave_host_content_settings_map.h b/components/content_settings/core/browser/brave_host_content_settings_map.h deleted file mode 100644 index 3fb2941cf706..000000000000 --- a/components/content_settings/core/browser/brave_host_content_settings_map.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (c) 2020 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ -#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ - -#include - -#include "base/time/time.h" -#include "components/content_settings/core/browser/host_content_settings_map.h" - -class BraveHostContentSettingsMap : public HostContentSettingsMap { - public: - using HostContentSettingsMap::HostContentSettingsMap; - - BraveHostContentSettingsMap(const BraveHostContentSettingsMap&) = delete; - BraveHostContentSettingsMap& operator=( - const BraveHostContentSettingsMap&) = delete; - - base::Time GetShieldsSettingLastModifiedDate( - const ContentSettingsPattern& primary_pattern, - const ContentSettingsPattern& secondary_pattern, - const std::string& resource_identifier) const; - - // Clear shields content settings with time constraint. - void ClearSettingsForPluginsType(base::Time begin_time, - base::Time end_time); - - private: - ~BraveHostContentSettingsMap() override = default; - - // Clear all shields settings. - void ClearSettingsForPluginsType(); -}; - -#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ diff --git a/patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate.cc.patch b/patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate.cc.patch deleted file mode 100644 index d547be54884a..000000000000 --- a/patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc -index 873f56bffd068bc0fbcba6db500392e32d736b5b..f9a35337e227e252ef8034e0ccea22b8d5f98306 100644 ---- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc -+++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc -@@ -709,6 +709,7 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( - info->website_settings_info()->type(), delete_begin_, delete_end_, - HostContentSettingsMap::PatternSourcePredicate()); - } -+ CLEAR_SHIELDS_SETTINGS - - host_content_settings_map_->ClearSettingsForOneTypeWithPredicate( - ContentSettingsType::USB_CHOOSER_DATA, delete_begin_, delete_end_, diff --git a/patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate_factory.cc.patch b/patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate_factory.cc.patch new file mode 100644 index 000000000000..e6477548a98b --- /dev/null +++ b/patches/chrome-browser-browsing_data-chrome_browsing_data_remover_delegate_factory.cc.patch @@ -0,0 +1,11 @@ +diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc +index 5737f324846addec7938b4dac1519e97abb7d1b1..e06f381fb39c50a67054a3fad2537b3d07c3ac3a 100644 +--- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc ++++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.cc +@@ -102,5 +102,5 @@ ChromeBrowsingDataRemoverDelegateFactory::GetBrowserContextToUse( + + KeyedService* ChromeBrowsingDataRemoverDelegateFactory::BuildServiceInstanceFor( + content::BrowserContext* context) const { +- return new ChromeBrowsingDataRemoverDelegate(context); ++ return new BraveBrowsingDataRemoverDelegate(context); + } diff --git a/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch b/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch index 6e842a095e96..cbd84347bd0c 100644 --- a/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch +++ b/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch @@ -1,13 +1,10 @@ diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc -index 47b1443298ec6ab9aed0f6525245487b02d6cba2..563f6f70021763652eaed097dbcaa67dc9cd4b41 100644 +index 47b1443298ec6ab9aed0f6525245487b02d6cba2..8c50e4cb89c03dc706c847907657cc469d8e83e2 100644 --- a/chrome/browser/content_settings/host_content_settings_map_factory.cc +++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc -@@ -79,8 +79,9 @@ scoped_refptr - if (profile->IsIncognitoProfile()) - GetForProfile(profile->GetOriginalProfile()); +@@ -81,6 +81,7 @@ scoped_refptr -- scoped_refptr settings_map(new HostContentSettingsMap( -+ scoped_refptr settings_map(new BraveHostContentSettingsMap( + scoped_refptr settings_map(new HostContentSettingsMap( profile->GetPrefs(), + BRAVE_BUILD_SERVICE_INSTANCE_FOR profile->IsIncognitoProfile() || profile->IsGuestSession(), diff --git a/patches/components-content_settings-core-browser-host_content_settings_map.h.patch b/patches/components-content_settings-core-browser-host_content_settings_map.h.patch deleted file mode 100644 index 0b83a7053411..000000000000 --- a/patches/components-content_settings-core-browser-host_content_settings_map.h.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/content_settings/core/browser/host_content_settings_map.h b/components/content_settings/core/browser/host_content_settings_map.h -index 68dd1557dc70ea36d531136f359e10d619c10750..50ba9d037c3e8adf7ee4e0c506a764bf5cb1b821 100644 ---- a/components/content_settings/core/browser/host_content_settings_map.h -+++ b/components/content_settings/core/browser/host_content_settings_map.h -@@ -309,6 +309,7 @@ class HostContentSettingsMap : public content_settings::Observer, - return pref_provider_; - } - -+ BRAVE_HOST_CONTENT_SETTINGS_MAP_H - private: - friend class base::RefCountedThreadSafe; - friend class content_settings::TestUtils; diff --git a/test/BUILD.gn b/test/BUILD.gn index 707516ca61d7..a2f6b1938978 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -70,6 +70,7 @@ test("brave_unit_tests") { sources = [ "//brave/browser/brave_content_browser_client_unittest.cc", "//brave/browser/brave_resources_util_unittest.cc", + "//brave/browser/browsing_data/brave_browsing_data_remover_delegate_unittest.cc", "//brave/browser/browsing_data/counters/brave_site_settings_counter_unittest.cc", "//brave/browser/download/brave_download_item_model_unittest.cc", "//brave/browser/metrics/metrics_reporting_util_unittest_linux.cc",