Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / kiosk_enable_screen_handler.cc
blob3e82671893dfff12ce8c2b9f7fe3f47c689e7cab
1 // Copyright 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/kiosk_enable_screen_handler.h"
7 #include <string>
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_service.h"
14 #include "grit/browser_resources.h"
15 #include "grit/generated_resources.h"
17 namespace {
19 const char kJsScreenPath[] = "login.KioskEnableScreen";
21 // Reset screen id.
22 const char kKioskEnableScreen[] = "kiosk-enable";
24 } // namespace
26 namespace chromeos {
28 KioskEnableScreenHandler::KioskEnableScreenHandler()
29 : BaseScreenHandler(kJsScreenPath),
30 delegate_(NULL),
31 show_on_init_(false),
32 is_configurable_(false),
33 weak_ptr_factory_(this) {
36 KioskEnableScreenHandler::~KioskEnableScreenHandler() {
37 if (delegate_)
38 delegate_->OnActorDestroyed(this);
41 void KioskEnableScreenHandler::Show() {
42 if (!page_is_ready()) {
43 show_on_init_ = true;
44 return;
47 KioskAppManager::Get()->GetConsumerKioskModeStatus(
48 base::Bind(&KioskEnableScreenHandler::OnGetConsumerKioskModeStatus,
49 weak_ptr_factory_.GetWeakPtr()));
52 void KioskEnableScreenHandler::OnGetConsumerKioskModeStatus(
53 KioskAppManager::ConsumerKioskModeStatus status) {
54 is_configurable_ =
55 (status == KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE);
56 if (!is_configurable_) {
57 LOG(WARNING) << "Consumer kiosk feature is not configurable anymore!";
58 return;
61 ShowScreen(kKioskEnableScreen, NULL);
63 content::NotificationService::current()->Notify(
64 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
65 content::NotificationService::AllSources(),
66 content::NotificationService::NoDetails());
69 void KioskEnableScreenHandler::SetDelegate(Delegate* delegate) {
70 delegate_ = delegate;
71 if (page_is_ready())
72 Initialize();
75 void KioskEnableScreenHandler::DeclareLocalizedValues(
76 LocalizedValuesBuilder* builder) {
77 builder->Add("kioskEnableTitle", IDS_KIOSK_ENABLE_SCREEN_WARNING);
78 builder->Add("kioskEnableWarningText",
79 IDS_KIOSK_ENABLE_SCREEN_WARNING);
80 builder->Add("kioskEnableWarningDetails",
81 IDS_KIOSK_ENABLE_SCREEN_WARNING_DETAILS);
82 builder->Add("kioskEnableButton", IDS_KIOSK_ENABLE_SCREEN_ENABLE_BUTTON);
83 builder->Add("kioskCancelButton", IDS_CANCEL);
84 builder->Add("kioskOKButton", IDS_OK);
85 builder->Add("kioskEnableSuccessMsg", IDS_KIOSK_ENABLE_SCREEN_SUCCESS);
86 builder->Add("kioskEnableErrorMsg", IDS_KIOSK_ENABLE_SCREEN_ERROR);
89 void KioskEnableScreenHandler::Initialize() {
90 if (!page_is_ready() || !delegate_)
91 return;
93 if (show_on_init_) {
94 Show();
95 show_on_init_ = false;
99 void KioskEnableScreenHandler::RegisterMessages() {
100 AddCallback("kioskOnClose", &KioskEnableScreenHandler::HandleOnClose);
101 AddCallback("kioskOnEnable", &KioskEnableScreenHandler::HandleOnEnable);
104 void KioskEnableScreenHandler::HandleOnClose() {
105 if (delegate_)
106 delegate_->OnExit();
108 content::NotificationService::current()->Notify(
109 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
110 content::NotificationService::AllSources(),
111 content::NotificationService::NoDetails());
114 void KioskEnableScreenHandler::HandleOnEnable() {
115 if (!is_configurable_) {
116 NOTREACHED();
117 if (delegate_)
118 delegate_->OnExit();
120 content::NotificationService::current()->Notify(
121 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
122 content::NotificationService::AllSources(),
123 content::NotificationService::NoDetails());
124 return;
127 KioskAppManager::Get()->EnableConsumerModeKiosk(
128 base::Bind(&KioskEnableScreenHandler::OnEnableConsumerModeKiosk,
129 weak_ptr_factory_.GetWeakPtr()));
132 void KioskEnableScreenHandler::OnEnableConsumerModeKiosk(bool success) {
133 if (!success)
134 LOG(WARNING) << "Consumer kiosk mode can't be enabled!";
136 CallJS("onCompleted", success);
137 if (success) {
138 content::NotificationService::current()->Notify(
139 chrome::NOTIFICATION_KIOSK_ENABLED,
140 content::NotificationService::AllSources(),
141 content::NotificationService::NoDetails());
145 } // namespace chromeos