| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace chromeos { | 24 namespace chromeos { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // JS functions that define new and old kiosk UI API. | 28 // JS functions that define new and old kiosk UI API. |
| 29 const char kKioskSetAppsNewAPI[] = "login.AccountPickerScreen.setApps"; | 29 const char kKioskSetAppsNewAPI[] = "login.AccountPickerScreen.setApps"; |
| 30 const char kKioskSetAppsOldAPI[] = "login.AppsMenuButton.setApps"; | 30 const char kKioskSetAppsOldAPI[] = "login.AppsMenuButton.setApps"; |
| 31 const char kKioskShowErrorNewAPI[] = "login.AccountPickerScreen.showAppError"; | 31 const char kKioskShowErrorNewAPI[] = "login.AccountPickerScreen.showAppError"; |
| 32 const char kKioskShowErrorOldAPI[] = "login.AppsMenuButton.showError"; | 32 const char kKioskShowErrorOldAPI[] = "login.AppsMenuButton.showError"; |
| 33 | 33 |
| 34 // Default app icon size. | |
| 35 const char kDefaultAppIconSizeString[] = "96px"; | |
| 36 const int kMaxAppIconSize = 160; | |
| 37 | |
| 38 } // namespace | 34 } // namespace |
| 39 | 35 |
| 40 KioskAppMenuHandler::KioskAppMenuHandler() | 36 KioskAppMenuHandler::KioskAppMenuHandler() |
| 41 : weak_ptr_factory_(this), | 37 : weak_ptr_factory_(this), |
| 42 is_webui_initialized_(false) { | 38 is_webui_initialized_(false) { |
| 43 KioskAppManager::Get()->AddObserver(this); | 39 KioskAppManager::Get()->AddObserver(this); |
| 44 } | 40 } |
| 45 | 41 |
| 46 KioskAppMenuHandler::~KioskAppMenuHandler() { | 42 KioskAppMenuHandler::~KioskAppMenuHandler() { |
| 47 KioskAppManager::Get()->RemoveObserver(this); | 43 KioskAppManager::Get()->RemoveObserver(this); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 for (size_t i = 0; i < apps.size(); ++i) { | 92 for (size_t i = 0; i < apps.size(); ++i) { |
| 97 const KioskAppManager::App& app_data = apps[i]; | 93 const KioskAppManager::App& app_data = apps[i]; |
| 98 | 94 |
| 99 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 95 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
| 100 app_info->SetBoolean("isApp", true); | 96 app_info->SetBoolean("isApp", true); |
| 101 app_info->SetString("id", app_data.app_id); | 97 app_info->SetString("id", app_data.app_id); |
| 102 app_info->SetString("label", app_data.name); | 98 app_info->SetString("label", app_data.name); |
| 103 | 99 |
| 104 // TODO(xiyuan): Replace data url with a URLDataSource. | 100 // TODO(xiyuan): Replace data url with a URLDataSource. |
| 105 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 101 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
| 106 | 102 if (!app_data.icon.isNull()) |
| 107 if (!app_data.icon.isNull()) { | |
| 108 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); | 103 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); |
| 109 int width = app_data.icon.width(); | |
| 110 int height = app_data.icon.height(); | |
| 111 | |
| 112 // If app icon size is larger than default 160x160 then don't provide | |
| 113 // size at all since it's already limited on the css side. | |
| 114 if (width <= kMaxAppIconSize && height <= kMaxAppIconSize) { | |
| 115 app_info->SetString("iconWidth", base::IntToString(width) + "px"); | |
| 116 app_info->SetString("iconHeight", base::IntToString(height) + "px"); | |
| 117 } | |
| 118 } else { | |
| 119 app_info->SetString("iconWidth", kDefaultAppIconSizeString); | |
| 120 app_info->SetString("iconHeight", kDefaultAppIconSizeString); | |
| 121 } | |
| 122 app_info->SetString("iconUrl", icon_url); | 104 app_info->SetString("iconUrl", icon_url); |
| 123 | 105 |
| 124 apps_list.Append(app_info.release()); | 106 apps_list.Append(app_info.release()); |
| 125 } | 107 } |
| 126 | 108 |
| 127 web_ui()->CallJavascriptFunction(EnableNewKioskUI() ? | 109 web_ui()->CallJavascriptFunction(EnableNewKioskUI() ? |
| 128 kKioskSetAppsNewAPI : kKioskSetAppsOldAPI, | 110 kKioskSetAppsNewAPI : kKioskSetAppsOldAPI, |
| 129 apps_list); | 111 apps_list); |
| 130 } | 112 } |
| 131 | 113 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 159 | 141 |
| 160 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { | 142 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { |
| 161 SendKioskApps(); | 143 SendKioskApps(); |
| 162 } | 144 } |
| 163 | 145 |
| 164 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { | 146 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { |
| 165 SendKioskApps(); | 147 SendKioskApps(); |
| 166 } | 148 } |
| 167 | 149 |
| 168 } // namespace chromeos | 150 } // namespace chromeos |
| OLD | NEW |