[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / chrome / browser / renderer_preferences_util.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/renderer_preferences_util.h"
6
7 #include <string>
8
9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/language/core/browser/pref_names.h"
17 #include "components/prefs/pref_service.h"
18 #include "content/public/browser/renderer_preferences_util.h"
19 #include "media/media_buildflags.h"
20 #include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
21 #include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
22 #include "third_party/blink/public/public_buildflags.h"
23 #include "third_party/skia/include/core/SkColor.h"
24 #include "ui/base/ui_base_features.h"
25
26 #if defined(TOOLKIT_VIEWS)
27 #include "ui/views/controls/textfield/textfield.h"
28 #endif
29
30 #if defined(OS_MACOSX)
31 #include "ui/base/cocoa/defaults_utils.h"
32 #endif
33
34 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
35 #include "chrome/browser/themes/theme_service.h"
36 #include "chrome/browser/themes/theme_service_factory.h"
37 #include "ui/views/linux_ui/linux_ui.h"
38 #endif
39
40 namespace {
41
42 // Parses a string |range| with a port range in the form "<min>-<max>".
43 // If |range| is not in the correct format or contains an invalid range, zero
44 // is written to |min_port| and |max_port|.
45 // TODO(guidou): Consider replacing with remoting/protocol/port_range.cc
46 void ParsePortRange(const std::string& range,
47                     uint16_t* min_port,
48                     uint16_t* max_port) {
49   *min_port = 0;
50   *max_port = 0;
51
52   if (range.empty())
53     return;
54
55   size_t separator_index = range.find('-');
56   if (separator_index == std::string::npos)
57     return;
58
59   std::string min_port_string, max_port_string;
60   base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL,
61                             &min_port_string);
62   base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL,
63                             &max_port_string);
64   unsigned min_port_uint, max_port_uint;
65   if (!base::StringToUint(min_port_string, &min_port_uint) ||
66       !base::StringToUint(max_port_string, &max_port_uint)) {
67     return;
68   }
69   if (min_port_uint == 0 || min_port_uint > max_port_uint ||
70       max_port_uint > UINT16_MAX) {
71     return;
72   }
73
74   *min_port = static_cast<uint16_t>(min_port_uint);
75   *max_port = static_cast<uint16_t>(max_port_uint);
76 }
77
78 // Extracts the string representation of URLs allowed for local IP exposure.
79 std::vector<std::string> GetLocalIpsAllowedUrls(
80     const base::ListValue* allowed_urls) {
81   std::vector<std::string> ret;
82   if (allowed_urls) {
83     const auto& urls = allowed_urls->GetList();
84     for (const auto& url : urls)
85       ret.push_back(url.GetString());
86   }
87   return ret;
88 }
89
90 }  // namespace
91
92 namespace renderer_preferences_util {
93
94 void UpdateFromSystemSettings(blink::mojom::RendererPreferences* prefs,
95                               Profile* profile) {
96   const PrefService* pref_service = profile->GetPrefs();
97   prefs->accept_languages =
98       pref_service->GetString(language::prefs::kAcceptLanguages);
99   prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
100   prefs->enable_do_not_track =
101       pref_service->GetBoolean(prefs::kEnableDoNotTrack);
102   prefs->enable_encrypted_media =
103       pref_service->GetBoolean(prefs::kEnableEncryptedMedia);
104   prefs->webrtc_ip_handling_policy = std::string();
105   // Handling the backward compatibility of previous boolean verions of policy
106   // controls.
107   if (!pref_service->HasPrefPath(prefs::kWebRTCIPHandlingPolicy)) {
108     if (!pref_service->GetBoolean(prefs::kWebRTCNonProxiedUdpEnabled)) {
109       prefs->webrtc_ip_handling_policy =
110           blink::kWebRTCIPHandlingDisableNonProxiedUdp;
111     } else if (!pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled)) {
112       prefs->webrtc_ip_handling_policy =
113           blink::kWebRTCIPHandlingDefaultPublicInterfaceOnly;
114     }
115   }
116   if (prefs->webrtc_ip_handling_policy.empty()) {
117     prefs->webrtc_ip_handling_policy =
118         pref_service->GetString(prefs::kWebRTCIPHandlingPolicy);
119   }
120   std::string webrtc_udp_port_range =
121       pref_service->GetString(prefs::kWebRTCUDPPortRange);
122   ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port,
123                  &prefs->webrtc_udp_max_port);
124
125   const base::ListValue* allowed_urls =
126       pref_service->GetList(prefs::kWebRtcLocalIpsAllowedUrls);
127   prefs->webrtc_local_ips_allowed_urls = GetLocalIpsAllowedUrls(allowed_urls);
128 #if defined(USE_AURA)
129   prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
130 #if defined(OS_CHROMEOS)
131   // This color is 0x544d90fe modulated with 0xffffff.
132   prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
133   prefs->active_selection_fg_color = SK_ColorBLACK;
134   prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
135   prefs->inactive_selection_fg_color = SK_ColorBLACK;
136 #endif
137 #endif
138
139 #if defined(TOOLKIT_VIEWS)
140   prefs->caret_blink_interval = views::Textfield::GetCaretBlinkInterval();
141 #endif
142
143 #if defined(OS_MACOSX)
144   base::TimeDelta interval;
145   if (ui::TextInsertionCaretBlinkPeriod(&interval))
146     prefs->caret_blink_interval = interval;
147 #endif
148
149 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
150   views::LinuxUI* linux_ui = views::LinuxUI::instance();
151   if (linux_ui) {
152     if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
153       prefs->focus_ring_color = linux_ui->GetFocusRingColor();
154       prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor();
155       prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor();
156       prefs->inactive_selection_bg_color =
157         linux_ui->GetInactiveSelectionBgColor();
158       prefs->inactive_selection_fg_color =
159         linux_ui->GetInactiveSelectionFgColor();
160     }
161
162     // If we have a linux_ui object, set the caret blink interval regardless of
163     // whether we're in native theme mode.
164     prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
165   }
166 #endif
167
168 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN)
169   content::UpdateFontRendererPreferencesFromSystemSettings(prefs);
170 #endif
171
172 #if !defined(OS_MACOSX)
173   prefs->plugin_fullscreen_allowed =
174       pref_service->GetBoolean(prefs::kFullscreenAllowed);
175 #endif
176
177   PrefService* local_state = g_browser_process->local_state();
178   if (local_state) {
179     prefs->allow_cross_origin_auth_prompt =
180         local_state->GetBoolean(prefs::kAllowCrossOriginAuthPrompt);
181   }
182
183   if (::features::IsFormControlsRefreshEnabled()) {
184 #if defined(OS_MACOSX)
185     prefs->focus_ring_color = SkColorSetRGB(0x00, 0x5F, 0xCC);
186 #else
187     prefs->focus_ring_color = SkColorSetRGB(0x10, 0x10, 0x10);
188 #endif
189   }
190 }
191
192 }  // namespace renderer_preferences_util