Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [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 | |
dpapad | 538e016 | 2020-12-17 23:06:23 | [diff] [blame] | 5 | #include "chrome/browser/ui/webui/policy/policy_ui.h" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 6 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 9 | #include "base/check.h" |
Yann Dago | b206dca4 | 2023-10-30 17:24:48 | [diff] [blame] | 10 | #include "base/json/json_string_value_serializer.h" |
Salma Elmahallawy | a78c7673 | 2023-06-29 15:39:40 | [diff] [blame] | 11 | #include "base/json/json_writer.h" |
| 12 | #include "base/strings/stringprintf.h" |
| 13 | #include "base/system/sys_info.h" |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 14 | #include "base/values.h" |
Anton Urusov | eb2d381 | 2017-08-24 20:01:02 | [diff] [blame] | 15 | #include "build/build_config.h" |
Elena Scobici | 1d50eea3 | 2023-07-17 20:32:06 | [diff] [blame] | 16 | #include "chrome/browser/enterprise/browser_management/management_service_factory.h" |
Yann Dago | e09f88e | 2024-08-06 20:58:02 | [diff] [blame] | 17 | #include "chrome/browser/policy/profile_policy_connector.h" |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 18 | #include "chrome/browser/policy/schema_registry_service.h" |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 19 | #include "chrome/browser/policy/value_provider/chrome_policies_value_provider.h" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 20 | #include "chrome/browser/profiles/profile.h" |
dpapad | 538e016 | 2020-12-17 23:06:23 | [diff] [blame] | 21 | #include "chrome/browser/ui/webui/policy/policy_ui_handler.h" |
Yann Dago | ee874fcd | 2023-09-15 15:49:31 | [diff] [blame] | 22 | #include "chrome/common/channel_info.h" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 23 | #include "chrome/common/url_constants.h" |
Henrique Ferreiro | d78ab26 | 2023-09-13 11:21:43 | [diff] [blame] | 24 | #include "chrome/grit/branded_strings.h" |
Raphael Kubo da Costa | b742ad8 | 2025-03-04 10:08:45 | [diff] [blame] | 25 | #include "components/embedder_support/user_agent_utils.h" |
dpapad | 5a98fb2 | 2023-01-12 18:51:34 | [diff] [blame] | 26 | #include "components/grit/policy_resources.h" |
| 27 | #include "components/grit/policy_resources_map.h" |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 28 | #include "components/policy/core/common/features.h" |
Elena Scobici | e31fb4a | 2023-07-28 15:06:58 | [diff] [blame] | 29 | #include "components/policy/core/common/management/management_service.h" |
Jayee | 9ba64c20 | 2023-07-24 15:01:36 | [diff] [blame] | 30 | #include "components/policy/core/common/policy_loader_common.h" |
Jayee | 07bb468c | 2023-06-01 18:25:31 | [diff] [blame] | 31 | #include "components/policy/core/common/policy_pref_names.h" |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 32 | #include "components/policy/core/common/policy_utils.h" |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 33 | #include "components/policy/core/common/schema_registry.h" |
Elena Scobici | e31fb4a | 2023-07-28 15:06:58 | [diff] [blame] | 34 | #include "components/policy/policy_constants.h" |
Jayee | 07bb468c | 2023-06-01 18:25:31 | [diff] [blame] | 35 | #include "components/prefs/pref_registry_simple.h" |
thestig | 4a2e88e | 2016-08-27 23:23:51 | [diff] [blame] | 36 | #include "components/strings/grit/components_strings.h" |
Salma Elmahallawy | a78c7673 | 2023-06-29 15:39:40 | [diff] [blame] | 37 | #include "components/version_info/version_info.h" |
rbpotter | aeb05c8 | 2025-01-24 18:41:04 | [diff] [blame] | 38 | #include "components/webui/version/version_handler_helper.h" |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 39 | #include "content/public/browser/web_ui.h" |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 40 | #include "content/public/browser/web_ui_controller.h" |
| 41 | #include "content/public/browser/web_ui_message_handler.h" |
Rebekah Potter | f6b2f26 | 2022-05-27 21:43:19 | [diff] [blame] | 42 | #include "services/network/public/mojom/content_security_policy.mojom.h" |
Rohit Rao | e38fb48 | 2020-01-19 21:35:14 | [diff] [blame] | 43 | #include "ui/base/webui/web_ui_util.h" |
Teresa Mao | adc56730 | 2024-12-18 21:15:09 | [diff] [blame] | 44 | #include "ui/webui/webui_util.h" |
[email protected] | 8a2166d9 | 2012-12-06 23:58:45 | [diff] [blame] | 45 | |
Salma Elmahallawy | ee91a670 | 2024-06-07 16:20:56 | [diff] [blame] | 46 | // LINT.IfChange |
| 47 | |
[email protected] | a8ac9bd2 | 2012-05-02 12:30:37 | [diff] [blame] | 48 | namespace { |
David Jean | 93315a8f9 | 2023-06-16 08:03:22 | [diff] [blame] | 49 | |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 50 | // Returns the operating system information to be displayed on |
| 51 | // chrome://policy/logs page. |
| 52 | std::string GetOsInfo() { |
Salma Elmahallawy | a78c7673 | 2023-06-29 15:39:40 | [diff] [blame] | 53 | #if BUILDFLAG(IS_ANDROID) |
| 54 | // The base format for the OS version and build. |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 55 | constexpr char kOSVersionAndBuildFormat[] = "Android %s %s"; |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 56 | return base::StringPrintf( |
| 57 | kOSVersionAndBuildFormat, |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 58 | (base::SysInfo::OperatingSystemVersion()).c_str(), |
Raphael Kubo da Costa | b742ad8 | 2025-03-04 10:08:45 | [diff] [blame] | 59 | (embedder_support::GetAndroidOSInfo( |
| 60 | embedder_support::IncludeAndroidBuildNumber::Include, |
| 61 | embedder_support::IncludeAndroidModel::Include)) |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 62 | .c_str()); |
Salma Elmahallawy | a78c7673 | 2023-06-29 15:39:40 | [diff] [blame] | 63 | #else |
| 64 | return base::StringPrintf("%s %s", |
| 65 | base::SysInfo::OperatingSystemName().c_str(), |
| 66 | base::SysInfo::OperatingSystemVersion().c_str()); |
| 67 | #endif // BUILDFLAG (IS_ANDROID) |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | // Returns the version information to be displayed on the chrome://policy/logs |
| 71 | // page. |
Roman Sorokin | 9f655dca | 2023-02-01 14:09:32 | [diff] [blame] | 72 | base::Value::Dict GetVersionInfo() { |
| 73 | base::Value::Dict version_info; |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 74 | |
Roman Sorokin | 9f655dca | 2023-02-01 14:09:32 | [diff] [blame] | 75 | version_info.Set("revision", version_info::GetLastChange()); |
| 76 | version_info.Set("version", version_info::GetVersionNumber()); |
| 77 | version_info.Set("deviceOs", GetOsInfo()); |
| 78 | version_info.Set("variations", version_ui::GetVariationsList()); |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 79 | |
| 80 | return version_info; |
| 81 | } |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 82 | |
Rebekah Potter | 463261e | 2022-12-20 20:49:01 | [diff] [blame] | 83 | void CreateAndAddPolicyUIHtmlSource(Profile* profile) { |
| 84 | content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd( |
| 85 | profile, chrome::kChromeUIPolicyHost); |
fhorschig | 07c5e062 | 2015-12-03 16:48:57 | [diff] [blame] | 86 | PolicyUIHandler::AddCommonLocalizedStringsToSource(source); |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 87 | |
Lei Zhang | 6af63c26 | 2019-11-22 02:07:03 | [diff] [blame] | 88 | static constexpr webui::LocalizedString kStrings[] = { |
Austin Zhang | 6cf6abe7 | 2024-10-09 19:28:37 | [diff] [blame] | 89 | // Localized strings (alphabetical order). |
| 90 | {"copyPoliciesJSON", IDS_COPY_POLICIES_JSON}, |
| 91 | {"exportPoliciesJSON", IDS_EXPORT_POLICIES_JSON}, |
| 92 | {"filterPlaceholder", IDS_POLICY_FILTER_PLACEHOLDER}, |
| 93 | {"hideExpandedStatus", IDS_POLICY_HIDE_EXPANDED_STATUS}, |
| 94 | {"isAffiliatedYes", IDS_POLICY_IS_AFFILIATED_YES}, |
| 95 | {"isAffiliatedNo", IDS_POLICY_IS_AFFILIATED_NO}, |
| 96 | {"labelAssetId", IDS_POLICY_LABEL_ASSET_ID}, |
| 97 | {"labelClientId", IDS_POLICY_LABEL_CLIENT_ID}, |
| 98 | {"labelDirectoryApiId", IDS_POLICY_LABEL_DIRECTORY_API_ID}, |
| 99 | {"labelError", IDS_POLICY_LABEL_ERROR}, |
| 100 | {"labelWarning", IDS_POLICY_HEADER_WARNING}, |
| 101 | {"labelGaiaId", IDS_POLICY_LABEL_GAIA_ID}, |
| 102 | {"labelIsAffiliated", IDS_POLICY_LABEL_IS_AFFILIATED}, |
| 103 | {"labelLastCloudReportSentTimestamp", |
| 104 | IDS_POLICY_LABEL_LAST_CLOUD_REPORT_SENT_TIMESTAMP}, |
| 105 | {"labelLocation", IDS_POLICY_LABEL_LOCATION}, |
| 106 | {"labelMachineEnrollmentDomain", |
| 107 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DOMAIN}, |
| 108 | {"labelMachineEnrollmentMachineName", |
| 109 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_MACHINE_NAME}, |
| 110 | {"labelMachineEnrollmentToken", |
| 111 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_TOKEN}, |
| 112 | {"labelMachineEntrollmentDeviceId", |
| 113 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DEVICE_ID}, |
| 114 | {"labelIsOffHoursActive", IDS_POLICY_LABEL_IS_OFFHOURS_ACTIVE}, |
| 115 | {"labelPoliciesPush", IDS_POLICY_LABEL_PUSH_POLICIES}, |
| 116 | {"labelPrecedence", IDS_POLICY_LABEL_PRECEDENCE}, |
| 117 | {"labelProfileId", IDS_POLICY_LABEL_PROFILE_ID}, |
| 118 | {"labelRefreshInterval", IDS_POLICY_LABEL_REFRESH_INTERVAL}, |
| 119 | {"labelStatus", IDS_POLICY_LABEL_STATUS}, |
| 120 | {"labelTimeSinceLastFetchAttempt", |
| 121 | IDS_POLICY_LABEL_TIME_SINCE_LAST_FETCH_ATTEMPT}, |
| 122 | {"labelTimeSinceLastRefresh", IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH}, |
| 123 | {"labelUsername", IDS_POLICY_LABEL_USERNAME}, |
| 124 | {"labelManagedBy", IDS_POLICY_LABEL_MANAGED_BY}, |
| 125 | {"labelVersion", IDS_POLICY_LABEL_VERSION}, |
| 126 | {"moreActions", IDS_POLICY_MORE_ACTIONS}, |
| 127 | {"noPoliciesSet", IDS_POLICY_NO_POLICIES_SET}, |
| 128 | {"offHoursActive", IDS_POLICY_OFFHOURS_ACTIVE}, |
| 129 | {"offHoursNotActive", IDS_POLICY_OFFHOURS_NOT_ACTIVE}, |
| 130 | {"policyCopyValue", IDS_POLICY_COPY_VALUE}, |
| 131 | {"policiesPushOff", IDS_POLICY_PUSH_POLICIES_OFF}, |
| 132 | {"policiesPushOn", IDS_POLICY_PUSH_POLICIES_ON}, |
| 133 | {"policyLearnMore", IDS_POLICY_LEARN_MORE}, |
| 134 | {"reloadPolicies", IDS_POLICY_RELOAD_POLICIES}, |
| 135 | {"showExpandedStatus", IDS_POLICY_SHOW_EXPANDED_STATUS}, |
| 136 | {"showLess", IDS_POLICY_SHOW_LESS}, |
| 137 | {"showMore", IDS_POLICY_SHOW_MORE}, |
| 138 | {"showUnset", IDS_POLICY_SHOW_UNSET}, |
| 139 | {"signinProfile", IDS_POLICY_SIGNIN_PROFILE}, |
| 140 | {"status", IDS_POLICY_STATUS}, |
| 141 | {"statusErrorManagedNoPolicy", IDS_POLICY_STATUS_ERROR_MANAGED_NO_POLICY}, |
| 142 | {"statusFlexOrgNoPolicy", IDS_POLICY_STATUS_FLEX_ORG_NO_POLICY}, |
| 143 | {"statusDevice", IDS_POLICY_STATUS_DEVICE}, |
| 144 | {"statusMachine", IDS_POLICY_STATUS_MACHINE}, |
Xiaohan Wang | e9439fd | 2022-01-18 21:00:31 | [diff] [blame] | 145 | #if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) |
Austin Zhang | 6cf6abe7 | 2024-10-09 19:28:37 | [diff] [blame] | 146 | {"statusUpdater", IDS_POLICY_STATUS_UPDATER}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 147 | #endif |
Austin Zhang | 6cf6abe7 | 2024-10-09 19:28:37 | [diff] [blame] | 148 | {"statusUser", IDS_POLICY_STATUS_USER}, |
Owen Min | a4157615 | 2022-10-20 23:27:37 | [diff] [blame] | 149 | #if !BUILDFLAG(IS_CHROMEOS) |
Austin Zhang | 6cf6abe7 | 2024-10-09 19:28:37 | [diff] [blame] | 150 | {"uploadReport", IDS_UPLOAD_REPORT}, |
Owen Min | a4157615 | 2022-10-20 23:27:37 | [diff] [blame] | 151 | #endif // !BUILDFLAG(IS_CHROMEOS) |
Austin Zhang | 6cf6abe7 | 2024-10-09 19:28:37 | [diff] [blame] | 152 | {"viewLogs", IDS_VIEW_POLICY_LOGS}, |
| 153 | #if !BUILDFLAG(IS_ANDROID) |
| 154 | {"promotionBannerTitle", IDS_POLICY_BANNER_PROMOTION_TITLE}, |
| 155 | {"promotionBannerDesc", IDS_POLICY_BANNER_PROMOTION_DESC}, |
| 156 | {"promotionBannerBtn", IDS_POLICY_BANNER_PROMOTION_BTN}, |
| 157 | #endif |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 158 | }; |
dpapad | f61285c | 2021-02-09 21:56:39 | [diff] [blame] | 159 | source->AddLocalizedStrings(kStrings); |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 160 | |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 161 | // Localized strings for chrome://policy/logs. |
| 162 | static constexpr webui::LocalizedString kPolicyLogsStrings[] = { |
| 163 | {"browserName", IDS_PRODUCT_NAME}, |
| 164 | {"exportLogsJSON", IDS_EXPORT_POLICY_LOGS_JSON}, |
| 165 | {"logsTitle", IDS_POLICY_LOGS_TITLE}, |
| 166 | {"os", IDS_VERSION_UI_OS}, |
| 167 | {"refreshLogs", IDS_REFRESH_POLICY_LOGS}, |
| 168 | {"revision", IDS_VERSION_UI_REVISION}, |
| 169 | {"versionInfoLabel", IDS_VERSION_INFO}, |
| 170 | {"variations", IDS_VERSION_UI_VARIATIONS}, |
| 171 | }; |
| 172 | source->AddLocalizedStrings(kPolicyLogsStrings); |
| 173 | |
Salma Elmahallawy | 3059e68 | 2023-10-19 13:41:12 | [diff] [blame] | 174 | std::string variations_json_value; |
| 175 | base::JSONWriter::Write(GetVersionInfo(), &variations_json_value); |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 176 | |
Salma Elmahallawy | 3059e68 | 2023-10-19 13:41:12 | [diff] [blame] | 177 | source->AddString("versionInfo", variations_json_value); |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 178 | |
| 179 | source->AddResourcePath("logs/", IDR_POLICY_LOGS_POLICY_LOGS_HTML); |
| 180 | source->AddResourcePath("logs", IDR_POLICY_LOGS_POLICY_LOGS_HTML); |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 181 | |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 182 | const bool allow_policy_test_page = PolicyUI::ShouldLoadTestPage(profile); |
Yann Dago | f66aa549 | 2023-12-05 18:21:03 | [diff] [blame] | 183 | if (allow_policy_test_page) { |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 184 | // Localized strings for chrome://policy/test. |
| 185 | static constexpr webui::LocalizedString kPolicyTestStrings[] = { |
| 186 | {"testTitle", IDS_POLICY_TEST_TITLE}, |
Jayee | 7b9b6df | 2023-07-31 16:39:24 | [diff] [blame] | 187 | {"testRestart", IDS_POLICY_TEST_RESTART_AND_APPLY}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 188 | {"testApply", IDS_POLICY_TEST_APPLY}, |
| 189 | {"testImport", IDS_POLICY_TEST_IMPORT}, |
| 190 | {"testDesc", IDS_POLICY_TEST_DESC}, |
Elena Scobici | 3f4dc66 | 2023-07-17 20:27:29 | [diff] [blame] | 191 | {"testRevertAppliedPolicies", IDS_POLICY_TEST_REVERT}, |
| 192 | {"testClearPolicies", IDS_CLEAR}, |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 193 | {"testTableNamespace", IDS_POLICY_HEADER_NAMESPACE}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 194 | {"testTableName", IDS_POLICY_HEADER_NAME}, |
| 195 | {"testTableSource", IDS_POLICY_HEADER_SOURCE}, |
Elena Scobici | 7b3bcbc | 2023-08-08 22:08:26 | [diff] [blame] | 196 | {"testTableScope", IDS_POLICY_TEST_TABLE_SCOPE}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 197 | {"testTableLevel", IDS_POLICY_HEADER_LEVEL}, |
| 198 | {"testTableValue", IDS_POLICY_LABEL_VALUE}, |
| 199 | {"testTableRemove", IDS_REMOVE}, |
| 200 | {"testAdd", IDS_POLICY_TEST_ADD}, |
| 201 | {"testNameSelect", IDS_POLICY_SELECT_NAME}, |
Elena Scobici | 277122b | 2023-08-01 17:44:12 | [diff] [blame] | 202 | {"testTablePreset", IDS_POLICY_TEST_TABLE_PRESET}, |
| 203 | {"testTablePresetCustom", IDS_POLICY_TEST_PRESET_CUSTOM}, |
| 204 | {"testTablePresetLocalMachine", IDS_POLICY_TEST_PRESET_LOCAL_MACHINE}, |
| 205 | {"testTablePresetCloudAccount", IDS_POLICY_TEST_PRESET_CLOUD_ACCOUNT}, |
Jayee | 826f50776 | 2023-08-07 16:57:37 | [diff] [blame] | 206 | {"testUserAffiliated", IDS_POLICY_TEST_USER_AFFILIATED}, |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 207 | }; |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 208 | |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 209 | source->AddLocalizedStrings(kPolicyTestStrings); |
| 210 | source->AddResourcePath("test/", IDR_POLICY_TEST_POLICY_TEST_HTML); |
| 211 | source->AddResourcePath("test", IDR_POLICY_TEST_POLICY_TEST_HTML); |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 212 | |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 213 | std::string schema; |
| 214 | JSONStringValueSerializer serializer(&schema); |
| 215 | serializer.Serialize(PolicyUI::GetSchema(profile)); |
| 216 | source->AddString("initialSchema", schema); |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 217 | |
Elena Scobici | a8858f2 | 2023-07-24 14:46:19 | [diff] [blame] | 218 | // Strings for policy levels, scopes and sources. |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 219 | static constexpr webui::LocalizedString kPolicyTestTypes[] = { |
| 220 | {"scopeUser", IDS_POLICY_SCOPE_USER}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 221 | {"scopeDevice", IDS_POLICY_SCOPE_DEVICE}, |
| 222 | {"levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED}, |
| 223 | {"levelMandatory", IDS_POLICY_LEVEL_MANDATORY}, |
| 224 | {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 225 | {"sourceCommandLine", IDS_POLICY_SOURCE_COMMAND_LINE}, |
| 226 | {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, |
Elena Scobici | a8858f2 | 2023-07-24 14:46:19 | [diff] [blame] | 227 | {"sourceActiveDirectory", IDS_POLICY_SOURCE_ACTIVE_DIRECTORY}, |
| 228 | {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 229 | {"sourceMerged", IDS_POLICY_SOURCE_MERGED}, |
| 230 | {"sourceCloudFromAsh", IDS_POLICY_SOURCE_CLOUD_FROM_ASH}, |
| 231 | {"sourceRestrictedManagedGuestSessionOverride", |
| 232 | IDS_POLICY_SOURCE_RESTRICTED_MANAGED_GUEST_SESSION_OVERRIDE}, |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | source->AddLocalizedStrings(kPolicyTestTypes); |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 236 | } |
| 237 | |
Yann Dago | f66aa549 | 2023-12-05 18:21:03 | [diff] [blame] | 238 | source->AddString("acceptedPaths", |
| 239 | allow_policy_test_page ? "/|/test|/logs" : "/|/logs"); |
Peter Kasting | 19ab502 | 2024-12-03 00:49:41 | [diff] [blame] | 240 | webui::SetupWebUIDataSource(source, kPolicyResources, IDR_POLICY_POLICY_HTML); |
Rebekah Potter | f6b2f26 | 2022-05-27 21:43:19 | [diff] [blame] | 241 | |
Yann Dago | 4937e13 | 2023-01-23 14:19:26 | [diff] [blame] | 242 | webui::EnableTrustedTypesCSP(source); |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | 8a2166d9 | 2012-12-06 23:58:45 | [diff] [blame] | 245 | } // namespace |
| 246 | |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 247 | PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 248 | web_ui->AddMessageHandler(std::make_unique<PolicyUIHandler>()); |
Rebekah Potter | 463261e | 2022-12-20 20:49:01 | [diff] [blame] | 249 | CreateAndAddPolicyUIHtmlSource(Profile::FromWebUI(web_ui)); |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 250 | } |
| 251 | |
Jérôme Gingras | 272c1f7d | 2020-05-27 16:35:50 | [diff] [blame] | 252 | PolicyUI::~PolicyUI() = default; |
Jayee | 07bb468c | 2023-06-01 18:25:31 | [diff] [blame] | 253 | |
| 254 | // static |
| 255 | void PolicyUI::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| 256 | registry->RegisterBooleanPref(policy::policy_prefs::kPolicyTestPageEnabled, |
| 257 | true); |
Austin Zhang | 71790fc6 | 2024-10-09 19:29:50 | [diff] [blame] | 258 | registry->RegisterBooleanPref( |
| 259 | policy::policy_prefs::kHasDismissedPolicyPagePromotionBanner, false); |
Jayee | 07bb468c | 2023-06-01 18:25:31 | [diff] [blame] | 260 | } |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 261 | |
| 262 | // static |
| 263 | bool PolicyUI::ShouldLoadTestPage(Profile* profile) { |
Yann Dago | e09f88e | 2024-08-06 20:58:02 | [diff] [blame] | 264 | // Test page should only load if testing is enabled. |
| 265 | if (!policy::utils::IsPolicyTestingEnabled(profile->GetPrefs(), |
| 266 | chrome::GetChannel())) { |
| 267 | return false; |
| 268 | } |
| 269 | // The test page is not allowed if the profile is cloud managed unless |
| 270 | // we are already using the test policies. |
| 271 | if (policy::ManagementServiceFactory::GetForProfile(profile) |
| 272 | ->HasManagementAuthority( |
| 273 | policy::EnterpriseManagementAuthority::CLOUD) && |
| 274 | !profile->GetProfilePolicyConnector()->IsUsingLocalTestPolicyProvider()) { |
| 275 | return false; |
| 276 | } |
| 277 | return true; |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | // static |
| 281 | base::Value PolicyUI::GetSchema(Profile* profile) { |
Dominique Fauteux-Chapleau | dd2cf1f | 2024-06-17 19:25:29 | [diff] [blame] | 282 | if (!profile->GetPolicySchemaRegistryService()) { |
| 283 | return base::Value(); |
| 284 | } |
| 285 | |
Nicolas Ouellet-Payeur | 4c514879 | 2024-02-05 20:06:34 | [diff] [blame] | 286 | policy::SchemaRegistry* registry = |
| 287 | profile->GetPolicySchemaRegistryService()->registry(); |
| 288 | static const policy::PolicyDomain kDomains[] = { |
| 289 | policy::POLICY_DOMAIN_CHROME, |
| 290 | policy::POLICY_DOMAIN_EXTENSIONS, |
| 291 | }; |
| 292 | // Build a dictionary like this: |
| 293 | // { |
| 294 | // "chrome": { |
| 295 | // "PolicyOne": "number", |
| 296 | // "PolicyTwo": "string", |
| 297 | // ... |
| 298 | // }, |
| 299 | // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": { |
| 300 | // "PolicyOne": "number", |
| 301 | // ... |
| 302 | // }, |
| 303 | // ... |
| 304 | // } |
| 305 | base::Value::Dict dict; |
| 306 | for (const auto domain : kDomains) { |
| 307 | const policy::ComponentMap* components = |
| 308 | registry->schema_map()->GetComponents(domain); |
| 309 | if (!components) { |
| 310 | continue; |
| 311 | } |
| 312 | for (const auto& [component_id, schema] : *components) { |
| 313 | DCHECK_EQ(schema.type(), base::Value::Type::DICT); |
| 314 | base::Value::List policy_names; |
| 315 | auto it = schema.GetPropertiesIterator(); |
| 316 | for (; !it.IsAtEnd(); it.Advance()) { |
| 317 | if (it.schema().IsSensitiveValue() || |
| 318 | policy::IsPolicyNameSensitive(it.key())) { |
| 319 | continue; |
| 320 | } |
| 321 | policy_names.Append(it.key()); |
| 322 | } |
| 323 | // Use "chrome" instead of the empty string for the Chrome namespace, |
| 324 | // for better debuggability. Use the extension ID for other namespaces. |
| 325 | dict.Set(domain == policy::POLICY_DOMAIN_CHROME ? "chrome" : component_id, |
| 326 | policy::utils::GetPolicyNameToTypeMapping(policy_names, schema)); |
| 327 | } |
| 328 | } |
| 329 | return base::Value(std::move(dict)); |
| 330 | } |
Salma Elmahallawy | ee91a670 | 2024-06-07 16:20:56 | [diff] [blame] | 331 | |
| 332 | // LINT.ThenChange(//ios/chrome/browser/webui/ui_bundled/policy/policy_ui.mm) |