summaryrefslogtreecommitdiffstats
path: root/src/core/web_engine_settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/web_engine_settings.cpp')
-rw-r--r--src/core/web_engine_settings.cpp184
1 files changed, 97 insertions, 87 deletions
diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp
index 93c822f2f..e302998f0 100644
--- a/src/core/web_engine_settings.cpp
+++ b/src/core/web_engine_settings.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "web_engine_settings.h"
@@ -45,15 +9,16 @@
#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
-#include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
-#include "content/public/common/web_preferences.h"
#include "media/base/media_switches.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
-#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
+#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
+#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "ui/base/ui_base_switches.h"
+#include "ui/base/pointer/pointer_device.h"
#include "ui/events/event_switches.h"
#include "ui/native_theme/native_theme.h"
@@ -91,10 +56,25 @@ static inline bool isTouchEventsAPIEnabled() {
return touchEventsAPIEnabled;
}
+blink::mojom::ImageAnimationPolicy
+toBlinkImageAnimationPolicy(QWebEngineSettings::ImageAnimationPolicy policy)
+{
+ switch (policy) {
+ case QWebEngineSettings::AllowImageAnimation:
+ return blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
+ case QWebEngineSettings::AnimateImageOnce:
+ return blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
+ case QWebEngineSettings::DisallowImageAnimation:
+ return blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
+ }
+ return blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
+}
+
WebEngineSettings::WebEngineSettings(WebEngineSettings *_parentSettings)
: m_adapter(nullptr)
, parentSettings(_parentSettings)
, m_unknownUrlSchemePolicy(QWebEngineSettings::InheritedUnknownUrlSchemePolicy)
+ , m_imageAnimationPolicy(QWebEngineSettings::InheritedImageAnimationPolicy)
{
if (parentSettings)
parentSettings->childSettings.insert(this);
@@ -112,12 +92,11 @@ WebEngineSettings::~WebEngineSettings()
if (parentSettings)
parentSettings->childSettings.remove(this);
// In QML the profile and its settings may be garbage collected before the page and its settings.
- for (WebEngineSettings *settings : qAsConst(childSettings)) {
- settings->parentSettings = 0;
- }
+ for (WebEngineSettings *settings : std::as_const(childSettings))
+ settings->parentSettings = nullptr;
}
-void WebEngineSettings::overrideWebPreferences(content::WebContents *webContents, content::WebPreferences *prefs)
+void WebEngineSettings::overrideWebPreferences(content::WebContents *webContents, blink::web_pref::WebPreferences *prefs)
{
// Apply our settings on top of those.
applySettingsToWebPreferences(prefs);
@@ -125,7 +104,7 @@ void WebEngineSettings::overrideWebPreferences(content::WebContents *webContents
// as the host process already overides some of the default WebPreferences values
// before we get here (e.g. number_of_cpu_cores).
if (webPreferences.isNull())
- webPreferences.reset(new content::WebPreferences(*prefs));
+ webPreferences.reset(new blink::web_pref::WebPreferences(*prefs));
if (webContents
&& applySettingsToRendererPreferences(webContents->GetMutableRendererPrefs())) {
@@ -141,11 +120,15 @@ void WebEngineSettings::setAttribute(QWebEngineSettings::WebAttribute attr, bool
bool WebEngineSettings::testAttribute(QWebEngineSettings::WebAttribute attr) const
{
- if (!parentSettings) {
- Q_ASSERT(s_defaultAttributes.contains(attr));
- return m_attributes.value(attr, s_defaultAttributes.value(attr));
- }
- return m_attributes.value(attr, parentSettings->testAttribute(attr));
+ auto it = m_attributes.constFind(attr);
+ if (it != m_attributes.constEnd())
+ return *it;
+
+ if (parentSettings)
+ return parentSettings->testAttribute(attr);
+
+ Q_ASSERT(s_defaultAttributes.contains(attr));
+ return s_defaultAttributes.value(attr);
}
bool WebEngineSettings::isAttributeExplicitlySet(QWebEngineSettings::WebAttribute attr) const
@@ -223,6 +206,24 @@ QString WebEngineSettings::defaultTextEncoding() const
void WebEngineSettings::setUnknownUrlSchemePolicy(QWebEngineSettings::UnknownUrlSchemePolicy policy)
{
m_unknownUrlSchemePolicy = policy;
+ scheduleApplyRecursively();
+}
+
+void WebEngineSettings::setImageAnimationPolicy(QWebEngineSettings::ImageAnimationPolicy policy)
+{
+ m_imageAnimationPolicy = policy;
+ scheduleApplyRecursively();
+}
+
+QWebEngineSettings::ImageAnimationPolicy WebEngineSettings::imageAnimationPolicy() const
+{
+ if (m_imageAnimationPolicy != QWebEngineSettings::InheritedImageAnimationPolicy)
+ return m_imageAnimationPolicy;
+
+ if (parentSettings)
+ return parentSettings->imageAnimationPolicy();
+
+ return QWebEngineSettings::AllowImageAnimation;
}
QWebEngineSettings::UnknownUrlSchemePolicy WebEngineSettings::unknownUrlSchemePolicy() const
@@ -287,11 +288,17 @@ void WebEngineSettings::initDefaults()
s_defaultAttributes.insert(QWebEngineSettings::WebRTCPublicInterfacesOnly, false);
s_defaultAttributes.insert(QWebEngineSettings::JavascriptCanPaste, false);
s_defaultAttributes.insert(QWebEngineSettings::DnsPrefetchEnabled, false);
-#if QT_CONFIG(webengine_extensions)
+#if QT_CONFIG(webengine_extensions) && QT_CONFIG(webengine_printing_and_pdf)
s_defaultAttributes.insert(QWebEngineSettings::PdfViewerEnabled, true);
#else
s_defaultAttributes.insert(QWebEngineSettings::PdfViewerEnabled, false);
#endif
+ s_defaultAttributes.insert(QWebEngineSettings::NavigateOnDropEnabled, true);
+ bool noReadingFromCanvas =
+ commandLine->HasSwitch(switches::kDisableReadingFromCanvas);
+ s_defaultAttributes.insert(QWebEngineSettings::ReadingFromCanvasEnabled, !noReadingFromCanvas);
+ bool forceDarkMode = commandLine->HasSwitch(switches::kForceDarkMode);
+ s_defaultAttributes.insert(QWebEngineSettings::ForceDarkMode, forceDarkMode);
}
if (s_defaultFontFamilies.isEmpty()) {
@@ -326,6 +333,7 @@ void WebEngineSettings::initDefaults()
m_defaultEncoding = QStringLiteral("ISO-8859-1");
m_unknownUrlSchemePolicy = QWebEngineSettings::InheritedUnknownUrlSchemePolicy;
+ m_imageAnimationPolicy = QWebEngineSettings::InheritedImageAnimationPolicy;
}
void WebEngineSettings::scheduleApply()
@@ -349,19 +357,23 @@ void WebEngineSettings::doApply()
m_adapter->webContents()->SyncRendererPrefs();
}
-void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *prefs)
+void WebEngineSettings::applySettingsToWebPreferences(blink::web_pref::WebPreferences *prefs)
{
+ // Not supported
+ prefs->picture_in_picture_enabled = false;
+
// Override for now
prefs->touch_event_feature_detection_enabled = isTouchEventsAPIEnabled();
#if !QT_CONFIG(webengine_embedded_build)
- prefs->available_hover_types = ui::HOVER_TYPE_HOVER;
- prefs->primary_hover_type = ui::HOVER_TYPE_HOVER;
+ prefs->available_hover_types = (int)blink::mojom::HoverType::kHoverHoverType;
+ prefs->primary_hover_type = blink::mojom::HoverType::kHoverHoverType;
#endif
if (prefs->viewport_enabled) {
// We need to enable the viewport options together as it doesn't really work
// to enable them separately. With viewport-enabled we match Android defaults.
prefs->viewport_meta_enabled = true;
prefs->shrinks_viewport_contents_to_fit = true;
+ prefs->main_frame_resizes_are_orientation_changes = true;
}
// Attributes mapping.
@@ -372,7 +384,7 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p
prefs->tabs_to_links = testAttribute(QWebEngineSettings::LinksIncludedInFocusChain);
prefs->local_storage_enabled = testAttribute(QWebEngineSettings::LocalStorageEnabled);
prefs->databases_enabled = testAttribute(QWebEngineSettings::LocalStorageEnabled);
- prefs->allow_universal_access_from_file_urls =
+ prefs->allow_remote_access_from_local_urls =
testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls);
prefs->spatial_navigation_enabled = testAttribute(QWebEngineSettings::SpatialNavigationEnabled);
prefs->allow_file_access_from_file_urls =
@@ -384,6 +396,7 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p
prefs->fullscreen_supported = testAttribute(QWebEngineSettings::FullScreenSupportEnabled);
prefs->accelerated_2d_canvas_enabled =
testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled);
+ prefs->force_dark_mode_enabled = testAttribute(QWebEngineSettings::ForceDarkMode);
prefs->webgl1_enabled = prefs->webgl2_enabled = testAttribute(QWebEngineSettings::WebGLEnabled);
prefs->should_print_backgrounds = testAttribute(QWebEngineSettings::PrintElementBackgrounds);
prefs->allow_running_insecure_content =
@@ -393,27 +406,27 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p
prefs->hide_scrollbars = !testAttribute(QWebEngineSettings::ShowScrollBars);
if (isAttributeExplicitlySet(QWebEngineSettings::PlaybackRequiresUserGesture)) {
prefs->autoplay_policy = testAttribute(QWebEngineSettings::PlaybackRequiresUserGesture)
- ? content::AutoplayPolicy::kUserGestureRequired
- : content::AutoplayPolicy::kNoUserGestureRequired;
+ ? blink::mojom::AutoplayPolicy::kUserGestureRequired
+ : blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
}
prefs->dom_paste_enabled = testAttribute(QWebEngineSettings::JavascriptCanPaste);
prefs->dns_prefetching_enabled = testAttribute(QWebEngineSettings::DnsPrefetchEnabled);
+ prefs->disable_reading_from_canvas = !testAttribute(QWebEngineSettings::ReadingFromCanvasEnabled);
+ prefs->animation_policy = toBlinkImageAnimationPolicy(imageAnimationPolicy());
// Fonts settings.
- prefs->standard_font_family_map[content::kCommonScript] =
+ prefs->standard_font_family_map[blink::web_pref::kCommonScript] =
toString16(fontFamily(QWebEngineSettings::StandardFont));
- prefs->fixed_font_family_map[content::kCommonScript] =
+ prefs->fixed_font_family_map[blink::web_pref::kCommonScript] =
toString16(fontFamily(QWebEngineSettings::FixedFont));
- prefs->serif_font_family_map[content::kCommonScript] =
+ prefs->serif_font_family_map[blink::web_pref::kCommonScript] =
toString16(fontFamily(QWebEngineSettings::SerifFont));
- prefs->sans_serif_font_family_map[content::kCommonScript] =
+ prefs->sans_serif_font_family_map[blink::web_pref::kCommonScript] =
toString16(fontFamily(QWebEngineSettings::SansSerifFont));
- prefs->cursive_font_family_map[content::kCommonScript] =
+ prefs->cursive_font_family_map[blink::web_pref::kCommonScript] =
toString16(fontFamily(QWebEngineSettings::CursiveFont));
- prefs->fantasy_font_family_map[content::kCommonScript] =
+ prefs->fantasy_font_family_map[blink::web_pref::kCommonScript] =
toString16(fontFamily(QWebEngineSettings::FantasyFont));
- prefs->pictograph_font_family_map[content::kCommonScript] =
- toString16(fontFamily(QWebEngineSettings::PictographFont));
prefs->default_font_size = fontSize(QWebEngineSettings::DefaultFontSize);
prefs->default_fixed_font_size = fontSize(QWebEngineSettings::DefaultFixedFontSize);
prefs->minimum_font_size = fontSize(QWebEngineSettings::MinimumFontSize);
@@ -422,26 +435,19 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p
// Set the theme colors. Based on chrome_content_browser_client.cc:
const ui::NativeTheme *webTheme = ui::NativeTheme::GetInstanceForWeb();
- // WebPreferences::preferred_color_scheme was deleted in Chromium 80, but it
- // will make a comeback in Chromium 82...
- //
- // See also: https://chromium-review.googlesource.com/c/chromium/src/+/2079192
- //
- // if (webTheme) {
- // switch (webTheme->GetPreferredColorScheme()) {
- // case ui::NativeTheme::PreferredColorScheme::kDark:
- // prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
- // break;
- // case ui::NativeTheme::PreferredColorScheme::kLight:
- // prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
- // break;
- // case ui::NativeTheme::PreferredColorScheme::kNoPreference:
- // prefs->preferred_color_scheme = blink::PreferredColorScheme::kNoPreference;
- // }
- // }
+ if (webTheme) {
+ switch (webTheme->GetPreferredColorScheme()) {
+ case ui::NativeTheme::PreferredColorScheme::kDark:
+ prefs->preferred_color_scheme = blink::mojom::PreferredColorScheme::kDark;
+ break;
+ case ui::NativeTheme::PreferredColorScheme::kLight:
+ prefs->preferred_color_scheme = blink::mojom::PreferredColorScheme::kLight;
+ break;
+ }
+ }
// Apply native CaptionStyle parameters.
- base::Optional<ui::CaptionStyle> style;
+ absl::optional<ui::CaptionStyle> style;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceCaptionStyle)) {
style = ui::CaptionStyle::FromSpec(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kForceCaptionStyle));
@@ -459,12 +465,11 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p
prefs->text_track_font_family = style->font_family;
prefs->text_track_font_variant = style->font_variant;
prefs->text_track_window_color = style->window_color;
- prefs->text_track_window_padding = style->window_padding;
prefs->text_track_window_radius = style->window_radius;
}
}
-bool WebEngineSettings::applySettingsToRendererPreferences(blink::mojom::RendererPreferences *prefs)
+bool WebEngineSettings::applySettingsToRendererPreferences(blink::RendererPreferences *prefs)
{
bool changed = false;
#if QT_CONFIG(webengine_webrtc)
@@ -479,13 +484,18 @@ bool WebEngineSettings::applySettingsToRendererPreferences(blink::mojom::Rendere
}
}
#endif
+ bool canNavigateOnDrop = testAttribute(QWebEngineSettings::NavigateOnDropEnabled);
+ if (canNavigateOnDrop != prefs->can_accept_load_drops) {
+ prefs->can_accept_load_drops = canNavigateOnDrop;
+ changed = true;
+ }
return changed;
}
void WebEngineSettings::scheduleApplyRecursively()
{
scheduleApply();
- for (WebEngineSettings *settings : qAsConst(childSettings)) {
+ for (WebEngineSettings *settings : std::as_const(childSettings)) {
settings->scheduleApply();
}
}