Files
cromite/build/patches/Change-popup-site-setting.patch

319 lines
15 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
From: uazo <uazo@users.noreply.github.com>
Date: Sun, 4 Feb 2024 16:02:48 +0000
Subject: Change popup site setting
In site settings added ability to block all popups per site
License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
---
.../settings/site_settings/popups_page.html | 2 +
.../tab_under_navigation_throttle.cc | 11 +-
.../android/popup_blocked_message_delegate.cc | 20 ++-
.../android/popup_blocked_message_delegate.h | 1 +
components/blocked_content/popup_blocker.cc | 3 +
components/blocked_content_strings.grdp | 3 +
.../impl/BromitePopupContentSetting.java | 115 ++++++++++++++++++
.../bromite_content_settings/popups.grdp | 18 +++
.../bromite_content_settings/popups.inc | 13 ++
.../core/browser/content_settings_registry.cc | 2 +-
10 files changed, 182 insertions(+), 6 deletions(-)
create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromitePopupContentSetting.java
create mode 100644 components/browser_ui/strings/bromite_content_settings/popups.grdp
create mode 100644 components/content_settings/core/browser/bromite_content_settings/popups.inc
diff --git a/chrome/browser/resources/settings/site_settings/popups_page.html b/chrome/browser/resources/settings/site_settings/popups_page.html
--- a/chrome/browser/resources/settings/site_settings/popups_page.html
+++ b/chrome/browser/resources/settings/site_settings/popups_page.html
@@ -10,6 +10,8 @@
category="[[contentSettingsTypesEnum_.POPUPS]]"
allow-option-label="$i18n{siteSettingsPopupsAllowed}"
allow-option-icon="cr:open-in-new"
+ ask-option-label="$i18n{brSiteSettingspopupsAsk}"
+ ask-option-icon="privacy:open-in-new-off"
block-option-label="$i18n{siteSettingsPopupsBlocked}"
block-option-icon="privacy:open-in-new-off">
</settings-category-default-radio-group>
diff --git a/chrome/browser/ui/blocked_content/tab_under_navigation_throttle.cc b/chrome/browser/ui/blocked_content/tab_under_navigation_throttle.cc
--- a/chrome/browser/ui/blocked_content/tab_under_navigation_throttle.cc
+++ b/chrome/browser/ui/blocked_content/tab_under_navigation_throttle.cc
@@ -143,9 +143,14 @@ TabUnderNavigationThrottle::MaybeBlockNavigation() {
LogTabUnderAttempt(navigation_handle());
- // We unconditionally proceed. There used to be a tab-under blocking
- // experiment, but it never launched.
- return content::NavigationThrottle::PROCEED;
+ content::WebContents* web_contents = navigation_handle()->GetWebContents();
+ const std::string error =
+ base::StringPrintf(kBlockTabUnderFormatMessage,
+ navigation_handle()->GetURL().spec().c_str());
+ web_contents->GetPrimaryMainFrame()->AddMessageToConsole(
+ blink::mojom::ConsoleMessageLevel::kError, error.c_str());
+ ShowUI();
+ return content::NavigationThrottle::CANCEL;
}
void TabUnderNavigationThrottle::ShowUI() {
diff --git a/components/blocked_content/android/popup_blocked_message_delegate.cc b/components/blocked_content/android/popup_blocked_message_delegate.cc
--- a/components/blocked_content/android/popup_blocked_message_delegate.cc
+++ b/components/blocked_content/android/popup_blocked_message_delegate.cc
@@ -32,7 +32,7 @@ bool PopupBlockedMessageDelegate::ShowMessage(
// the callback.
auto message = std::make_unique<messages::MessageWrapper>(
messages::MessageIdentifier::POPUP_BLOCKED,
- base::BindOnce(&PopupBlockedMessageDelegate::HandleClick,
+ base::BindOnce(&PopupBlockedMessageDelegate::HandleOpenLink,
base::Unretained(this)),
base::BindOnce(&PopupBlockedMessageDelegate::HandleDismissCallback,
base::Unretained(this)));
@@ -46,7 +46,7 @@ bool PopupBlockedMessageDelegate::ShowMessage(
// Don't allow the user to configure the setting in the UI if the setting
// is managed by policy.
int button_text_id =
- allow_settings_changes_ ? IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW : IDS_OK;
+ allow_settings_changes_ ? IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW_THIS_TIME : IDS_OK;
message->SetPrimaryButtonText(l10n_util::GetStringUTF16(button_text_id));
messages::MessageDispatcherBridge* message_dispatcher_bridge =
messages::MessageDispatcherBridge::Get();
@@ -54,6 +54,14 @@ bool PopupBlockedMessageDelegate::ShowMessage(
message->SetIconResourceId(message_dispatcher_bridge->MapToJavaDrawableId(
IDR_ANDROID_INFOBAR_BLOCKED_POPUPS));
+ message->SetSecondaryIconResourceId(
+ message_dispatcher_bridge->MapToJavaDrawableId(
+ IDR_ANDROID_SETTINGS));
+ message->SetSecondaryButtonMenuText(
+ l10n_util::GetStringUTF16(IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW));
+ message->SetSecondaryActionCallback(
+ base::BindRepeating(&PopupBlockedMessageDelegate::HandleClick,
+ base::Unretained(this)));
// On rare occasions, such as the moment when activity is being recreated
// or destroyed, popup blocked message will not be displayed and the
// method will return false.
@@ -102,6 +110,14 @@ void PopupBlockedMessageDelegate::HandleClick() {
std::move(on_show_popups_callback_).Run();
}
+void PopupBlockedMessageDelegate::HandleOpenLink() {
+ // Launch popups.
+ ShowBlockedPopups(&GetWebContents());
+
+ if (on_show_popups_callback_)
+ std::move(on_show_popups_callback_).Run();
+}
+
WEB_CONTENTS_USER_DATA_KEY_IMPL(PopupBlockedMessageDelegate);
} // namespace blocked_content
diff --git a/components/blocked_content/android/popup_blocked_message_delegate.h b/components/blocked_content/android/popup_blocked_message_delegate.h
--- a/components/blocked_content/android/popup_blocked_message_delegate.h
+++ b/components/blocked_content/android/popup_blocked_message_delegate.h
@@ -41,6 +41,7 @@ class PopupBlockedMessageDelegate
explicit PopupBlockedMessageDelegate(content::WebContents* web_contents);
void HandleClick();
+ void HandleOpenLink();
void HandleDismissCallback(messages::DismissReason dismiss_reason);
raw_ptr<HostContentSettingsMap> map_ = nullptr;
diff --git a/components/blocked_content/popup_blocker.cc b/components/blocked_content/popup_blocker.cc
--- a/components/blocked_content/popup_blocker.cc
+++ b/components/blocked_content/popup_blocker.cc
@@ -70,6 +70,9 @@ PopupBlockType ShouldBlockPopup(content::WebContents* web_contents,
if (cs == CONTENT_SETTING_ALLOW)
return PopupBlockType::kNotBlocked;
+ if (cs == CONTENT_SETTING_ASK)
+ return PopupBlockType::kAbusive;
+
if (!user_gesture)
return PopupBlockType::kNoGesture;
diff --git a/components/blocked_content_strings.grdp b/components/blocked_content_strings.grdp
--- a/components/blocked_content_strings.grdp
+++ b/components/blocked_content_strings.grdp
@@ -4,6 +4,9 @@
<message name="IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW" desc="Pop-up Blocking Show Button [CHAR_LIMIT=32]">
Always show
</message>
+ <message name="IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW_THIS_TIME" desc="Pop-up Blocking Show Button [CHAR_LIMIT=32]">
+ Open this time
+ </message>
<message name="IDS_POPUPS_BLOCKED_INFOBAR_TEXT" desc="Pop-up Blocking Title [CHAR_LIMIT=32] [ICU Syntax]">
{NUM_POPUPS,plural,=1{Pop-up blocked} other{# pop-ups blocked}}
</message>
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromitePopupContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromitePopupContentSetting.java
new file mode 100644
--- /dev/null
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromitePopupContentSetting.java
@@ -0,0 +1,115 @@
+/*
+ This file is part of Bromite.
+
+ Bromite is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Bromite is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bromite. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+package org.chromium.components.browser_ui.site_settings.impl;
+
+import android.content.Context;
+
+import org.chromium.components.browser_ui.site_settings.R;
+
+import org.chromium.components.browser_ui.site_settings.BromiteCustomContentSetting;
+import org.chromium.components.browser_ui.site_settings.ContentSettingsResources;
+import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory;
+import org.chromium.components.content_settings.ContentSetting;
+import org.chromium.components.content_settings.ContentSettingsType;
+import org.chromium.content_public.browser.BrowserContextHandle;
+
+import androidx.annotation.Nullable;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import java.util.ArrayList;
+
+public class BromitePopupContentSetting extends BromiteCustomContentSetting {
+ public BromitePopupContentSetting() {
+ super(/*contentSettingsType*/ ContentSettingsType.POPUPS,
+ /*defaultEnabledValue*/ ContentSetting.ALLOW,
+ /*defaultDisabledValue*/ ContentSetting.BLOCK,
+ /*allowException*/ true,
+ /*preferenceKey*/ "popups",
+ /*profilePrefKey*/ "popups");
+ }
+
+ @Override
+ public ContentSettingsResources.ResourceItem getResourceItem() {
+ return new ContentSettingsResources.ResourceItem(
+ /*icon*/ R.drawable.permission_popups,
+ /*title*/ R.string.popup_permission_title,
+ /*defaultEnabledValue*/ getDefaultEnabledValue(),
+ /*defaultDisabledValue*/ getDefaultDisabledValue(),
+ /*enabledSummary*/ R.string.website_settings_category_popup_allowed,
+ /*disabledSummary*/ R.string.website_settings_category_popup_blocked,
+ /*summaryOverrideForScreenReader*/ 0);
+ }
+
+ @Override
+ public int getCategorySummary(@Nullable @ContentSetting int value) {
+ switch (value) {
+ case ContentSetting.ALLOW:
+ return R.string.website_settings_category_popup_allowed;
+ case ContentSetting.BLOCK:
+ return R.string.website_settings_category_popup_blocked;
+ case ContentSetting.ASK:
+ return R.string.website_settings_category_popup_block_all;
+ default:
+ return 0;
+ }
+ }
+
+ @Override
+ public int getCategoryDescription() {
+ return 0;
+ }
+
+ @Override
+ public boolean requiresTriStateContentSetting() {
+ return true;
+ }
+
+ @Override
+ public int[] getTriStateSettingDescriptionIDs() {
+ int[] descriptionIDs = {
+ R.string.website_settings_category_popup_allowed, // ALLOWED
+ R.string.website_settings_category_popup_block_all, // ASK
+ R.string.website_settings_category_popup_blocked}; // BLOCKED
+ return descriptionIDs;
+ }
+
+ @Override
+ public int[] getTriStateSettingIconIDs() {
+ return new int[] {
+ R.drawable.permission_popups,
+ R.drawable.permission_popups,
+ R.drawable.sensors_off_24px
+ };
+ }
+
+ @Override
+ public boolean showOnlyDescriptions() {
+ return true;
+ }
+
+ @Override
+ public int getAddExceptionDialogMessage() {
+ return R.string.website_settings_category_popup_allowed;
+ }
+
+ @Override
+ public @Nullable Boolean considerException(SiteSettingsCategory category, @ContentSetting int value) {
+ return ContentSetting.ALLOW != value;
+ }
+}
diff --git a/components/browser_ui/strings/bromite_content_settings/popups.grdp b/components/browser_ui/strings/bromite_content_settings/popups.grdp
new file mode 100644
--- /dev/null
+++ b/components/browser_ui/strings/bromite_content_settings/popups.grdp
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<grit-part>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_POPUP" desc="" formatter_data="android_java">
+ Block sites from showing pop-ups and redirects
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_DESCRIPTION" desc="" formatter_data="android_java">
+ When on, sites can use pop-ups and redirects. When off, sites cant use pop-ups and redirects.
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_BLOCK_ALL" desc="" formatter_data="android_java">
+ Block all popups
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_ALLOWED" desc="" formatter_data="android_java">
+ Allows popups
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_BLOCKED" desc="" formatter_data="android_java">
+ Block some popups
+ </message>
+</grit-part>
diff --git a/components/content_settings/core/browser/bromite_content_settings/popups.inc b/components/content_settings/core/browser/bromite_content_settings/popups.inc
new file mode 100644
--- /dev/null
+++ b/components/content_settings/core/browser/bromite_content_settings/popups.inc
@@ -0,0 +1,13 @@
+ content_settings::WebsiteSettingsRegistry::GetInstance()
+ ->GetMutable(ContentSettingsType::POPUPS)
+ ->set_show_into_info_page()
+ .set_desktop_ui()
+ .set_is_renderer_content_setting()
+ .set_title_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP)
+ .set_description_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_DESCRIPTION)
+ .set_allowed_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_ALLOWED)
+ .set_ask_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_BLOCK_ALL)
+ .set_blocked_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_BLOCKED)
+ .set_allowed_exceptions_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_ALLOWED)
+ .set_blocked_exceptions_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP_BLOCKED)
+ .set_mid_sentence_ui(IDS_WEBSITE_SETTINGS_CATEGORY_POPUP);
diff --git a/components/content_settings/core/browser/content_settings_registry.cc b/components/content_settings/core/browser/content_settings_registry.cc
--- a/components/content_settings/core/browser/content_settings_registry.cc
+++ b/components/content_settings/core/browser/content_settings_registry.cc
@@ -139,7 +139,7 @@ void ContentSettingsRegistry::Init() {
WebsiteSettingsInfo::SYNCABLE,
/*allowlisted_primary_schemes=*/
{kChromeUIScheme, kChromeDevToolsScheme, kExtensionScheme},
- /*valid_settings=*/{CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK},
+ /*valid_settings=*/{CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ASK},
WebsiteSettingsInfo::TOP_ORIGIN_ONLY_SCOPE,
WebsiteSettingsRegistry::ALL_PLATFORMS,
ContentSettingsInfo::INHERIT_IN_INCOGNITO,
--