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" |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 18 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Henrique Ferreiro | 606669a | 2021-02-24 13:36:55 | [diff] [blame] | 19 | #include "chrome/browser/ash/login/demo_mode/demo_session.h" |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 20 | #endif |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 22 | #include "chrome/browser/profiles/profile_manager.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" |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 27 | #include "content/public/browser/browser_accessibility_state.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" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 32 | #include "third_party/blink/public/public_buildflags.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 33 | #include "third_party/skia/include/core/SkColor.h" |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 34 | #include "ui/base/ui_base_features.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 35 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 36 | #if defined(TOOLKIT_VIEWS) |
| 37 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 38 | #endif |
| 39 | |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 40 | #if defined(USE_AURA) && BUILDFLAG(IS_LINUX) |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 41 | #include "chrome/browser/themes/theme_service.h" |
| 42 | #include "chrome/browser/themes/theme_service_factory.h" |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 43 | #include "ui/linux/linux_ui.h" |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 44 | #endif |
| 45 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 46 | namespace { |
| 47 | |
| 48 | // Parses a string |range| with a port range in the form "<min>-<max>". |
| 49 | // If |range| is not in the correct format or contains an invalid range, zero |
| 50 | // is written to |min_port| and |max_port|. |
| 51 | // TODO(guidou): Consider replacing with remoting/protocol/port_range.cc |
| 52 | void ParsePortRange(const std::string& range, |
| 53 | uint16_t* min_port, |
| 54 | uint16_t* max_port) { |
| 55 | *min_port = 0; |
| 56 | *max_port = 0; |
| 57 | |
| 58 | if (range.empty()) |
| 59 | return; |
| 60 | |
| 61 | size_t separator_index = range.find('-'); |
| 62 | if (separator_index == std::string::npos) |
| 63 | return; |
| 64 | |
| 65 | std::string min_port_string, max_port_string; |
| 66 | base::TrimWhitespaceASCII(range.substr(0, separator_index), base::TRIM_ALL, |
| 67 | &min_port_string); |
| 68 | base::TrimWhitespaceASCII(range.substr(separator_index + 1), base::TRIM_ALL, |
| 69 | &max_port_string); |
| 70 | unsigned min_port_uint, max_port_uint; |
| 71 | if (!base::StringToUint(min_port_string, &min_port_uint) || |
| 72 | !base::StringToUint(max_port_string, &max_port_uint)) { |
| 73 | return; |
| 74 | } |
| 75 | if (min_port_uint == 0 || min_port_uint > max_port_uint || |
| 76 | max_port_uint > UINT16_MAX) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | *min_port = static_cast<uint16_t>(min_port_uint); |
| 81 | *max_port = static_cast<uint16_t>(max_port_uint); |
| 82 | } |
| 83 | |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 84 | // Extracts the string representation of URLs allowed for local IP exposure. |
| 85 | std::vector<std::string> GetLocalIpsAllowedUrls( |
Roland Bock | 04381a57 | 2022-08-19 19:54:13 | [diff] [blame] | 86 | const base::Value::List& allowed_urls) { |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 87 | std::vector<std::string> ret; |
Roland Bock | 04381a57 | 2022-08-19 19:54:13 | [diff] [blame] | 88 | for (const auto& url : allowed_urls) |
| 89 | ret.push_back(url.GetString()); |
Qingsi Wang | 337dc7a | 2019-10-29 01:02:04 | [diff] [blame] | 90 | return ret; |
| 91 | } |
| 92 | |
Yves Arrouye | 39b8ef6 | 2021-02-23 00:39:29 | [diff] [blame] | 93 | std::string GetLanguageListForProfile(Profile* profile, |
| 94 | const std::string& language_list) { |
| 95 | if (profile->IsOffTheRecord()) { |
| 96 | // In incognito mode return only the first language. |
| 97 | return language::GetFirstLanguage(language_list); |
| 98 | } |
| 99 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 100 | // On Chrome OS, if in demo mode, add the demo mode private language list. |
Henrique Ferreiro | d71de90 | 2021-05-10 18:57:11 | [diff] [blame] | 101 | if (ash::DemoSession::IsDeviceInDemoMode()) { |
| 102 | return language_list + "," + ash::DemoSession::GetAdditionalLanguageList(); |
Yves Arrouye |
|