OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chromeos/login/help_app_launcher.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/login_web_dialog.h" |
10 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" | 13 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" |
11 #include "chrome/browser/chromeos/login/webui_login_display.h" | 14 #include "chrome/browser/chromeos/login/webui_login_display.h" |
12 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 15 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
13 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/web_contents.h" |
14 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
15 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
16 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 21 #include "grit/locale_settings.h" |
| 22 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 #include "url/gurl.h" |
18 | 25 |
19 namespace { | 26 namespace { |
20 | 27 |
21 const char kJsScreenPath[] = "login.EulaScreen"; | 28 const char kJsScreenPath[] = "login.EulaScreen"; |
22 | 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 chromeos::LoginWebDialog::STYLE_BUBBLE) { |
| 42 } |
| 43 |
| 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( |
| 50 "(function () {" |
| 51 " document.body.classList.toggle('dialog', true);" |
| 52 " keyboard.initializeKeyboardFlow();" |
| 53 "})"); |
| 54 } |
| 55 } |
| 56 |
| 57 private: |
| 58 DISALLOW_COPY_AND_ASSIGN(CreditsWebDialog); |
| 59 }; |
| 60 |
| 61 void ShowCreditsDialog(Profile* profile, |
| 62 gfx::NativeWindow parent_window, |
| 63 int title_id, |
| 64 const GURL& credits_url) { |
| 65 CreditsWebDialog* dialog = new CreditsWebDialog(profile, |
| 66 parent_window, |
| 67 title_id, |
| 68 credits_url); |
| 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)); |
| 74 dialog->Show(); |
| 75 // The dialog object will be deleted on dialog close. |
| 76 } |
| 77 |
23 } // namespace | 78 } // namespace |
24 | 79 |
25 namespace chromeos { | 80 namespace chromeos { |
26 | 81 |
27 EulaScreenHandler::EulaScreenHandler(CoreOobeActor* core_oobe_actor) | 82 EulaScreenHandler::EulaScreenHandler(CoreOobeActor* core_oobe_actor) |
28 : BaseScreenHandler(kJsScreenPath), | 83 : BaseScreenHandler(kJsScreenPath), |
29 delegate_(NULL), | 84 delegate_(NULL), |
30 core_oobe_actor_(core_oobe_actor), | 85 core_oobe_actor_(core_oobe_actor), |
31 show_on_init_(false) { | 86 show_on_init_(false) { |
32 } | 87 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING); | 130 builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING); |
76 #if defined(ENABLE_RLZ) | 131 #if defined(ENABLE_RLZ) |
77 builder->AddF("eulaRlzDesc", | 132 builder->AddF("eulaRlzDesc", |
78 IDS_EULA_RLZ_DESCRIPTION, | 133 IDS_EULA_RLZ_DESCRIPTION, |
79 IDS_SHORT_PRODUCT_NAME, | 134 IDS_SHORT_PRODUCT_NAME, |
80 IDS_PRODUCT_NAME); | 135 IDS_PRODUCT_NAME); |
81 builder->AddF("eulaRlzEnable", | 136 builder->AddF("eulaRlzEnable", |
82 IDS_EULA_RLZ_ENABLE, | 137 IDS_EULA_RLZ_ENABLE, |
83 IDS_SHORT_PRODUCT_OS_NAME); | 138 IDS_SHORT_PRODUCT_OS_NAME); |
84 #endif | 139 #endif |
| 140 |
| 141 builder->Add("chromeCreditsLink", IDS_ABOUT_VERSION_LICENSE_EULA); |
| 142 builder->Add("chromeosCreditsLink", IDS_ABOUT_CROS_VERSION_LICENSE_EULA); |
85 } | 143 } |
86 | 144 |
87 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) { | 145 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) { |
88 #if defined(ENABLE_RLZ) | 146 #if defined(ENABLE_RLZ) |
89 dict->SetString("rlzEnabled", "enabled"); | 147 dict->SetString("rlzEnabled", "enabled"); |
90 #else | 148 #else |
91 dict->SetString("rlzEnabled", "disabled"); | 149 dict->SetString("rlzEnabled", "disabled"); |
92 #endif | 150 #endif |
93 } | 151 } |
94 | 152 |
(...skipping 10 matching lines...) Expand all Loading... |
105 | 163 |
106 if (show_on_init_) { | 164 if (show_on_init_) { |
107 Show(); | 165 Show(); |
108 show_on_init_ = false; | 166 show_on_init_ = false; |
109 } | 167 } |
110 } | 168 } |
111 | 169 |
112 void EulaScreenHandler::RegisterMessages() { | 170 void EulaScreenHandler::RegisterMessages() { |
113 AddCallback("eulaOnExit", &EulaScreenHandler::HandleOnExit); | 171 AddCallback("eulaOnExit", &EulaScreenHandler::HandleOnExit); |
114 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore); | 172 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore); |
| 173 AddCallback("eulaOnChromeOSCredits", |
| 174 &EulaScreenHandler::HandleOnChromeOSCredits); |
| 175 AddCallback("eulaOnChromeCredits", |
| 176 &EulaScreenHandler::HandleOnChromeCredits); |
| 177 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore); |
115 AddCallback("eulaOnInstallationSettingsPopupOpened", | 178 AddCallback("eulaOnInstallationSettingsPopupOpened", |
116 &EulaScreenHandler::HandleOnInstallationSettingsPopupOpened); | 179 &EulaScreenHandler::HandleOnInstallationSettingsPopupOpened); |
117 } | 180 } |
118 | 181 |
119 void EulaScreenHandler::OnPasswordFetched(const std::string& tpm_password) { | 182 void EulaScreenHandler::OnPasswordFetched(const std::string& tpm_password) { |
120 core_oobe_actor_->SetTpmPassword(tpm_password); | 183 core_oobe_actor_->SetTpmPassword(tpm_password); |
121 } | 184 } |
122 | 185 |
123 void EulaScreenHandler::HandleOnExit(bool accepted, bool usage_stats_enabled) { | 186 void EulaScreenHandler::HandleOnExit(bool accepted, bool usage_stats_enabled) { |
124 if (delegate_) | 187 if (delegate_) |
125 delegate_->OnExit(accepted, usage_stats_enabled); | 188 delegate_->OnExit(accepted, usage_stats_enabled); |
126 } | 189 } |
127 | 190 |
128 void EulaScreenHandler::HandleOnLearnMore() { | 191 void EulaScreenHandler::HandleOnLearnMore() { |
129 if (!help_app_.get()) | 192 if (!help_app_.get()) |
130 help_app_ = new HelpAppLauncher(GetNativeWindow()); | 193 help_app_ = new HelpAppLauncher(GetNativeWindow()); |
131 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE); | 194 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE); |
132 } | 195 } |
133 | 196 |
| 197 void EulaScreenHandler::HandleOnChromeOSCredits() { |
| 198 ShowCreditsDialog( |
| 199 Profile::FromBrowserContext( |
| 200 web_ui()->GetWebContents()->GetBrowserContext()), |
| 201 GetNativeWindow(), |
| 202 IDS_ABOUT_CROS_VERSION_LICENSE_EULA, |
| 203 GURL(chrome::kChromeUIOSCreditsURL)); |
| 204 } |
| 205 |
| 206 void EulaScreenHandler::HandleOnChromeCredits() { |
| 207 ShowCreditsDialog( |
| 208 Profile::FromBrowserContext( |
| 209 web_ui()->GetWebContents()->GetBrowserContext()), |
| 210 GetNativeWindow(), |
| 211 IDS_ABOUT_VERSION_LICENSE_EULA, |
| 212 GURL(chrome::kChromeUICreditsURL)); |
| 213 } |
| 214 |
134 void EulaScreenHandler::HandleOnInstallationSettingsPopupOpened() { | 215 void EulaScreenHandler::HandleOnInstallationSettingsPopupOpened() { |
135 if (delegate_) | 216 if (delegate_) |
136 delegate_->InitiatePasswordFetch(); | 217 delegate_->InitiatePasswordFetch(); |
137 } | 218 } |
138 | 219 |
139 } // namespace chromeos | 220 } // namespace chromeos |
OLD | NEW |