Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / kiosk_autolaunch_screen_handler.cc
blob857f683fe5c6ab2329958391c4e2075dff8da7a8
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"
7 #include <string>
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"
25 namespace {
27 const char kJsScreenPath[] = "login.AutolaunchScreen";
29 // Autolaunch screen id.
30 const char kAutolaunchScreen[] = "autolaunch";
32 } // namespace
34 namespace chromeos {
36 KioskAutolaunchScreenHandler::KioskAutolaunchScreenHandler()
37 : BaseScreenHandler(kJsScreenPath),
38 delegate_(NULL),
39 show_on_init_(false),
40 is_visible_(false) {
41 KioskAppManager::Get()->AddObserver(this);
44 KioskAutolaunchScreenHandler::~KioskAutolaunchScreenHandler() {
45 if (delegate_)
46 delegate_->OnActorDestroyed(this);
48 KioskAppManager::Get()->RemoveObserver(this);
51 void KioskAutolaunchScreenHandler::Show() {
52 if (!page_is_ready()) {
53 show_on_init_ = true;
54 return;
56 UpdateKioskApp();
57 ShowScreen(kAutolaunchScreen, NULL);
60 void KioskAutolaunchScreenHandler::SetDelegate(Delegate* delegate) {
61 delegate_ = delegate;
62 if (page_is_ready())
63 Initialize();
66 void KioskAutolaunchScreenHandler::UpdateKioskApp() {
67 if (!is_visible_)
68 return;
70 KioskAppManager* manager = KioskAppManager::Get();
71 KioskAppManager::App app;
72 std::string app_id = manager->GetAutoLaunchApp();
73 if (app_id.empty() ||
74 manager->IsAutoLaunchEnabled() ||
75 !manager->GetApp(app_id, &app)) {
76 return;
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_)
101 return;
103 if (show_on_init_) {
104 Show();
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);
121 if (delegate_)
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);
133 if (delegate_)
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() {
143 if (is_visible_)
144 return;
146 is_visible_ = true;
147 UpdateKioskApp();
148 content::NotificationService::current()->Notify(
149 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
150 content::NotificationService::AllSources(),
151 content::NotificationService::NoDetails());
154 void KioskAutolaunchScreenHandler::OnKioskAppsSettingsChanged() {
155 UpdateKioskApp();
158 void KioskAutolaunchScreenHandler::OnKioskAppDataChanged(
159 const std::string& app_id) {
160 UpdateKioskApp();
163 } // namespace chromeos