blob: ed00da9fe671d4070c4631ad911a245ed8eeea51 [file] [log] [blame]
[email protected]37cc8042012-02-27 19:32:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]93623c5d2009-12-10 21:40:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/renderer_preferences_util.h"
6
guidouca055a542016-08-11 11:15:537#include <string>
8
[email protected]516b2c732014-07-25 00:10:319#include "base/macros.h"
guidouca055a542016-08-11 11:15:5310#include "base/strings/string_number_conversions.h"
11#include "base/strings/string_util.h"
avib896c712015-12-26 02:10:4312#include "build/build_config.h"
John Abd-El-Malek7d032b372019-05-07 18:01:3113#include "chrome/browser/browser_process.h"
[email protected]8ecad5e2010-12-02 21:18:3314#include "chrome/browser/profiles/profile.h"
[email protected]0a8db0d2011-04-13 15:15:4015#include "chrome/common/pref_names.h"
Alexandre Frechette572755b2019-02-13 22:30:2016#include "components/language/core/browser/pref_names.h"
brettwb1fc1b82016-02-02 00:19:0817#include "components/prefs/pref_service.h"
Ian Vollick0c34a072019-02-15 03:40:2718#include "content/public/browser/renderer_preferences_util.h"
Scott Violeta35f9a42018-03-22 22:00:4419#include "media/media_buildflags.h"
Antonio Gomesb5bf548f2019-09-12 17:40:1520#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
Leon Hanc819dc62019-01-28 04:30:1921#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Blink Reformata30d4232018-04-07 15:31:0622#include "third_party/blink/public/public_buildflags.h"
[email protected]38a85712013-01-02 22:45:0223#include "third_party/skia/include/core/SkColor.h"
[email protected]93623c5d2009-12-10 21:40:3224
[email protected]dbf75012013-09-24 06:37:2525#if defined(TOOLKIT_VIEWS)
26#include "ui/views/controls/textfield/textfield.h"
[email protected]7bd129f2012-11-30 02:06:0127#endif
28
ellyjonesd0fd7b12016-08-26 18:26:3629#if defined(OS_MACOSX)
30#include "ui/base/cocoa/defaults_utils.h"
31#endif
32
[email protected]96514e72013-09-25 20:42:2433#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
34#include "chrome/browser/themes/theme_service.h"
35#include "chrome/browser/themes/theme_service_factory.h"
36#include "ui/views/linux_ui/linux_ui.h"
37#endif
38
guidouca055a542016-08-11 11:15:5339namespace {
40
41// Parses a string |range| with a port range in the form "<min>-<max>".
42// If |range| is not in the correct format or contains an invalid range, zero
43// is written to |min_port| and |max_port|.
44// TODO(guidou): Consider replacing with remoting/protocol/port_range.cc
45void ParsePortRange(const std::string& range,
46 uint16_t* min_port,
47 uint16_t* max_port) {
48 *min_port = 0;
49 *max_port = 0;
50
51 if (range.empty())
52 return;
53
54 size_t separator_index = range.find('-');
55 if (separator_index == std::string::npos)
56 return;
57
58 std::string min_port_string, max_port_string;
59 base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL,
60 &min_port_string);
61 base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL,
62 &max_port_string);
63 unsigned min_port_uint, max_port_uint;
64 if (!base::StringToUint(min_port_string, &min_port_uint) ||
65 !base::StringToUint(max_port_string, &max_port_uint)) {
66 return;
67 }
68 if (min_port_uint == 0 || min_port_uint > max_port_uint ||
69 max_port_uint > UINT16_MAX) {
70 return;
71 }
72
73 *min_port = static_cast<uint16_t>(min_port_uint);
74 *max_port = static_cast<uint16_t>(max_port_uint);
75}
76
Qingsi Wang337dc7a2019-10-29 01:02:0477// Extracts the string representation of URLs allowed for local IP exposure.
78std::vector<std::string> GetLocalIpsAllowedUrls(
79 const base::ListValue* allowed_urls) {
80 std::vector<std::string> ret;
81 if (allowed_urls) {
82 const auto& urls = allowed_urls->GetList();
83 for (const auto& url : urls)
84 ret.push_back(url.GetString());
85 }
86 return ret;
87}
88
guidouca055a542016-08-11 11:15:5389} // namespace
90
[email protected]93623c5d2009-12-10 21:40:3291namespace renderer_preferences_util {
92
Leon Hanc819dc62019-01-28 04:30:1993void UpdateFromSystemSettings(blink::mojom::RendererPreferences* prefs,
Kenichi Ishibashif522ac42018-07-12 23:16:4694 Profile* profile) {
[email protected]f57f69012012-06-13 02:52:2195 const PrefService* pref_service = profile->GetPrefs();
Alexandre Frechette572755b2019-02-13 22:30:2096 prefs->accept_languages =
97 pref_service->GetString(language::prefs::kAcceptLanguages);
[email protected]f57f69012012-06-13 02:52:2198 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
[email protected]498bc512012-09-21 21:50:0899 prefs->enable_do_not_track =
100 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
Xiaohan Wang2ec4a6832017-11-15 00:55:51101 prefs->enable_encrypted_media =
102 pref_service->GetBoolean(prefs::kEnableEncryptedMedia);
guoweisc537ba22015-11-06 21:20:31103 prefs->webrtc_ip_handling_policy = std::string();
104 // Handling the backward compatibility of previous boolean verions of policy
105 // controls.
106 if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) {
107 if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) {
108 prefs->webrtc_ip_handling_policy =
Antonio Gomesb5bf548f2019-09-12 17:40:15109 blink::kWebRTCIPHandlingDisableNonProxiedUdp;
guoweisc537ba22015-11-06 21:20:31110 } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) {
111 prefs->webrtc_ip_handling_policy =
Antonio Gomesb5bf548f2019-09-12 17:40:15112 blink::kWebRTCIPHandlingDefaultPublicInterfaceOnly;
guoweisc537ba22015-11-06 21:20:31113 }
114 }
115 if (prefs->webrtc_ip_handling_policy.empty()) {
116 prefs->webrtc_ip_handling_policy =
117 pref_service->GetString(prefs::kWebRTCIPHandlingPolicy);
118 }
guidouca055a542016-08-11 11:15:53119 std::string webrtc_udp_port_range =
120 pref_service->GetString(prefs::kWebRTCUDPPortRange);
121 ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port,
122 &prefs->webrtc_udp_max_port);
thestig2c8c41e2014-10-23 02:56:50123
Qingsi Wang337dc7a2019-10-29 01:02:04124 const base::ListValue* allowed_urls =
125 pref_service->GetList(prefs::kWebRtcLocalIpsAllowedUrls);
126 prefs->webrtc_local_ips_allowed_urls = GetLocalIpsAllowedUrls(allowed_urls);
Christopher Cameronadf36612019-05-14 17:19:42127#if defined(USE_AURA)
[email protected]38a85712013-01-02 22:45:02128 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
[email protected]d41e40502014-04-12 00:56:22129#if defined(OS_CHROMEOS)
[email protected]38a85712013-01-02 22:45:02130 // This color is 0x544d90fe modulated with 0xffffff.
131 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
132 prefs->active_selection_fg_color = SK_ColorBLACK;
133 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
134 prefs->inactive_selection_fg_color = SK_ColorBLACK;
[email protected]f2cb988d22013-07-01 22:07:04135#endif
[email protected]7bd129f2012-11-30 02:06:01136#endif
137
[email protected]dbf75012013-09-24 06:37:25138#if defined(TOOLKIT_VIEWS)
tzikd450061e2017-11-28 17:14:50139 prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval();
[email protected]dbf75012013-09-24 06:37:25140#endif
141
ellyjonesd0fd7b12016-08-26 18:26:36142#if defined(OS_MACOSX)
143 base::TimeDelta interval;
144 if (ui::TextInsertionCaretBlinkPeriod(&interval))
tzikd450061e2017-11-28 17:14:50145 prefs->caret_blink_interval = interval;
ellyjonesd0fd7b12016-08-26 18:26:36146#endif
147
[email protected]96514e72013-09-25 20:42:24148#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
149 views::LinuxUI* linux_ui = views::LinuxUI::instance();
150 if (linux_ui) {
[email protected]448d7dc2014-05-13 03:22:55151 if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
[email protected]96514e72013-09-25 20:42:24152 prefs->focus_ring_color = linux_ui->GetFocusRingColor();
[email protected]96514e72013-09-25 20:42:24153 prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor();
154 prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor();
155 prefs->inactive_selection_bg_color =
156 linux_ui->GetInactiveSelectionBgColor();
157 prefs->inactive_selection_fg_color =
158 linux_ui->GetInactiveSelectionFgColor();
159 }
160
161 // If we have a linux_ui object, set the caret blink interval regardless of
162 // whether we're in native theme mode.
163 prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
164 }
165#endif
166
scottmga04a4b32015-03-26 22:56:49167#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN)
Sergey Ulanovfd5f85a2019-01-07 21:57:28168 content::UpdateFontRendererPreferencesFromSystemSettings(prefs);
[email protected]f57f69012012-06-13 02:52:21169#endif
[email protected]0509bc82013-09-20 20:42:59170
171#if !defined(OS_MACOSX)
172 prefs->plugin_fullscreen_allowed =
173 pref_service->GetBoolean(prefs::kFullscreenAllowed);
174#endif
John Abd-El-Malek7d032b372019-05-07 18:01:31175
176 PrefService* local_state = g_browser_process->local_state();
177 if (local_state) {
178 prefs->allow_cross_origin_auth_prompt =
179 local_state->GetBoolean(prefs::kAllowCrossOriginAuthPrompt);
180 }
[email protected]93623c5d2009-12-10 21:40:32181}
182
[email protected]0509bc82013-09-20 20:42:59183} // namespace renderer_preferences_util