blob: 5547f4024319a17ca8d0b1ec94fb25e9484806d1 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]a81712032011-08-31 16:10:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
dpapad538e0162020-12-17 23:06:235#include "chrome/browser/ui/webui/policy/policy_ui.h"
[email protected]a81712032011-08-31 16:10:046
Jinho Bang7ab7a4e2018-01-15 14:36:077#include <memory>
8
Anton Urusoveb2d3812017-08-24 20:01:029#include "build/build_config.h"
Owen Mina41576152022-10-20 23:27:3710#include "build/chromeos_buildflags.h"
Elena Scobici518d19c2023-06-28 15:01:3811#include "chrome/browser/policy/value_provider/chrome_policies_value_provider.h"
[email protected]a81712032011-08-31 16:10:0412#include "chrome/browser/profiles/profile.h"
dpapad538e0162020-12-17 23:06:2313#include "chrome/browser/ui/webui/policy/policy_ui_handler.h"
Lei Zhang6af63c262019-11-22 02:07:0314#include "chrome/browser/ui/webui/webui_util.h"
[email protected]a81712032011-08-31 16:10:0415#include "chrome/common/url_constants.h"
Salma Elmahallawya44f0442023-01-26 22:00:1516#include "chrome/grit/chromium_strings.h"
dpapad5a98fb22023-01-12 18:51:3417#include "components/grit/policy_resources.h"
18#include "components/grit/policy_resources_map.h"
Elena Scobicidb1e74e2023-06-08 22:52:2419#include "components/policy/core/common/features.h"
Jayee07bb468c2023-06-01 18:25:3120#include "components/policy/core/common/policy_pref_names.h"
Elena Scobicidb1e74e2023-06-08 22:52:2421#include "components/policy/core/common/policy_utils.h"
Jayee07bb468c2023-06-01 18:25:3122#include "components/prefs/pref_registry_simple.h"
thestig4a2e88e2016-08-27 23:23:5123#include "components/strings/grit/components_strings.h"
[email protected]01ec4ec2012-01-18 04:13:4724#include "content/public/browser/web_ui.h"
Elena Scobicidb1e74e2023-06-08 22:52:2425#include "content/public/browser/web_ui_controller.h"
26#include "content/public/browser/web_ui_message_handler.h"
Rebekah Potterf6b2f262022-05-27 21:43:1927#include "services/network/public/mojom/content_security_policy.mojom.h"
Rohit Raoe38fb482020-01-19 21:35:1428#include "ui/base/webui/web_ui_util.h"
[email protected]8a2166d92012-12-06 23:58:4529
David Jean93315a8f92023-06-16 08:03:2230#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]a8ac9bd22012-05-02 12:30:3740namespace {
David Jean93315a8f92023-06-16 08:03:2241
42#if BUILDFLAG(IS_ANDROID)
Salma Elmahallawy0d7b1c42023-01-24 01:03:5143// Returns the operating system information to be displayed on
44// chrome://policy/logs page.
45std::string GetOsInfo() {
David Jean93315a8f92023-06-16 08:03:2246 // The base format for the OS version and build
Salma Elmahallawya44f0442023-01-26 22:00:1547 constexpr char kOSVersionAndBuildFormat[] = "Android %s %s";
Salma Elmahallawy0d7b1c42023-01-24 01:03:5148 return base::StringPrintf(
49 kOSVersionAndBuildFormat,
Salma Elmahallawya44f0442023-01-26 22:00:1550 (base::SysInfo::OperatingSystemVersion()).c_str(),
Salma Elmahallawy0d7b1c42023-01-24 01:03:5151 (content::GetAndroidOSInfo(content::IncludeAndroidBuildNumber::Include,
52 content::IncludeAndroidModel::Include))
Salma Elmahallawya44f0442023-01-26 22:00:1553 .c_str());
Salma Elmahallawy0d7b1c42023-01-24 01:03:5154}
55
56// Returns the version information to be displayed on the chrome://policy/logs
57// page.
Roman Sorokin9f655dca2023-02-01 14:09:3258base::Value::Dict GetVersionInfo() {
59 base::Value::Dict version_info;
Salma Elmahallawy0d7b1c42023-01-24 01:03:5160
Roman Sorokin9f655dca2023-02-01 14:09:3261 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 Elmahallawy0d7b1c42023-01-24 01:03:5165
66 return version_info;
67}
David Jean93315a8f92023-06-16 08:03:2268#endif
Salma Elmahallawy0d7b1c42023-01-24 01:03:5169
Rebekah Potter463261e2022-12-20 20:49:0170void CreateAndAddPolicyUIHtmlSource(Profile* profile) {
71 content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd(
72 profile, chrome::kChromeUIPolicyHost);
fhorschig07c5e0622015-12-03 16:48:5773 PolicyUIHandler::AddCommonLocalizedStringsToSource(source);
Henrique Limasbc7b1ba2019-05-22 22:35:5574
Lei Zhang6af63c262019-11-22 02:07:0375 static constexpr webui::LocalizedString kStrings[] = {
Yann Dago7a25b6f2020-05-14 01:09:2476 // Localized strings (alphabetical order).
Jérôme Gingras4b90f6fc2020-05-28 18:48:5777 {"copyPoliciesJSON", IDS_COPY_POLICIES_JSON},
Yann Dago7a25b6f2020-05-14 01:09:2478 {"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. Patileb8c8a2b2022-11-16 18:29:22