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"
|
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);
|
|
|
|
FontFamilyCache::FillFontFamilyMap(profile,
|
|
|
|
prefs::kWebKitPictographFontFamilyMap,
|
|
|
|
&web.pictograph_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);
|
|
|
|
|
|
|
|
if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
|
|
|
|
web.javascript_enabled = false;
|
|
|
|
if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
|
|
|
|
web.web_security_enabled = false;
|
|
|
|
if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
|
|
|
|
web.plugins_enabled = false;
|
|
|
|
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);
|
|
|
|
|
|
|
|
web.password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
|
|
|
|
|
|
|
|
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.
|
|
|
|
void SetExtensionPrefs(content::RenderViewHost* rvh,
|
2020-10-08 21:54:42 +02:00
|
|
|
blink::web_pref::WebPreferences& web) {
|
2015-10-17 02:44:00 +02:00
|
|
|
if (!extensions::ExtensionsEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(
|
|
|
|
rvh->GetProcess()->GetBrowserContext());
|
|
|
|
if (!registry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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-03-04 23:36:57 +01:00
|
|
|
const GURL& site_url = rvh->GetMainFrame()->GetSiteInstance()->GetSiteURL();
|
2015-10-17 02:44:00 +02:00
|
|
|
if (!site_url.SchemeIs(extensions::kExtensionScheme))
|
|
|
|
return;
|
|
|
|
|
|
|
|
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) {
|
2017-05-17 11:29:28 +02:00
|
|
|
prefs->SetValue(key, base::WrapUnique(new base::Value(value)),
|
|
|
|
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) {
|
|
|
|
prefs->SetValue(key, base::WrapUnique(new base::Value(value)),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
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());
|
|
|
|
|
2020-09-15 18:34:22 +02:00
|
|
|
// Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
|
|
|
|
// disabled; some of the UI is not yet correctly themed.
|
2020-12-02 23:31:49 +01:00
|
|
|
if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
|
|
|
|
// Update based on last committed url.
|
|
|
|
bool force_light = url.SchemeIs(content::kChromeUIScheme);
|
|
|
|
if (!force_light) {
|
|
|
|
force_light = url.SchemeIs(extensions::kExtensionScheme) &&
|
|
|
|
url.host_piece() == extension_misc::kPdfExtensionId;
|
|
|
|
}
|
|
|
|
if (force_light) {
|
|
|
|
web_prefs->preferred_color_scheme =
|
|
|
|
blink::mojom::PreferredColorScheme::kLight;
|
|
|
|
}
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command_line->HasSwitch(switches::kDisableJavascriptDomPaste))
|
|
|
|
SetBool(prefs, prefs::kWebKitDomPasteEnabled, false);
|
|
|
|
if (command_line->HasSwitch(switches::kDisableImageLoading))
|
|
|
|
SetBool(prefs, prefs::kWebKitLoadsImagesAutomatically, false);
|
|
|
|
if (command_line->HasSwitch(switches::kDisableTabToLinks))
|
|
|
|
SetBool(prefs, prefs::kWebkitTabsToLinks, false);
|
2018-02-03 01:01:36 +01:00
|
|
|
if (command_line->HasSwitch(switches::kDisablePlugins))
|
|
|
|
SetBool(prefs, prefs::kWebKitPluginsEnabled, false);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cef.default_font_size > 0)
|
|
|
|
web.default_font_size = cef.default_font_size;
|
|
|
|
if (cef.default_fixed_font_size > 0)
|
|
|
|
web.default_fixed_font_size = cef.default_fixed_font_size;
|
|
|
|
if (cef.minimum_font_size > 0)
|
|
|
|
web.minimum_font_size = cef.minimum_font_size;
|
|
|
|
if (cef.minimum_logical_font_size > 0)
|
|
|
|
web.minimum_logical_font_size = cef.minimum_logical_font_size;
|
|
|
|
|
|
|
|
if (cef.default_encoding.length > 0)
|
|
|
|
web.default_encoding = CefString(&cef.default_encoding);
|
|
|
|
|
|
|
|
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.plugins, web.plugins_enabled);
|
|
|
|
SET_STATE(cef.universal_access_from_file_urls,
|
|
|
|
web.allow_universal_access_from_file_urls);
|
|
|
|
SET_STATE(cef.file_access_from_file_urls,
|
|
|
|
web.allow_file_access_from_file_urls);
|
|
|
|
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);
|
|
|
|
SET_STATE(cef.application_cache, web.application_cache_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.
|
2015-10-17 02:44:00 +02:00
|
|
|
registry->RegisterBooleanPref(
|
2017-05-17 11:29:28 +02:00
|
|
|
prefs::kEnableDoNotTrack, false,
|
2015-10-17 02:44:00 +02:00
|
|
|
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
|
2020-08-29 00:39:23 +02:00
|
|
|
registry->RegisterBooleanPref(prefs::kCaretBrowsingEnabled, false);
|
2020-09-22 23:12:18 +02:00
|
|
|
registry->RegisterBooleanPref(prefs::kCloudPrintDeprecationWarningsSuppressed,
|
|
|
|
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
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
#if !defined(OS_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,
|
2020-10-08 21:54:42 +02:00
|
|
|
blink::web_pref::WebPreferences& web) {
|
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-03-04 23:36:57 +01:00
|
|
|
UpdatePreferredColorScheme(
|
|
|
|
&web, rvh->GetMainFrame()->GetSiteInstance()->GetSiteURL(), native_theme);
|
2020-09-15 18:34:22 +02:00
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Set preferences based on the extension.
|
|
|
|
SetExtensionPrefs(rvh, web);
|
|
|
|
|
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.
|
2017-04-20 21:28:17 +02:00
|
|
|
web.base_background_color = browser->GetBackgroundColor();
|
|
|
|
} 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.
|
|
|
|
web.base_background_color =
|
|
|
|
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(),
|
|
|
|
native_theme);
|
2020-09-15 18:34:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
} // namespace renderer_prefs
|