2015-10-17 02:44:00 +02:00
|
|
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/prefs/renderer_prefs.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "libcef/browser/context.h"
|
|
|
|
#include "libcef/browser/extensions/browser_extensions_util.h"
|
|
|
|
#include "libcef/common/cef_switches.h"
|
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "libcef/features/runtime_checks.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2017-01-23 18:36:54 +01:00
|
|
|
#include "base/i18n/character_encoding.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "base/values.h"
|
|
|
|
#include "chrome/browser/accessibility/animation_policy_prefs.h"
|
|
|
|
#include "chrome/browser/defaults.h"
|
|
|
|
#include "chrome/browser/extensions/extension_webkit_preferences.h"
|
|
|
|
#include "chrome/browser/font_family_cache.h"
|
2020-07-01 02:57:00 +02:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
2020-09-15 18:34:22 +02:00
|
|
|
#include "chrome/common/chrome_features.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
|
|
|
#include "chrome/common/pref_names.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "components/pref_registry/pref_registry_syncable.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "components/prefs/command_line_pref_store.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/pref_service.h"
|
|
|
|
#include "components/prefs/pref_store.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "content/public/browser/site_instance.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2020-09-15 18:34:22 +02:00
|
|
|
#include "content/public/common/url_constants.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "extensions/browser/extension_registry.h"
|
|
|
|
#include "extensions/browser/view_type_utils.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "media/media_buildflags.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
|
2023-07-21 00:11:34 +02:00
|
|
|
#include "ui/color/color_provider_key.h"
|
2020-09-15 18:34:22 +02:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
namespace renderer_prefs {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Chrome preferences.
|
|
|
|
// Should match ChromeContentBrowserClient::OverrideWebkitPrefs.
|
2020-10-08 21:54:42 +02:00
|
|
|
void SetChromePrefs(Profile* profile, blink::web_pref::WebPreferences& web) {
|
2015-10-17 02:44:00 +02:00
|
|
|
PrefService* prefs = profile->GetPrefs();
|
|
|
|
|
|
|
|
// Fill per-script font preferences.
|
|
|
|
FontFamilyCache::FillFontFamilyMap(profile,
|
|
|
|
prefs::kWebKitStandardFontFamilyMap,
|
|
|
|
&web.standard_font_family_map);
|
2017-05-17 11:29:28 +02:00
|
|
|
FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
|
2015-10-17 02:44:00 +02:00
|
|
|
&web.fixed_font_family_map);
|
2017-05-17 11:29:28 +02:00
|
|
|
FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
|
2015-10-17 02:44:00 +02:00
|
|
|
&web.serif_font_family_map);
|
|
|
|
FontFamilyCache::FillFontFamilyMap(profile,
|
|
|
|
prefs::kWebKitSansSerifFontFamilyMap,
|
|
|
|
&web.sans_serif_font_family_map);
|
|
|
|
FontFamilyCache::FillFontFamilyMap(profile,
|
|
|
|
prefs::kWebKitCursiveFontFamilyMap,
|
|
|
|
&web.cursive_font_family_map);
|
|
|
|
FontFamilyCache::FillFontFamilyMap(profile,
|
|
|
|
prefs::kWebKitFantasyFontFamilyMap,
|
|
|
|
&web.fantasy_font_family_map);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
web.default_font_size = prefs->GetInteger(prefs::kWebKitDefaultFontSize);
|
2015-10-17 02:44:00 +02:00
|
|
|
web.default_fixed_font_size =
|
|
|
|
prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
|
2017-05-17 11:29:28 +02:00
|
|
|
web.minimum_font_size = prefs->GetInteger(prefs::kWebKitMinimumFontSize);
|
2015-10-17 02:44:00 +02:00
|
|
|
web.minimum_logical_font_size =
|
|
|
|
prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
|
|
|
|
|
|
|
|
web.default_encoding = prefs->GetString(prefs::kDefaultCharset);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
web.dom_paste_enabled = prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
|
2015-10-17 02:44:00 +02:00
|
|
|
web.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
web.javascript_enabled = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
web.web_security_enabled = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
web.plugins_enabled = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
web.loads_images_automatically =
|
|
|
|
prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
|
|
|
|
web.webgl1_enabled = false;
|
|
|
|
web.webgl2_enabled = false;
|
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
web.allow_running_insecure_content =
|
|
|
|
prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
|
|
|
|
|
2023-09-15 21:51:43 +02:00
|
|
|
web.password_echo_enabled = false;
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
web.text_areas_are_resizable =
|
|
|
|
prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
|
|
|
|
web.hyperlink_auditing_enabled =
|
|
|
|
prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
|
|
|
|
|
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
std::string image_animation_policy =
|
|
|
|
prefs->GetString(prefs::kAnimationPolicy);
|
2020-12-02 23:31:49 +01:00
|
|
|
if (image_animation_policy == kAnimationPolicyOnce) {
|
|
|
|
web.animation_policy =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
|
|
|
|
} else if (image_animation_policy == kAnimationPolicyNone) {
|
|
|
|
web.animation_policy =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
|
|
|
|
} else {
|
|
|
|
web.animation_policy =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
|
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we will set the default_encoding with canonical encoding name.
|
2017-05-17 11:29:28 +02:00
|
|
|
web.default_encoding =
|
|
|
|
base::GetCanonicalEncodingNameByAliasName(web.default_encoding);
|
2015-10-17 02:44:00 +02:00
|
|
|
if (web.default_encoding.empty()) {
|
|
|
|
prefs->ClearPref(prefs::kDefaultCharset);
|
|
|
|
web.default_encoding = prefs->GetString(prefs::kDefaultCharset);
|
|
|
|
}
|
|
|
|
DCHECK(!web.default_encoding.empty());
|
|
|
|
|
|
|
|
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
|
switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
|
|
|
|
web.disable_reading_from_canvas = true;
|
|
|
|
web.strict_mixed_content_checking = true;
|
|
|
|
web.strict_powerful_feature_restrictions = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extension preferences.
|
|
|
|
// Should match ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs.
|
2021-09-20 11:06:23 +02:00
|
|
|
void SetExtensionPrefs(content::WebContents* web_contents,
|
|
|
|
content::RenderViewHost* rvh,
|
2020-10-08 21:54:42 +02:00
|
|
|
blink::web_pref::WebPreferences& web) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!extensions::ExtensionsEnabled()) {
|
2015-10-17 02:44:00 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
const extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(
|
|
|
|
rvh->GetProcess()->GetBrowserContext());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!registry) {
|
2015-10-17 02:44:00 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
// Note: it's not possible for kExtensionsScheme to change during the lifetime
|
|
|
|
// of the process.
|
|
|
|
//
|
|
|
|
// Ensure that we are only granting extension preferences to URLs with the
|
|
|
|
// correct scheme. Without this check, chrome-guest:// schemes used by webview
|
|
|
|
// tags as well as hosts that happen to match the id of an installed extension
|
|
|
|
// would get the wrong preferences.
|
2021-09-20 11:06:23 +02:00
|
|
|
const GURL& site_url =
|
2022-07-21 19:26:10 +02:00
|
|
|
web_contents->GetPrimaryMainFrame()->GetSiteInstance()->GetSiteURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!site_url.SchemeIs(extensions::kExtensionScheme)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
registry->enabled_extensions().GetByID(site_url.host());
|
2021-04-21 00:52:34 +02:00
|
|
|
extension_webkit_preferences::SetPreferences(extension, &web);
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetString(CommandLinePrefStore* prefs,
|
|
|
|
const std::string& key,
|
|
|
|
const std::string& value) {
|
2022-10-17 19:27:40 +02:00
|
|
|
prefs->SetValue(key, base::Value(value),
|
2017-05-17 11:29:28 +02:00
|
|
|
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void SetBool(CommandLinePrefStore* prefs, const std::string& key, bool value) {
|
2022-10-17 19:27:40 +02:00
|
|
|
prefs->SetValue(key, base::Value(value),
|
2017-05-17 11:29:28 +02:00
|
|
|
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:31:49 +01:00
|
|
|
blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme(
|
|
|
|
ui::NativeTheme::PreferredColorScheme native_theme_scheme) {
|
|
|
|
switch (native_theme_scheme) {
|
|
|
|
case ui::NativeTheme::PreferredColorScheme::kDark:
|
|
|
|
return blink::mojom::PreferredColorScheme::kDark;
|
|
|
|
case ui::NativeTheme::PreferredColorScheme::kLight:
|
|
|
|
return blink::mojom::PreferredColorScheme::kLight;
|
|
|
|
}
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2020-12-02 23:31:49 +01:00
|
|
|
}
|
|
|
|
|
2020-09-15 18:34:22 +02:00
|
|
|
// From chrome/browser/chrome_content_browser_client.cc
|
2020-12-02 23:31:49 +01:00
|
|
|
// Returns true if preferred color scheme is modified based on at least one of
|
|
|
|
// the following -
|
|
|
|
// |url| - Last committed url.
|
|
|
|
// |native_theme| - For other platforms based on native theme scheme.
|
|
|
|
bool UpdatePreferredColorScheme(blink::web_pref::WebPreferences* web_prefs,
|
|
|
|
const GURL& url,
|
2023-06-26 12:13:38 +02:00
|
|
|
content::WebContents* web_contents,
|
2020-12-02 23:31:49 +01:00
|
|
|
const ui::NativeTheme* native_theme) {
|
|
|
|
auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
|
|
|
|
|
|
|
|
// Update based on native theme scheme.
|
|
|
|
web_prefs->preferred_color_scheme =
|
|
|
|
ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
|
|
|
|
|
2023-06-26 12:13:38 +02:00
|
|
|
if (url.SchemeIs(content::kChromeUIScheme)) {
|
|
|
|
// WebUI should track the color mode of the ColorProvider associated with
|
|
|
|
// |web_contents|.
|
|
|
|
web_prefs->preferred_color_scheme =
|
2023-07-21 00:11:34 +02:00
|
|
|
web_contents->GetColorMode() == ui::ColorProviderKey::ColorMode::kLight
|
2023-06-26 12:13:38 +02:00
|
|
|
? blink::mojom::PreferredColorScheme::kLight
|
|
|
|
: blink::mojom::PreferredColorScheme::kDark;
|
2020-09-15 18:34:22 +02:00
|
|
|
}
|
2020-12-02 23:31:49 +01:00
|
|
|
|
2020-09-15 18:34:22 +02:00
|
|
|
return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
|
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs) {
|
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
if (command_line->HasSwitch(switches::kDefaultEncoding)) {
|
|
|
|
SetString(prefs, prefs::kDefaultCharset,
|
|
|
|
command_line->GetSwitchValueASCII(switches::kDefaultEncoding));
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (command_line->HasSwitch(switches::kDisableJavascriptDomPaste)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
SetBool(prefs, prefs::kWebKitDomPasteEnabled, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (command_line->HasSwitch(switches::kDisableImageLoading)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
SetBool(prefs, prefs::kWebKitLoadsImagesAutomatically, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (command_line->HasSwitch(switches::kDisableTabToLinks)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
SetBool(prefs, prefs::kWebkitTabsToLinks, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 03:12:54 +02:00
|
|
|
void SetDefaultPrefs(blink::web_pref::WebPreferences& web) {
|
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
web.javascript_enabled =
|
|
|
|
!command_line->HasSwitch(switches::kDisableJavascript);
|
|
|
|
web.allow_scripts_to_close_windows =
|
|
|
|
!command_line->HasSwitch(switches::kDisableJavascriptCloseWindows);
|
|
|
|
web.javascript_can_access_clipboard =
|
|
|
|
!command_line->HasSwitch(switches::kDisableJavascriptAccessClipboard);
|
|
|
|
web.allow_universal_access_from_file_urls =
|
|
|
|
command_line->HasSwitch(switches::kAllowUniversalAccessFromFileUrls);
|
|
|
|
web.shrinks_standalone_images_to_fit =
|
|
|
|
command_line->HasSwitch(switches::kImageShrinkStandaloneToFit);
|
|
|
|
web.text_areas_are_resizable =
|
|
|
|
!command_line->HasSwitch(switches::kDisableTextAreaResize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper macro for setting a WebPreferences variable based on the value of a
|
|
|
|
// CefBrowserSettings variable.
|
|
|
|
#define SET_STATE(cef_var, web_var) \
|
|
|
|
if (cef_var == STATE_ENABLED) \
|
|
|
|
web_var = true; \
|
|
|
|
else if (cef_var == STATE_DISABLED) \
|
|
|
|
web_var = false;
|
|
|
|
|
|
|
|
void SetCefPrefs(const CefBrowserSettings& cef,
|
|
|
|
blink::web_pref::WebPreferences& web) {
|
|
|
|
if (cef.standard_font_family.length > 0) {
|
|
|
|
web.standard_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
CefString(&cef.standard_font_family);
|
|
|
|
}
|
|
|
|
if (cef.fixed_font_family.length > 0) {
|
|
|
|
web.fixed_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
CefString(&cef.fixed_font_family);
|
|
|
|
}
|
|
|
|
if (cef.serif_font_family.length > 0) {
|
|
|
|
web.serif_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
CefString(&cef.serif_font_family);
|
|
|
|
}
|
|
|
|
if (cef.sans_serif_font_family.length > 0) {
|
|
|
|
web.sans_serif_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
CefString(&cef.sans_serif_font_family);
|
|
|
|
}
|
|
|
|
if (cef.cursive_font_family.length > 0) {
|
|
|
|
web.cursive_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
CefString(&cef.cursive_font_family);
|
|
|
|
}
|
|
|
|
if (cef.fantasy_font_family.length > 0) {
|
|
|
|
web.fantasy_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
CefString(&cef.fantasy_font_family);
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cef.default_font_size > 0) {
|
2021-04-18 03:12:54 +02:00
|
|
|
web.default_font_size = cef.default_font_size;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef.default_fixed_font_size > 0) {
|
2021-04-18 03:12:54 +02:00
|
|
|
web.default_fixed_font_size = cef.default_fixed_font_size;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef.minimum_font_size > 0) {
|
2021-04-18 03:12:54 +02:00
|
|
|
web.minimum_font_size = cef.minimum_font_size;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef.minimum_logical_font_size > 0) {
|
2021-04-18 03:12:54 +02:00
|
|
|
web.minimum_logical_font_size = cef.minimum_logical_font_size;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-18 03:12:54 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cef.default_encoding.length > 0) {
|
2021-04-18 03:12:54 +02:00
|
|
|
web.default_encoding = CefString(&cef.default_encoding);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-18 03:12:54 +02:00
|
|
|
|
|
|
|
SET_STATE(cef.remote_fonts, web.remote_fonts_enabled);
|
|
|
|
SET_STATE(cef.javascript, web.javascript_enabled);
|
|
|
|
SET_STATE(cef.javascript_close_windows, web.allow_scripts_to_close_windows);
|
|
|
|
SET_STATE(cef.javascript_access_clipboard,
|
|
|
|
web.javascript_can_access_clipboard);
|
|
|
|
SET_STATE(cef.javascript_dom_paste, web.dom_paste_enabled);
|
|
|
|
SET_STATE(cef.image_loading, web.loads_images_automatically);
|
|
|
|
SET_STATE(cef.image_shrink_standalone_to_fit,
|
|
|
|
web.shrinks_standalone_images_to_fit);
|
|
|
|
SET_STATE(cef.text_area_resize, web.text_areas_are_resizable);
|
|
|
|
SET_STATE(cef.tab_to_links, web.tabs_to_links);
|
|
|
|
SET_STATE(cef.local_storage, web.local_storage_enabled);
|
|
|
|
SET_STATE(cef.databases, web.databases_enabled);
|
|
|
|
|
|
|
|
// Never explicitly enable GPU-related functions in this method because the
|
|
|
|
// GPU blacklist is not being checked here.
|
|
|
|
if (cef.webgl == STATE_DISABLED) {
|
|
|
|
web.webgl1_enabled = false;
|
|
|
|
web.webgl2_enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
|
|
|
|
const std::string& locale) {
|
|
|
|
PrefsTabHelper::RegisterProfilePrefs(registry, locale);
|
2015-10-17 02:44:00 +02:00
|
|
|
RegisterAnimationPolicyPrefs(registry);
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
// From chrome/browser/ui/browser_ui_prefs.cc RegisterBrowserUserPrefs.
|
|
|
|
registry->RegisterBooleanPref(prefs::kCaretBrowsingEnabled, false);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
registry->RegisterStringPref(prefs::kWebRTCIPHandlingPolicy,
|
2019-11-12 17:11:44 +01:00
|
|
|
blink::kWebRTCIPHandlingDefault);
|
2016-08-31 13:25:56 +02:00
|
|
|
registry->RegisterStringPref(prefs::kWebRTCUDPPortRange, std::string());
|
2015-12-09 17:10:16 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2015-10-17 02:44:00 +02:00
|
|
|
registry->RegisterBooleanPref(prefs::kFullscreenAllowed, true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// From ChromeContentBrowserClient::RegisterProfilePrefs.
|
|
|
|
registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
|
|
|
|
registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
|
|
|
|
|
|
|
|
// From Profile::RegisterProfilePrefs.
|
|
|
|
registry->RegisterDictionaryPref(prefs::kPartitionDefaultZoomLevel);
|
|
|
|
registry->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopulateWebPreferences(content::RenderViewHost* rvh,
|
2021-07-23 18:40:13 +02:00
|
|
|
blink::web_pref::WebPreferences& web,
|
|
|
|
SkColor& base_background_color) {
|
2020-09-18 00:24:08 +02:00
|
|
|
REQUIRE_ALLOY_RUNTIME();
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser = static_cast<AlloyBrowserHostImpl*>(
|
2020-09-18 00:24:08 +02:00
|
|
|
extensions::GetOwnerBrowserForHost(rvh, nullptr).get());
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
// Set defaults for preferences that are not handled by PrefService.
|
|
|
|
SetDefaultPrefs(web);
|
|
|
|
|
|
|
|
// Set preferences based on the context's PrefService.
|
2017-04-20 21:28:17 +02:00
|
|
|
if (browser) {
|
2020-07-01 02:57:00 +02:00
|
|
|
auto profile = Profile::FromBrowserContext(
|
2017-05-17 11:29:28 +02:00
|
|
|
browser->web_contents()->GetBrowserContext());
|
2015-10-17 02:44:00 +02:00
|
|
|
SetChromePrefs(profile, web);
|
|
|
|
}
|
|
|
|
|
2020-09-15 18:34:22 +02:00
|
|
|
auto* native_theme = ui::NativeTheme::GetInstanceForWeb();
|
|
|
|
switch (native_theme->GetPreferredColorScheme()) {
|
|
|
|
case ui::NativeTheme::PreferredColorScheme::kDark:
|
2020-12-02 23:31:49 +01:00
|
|
|
web.preferred_color_scheme = blink::mojom::PreferredColorScheme::kDark;
|
2020-09-15 18:34:22 +02:00
|
|
|
break;
|
|
|
|
case ui::NativeTheme::PreferredColorScheme::kLight:
|
2020-12-02 23:31:49 +01:00
|
|
|
web.preferred_color_scheme = blink::mojom::PreferredColorScheme::kLight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (native_theme->GetPreferredContrast()) {
|
|
|
|
case ui::NativeTheme::PreferredContrast::kNoPreference:
|
|
|
|
web.preferred_contrast = blink::mojom::PreferredContrast::kNoPreference;
|
|
|
|
break;
|
|
|
|
case ui::NativeTheme::PreferredContrast::kMore:
|
|
|
|
web.preferred_contrast = blink::mojom::PreferredContrast::kMore;
|
|
|
|
break;
|
|
|
|
case ui::NativeTheme::PreferredContrast::kLess:
|
|
|
|
web.preferred_contrast = blink::mojom::PreferredContrast::kLess;
|
2020-09-15 18:34:22 +02:00
|
|
|
break;
|
2021-08-20 01:40:49 +02:00
|
|
|
case ui::NativeTheme::PreferredContrast::kCustom:
|
|
|
|
web.preferred_contrast = blink::mojom::PreferredContrast::kCustom;
|
|
|
|
break;
|
2020-09-15 18:34:22 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 11:06:23 +02:00
|
|
|
auto web_contents = content::WebContents::FromRenderViewHost(rvh);
|
2021-03-04 23:36:57 +01:00
|
|
|
UpdatePreferredColorScheme(
|
2022-07-21 19:26:10 +02:00
|
|
|
&web,
|
|
|
|
web_contents->GetPrimaryMainFrame()->GetSiteInstance()->GetSiteURL(),
|
2023-06-26 12:13:38 +02:00
|
|
|
web_contents, native_theme);
|
2020-09-15 18:34:22 +02:00
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Set preferences based on the extension.
|
2021-09-20 11:06:23 +02:00
|
|
|
SetExtensionPrefs(web_contents, rvh, web);
|
2015-10-17 02:44:00 +02:00
|
|
|
|
2019-10-15 13:11:59 +02:00
|
|
|
if (browser) {
|
|
|
|
// Set preferences based on CefBrowserSettings.
|
2015-10-17 02:44:00 +02:00
|
|
|
SetCefPrefs(browser->settings(), web);
|
|
|
|
|
2019-10-15 13:11:59 +02:00
|
|
|
web.picture_in_picture_enabled = browser->IsPictureInPictureSupported();
|
|
|
|
|
|
|
|
// Set the background color for the WebView.
|
2021-07-23 18:40:13 +02:00
|
|
|
base_background_color = browser->GetBackgroundColor();
|
2017-04-20 21:28:17 +02:00
|
|
|
} else {
|
|
|
|
// We don't know for sure that the browser will be windowless but assume
|
|
|
|
// that the global windowless state is likely to be accurate.
|
2021-07-23 18:40:13 +02:00
|
|
|
base_background_color =
|
2017-04-20 21:28:17 +02:00
|
|
|
CefContext::Get()->GetBackgroundColor(nullptr, STATE_DEFAULT);
|
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
bool PopulateWebPreferencesAfterNavigation(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
blink::web_pref::WebPreferences& web) {
|
2020-12-02 23:31:49 +01:00
|
|
|
auto* native_theme = ui::NativeTheme::GetInstanceForWeb();
|
|
|
|
return UpdatePreferredColorScheme(&web, web_contents->GetLastCommittedURL(),
|
2023-06-26 12:13:38 +02:00
|
|
|
web_contents, native_theme);
|
2020-09-15 18:34:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
} // namespace renderer_prefs
|