forked from bromite/bromite
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In site settings added ability to block all popups per site
- Loading branch information
Showing
2 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
From: uazo <[email protected]> | ||
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 | ||
--- | ||
.../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 | 106 ++++++++++++++++++ | ||
.../bromite_content_settings/popups.grdp | 12 ++ | ||
.../bromite_content_settings/popups.inc | 7 ++ | ||
.../core/browser/content_settings_registry.cc | 2 +- | ||
8 files changed, 151 insertions(+), 3 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/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,106 @@ | ||
+/* | ||
+ 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.ContentSettingValues; | ||
+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*/ ContentSettingValues.ALLOW, | ||
+ /*defaultDisabledValue*/ ContentSettingValues.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 @ContentSettingValues int value) { | ||
+ switch (value) { | ||
+ case ContentSettingValues.ALLOW: | ||
+ return R.string.website_settings_category_popup_allowed; | ||
+ case ContentSettingValues.BLOCK: | ||
+ return R.string.website_settings_category_popup_blocked; | ||
+ case ContentSettingValues.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 boolean showOnlyDescriptions() { | ||
+ return true; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public int getAddExceptionDialogMessage() { | ||
+ return R.string.website_settings_category_popup_allowed; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public @Nullable Boolean considerException(SiteSettingsCategory category, @ContentSettingValues int value) { | ||
+ return ContentSettingValues.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,12 @@ | ||
+<?xml version="1.0" encoding="utf-8"?> | ||
+<grit-part> | ||
+ <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,7 @@ | ||
+ content_settings::WebsiteSettingsRegistry::GetInstance() | ||
+ ->GetMutable(ContentSettingsType::POPUPS) | ||
+ ->set_show_into_info_page() | ||
+ .set_desktop_ui() | ||
+ .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); | ||
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 | ||
@@ -126,7 +126,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, | ||
-- |