1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
ash / webui / sanitize_ui / sanitize_ui.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/webui/sanitize_ui/sanitize_ui.h"
#include "ash/constants/ash_features.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/webui/common/trusted_types_util.h"
#include "ash/webui/grit/ash_sanitize_app_resources.h"
#include "ash/webui/grit/ash_sanitize_app_resources_map.h"
#include "ash/webui/sanitize_ui/sanitize_ui_delegate.h"
#include "ash/webui/sanitize_ui/url_constants.h"
#include "chromeos/ash/components/install_attributes/install_attributes.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/webui/resources/grit/webui_resources.h"
namespace {
// This function chooses which view should be shown based on the url. The done
// page is only shown if the url query is set to "done".
bool ShowDone(const GURL url) {
return url.has_query() && url.query() == "done";
}
} // namespace
namespace ash {
bool SanitizeDialogUIConfig::IsWebUIEnabled(
content::BrowserContext* browser_context) {
auto* session_controller = Shell::Get()->session_controller();
bool is_managed_user = session_controller->IsActiveAccountManaged();
bool is_child_user = session_controller->IsUserChild();
bool is_guest_mode_active = session_controller->IsUserGuest();
bool is_managed_device =
!ash::InstallAttributes::Get()->IsEnterpriseManaged();
return ChromeOSWebUIConfig::IsWebUIEnabled(browser_context) &&
is_managed_device && !is_managed_user && !is_guest_mode_active &&
!is_child_user &&
base::FeatureList::IsEnabled(ash::features::kSanitize);
}
class SanitizeSettingsResetter : public sanitize_ui::mojom::SettingsResetter {
public:
SanitizeSettingsResetter(std::unique_ptr<SanitizeUIDelegate> delegate) {
sanitize_ui_delegate_ = std::move(delegate);
}
void PerformSanitizeSettings() override {
if (sanitize_ui_delegate_) {
sanitize_ui_delegate_->PerformSanitizeSettings();
}
}
void BindInterface(
mojo::PendingReceiver<sanitize_ui::mojom::SettingsResetter> receiver) {
receiver_.reset();
receiver_.Bind(std::move(receiver));
}
void SetAttemptRestartForTesting( // IN-TEST
const base::RepeatingClosure& restart_attempt) {
sanitize_ui_delegate_->SetAttemptRestartForTesting( // IN-TEST
restart_attempt);
}
private:
std::unique_ptr<SanitizeUIDelegate> sanitize_ui_delegate_;
mojo::Receiver<sanitize_ui::mojom::SettingsResetter> receiver_{this};
};
SanitizeDialogUI::SanitizeDialogUI(
content::WebUI* web_ui,
std::unique_ptr<SanitizeUIDelegate> sanitize_ui_delegate)
: ui::MojoWebDialogUI(web_ui) {
sanitize_settings_resetter_ = std::make_unique<SanitizeSettingsResetter>(
std::move(sanitize_ui_delegate));
content::WebUIDataSource* html_source =
content::WebUIDataSource::CreateAndAdd(
web_ui->GetWebContents()->GetBrowserContext(),
kChromeUISanitizeAppHost);
html_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources chrome://webui-test 'self';");
ash::EnableTrustedTypesCSP(html_source);
html_source->UseStringsJs();
html_source->EnableReplaceI18nInJS();
html_source->AddResourcePaths(kAshSanitizeAppResources);
html_source->AddResourcePath("", IDR_ASH_SANITIZE_APP_INDEX_HTML);
html_source->AddResourcePath("test_loader.html", IDR_WEBUI_TEST_LOADER_HTML);
html_source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER_JS);
html_source->AddResourcePath("test_loader_util.js",
IDR_WEBUI_JS_TEST_LOADER_UTIL_JS);
webui::LocalizedString kLocalizedStrings[] = {
{"sanitizeDoneTitle", IDS_SANITIZE_DONE_HEADING},
{"sanitizeDoneExplanation", IDS_SANITIZE_DONE_DESCRIPTION},
{"sanitizeDoneRollback", IDS_SANITIZE_DONE_ROLLBACK},
{"sanitizeDoneButton", IDS_SANITIZE_DONE},
{"sanitizeDoneAccordionExtensionsTitle",
IDS_SANITIZE_DONE_ACCORDION_EXTENSIONS_TITLE},
{"sanitizeDoneAccordionExtensionsReenable",
IDS_SANITIZE_DONE_ACCORDION_EXTENSIONS_REENABLE},
{"sanitizeDoneAccordionChromeOsTitle",
IDS_SANITIZE_DONE_ACCORDION_CHROMEOS_TITLE},
{"sanitizeDoneAccordionChromeOsInput",
IDS_SANITIZE_DONE_ACCORDION_CHROMEOS_INPUT},
{"sanitizeDoneAccordionChromeOsNetwork",
IDS_SANITIZE_DONE_ACCORDION_CHROMEOS_NETWORK},
{"sanitizeDoneAccordionChromeTitle",
IDS_SANITIZE_DONE_ACCORDION_CHROME_TITLE},
{"sanitizeDoneAccordionChromeSiteContent",
IDS_SANITIZE_DONE_ACCORDION_CHROME_SITE_CONTENT},
{"sanitizeDoneAccordionChromeStartup",
IDS_SANITZIE_DONE_ACCORDION_CHROME_STARTUP},
{"sanitizeDoneAccordionChromeHomepage",
IDS_SANITIZE_DONE_ACCORDION_CHROME_HOMEPAGE},
{"sanitizeDoneAccordionChromeLanguages",
IDS_SANITIZE_DONE_ACCORDION_CHROME_LANGUAGES},
{"sanitizeDoneButtonExtensions", IDS_SANITIZE_DONE_BUTTON_EXTENSIONS},
{"sanitizeDoneButtonChromeOSInput",
IDS_SANITIZE_DONE_BUTTON_CHROMEOS_INPUT},
{"sanitizeDoneButtonChromeOSNetwork",
IDS_SANITIZE_DONE_BUTTON_CHROMEOS_NETWORK},
{"sanitizeDoneButtonChromeSiteContent",
IDS_SANITIZE_DONE_BUTTON_CHROME_SITE_CONTENT},
{"sanitizeDoneButtonChromeStartup",
IDS_SANITIZE_DONE_BUTTON_CHROME_STARTUP},
{"sanitizeDoneButtonChromeHomepage",
IDS_SANITIZE_DONE_BUTTON_CHROME_HOMEPAGE},
{"sanitizeDoneButtonChromeLanguages",
IDS_SANITIZE_DONE_BUTTON_CHROME_LANGUAGES},
{"sanitizeDescription", IDS_SANITIZE_DESCRIPTION},
{"sanitizeDialogTitle", IDS_SANITIZE_HEADING},
{"sanitizeDialogExplanation", IDS_SANITIZE_WARNING},
{"sanitizeDialogButton", IDS_SANITIZE},
{"sanitizeFeedback", IDS_SANITIZE_FEEDBACK},
{"sanitizeCancel", IDS_SANITIZE_CANCEL}};
html_source->AddLocalizedStrings(kLocalizedStrings);
html_source->AddBoolean("showDone",
ShowDone(web_ui->GetWebContents()->GetURL()));
}
SanitizeDialogUI::~SanitizeDialogUI() {}
void SanitizeDialogUI::BindInterface(
mojo::PendingReceiver<color_change_listener::mojom::PageHandler> receiver) {
color_provider_handler_ = std::make_unique<ui::ColorChangeHandler>(
web_ui()->GetWebContents(), std::move(receiver));
}
void SanitizeDialogUI::BindInterface(
mojo::PendingReceiver<sanitize_ui::mojom::SettingsResetter> receiver) {
sanitize_settings_resetter_->BindInterface(std::move(receiver));
}
void SanitizeDialogUI::SetAttemptRestartForTesting(
const base::RepeatingClosure& restart_attempt) {
sanitize_settings_resetter_->SetAttemptRestartForTesting( // IN-TEST
restart_attempt);
}
WEB_UI_CONTROLLER_TYPE_IMPL(SanitizeDialogUI)
} // namespace ash