Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / terms_of_service_screen_handler.cc
blob496f1436d42014276d51e887b0d40a978ccfe04e
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"
11 namespace {
13 const char kJsScreenPath[] = "login.TermsOfServiceScreen";
15 } // namespace
17 namespace chromeos {
19 TermsOfServiceScreenHandler::TermsOfServiceScreenHandler()
20 : BaseScreenHandler(kJsScreenPath),
21 screen_(NULL),
22 show_on_init_(false),
23 load_error_(false) {
26 TermsOfServiceScreenHandler::~TermsOfServiceScreenHandler() {
27 if (screen_)
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) {
56 screen_ = screen;
59 void TermsOfServiceScreenHandler::Show() {
60 if (!page_is_ready()) {
61 show_on_init_ = true;
62 return;
65 // Updates the domain name shown in the UI.
66 UpdateDomainInUI();
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) {
78 domain_ = domain;
79 UpdateDomainInUI();
82 void TermsOfServiceScreenHandler::OnLoadError() {
83 load_error_ = true;
84 terms_of_service_ = "";
85 UpdateTermsOfServiceInUI();
88 void TermsOfServiceScreenHandler::OnLoadSuccess(
89 const std::string& terms_of_service) {
90 load_error_ = false;
91 terms_of_service_ = terms_of_service;
92 UpdateTermsOfServiceInUI();
95 void TermsOfServiceScreenHandler::Initialize() {
96 if (show_on_init_) {
97 Show();
98 show_on_init_ = false;
102 void TermsOfServiceScreenHandler::UpdateDomainInUI() {
103 if (page_is_ready())
104 CallJS("setDomain", domain_);
107 void TermsOfServiceScreenHandler::UpdateTermsOfServiceInUI() {
108 if (!page_is_ready())
109 return;
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.
115 if (load_error_)
116 CallJS("setTermsOfServiceLoadError");
117 else if (!terms_of_service_.empty())
118 CallJS("setTermsOfService", terms_of_service_);
121 void TermsOfServiceScreenHandler::HandleBack() {
122 if (screen_)
123 screen_->OnDecline();
126 void TermsOfServiceScreenHandler::HandleAccept() {
127 if (!screen_)
128 return;
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();
136 else
137 screen_->OnAccept();
140 } // namespace chromeos