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/common/pref_names.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 "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_service.h"
22 #include "grit/browser_resources.h"
23 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h"
25 #include "ui/base/webui/web_ui_util.h"
29 const char kJsScreenPath
[] = "login.AutolaunchScreen";
31 // Autolaunch screen id.
32 const char kAutolaunchScreen
[] = "autolaunch";
38 KioskAutolaunchScreenHandler::KioskAutolaunchScreenHandler()
39 : BaseScreenHandler(kJsScreenPath
),
43 KioskAppManager::Get()->AddObserver(this);
46 KioskAutolaunchScreenHandler::~KioskAutolaunchScreenHandler() {
48 delegate_
->OnActorDestroyed(this);
50 KioskAppManager::Get()->RemoveObserver(this);
53 void KioskAutolaunchScreenHandler::Show() {
54 if (!page_is_ready()) {
59 ShowScreen(kAutolaunchScreen
, NULL
);
62 void KioskAutolaunchScreenHandler::SetDelegate(Delegate
* delegate
) {
68 void KioskAutolaunchScreenHandler::UpdateKioskApp() {
72 KioskAppManager
* manager
= KioskAppManager::Get();
73 KioskAppManager::App app
;
74 std::string app_id
= manager
->GetAutoLaunchApp();
76 manager
->IsAutoLaunchEnabled() ||
77 !manager
->GetApp(app_id
, &app
)) {
81 base::DictionaryValue app_info
;
82 app_info
.SetString("appName", app
.name
);
84 std::string
icon_url("chrome://theme/IDR_APP_DEFAULT_ICON");
85 if (!app
.icon
.isNull())
86 icon_url
= webui::GetBitmapDataUrl(*app
.icon
.bitmap());
88 app_info
.SetString("appIconUrl", icon_url
);
89 CallJS("updateApp", app_info
);
92 void KioskAutolaunchScreenHandler::DeclareLocalizedValues(
93 LocalizedValuesBuilder
* builder
) {
94 builder
->Add("autolaunchTitle", IDS_AUTOSTART_WARNING_TITLE
);
95 builder
->Add("autolaunchWarningTitle", IDS_AUTOSTART_WARNING_TITLE
);
96 builder
->Add("autolaunchWarning", IDS_KIOSK_AUTOSTART_SCREEN_WARNING_MSG
);
97 builder
->Add("autolaunchConfirmButton", IDS_KIOSK_AUTOSTART_CONFIRM
);
98 builder
->Add("autolaunchCancelButton", IDS_CANCEL
);
101 void KioskAutolaunchScreenHandler::Initialize() {
102 if (!page_is_ready() || !delegate_
)
107 show_on_init_
= false;
111 void KioskAutolaunchScreenHandler::RegisterMessages() {
112 AddCallback("autolaunchVisible",
113 &KioskAutolaunchScreenHandler::HandleOnVisible
);
114 AddCallback("autolaunchOnCancel",
115 &KioskAutolaunchScreenHandler::HandleOnCancel
);
116 AddCallback("autolaunchOnConfirm",
117 &KioskAutolaunchScreenHandler::HandleOnConfirm
);
120 void KioskAutolaunchScreenHandler::HandleOnCancel() {
121 KioskAppManager::Get()->RemoveObserver(this);
122 KioskAppManager::Get()->SetEnableAutoLaunch(false);
124 delegate_
->OnExit(false);
126 content::NotificationService::current()->Notify(
127 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
128 content::NotificationService::AllSources(),
129 content::NotificationService::NoDetails());
132 void KioskAutolaunchScreenHandler::HandleOnConfirm() {
133 KioskAppManager::Get()->RemoveObserver(this);
134 KioskAppManager::Get()->SetEnableAutoLaunch(true);
136 delegate_
->OnExit(true);
138 content::NotificationService::current()->Notify(
139 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
140 content::NotificationService::AllSources(),
141 content::NotificationService::NoDetails());
144 void KioskAutolaunchScreenHandler::HandleOnVisible() {
150 content::NotificationService::current()->Notify(
151 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
152 content::NotificationService::AllSources(),
153 content::NotificationService::NoDetails());
156 void KioskAutolaunchScreenHandler::OnKioskAppsSettingsChanged() {
160 void KioskAutolaunchScreenHandler::OnKioskAppDataChanged(
161 const std::string
& app_id
) {
165 } // namespace chromeos