[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" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 13 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 14 | #include "chrome/common/pref_names.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 15 | #include "components/prefs/pref_service.h" |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 16 | #include "content/public/browser/web_contents.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 17 | #include "content/public/common/renderer_preferences.h" |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 18 | #include "content/public/common/webrtc_ip_handling_policy.h" |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 19 | #include "media/media_features.h" |
brettw | 8a274fa | 2016-11-15 00:20:40 | [diff] [blame] | 20 | #include "third_party/WebKit/public/public_features.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 21 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 22 | |
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 23 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | cd9c65e | 2014-07-10 02:57:01 | [diff] [blame] | 24 | #include "ui/gfx/font_render_params.h" |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 25 | #endif |
| 26 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 27 | #if defined(TOOLKIT_VIEWS) |
| 28 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 29 | #endif |
| 30 | |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 31 | #if defined(OS_MACOSX) |
| 32 | #include "ui/base/cocoa/defaults_utils.h" |
| 33 | #endif |
| 34 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 35 | #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 | |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 41 | #if BUILDFLAG(ENABLE_WEBRTC) |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | // Parses a string |range| with a port range in the form "<min>-<max>". |
| 45 | // If |range| is not in the correct format or contains an invalid range, zero |
| 46 | // is written to |min_port| and |max_port|. |
| 47 | // TODO(guidou): Consider replacing with remoting/protocol/port_range.cc |
| 48 | void ParsePortRange(const std::string& range, |
| 49 | uint16_t* min_port, |
| 50 | uint16_t* max_port) { |
| 51 | *min_port = 0; |
| 52 | *max_port = 0; |
| 53 | |
| 54 | if (range.empty()) |
| 55 | return; |
| 56 | |
| 57 | size_t separator_index = range.find('-'); |
| 58 | if (separator_index == std::string::npos) |
| 59 | return; |
| 60 | |
| 61 | std::string min_port_string, max_port_string; |
| 62 | base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL, |
| 63 | &min_port_string); |
| 64 | base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL, |
| 65 | &max_port_string); |
| 66 | unsigned min_port_uint, max_port_uint; |
| 67 | if (!base::StringToUint(min_port_string, &min_port_uint) || |
| 68 | !base::StringToUint(max_port_string, &max_port_uint)) { |
| 69 | return; |
| 70 | } |
| 71 | if (min_port_uint == 0 || min_port_uint > max_port_uint || |
| 72 | max_port_uint > UINT16_MAX) { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | *min_port = static_cast<uint16_t>(min_port_uint); |
| 77 | *max_port = static_cast<uint16_t>(max_port_uint); |
| 78 | } |
| 79 | |
| 80 | } // namespace |
liushouqun | 4d122dd | 2016-09-19 02:07:41 | [diff] [blame] | 81 | #endif |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 82 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 83 | namespace renderer_preferences_util { |
| 84 | |
wjmaclean | e530aa74 | 2014-10-14 21:43:30 | [diff] [blame] | 85 | void UpdateFromSystemSettings(content::RendererPreferences* prefs, |
| 86 | Profile* profile, |
| 87 | content::WebContents* web_contents) { |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 88 | const PrefService* pref_service = profile->GetPrefs(); |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 89 | prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 90 | prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 91 | prefs->enable_do_not_track = |
| 92 | pref_service->GetBoolean(prefs::kEnableDoNotTrack); |
Xiaohan Wang | 2ec4a683 | 2017-11-15 00:55:51 | [diff] [blame^] | 93 | prefs->enable_encrypted_media = |
| 94 | pref_service->GetBoolean(prefs::kEnableEncryptedMedia); |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 95 | #if BUILDFLAG(ENABLE_WEBRTC) |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 96 | prefs->webrtc_ip_handling_policy = std::string(); |
| 97 | // Handling the backward compatibility of previous boolean verions of policy |
| 98 | // controls. |
| 99 | if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) { |
| 100 | if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) { |
| 101 | prefs->webrtc_ip_handling_policy = |
| 102 | content::kWebRTCIPHandlingDisableNonProxiedUdp; |
| 103 | } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) { |
| 104 | prefs->webrtc_ip_handling_policy = |
| 105 | content::kWebRTCIPHandlingDefaultPublicInterfaceOnly; |
| 106 | } |
| 107 | } |
| 108 | if (prefs->webrtc_ip_handling_policy.empty()) { |
| 109 | prefs->webrtc_ip_handling_policy = |
| 110 | pref_service->GetString(prefs::kWebRTCIPHandlingPolicy); |
| 111 | } |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 112 | std::string webrtc_udp_port_range = |
| 113 | pref_service->GetString(prefs::kWebRTCUDPPortRange); |
| 114 | ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port, |
| 115 | &prefs->webrtc_udp_max_port); |
guoweis | 7c98bab0 | 2015-02-19 14:54:51 | [diff] [blame] | 116 | #endif |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 117 | |
brettw | 8a274fa | 2016-11-15 00:20:40 | [diff] [blame] | 118 | #if BUILDFLAG(USE_DEFAULT_RENDER_THEME) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 119 | prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); |
[email protected] | d41e4050 | 2014-04-12 00:56:22 | [diff] [blame] | 120 | #if defined(OS_CHROMEOS) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 121 | // This color is 0x544d90fe modulated with 0xffffff. |
| 122 | prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); |
| 123 | prefs->active_selection_fg_color = SK_ColorBLACK; |
| 124 | prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); |
| 125 | prefs->inactive_selection_fg_color = SK_ColorBLACK; |
[email protected] | f2cb988d2 | 2013-07-01 22:07:04 | [diff] [blame] | 126 | #endif |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 127 | #endif |
| 128 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 129 | #if defined(TOOLKIT_VIEWS) |
| 130 | prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0; |
| 131 | #endif |
| 132 | |
ellyjones | d0fd7b1 | 2016-08-26 18:26:36 | [diff] [blame] | 133 | #if defined(OS_MACOSX) |
| 134 | base::TimeDelta interval; |
| 135 | if (ui::TextInsertionCaretBlinkPeriod(&interval)) |
| 136 | prefs->caret_blink_interval = interval.InSecondsF(); |
| 137 | #endif |
| 138 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 139 | #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 140 | views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
| 141 | if (linux_ui) { |
[email protected] | 448d7dc | 2014-05-13 03:22:55 | [diff] [blame] | 142 | if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 143 | prefs->focus_ring_color = linux_ui->GetFocusRingColor(); |
| 144 | prefs->thumb_active_color = linux_ui->GetThumbActiveColor(); |
| 145 | prefs->thumb_inactive_color = linux_ui->GetThumbInactiveColor(); |
| 146 | prefs->track_color = linux_ui->GetTrackColor(); |
| 147 | prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor(); |
| 148 | prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor(); |
| 149 | prefs->inactive_selection_bg_color = |
| 150 | linux_ui->GetInactiveSelectionBgColor(); |
| 151 | prefs->inactive_selection_fg_color = |
| 152 | linux_ui->GetInactiveSelectionFgColor(); |
| 153 | } |
| 154 | |
| 155 | // If we have a linux_ui object, set the caret blink interval regardless of |
| 156 | // whether we're in native theme mode. |
| 157 | prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval(); |
| 158 | } |
| 159 | #endif |
| 160 | |
scottmg | a04a4b3 | 2015-03-26 22:56:49 | [diff] [blame] | 161 | #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN) |
[email protected] | 516b2c73 | 2014-07-25 00:10:31 | [diff] [blame] | 162 | CR_DEFINE_STATIC_LOCAL(const gfx::FontRenderParams, params, |
stapelberg | 575097c | 2015-04-06 18:31:38 | [diff] [blame] | 163 | (gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), NULL))); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 164 | prefs->should_antialias_text = params.antialiasing; |
| 165 | prefs->use_subpixel_positioning = params.subpixel_positioning; |
[email protected] | 0681ba0 | 2014-07-28 00:27:11 | [diff] [blame] | 166 | prefs->hinting = params.hinting; |
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 167 | prefs->use_autohinter = params.autohinter; |
| 168 | prefs->use_bitmaps = params.use_bitmaps; |
[email protected] | 0681ba0 | 2014-07-28 00:27:11 | [diff] [blame] | 169 | prefs->subpixel_rendering = params.subpixel_rendering; |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 170 | #endif |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 171 | |
| 172 | #if !defined(OS_MACOSX) |
| 173 | prefs->plugin_fullscreen_allowed = |
| 174 | pref_service->GetBoolean(prefs::kFullscreenAllowed); |
| 175 | #endif |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 176 | } |
| 177 | |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 178 | } // namespace renderer_preferences_util |