1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/renderer_preferences_util.h"
#include <stdint.h>
#include <string>
#include <vector>
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/convert_explicitly_allowed_network_ports_pref.h"
#include "chrome/browser/privacy_sandbox/tracking_protection_settings_factory.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ash/login/demo_mode/demo_session.h"
#endif
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/language/core/browser/language_prefs.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/privacy_sandbox/tracking_protection_settings.h"
#include "content/public/browser/renderer_preferences_util.h"
#include "media/media_buildflags.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
#include "third_party/blink/public/mojom/peerconnection/webrtc_ip_handling_policy.mojom.h"
#include "third_party/blink/public/public_buildflags.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/platform/ax_platform.h"
#include "ui/base/ui_base_features.h"
#if defined(TOOLKIT_VIEWS)
#include "ui/views/controls/textfield/textfield.h"
#endif
#if defined(USE_AURA) && BUILDFLAG(IS_LINUX)
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "ui/linux/linux_ui.h"
#endif
namespace {
// Parses a string |range| with a port range in the form "<min>-<max>".
// If |range| is not in the correct format or contains an invalid range, zero
// is written to |min_port| and |max_port|.
// TODO(guidou): Consider replacing with remoting/protocol/port_range.cc
void ParsePortRange(const std::string& range,
uint16_t* min_port,
uint16_t* max_port) {
*min_port = 0;
*max_port = 0;
if (range.empty())
return;
size_t separator_index = range.find('-');
if (separator_index == std::string::npos)
return;
std::string min_port_string, max_port_string;
base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL,
&min_port_string);
base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL,
&max_port_string);
unsigned min_port_uint, max_port_uint;
if (!base::StringToUint(min_port_string, &min_port_uint) ||
!base::StringToUint(max_port_string, &max_port_uint)) {
return;
}
if (min_port_uint == 0 || min_port_uint > max_port_uint ||
max_port_uint > UINT16_MAX) {
return;
}
*min_port = static_cast<uint16_t>(min_port_uint);
*max_port = static_cast<uint16_t>(max_port_uint);
}
// Extracts the string representation of URLs allowed for local IP exposure.
std::vector<std::string> GetLocalIpsAllowedUrls(
const base::Value::List& allowed_urls) {
std::vector<std::string> ret;
for (const auto& url : allowed_urls)
ret.push_back(url.GetString());
return ret;
}
std::string GetLanguageListForProfile(Profile* profile,
const std::string& language_list) {
if (profile->IsOffTheRecord()) {
// In incognito mode return only the first language.
return language::GetFirstLanguage(language_list);
}
return language_list;
}
} // namespace
namespace renderer_preferences_util {
void UpdateFromSystemSettings(blink::RendererPreferences* prefs,
Profile* profile) {
const PrefService* pref_service = profile->GetPrefs();
prefs->accept_languages = GetLanguageListForProfile(
profile, pref_service->GetString(language::prefs::kAcceptLanguages));
prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
prefs->enable_do_not_track =
TrackingProtectionSettingsFactory::GetForProfile(profile)
->IsDoNotTrackEnabled();
prefs->enable_encrypted_media =
pref_service->GetBoolean(prefs::kEnableEncryptedMedia);
#if BUILDFLAG(IS_ANDROID)
prefs->uses_platform_autofill = pref_service->GetBoolean(
autofill::prefs::kAutofillUsingVirtualViewStructure);
#else // if !BUILDFLAG(IS_ANDROID)
prefs->caret_browsing_enabled =
pref_service->GetBoolean(prefs::kCaretBrowsingEnabled);
ui::AXPlatform::GetInstance().SetCaretBrowsingState(
prefs->caret_browsing_enabled);
#endif
prefs->webrtc_ip_handling_policy = blink::ToWebRTCIPHandlingPolicy(
pref_service->GetString(prefs::kWebRTCIPHandlingPolicy));
const base::Value::List& webrtc_ip_handling_urls =
pref_service->GetList(prefs::kWebRTCIPHandlingUrl);
for (const base::Value& entry : webrtc_ip_handling_urls) {
const base::Value::Dict& dict = entry.GetDict();
const std::string* url = dict.FindString("url");
if (!url) {
DVLOG(1) << "Malformed WebRtcIPHandlingUrl entry: Missing 'url' value.";
continue;
}
ContentSettingsPattern pattern = ContentSettingsPattern::FromString(*url);
if (!pattern.IsValid()) {
DVLOG(1)
<< "Malformed WebRtcIPHandlingUrl entry: Invalid pattern found: '"
<< *url << "'.";
continue;
}
const std::string* handling = dict.FindString("handling");
if (!handling) {
DVLOG(1)
<< "Malformed WebRtcIPHandlingUrl entry: Missing 'handling' value.";
continue;
}
prefs->webrtc_ip_handling_urls.push_back(
{pattern, blink::ToWebRTCIPHandlingPolicy(*handling)});
}
std::string webrtc_udp_port_range =
pref_service->GetString(prefs::kWebRTCUDPPortRange);
ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port,
&prefs->webrtc_udp_max_port);
const base::Value::List& allowed_urls =
pref_service->GetList(prefs::kWebRtcLocalIpsAllowedUrls);
prefs->webrtc_local_ips_allowed_urls = GetLocalIpsAllowedUrls(allowed_urls);
#if defined(USE_AURA)
prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
#if BUILDFLAG(IS_CHROMEOS)
// This color is 0x544d90fe modulated with 0xffffff.
prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
prefs->active_selection_fg_color = SK_ColorBLACK;
prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
prefs->inactive_selection_fg_color = SK_ColorBLACK;
#endif
#endif
#if defined(TOOLKIT_VIEWS)
prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval();
#endif
#if defined(USE_AURA) && BUILDFLAG(IS_LINUX)
auto* linux_ui_theme = ui::LinuxUiTheme::GetForProfile(profile);
if (linux_ui_theme) {
if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
linux_ui_theme->GetFocusRingColor(&prefs->focus_ring_color);
linux_ui_theme->GetActiveSelectionBgColor(
&prefs->active_selection_bg_color);
linux_ui_theme->GetActiveSelectionFgColor(
&prefs->active_selection_fg_color);
linux_ui_theme->GetInactiveSelectionBgColor(
&prefs->inactive_selection_bg_color);
linux_ui_theme->GetInactiveSelectionFgColor(
&prefs->inactive_selection_fg_color);
}
}
// If we have a linux_ui object, set the caret blink interval regardless of
// whether we're in native theme mode.
if (auto* linux_ui = ui::LinuxUi::instance())
prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
BUILDFLAG(IS_WIN)
content::UpdateFontRendererPreferencesFromSystemSettings(prefs);
#endif
#if !BUILDFLAG(IS_MAC)
prefs->plugin_fullscreen_allowed =
pref_service->GetBoolean(prefs::kFullscreenAllowed);
#endif
PrefService* local_state = g_browser_process->local_state();
if (local_state) {
prefs->allow_cross_origin_auth_prompt =
local_state->GetBoolean(prefs::kAllowCrossOriginAuthPrompt);
prefs->explicitly_allowed_network_ports =
ConvertExplicitlyAllowedNetworkPortsPref(local_state);
}
#if BUILDFLAG(IS_MAC)
prefs->focus_ring_color = SkColorSetRGB(0x00, 0x5F, 0xCC);
#else
prefs->focus_ring_color = SkColorSetRGB(0x10, 0x10, 0x10);
#endif
prefs->view_source_line_wrap_enabled =
pref_service->GetBoolean(prefs::kViewSourceLineWrappingEnabled);
}
} // namespace renderer_preferences_util
|