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 "chrome/grit/generated_resources.h"
13 #include "components/login/localized_values_builder.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.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()->GetConsumerKioskAutoLaunchStatus(
49 &KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus
,
50 weak_ptr_factory_
.GetWeakPtr()));
53 void KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus(
54 KioskAppManager::ConsumerKioskAutoLaunchStatus status
) {
56 (status
== KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
);
57 if (!is_configurable_
) {
58 LOG(WARNING
) << "Consumer kiosk auto launch feature is not configurable!";
62 ShowScreen(kKioskEnableScreen
, NULL
);
64 content::NotificationService::current()->Notify(
65 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
66 content::NotificationService::AllSources(),
67 content::NotificationService::NoDetails());
70 void KioskEnableScreenHandler::SetDelegate(Delegate
* delegate
) {
76 void KioskEnableScreenHandler::DeclareLocalizedValues(
77 ::login::LocalizedValuesBuilder
* builder
) {
78 builder
->Add("kioskEnableTitle", IDS_KIOSK_ENABLE_SCREEN_WARNING
);
79 builder
->Add("kioskEnableWarningText",
80 IDS_KIOSK_ENABLE_SCREEN_WARNING
);
81 builder
->Add("kioskEnableWarningDetails",
82 IDS_KIOSK_ENABLE_SCREEN_WARNING_DETAILS
);
83 builder
->Add("kioskEnableButton", IDS_KIOSK_ENABLE_SCREEN_ENABLE_BUTTON
);
84 builder
->Add("kioskCancelButton", IDS_CANCEL
);
85 builder
->Add("kioskOKButton", IDS_OK
);
86 builder
->Add("kioskEnableSuccessMsg", IDS_KIOSK_ENABLE_SCREEN_SUCCESS
);
87 builder
->Add("kioskEnableErrorMsg", IDS_KIOSK_ENABLE_SCREEN_ERROR
);
90 void KioskEnableScreenHandler::Initialize() {
91 if (!page_is_ready() || !delegate_
)
96 show_on_init_
= false;
100 void KioskEnableScreenHandler::RegisterMessages() {
101 AddCallback("kioskOnClose", &KioskEnableScreenHandler::HandleOnClose
);
102 AddCallback("kioskOnEnable", &KioskEnableScreenHandler::HandleOnEnable
);
105 void KioskEnableScreenHandler::HandleOnClose() {
109 content::NotificationService::current()->Notify(
110 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
111 content::NotificationService::AllSources(),
112 content::NotificationService::NoDetails());
115 void KioskEnableScreenHandler::HandleOnEnable() {
116 if (!is_configurable_
) {
121 content::NotificationService::current()->Notify(
122 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
123 content::NotificationService::AllSources(),
124 content::NotificationService::NoDetails());
128 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch(
129 base::Bind(&KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch
,
130 weak_ptr_factory_
.GetWeakPtr()));
133 void KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch(
136 LOG(WARNING
) << "Consumer kiosk mode can't be enabled!";
138 CallJS("onCompleted", success
);
140 content::NotificationService::current()->Notify(
141 chrome::NOTIFICATION_KIOSK_ENABLED
,
142 content::NotificationService::AllSources(),
143 content::NotificationService::NoDetails());
147 } // namespace chromeos