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_autolaunch_screen_handler.h"
9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/grit/generated_resources.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/session_manager_client.h"
20 #include "components/login/localized_values_builder.h"
21 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h"
23 #include "ui/base/webui/web_ui_util.h"
27 const char kJsScreenPath
[] = "login.AutolaunchScreen";
29 // Autolaunch screen id.
30 const char kAutolaunchScreen
[] = "autolaunch";
36 KioskAutolaunchScreenHandler::KioskAutolaunchScreenHandler()
37 : BaseScreenHandler(kJsScreenPath
),
41 KioskAppManager::Get()->AddObserver(this);
44 KioskAutolaunchScreenHandler::~KioskAutolaunchScreenHandler() {
46 delegate_
->OnActorDestroyed(this);
48 KioskAppManager::Get()->RemoveObserver(this);
51 void KioskAutolaunchScreenHandler::Show() {
52 if (!page_is_ready()) {
57 ShowScreen(kAutolaunchScreen
, NULL
);
60 void KioskAutolaunchScreenHandler::SetDelegate(Delegate
* delegate
) {
66 void KioskAutolaunchScreenHandler::UpdateKioskApp() {
70 KioskAppManager
* manager
= KioskAppManager::Get();
71 KioskAppManager::App app
;
72 std::string app_id
= manager
->GetAutoLaunchApp();
74 manager
->IsAutoLaunchEnabled() ||
75 !manager
->GetApp(app_id
, &app
)) {
79 base::DictionaryValue app_info
;
80 app_info
.SetString("appName", app
.name
);
82 std::string
icon_url("chrome://theme/IDR_APP_DEFAULT_ICON");
83 if (!app
.icon
.isNull())
84 icon_url
= webui::GetBitmapDataUrl(*app
.icon
.bitmap());
86 app_info
.SetString("appIconUrl", icon_url
);
87 CallJS("updateApp", app_info
);
90 void KioskAutolaunchScreenHandler::DeclareLocalizedValues(
91 ::login::LocalizedValuesBuilder
* builder
) {
92 builder
->Add("autolaunchTitle", IDS_AUTOSTART_WARNING_TITLE
);
93 builder
->Add("autolaunchWarningTitle", IDS_AUTOSTART_WARNING_TITLE
);
94 builder
->Add("autolaunchWarning", IDS_KIOSK_AUTOSTART_SCREEN_WARNING_MSG
);
95 builder
->Add("autolaunchConfirmButton", IDS_KIOSK_AUTOSTART_CONFIRM
);
96 builder
->Add("autolaunchCancelButton", IDS_CANCEL
);
99 void KioskAutolaunchScreenHandler::Initialize() {
100 if (!page_is_ready() || !delegate_
)
105 show_on_init_
= false;
109 void KioskAutolaunchScreenHandler::RegisterMessages() {
110 AddCallback("autolaunchVisible",
111 &KioskAutolaunchScreenHandler::HandleOnVisible
);
112 AddCallback("autolaunchOnCancel",
113 &KioskAutolaunchScreenHandler::HandleOnCancel
);
114 AddCallback("autolaunchOnConfirm",
115 &KioskAutolaunchScreenHandler::HandleOnConfirm
);
118 void KioskAutolaunchScreenHandler::HandleOnCancel() {
119 KioskAppManager::Get()->RemoveObserver(this);
120 KioskAppManager::Get()->SetEnableAutoLaunch(false);
122 delegate_
->OnExit(false);
124 content::NotificationService::current()->Notify(
125 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
126 content::NotificationService::AllSources(),
127 content::NotificationService::NoDetails());
130 void KioskAutolaunchScreenHandler::HandleOnConfirm() {
131 KioskAppManager::Get()->RemoveObserver(this);
132 KioskAppManager::Get()->SetEnableAutoLaunch(true);
134 delegate_
->OnExit(true);
136 content::NotificationService::current()->Notify(
137 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
138 content::NotificationService::AllSources(),
139 content::NotificationService::NoDetails());
142 void KioskAutolaunchScreenHandler::HandleOnVisible() {
148 content::NotificationService::current()->Notify(
149 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
150 content::NotificationService::AllSources(),
151 content::NotificationService::NoDetails());
154 void KioskAutolaunchScreenHandler::OnKioskAppsSettingsChanged() {
158 void KioskAutolaunchScreenHandler::OnKioskAppDataChanged(
159 const std::string
& app_id
) {
163 } // namespace chromeos