Chromium Code Reviews| OLD | NEW |
|---|---|
| (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)); | |
|
xiyuan
2013/08/15 18:19:42
nit: alignment
Tim Song
2013/08/16 19:07:59
Done.
| |
| 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::ToggleNetworkConfig(bool visible) { | |
| 87 // TODO(tengs): Implement network configuration in app launch. | |
| 88 } | |
| 89 | |
| 90 void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state) { | |
| 91 if (state == state_) | |
| 92 return; | |
| 93 | |
| 94 state_ = state; | |
| 95 if (page_is_ready()) | |
| 96 SetLaunchText( | |
| 97 l10n_util::GetStringUTF8(GetProgressMessageFromState(state_))); | |
|
xiyuan
2013/08/15 18:19:42
nit: need enclosing {} since it's more than one li
Tim Song
2013/08/16 19:07:59
Done.
| |
| 98 } | |
| 99 | |
| 100 void AppLaunchSplashScreenHandler::SetDelegate( | |
| 101 AppLaunchSplashScreenHandler::Delegate* delegate) { | |
| 102 delegate_ = delegate; | |
| 103 } | |
| 104 | |
| 105 void AppLaunchSplashScreenHandler::PopulateAppInfo( | |
| 106 base::DictionaryValue& out_info) { | |
|
xiyuan
2013/08/15 18:19:42
nit: usually we use '*' if the function changes th
Tim Song
2013/08/16 19:07:59
Done.
| |
| 107 KioskAppManager::App app; | |
| 108 KioskAppManager::Get()->GetApp(app_id_, &app); | |
| 109 | |
| 110 if (app.name.empty()) | |
| 111 app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME); | |
| 112 | |
| 113 if (app.icon.isNull()) { | |
| 114 app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 115 IDR_PRODUCT_LOGO_128); | |
| 116 } | |
| 117 | |
| 118 out_info.SetString("name", app.name); | |
| 119 out_info.SetString("iconURL", webui::GetBitmapDataUrl(*app.icon.bitmap())); | |
| 120 } | |
| 121 | |
| 122 void AppLaunchSplashScreenHandler::SetLaunchText(const std::string& text) { | |
| 123 CallJS("updateMessage", text); | |
| 124 } | |
| 125 | |
| 126 int AppLaunchSplashScreenHandler::GetProgressMessageFromState( | |
| 127 AppLaunchState state) { | |
| 128 switch (state) { | |
| 129 case APP_LAUNCH_STATE_LOADING_AUTH_FILE: | |
| 130 case APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE: | |
| 131 // TODO(zelidrag): Add better string for this one than "Please wait..." | |
| 132 return IDS_SYNC_SETUP_SPINNER_TITLE; | |
| 133 case APP_LAUNCH_STATE_PREPARING_NETWORK: | |
| 134 return IDS_APP_START_NETWORK_WAIT_MESSAGE; | |
| 135 case APP_LAUNCH_STATE_INSTALLING_APPLICATION: | |
| 136 return IDS_APP_START_APP_WAIT_MESSAGE; | |
| 137 } | |
| 138 return IDS_APP_START_NETWORK_WAIT_MESSAGE; | |
| 139 } | |
| 140 | |
| 141 void AppLaunchSplashScreenHandler::HandleConfigureNetwork() { | |
| 142 if (delegate_) | |
| 143 delegate_->OnConfigureNetwork(); | |
| 144 else | |
| 145 LOG(WARNING) << "No delegate set to handle network configuration."; | |
| 146 } | |
| 147 | |
| 148 void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() { | |
| 149 if (delegate_) | |
| 150 delegate_->OnCancelAppLaunch(); | |
| 151 else | |
| 152 LOG(WARNING) << "No delegate set to handle cancel app launch"; | |
| 153 } | |
| 154 | |
| 155 } // namespace chromeos | |
|
xiyuan
2013/08/15 18:19:42
nit: two-space before //
Tim Song
2013/08/16 19:07:59
Done.
| |
| OLD | NEW |