From 932cfc6f1e6ed1d9133fb648e5d12cd60fb3004d Mon Sep 17 00:00:00 2001 From: Carmelo Messina Date: Fri, 22 Dec 2023 14:47:11 +0100 Subject: [PATCH] #79 Disable viewport protection by default for chrome:// urls and pdfviewer patches merged --- build/bromite_patches_list.txt | 1 - .../Viewport-Protection-Site-Setting.patch | 208 -------------- build/patches/Viewport-Protection-flag.patch | 267 ++++++++++++++++-- 3 files changed, 246 insertions(+), 230 deletions(-) delete mode 100644 build/patches/Viewport-Protection-Site-Setting.patch diff --git a/build/bromite_patches_list.txt b/build/bromite_patches_list.txt index eb9954d67..0584a2838 100644 --- a/build/bromite_patches_list.txt +++ b/build/bromite_patches_list.txt @@ -242,7 +242,6 @@ Add-webGL-site-setting.patch Add-webRTC-site-settings.patch Show-site-settings-for-cookies-javascript-and-ads.patch Viewport-Protection-flag.patch -Viewport-Protection-Site-Setting.patch Timezone-customization.patch 00Disable-speechSynthesis-getVoices-API.patch 00Remove-support-for-device-memory-and-cpu-recovery.patch diff --git a/build/patches/Viewport-Protection-Site-Setting.patch b/build/patches/Viewport-Protection-Site-Setting.patch deleted file mode 100644 index 27a86da8c..000000000 --- a/build/patches/Viewport-Protection-Site-Setting.patch +++ /dev/null @@ -1,208 +0,0 @@ -From: uazo -Date: Fri, 16 Jun 2023 15:56:35 +0000 -Subject: Viewport Protection Site Setting - -Require: Content-settings-infrastructure.patch ---- - .../impl/BromiteViewportContentSetting.java | 93 +++++++++++++++++++ - .../bromite_content_settings/viewport.grdp | 27 ++++++ - .../bromite_content_settings/viewport.inc | 22 +++++ - .../bromite_content_settings/VIEWPORT.inc | 1 + - .../renderer/core/frame/local_dom_window.cc | 2 + - third_party/blink/renderer/core/page/page.cc | 3 + - 6 files changed, 148 insertions(+) - create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java - create mode 100644 components/browser_ui/strings/bromite_content_settings/viewport.grdp - create mode 100644 components/content_settings/core/browser/bromite_content_settings/viewport.inc - create mode 100644 components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc - -diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java -new file mode 100644 ---- /dev/null -+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java -@@ -0,0 +1,93 @@ -+/* -+ 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 . -+*/ -+ -+package org.chromium.components.browser_ui.site_settings.impl; -+ -+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 BromiteViewportContentSetting extends BromiteCustomContentSetting { -+ public BromiteViewportContentSetting() { -+ super(/*contentSettingsType*/ ContentSettingsType.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 int getCategoryDescription() { -+ return R.string.settings_site_settings_viewport_protection_description; -+ } -+ -+ @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/strings/bromite_content_settings/viewport.grdp b/components/browser_ui/strings/bromite_content_settings/viewport.grdp -new file mode 100644 ---- /dev/null -+++ b/components/browser_ui/strings/bromite_content_settings/viewport.grdp -@@ -0,0 +1,27 @@ -+ -+ -+ -+ Viewport Size Protection -+ -+ -+ Viewport Size Protection -+ -+ -+ Viewport Size Protection -+ -+ -+ Hides the screen size by randomly changing the values for each website -+ -+ -+ Enabled -+ -+ -+ Disabled -+ -+ -+ Viewport Protection is enabled with these websites -+ -+ -+ Not allowed to use Viewport Protection -+ -+ -diff --git a/components/content_settings/core/browser/bromite_content_settings/viewport.inc b/components/content_settings/core/browser/bromite_content_settings/viewport.inc -new file mode 100644 ---- /dev/null -+++ b/components/content_settings/core/browser/bromite_content_settings/viewport.inc -@@ -0,0 +1,22 @@ -+ 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); -+ -+ content_settings::WebsiteSettingsRegistry::GetInstance() -+ ->GetMutable(ContentSettingsType::VIEWPORT) -+ ->set_show_into_info_page() -+ .set_desktop_ui() -+ .set_is_renderer_content_setting() -+ .set_title_ui(IDS_SITE_SETTINGS_TYPE_VIEWPORT) -+ .set_description_ui(IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_DESCRIPTION) -+ .set_allowed_ui(IDS_WEBSITE_SETTINGS_CATEGORY_VIEWPORT_ENABLED) -+ .set_blocked_ui(IDS_WEBSITE_SETTINGS_CATEGORY_VIEWPORT_DISABLED) -+ .set_allowed_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_ALLOWED_EXCEPTIONS) -+ .set_blocked_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_BLOCKED_EXCEPTIONS) -+ .set_mid_sentence_ui(IDS_SITE_SETTINGS_TYPE_VIEWPORT_MID_SENTENCE); -diff --git a/components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc b/components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc -new file mode 100644 ---- /dev/null -+++ b/components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc -@@ -0,0 +1 @@ -+ VIEWPORT, -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 -@@ -2285,6 +2285,8 @@ 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()->AllowContentSetting( -+ ContentSettingsType::VIEWPORT, false); - result.frame->GetPage()->CalculateEmulatedScreenSetting( - To(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 -@@ -908,6 +908,9 @@ 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->AllowContentSetting( -+ ContentSettingsType::VIEWPORT, /*default_value*/ false)); - if (isEnabled || force) { - // this is the maximum (and minimum) value which in percentage - // corresponds to +- 0.03% --- -2.25.1 diff --git a/build/patches/Viewport-Protection-flag.patch b/build/patches/Viewport-Protection-flag.patch index e907e3a3d..1e99d44c7 100644 --- a/build/patches/Viewport-Protection-flag.patch +++ b/build/patches/Viewport-Protection-flag.patch @@ -6,31 +6,223 @@ Scale the viewport and the screen by a random factor to prevent coordinate-based fingerprinting scripts. The factor is changed at each change of origin. The feature is controlled by a feature flag (default enabled) + +Require: Content-settings-infrastructure.patch --- - .../Viewport-Protection-flag.inc | 10 +++ + .../impl/BromiteViewportContentSetting.java | 93 +++++++++++++++++++ + .../bromite_content_settings/viewport.grdp | 27 ++++++ + .../bromite_content_settings/viewport.inc | 22 +++++ + .../bromite_content_settings/VIEWPORT.inc | 1 + + .../guest_view/browser/guest_view_base.cc | 8 ++ + .../Viewport-Protection-flag.inc | 10 ++ .../features_cc/Viewport-Protection-flag.inc | 3 + .../features_h/Viewport-Protection-flag.inc | 2 + .../common/widget/device_emulation_params.h | 6 +- .../blink/renderer/core/css/media_values.cc | 2 +- .../core/css/resolver/style_resolver.cc | 7 +- - .../blink/renderer/core/events/mouse_event.h | 19 ++++- + .../blink/renderer/core/events/mouse_event.h | 19 +++- .../renderer/core/events/pointer_event.h | 11 +++ .../renderer/core/exported/web_view_impl.cc | 2 +- - .../renderer/core/frame/local_dom_window.cc | 41 +++++++++- - .../blink/renderer/core/frame/local_frame.cc | 12 ++- + .../renderer/core/frame/local_dom_window.cc | 43 ++++++++- + .../blink/renderer/core/frame/local_frame.cc | 17 +++- .../blink/renderer/core/frame/local_frame.h | 6 +- - .../core/frame/screen_metrics_emulator.cc | 18 ++++- - .../core/frame/screen_metrics_emulator.h | 14 ++++ + .../core/frame/screen_metrics_emulator.cc | 18 +++- + .../core/frame/screen_metrics_emulator.h | 14 +++ .../core/frame/web_frame_widget_impl.cc | 8 ++ .../core/frame/web_remote_frame_impl.cc | 3 +- - .../blink/renderer/core/input/touch.cc | 17 ++++- - third_party/blink/renderer/core/page/page.cc | 76 +++++++++++++++++++ - third_party/blink/renderer/core/page/page.h | 7 ++ - 19 files changed, 245 insertions(+), 19 deletions(-) + .../blink/renderer/core/input/touch.cc | 17 +++- + third_party/blink/renderer/core/page/page.cc | 92 ++++++++++++++++++ + third_party/blink/renderer/core/page/page.h | 9 ++ + 24 files changed, 421 insertions(+), 19 deletions(-) + create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java + create mode 100644 components/browser_ui/strings/bromite_content_settings/viewport.grdp + create mode 100644 components/content_settings/core/browser/bromite_content_settings/viewport.inc + create mode 100644 components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Viewport-Protection-flag.inc create mode 100644 cromite_flags/third_party/blink/common/features_cc/Viewport-Protection-flag.inc create mode 100644 cromite_flags/third_party/blink/common/features_h/Viewport-Protection-flag.inc +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java +new file mode 100644 +--- /dev/null ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteViewportContentSetting.java +@@ -0,0 +1,93 @@ ++/* ++ 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 . ++*/ ++ ++package org.chromium.components.browser_ui.site_settings.impl; ++ ++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 BromiteViewportContentSetting extends BromiteCustomContentSetting { ++ public BromiteViewportContentSetting() { ++ super(/*contentSettingsType*/ ContentSettingsType.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 int getCategoryDescription() { ++ return R.string.settings_site_settings_viewport_protection_description; ++ } ++ ++ @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/strings/bromite_content_settings/viewport.grdp b/components/browser_ui/strings/bromite_content_settings/viewport.grdp +new file mode 100644 +--- /dev/null ++++ b/components/browser_ui/strings/bromite_content_settings/viewport.grdp +@@ -0,0 +1,27 @@ ++ ++ ++ ++ Viewport Size Protection ++ ++ ++ Viewport Size Protection ++ ++ ++ Viewport Size Protection ++ ++ ++ Hides the screen size by randomly changing the values for each website ++ ++ ++ Enabled ++ ++ ++ Disabled ++ ++ ++ Viewport Protection is enabled with these websites ++ ++ ++ Not allowed to use Viewport Protection ++ ++ +diff --git a/components/content_settings/core/browser/bromite_content_settings/viewport.inc b/components/content_settings/core/browser/bromite_content_settings/viewport.inc +new file mode 100644 +--- /dev/null ++++ b/components/content_settings/core/browser/bromite_content_settings/viewport.inc +@@ -0,0 +1,22 @@ ++ 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); ++ ++ content_settings::WebsiteSettingsRegistry::GetInstance() ++ ->GetMutable(ContentSettingsType::VIEWPORT) ++ ->set_show_into_info_page() ++ .set_desktop_ui() ++ .set_is_renderer_content_setting() ++ .set_title_ui(IDS_SITE_SETTINGS_TYPE_VIEWPORT) ++ .set_description_ui(IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_DESCRIPTION) ++ .set_allowed_ui(IDS_WEBSITE_SETTINGS_CATEGORY_VIEWPORT_ENABLED) ++ .set_blocked_ui(IDS_WEBSITE_SETTINGS_CATEGORY_VIEWPORT_DISABLED) ++ .set_allowed_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_ALLOWED_EXCEPTIONS) ++ .set_blocked_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_VIEWPORT_PROTECTION_BLOCKED_EXCEPTIONS) ++ .set_mid_sentence_ui(IDS_SITE_SETTINGS_TYPE_VIEWPORT_MID_SENTENCE); +diff --git a/components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc b/components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc +new file mode 100644 +--- /dev/null ++++ b/components/content_settings/core/common/bromite_content_settings/VIEWPORT.inc +@@ -0,0 +1 @@ ++ VIEWPORT, +diff --git a/components/guest_view/browser/guest_view_base.cc b/components/guest_view/browser/guest_view_base.cc +--- a/components/guest_view/browser/guest_view_base.cc ++++ b/components/guest_view/browser/guest_view_base.cc +@@ -497,6 +497,14 @@ void GuestViewBase::AttachToOuterWebContentsFrame( + if (attachment_callback) + std::move(attachment_callback).Run(); + ++ // Disable viewport protection ++ // I use this hack, i.e. I reuse the SetPageScale method for my own purposes, ++ // so that I do not have to enter a new call in mojo and thus edit ++ // so many files. ++ // the chromium code never uses negative values, so there is no ++ // danger of inserting problems ++ embedder_web_contents->SetPageScale(-999); ++ + // Completing attachment will resume suspended resource loads and then send + // queued events. + SignalWhenReady(base::BindOnce(&GuestViewBase::DidAttach, diff --git a/cromite_flags/chrome/browser/about_flags_cc/Viewport-Protection-flag.inc b/cromite_flags/chrome/browser/about_flags_cc/Viewport-Protection-flag.inc new file mode 100644 --- /dev/null @@ -235,7 +427,7 @@ diff --git a/third_party/blink/renderer/core/frame/local_dom_window.cc b/third_p } void LocalDOMWindow::scrollBy(double x, double y) const { -@@ -2264,6 +2275,21 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate, +@@ -2264,6 +2275,23 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate, if (!completed_url.IsEmpty() || result.new_window) result.frame->Navigate(frame_request, WebFrameLoadType::kStandard); @@ -249,6 +441,8 @@ diff --git a/third_party/blink/renderer/core/frame/local_dom_window.cc b/third_p + // var w = window.open() + // var not_emulated_screen_info = w.screen + bool protection_enabled = base::FeatureList::IsEnabled(features::kViewportProtection); ++ protection_enabled |= GetFrame()->GetContentSettingsClient()->AllowContentSetting( ++ ContentSettingsType::VIEWPORT, false); + result.frame->GetPage()->CalculateEmulatedScreenSetting( + To(result.frame), + /*force*/ protection_enabled); @@ -257,7 +451,7 @@ diff --git a/third_party/blink/renderer/core/frame/local_dom_window.cc b/third_p // TODO(japhet): window-open-noopener.html?_top and several tests in // html/browsers/windows/browsing-context-names/ appear to require that // the special case target names (_top, _parent, _self) ignore opener -@@ -2320,6 +2346,15 @@ DOMWindow* LocalDOMWindow::openPictureInPictureWindow( +@@ -2320,6 +2348,15 @@ DOMWindow* LocalDOMWindow::openPictureInPictureWindow( DCHECK(result.new_window); result.frame->Navigate(frame_request, WebFrameLoadType::kStandard); @@ -306,6 +500,18 @@ diff --git a/third_party/blink/renderer/core/frame/local_frame.cc b/third_party/ return ratio; } +@@ -3075,6 +3083,11 @@ void LocalFrame::SetScaleFactor(float scale_factor) { + DCHECK(!GetDocument() || !GetDocument()->Printing()); + DCHECK(IsMainFrame()); + ++ if (scale_factor <= -999) { ++ GetPage()->DisableScreenEmulated(); ++ return; ++ } ++ + const PageScaleConstraints& constraints = + GetPage()->GetPageScaleConstraintsSet().FinalConstraints(); + scale_factor = constraints.ClampToConstraints(scale_factor); diff --git a/third_party/blink/renderer/core/frame/local_frame.h b/third_party/blink/renderer/core/frame/local_frame.h --- a/third_party/blink/renderer/core/frame/local_frame.h +++ b/third_party/blink/renderer/core/frame/local_frame.h @@ -512,9 +718,11 @@ diff --git a/third_party/blink/renderer/core/page/page.cc b/third_party/blink/re #include "third_party/blink/public/common/features.h" #include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink-forward.h" #include "third_party/blink/public/platform/platform.h" -@@ -92,6 +93,9 @@ +@@ -91,7 +92,11 @@ + #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h" #include "third_party/blink/renderer/platform/scheduler/public/agent_group_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h" ++#include "third_party/blink/renderer/platform/weborigin/scheme_registry.h" #include "third_party/skia/include/core/SkColor.h" +#include "base/rand_util.h" +#include "third_party/blink/public/common/widget/device_emulation_params.h" @@ -522,12 +730,20 @@ diff --git a/third_party/blink/renderer/core/page/page.cc b/third_party/blink/re namespace blink { -@@ -902,7 +906,79 @@ void Page::UpdateAcceleratedCompositingSettings() { +@@ -902,7 +907,94 @@ 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->AllowContentSetting( ++ ContentSettingsType::VIEWPORT, /*default_value*/ false)); ++ String protocol = ++ frame->GetSecurityContext()->GetSecurityOrigin()->Protocol(); ++ if (SchemeRegistry::IsWebUIScheme(protocol) || disable_screen_emulated_) { ++ isEnabled = false; ++ } + if (isEnabled || force) { + // this is the maximum (and minimum) value which in percentage + // corresponds to +- 0.03% @@ -587,15 +803,22 @@ diff --git a/third_party/blink/renderer/core/page/page.cc b/third_party/blink/re + + frame->SetPageZoomFactorBaseValue(zoom_factor); + } -+ is_screen_emulated = true; ++ is_screen_emulated_ = true; + } else { -+ if (is_screen_emulated && main_frame_ == frame) { ++ if (is_screen_emulated_ && main_frame_ == frame) { + GetChromeClient().GetWebView()->DisableDeviceEmulation(); + frame->SetPageZoomFactorBaseValue(0); + } -+ is_screen_emulated = false; ++ is_screen_emulated_ = false; + } +} ++ ++void Page::DisableScreenEmulated() { ++ disable_screen_emulated_ = true; ++ GetChromeClient().GetWebView()->DisableDeviceEmulation(); ++ DeprecatedLocalMainFrame()->SetPageZoomFactorBaseValue(0); ++ is_screen_emulated_ = false; ++} + void Page::DidCommitLoad(LocalFrame* frame) { + CalculateEmulatedScreenSetting(frame); @@ -605,21 +828,23 @@ diff --git a/third_party/blink/renderer/core/page/page.cc b/third_party/blink/re diff --git a/third_party/blink/renderer/core/page/page.h b/third_party/blink/renderer/core/page/page.h --- a/third_party/blink/renderer/core/page/page.h +++ b/third_party/blink/renderer/core/page/page.h -@@ -460,6 +460,9 @@ class CORE_EXPORT Page final : public GarbageCollected, +@@ -460,6 +460,10 @@ class CORE_EXPORT Page final : public GarbageCollected, return attribution_support_; } + void CalculateEmulatedScreenSetting(LocalFrame* frame, bool force = false); -+ bool IsScreenEmulated() { return is_screen_emulated; } ++ bool IsScreenEmulated() { return is_screen_emulated_; } ++ void DisableScreenEmulated(); + private: friend class ScopedPagePauser; -@@ -605,6 +608,10 @@ class CORE_EXPORT Page final : public GarbageCollected, +@@ -605,6 +609,11 @@ class CORE_EXPORT Page final : public GarbageCollected, // browser side FrameTree has the FrameTree::Type of kFencedFrame. bool is_fenced_frame_tree_ = false; -+ bool is_screen_emulated = false; ++ bool is_screen_emulated_ = false; ++ bool disable_screen_emulated_ = false; + double override_window_scale_factor_ = 0; + double override_zoom_factor_ = 0; +