1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/login/help_app_launcher.h"
11 #include "chrome/browser/chromeos/login/helper.h"
12 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h"
13 #include "chrome/browser/chromeos/login/screens/eula_model.h"
14 #include "chrome/browser/chromeos/login/ui/login_web_dialog.h"
15 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/chromium_strings.h"
20 #include "chrome/grit/generated_resources.h"
21 #include "chrome/grit/locale_settings.h"
22 #include "components/login/localized_values_builder.h"
23 #include "content/public/browser/web_contents.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/views/widget/widget.h"
30 const char kJsScreenPath
[] = "login.EulaScreen";
32 // Helper class to tweak display details of credits pages in the context
34 class CreditsWebDialog
: public chromeos::LoginWebDialog
{
36 CreditsWebDialog(Profile
* profile
,
37 gfx::NativeWindow parent_window
,
40 : chromeos::LoginWebDialog(profile
, NULL
, parent_window
,
41 l10n_util::GetStringUTF16(title_id
),
45 void OnLoadingStateChanged(content::WebContents
* source
) override
{
46 chromeos::LoginWebDialog::OnLoadingStateChanged(source
);
47 // Remove visual elements that we can handle in EULA page.
48 bool is_loading
= source
->IsLoading();
49 if (!is_loading
&& source
->GetWebUI()) {
50 source
->GetWebUI()->CallJavascriptFunction(
52 " document.body.classList.toggle('dialog', true);"
53 " keyboard.initializeKeyboardFlow();"
59 DISALLOW_COPY_AND_ASSIGN(CreditsWebDialog
);
62 void ShowCreditsDialog(Profile
* profile
,
63 gfx::NativeWindow parent_window
,
65 const GURL
& credits_url
) {
66 CreditsWebDialog
* dialog
= new CreditsWebDialog(profile
,
70 gfx::Rect
screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
71 dialog
->SetDialogSize(l10n_util::GetLocalizedContentsWidthInPixels(
72 IDS_CREDITS_APP_DIALOG_WIDTH_PIXELS
),
73 l10n_util::GetLocalizedContentsWidthInPixels(
74 IDS_CREDITS_APP_DIALOG_HEIGHT_PIXELS
));
76 // The dialog object will be deleted on dialog close.
83 EulaScreenHandler::EulaScreenHandler(CoreOobeActor
* core_oobe_actor
)
84 : BaseScreenHandler(kJsScreenPath
),
86 core_oobe_actor_(core_oobe_actor
),
87 show_on_init_(false) {
90 EulaScreenHandler::~EulaScreenHandler() {
92 model_
->OnViewDestroyed(this);
95 void EulaScreenHandler::PrepareToShow() {
98 void EulaScreenHandler::Show() {
99 if (!page_is_ready()) {
100 show_on_init_
= true;
103 ShowScreen(OobeUI::kScreenOobeEula
, NULL
);
106 void EulaScreenHandler::Hide() {
109 void EulaScreenHandler::Bind(EulaModel
& model
) {
111 BaseScreenHandler::SetBaseScreen(model_
);
116 void EulaScreenHandler::Unbind() {
118 BaseScreenHandler::SetBaseScreen(nullptr);
121 void EulaScreenHandler::DeclareLocalizedValues(
122 ::login::LocalizedValuesBuilder
* builder
) {
123 builder
->Add("eulaScreenTitle", IDS_EULA_SCREEN_TITLE
);
124 builder
->Add("eulaScreenAccessibleTitle", IDS_EULA_SCREEN_ACCESSIBLE_TITLE
);
125 builder
->Add("checkboxLogging", IDS_EULA_CHECKBOX_ENABLE_LOGGING
);
126 builder
->Add("back", IDS_EULA_BACK_BUTTON
);
127 builder
->Add("acceptAgreement", IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON
);
128 builder
->Add("eulaSystemInstallationSettings",
129 IDS_EULA_SYSTEM_SECURITY_SETTING
);
130 builder
->Add("eulaTpmDesc", IDS_EULA_TPM_DESCRIPTION
);
131 builder
->Add("eulaTpmKeyDesc", IDS_EULA_TPM_KEY_DESCRIPTION
);
132 builder
->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH
);
133 builder
->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY
);
134 builder
->Add("eulaSystemInstallationSettingsOkButton", IDS_OK
);
135 builder
->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING
);
136 #if defined(ENABLE_RLZ)
137 builder
->AddF("eulaRlzDesc",
138 IDS_EULA_RLZ_DESCRIPTION
,
139 IDS_SHORT_PRODUCT_NAME
,
141 builder
->AddF("eulaRlzEnable",
143 IDS_SHORT_PRODUCT_OS_NAME
);
146 builder
->Add("chromeCreditsLink", IDS_ABOUT_VERSION_LICENSE_EULA
);
147 builder
->Add("chromeosCreditsLink", IDS_ABOUT_CROS_VERSION_LICENSE_EULA
);
150 void EulaScreenHandler::DeclareJSCallbacks() {
151 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore
);
152 AddCallback("eulaOnChromeOSCredits",
153 &EulaScreenHandler::HandleOnChromeOSCredits
);
154 AddCallback("eulaOnChromeCredits", &EulaScreenHandler::HandleOnChromeCredits
);
155 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore
);
156 AddCallback("eulaOnInstallationSettingsPopupOpened",
157 &EulaScreenHandler::HandleOnInstallationSettingsPopupOpened
);
160 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue
* dict
) {
161 #if defined(ENABLE_RLZ)
162 dict
->SetString("rlzEnabled", "enabled");
164 dict
->SetString("rlzEnabled", "disabled");
168 void EulaScreenHandler::Initialize() {
169 if (!page_is_ready() || !model_
)
172 core_oobe_actor_
->SetUsageStats(model_
->IsUsageStatsEnabled());
174 // This OEM EULA is a file:// URL which we're unable to load in iframe.
175 // Instead if it's defined we use chrome://terms/oem that will load same file.
176 if (!model_
->GetOemEulaUrl().is_empty())
177 core_oobe_actor_
->SetOemEulaUrl(chrome::kChromeUITermsOemURL
);
181 show_on_init_
= false;
185 void EulaScreenHandler::OnPasswordFetched(const std::string
& tpm_password
) {
186 core_oobe_actor_
->SetTpmPassword(tpm_password
);
189 void EulaScreenHandler::HandleOnLearnMore() {
190 if (!help_app_
.get())
191 help_app_
= new HelpAppLauncher(GetNativeWindow());
192 help_app_
->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE
);
195 void EulaScreenHandler::HandleOnChromeOSCredits() {
197 Profile::FromBrowserContext(
198 web_ui()->GetWebContents()->GetBrowserContext()),
200 IDS_ABOUT_CROS_VERSION_LICENSE_EULA
,
201 GURL(chrome::kChromeUIOSCreditsURL
));
204 void EulaScreenHandler::HandleOnChromeCredits() {
206 Profile::FromBrowserContext(
207 web_ui()->GetWebContents()->GetBrowserContext()),
209 IDS_ABOUT_VERSION_LICENSE_EULA
,
210 GURL(chrome::kChromeUICreditsURL
));
213 void EulaScreenHandler::HandleOnInstallationSettingsPopupOpened() {
215 model_
->InitiatePasswordFetch();
218 } // namespace chromeos