From d42e6a4f059f2703a1e4a6100e2a9a38eaf71120 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Wed, 11 Sep 2019 15:21:29 -0700 Subject: [PATCH 1/3] Convert method to macro to avoid patching the `.h` file --- .../core/browser/content_settings_registry.cc | 73 ++++++++++--------- ...browser-content_settings_registry.cc.patch | 4 +- ...-browser-content_settings_registry.h.patch | 12 --- 3 files changed, 40 insertions(+), 49 deletions(-) delete mode 100644 patches/components-content_settings-core-browser-content_settings_registry.h.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 3f996b054d86..1259aec10801 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 @@ -1,38 +1,41 @@ -#include "../../../../../../components/content_settings/core/browser/content_settings_registry.cc" - -namespace content_settings { - -void ContentSettingsRegistry::BraveInit() { - // Add CONTENT_SETTING_ASK and make it default for autoplay - content_settings_info_.erase(CONTENT_SETTINGS_TYPE_AUTOPLAY); - website_settings_registry_->UnRegister(CONTENT_SETTINGS_TYPE_AUTOPLAY); - Register(CONTENT_SETTINGS_TYPE_AUTOPLAY, "autoplay", CONTENT_SETTING_BLOCK, - WebsiteSettingsInfo::UNSYNCABLE, WhitelistedSchemes(), - ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, - CONTENT_SETTING_ASK), - WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, - WebsiteSettingsRegistry::DESKTOP | - WebsiteSettingsRegistry::PLATFORM_ANDROID, - ContentSettingsInfo::INHERIT_IN_INCOGNITO, - ContentSettingsInfo::PERSISTENT, - ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); +/* Copyright (c) 2019 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 https://mozilla.org/MPL/2.0/. */ - // 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 | - WebsiteSettingsRegistry::PLATFORM_ANDROID, - ContentSettingsInfo::INHERIT_IN_INCOGNITO, - ContentSettingsInfo::EPHEMERAL, - ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); +#define BRAVE_INIT { \ + /* Add CONTENT_SETTING_ASK and make it default for autoplay*/ \ + content_settings_info_.erase(CONTENT_SETTINGS_TYPE_AUTOPLAY); \ + website_settings_registry_->UnRegister(CONTENT_SETTINGS_TYPE_AUTOPLAY); \ + Register(CONTENT_SETTINGS_TYPE_AUTOPLAY, "autoplay", CONTENT_SETTING_BLOCK, \ + WebsiteSettingsInfo::UNSYNCABLE, WhitelistedSchemes(), \ + ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, \ + CONTENT_SETTING_ASK), \ + WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, \ + WebsiteSettingsRegistry::DESKTOP | \ + WebsiteSettingsRegistry::PLATFORM_ANDROID, \ + ContentSettingsInfo::INHERIT_IN_INCOGNITO, \ + ContentSettingsInfo::PERSISTENT, \ + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); \ + \ + /* 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 | \ + WebsiteSettingsRegistry::PLATFORM_ANDROID, \ + ContentSettingsInfo::INHERIT_IN_INCOGNITO, \ + ContentSettingsInfo::EPHEMERAL, \ + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); \ } -} // namespace content_settings +#include "../../../../../../components/content_settings/core/browser/content_settings_registry.cc" + +#undef BRAVE_INIT diff --git a/patches/components-content_settings-core-browser-content_settings_registry.cc.patch b/patches/components-content_settings-core-browser-content_settings_registry.cc.patch index 1773f443ab16..9d3bbe625da9 100644 --- a/patches/components-content_settings-core-browser-content_settings_registry.cc.patch +++ b/patches/components-content_settings-core-browser-content_settings_registry.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/content_settings/core/browser/content_settings_registry.cc b/components/content_settings/core/browser/content_settings_registry.cc -index dc67564cd90fb1964de545b933ac5104dbfbc785..d9ca4251e5e9606566dcd88ba5f76f1dca0759cd 100644 +index dc67564cd90fb1964de545b933ac5104dbfbc785..95ce90bc2960359d65433038b225c6f3cf53d996 100644 --- a/components/content_settings/core/browser/content_settings_registry.cc +++ b/components/content_settings/core/browser/content_settings_registry.cc @@ -491,6 +491,7 @@ void ContentSettingsRegistry::Init() { ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE, ContentSettingsInfo::PERSISTENT, ContentSettingsInfo::EXCEPTIONS_ON_SECURE_ORIGINS_ONLY); -+ BraveInit(); ++ BRAVE_INIT } void ContentSettingsRegistry::Register( diff --git a/patches/components-content_settings-core-browser-content_settings_registry.h.patch b/patches/components-content_settings-core-browser-content_settings_registry.h.patch deleted file mode 100644 index 33d2d60b1568..000000000000 --- a/patches/components-content_settings-core-browser-content_settings_registry.h.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/content_settings/core/browser/content_settings_registry.h b/components/content_settings/core/browser/content_settings_registry.h -index 20c43a7ee297e2ddea849d903f5e12608e303095..4cc4e4b2bfff6231d80027c32a9d9598eb03a434 100644 ---- a/components/content_settings/core/browser/content_settings_registry.h -+++ b/components/content_settings/core/browser/content_settings_registry.h -@@ -53,6 +53,7 @@ class ContentSettingsRegistry { - ~ContentSettingsRegistry(); - - void Init(); -+ void BraveInit(); - - typedef uint32_t Platforms; - From cf04867eceffc76e8b536ace3f78f4e3997ab822 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Wed, 11 Sep 2019 15:29:26 -0700 Subject: [PATCH 2/3] Disable background-sync by default (fixes brave/brave-browser#4709) --- .../core/browser/content_settings_registry.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 1259aec10801..2216b5f07f56 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 @@ -34,6 +34,19 @@ ContentSettingsInfo::INHERIT_IN_INCOGNITO, \ ContentSettingsInfo::EPHEMERAL, \ ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); \ + \ + /* Disable background sync by default (brave/brave-browser#4709)*/ \ + Register( \ + CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC, "background-sync", \ + CONTENT_SETTING_BLOCK, WebsiteSettingsInfo::UNSYNCABLE, \ + WhitelistedSchemes(), \ + ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK), \ + WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, \ + WebsiteSettingsRegistry::DESKTOP | \ + WebsiteSettingsRegistry::PLATFORM_ANDROID, \ + ContentSettingsInfo::INHERIT_IN_INCOGNITO, \ + ContentSettingsInfo::PERSISTENT, \ + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_ORIGINS_ONLY); \ } #include "../../../../../../components/content_settings/core/browser/content_settings_registry.cc" From 06f1f35676057321f9e8badebbe12acead76c362 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Thu, 12 Sep 2019 11:19:29 -0700 Subject: [PATCH 3/3] Disable motion sensors by default (fixes brave/brave-browser#4789) --- .../core/browser/content_settings_registry.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 2216b5f07f56..11c7451b10c2 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 @@ -47,6 +47,18 @@ ContentSettingsInfo::INHERIT_IN_INCOGNITO, \ ContentSettingsInfo::PERSISTENT, \ ContentSettingsInfo::EXCEPTIONS_ON_SECURE_ORIGINS_ONLY); \ + \ + /* Disable motion sensors by default (brave/brave-browser#4789)*/ \ + Register( \ + CONTENT_SETTINGS_TYPE_SENSORS, "sensors", CONTENT_SETTING_BLOCK, \ + WebsiteSettingsInfo::UNSYNCABLE, WhitelistedSchemes(), \ + ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK), \ + WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, \ + WebsiteSettingsRegistry::DESKTOP | \ + WebsiteSettingsRegistry::PLATFORM_ANDROID, \ + ContentSettingsInfo::INHERIT_IN_INCOGNITO, \ + ContentSettingsInfo::PERSISTENT, \ + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); \ } #include "../../../../../../components/content_settings/core/browser/content_settings_registry.cc"