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/ui/login_web_dialog.h"
14 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
17 #include "chrome/common/url_constants.h"
18 #include "chrome/grit/chromium_strings.h"
19 #include "chrome/grit/generated_resources.h"
20 #include "chrome/grit/locale_settings.h"
21 #include "content/public/browser/web_contents.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/views/widget/widget.h"
28 const char kJsScreenPath[] = "login.EulaScreen";
30 // Helper class to tweak display details of credits pages in the context
32 class CreditsWebDialog : public chromeos::LoginWebDialog {
34 CreditsWebDialog(Profile* profile,
35 gfx::NativeWindow parent_window,
38 : chromeos::LoginWebDialog(profile, NULL, parent_window,
39 l10n_util::GetStringUTF16(title_id),
43 virtual void OnLoadingStateChanged(content::WebContents* source) override {
44 chromeos::LoginWebDialog::OnLoadingStateChanged(source);
45 // Remove visual elements that we can handle in EULA page.
46 bool is_loading = source->IsLoading();
47 if (!is_loading && source->GetWebUI()) {
48 source->GetWebUI()->CallJavascriptFunction(
50 " document.body.classList.toggle('dialog', true);"
51 " keyboard.initializeKeyboardFlow();"
57 DISALLOW_COPY_AND_ASSIGN(CreditsWebDialog);
60 void ShowCreditsDialog(Profile* profile,
61 gfx::NativeWindow parent_window,
63 const GURL& credits_url) {
64 CreditsWebDialog* dialog = new CreditsWebDialog(profile,
68 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
69 dialog->SetDialogSize(l10n_util::GetLocalizedContentsWidthInPixels(
70 IDS_CREDITS_APP_DIALOG_WIDTH_PIXELS),
71 l10n_util::GetLocalizedContentsWidthInPixels(
72 IDS_CREDITS_APP_DIALOG_HEIGHT_PIXELS));
74 // The dialog object will be deleted on dialog close.
81 EulaScreenHandler::EulaScreenHandler(CoreOobeActor* core_oobe_actor)
82 : BaseScreenHandler(kJsScreenPath),
84 core_oobe_actor_(core_oobe_actor),
85 show_on_init_(false) {
88 EulaScreenHandler::~EulaScreenHandler() {
90 delegate_->OnActorDestroyed(this);
93 void EulaScreenHandler::PrepareToShow() {
96 void EulaScreenHandler::Show() {
97 if (!page_is_ready()) {
101 ShowScreen(OobeUI::kScreenOobeEula, NULL);
104 void EulaScreenHandler::Hide() {
107 void EulaScreenHandler::SetDelegate(Delegate* delegate) {
108 delegate_ = delegate;
113 void EulaScreenHandler::DeclareLocalizedValues(
114 LocalizedValuesBuilder* builder) {
115 builder->Add("eulaScreenTitle", IDS_EULA_SCREEN_TITLE);
116 builder->Add("eulaScreenAccessibleTitle", IDS_EULA_SCREEN_ACCESSIBLE_TITLE);
117 builder->Add("checkboxLogging", IDS_EULA_CHECKBOX_ENABLE_LOGGING);
118 builder->Add("back", IDS_EULA_BACK_BUTTON);
119 builder->Add("acceptAgreement", IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON);
120 builder->Add("eulaSystemInstallationSettings",
121 IDS_EULA_SYSTEM_SECURITY_SETTING);
122 builder->Add("eulaTpmDesc", IDS_EULA_TPM_DESCRIPTION);
123 builder->Add("eulaTpmKeyDesc", IDS_EULA_TPM_KEY_DESCRIPTION);
124 builder->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH);
125 builder->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY);
126 builder->Add("eulaSystemInstallationSettingsOkButton", IDS_OK);
127 builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING);
128 #if defined(ENABLE_RLZ)
129 builder->AddF("eulaRlzDesc",
130 IDS_EULA_RLZ_DESCRIPTION,
131 IDS_SHORT_PRODUCT_NAME,
133 builder->AddF("eulaRlzEnable",
135 IDS_SHORT_PRODUCT_OS_NAME);
138 builder->Add("chromeCreditsLink", IDS_ABOUT_VERSION_LICENSE_EULA);
139 builder->Add("chromeosCreditsLink", IDS_ABOUT_CROS_VERSION_LICENSE_EULA);
142 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) {
143 #if defined(ENABLE_RLZ)
144 dict->SetString("rlzEnabled", "enabled");
146 dict->SetString("rlzEnabled", "disabled");
150 void EulaScreenHandler::Initialize() {
151 if (!page_is_ready() || !delegate_)
154 core_oobe_actor_->SetUsageStats(delegate_->IsUsageStatsEnabled());
156 // This OEM EULA is a file:// URL which we're unable to load in iframe.
157 // Instead if it's defined we use chrome://terms/oem that will load same file.
158 if (!delegate_->GetOemEulaUrl().is_empty())
159 core_oobe_actor_->SetOemEulaUrl(chrome::kChromeUITermsOemURL);
163 show_on_init_ = false;
167 void EulaScreenHandler::RegisterMessages() {
168 AddCallback("eulaOnExit", &EulaScreenHandler::HandleOnExit);
169 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore);
170 AddCallback("eulaOnChromeOSCredits",
171 &EulaScreenHandler::HandleOnChromeOSCredits);
172 AddCallback("eulaOnChromeCredits",
173 &EulaScreenHandler::HandleOnChromeCredits);
174 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore);
175 AddCallback("eulaOnInstallationSettingsPopupOpened",
176 &EulaScreenHandler::HandleOnInstallationSettingsPopupOpened);
179 void EulaScreenHandler::OnPasswordFetched(const std::string& tpm_password) {
180 core_oobe_actor_->SetTpmPassword(tpm_password);
183 void EulaScreenHandler::HandleOnExit(bool accepted, bool usage_stats_enabled) {
185 delegate_->OnExit(accepted, usage_stats_enabled);
188 void EulaScreenHandler::HandleOnLearnMore() {
189 if (!help_app_.get())
190 help_app_ = new HelpAppLauncher(GetNativeWindow());
191 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE);
194 void EulaScreenHandler::HandleOnChromeOSCredits() {
196 Profile::FromBrowserContext(
197 web_ui()->GetWebContents()->GetBrowserContext()),
199 IDS_ABOUT_CROS_VERSION_LICENSE_EULA,
200 GURL(chrome::kChromeUIOSCreditsURL));
203 void EulaScreenHandler::HandleOnChromeCredits() {
205 Profile::FromBrowserContext(
206 web_ui()->GetWebContents()->GetBrowserContext()),
208 IDS_ABOUT_VERSION_LICENSE_EULA,
209 GURL(chrome::kChromeUICreditsURL));
212 void EulaScreenHandler::HandleOnInstallationSettingsPopupOpened() {
214 delegate_->InitiatePasswordFetch();
217 } // namespace chromeos