Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[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 | |
Adam Rice | 3d178a8 | 2021-04-12 13:49:53 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 9 | #include <string> |
Adam Rice | 3d178a8 | 2021-04-12 13:49:53 | [diff] [blame] | 10 | #include <vector> |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 11 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
| 13 | #include "base/strings/string_util.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 14 | #include "build/build_config.h" |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 15 | #include "build/chromeos_buildflags.h" |
John Abd-El-Malek | 7d032b37 | 2019-05-07 18:01:31 | [diff] [blame] | 16 | #include "chrome/browser/browser_process.h" |
Adam Rice | 3d178a8 | 2021-04-12 13:49:53 | [diff] [blame] | 17 | #include "chrome/browser/net/convert_explicitly_allowed_network_ports_pref.h" |
Fiona Macintosh | afa01d2 | 2023-09-18 12:55:49 | [diff] [blame] | 18 | #include "chrome/browser/privacy_sandbox/tracking_protection_settings_factory.h" |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 19 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Henrique Ferreiro | 606669a | 2021-02-24 13:36:55 | [diff] [blame] | 20 | #include "chrome/browser/ash/login/demo_mode/demo_session.h" |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 21 | #endif |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 22 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 23 | #include "chrome/common/pref_names.h" |
Trevor Perrier | fa7339d | 2020-09-11 00:42:40 | [diff] [blame] | 24 | #include "components/language/core/browser/language_prefs.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 25 | #include "components/language/core/browser/pref_names.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 26 | #include "components/prefs/pref_service.h" |
Fiona Macintosh | afa01d2 | 2023-09-18 12:55:49 | [diff] [blame] | 27 | #include "components/privacy_sandbox/tracking_protection_settings.h" |
Ian Vollick | 0c34a07 | 2019-02-15 03:40:27 | [diff] [blame] | 28 | #include "content/public/browser/renderer_preferences_util.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 29 | #include "media/media_buildflags.h" |
Antonio Gomes | b5bf548f | 2019-09-12 17:40:15 | [diff] [blame] | 30 | #include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h" |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 31 | #include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h" |
Guido Urdaneta | d8bfc6f9 | 2024-12-11 14:01:22 | [diff] [blame^] | 32 | #include "third_party/blink/public/mojom/peerconnection/webrtc_ip_handling_policy.mojom.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 33 | #include "third_party/blink/public/public_buildflags.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 34 | #include "third_party/skia/include/core/SkColor.h" |
Jacques Newman | 58690f2c | 2024-04-30 20:47:03 | [diff] [blame] | 35 | #include "ui/accessibility/platform/ax_platform.h" |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 36 | #include "ui/base/ui_base_features.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 37 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 38 | #if defined(TOOLKIT_VIEWS) |
| 39 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 40 | #endif |
| 41 | |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 42 | #if defined(USE_AURA) && BUILDFLAG(IS_LINUX) |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 43 | #include "chrome/browser/themes/theme_service.h" |
| 44 | #include "chrome/browser/themes/theme_service_factory.h" |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 45 | #include "ui/linux/linux_ui.h" |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 46 | #endif |
| 47 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | // Parses a string |range| with a port range in the form "<min>-<max>". |
| 51 | // If |range| is not in the correct format or contains an invalid range, zero |
| 52 | // is written to |min_port| and |max_port|. |
| 53 | // TODO(guidou): Consider replacing with remoting/protocol/port_range.cc |
| 54 | void ParsePortRange(const std::string& range, |
| 55 | uint16_t* min_port, |
| 56 | uint16_t* max_port) { |
| 57 | *min_port = 0; |
| 58 | *max_port = 0; |
| 59 | |
| 60 | if (range.empty()) |
| 61 | return; |
| 62 | |
| 63 | size_t separator_index = range.find('-'); |
| 64 | if (separator_index == std::string::npos) |
| 65 | return; |
| 66 | |
| 67 | std::string min_port_string, max_port_string; |
| 68 | base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL, |
| 69 | &min_port_string); |
| 70 | base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL, |
| 71 | &max_port_string); |
| 72 | unsigned min_port_uint, max_port_uint; |
| 73 | if (!base::StringToUint(min_port_string, &min_port_uint) || |
| 74 | !base::StringToUint(max_port_string, &max_port_uint)) { |
| 75 | return; |
| 76 | } |
| 77 | if (min_port_uint == 0 || min_port_uint > max_port_uint || |
| 78 | max_port_uint > UINT16_MAX) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | *min_port = static_cast<uint16_t>(min_port_uint); |
| 83 | *max_port = static_cast<uint16_t>(max_port_uint); |
| 84 | } |
| 85 | |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 86 | // Extracts the string representation of URLs allowed for local IP exposure. |
| 87 | std::vector<std::string> GetLocalIpsAllowedUrls( |
Roland Bock | 04381a57 | 2022-08-19 19:54:13 | [diff] [blame] | 88 | const base::Value::List& allowed_urls) { |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 89 | std::vector<std::string> ret; |
Roland Bock | 04381a57 | 2022-08-19 19:54:13 | [diff] [blame] | 90 | for (const auto& url : allowed_urls) |
| 91 | ret.push_back(url.GetString()); |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 92 | return ret; |
| 93 | } |
| 94 | |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 95 | std::string GetLanguageListForProfile(Profile* profile, |
| 96 | const std::string& language_list) { |
| 97 | if (profile->IsOffTheRecord()) { |
| 98 | // In incognito mode return only the first language. |
| 99 | return language::GetFirstLanguage(language_list); |
| 100 | } |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 101 | return language_list; |
| 102 | } |
| 103 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 104 | } // namespace |
| 105 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 106 | namespace renderer_preferences_util { |
| 107 | |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 108 | void UpdateFromSystemSettings(blink::RendererPreferences* prefs, |
Kenichi Ishibashi | f522ac4 | 2018-07-12 23:16:46 | [diff] [blame] | 109 | Profile* profile) { |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 110 | const PrefService* pref_service = profile->GetPrefs(); |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 111 | prefs->accept_languages = GetLanguageListForProfile( |
| 112 | profile, pref_service->GetString(language::prefs::kAcceptLanguages)); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 113 | prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 114 | prefs->enable_do_not_track = |
Fiona Macintosh | afa01d2 | 2023-09-18 12:55:49 | [diff] [blame] | 115 | TrackingProtectionSettingsFactory::GetForProfile(profile) |
| 116 | ->IsDoNotTrackEnabled(); |
Xiaohan Wang | 2ec4a683 | 2017-11-15 00:55:51 | [diff] [blame] | 117 | prefs->enable_encrypted_media = |
| 118 | pref_service->GetBoolean(prefs::kEnableEncryptedMedia); |
Xiaohan Wang | 55ae2c01 | 2022-01-20 21:49:11 | [diff] [blame] | 119 | #if !BUILDFLAG(IS_ANDROID) |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 120 | prefs->caret_browsing_enabled = |
| 121 | pref_service->GetBoolean(prefs::kCaretBrowsingEnabled); |
Jacques Newman | 58690f2c | 2024-04-30 20:47:03 | [diff] [blame] | 122 | ui::AXPlatform::GetInstance().SetCaretBrowsingState( |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 123 | prefs->caret_browsing_enabled); |
| 124 | #endif |
| 125 | |
Guido Urdaneta | d8bfc6f9 | 2024-12-11 14:01:22 | [diff] [blame^] | 126 | prefs->webrtc_ip_handling_policy = blink::ToWebRTCIPHandlingPolicy( |
| 127 | pref_service->GetString(prefs::kWebRTCIPHandlingPolicy)); |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 128 | std::string webrtc_udp_port_range = |
| 129 | pref_service->GetString(prefs::kWebRTCUDPPortRange); |
| 130 | ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port, |
| 131 | &prefs->webrtc_udp_max_port); |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 132 | |
Roland Bock | 04381a57 | 2022-08-19 19:54:13 | [diff] [blame] | 133 | const base::Value::List& allowed_urls = |
Roland Bock | 6edc4b7 | 2022-09-12 17:33:01 | [diff] [blame] | 134 | pref_service->GetList(prefs::kWebRtcLocalIpsAllowedUrls); |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 135 | prefs->webrtc_local_ips_allowed_urls = GetLocalIpsAllowedUrls(allowed_urls); |
Christopher Cameron | adf3661 | 2019-05-14 17:19:42 | [diff] [blame] | 136 | #if defined(USE_AURA) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 137 | prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); |
Eric Willigers | 02f80aa | 2022-04-29 01:29:32 | [diff] [blame] | 138 | #if BUILDFLAG(IS_CHROMEOS) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 139 | // This color is 0x544d90fe modulated with 0xffffff. |
| 140 | prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); |
| 141 | prefs->active_selection_fg_color = SK_ColorBLACK; |
| 142 | prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); |
| 143 | prefs->inactive_selection_fg_color = SK_ColorBLACK; |
[email protected] | f2cb988d2 | 2013-07-01 22:07:04 | [diff] [blame] | 144 | #endif |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 145 | #endif |
| 146 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 147 | #if defined(TOOLKIT_VIEWS) |
tzik | d450061e | 2017-11-28 17:14:50 | [diff] [blame] | 148 | prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval(); |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 149 | #endif |
| 150 | |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 151 | #if defined(USE_AURA) && BUILDFLAG(IS_LINUX) |
Tom Anderson | cd61f3b2 | 2022-09-14 16:27:49 | [diff] [blame] | 152 | auto* linux_ui_theme = ui::LinuxUiTheme::GetForProfile(profile); |
| 153 | if (linux_ui_theme) { |
[email protected] | 448d7dc | 2014-05-13 03:22:55 | [diff] [blame] | 154 | if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { |
Tom Anderson | 38f7473 | 2023-02-28 23:21:40 | [diff] [blame] | 155 | linux_ui_theme->GetFocusRingColor(&prefs->focus_ring_color); |
| 156 | linux_ui_theme->GetActiveSelectionBgColor( |
| 157 | &prefs->active_selection_bg_color); |
| 158 | linux_ui_theme->GetActiveSelectionFgColor( |
| 159 | &prefs->active_selection_fg_color); |
| 160 | linux_ui_theme->GetInactiveSelectionBgColor( |
| 161 | &prefs->inactive_selection_bg_color); |
| 162 | linux_ui_theme->GetInactiveSelectionFgColor( |
| 163 | &prefs->inactive_selection_fg_color); |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 164 | } |
Tom Anderson | cd61f3b2 | 2022-09-14 16:27:49 | [diff] [blame] | 165 | } |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 166 | |
| 167 | // If we have a linux_ui object, set the caret blink interval regardless of |
| 168 | // whether we're in native theme mode. |
Tom Anderson | cd61f3b2 | 2022-09-14 16:27:49 | [diff] [blame] | 169 | if (auto* linux_ui = ui::LinuxUi::instance()) |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 170 | prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval(); |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 171 | #endif |
| 172 | |
Xiaohan Wang | 55ae2c01 | 2022-01-20 21:49:11 | [diff] [blame] | 173 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \ |
| 174 | BUILDFLAG(IS_WIN) |
Sergey Ulanov | fd5f85a | 2019-01-07 21:57:28 | [diff] [blame] | 175 | content::UpdateFontRendererPreferencesFromSystemSettings(prefs); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 176 | #endif |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 177 | |
Xiaohan Wang | 55ae2c01 | 2022-01-20 21:49:11 | [diff] [blame] | 178 | #if !BUILDFLAG(IS_MAC) |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 179 | prefs->plugin_fullscreen_allowed = |
| 180 | pref_service->GetBoolean(prefs::kFullscreenAllowed); |
| 181 | #endif |
John Abd-El-Malek | 7d032b37 | 2019-05-07 18:01:31 | [diff] [blame] | 182 | |
| 183 | PrefService* local_state = g_browser_process->local_state(); |
| 184 | if (local_state) { |
| 185 | prefs->allow_cross_origin_auth_prompt = |
| 186 | local_state->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); |
Adam Rice | 3d178a8 | 2021-04-12 13:49:53 | [diff] [blame] | 187 | |
| 188 | prefs->explicitly_allowed_network_ports = |
| 189 | ConvertExplicitlyAllowedNetworkPortsPref(local_state); |
John Abd-El-Malek | 7d032b37 | 2019-05-07 18:01:31 | [diff] [blame] | 190 | } |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 191 | |
Xiaohan Wang | 55ae2c01 | 2022-01-20 21:49:11 | [diff] [blame] | 192 | #if BUILDFLAG(IS_MAC) |
Mason Freed | 972aab3 | 2021-05-21 19:11:46 | [diff] [blame] | 193 | prefs->focus_ring_color = SkColorSetRGB(0x00, 0x5F, 0xCC); |
Mason Freed | a32930f | 2020-03-05 16:57:24 | [diff] [blame] | 194 | #else |
Mason Freed | 972aab3 | 2021-05-21 19:11:46 | [diff] [blame] | 195 | prefs->focus_ring_color = SkColorSetRGB(0x10, 0x10, 0x10); |
Mason Freed | a32930f | 2020-03-05 16:57:24 | [diff] [blame] | 196 | #endif |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 199 | } // namespace renderer_preferences_util |