[email protected] | 37cc804 | 2012-02-27 19:32:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 2 | // 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 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 7 | #include <string> |
| 8 | |
[email protected] | 516b2c73 | 2014-07-25 00:10:31 | [diff] [blame] | 9 | #include "base/macros.h" |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
| 11 | #include "base/strings/string_util.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 12 | #include "build/build_config.h" |
John Abd-El-Malek | 7d032b37 | 2019-05-07 18:01:31 | [diff] [blame] | 13 | #include "chrome/browser/browser_process.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile.h" |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 15 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 16 | #include "chrome/common/pref_names.h" |
Trevor Perrier | fa7339d | 2020-09-11 00:42:40 | [diff] [blame] | 17 | #include "components/language/core/browser/language_prefs.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 18 | #include "components/language/core/browser/pref_names.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 19 | #include "components/prefs/pref_service.h" |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 20 | #include "content/public/browser/browser_accessibility_state.h" |
Ian Vollick | 0c34a07 | 2019-02-15 03:40:27 | [diff] [blame] | 21 | #include "content/public/browser/renderer_preferences_util.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 22 | #include "media/media_buildflags.h" |
Antonio Gomes | b5bf548f | 2019-09-12 17:40:15 | [diff] [blame] | 23 | #include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h" |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame^] | 24 | #include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 25 | #include "third_party/blink/public/public_buildflags.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 26 | #include "third_party/skia/include/core/SkColor.h" |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 27 | #include "ui/base/ui_base_features.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 28 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 29 | #if defined(TOOLKIT_VIEWS) |
| 30 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 31 | #endif |
| 32 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 33 | #if defined(OS_MAC) |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 34 | #include "ui/base/cocoa/defaults_utils.h" |
| 35 | #endif |
| 36 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 37 | #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 38 | #include "chrome/browser/themes/theme_service.h" |
| 39 | #include "chrome/browser/themes/theme_service_factory.h" |
| 40 | #include "ui/views/linux_ui/linux_ui.h" |
| 41 | #endif |
| 42 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 43 | namespace { |
| 44 | |
| 45 | // Parses a string |range| with a port range in the form "<min>-<max>". |
| 46 | // If |range| is not in the correct format or contains an invalid range, zero |
| 47 | // is written to |min_port| and |max_port|. |
| 48 | // TODO(guidou): Consider replacing with remoting/protocol/port_range.cc |
| 49 | void ParsePortRange(const std::string& range, |
| 50 | uint16_t* min_port, |
| 51 | uint16_t* max_port) { |
| 52 | *min_port = 0; |
| 53 | *max_port = 0; |
| 54 | |
| 55 | if (range.empty()) |
| 56 | return; |
| 57 | |
| 58 | size_t separator_index = range.find('-'); |
| 59 | if (separator_index == std::string::npos) |
| 60 | return; |
| 61 | |
| 62 | std::string min_port_string, max_port_string; |
| 63 | base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL, |
| 64 | &min_port_string); |
| 65 | base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL, |
| 66 | &max_port_string); |
| 67 | unsigned min_port_uint, max_port_uint; |
| 68 | if (!base::StringToUint(min_port_string, &min_port_uint) || |
| 69 | !base::StringToUint(max_port_string, &max_port_uint)) { |
| 70 | return; |
| 71 | } |
| 72 | if (min_port_uint == 0 || min_port_uint > max_port_uint || |
| 73 | max_port_uint > UINT16_MAX) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | *min_port = static_cast<uint16_t>(min_port_uint); |
| 78 | *max_port = static_cast<uint16_t>(max_port_uint); |
| 79 | } |
| 80 | |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 81 | // Extracts the string representation of URLs allowed for local IP exposure. |
| 82 | std::vector<std::string> GetLocalIpsAllowedUrls( |
| 83 | const base::ListValue* allowed_urls) { |
| 84 | std::vector<std::string> ret; |
| 85 | if (allowed_urls) { |
| 86 | const auto& urls = allowed_urls->GetList(); |
| 87 | for (const auto& url : urls) |
| 88 | ret.push_back(url.GetString()); |
| 89 | } |
| 90 | return ret; |
| 91 | } |
| 92 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 93 | } // namespace |
| 94 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 95 | namespace renderer_preferences_util { |
| 96 | |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame^] | 97 | void UpdateFromSystemSettings(blink::RendererPreferences* prefs, |
Kenichi Ishibashi | f522ac4 | 2018-07-12 23:16:46 | [diff] [blame] | 98 | Profile* profile) { |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 99 | const PrefService* pref_service = profile->GetPrefs(); |
Megan Jablonski | f223de4 | 2020-08-26 22:25:15 | [diff] [blame] | 100 | if (profile->IsOffTheRecord()) { |
Trevor Perrier | fa7339d | 2020-09-11 00:42:40 | [diff] [blame] | 101 | // In incognito mode return only the first language. |
| 102 | prefs->accept_languages = language::GetFirstLanguage( |
| 103 | pref_service->GetString(language::prefs::kAcceptLanguages)); |
Megan Jablonski | f223de4 | 2020-08-26 22:25:15 | [diff] [blame] | 104 | } else { |
| 105 | prefs->accept_languages = |
| 106 | pref_service->GetString(language::prefs::kAcceptLanguages); |
| 107 | } |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 108 | prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 109 | prefs->enable_do_not_track = |
| 110 | pref_service->GetBoolean(prefs::kEnableDoNotTrack); |
Xiaohan Wang | 2ec4a683 | 2017-11-15 00:55:51 | [diff] [blame] | 111 | prefs->enable_encrypted_media = |
| 112 | pref_service->GetBoolean(prefs::kEnableEncryptedMedia); |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 113 | prefs->webrtc_ip_handling_policy = std::string(); |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 114 | #if !defined(OS_ANDROID) |
| 115 | prefs->caret_browsing_enabled = |
| 116 | pref_service->GetBoolean(prefs::kCaretBrowsingEnabled); |
| 117 | content::BrowserAccessibilityState::GetInstance()->SetCaretBrowsingState( |
| 118 | prefs->caret_browsing_enabled); |
| 119 | #endif |
| 120 | |
| 121 | // Handling the backward compatibility of previous boolean versions of policy |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 122 | // controls. |
| 123 | if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) { |
| 124 | if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) { |
| 125 | prefs->webrtc_ip_handling_policy = |
Antonio Gomes | b5bf548f | 2019-09-12 17:40:15 | [diff] [blame] | 126 | blink::kWebRTCIPHandlingDisableNonProxiedUdp; |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 127 | } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) { |
| 128 | prefs->webrtc_ip_handling_policy = |
Antonio Gomes | b5bf548f | 2019-09-12 17:40:15 | [diff] [blame] | 129 | blink::kWebRTCIPHandlingDefaultPublicInterfaceOnly; |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | if (prefs->webrtc_ip_handling_policy.empty()) { |
| 133 | prefs->webrtc_ip_handling_policy = |
| 134 | pref_service->GetString(prefs::kWebRTCIPHandlingPolicy); |
| 135 | } |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 136 | std::string webrtc_udp_port_range = |
| 137 | pref_service->GetString(prefs::kWebRTCUDPPortRange); |
| 138 | ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port, |
| 139 | &prefs->webrtc_udp_max_port); |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 140 | |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 141 | const base::ListValue* allowed_urls = |
| 142 | pref_service->GetList(prefs::kWebRtcLocalIpsAllowedUrls); |
| 143 | prefs->webrtc_local_ips_allowed_urls = GetLocalIpsAllowedUrls(allowed_urls); |
Guido Urdaneta | 7f9f9df | 2020-09-29 15:19:17 | [diff] [blame] | 144 | prefs->webrtc_allow_legacy_tls_protocols = |
| 145 | pref_service->GetBoolean(prefs::kWebRTCAllowLegacyTLSProtocols); |
Christopher Cameron | adf3661 | 2019-05-14 17:19:42 | [diff] [blame] | 146 | #if defined(USE_AURA) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 147 | prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); |
[email protected] | d41e4050 | 2014-04-12 00:56:22 | [diff] [blame] | 148 | #if defined(OS_CHROMEOS) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 149 | // This color is 0x544d90fe modulated with 0xffffff. |
| 150 | prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); |
| 151 | prefs->active_selection_fg_color = SK_ColorBLACK; |
| 152 | prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); |
| 153 | prefs->inactive_selection_fg_color = SK_ColorBLACK; |
[email protected] | f2cb988d2 | 2013-07-01 22:07:04 | [diff] [blame] | 154 | #endif |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 155 | #endif |
| 156 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 157 | #if defined(TOOLKIT_VIEWS) |
tzik | d450061e | 2017-11-28 17:14:50 | [diff] [blame] | 158 | prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval(); |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 159 | #endif |
| 160 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 161 | #if defined(OS_MAC) |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 162 | base::TimeDelta interval; |
| 163 | if (ui::TextInsertionCaretBlinkPeriod(&interval)) |
tzik | d450061e | 2017-11-28 17:14:50 | [diff] [blame] | 164 | prefs->caret_blink_interval = interval; |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 165 | #endif |
| 166 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 167 | #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 168 | views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
| 169 | if (linux_ui) { |
[email protected] | 448d7dc | 2014-05-13 03:22:55 | [diff] [blame] | 170 | if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 171 | prefs->focus_ring_color = linux_ui->GetFocusRingColor(); |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 172 | prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor(); |
| 173 | prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor(); |
| 174 | prefs->inactive_selection_bg_color = |
| 175 | linux_ui->GetInactiveSelectionBgColor(); |
| 176 | prefs->inactive_selection_fg_color = |
| 177 | linux_ui->GetInactiveSelectionFgColor(); |
| 178 | } |
| 179 | |
| 180 | // If we have a linux_ui object, set the caret blink interval regardless of |
| 181 | // whether we're in native theme mode. |
| 182 | prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval(); |
| 183 | } |
| 184 | #endif |
| 185 | |
Sean McAllister | df80771 | 2020-08-13 23:19:09 | [diff] [blame] | 186 | #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) || \ |
| 187 | defined(OS_WIN) |
Sergey Ulanov | fd5f85a | 2019-01-07 21:57:28 | [diff] [blame] | 188 | content::UpdateFontRendererPreferencesFromSystemSettings(prefs); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 189 | #endif |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 190 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 191 | #if !defined(OS_MAC) |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 192 | prefs->plugin_fullscreen_allowed = |
| 193 | pref_service->GetBoolean(prefs::kFullscreenAllowed); |
| 194 | #endif |
John Abd-El-Malek | 7d032b37 | 2019-05-07 18:01:31 | [diff] [blame] | 195 | |
| 196 | PrefService* local_state = g_browser_process->local_state(); |
| 197 | if (local_state) { |
| 198 | prefs->allow_cross_origin_auth_prompt = |
| 199 | local_state->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); |
| 200 | } |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 201 | |
| 202 | if (::features::IsFormControlsRefreshEnabled()) { |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 203 | #if defined(OS_MAC) |
Mason Freed | e31aceb | 2020-03-09 17:04:46 | [diff] [blame] | 204 | prefs->focus_ring_color = SkColorSetRGB(0x00, 0x5F, 0xCC); |
Mason Freed | a32930f | 2020-03-05 16:57:24 | [diff] [blame] | 205 | #else |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 206 | prefs->focus_ring_color = SkColorSetRGB(0x10, 0x10, 0x10); |
Mason Freed | a32930f | 2020-03-05 16:57:24 | [diff] [blame] | 207 | #endif |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 208 | } |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 211 | } // namespace renderer_preferences_util |