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"
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"
19 const char kJsScreenPath
[] = "login.KioskEnableScreen";
22 const char kKioskEnableScreen
[] = "kiosk-enable";
28 KioskEnableScreenHandler::KioskEnableScreenHandler()
29 : BaseScreenHandler(kJsScreenPath
),
32 is_configurable_(false),
33 weak_ptr_factory_(this) {
36 KioskEnableScreenHandler::~KioskEnableScreenHandler() {
38 delegate_
->OnActorDestroyed(this);
41 void KioskEnableScreenHandler::Show() {
42 if (!page_is_ready()) {
47 KioskAppManager::Get()->GetConsumerKioskModeStatus(
48 base::Bind(&KioskEnableScreenHandler::OnGetConsumerKioskModeStatus
,
49 weak_ptr_factory_
.GetWeakPtr()));
52 void KioskEnableScreenHandler::OnGetConsumerKioskModeStatus(
53 KioskAppManager::ConsumerKioskModeStatus status
) {
55 (status
== KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE
);
56 if (!is_configurable_
) {
57 LOG(WARNING
) << "Consumer kiosk feature is not configurable anymore!";
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
) {
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_
)
95 show_on_init_
= false;
99 void KioskEnableScreenHandler::RegisterMessages() {
100 AddCallback("kioskOnClose", &KioskEnableScreenHandler::HandleOnClose
);
101 AddCallback("kioskOnEnable", &KioskEnableScreenHandler::HandleOnEnable
);
104 void KioskEnableScreenHandler::HandleOnClose() {
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_
) {
120 content::NotificationService::current()->Notify(
121 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
122 content::NotificationService::AllSources(),
123 content::NotificationService::NoDetails());
127 KioskAppManager::Get()->EnableConsumerModeKiosk(
128 base::Bind(&KioskEnableScreenHandler::OnEnableConsumerModeKiosk
,
129 weak_ptr_factory_
.GetWeakPtr()));
132 void KioskEnableScreenHandler::OnEnableConsumerModeKiosk(bool success
) {
134 LOG(WARNING
) << "Consumer kiosk mode can't be enabled!";
136 CallJS("onCompleted", success
);
138 content::NotificationService::current()->Notify(
139 chrome::NOTIFICATION_KIOSK_ENABLED
,
140 content::NotificationService::AllSources(),
141 content::NotificationService::NoDetails());
145 } // namespace chromeos