Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / kiosk_enable_screen_handler.cc
blobbd53189c3dd7762e288077538a480c7434ceb55f
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 "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"
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()->GetConsumerKioskAutoLaunchStatus(
48 base::Bind(
49 &KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus,
50 weak_ptr_factory_.GetWeakPtr()));
53 void KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus(
54 KioskAppManager::ConsumerKioskAutoLaunchStatus status) {
55 is_configurable_ =
56 (status == KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE);
57 if (!is_configurable_) {
58 LOG(WARNING) << "Consumer kiosk auto launch feature is not configurable!";
59 return;
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) {
71 delegate_ = delegate;
72 if (page_is_ready())
73 Initialize();
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_)
92 return;
94 if (show_on_init_) {
95 Show();
96 show_on_init_ = false;
100 void KioskEnableScreenHandler::RegisterMessages() {
101 AddCallback("kioskOnClose", &KioskEnableScreenHandler::HandleOnClose);
102 AddCallback("kioskOnEnable", &KioskEnableScreenHandler::HandleOnEnable);
105 void KioskEnableScreenHandler::HandleOnClose() {
106 if (delegate_)
107 delegate_->OnExit();
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_) {
117 NOTREACHED();
118 if (delegate_)
119 delegate_->OnExit();
121 content::NotificationService::current()->Notify(
122 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
123 content::NotificationService::AllSources(),
124 content::NotificationService::NoDetails());
125 return;
128 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch(
129 base::Bind(&KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch,
130 weak_ptr_factory_.GetWeakPtr()));
133 void KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch(
134 bool success) {
135 if (!success)
136 LOG(WARNING) << "Consumer kiosk mode can't be enabled!";
138 CallJS("onCompleted", success);
139 if (success) {
140 content::NotificationService::current()->Notify(
141 chrome::NOTIFICATION_KIOSK_ENABLED,
142 content::NotificationService::AllSources(),
143 content::NotificationService::NoDetails());
147 } // namespace chromeos