OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_preferences_util.h" | 5 #include "chrome/browser/renderer_preferences_util.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" |
8 #include "build/build_config.h" | 12 #include "build/build_config.h" |
9 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
11 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
12 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/renderer_preferences.h" | 17 #include "content/public/common/renderer_preferences.h" |
14 #include "content/public/common/webrtc_ip_handling_policy.h" | 18 #include "content/public/common/webrtc_ip_handling_policy.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
16 | 20 |
17 #if defined(OS_LINUX) || defined(OS_ANDROID) | 21 #if defined(OS_LINUX) || defined(OS_ANDROID) |
18 #include "ui/gfx/font_render_params.h" | 22 #include "ui/gfx/font_render_params.h" |
19 #endif | 23 #endif |
20 | 24 |
21 #if defined(TOOLKIT_VIEWS) | 25 #if defined(TOOLKIT_VIEWS) |
22 #include "ui/views/controls/textfield/textfield.h" | 26 #include "ui/views/controls/textfield/textfield.h" |
23 #endif | 27 #endif |
24 | 28 |
25 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) | 29 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
26 #include "chrome/browser/themes/theme_service.h" | 30 #include "chrome/browser/themes/theme_service.h" |
27 #include "chrome/browser/themes/theme_service_factory.h" | 31 #include "chrome/browser/themes/theme_service_factory.h" |
28 #include "ui/views/linux_ui/linux_ui.h" | 32 #include "ui/views/linux_ui/linux_ui.h" |
29 #endif | 33 #endif |
30 | 34 |
| 35 namespace { |
| 36 |
| 37 // Parses a string |range| with a port range in the form "<min>-<max>". |
| 38 // If |range| is not in the correct format or contains an invalid range, zero |
| 39 // is written to |min_port| and |max_port|. |
| 40 // TODO(guidou): Consider replacing with remoting/protocol/port_range.cc |
| 41 void ParsePortRange(const std::string& range, |
| 42 uint16_t* min_port, |
| 43 uint16_t* max_port) { |
| 44 *min_port = 0; |
| 45 *max_port = 0; |
| 46 |
| 47 if (range.empty()) |
| 48 return; |
| 49 |
| 50 size_t separator_index = range.find('-'); |
| 51 if (separator_index == std::string::npos) |
| 52 return; |
| 53 |
| 54 std::string min_port_string, max_port_string; |
| 55 base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL, |
| 56 &min_port_string); |
| 57 base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL, |
| 58 &max_port_string); |
| 59 unsigned min_port_uint, max_port_uint; |
| 60 if (!base::StringToUint(min_port_string, &min_port_uint) || |
| 61 !base::StringToUint(max_port_string, &max_port_uint)) { |
| 62 return; |
| 63 } |
| 64 if (min_port_uint == 0 || min_port_uint > max_port_uint || |
| 65 max_port_uint > UINT16_MAX) { |
| 66 return; |
| 67 } |
| 68 |
| 69 *min_port = static_cast<uint16_t>(min_port_uint); |
| 70 *max_port = static_cast<uint16_t>(max_port_uint); |
| 71 } |
| 72 |
| 73 } // namespace |
| 74 |
31 namespace renderer_preferences_util { | 75 namespace renderer_preferences_util { |
32 | 76 |
33 void UpdateFromSystemSettings(content::RendererPreferences* prefs, | 77 void UpdateFromSystemSettings(content::RendererPreferences* prefs, |
34 Profile* profile, | 78 Profile* profile, |
35 content::WebContents* web_contents) { | 79 content::WebContents* web_contents) { |
36 const PrefService* pref_service = profile->GetPrefs(); | 80 const PrefService* pref_service = profile->GetPrefs(); |
37 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages); | 81 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages); |
38 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); | 82 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
39 prefs->enable_do_not_track = | 83 prefs->enable_do_not_track = |
40 pref_service->GetBoolean(prefs::kEnableDoNotTrack); | 84 pref_service->GetBoolean(prefs::kEnableDoNotTrack); |
41 #if defined(ENABLE_WEBRTC) | 85 #if defined(ENABLE_WEBRTC) |
42 prefs->webrtc_ip_handling_policy = std::string(); | 86 prefs->webrtc_ip_handling_policy = std::string(); |
43 // Handling the backward compatibility of previous boolean verions of policy | 87 // Handling the backward compatibility of previous boolean verions of policy |
44 // controls. | 88 // controls. |
45 if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) { | 89 if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) { |
46 if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) { | 90 if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) { |
47 prefs->webrtc_ip_handling_policy = | 91 prefs->webrtc_ip_handling_policy = |
48 content::kWebRTCIPHandlingDisableNonProxiedUdp; | 92 content::kWebRTCIPHandlingDisableNonProxiedUdp; |
49 } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) { | 93 } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) { |
50 prefs->webrtc_ip_handling_policy = | 94 prefs->webrtc_ip_handling_policy = |
51 content::kWebRTCIPHandlingDefaultPublicInterfaceOnly; | 95 content::kWebRTCIPHandlingDefaultPublicInterfaceOnly; |
52 } | 96 } |
53 } | 97 } |
54 if (prefs->webrtc_ip_handling_policy.empty()) { | 98 if (prefs->webrtc_ip_handling_policy.empty()) { |
55 prefs->webrtc_ip_handling_policy = | 99 prefs->webrtc_ip_handling_policy = |
56 pref_service->GetString(prefs::kWebRTCIPHandlingPolicy); | 100 pref_service->GetString(prefs::kWebRTCIPHandlingPolicy); |
57 } | 101 } |
| 102 std::string webrtc_udp_port_range = |
| 103 pref_service->GetString(prefs::kWebRTCUDPPortRange); |
| 104 ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port, |
| 105 &prefs->webrtc_udp_max_port); |
58 #endif | 106 #endif |
59 | 107 |
60 #if defined(USE_DEFAULT_RENDER_THEME) | 108 #if defined(USE_DEFAULT_RENDER_THEME) |
61 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); | 109 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); |
62 #if defined(OS_CHROMEOS) | 110 #if defined(OS_CHROMEOS) |
63 // This color is 0x544d90fe modulated with 0xffffff. | 111 // This color is 0x544d90fe modulated with 0xffffff. |
64 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); | 112 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); |
65 prefs->active_selection_fg_color = SK_ColorBLACK; | 113 prefs->active_selection_fg_color = SK_ColorBLACK; |
66 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); | 114 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); |
67 prefs->inactive_selection_fg_color = SK_ColorBLACK; | 115 prefs->inactive_selection_fg_color = SK_ColorBLACK; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 prefs->subpixel_rendering = params.subpixel_rendering; | 153 prefs->subpixel_rendering = params.subpixel_rendering; |
106 #endif | 154 #endif |
107 | 155 |
108 #if !defined(OS_MACOSX) | 156 #if !defined(OS_MACOSX) |
109 prefs->plugin_fullscreen_allowed = | 157 prefs->plugin_fullscreen_allowed = |
110 pref_service->GetBoolean(prefs::kFullscreenAllowed); | 158 pref_service->GetBoolean(prefs::kFullscreenAllowed); |
111 #endif | 159 #endif |
112 } | 160 } |
113 | 161 |
114 } // namespace renderer_preferences_util | 162 } // namespace renderer_preferences_util |
OLD | NEW |