1 // Copyright (c) 2013 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/terms_of_service_screen_handler.h"
7 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
8 #include "grit/chromium_strings.h"
9 #include "grit/generated_resources.h"
13 const char kJsScreenPath
[] = "login.TermsOfServiceScreen";
19 TermsOfServiceScreenHandler::TermsOfServiceScreenHandler()
20 : BaseScreenHandler(kJsScreenPath
),
26 TermsOfServiceScreenHandler::~TermsOfServiceScreenHandler() {
28 screen_
->OnActorDestroyed(this);
31 void TermsOfServiceScreenHandler::RegisterMessages() {
32 AddCallback("termsOfServiceBack",
33 &TermsOfServiceScreenHandler::HandleBack
);
34 AddCallback("termsOfServiceAccept",
35 &TermsOfServiceScreenHandler::HandleAccept
);
38 void TermsOfServiceScreenHandler::DeclareLocalizedValues(
39 LocalizedValuesBuilder
* builder
) {
40 builder
->Add("termsOfServiceScreenHeading",
41 IDS_TERMS_OF_SERVICE_SCREEN_HEADING
);
42 builder
->Add("termsOfServiceScreenSubheading",
43 IDS_TERMS_OF_SERVICE_SCREEN_SUBHEADING
);
44 builder
->Add("termsOfServiceContentHeading",
45 IDS_TERMS_OF_SERVICE_SCREEN_CONTENT_HEADING
);
46 builder
->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING
);
47 builder
->Add("termsOfServiceError", IDS_TERMS_OF_SERVICE_SCREEN_ERROR
);
48 builder
->Add("termsOfServiceTryAgain", IDS_TERMS_OF_SERVICE_SCREEN_TRY_AGAIN
);
49 builder
->Add("termsOfServiceBackButton",
50 IDS_TERMS_OF_SERVICE_SCREEN_BACK_BUTTON
);
51 builder
->Add("termsOfServiceAcceptButton",
52 IDS_TERMS_OF_SERVICE_SCREEN_ACCEPT_BUTTON
);
55 void TermsOfServiceScreenHandler::SetDelegate(Delegate
* screen
) {
59 void TermsOfServiceScreenHandler::Show() {
60 if (!page_is_ready()) {
65 // Updates the domain name shown in the UI.
68 // Update the UI to show an error message or the Terms of Service.
69 UpdateTermsOfServiceInUI();
71 ShowScreen(OobeUI::kScreenTermsOfService
, NULL
);
74 void TermsOfServiceScreenHandler::Hide() {
77 void TermsOfServiceScreenHandler::SetDomain(const std::string
& domain
) {
82 void TermsOfServiceScreenHandler::OnLoadError() {
84 terms_of_service_
= "";
85 UpdateTermsOfServiceInUI();
88 void TermsOfServiceScreenHandler::OnLoadSuccess(
89 const std::string
& terms_of_service
) {
91 terms_of_service_
= terms_of_service
;
92 UpdateTermsOfServiceInUI();
95 void TermsOfServiceScreenHandler::Initialize() {
98 show_on_init_
= false;
102 void TermsOfServiceScreenHandler::UpdateDomainInUI() {
104 CallJS("setDomain", domain_
);
107 void TermsOfServiceScreenHandler::UpdateTermsOfServiceInUI() {
108 if (!page_is_ready())
111 // If either |load_error_| or |terms_of_service_| is set, the download of the
112 // Terms of Service has completed and the UI should be updated. Otherwise, the
113 // download is still in progress and the UI will be updated when the
114 // OnLoadError() or the OnLoadSuccess() callback is called.
116 CallJS("setTermsOfServiceLoadError");
117 else if (!terms_of_service_
.empty())
118 CallJS("setTermsOfService", terms_of_service_
);
121 void TermsOfServiceScreenHandler::HandleBack() {
123 screen_
->OnDecline();
126 void TermsOfServiceScreenHandler::HandleAccept() {
130 // If the Terms of Service have not been successfully downloaded, the "accept
131 // and continue" button should not be accessible. If the user managed to
132 // activate it somehow anway, do not treat this as acceptance of the Terms
133 // and Conditions and end the session instead, as if the user had declined.
134 if (terms_of_service_
.empty())
135 screen_
->OnDecline();
140 } // namespace chromeos