[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" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 15 | #include "chrome/common/pref_names.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 16 | #include "components/language/core/browser/pref_names.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 17 | #include "components/prefs/pref_service.h" |
Ian Vollick | 0c34a07 | 2019-02-15 03:40:27 | [diff] [blame] | 18 | #include "content/public/browser/renderer_preferences_util.h" |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 19 | #include "content/public/common/webrtc_ip_handling_policy.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 20 | #include "media/media_buildflags.h" |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 21 | #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 22 | #include "third_party/blink/public/public_buildflags.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 23 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 24 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 25 | #if defined(TOOLKIT_VIEWS) |
| 26 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 27 | #endif |
| 28 | |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 29 | #if defined(OS_MACOSX) |
| 30 | #include "ui/base/cocoa/defaults_utils.h" |
| 31 | #endif |
| 32 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 33 | #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 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 39 | namespace { |
| 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 |
| 45 | void 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 | |
| 77 | } // namespace |
| 78 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 79 | namespace renderer_preferences_util { |
| 80 | |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 81 | void UpdateFromSystemSettings(blink::mojom::RendererPreferences* prefs, |
Kenichi Ishibashi | f522ac4 | 2018-07-12 23:16:46 | [diff] [blame] | 82 | Profile* profile) { |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 83 | const PrefService* pref_service = profile->GetPrefs(); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 84 | prefs->accept_languages = |
| 85 | pref_service->GetString(language::prefs::kAcceptLanguages); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 86 | prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 87 | prefs->enable_do_not_track = |
| 88 | pref_service->GetBoolean(prefs::kEnableDoNotTrack); |
Xiaohan Wang | 2ec4a683 | 2017-11-15 00:55:51 | [diff] [blame] | 89 | prefs->enable_encrypted_media = |
| 90 | pref_service->GetBoolean(prefs::kEnableEncryptedMedia); |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 91 | prefs->webrtc_ip_handling_policy = std::string(); |
| 92 | // Handling the backward compatibility of previous boolean verions of policy |
| 93 | // controls. |
| 94 | if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) { |
| 95 | if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) { |
| 96 | prefs->webrtc_ip_handling_policy = |
| 97 | content::kWebRTCIPHandlingDisableNonProxiedUdp; |
| 98 | } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) { |
| 99 | prefs->webrtc_ip_handling_policy = |
| 100 | content::kWebRTCIPHandlingDefaultPublicInterfaceOnly; |
| 101 | } |
| 102 | } |
| 103 | if (prefs->webrtc_ip_handling_policy.empty()) { |
| 104 | prefs->webrtc_ip_handling_policy = |
| 105 | pref_service->GetString(prefs::kWebRTCIPHandlingPolicy); |
| 106 | } |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 107 | std::string webrtc_udp_port_range = |
| 108 | pref_service->GetString(prefs::kWebRTCUDPPortRange); |
| 109 | ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port, |
| 110 | &prefs->webrtc_udp_max_port); |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 111 | |
brettw | 8a274fa | 2016-11-15 00:20:40 | [diff] [blame] | 112 | #if BUILDFLAG(USE_DEFAULT_RENDER_THEME) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 113 | prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); |
[email protected] | d41e4050 | 2014-04-12 00:56:22 | [diff] [blame] | 114 | #if defined(OS_CHROMEOS) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 115 | // This color is 0x544d90fe modulated with 0xffffff. |
| 116 | prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); |
| 117 | prefs->active_selection_fg_color = SK_ColorBLACK; |
| 118 | prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); |
| 119 | prefs->inactive_selection_fg_color = SK_ColorBLACK; |
[email protected] | f2cb988d2 | 2013-07-01 22:07:04 | [diff] [blame] | 120 | #endif |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 121 | #endif |
| 122 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 123 | #if defined(TOOLKIT_VIEWS) |
tzik | d450061e | 2017-11-28 17:14:50 | [diff] [blame] | 124 | prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval(); |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 125 | #endif |
| 126 | |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 127 | #if defined(OS_MACOSX) |
| 128 | base::TimeDelta interval; |
| 129 | if (ui::TextInsertionCaretBlinkPeriod(&interval)) |
tzik | d450061e | 2017-11-28 17:14:50 | [diff] [blame] | 130 | prefs->caret_blink_interval = interval; |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 131 | #endif |
| 132 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 133 | #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 134 | views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
| 135 | if (linux_ui) { |
[email protected] | 448d7dc | 2014-05-13 03:22:55 | [diff] [blame] | 136 | if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 137 | prefs->focus_ring_color = linux_ui->GetFocusRingColor(); |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 138 | prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor(); |
| 139 | prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor(); |
| 140 | prefs->inactive_selection_bg_color = |
| 141 | linux_ui->GetInactiveSelectionBgColor(); |
| 142 | prefs->inactive_selection_fg_color = |
| 143 | linux_ui->GetInactiveSelectionFgColor(); |
| 144 | } |
| 145 | |
| 146 | // If we have a linux_ui object, set the caret blink interval regardless of |
| 147 | // whether we're in native theme mode. |
| 148 | prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval(); |
| 149 | } |
| 150 | #endif |
| 151 | |
scottmg | a04a4b3 | 2015-03-26 22:56:49 | [diff] [blame] | 152 | #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN) |
Sergey Ulanov | fd5f85a | 2019-01-07 21:57:28 | [diff] [blame] | 153 | content::UpdateFontRendererPreferencesFromSystemSettings(prefs); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 154 | #endif |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 155 | |
| 156 | #if !defined(OS_MACOSX) |
| 157 | prefs->plugin_fullscreen_allowed = |
| 158 | pref_service->GetBoolean(prefs::kFullscreenAllowed); |
| 159 | #endif |
John Abd-El-Malek | 7d032b37 | 2019-05-07 18:01:31 | [diff] [blame] | 160 | |
| 161 | PrefService* local_state = g_browser_process->local_state(); |
| 162 | if (local_state) { |
| 163 | prefs->allow_cross_origin_auth_prompt = |
| 164 | local_state->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); |
| 165 | } |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 168 | } // namespace renderer_preferences_util |