| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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/app_launch_ui.h" | |
| 6 | |
| 7 #include "base/values.h" | |
| 8 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ui/webui/theme_source.h" | |
| 11 #include "chrome/common/url_constants.h" | |
| 12 #include "content/public/browser/web_ui.h" | |
| 13 #include "content/public/browser/web_ui_data_source.h" | |
| 14 #include "content/public/browser/web_ui_message_handler.h" | |
| 15 #include "grit/browser_resources.h" | |
| 16 #include "grit/chrome_unscaled_resources.h" | |
| 17 #include "grit/chromium_strings.h" | |
| 18 #include "grit/generated_resources.h" | |
| 19 #include "net/base/network_change_notifier.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 21 #include "ui/base/resource/resource_bundle.h" | |
| 22 #include "ui/webui/web_ui_util.h" | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 content::WebUIDataSource* CreateWebUIDataSource() { | |
| 29 content::WebUIDataSource* source = | |
| 30 content::WebUIDataSource::Create(chrome::kChromeUIAppLaunchHost); | |
| 31 source->SetDefaultResource(IDR_APP_LAUNCH_SPLASH_HTML); | |
| 32 source->SetUseJsonJSFormatV2(); | |
| 33 source->AddLocalizedString("appStartMessage", | |
| 34 net::NetworkChangeNotifier::IsOffline() ? | |
| 35 IDS_APP_START_NETWORK_WAIT_MESSAGE : | |
| 36 IDS_APP_START_APP_WAIT_MESSAGE); | |
| 37 source->AddLocalizedString("productName", IDS_SHORT_PRODUCT_NAME); | |
| 38 | |
| 39 const string16 product_os_name = | |
| 40 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME); | |
| 41 source->AddString( | |
| 42 "shortcutInfo", | |
| 43 l10n_util::GetStringFUTF16(IDS_APP_START_BAILOUT_SHORTCUT_FORMAT, | |
| 44 product_os_name)); | |
| 45 | |
| 46 source->AddBoolean("shortcutEnabled", | |
| 47 !KioskAppManager::Get()->GetDisableBailoutShortcut()); | |
| 48 | |
| 49 source->SetJsonPath("strings.js"); | |
| 50 source->AddResourcePath("app_launch.js", IDR_APP_LAUNCH_SPLASH_JS); | |
| 51 return source; | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 class AppLaunchUI::AppLaunchUIHandler : public content::WebUIMessageHandler { | |
| 57 public: | |
| 58 AppLaunchUIHandler() : initialized_(false) {} | |
| 59 virtual ~AppLaunchUIHandler() {} | |
| 60 | |
| 61 void SetLaunchText(const std::string& text) { | |
| 62 text_ = text; | |
| 63 if (initialized_) | |
| 64 SendLaunchText(); | |
| 65 } | |
| 66 | |
| 67 // content::WebUIMessageHandler overrides: | |
| 68 virtual void RegisterMessages() OVERRIDE { | |
| 69 web_ui()->RegisterMessageCallback("initialize", | |
| 70 base::Bind(&AppLaunchUIHandler::HandleInitialize, | |
| 71 base::Unretained(this))); | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 void SendAppInfo(const std::string& app_id) { | |
| 76 KioskAppManager::App app; | |
| 77 KioskAppManager::Get()->GetApp(app_id, &app); | |
| 78 | |
| 79 if (app.name.empty()) | |
| 80 app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME); | |
| 81 | |
| 82 if (app.icon.isNull()) { | |
| 83 app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 84 IDR_PRODUCT_LOGO_128); | |
| 85 } | |
| 86 | |
| 87 base::DictionaryValue app_info; | |
| 88 app_info.SetString("name", app.name); | |
| 89 app_info.SetString("iconURL", webui::GetBitmapDataUrl(*app.icon.bitmap())); | |
| 90 | |
| 91 web_ui()->CallJavascriptFunction("updateApp", app_info); | |
| 92 } | |
| 93 | |
| 94 void SendLaunchText() { | |
| 95 web_ui()->CallJavascriptFunction("updateMessage", base::StringValue(text_)); | |
| 96 } | |
| 97 | |
| 98 // JS callbacks. | |
| 99 void HandleInitialize(const base::ListValue* args) { | |
| 100 initialized_ = true; | |
| 101 | |
| 102 std::string app_id; | |
| 103 if (args->GetString(0, &app_id) && !app_id.empty()) | |
| 104 SendAppInfo(app_id); | |
| 105 | |
| 106 SendLaunchText(); | |
| 107 } | |
| 108 | |
| 109 bool initialized_; | |
| 110 std::string text_; | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(AppLaunchUIHandler); | |
| 113 }; | |
| 114 | |
| 115 AppLaunchUI::AppLaunchUI(content::WebUI* web_ui) | |
| 116 : WebUIController(web_ui), | |
| 117 handler_(NULL) { | |
| 118 Profile* profile = Profile::FromWebUI(web_ui); | |
| 119 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); | |
| 120 | |
| 121 handler_ = new AppLaunchUIHandler; | |
| 122 web_ui->AddMessageHandler(handler_); | |
| 123 } | |
| 124 | |
| 125 void AppLaunchUI::SetLaunchText(const std::string& text) { | |
| 126 handler_->SetLaunchText(text); | |
| 127 } | |
| 128 | |
| 129 } // namespace chromeos | |
| OLD | NEW |