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/ui/webui/chromeos/login/oobe_ui.h" 16 #include "chrome/common/url_constants.h" 17 #include "content/public/browser/web_contents.h" 18 #include "grit/browser_resources.h" 19 #include "grit/chromium_strings.h" 20 #include "grit/generated_resources.h" 21 #include "grit/locale_settings.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 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 78 } // namespace 79 80 namespace chromeos { 81 82 EulaScreenHandler::EulaScreenHandler(CoreOobeActor* core_oobe_actor) 83 : BaseScreenHandler(kJsScreenPath), 84 delegate_(NULL), 85 core_oobe_actor_(core_oobe_actor), 86 show_on_init_(false) { 87 } 88 89 EulaScreenHandler::~EulaScreenHandler() { 90 if (delegate_) 91 delegate_->OnActorDestroyed(this); 92 } 93 94 void EulaScreenHandler::PrepareToShow() { 95 } 96 97 void EulaScreenHandler::Show() { 98 if (!page_is_ready()) { 99 show_on_init_ = true; 100 return; 101 } 102 ShowScreen(OobeUI::kScreenOobeEula, NULL); 103 } 104 105 void EulaScreenHandler::Hide() { 106 } 107 108 void EulaScreenHandler::SetDelegate(Delegate* delegate) { 109 delegate_ = delegate; 110 if (page_is_ready()) 111 Initialize(); 112 } 113 114 void EulaScreenHandler::DeclareLocalizedValues( 115 LocalizedValuesBuilder* builder) { 116 builder->Add("eulaScreenTitle", IDS_EULA_SCREEN_TITLE); 117 builder->AddF("eulaScreenAccessibleTitle", 118 IDS_EULA_SCREEN_ACCESSIBLE_TITLE, 119 IDS_PRODUCT_OS_NAME); 120 builder->Add("checkboxLogging", IDS_EULA_CHECKBOX_ENABLE_LOGGING); 121 builder->Add("back", IDS_EULA_BACK_BUTTON); 122 builder->Add("acceptAgreement", IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON); 123 builder->Add("eulaSystemInstallationSettings", 124 IDS_EULA_SYSTEM_SECURITY_SETTING); 125 builder->Add("eulaTpmDesc", IDS_EULA_TPM_DESCRIPTION); 126 builder->Add("eulaTpmKeyDesc", IDS_EULA_TPM_KEY_DESCRIPTION); 127 builder->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH); 128 builder->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY); 129 builder->Add("eulaSystemInstallationSettingsOkButton", IDS_OK); 130 builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING); 131 #if defined(ENABLE_RLZ) 132 builder->AddF("eulaRlzDesc", 133 IDS_EULA_RLZ_DESCRIPTION, 134 IDS_SHORT_PRODUCT_NAME, 135 IDS_PRODUCT_NAME); 136 builder->AddF("eulaRlzEnable", 137 IDS_EULA_RLZ_ENABLE, 138 IDS_SHORT_PRODUCT_OS_NAME); 139 #endif 140 141 builder->Add("chromeCreditsLink", IDS_ABOUT_VERSION_LICENSE_EULA); 142 builder->Add("chromeosCreditsLink", IDS_ABOUT_CROS_VERSION_LICENSE_EULA); 143 } 144 145 void EulaScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) { 146 #if defined(ENABLE_RLZ) 147 dict->SetString("rlzEnabled", "enabled"); 148 #else 149 dict->SetString("rlzEnabled", "disabled"); 150 #endif 151 } 152 153 void EulaScreenHandler::Initialize() { 154 if (!page_is_ready() || !delegate_) 155 return; 156 157 core_oobe_actor_->SetUsageStats(delegate_->IsUsageStatsEnabled()); 158 159 // This OEM EULA is a file:// URL which we're unable to load in iframe. 160 // Instead if it's defined we use chrome://terms/oem that will load same file. 161 if (!delegate_->GetOemEulaUrl().is_empty()) 162 core_oobe_actor_->SetOemEulaUrl(chrome::kChromeUITermsOemURL); 163 164 if (show_on_init_) { 165 Show(); 166 show_on_init_ = false; 167 } 168 } 169 170 void EulaScreenHandler::RegisterMessages() { 171 AddCallback("eulaOnExit", &EulaScreenHandler::HandleOnExit); 172 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore); 173 AddCallback("eulaOnChromeOSCredits", 174 &EulaScreenHandler::HandleOnChromeOSCredits); 175 AddCallback("eulaOnChromeCredits", 176 &EulaScreenHandler::HandleOnChromeCredits); 177 AddCallback("eulaOnLearnMore", &EulaScreenHandler::HandleOnLearnMore); 178 AddCallback("eulaOnInstallationSettingsPopupOpened", 179 &EulaScreenHandler::HandleOnInstallationSettingsPopupOpened); 180 } 181 182 void EulaScreenHandler::OnPasswordFetched(const std::string& tpm_password) { 183 core_oobe_actor_->SetTpmPassword(tpm_password); 184 } 185 186 void EulaScreenHandler::HandleOnExit(bool accepted, bool usage_stats_enabled) { 187 if (delegate_) 188 delegate_->OnExit(accepted, usage_stats_enabled); 189 } 190 191 void EulaScreenHandler::HandleOnLearnMore() { 192 if (!help_app_.get()) 193 help_app_ = new HelpAppLauncher(GetNativeWindow()); 194 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE); 195 } 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 215 void EulaScreenHandler::HandleOnInstallationSettingsPopupOpened() { 216 if (delegate_) 217 delegate_->InitiatePasswordFetch(); 218 } 219 220 } // namespace chromeos 221