From 0ca311bb5b800125de1b9d2b6461bd2fb98e3e76 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Fri, 19 Oct 2018 12:00:40 -0400 Subject: [PATCH] Move Flash default to ContentSettingsRegistry --- .../core/browser/content_settings_registry.cc | 16 +++++ .../content_settings/core/browser/BUILD.gn | 2 - .../brave_host_content_settings_map.cc | 34 ---------- .../browser/brave_host_content_settings_map.h | 22 ------- ...rave_host_content_settings_map_unittest.cc | 65 ------------------- ...host_content_settings_map_factory.cc.patch | 21 ------ test/BUILD.gn | 1 - 7 files changed, 16 insertions(+), 145 deletions(-) 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 components/content_settings/core/browser/brave_host_content_settings_map_unittest.cc delete mode 100644 patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch diff --git a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc index 8eb358c08e9a..32c707b16a10 100644 --- a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc +++ b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc @@ -16,6 +16,22 @@ void ContentSettingsRegistry::BraveInit() { ContentSettingsInfo::INHERIT_IN_INCOGNITO, ContentSettingsInfo::PERSISTENT); + // Change plugins default to CONTENT_SETTING_BLOCK + content_settings_info_.erase(CONTENT_SETTINGS_TYPE_PLUGINS); + website_settings_registry_->UnRegister(CONTENT_SETTINGS_TYPE_PLUGINS); + Register( + CONTENT_SETTINGS_TYPE_PLUGINS, "plugins", + CONTENT_SETTING_BLOCK, WebsiteSettingsInfo::SYNCABLE, + WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme), + ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, + CONTENT_SETTING_ASK, + CONTENT_SETTING_DETECT_IMPORTANT_CONTENT), + WebsiteSettingsInfo::SINGLE_ORIGIN_WITH_EMBEDDED_EXCEPTIONS_SCOPE, + WebsiteSettingsRegistry::DESKTOP, + ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE, + base::FeatureList::IsEnabled(features::kEnableEphemeralFlashPermission) + ? ContentSettingsInfo::EPHEMERAL + : ContentSettingsInfo::PERSISTENT); } } // namespace content_settings diff --git a/components/content_settings/core/browser/BUILD.gn b/components/content_settings/core/browser/BUILD.gn index f0c94453a839..270881b74c79 100644 --- a/components/content_settings/core/browser/BUILD.gn +++ b/components/content_settings/core/browser/BUILD.gn @@ -6,8 +6,6 @@ source_set("browser") { "brave_content_settings_pref_provider.h", "brave_cookie_settings.cc", "brave_cookie_settings.h", - "brave_host_content_settings_map.cc", - "brave_host_content_settings_map.h", ] deps = [ 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 e974db1d5595..000000000000 --- a/components/content_settings/core/browser/brave_host_content_settings_map.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* 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/brave_shields/common/brave_shield_constants.h" -#include "components/content_settings/core/common/content_settings_pattern.h" -#include "components/prefs/pref_service.h" - -BraveHostContentSettingsMap::BraveHostContentSettingsMap( - PrefService* prefs, - bool is_incognito_profile, - bool is_guest_profile, - bool store_last_modified, - bool migrate_requesting_and_top_level_origin_settings) - : HostContentSettingsMap(prefs, is_incognito_profile, is_guest_profile, - store_last_modified, migrate_requesting_and_top_level_origin_settings) { - InitializeFlashContentSetting(); -} - -BraveHostContentSettingsMap::~BraveHostContentSettingsMap() { -} - -void BraveHostContentSettingsMap::InitializeFlashContentSetting() { - SetContentSettingCustomScope( - ContentSettingsPattern::Wildcard(), - ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_PLUGINS, - // One would think this should be brave_shields::kFlash; however, if you - // use it, it will always ask and click-to-play will not work. - std::string(), - CONTENT_SETTING_BLOCK); -} 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 c4c1826b08df..000000000000 --- a/components/content_settings/core/browser/brave_host_content_settings_map.h +++ /dev/null @@ -1,22 +0,0 @@ -/* 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 "components/content_settings/core/browser/host_content_settings_map.h" - -class BraveHostContentSettingsMap : public HostContentSettingsMap { - public: - BraveHostContentSettingsMap(PrefService* prefs, - bool is_incognito_profile, - bool is_guest_profile, - bool store_last_modified, - bool migrate_requesting_and_top_level_origin_settings); - private: - void InitializeFlashContentSetting(); - ~BraveHostContentSettingsMap() override; -}; - -#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ diff --git a/components/content_settings/core/browser/brave_host_content_settings_map_unittest.cc b/components/content_settings/core/browser/brave_host_content_settings_map_unittest.cc deleted file mode 100644 index 8e8d8ea9d83f..000000000000 --- a/components/content_settings/core/browser/brave_host_content_settings_map_unittest.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* 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 "base/files/file_path.h" -#include "base/files/scoped_temp_dir.h" -#include "brave/browser/profiles/brave_profile_manager.h" -#include "brave/browser/profiles/tor_unittest_profile_manager.h" -#include "brave/common/tor/pref_names.h" -#include "chrome/browser/content_settings/host_content_settings_map_factory.h" -#include "chrome/test/base/scoped_testing_local_state.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" -#include "components/content_settings/core/common/content_settings.h" -#include "content/public/test/test_browser_thread_bundle.h" -#include "testing/gtest/include/gtest/gtest.h" - -class BraveHostContentSettingsMapTest: public testing::Test { - public: - BraveHostContentSettingsMapTest() - : local_state_(TestingBrowserProcess::GetGlobal()), - thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { - } - - void SetUp() override { - // Create a new temporary directory, and store the path - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - TestingBrowserProcess::GetGlobal()->SetProfileManager( - new TorUnittestProfileManager(temp_dir_.GetPath())); - - url_ = GURL("http://testing.com/"); - } - - void TearDown() override { - TestingBrowserProcess::GetGlobal()->SetProfileManager(nullptr); - } - - - const GURL& url() { - return url_; - } - - protected: - // The path to temporary directory used to contain the test operations. - base::ScopedTempDir temp_dir_; - ScopedTestingLocalState local_state_; - - private: - GURL url_; - content::TestBrowserThreadBundle thread_bundle_; -}; - -TEST_F(BraveHostContentSettingsMapTest, AskGeolocationNotInTorProfile) { - TestingProfile profile; - HostContentSettingsMap* host_content_settings_map = - HostContentSettingsMapFactory::GetForProfile(&profile); - EXPECT_EQ(CONTENT_SETTING_ASK, - host_content_settings_map->GetContentSetting( - url(), - url(), - CONTENT_SETTINGS_TYPE_GEOLOCATION, - std::string())); -} 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 deleted file mode 100644 index 45e91b0e190c..000000000000 --- a/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch +++ /dev/null @@ -1,21 +0,0 @@ -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 9596665e9320bc1999f014f5d28e745104a11082..51b1a67af33bfa004636d0a014e7f448859ab56b 100644 ---- a/chrome/browser/content_settings/host_content_settings_map_factory.cc -+++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc -@@ -7,6 +7,7 @@ - #include - - #include "base/feature_list.h" -+#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" - #include "chrome/browser/profiles/off_the_record_profile_impl.h" - #include "chrome/browser/profiles/profile.h" - #include "chrome/browser/search_engines/template_url_service_factory.h" -@@ -80,7 +81,7 @@ scoped_refptr - GetForProfile(profile->GetOriginalProfile()); - } - -- scoped_refptr settings_map(new HostContentSettingsMap( -+ scoped_refptr settings_map(new BraveHostContentSettingsMap( - profile->GetPrefs(), - profile->GetProfileType() == Profile::INCOGNITO_PROFILE, - profile->GetProfileType() == Profile::GUEST_PROFILE, diff --git a/test/BUILD.gn b/test/BUILD.gn index 8f775ad97869..e405cba47308 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -58,7 +58,6 @@ test("brave_unit_tests") { "//brave/common/tor/tor_test_constants.h", "//brave/components/brave_shields/browser/ad_block_regional_service_unittest.cc", "//brave/components/brave_webtorrent/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc", - "//brave/components/content_settings/core/browser/brave_host_content_settings_map_unittest.cc", "//chrome/common/importer/mock_importer_bridge.cc", "//chrome/common/importer/mock_importer_bridge.h", "../browser/importer/chrome_profile_lock_unittest.cc",