[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[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" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
dpapad | 538e016 | 2020-12-17 23:06:23 | [diff] [blame] | 11 | #include "chrome/browser/ui/webui/policy/policy_ui_handler.h" |
Lei Zhang | 6af63c26 | 2019-11-22 02:07:03 | [diff] [blame] | 12 | #include "chrome/browser/ui/webui/webui_util.h" |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 13 | #include "chrome/common/url_constants.h" |
Samuel Huang | 1b99a06 | 2020-01-08 22:20:34 | [diff] [blame] | 14 | #include "components/grit/dev_ui_components_resources.h" |
thestig | 4a2e88e | 2016-08-27 23:23:51 | [diff] [blame] | 15 | #include "components/strings/grit/components_strings.h" |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 16 | #include "content/public/browser/web_ui.h" |
Rebekah Potter | f6b2f26 | 2022-05-27 21:43:19 | [diff] [blame^] | 17 | #include "services/network/public/mojom/content_security_policy.mojom.h" |
Rohit Rao | e38fb48 | 2020-01-19 21:35:14 | [diff] [blame] | 18 | #include "ui/base/webui/web_ui_util.h" |
[email protected] | 8a2166d9 | 2012-12-06 23:58:45 | [diff] [blame] | 19 | |
[email protected] | a8ac9bd2 | 2012-05-02 12:30:37 | [diff] [blame] | 20 | namespace { |
[email protected] | 0ec4898e | 2011-12-30 21:09:24 | [diff] [blame] | 21 | |
fhorschig | 07c5e062 | 2015-12-03 16:48:57 | [diff] [blame] | 22 | content::WebUIDataSource* CreatePolicyUIHtmlSource() { |
| 23 | content::WebUIDataSource* source = |
| 24 | content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost); |
| 25 | PolicyUIHandler::AddCommonLocalizedStringsToSource(source); |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 26 | |
Lei Zhang | 6af63c26 | 2019-11-22 02:07:03 | [diff] [blame] | 27 | static constexpr webui::LocalizedString kStrings[] = { |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 28 | // Localized strings (alphabetical order). |
Jérôme Gingras | 4b90f6fc | 2020-05-28 18:48:57 | [diff] [blame] | 29 | {"copyPoliciesJSON", IDS_COPY_POLICIES_JSON}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 30 | {"exportPoliciesJSON", IDS_EXPORT_POLICIES_JSON}, |
| 31 | {"filterPlaceholder", IDS_POLICY_FILTER_PLACEHOLDER}, |
| 32 | {"hideExpandedStatus", IDS_POLICY_HIDE_EXPANDED_STATUS}, |
| 33 | {"isAffiliatedYes", IDS_POLICY_IS_AFFILIATED_YES}, |
| 34 | {"isAffiliatedNo", IDS_POLICY_IS_AFFILIATED_NO}, |
| 35 | {"labelAssetId", IDS_POLICY_LABEL_ASSET_ID}, |
| 36 | {"labelClientId", IDS_POLICY_LABEL_CLIENT_ID}, |
| 37 | {"labelDirectoryApiId", IDS_POLICY_LABEL_DIRECTORY_API_ID}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 38 | {"labelGaiaId", IDS_POLICY_LABEL_GAIA_ID}, |
| 39 | {"labelIsAffiliated", IDS_POLICY_LABEL_IS_AFFILIATED}, |
| 40 | {"labelLocation", IDS_POLICY_LABEL_LOCATION}, |
| 41 | {"labelMachineEnrollmentDomain", |
| 42 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DOMAIN}, |
| 43 | {"labelMachineEnrollmentMachineName", |
| 44 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_MACHINE_NAME}, |
| 45 | {"labelMachineEnrollmentToken", IDS_POLICY_LABEL_MACHINE_ENROLLMENT_TOKEN}, |
| 46 | {"labelMachineEntrollmentDeviceId", |
| 47 | IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DEVICE_ID}, |
| 48 | {"labelIsOffHoursActive", IDS_POLICY_LABEL_IS_OFFHOURS_ACTIVE}, |
| 49 | {"labelPoliciesPush", IDS_POLICY_LABEL_PUSH_POLICIES}, |
Igor Ruvinov | 129ad8c | 2021-11-05 19:35:40 | [diff] [blame] | 50 | {"labelPrecedence", IDS_POLICY_LABEL_PRECEDENCE}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 51 | {"labelRefreshInterval", IDS_POLICY_LABEL_REFRESH_INTERVAL}, |
| 52 | {"labelStatus", IDS_POLICY_LABEL_STATUS}, |
Sergiy Belozorov | ff0a940 | 2022-03-08 17:58:24 | [diff] [blame] | 53 | {"labelTimeSinceLastFetchAttempt", |
| 54 | IDS_POLICY_LABEL_TIME_SINCE_LAST_FETCH_ATTEMPT}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 55 | {"labelTimeSinceLastRefresh", IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH}, |
| 56 | {"labelUsername", IDS_POLICY_LABEL_USERNAME}, |
Jana Grill | 81c20295 | 2021-02-08 11:57:38 | [diff] [blame] | 57 | {"labelManagedBy", IDS_POLICY_LABEL_MANAGED_BY}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 58 | {"labelVersion", IDS_POLICY_LABEL_VERSION}, |
| 59 | {"noPoliciesSet", IDS_POLICY_NO_POLICIES_SET}, |
| 60 | {"offHoursActive", IDS_POLICY_OFFHOURS_ACTIVE}, |
| 61 | {"offHoursNotActive", IDS_POLICY_OFFHOURS_NOT_ACTIVE}, |
Jérôme Gingras | 272c1f7d | 2020-05-27 16:35:50 | [diff] [blame] | 62 | {"policyCopyValue", IDS_POLICY_COPY_VALUE}, |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 63 | {"policiesPushOff", IDS_POLICY_PUSH_POLICIES_OFF}, |
| 64 | {"policiesPushOn", IDS_POLICY_PUSH_POLICIES_ON}, |
| 65 | {"policyLearnMore", IDS_POLICY_LEARN_MORE}, |
| 66 | {"reloadPolicies", IDS_POLICY_RELOAD_POLICIES}, |
| 67 | {"showExpandedStatus", IDS_POLICY_SHOW_EXPANDED_STATUS}, |
| 68 | {"showLess", IDS_POLICY_SHOW_LESS}, |
| 69 | {"showMore", IDS_POLICY_SHOW_MORE}, |
| 70 | {"showUnset", IDS_POLICY_SHOW_UNSET}, |
| 71 | {"signinProfile", IDS_POLICY_SIGNIN_PROFILE}, |
| 72 | {"status", IDS_POLICY_STATUS}, |
| 73 | {"statusDevice", IDS_POLICY_STATUS_DEVICE}, |
| 74 | {"statusMachine", IDS_POLICY_STATUS_MACHINE}, |
Xiaohan Wang | e9439fd | 2022-01-18 21:00:31 | [diff] [blame] | 75 | #if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) |
Yann Dago | 7a25b6f | 2020-05-14 01:09:24 | [diff] [blame] | 76 | {"statusUpdater", IDS_POLICY_STATUS_UPDATER}, |
| 77 | #endif |
| 78 | {"statusUser", IDS_POLICY_STATUS_USER}, |
Jin Young Hur | 15e75ab5 | 2021-05-07 15:02:55 | [diff] [blame] | 79 | {"labelLastCloudReportSentTimestamp", |
| 80 | IDS_POLICY_LABEL_LAST_CLOUD_REPORT_SENT_TIMESTAMP}, |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 81 | }; |
dpapad | f61285c | 2021-02-09 21:56:39 | [diff] [blame] | 82 | source->AddLocalizedStrings(kStrings); |
Henrique Limas | bc7b1ba | 2019-05-22 22:35:55 | [diff] [blame] | 83 | |
[email protected] | 3dbd64d | 2013-01-19 23:05:16 | [diff] [blame] | 84 | source->AddResourcePath("policy.css", IDR_POLICY_CSS); |
Anton Urusov | eb2d381 | 2017-08-24 20:01:02 | [diff] [blame] | 85 | source->AddResourcePath("policy_base.js", IDR_POLICY_BASE_JS); |
[email protected] | 3dbd64d | 2013-01-19 23:05:16 | [diff] [blame] | 86 | source->AddResourcePath("policy.js", IDR_POLICY_JS); |
Rebekah Potter | f6b2f26 | 2022-05-27 21:43:19 | [diff] [blame^] | 87 | source->AddResourcePath("policy_conflict.js", IDR_POLICY_POLICY_CONFLICT_JS); |
| 88 | source->AddResourcePath("policy_row.js", IDR_POLICY_POLICY_ROW_JS); |
| 89 | source->AddResourcePath("policy_precedence_row.js", |
| 90 | IDR_POLICY_POLICY_PRECEDENCE_ROW_JS); |
| 91 | source->AddResourcePath("policy_table.js", IDR_POLICY_POLICY_TABLE_JS); |
| 92 | source->AddResourcePath("status_box.js", IDR_POLICY_STATUS_BOX_JS); |
[email protected] | 3dbd64d | 2013-01-19 23:05:16 | [diff] [blame] | 93 | source->SetDefaultResource(IDR_POLICY_HTML); |
Rebekah Potter | f6b2f26 | 2022-05-27 21:43:19 | [diff] [blame^] | 94 | |
| 95 | source->EnableReplaceI18nInJS(); |
| 96 | source->OverrideContentSecurityPolicy( |
| 97 | network::mojom::CSPDirectiveName::TrustedTypes, |
| 98 | "trusted-types static-types;"); |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 99 | return source; |
| 100 | } |
| 101 | |
[email protected] | 8a2166d9 | 2012-12-06 23:58:45 | [diff] [blame] | 102 | } // namespace |
| 103 | |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 104 | PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 105 | web_ui->AddMessageHandler(std::make_unique<PolicyUIHandler>()); |
[email protected] | c79f3c27 | 2013-02-05 11:51:53 | [diff] [blame] | 106 | content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
fhorschig | c9018a4fe | 2015-10-07 08:41:50 | [diff] [blame] | 107 | CreatePolicyUIHtmlSource()); |
[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame] | 108 | } |
| 109 | |
Jérôme Gingras | 272c1f7d | 2020-05-27 16:35:50 | [diff] [blame] | 110 | PolicyUI::~PolicyUI() = default; |