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),
41 chromeos::LoginWebDialog::STYLE_BUBBLE) {
44 virtual void OnLoadingStateChanged(content::WebContents* source) OVERRIDE {
45 chromeos::LoginWebDialog::OnLoadingStateChanged(source);
46 // Remove visual elements that we can handle in EULA page.
47 bool is_loading = source->IsLoading();
48 if (!is_loading && source->GetWebUI()) {
49 source->GetWebUI()->CallJavascriptFunction(
51 " document.body.classList.toggle('dialog', true);"
52 " keyboard.initializeKeyboardFlow();"
58 DISALLOW_COPY_AND_ASSIGN(CreditsWebDialog);
61 void ShowCreditsDialog(Profile* profile,
62 gfx::NativeWindow parent_window,
64 const GURL& credits_url) {
65 CreditsWebDialog* dialog = new CreditsWebDialog(profile,
69 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
70 dialog->SetDialogSize(l10n_util::GetLocalizedContentsWidthInPixels(
71 IDS_CREDITS_APP_DIALOG_WIDTH_PIXELS),
72 l10n_util::GetLocalizedContentsWidthInPixels(
73 IDS_CREDITS_APP_DIALOG_HEIGHT_PIXELS));
75 // The dialog object will be deleted on dialog close.
82 EulaScreenHandler::EulaScreenHandler(CoreOobeActor* core_oobe_actor)
83 : BaseScreenHandler(kJsScreenPath),
85 core_oobe_actor_(core_oobe_actor),
86 show_on_init_(false) {
89 EulaScreenHandler::~EulaScreenHandler() {
91 delegate_->OnActorDestroyed(this);
94 void EulaScreenHandler::PrepareToShow() {
97 void EulaScreenHandler::Show() {
98 if (!page_is_ready()) {
102 ShowScreen(OobeUI::kScreenOobeEula, NULL);
105 void EulaScreenHandler::Hide() {
108 void EulaScreenHandler::SetDelegate(Delegate* delegate) {
109 delegate_ = delegate;
114 void EulaScreenHandler::DeclareLocalizedValues(
115 LocalizedValuesBuilder* builder) {
116 builder->Add("eulaScreenTitle", IDS_EULA_SCREEN_TITLE);
117 builder->Add("eulaScreenAccessibleTitle", IDS_EULA_SCREEN_ACCESSIBLE_TITLE);
118 builder->Add("checkboxLogging", IDS_EULA_CHECKBOX_ENABLE_LOGGING);
119 builder->Add("back", IDS_EULA_BACK_BUTTON);
120 builder->Add("acceptAgreement", IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON);
121 builder->Add("eulaSystemInstallationSettings",
122 IDS_EULA_SYSTEM_SECURITY_SETTING);
123 builder->Add("eulaTpmDesc", IDS_EULA_TPM_DESCRIPTION);
124 builder->Add("eulaTpmKeyDesc", IDS_EULA_TPM_KEY_DESCRIPTION);
125 builder->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH);
126 builder->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY);
127 builder->Add("eulaSystemInstallationSettingsOkButton", IDS_OK);
128 builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING);
129 #if defined(ENABLE_RLZ)
130 builder->AddF("eulaRlzDesc",
131 IDS_EULA_RLZ_DESCRIPTION,
132 IDS_SHORT_PRODUCT_NAME,
134 builder->AddF("eulaRlzEnable",
136 IDS_SHORT_PRODUCT_OS_NAME);
139 builder->Add("chromeCreditsLink", IDS_ABOUT_VERSION_LICENSE_EULA);
140 builder->Add("chromeosCreditsLink", IDS_ABOUT_CROS_VERSION_LICENSE_EULA);
143 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) {
144 #if defined(ENABLE_RLZ)
145 dict->SetString("rlzEnabled", "enabled");
147 dict->SetString("rlzEnabled", "disabled");
151 void EulaScreenHandler::Initialize() {
152 if (!page_is_ready() || !delegate_)
155 core_oobe_actor_->SetUsageStats(delegate_->IsUsageStatsEnabled());
157 // This OEM EULA is a file:// URL which we're unable to load in iframe.
158 // Instead if it's defined we use chrome://terms/oem that will load same file.
159 if (!delegate_->GetOemEulaUrl().is_empty())
160 core_oobe_actor_->SetOemEulaUrl(chrome::kChromeUITermsOemURL);
164 show_on_init_ = false;
168 void EulaScreenHandler::RegisterMessages() {
169 AddCallback("eulaOnExit", &EulaScreenHandler::HandleOnExit);
170 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore);
171 AddCallback("eulaOnChromeOSCredits",
172 &EulaScreenHandler::HandleOnChromeOSCredits);
173 AddCallback("eulaOnChromeCredits",
174 &EulaScreenHandler::HandleOnChromeCredits);
175 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore);
176 AddCallback("eulaOnInstallationSettingsPopupOpened",
177 &EulaScreenHandler::HandleOnInstallationSettingsPopupOpened);
180 void EulaScreenHandler::OnPasswordFetched(const std::string& tpm_password) {
181 core_oobe_actor_->SetTpmPassword(tpm_password);
184 void EulaScreenHandler::HandleOnExit(bool accepted, bool usage_stats_enabled) {
186 delegate_->OnExit(accepted, usage_stats_enabled);
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 delegate_->InitiatePasswordFetch();
218 } // namespace chromeos