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 "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h"
18 const char kJsScreenPath[] = "login.KioskEnableScreen";
21 const char kKioskEnableScreen[] = "kiosk-enable";
27 KioskEnableScreenHandler::KioskEnableScreenHandler()
28 : BaseScreenHandler(kJsScreenPath),
31 is_configurable_(false),
32 weak_ptr_factory_(this) {
35 KioskEnableScreenHandler::~KioskEnableScreenHandler() {
37 delegate_->OnActorDestroyed(this);
40 void KioskEnableScreenHandler::Show() {
41 if (!page_is_ready()) {
46 KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus(
48 &KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus,
49 weak_ptr_factory_.GetWeakPtr()));
52 void KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus(
53 KioskAppManager::ConsumerKioskAutoLaunchStatus status) {
55 (status == KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE);
56 if (!is_configurable_) {
57 LOG(WARNING) << "Consumer kiosk auto launch feature is not configurable!";
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()->EnableConsumerKioskAutoLaunch(
128 base::Bind(&KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch,
129 weak_ptr_factory_.GetWeakPtr()));
132 void KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch(
135 LOG(WARNING) << "Consumer kiosk mode can't be enabled!";
137 CallJS("onCompleted", success);
139 content::NotificationService::current()->Notify(
140 chrome::NOTIFICATION_KIOSK_ENABLED,
141 content::NotificationService::AllSources(),
142 content::NotificationService::NoDetails());
146 } // namespace chromeos