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