Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.cc

Issue 22914008: Refactor kiosk app launch to be part of login screen UI flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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/app_launch_splash_screen_handle r.h"
6
7 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
8 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
9 #include "grit/browser_resources.h"
10 #include "grit/chrome_unscaled_resources.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/webui/web_ui_util.h"
16
17 namespace {
18
19 const char kJsScreenPath[] = "login.AppLaunchSplashScreen";
20
21 } // namespace
22
23 namespace chromeos {
24
25 AppLaunchSplashScreenHandler::AppLaunchSplashScreenHandler()
26 : BaseScreenHandler(kJsScreenPath),
27 delegate_(NULL),
28 show_on_init_(false),
29 state_(APP_LAUNCH_STATE_LOADING_AUTH_FILE) {
30 }
31
32 AppLaunchSplashScreenHandler::~AppLaunchSplashScreenHandler() {
33 }
34
35 void AppLaunchSplashScreenHandler::DeclareLocalizedValues(
36 LocalizedValuesBuilder* builder) {
37
38 builder->Add("appStartMessage", IDS_APP_START_NETWORK_WAIT_MESSAGE);
39
40 const string16 product_os_name =
41 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME);
42 builder->Add(
43 "shortcutInfo",
44 l10n_util::GetStringFUTF16(IDS_APP_START_BAILOUT_SHORTCUT_FORMAT,
45 product_os_name));
46
47 builder->Add(
48 "productName",
49 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME));
50 }
51
52 void AppLaunchSplashScreenHandler::Initialize() {
53 if (show_on_init_) {
54 show_on_init_ = false;
55 Show(app_id_);
56 }
57 }
58
59 void AppLaunchSplashScreenHandler::Show(const std::string& app_id) {
60 app_id_ = app_id;
61 if (!page_is_ready()) {
62 show_on_init_ = true;
63 return;
64 }
65
66 base::DictionaryValue data;
67 data.SetBoolean("shortcutEnabled",
68 !KioskAppManager::Get()->GetDisableBailoutShortcut());
69
70 // |data| will take ownership of |app_info|.
71 base::DictionaryValue *app_info = new base::DictionaryValue();
72 PopulateAppInfo(app_info);
73 data.Set("appInfo", app_info);
74
75 SetLaunchText(l10n_util::GetStringUTF8(GetProgressMessageFromState(state_)));
76 ShowScreen(OobeUI::kScreenAppLaunchSplash, &data);
77 }
78
79 void AppLaunchSplashScreenHandler::RegisterMessages() {
80 AddCallback("configureNetwork",
81 &AppLaunchSplashScreenHandler::HandleConfigureNetwork);
82 AddCallback("cancelAppLaunch",
83 &AppLaunchSplashScreenHandler::HandleCancelAppLaunch);
84 }
85
86 void AppLaunchSplashScreenHandler::PrepareToShow() {
87 }
88
89 void AppLaunchSplashScreenHandler::Hide() {
90 }
91
92 void AppLaunchSplashScreenHandler::ToggleNetworkConfig(bool visible) {
93 // TODO(tengs): Implement network configuration in app launch.
94 }
95
96 void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state) {
97 if (state == state_)
98 return;
99
100 state_ = state;
101 if (page_is_ready()) {
102 SetLaunchText(
103 l10n_util::GetStringUTF8(GetProgressMessageFromState(state_)));
104 }
105 }
106
107 void AppLaunchSplashScreenHandler::SetDelegate(
108 AppLaunchSplashScreenHandler::Delegate* delegate) {
109 delegate_ = delegate;
110 }
111
112 void AppLaunchSplashScreenHandler::PopulateAppInfo(
113 base::DictionaryValue* out_info) {
114 KioskAppManager::App app;
115 KioskAppManager::Get()->GetApp(app_id_, &app);
116
117 if (app.name.empty())
118 app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME);
119
120 if (app.icon.isNull()) {
121 app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
122 IDR_PRODUCT_LOGO_128);
123 }
124
125 out_info->SetString("name", app.name);
126 out_info->SetString("iconURL", webui::GetBitmapDataUrl(*app.icon.bitmap()));
127 }
128
129 void AppLaunchSplashScreenHandler::SetLaunchText(const std::string& text) {
130 CallJS("updateMessage", text);
131 }
132
133 int AppLaunchSplashScreenHandler::GetProgressMessageFromState(
134 AppLaunchState state) {
135 switch (state) {
136 case APP_LAUNCH_STATE_LOADING_AUTH_FILE:
137 case APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE:
138 // TODO(zelidrag): Add better string for this one than "Please wait..."
139 return IDS_SYNC_SETUP_SPINNER_TITLE;
140 case APP_LAUNCH_STATE_PREPARING_NETWORK:
141 return IDS_APP_START_NETWORK_WAIT_MESSAGE;
142 case APP_LAUNCH_STATE_INSTALLING_APPLICATION:
143 return IDS_APP_START_APP_WAIT_MESSAGE;
144 }
145 return IDS_APP_START_NETWORK_WAIT_MESSAGE;
146 }
147
148 void AppLaunchSplashScreenHandler::HandleConfigureNetwork() {
149 if (delegate_)
150 delegate_->OnConfigureNetwork();
151 else
152 LOG(WARNING) << "No delegate set to handle network configuration.";
153 }
154
155 void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() {
156 if (delegate_)
157 delegate_->OnCancelAppLaunch();
158 else
159 LOG(WARNING) << "No delegate set to handle cancel app launch";
160 }
161
162 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698