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 | |
Anton Urusov | eb2d381 | 2017-08-24 20:01:02 | [diff] [blame] | 9 | #include "build/build_config.h" |
Owen Min | a4157615 | 2022-10-20 23:27:37 | [diff] [blame] | 10 | #include "build/chromeos_buildflags.h" |
Elena Scobici | 518d19c | 2023-06-28 15:01:38 | [diff] [blame^] | 11 | #include "chrome/browser/policy/value_provider/chrome_policies_value_provider.h" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
dpapad | 538e016 | 2020-12-17 23:06:23 | [diff] [blame] | 13 | #include "chrome/browser/ui/webui/policy/policy_ui_handler.h" |
Lei Zhang | 6af63c26 | 2019-11-22 02:07:03 | [diff] [blame] | 14 | #include "chrome/browser/ui/webui/webui_util.h" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 15 | #include "chrome/common/url_constants.h" |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 16 | #include "chrome/grit/chromium_strings.h" |
dpapad | 5a98fb2 | 2023-01-12 18:51:34 | [diff] [blame] | 17 | #include "components/grit/policy_resources.h" |
| 18 | #include "components/grit/policy_resources_map.h" |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 19 | #include "components/policy/core/common/features.h" |
Jayee | 07bb468c | 2023-06-01 18:25:31 | [diff] [blame] | 20 | #include "components/policy/core/common/policy_pref_names.h" |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 21 | #include "components/policy/core/common/policy_utils.h" |
Jayee | 07bb468c | 2023-06-01 18:25:31 | [diff] [blame] | 22 | #include "components/prefs/pref_registry_simple.h" |
thestig | 4a2e88e | 2016-08-27 23:23:51 | [diff] [blame] | 23 | #include "components/strings/grit/components_strings.h" |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 24 | #include "content/public/browser/web_ui.h" |
Elena Scobici | db1e74e | 2023-06-08 22:52:24 | [diff] [blame] | 25 | #include "content/public/browser/web_ui_controller.h" |
| 26 | #include "content/public/browser/web_ui_message_handler.h" |
Rebekah Potter | f6b2f26 | 2022-05-27 21:43:19 | [diff] [blame] | 27 | #include "services/network/public/mojom/content_security_policy.mojom.h" |
Rohit Rao | e38fb48 | 2020-01-19 21:35:14 | [diff] [blame] | 28 | #include "ui/base/webui/web_ui_util.h" |
[email protected] | 8a2166d9 | 2012-12-06 23:58:45 | [diff] [blame] | 29 | |
David Jean | 93315a8f9 | 2023-06-16 08:03:22 | [diff] [blame] | 30 | #if BUILDFLAG(IS_ANDROID) |
| 31 | #include "base/json/json_writer.h" |
| 32 | #include "base/strings/stringprintf.h" |
| 33 | #include "base/system/sys_info.h" |
| 34 | #include "components/policy/core/common/policy_logger.h" |
| 35 | #include "components/version_info/version_info.h" |
| 36 | #include "components/version_ui/version_handler_helper.h" |
| 37 | #include "content/public/common/user_agent.h" |
| 38 | #endif // BUILDFLAG(IS_ANDROID) |
| 39 | |
[email protected] | a8ac9bd2 | 2012-05-02 12:30:37 | [diff] [blame] | 40 | namespace { |
David Jean | 93315a8f9 | 2023-06-16 08:03:22 | [diff] [blame] | 41 | |
| 42 | #if BUILDFLAG(IS_ANDROID) |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 43 | // Returns the operating system information to be displayed on |
| 44 | // chrome://policy/logs page. |
| 45 | std::string GetOsInfo() { |
David Jean | 93315a8f9 | 2023-06-16 08:03:22 | [diff] [blame] | 46 | // The base format for the OS version and build |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 47 | constexpr char kOSVersionAndBuildFormat[] = "Android %s %s"; |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 48 | return base::StringPrintf( |
| 49 | kOSVersionAndBuildFormat, |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 50 | (base::SysInfo::OperatingSystemVersion()).c_str(), |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 51 | (content::GetAndroidOSInfo(content::IncludeAndroidBuildNumber::Include, |
| 52 | content::IncludeAndroidModel::Include)) |
Salma Elmahallawy | a44f044 | 2023-01-26 22:00:15 | [diff] [blame] | 53 | .c_str()); |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // Returns the version information to be displayed on the chrome://policy/logs |
| 57 | // page. |
Roman Sorokin | 9f655dca | 2023-02-01 14:09:32 | [diff] [blame] | 58 | base::Value::Dict GetVersionInfo() { |
| 59 | base::Value::Dict version_info; |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 60 | |
Roman Sorokin | 9f655dca | 2023-02-01 14:09:32 | [diff] [blame] | 61 | version_info.Set("revision", version_info::GetLastChange()); |
| 62 | version_info.Set("version", version_info::GetVersionNumber()); |
| 63 | version_info.Set("deviceOs", GetOsInfo()); |
| 64 | version_info.Set("variations", version_ui::GetVariationsList()); |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 65 | |
| 66 | return version_info; |
| 67 | } |
David Jean | 93315a8f9 | 2023-06-16 08:03:22 | [diff] [blame] | 68 | #endif |
Salma Elmahallawy | 0d7b1c4 | 2023-01-24 01:03:51 | [diff] [blame] | 69 | |
Rebekah Potter | 463261e | 2022-12-20 20:49:01 | [diff] [blame] | 70 | void CreateAndAddPolicyUIHtmlSource(Profile* profile) { |
| 71 | content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd( |
| 72 | profile, chrome::kChromeUIPolicyHost); |
fhorschig | 07c5e062 | 2015-12-03 16:48:57 | [diff] [blame] | 73 | PolicyUIHandler::AddCommonLocalizedStringsToSource(source); |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 74 | |
Lei Zhang | 6af63c26 | 2019-11-22 02:07:03 | [diff] [blame] | 75 | static constexpr webui::LocalizedString kStrings[] = { |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 76 | // Localized strings (alphabetical order). |
Jérôme Gingras | 4b90f6fc | 2020-05-28 18:48:57 | [diff] [blame] | 77 | {"copyPoliciesJSON", IDS_COPY_POLICIES_JSON}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 78 | {"exportPoliciesJSON", IDS_EXPORT_POLICIES_JSON}, |
| 79 | {"filterPlaceholder", IDS_POLICY_FILTER_PLACEHOLDER}, |
| 80 | {"hideExpandedStatus", IDS_POLICY_HIDE_EXPANDED_STATUS}, |
| 81 | {"isAffiliatedYes", IDS_POLICY_IS_AFFILIATED_YES}, |
| 82 | {"isAffiliatedNo", IDS_POLICY_IS_AFFILIATED_NO}, |
| 83 | {"labelAssetId", IDS_POLICY_LABEL_ASSET_ID}, |
| 84 | {"labelClientId", IDS_POLICY_LABEL_CLIENT_ID}, |
| 85 | {"labelDirectoryApiId", IDS_POLICY_LABEL_DIRECTORY_API_ID}, |
Prateek R. Patil | eb8c8a2b | 2022-11-16 18:29:22 | [
|