Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / login / eula_screen_handler.cc
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.
4
5 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h"
6
7 #include <string>
8
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"
24 #include "url/gurl.h"
25
26 namespace {
27
28 const char kJsScreenPath[] = "login.EulaScreen";
29
30 // Helper class to tweak display details of credits pages in the context
31 // of OOBE/EULA step.
32 class CreditsWebDialog : public chromeos::LoginWebDialog {
33  public:
34   CreditsWebDialog(Profile* profile,
35                    gfx::NativeWindow parent_window,
36                    int title_id,
37                    const GURL& url)
38       : chromeos::LoginWebDialog(profile, NULL, parent_window,
39                                  l10n_util::GetStringUTF16(title_id),
40                                  url) {
41   }
42
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(
49           "(function () {"
50           "  document.body.classList.toggle('dialog', true);"
51           "  keyboard.initializeKeyboardFlow();"
52           "})");
53     }
54   }
55
56  private:
57   DISALLOW_COPY_AND_ASSIGN(CreditsWebDialog);
58 };
59
60 void ShowCreditsDialog(Profile* profile,
61                        gfx::NativeWindow parent_window,
62                        int title_id,
63                        const GURL& credits_url) {
64   CreditsWebDialog* dialog = new CreditsWebDialog(profile,
65                                                   parent_window,
66                                                   title_id,
67                                                   credits_url);
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));
73   dialog->Show();
74   // The dialog object will be deleted on dialog close.
75 }
76
77 }  // namespace
78
79 namespace chromeos {
80
81 EulaScreenHandler::EulaScreenHandler(CoreOobeActor* core_oobe_actor)
82     : BaseScreenHandler(kJsScreenPath),
83       delegate_(NULL),
84       core_oobe_actor_(core_oobe_actor),
85       show_on_init_(false) {
86 }
87
88 EulaScreenHandler::~EulaScreenHandler() {
89   if (delegate_)
90     delegate_->OnActorDestroyed(this);
91 }
92
93 void EulaScreenHandler::PrepareToShow() {
94 }
95
96 void EulaScreenHandler::Show() {
97   if (!page_is_ready()) {
98     show_on_init_ = true;
99     return;
100   }
101   ShowScreen(OobeUI::kScreenOobeEula, NULL);
102 }
103
104 void EulaScreenHandler::Hide() {
105 }
106
107 void EulaScreenHandler::SetDelegate(Delegate* delegate) {
108   delegate_ = delegate;
109   if (page_is_ready())
110     Initialize();
111 }
112
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,
132                 IDS_PRODUCT_NAME);
133   builder->AddF("eulaRlzEnable",
134                 IDS_EULA_RLZ_ENABLE,
135                 IDS_SHORT_PRODUCT_OS_NAME);
136 #endif
137
138   builder->Add("chromeCreditsLink", IDS_ABOUT_VERSION_LICENSE_EULA);
139   builder->Add("chromeosCreditsLink", IDS_ABOUT_CROS_VERSION_LICENSE_EULA);
140 }
141
142 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) {
143 #if defined(ENABLE_RLZ)
144   dict->SetString("rlzEnabled", "enabled");
145 #else
146   dict->SetString("rlzEnabled", "disabled");
147 #endif
148 }
149
150 void EulaScreenHandler::Initialize() {
151   if (!page_is_ready() || !delegate_)
152     return;
153
154   core_oobe_actor_->SetUsageStats(delegate_->IsUsageStatsEnabled());
155
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);
160
161   if (show_on_init_) {
162     Show();
163     show_on_init_ = false;
164   }
165 }
166
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);
177 }
178
179 void EulaScreenHandler::OnPasswordFetched(const std::string& tpm_password) {
180   core_oobe_actor_->SetTpmPassword(tpm_password);
181 }
182
183 void EulaScreenHandler::HandleOnExit(bool accepted, bool usage_stats_enabled) {
184   if (delegate_)
185     delegate_->OnExit(accepted, usage_stats_enabled);
186 }
187
188 void EulaScreenHandler::HandleOnLearnMore() {
189   if (!help_app_.get())
190     help_app_ = new HelpAppLauncher(GetNativeWindow());
191   help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE);
192 }
193
194 void EulaScreenHandler::HandleOnChromeOSCredits() {
195   ShowCreditsDialog(
196       Profile::FromBrowserContext(
197           web_ui()->GetWebContents()->GetBrowserContext()),
198       GetNativeWindow(),
199       IDS_ABOUT_CROS_VERSION_LICENSE_EULA,
200       GURL(chrome::kChromeUIOSCreditsURL));
201 }
202
203 void EulaScreenHandler::HandleOnChromeCredits() {
204   ShowCreditsDialog(
205       Profile::FromBrowserContext(
206           web_ui()->GetWebContents()->GetBrowserContext()),
207       GetNativeWindow(),
208       IDS_ABOUT_VERSION_LICENSE_EULA,
209       GURL(chrome::kChromeUICreditsURL));
210 }
211
212 void EulaScreenHandler::HandleOnInstallationSettingsPopupOpened() {
213   if (delegate_)
214     delegate_->InitiatePasswordFetch();
215 }
216
217 }  // namespace chromeos