• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/webui/chromeos/login/kiosk_enable_screen_handler.h"
6 
7 #include <string>
8 
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"
15 
16 namespace {
17 
18 const char kJsScreenPath[] = "login.KioskEnableScreen";
19 
20 // Reset screen id.
21 const char kKioskEnableScreen[] = "kiosk-enable";
22 
23 }  // namespace
24 
25 namespace chromeos {
26 
KioskEnableScreenHandler()27 KioskEnableScreenHandler::KioskEnableScreenHandler()
28     : BaseScreenHandler(kJsScreenPath),
29       delegate_(NULL),
30       show_on_init_(false),
31       is_configurable_(false),
32       weak_ptr_factory_(this) {
33 }
34 
~KioskEnableScreenHandler()35 KioskEnableScreenHandler::~KioskEnableScreenHandler() {
36   if (delegate_)
37     delegate_->OnActorDestroyed(this);
38 }
39 
Show()40 void KioskEnableScreenHandler::Show() {
41   if (!page_is_ready()) {
42     show_on_init_ = true;
43     return;
44   }
45 
46   KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus(
47       base::Bind(
48           &KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus,
49           weak_ptr_factory_.GetWeakPtr()));
50 }
51 
OnGetConsumerKioskAutoLaunchStatus(KioskAppManager::ConsumerKioskAutoLaunchStatus status)52 void KioskEnableScreenHandler::OnGetConsumerKioskAutoLaunchStatus(
53     KioskAppManager::ConsumerKioskAutoLaunchStatus status) {
54   is_configurable_ =
55       (status == KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE);
56   if (!is_configurable_) {
57     LOG(WARNING) << "Consumer kiosk auto launch feature is not configurable!";
58     return;
59   }
60 
61   ShowScreen(kKioskEnableScreen, NULL);
62 
63   content::NotificationService::current()->Notify(
64       chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
65       content::NotificationService::AllSources(),
66       content::NotificationService::NoDetails());
67 }
68 
SetDelegate(Delegate * delegate)69 void KioskEnableScreenHandler::SetDelegate(Delegate* delegate) {
70   delegate_ = delegate;
71   if (page_is_ready())
72     Initialize();
73 }
74 
DeclareLocalizedValues(LocalizedValuesBuilder * builder)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);
87 }
88 
Initialize()89 void KioskEnableScreenHandler::Initialize() {
90   if (!page_is_ready() || !delegate_)
91     return;
92 
93   if (show_on_init_) {
94     Show();
95     show_on_init_ = false;
96   }
97 }
98 
RegisterMessages()99 void KioskEnableScreenHandler::RegisterMessages() {
100   AddCallback("kioskOnClose", &KioskEnableScreenHandler::HandleOnClose);
101   AddCallback("kioskOnEnable", &KioskEnableScreenHandler::HandleOnEnable);
102 }
103 
HandleOnClose()104 void KioskEnableScreenHandler::HandleOnClose() {
105   if (delegate_)
106     delegate_->OnExit();
107 
108   content::NotificationService::current()->Notify(
109       chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
110       content::NotificationService::AllSources(),
111       content::NotificationService::NoDetails());
112 }
113 
HandleOnEnable()114 void KioskEnableScreenHandler::HandleOnEnable() {
115   if (!is_configurable_) {
116     NOTREACHED();
117     if (delegate_)
118       delegate_->OnExit();
119 
120     content::NotificationService::current()->Notify(
121         chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
122         content::NotificationService::AllSources(),
123         content::NotificationService::NoDetails());
124     return;
125   }
126 
127   KioskAppManager::Get()->EnableConsumerKioskAutoLaunch(
128       base::Bind(&KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch,
129                  weak_ptr_factory_.GetWeakPtr()));
130 }
131 
OnEnableConsumerKioskAutoLaunch(bool success)132 void KioskEnableScreenHandler::OnEnableConsumerKioskAutoLaunch(
133     bool success) {
134   if (!success)
135     LOG(WARNING) << "Consumer kiosk mode can't be enabled!";
136 
137   CallJS("onCompleted", success);
138   if (success) {
139     content::NotificationService::current()->Notify(
140         chrome::NOTIFICATION_KIOSK_ENABLED,
141         content::NotificationService::AllSources(),
142         content::NotificationService::NoDetails());
143   }
144 }
145 
146 }  // namespace chromeos
147