Files
cromite/build/patches/00Viewport-Protection-Site-Setting.patch
T
2023-03-30 14:32:09 +02:00

650 lines
36 KiB
Diff

From: Your Name <you@example.com>
Date: Tue, 20 Dec 2022 14:27:02 +0000
Subject: Viewport Protection Site Setting
---
chrome/app/settings_strings.grdp | 19 ++++
chrome/browser/resources/settings/icons.html | 2 +
.../settings/privacy_page/privacy_page.html | 22 +++++
chrome/browser/resources/settings/route.ts | 1 +
chrome/browser/resources/settings/router.ts | 1 +
.../site_settings/category_default_setting.ts | 1 +
.../settings/site_settings/constants.ts | 1 +
.../settings_category_default_radio_group.ts | 1 +
.../settings/site_settings/site_details.html | 5 ++
.../site_settings_page/site_settings_page.ts | 9 ++
.../site_settings_page_util.ts | 2 +
.../views/page_info/page_info_view_factory.cc | 3 +
.../settings_localized_strings_provider.cc | 7 ++
.../ui/webui/settings/site_settings_helper.cc | 1 +
.../browser_ui/site_settings/android/BUILD.gn | 3 +
.../BromiteCustomContentSettingImpl.java | 1 +
.../BromiteViewportContentSetting.java | 86 +++++++++++++++++++
.../site_settings/SiteSettingsCategory.java | 5 +-
.../strings/android/browser_ui_strings.grd | 1 +
.../browser_ui/strings/android/viewport.grdp | 18 ++++
components/components_strings.grd | 1 +
.../core/browser/content_settings_registry.cc | 15 +++-
.../core/browser/content_settings_utils.cc | 2 +
.../core/common/content_settings.cc | 4 +-
.../core/common/content_settings.h | 1 +
.../core/common/content_settings.mojom | 1 +
.../common/content_settings_mojom_traits.cc | 3 +-
.../common/content_settings_mojom_traits.h | 5 ++
.../core/common/content_settings_types.h | 2 +
.../renderer/content_settings_agent_impl.cc | 9 ++
.../renderer/content_settings_agent_impl.h | 1 +
third_party/blink/common/features.cc | 2 +-
.../platform/web_content_settings_client.h | 2 +
.../renderer/core/frame/local_dom_window.cc | 1 +
third_party/blink/renderer/core/page/page.cc | 2 +
35 files changed, 234 insertions(+), 6 deletions(-)
create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteViewportContentSetting.java
create mode 100644 components/browser_ui/strings/android/viewport.grdp
diff --git a/chrome/app/settings_strings.grdp b/chrome/app/settings_strings.grdp
--- a/chrome/app/settings_strings.grdp
+++ b/chrome/app/settings_strings.grdp
@@ -4316,6 +4316,25 @@
Not allowed to use WebRTC
</message>
+ <message name="IDS_SITE_SETTINGS_VIEWPORT_PROTECTION_TITLE" desc="Description of the viewport protection content setting page title.">
+ Viewport Protection
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_DESCRIPTION" desc="Description of the viewport protection content setting.">
+ Enable Viewport Protection
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_ALLOWED" desc="Label for the enabled option of the viewport protection setting.">
+ Viewport Protection is enabled
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_BLOCKED" desc="Label for the disabled option of the viewport protection setting.">
+ Viewport Protection is disabled
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_ALLOWED_EXCEPTIONS" desc="Label for the allowed exceptions site list of the viewport protection setting.">
+ Allowed to use Viewport Protection
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_BLOCKED_EXCEPTIONS" desc="Label for the blocked exceptions site list of the viewport protection setting.">
+ Not allowed to use Viewport Protection
+ </message>
+
<if expr="not is_chromeos">
<!-- Import Settings Dialog -->
<message name="IDS_SETTINGS_IMPORT_SETTINGS_TITLE" desc="Dialog title for import dialog.">
diff --git a/chrome/browser/resources/settings/icons.html b/chrome/browser/resources/settings/icons.html
--- a/chrome/browser/resources/settings/icons.html
+++ b/chrome/browser/resources/settings/icons.html
@@ -199,6 +199,8 @@ NOTE: Chrome OS icons go in ./chromeos/os_icons.html.
<g id="webgl-off"><path d="M13.002 4.001H7.106L5.252 2.148c.232-.094.485-.147.75-.147h8l6 6v8.896l-2-2V9.001h-5v-5z" fill="#5F6368"></path><path d="M16.002 12.001h-.896l.896.896v-.896zM.6 3.45l1.414-1.414 19.94 19.94-1.414 1.414L.6 3.45zM3.986 20.01V6.84l2 2V20.01h11.172l1.765 1.766c-.28.15-.599.234-.937.234H5.976c-1.1 0-1.99-.9-1.99-2z" fill="#5F6368"></path><path d="M9.158 12.01H7.986v2h3.172l-2-2zM13.158 16.01H7.986v2h7.172l-2-2z" fill="#5F6368"></path></g>
<g id="webrtc"><path d="M8 16h8v2H8v-2zm0-4h8v2H8v-2zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z" fill="#5F6368"></path></g>
<g id="webrtc-off"><path d="M13.002 4.001H7.106L5.252 2.148c.232-.094.485-.147.75-.147h8l6 6v8.896l-2-2V9.001h-5v-5z" fill="#5F6368"></path><path d="M16.002 12.001h-.896l.896.896v-.896zM.6 3.45l1.414-1.414 19.94 19.94-1.414 1.414L.6 3.45zM3.986 20.01V6.84l2 2V20.01h11.172l1.765 1.766c-.28.15-.599.234-.937.234H5.976c-1.1 0-1.99-.9-1.99-2z" fill="#5F6368"></path><path d="M9.158 12.01H7.986v2h3.172l-2-2zM13.158 16.01H7.986v2h7.172l-2-2z" fill="#5F6368"></path></g>
+ <g id="viewport-protection"><path d="M8 16h8v2H8v-2zm0-4h8v2H8v-2zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z" fill="#5F6368"></path></g>
+ <g id="viewport-protection-off"><path d="M13.002 4.001H7.106L5.252 2.148c.232-.094.485-.147.75-.147h8l6 6v8.896l-2-2V9.001h-5v-5z" fill="#5F6368"></path><path d="M16.002 12.001h-.896l.896.896v-.896zM.6 3.45l1.414-1.414 19.94 19.94-1.414 1.414L.6 3.45zM3.986 20.01V6.84l2 2V20.01h11.172l1.765 1.766c-.28.15-.599.234-.937.234H5.976c-1.1 0-1.99-.9-1.99-2z" fill="#5F6368"></path><path d="M9.158 12.01H7.986v2h3.172l-2-2zM13.158 16.01H7.986v2h7.172l-2-2z" fill="#5F6368"></path></g>
</defs>
</svg>
</iron-iconset-svg>
diff --git a/chrome/browser/resources/settings/privacy_page/privacy_page.html b/chrome/browser/resources/settings/privacy_page/privacy_page.html
--- a/chrome/browser/resources/settings/privacy_page/privacy_page.html
+++ b/chrome/browser/resources/settings/privacy_page/privacy_page.html
@@ -1213,4 +1213,26 @@
</category-setting-exceptions>
</settings-subpage>
</template>
+ <template is="dom-if" route-path="/content/viewport-protection" no-search>
+ <settings-subpage page-title="$i18n{siteSettingsViewportProtection}"
+ search-label="$i18n{siteSettingsAllSitesSearch}"
+ search-term="{{searchFilter_}}">
+ <div class="content-settings-header secondary">
+ $i18n{siteSettingsViewportProtectionDescription}
+ </div>
+ <settings-category-default-radio-group
+ category="[[contentSettingsTypesEnum_.VIEWPORT]]"
+ allow-option-label="$i18n{siteSettingsViewportProtectionAllowed}"
+ allow-option-icon="settings:viewport-protection"
+ block-option-label="$i18n{siteSettingsViewportProtectionBlocked}"
+ block-option-icon="settings:viewport-protection-off">
+ </settings-category-default-radio-group>
+ <category-setting-exceptions
+ category="[[contentSettingsTypesEnum_.VIEWPORT]]"
+ block-header="$i18n{siteSettingsViewportProtectionBlockedExceptions}"
+ allow-header="$i18n{siteSettingsViewportProtectionAllowedExceptions}"
+ search-filter="[[searchFilter_]]">
+ </category-setting-exceptions>
+ </settings-subpage>
+ </template>
</settings-animated-pages>
diff --git a/chrome/browser/resources/settings/route.ts b/chrome/browser/resources/settings/route.ts
--- a/chrome/browser/resources/settings/route.ts
+++ b/chrome/browser/resources/settings/route.ts
@@ -119,6 +119,7 @@ function addPrivacyChildRoutes(r: Partial<SettingsRoutes>) {
r.SITE_SETTINGS_TIMEZONE_OVERRIDE = r.SITE_SETTINGS.createChild('timezone-override');
r.SITE_SETTINGS_WEBGL = r.SITE_SETTINGS.createChild('webgl');
r.SITE_SETTINGS_WEBRTC = r.SITE_SETTINGS.createChild('webrtc');
+ r.SITE_SETTINGS_VIEWPORT = r.SITE_SETTINGS.createChild('viewport-protection');
}
/**
diff --git a/chrome/browser/resources/settings/router.ts b/chrome/browser/resources/settings/router.ts
--- a/chrome/browser/resources/settings/router.ts
+++ b/chrome/browser/resources/settings/router.ts
@@ -106,6 +106,7 @@ export interface SettingsRoutes {
SITE_SETTINGS_TIMEZONE_OVERRIDE: Route;
SITE_SETTINGS_WEBGL: Route;
SITE_SETTINGS_WEBRTC: Route;
+ SITE_SETTINGS_VIEWPORT: Route;
}
/** Class for navigable routes. */
diff --git a/chrome/browser/resources/settings/site_settings/category_default_setting.ts b/chrome/browser/resources/settings/site_settings/category_default_setting.ts
--- a/chrome/browser/resources/settings/site_settings/category_default_setting.ts
+++ b/chrome/browser/resources/settings/site_settings/category_default_setting.ts
@@ -200,6 +200,7 @@ export class CategoryDefaultSettingElement extends
case ContentSettingsTypes.TIMEZONE_OVERRIDE:
case ContentSettingsTypes.WEBGL:
case ContentSettingsTypes.WEBRTC:
+ case ContentSettingsTypes.VIEWPORT:
// "Allowed" vs "Blocked".
this.browserProxy.setDefaultValueForContentType(
this.category,
diff --git a/chrome/browser/resources/settings/site_settings/constants.ts b/chrome/browser/resources/settings/site_settings/constants.ts
--- a/chrome/browser/resources/settings/site_settings/constants.ts
+++ b/chrome/browser/resources/settings/site_settings/constants.ts
@@ -51,6 +51,7 @@ export enum ContentSettingsTypes {
TIMEZONE_OVERRIDE = 'timezone-override',
WEBGL = 'webgl',
WEBRTC = 'webrtc',
+ VIEWPORT = 'viewport',
// The following items are not in the C++ kContentSettingsTypeGroupNames, but
// are used everywhere where ContentSettingsTypes is used in JS.
diff --git a/chrome/browser/resources/settings/site_settings/settings_category_default_radio_group.ts b/chrome/browser/resources/settings/site_settings/settings_category_default_radio_group.ts
--- a/chrome/browser/resources/settings/site_settings/settings_category_default_radio_group.ts
+++ b/chrome/browser/resources/settings/site_settings/settings_category_default_radio_group.ts
@@ -144,6 +144,7 @@ export class SettingsCategoryDefaultRadioGroupElement extends
case ContentSettingsTypes.TIMEZONE_OVERRIDE:
case ContentSettingsTypes.WEBGL:
case ContentSettingsTypes.WEBRTC:
+ case ContentSettingsTypes.VIEWPORT:
// "Allowed" vs "Blocked".
return ContentSetting.ALLOW;
case ContentSettingsTypes.AR:
diff --git a/chrome/browser/resources/settings/site_settings/site_details.html b/chrome/browser/resources/settings/site_settings/site_details.html
--- a/chrome/browser/resources/settings/site_settings/site_details.html
+++ b/chrome/browser/resources/settings/site_settings/site_details.html
@@ -291,4 +291,9 @@
icon="settings:webrtc"
label="$i18n{siteSettingsWebRTC}">
</site-details-permission>
+ <site-details-permission
+ category="[[contentSettingsTypesEnum_.VIEWPORT]]"
+ icon="settings:viewport-protection"
+ label="$i18n{siteSettingsViewportProtection}">
+ </site-details-permission>
</div>
diff --git a/chrome/browser/resources/settings/site_settings_page/site_settings_page.ts b/chrome/browser/resources/settings/site_settings_page/site_settings_page.ts
--- a/chrome/browser/resources/settings/site_settings_page/site_settings_page.ts
+++ b/chrome/browser/resources/settings/site_settings_page/site_settings_page.ts
@@ -374,6 +374,14 @@ function getCategoryItemMap(): Map<ContentSettingsTypes, CategoryListItem> {
enabledLabel: 'siteSettingsWebRTCAllowed',
disabledLabel: 'siteSettingsWebRTCBlocked',
},
+ {
+ route: routes.SITE_SETTINGS_VIEWPORT,
+ id: Id.VIEWPORT,
+ label: 'siteSettingsViewportProtection',
+ icon: 'settings:viewport-protection',
+ enabledLabel: 'siteSettingsViewportProtectionAllowed',
+ disabledLabel: 'siteSettingsViewportProtectionBlocked',
+ },
];
categoryItemMap = new Map(categoryList.map(item => [item.id, item]));
@@ -472,6 +480,7 @@ export class SettingsSiteSettingsPageElement extends
Id.TIMEZONE_OVERRIDE,
Id.WEBGL,
Id.WEBRTC,
+ Id.VIEWPORT,
]),
};
},
diff --git a/chrome/browser/resources/settings/site_settings_page/site_settings_page_util.ts b/chrome/browser/resources/settings/site_settings_page/site_settings_page_util.ts
--- a/chrome/browser/resources/settings/site_settings_page/site_settings_page_util.ts
+++ b/chrome/browser/resources/settings/site_settings_page/site_settings_page_util.ts
@@ -87,6 +87,8 @@ export function getLocalizationStringForContentType(
return 'siteSettingsWebglMidSentence';
case ContentSettingsTypes.WEBRTC:
return 'siteSettingsWebRTCMidSentence';
+ case ContentSettingsTypes.VIEWPORT:
+ return 'siteSettingsViewportProtectionMidSentence';
// The following members do not have a mid-sentence localization.
case ContentSettingsTypes.ANTI_ABUSE:
case ContentSettingsTypes.PDF_DOCUMENTS:
diff --git a/chrome/browser/ui/views/page_info/page_info_view_factory.cc b/chrome/browser/ui/views/page_info/page_info_view_factory.cc
--- a/chrome/browser/ui/views/page_info/page_info_view_factory.cc
+++ b/chrome/browser/ui/views/page_info/page_info_view_factory.cc
@@ -353,6 +353,9 @@ const ui::ImageModel PageInfoViewFactory::GetPermissionIcon(
case ContentSettingsType::WEBRTC:
icon = &vector_icons::kProtectedContentIcon;
break;
+ case ContentSettingsType::VIEWPORT:
+ icon = &vector_icons::kProtectedContentIcon;
+ break;
default:
// All other |ContentSettingsType|s do not have icons on desktop or are
// not shown in the Page Info bubble.
diff --git a/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc b/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
--- a/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
+++ b/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
@@ -2455,6 +2455,13 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source,
{"siteSettingsWebRTCAllowedExceptions",IDS_SETTINGS_SITE_SETTINGS_WEBRTC_ALLOWED_EXCEPTIONS},
{"siteSettingsWebRTCBlockedExceptions", IDS_SETTINGS_SITE_SETTINGS_WEBRTC_BLOCKED_EXCEPTIONS},
{"siteSettingsWebRTCMidSentence", IDS_SITE_SETTINGS_WEBRTC_TITLE},
+ {"siteSettingsViewportProtection", IDS_SITE_SETTINGS_VIEWPORT_PROTECTION_TITLE},
+ {"siteSettingsViewportProtectionDescription", IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_DESCRIPTION},
+ {"siteSettingsViewportProtectionAllowed", IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_ALLOWED},
+ {"siteSettingsViewportProtectionBlocked", IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_BLOCKED},
+ {"siteSettingsViewportProtectionAllowedExceptions",IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_ALLOWED_EXCEPTIONS},
+ {"siteSettingsViewportProtectionBlockedExceptions", IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_BLOCKED_EXCEPTIONS},
+ {"siteSettingsViewportProtectionMidSentence", IDS_SITE_SETTINGS_VIEWPORT_PROTECTION_TITLE},
{"addSite", IDS_SETTINGS_ADD_SITE},
{"addSiteTitle", IDS_SETTINGS_ADD_SITE_TITLE},
#if BUILDFLAG(IS_CHROMEOS_ASH)
diff --git a/chrome/browser/ui/webui/settings/site_settings_helper.cc b/chrome/browser/ui/webui/settings/site_settings_helper.cc
--- a/chrome/browser/ui/webui/settings/site_settings_helper.cc
+++ b/chrome/browser/ui/webui/settings/site_settings_helper.cc
@@ -130,6 +130,7 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
{ContentSettingsType::TIMEZONE_OVERRIDE, "timezone-override"},
{ContentSettingsType::WEBGL, "webgl"},
{ContentSettingsType::WEBRTC, "webrtc"},
+ {ContentSettingsType::VIEWPORT, "viewport"},
// Add new content settings here if a corresponding Javascript string
// representation for it is not required, for example if the content setting
diff --git a/components/browser_ui/site_settings/android/BUILD.gn b/components/browser_ui/site_settings/android/BUILD.gn
--- a/components/browser_ui/site_settings/android/BUILD.gn
+++ b/components/browser_ui/site_settings/android/BUILD.gn
@@ -112,6 +112,9 @@ android_library("java") {
sources += [
"java/src/org/chromium/components/browser_ui/site_settings/BromiteWebRTCContentSetting.java",
]
+ sources += [
+ "java/src/org/chromium/components/browser_ui/site_settings/BromiteViewportContentSetting.java",
+ ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
resources_package = "org.chromium.components.browser_ui.site_settings"
deps = [
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java
@@ -45,6 +45,7 @@ public abstract class BromiteCustomContentSettingImpl {
mItemList = new ArrayList<BromiteCustomContentSetting>();
mItemList.add(new BromiteWebGLContentSetting());
mItemList.add(new BromiteWebRTCContentSetting());
+ mItemList.add(new BromiteViewportContentSetting());
}
public static SiteSettingsCategory createFromType(
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteViewportContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteViewportContentSetting.java
new file mode 100644
--- /dev/null
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteViewportContentSetting.java
@@ -0,0 +1,86 @@
+/*
+ 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;
+
+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 BromiteViewportContentSetting extends BromiteCustomContentSetting {
+ public BromiteViewportContentSetting() {
+ super(/*contentSettingsType*/ ContentSettingsType.VIEWPORT,
+ /*siteSettingsCategory*/ SiteSettingsCategory.Type.VIEWPORT,
+ /*defaultEnabledValue*/ ContentSettingValues.ALLOW,
+ /*defaultDisabledValue*/ ContentSettingValues.BLOCK,
+ /*allowException*/ true,
+ /*preferenceKey*/ "viewport",
+ /*profilePrefKey*/ "viewport");
+ }
+
+ @Override
+ public ContentSettingsResources.ResourceItem getResourceItem() {
+ return new ContentSettingsResources.ResourceItem(
+ /*icon*/ R.drawable.web_asset,
+ /*title*/ R.string.viewport_permission_title,
+ /*defaultEnabledValue*/ getDefaultEnabledValue(),
+ /*defaultDisabledValue*/ getDefaultDisabledValue(),
+ /*enabledSummary*/ R.string.website_settings_category_viewport_enabled,
+ /*disabledSummary*/ R.string.website_settings_category_viewport_disabled);
+ }
+
+ @Override
+ public int getCategorySummary(@Nullable @ContentSettingValues int value) {
+ switch (value) {
+ case ContentSettingValues.ALLOW:
+ return R.string.website_settings_category_viewport_enabled;
+ case ContentSettingValues.BLOCK:
+ return R.string.website_settings_category_viewport_disabled;
+ default:
+ // this will cause a runtime exception
+ return 0;
+ }
+ }
+
+ @Override
+ public boolean requiresTriStateContentSetting() {
+ return false;
+ }
+
+ @Override
+ public boolean showOnlyDescriptions() {
+ return true;
+ }
+
+ @Override
+ public int getAddExceptionDialogMessage() {
+ return R.string.website_settings_category_viewport_enabled;
+ }
+
+ @Override
+ public @Nullable Boolean considerException(SiteSettingsCategory category, @ContentSettingValues int value) {
+ return value != ContentSettingValues.BLOCK;
+ }
+}
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
@@ -48,7 +48,7 @@ public class SiteSettingsCategory {
Type.USE_STORAGE, Type.AUTO_DARK_WEB_CONTENT, Type.REQUEST_DESKTOP_SITE,
Type.FEDERATED_IDENTITY_API, Type.THIRD_PARTY_COOKIES, Type.SITE_DATA, Type.ANTI_ABUSE,
Type.TIMEZONE_OVERRIDE, Type.AUTOPLAY, Type.JAVASCRIPT_JIT, Type.IMAGES,
- Type.NUM_ENTRIES, Type.WEBGL, Type.WEBRTC})
+ Type.NUM_ENTRIES, Type.WEBGL, Type.WEBRTC, Type.VIEWPORT})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
// All updates here must also be reflected in {@link #preferenceKey(int)
@@ -88,10 +88,11 @@ public class SiteSettingsCategory {
int IMAGES = 32;
int WEBGL = 33;
int WEBRTC = 34;
+ int VIEWPORT = 35;
/**
* Number of handled categories used for calculating array sizes.
*/
- int NUM_ENTRIES = 35;
+ int NUM_ENTRIES = 36;
}
private final BrowserContextHandle mBrowserContextHandle;
diff --git a/components/browser_ui/strings/android/browser_ui_strings.grd b/components/browser_ui/strings/android/browser_ui_strings.grd
--- a/components/browser_ui/strings/android/browser_ui_strings.grd
+++ b/components/browser_ui/strings/android/browser_ui_strings.grd
@@ -176,6 +176,7 @@
<part file="site_settings.grdp" />
<part file="webgl.grdp" />
<part file="webrtc.grdp" />
+ <part file="viewport.grdp" />
<message name="IDS_GOT_IT" desc="Button for the user to accept a disclosure/message" formatter_data="android_java">
Got it
diff --git a/components/browser_ui/strings/android/viewport.grdp b/components/browser_ui/strings/android/viewport.grdp
new file mode 100644
--- /dev/null
+++ b/components/browser_ui/strings/android/viewport.grdp
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<grit-part>
+ <message name="IDS_SITE_SETTINGS_TYPE_VIEWPORT" desc="The label used for viewport size change site settings controls.">
+ Viewport Size Protection
+ </message>
+ <message name="IDS_SITE_SETTINGS_TYPE_VIEWPORT_MID_SENTENCE" desc="The label used for viewport size change site settings controls when used mid-sentence.">
+ Viewport Size Protection
+ </message>
+ <message name="IDS_VIEWPORT_PERMISSION_TITLE" desc="Title of the permission to use viewport size change [CHAR-LIMIT=32]">
+ Viewport Size Protection
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_VIEWPORT_ENABLED" desc="Summary text explaining that viewport size change is full enabled.">
+ Enabled
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_VIEWPORT_DISABLED" desc="Summary text explaining that viewport size change is full disabled.">
+ Disabled
+ </message>
+</grit-part>
diff --git a/components/components_strings.grd b/components/components_strings.grd
--- a/components/components_strings.grd
+++ b/components/components_strings.grd
@@ -341,6 +341,7 @@
<part file="browser_ui/strings/android/webgl.grdp" />
<part file="browser_ui/strings/android/webrtc.grdp" />
+ <part file="browser_ui/strings/android/viewport.grdp" />
<if expr="not is_ios">
<part file="history_clusters_strings.grdp" />
</if>
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
@@ -622,12 +622,25 @@ void ContentSettingsRegistry::Init() {
/*valid_settings=*/{CONTENT_SETTING_ALLOW,
CONTENT_SETTING_BLOCK},
WebsiteSettingsInfo::TOP_ORIGIN_ONLY_SCOPE,
- WebsiteSettingsRegistry::PLATFORM_ANDROID,
+ WebsiteSettingsRegistry::ALL_PLATFORMS,
ContentSettingsInfo::INHERIT_IN_INCOGNITO,
ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS,
/*show_into_info_page*/ true,
/*permission_type_ui*/ IDS_SITE_SETTINGS_TYPE_WEBRTC,
/*permission_type_ui_mid_sentence*/ IDS_SITE_SETTINGS_TYPE_WEBRTC_MID_SENTENCE);
+
+ Register(ContentSettingsType::VIEWPORT, "viewport", CONTENT_SETTING_ALLOW,
+ WebsiteSettingsInfo::SYNCABLE,
+ /*allowlisted_schemes=*/{},
+ /*valid_settings=*/{CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK},
+ WebsiteSettingsInfo::TOP_ORIGIN_ONLY_SCOPE,
+ WebsiteSettingsRegistry::ALL_PLATFORMS,
+ ContentSettingsInfo::INHERIT_IN_INCOGNITO,
+ ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS,
+ /*show_into_info_page*/ true,
+ /*permission_type_ui*/ IDS_SITE_SETTINGS_TYPE_VIEWPORT,
+ /*permission_type_ui_mid_sentence*/ IDS_SITE_SETTINGS_TYPE_VIEWPORT_MID_SENTENCE);
}
void ContentSettingsRegistry::Register(
diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc
--- a/components/content_settings/core/browser/content_settings_utils.cc
+++ b/components/content_settings/core/browser/content_settings_utils.cc
@@ -162,6 +162,8 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map,
&(rules->webgl_rules));
map->GetSettingsForOneType(ContentSettingsType::WEBRTC,
&(rules->webrtc_rules));
+ map->GetSettingsForOneType(ContentSettingsType::VIEWPORT,
+ &(rules->viewport_rules));
}
bool IsMorePermissive(ContentSetting a, ContentSetting b) {
diff --git a/components/content_settings/core/common/content_settings.cc b/components/content_settings/core/common/content_settings.cc
--- a/components/content_settings/core/common/content_settings.cc
+++ b/components/content_settings/core/common/content_settings.cc
@@ -219,7 +219,8 @@ bool RendererContentSettingRules::IsRendererContentSetting(
content_type == ContentSettingsType::AUTO_DARK_WEB_CONTENT ||
content_type == ContentSettingsType::TIMEZONE_OVERRIDE ||
content_type == ContentSettingsType::WEBGL ||
- content_type == ContentSettingsType::WEBRTC;
+ content_type == ContentSettingsType::WEBRTC ||
+ content_type == ContentSettingsType::VIEWPORT;
}
void RendererContentSettingRules::FilterRulesByOutermostMainFrameURL(
@@ -233,6 +234,7 @@ void RendererContentSettingRules::FilterRulesByOutermostMainFrameURL(
FilterRulesForType(autoplay_rules, outermost_main_frame_url);
FilterRulesForType(webgl_rules, outermost_main_frame_url);
FilterRulesForType(webrtc_rules, outermost_main_frame_url);
+ FilterRulesForType(viewport_rules, outermost_main_frame_url);
}
RendererContentSettingRules::RendererContentSettingRules() = default;
diff --git a/components/content_settings/core/common/content_settings.h b/components/content_settings/core/common/content_settings.h
--- a/components/content_settings/core/common/content_settings.h
+++ b/components/content_settings/core/common/content_settings.h
@@ -98,6 +98,7 @@ struct RendererContentSettingRules {
std::string timezone_override_value;
ContentSettingsForOneType webgl_rules;
ContentSettingsForOneType webrtc_rules;
+ ContentSettingsForOneType viewport_rules;
};
namespace content_settings {
diff --git a/components/content_settings/core/common/content_settings.mojom b/components/content_settings/core/common/content_settings.mojom
--- a/components/content_settings/core/common/content_settings.mojom
+++ b/components/content_settings/core/common/content_settings.mojom
@@ -83,4 +83,5 @@ struct RendererContentSettingRules {
string timezone_override_value;
array<ContentSettingPatternSource> webgl_rules;
array<ContentSettingPatternSource> webrtc_rules;
+ array<ContentSettingPatternSource> viewport_rules;
};
diff --git a/components/content_settings/core/common/content_settings_mojom_traits.cc b/components/content_settings/core/common/content_settings_mojom_traits.cc
--- a/components/content_settings/core/common/content_settings_mojom_traits.cc
+++ b/components/content_settings/core/common/content_settings_mojom_traits.cc
@@ -107,7 +107,8 @@ bool StructTraits<content_settings::mojom::RendererContentSettingRulesDataView,
data.ReadTimezoneOverrideRules(&out->timezone_override_rules) &&
data.ReadTimezoneOverrideValue(&out->timezone_override_value) &&
data.ReadWebglRules(&out->webgl_rules) &&
- data.ReadWebrtcRules(&out->webrtc_rules);
+ data.ReadWebrtcRules(&out->webrtc_rules) &&
+ data.ReadViewportRules(&out->viewport_rules);
}
} // namespace mojo
diff --git a/components/content_settings/core/common/content_settings_mojom_traits.h b/components/content_settings/core/common/content_settings_mojom_traits.h
--- a/components/content_settings/core/common/content_settings_mojom_traits.h
+++ b/components/content_settings/core/common/content_settings_mojom_traits.h
@@ -175,6 +175,11 @@ struct StructTraits<
return r.webrtc_rules;
}
+ static const std::vector<ContentSettingPatternSource>& viewport_rules(
+ const RendererContentSettingRules& r) {
+ return r.viewport_rules;
+ }
+
static bool Read(
content_settings::mojom::RendererContentSettingRulesDataView data,
RendererContentSettingRules* out);
diff --git a/components/content_settings/core/common/content_settings_types.h b/components/content_settings/core/common/content_settings_types.h
--- a/components/content_settings/core/common/content_settings_types.h
+++ b/components/content_settings/core/common/content_settings_types.h
@@ -281,6 +281,8 @@ enum class ContentSettingsType : int32_t {
WEBRTC,
+ VIEWPORT,
+
// Setting to indicate whether browser should allow signing into a website via
// the browser FedCM API.
FEDERATED_IDENTITY_API,
diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc
--- a/components/content_settings/renderer/content_settings_agent_impl.cc
+++ b/components/content_settings/renderer/content_settings_agent_impl.cc
@@ -459,6 +459,15 @@ bool ContentSettingsAgentImpl::AllowWebRTC(bool enabled_per_settings) {
url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL());
}
+bool ContentSettingsAgentImpl::AllowViewportChange(bool enabled_per_settings) {
+ if (!content_setting_rules_)
+ return false;
+ blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
+ return CONTENT_SETTING_ALLOW == GetContentSettingFromRules(
+ content_setting_rules_->viewport_rules,
+ url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL());
+}
+
bool ContentSettingsAgentImpl::IsAllowlistedForContentSettings() const {
if (should_allowlist_)
return true;
diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h
--- a/components/content_settings/renderer/content_settings_agent_impl.h
+++ b/components/content_settings/renderer/content_settings_agent_impl.h
@@ -101,6 +101,7 @@ class ContentSettingsAgentImpl
bool ShouldAutoupgradeMixedContent() override;
bool AllowWebgl(bool enabled_per_settings) override;
bool AllowWebRTC(bool enabled_per_settings) override;
+ bool AllowViewportChange(bool enabled_per_settings) override;
bool allow_running_insecure_content() const {
return allow_running_insecure_content_;
diff --git a/third_party/blink/common/features.cc b/third_party/blink/common/features.cc
--- a/third_party/blink/common/features.cc
+++ b/third_party/blink/common/features.cc
@@ -219,7 +219,7 @@ BASE_FEATURE(kPath2DPaintCache,
BASE_FEATURE(kViewportProtection,
"ViewportProtection",
- base::FEATURE_ENABLED_BY_DEFAULT);
+ base::FEATURE_DISABLED_BY_DEFAULT);
BASE_FEATURE(kPrivacySandboxAdsAPIs,
"PrivacySandboxAdsAPIs",
diff --git a/third_party/blink/public/platform/web_content_settings_client.h b/third_party/blink/public/platform/web_content_settings_client.h
--- a/third_party/blink/public/platform/web_content_settings_client.h
+++ b/third_party/blink/public/platform/web_content_settings_client.h
@@ -103,6 +103,8 @@ class WebContentSettingsClient {
virtual bool AllowWebRTC(bool default_value) { return default_value; }
+ virtual bool AllowViewportChange(bool default_value) { return default_value; }
+
// Reports that passive mixed content was found at the provided URL.
virtual void PassiveInsecureContentFound(const WebURL&) {}
diff --git a/third_party/blink/renderer/core/frame/local_dom_window.cc b/third_party/blink/renderer/core/frame/local_dom_window.cc
--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
+++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
@@ -2303,6 +2303,7 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
// var w = window.open()
// var not_emulated_screen_info = w.screen
bool protection_enabled = base::FeatureList::IsEnabled(features::kViewportProtection);
+ protection_enabled |= GetFrame()->GetContentSettingsClient()->AllowViewportChange(false);
result.frame->GetPage()->CalculateEmulatedScreenSetting(
To<LocalFrame>(result.frame),
/*force*/ protection_enabled);
diff --git a/third_party/blink/renderer/core/page/page.cc b/third_party/blink/renderer/core/page/page.cc
--- a/third_party/blink/renderer/core/page/page.cc
+++ b/third_party/blink/renderer/core/page/page.cc
@@ -885,6 +885,8 @@ void Page::UpdateAcceleratedCompositingSettings() {
void Page::CalculateEmulatedScreenSetting(LocalFrame* frame, bool force) {
bool isEnabled = base::FeatureList::IsEnabled(features::kViewportProtection);
+ blink::WebContentSettingsClient* settings = frame->GetContentSettingsClient();
+ isEnabled |= (settings && settings->AllowViewportChange(false));
if (isEnabled || force) {
// this is the maximum (and minimum) value which in percentage
// corresponds to +- 0.03%
--
2.25.1