diff options
Diffstat (limited to 'src/core/web_engine_settings.cpp')
-rw-r--r-- | src/core/web_engine_settings.cpp | 98 |
1 files changed, 55 insertions, 43 deletions
diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp index 1a0461897..e302998f0 100644 --- a/src/core/web_engine_settings.cpp +++ b/src/core/web_engine_settings.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2022 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,7 +9,6 @@ #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" @@ -93,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); @@ -114,7 +92,7 @@ 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)) + for (WebEngineSettings *settings : std::as_const(childSettings)) settings->parentSettings = nullptr; } @@ -228,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 @@ -298,6 +294,11 @@ void WebEngineSettings::initDefaults() 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()) { @@ -332,6 +333,7 @@ void WebEngineSettings::initDefaults() m_defaultEncoding = QStringLiteral("ISO-8859-1"); m_unknownUrlSchemePolicy = QWebEngineSettings::InheritedUnknownUrlSchemePolicy; + m_imageAnimationPolicy = QWebEngineSettings::InheritedImageAnimationPolicy; } void WebEngineSettings::scheduleApply() @@ -357,6 +359,9 @@ void WebEngineSettings::doApply() 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) @@ -368,6 +373,7 @@ void WebEngineSettings::applySettingsToWebPreferences(blink::web_pref::WebPrefer // 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. @@ -390,6 +396,7 @@ void WebEngineSettings::applySettingsToWebPreferences(blink::web_pref::WebPrefer 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 = @@ -404,7 +411,8 @@ void WebEngineSettings::applySettingsToWebPreferences(blink::web_pref::WebPrefer } prefs->dom_paste_enabled = testAttribute(QWebEngineSettings::JavascriptCanPaste); prefs->dns_prefetching_enabled = testAttribute(QWebEngineSettings::DnsPrefetchEnabled); - prefs->navigate_on_drag_drop = testAttribute(QWebEngineSettings::NavigateOnDropEnabled); + prefs->disable_reading_from_canvas = !testAttribute(QWebEngineSettings::ReadingFromCanvasEnabled); + prefs->animation_policy = toBlinkImageAnimationPolicy(imageAnimationPolicy()); // Fonts settings. prefs->standard_font_family_map[blink::web_pref::kCommonScript] = @@ -457,7 +465,6 @@ void WebEngineSettings::applySettingsToWebPreferences(blink::web_pref::WebPrefer 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; } } @@ -477,13 +484,18 @@ bool WebEngineSettings::applySettingsToRendererPreferences(blink::RendererPrefer } } #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(); } } |