blob: bfaec640fadb6f0c92001a5d6d401d9d04092ace [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"
Avi Drissman364efc52018-10-09 23:01:5610#include "base/no_destructor.h"
guidouca055a542016-08-11 11:15:5311#include "base/strings/string_number_conversions.h"
12#include "base/strings/string_util.h"
avib896c712015-12-26 02:10:4313#include "build/build_config.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"
brettwb1fc1b82016-02-02 00:19:0816#include "components/prefs/pref_service.h"
[email protected]daf82f82011-10-31 22:35:3117#include "content/public/common/renderer_preferences.h"
guoweisc537ba22015-11-06 21:20:3118#include "content/public/common/webrtc_ip_handling_policy.h"
Scott Violeta35f9a42018-03-22 22:00:4419#include "media/media_buildflags.h"
Blink Reformata30d4232018-04-07 15:31:0620#include "third_party/blink/public/public_buildflags.h"
[email protected]38a85712013-01-02 22:45:0221#include "third_party/skia/include/core/SkColor.h"
[email protected]93623c5d2009-12-10 21:40:3222
[email protected]7d076cf52012-07-09 23:04:4723#if defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]cd9c65e2014-07-10 02:57:0124#include "ui/gfx/font_render_params.h"
[email protected]f57f69012012-06-13 02:52:2125#endif
26
[email protected]dbf75012013-09-24 06:37:2527#if defined(TOOLKIT_VIEWS)
28#include "ui/views/controls/textfield/textfield.h"
[email protected]7bd129f2012-11-30 02:06:0129#endif
30
ellyjonesd0fd7b12016-08-26 18:26:3631#if defined(OS_MACOSX)
32#include "ui/base/cocoa/defaults_utils.h"
33#endif
34
[email protected]96514e72013-09-25 20:42:2435#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
36#include "chrome/browser/themes/theme_service.h"
37#include "chrome/browser/themes/theme_service_factory.h"
38#include "ui/views/linux_ui/linux_ui.h"
39#endif
40
guidouca055a542016-08-11 11:15:5341namespace {
42
43// Parses a string |range| with a port range in the form "<min>-<max>".
44// If |range| is not in the correct format or contains an invalid range, zero
45// is written to |min_port| and |max_port|.
46// TODO(guidou): Consider replacing with remoting/protocol/port_range.cc
47void ParsePortRange(const std::string& range,
48 uint16_t* min_port,
49 uint16_t* max_port) {
50 *min_port = 0;
51 *max_port = 0;
52
53 if (range.empty())
54 return;
55
56 size_t separator_index = range.find('-');
57 if (separator_index == std::string::npos)
58 return;
59
60 std::string min_port_string, max_port_string;
61 base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL,
62 &min_port_string);
63 base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL,
64 &max_port_string);
65 unsigned min_port_uint, max_port_uint;
66 if (!base::StringToUint(min_port_string, &min_port_uint) ||
67 !base::StringToUint(max_port_string, &max_port_uint)) {
68 return;
69 }
70 if (min_port_uint == 0 || min_port_uint > max_port_uint ||
71 max_port_uint > UINT16_MAX) {
72 return;
73 }
74
75 *min_port = static_cast<uint16_t>(min_port_uint);
76 *max_port = static_cast<uint16_t>(max_port_uint);
77}
78
79} // namespace
80
[email protected]93623c5d2009-12-10 21:40:3281namespace renderer_preferences_util {
82
wjmacleane530aa742014-10-14 21:43:3083void UpdateFromSystemSettings(content::RendererPreferences* prefs,
Kenichi Ishibashif522ac42018-07-12 23:16:4684 Profile* profile) {
[email protected]f57f69012012-06-13 02:52:2185 const PrefService* pref_service = profile->GetPrefs();
[email protected]9982c802013-06-12 15:22:0686 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages);
[email protected]f57f69012012-06-13 02:52:2187 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
[email protected]498bc512012-09-21 21:50:0888 prefs->enable_do_not_track =
89 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
Xiaohan Wang2ec4a6832017-11-15 00:55:5190 prefs->enable_encrypted_media =
91 pref_service->GetBoolean(prefs::kEnableEncryptedMedia);
guoweisc537ba22015-11-06 21:20:3192 prefs->webrtc_ip_handling_policy = std::string();
93 // Handling the backward compatibility of previous boolean verions of policy
94 // controls.
95 if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) {
96 if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) {
97 prefs->webrtc_ip_handling_policy =
98 content::kWebRTCIPHandlingDisableNonProxiedUdp;
99 } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) {
100 prefs->webrtc_ip_handling_policy =
101 content::kWebRTCIPHandlingDefaultPublicInterfaceOnly;
102 }
103 }
104 if (prefs->webrtc_ip_handling_policy.empty()) {
105 prefs->webrtc_ip_handling_policy =
106 pref_service->GetString(prefs::kWebRTCIPHandlingPolicy);
107 }
guidouca055a542016-08-11 11:15:53108 std::string webrtc_udp_port_range =
109 pref_service->GetString(prefs::kWebRTCUDPPortRange);
110 ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port,
111 &prefs->webrtc_udp_max_port);
thestig2c8c41e2014-10-23 02:56:50112
brettw8a274fa2016-11-15 00:20:40113#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]38a85712013-01-02 22:45:02114 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
[email protected]d41e40502014-04-12 00:56:22115#if defined(OS_CHROMEOS)
[email protected]38a85712013-01-02 22:45:02116 // This color is 0x544d90fe modulated with 0xffffff.
117 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
118 prefs->active_selection_fg_color = SK_ColorBLACK;
119 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
120 prefs->inactive_selection_fg_color = SK_ColorBLACK;
[email protected]f2cb988d22013-07-01 22:07:04121#endif
[email protected]7bd129f2012-11-30 02:06:01122#endif
123
[email protected]dbf75012013-09-24 06:37:25124#if defined(TOOLKIT_VIEWS)
tzikd450061e2017-11-28 17:14:50125 prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval();
[email protected]dbf75012013-09-24 06:37:25126#endif
127
ellyjonesd0fd7b12016-08-26 18:26:36128#if defined(OS_MACOSX)
129 base::TimeDelta interval;
130 if (ui::TextInsertionCaretBlinkPeriod(&interval))
tzikd450061e2017-11-28 17:14:50131 prefs->caret_blink_interval = interval;
ellyjonesd0fd7b12016-08-26 18:26:36132#endif
133
[email protected]96514e72013-09-25 20:42:24134#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
135 views::LinuxUI* linux_ui = views::LinuxUI::instance();
136 if (linux_ui) {
[email protected]448d7dc2014-05-13 03:22:55137 if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
[email protected]96514e72013-09-25 20:42:24138 prefs->focus_ring_color = linux_ui->GetFocusRingColor();
[email protected]96514e72013-09-25 20:42:24139 prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor();
140 prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor();
141 prefs->inactive_selection_bg_color =
142 linux_ui->GetInactiveSelectionBgColor();
143 prefs->inactive_selection_fg_color =
144 linux_ui->GetInactiveSelectionFgColor();
145 }
146
147 // If we have a linux_ui object, set the caret blink interval regardless of
148 // whether we're in native theme mode.
149 prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
150 }
151#endif
152
scottmga04a4b32015-03-26 22:56:49153#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN)
Avi Drissman364efc52018-10-09 23:01:56154 static const base::NoDestructor<gfx::FontRenderParams> params(
155 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr));
156 prefs->should_antialias_text = params->antialiasing;
157 prefs->use_subpixel_positioning = params->subpixel_positioning;
158 prefs->hinting = params->hinting;
159 prefs->use_autohinter = params->autohinter;
160 prefs->use_bitmaps = params->use_bitmaps;
161 prefs->subpixel_rendering = params->subpixel_rendering;
[email protected]f57f69012012-06-13 02:52:21162#endif
[email protected]0509bc82013-09-20 20:42:59163
164#if !defined(OS_MACOSX)
165 prefs->plugin_fullscreen_allowed =
166 pref_service->GetBoolean(prefs::kFullscreenAllowed);
167#endif
[email protected]93623c5d2009-12-10 21:40:32168}
169
[email protected]0509bc82013-09-20 20:42:59170} // namespace renderer_preferences_util