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 const scoped_refptr<NetworkStateInformer>& network_state_informer) | 37 const scoped_refptr<NetworkStateInformer>& network_state_informer) |
42 : weak_ptr_factory_(this), | 38 : weak_ptr_factory_(this), |
43 is_webui_initialized_(false), | 39 is_webui_initialized_(false), |
44 network_state_informer_(network_state_informer) { | 40 network_state_informer_(network_state_informer) { |
45 KioskAppManager::Get()->AddObserver(this); | 41 KioskAppManager::Get()->AddObserver(this); |
46 network_state_informer_->AddObserver(this); | 42 network_state_informer_->AddObserver(this); |
47 } | 43 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 for (size_t i = 0; i < apps.size(); ++i) { | 96 for (size_t i = 0; i < apps.size(); ++i) { |
101 const KioskAppManager::App& app_data = apps[i]; | 97 const KioskAppManager::App& app_data = apps[i]; |
102 | 98 |
103 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 99 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
104 app_info->SetBoolean("isApp", true); | 100 app_info->SetBoolean("isApp", true); |
105 app_info->SetString("id", app_data.app_id); | 101 app_info->SetString("id", app_data.app_id); |
106 app_info->SetString("label", app_data.name); | 102 app_info->SetString("label", app_data.name); |
107 | 103 |
108 // TODO(xiyuan): Replace data url with a URLDataSource. | 104 // TODO(xiyuan): Replace data url with a URLDataSource. |
109 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 105 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
110 | 106 if (!app_data.icon.isNull()) |
111 if (!app_data.icon.isNull()) { | |
112 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); | 107 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); |
113 int width = app_data.icon.width(); | |
114 int height = app_data.icon.height(); | |
115 | |
116 // If app icon size is larger than default 160x160 then don't provide | |
117 // size at all since it's already limited on the css side. | |
118 if (width <= kMaxAppIconSize && height <= kMaxAppIconSize) { | |
119 app_info->SetString("iconWidth", base::IntToString(width) + "px"); | |
120 app_info->SetString("iconHeight", base::IntToString(height) + "px"); | |
121 } | |
122 } else { | |
123 app_info->SetString("iconWidth", kDefaultAppIconSizeString); | |
124 app_info->SetString("iconHeight", kDefaultAppIconSizeString); | |
125 } | |
126 app_info->SetString("iconUrl", icon_url); | 108 app_info->SetString("iconUrl", icon_url); |
127 | 109 |
128 apps_list.Append(app_info.release()); | 110 apps_list.Append(app_info.release()); |
129 } | 111 } |
130 | 112 |
131 web_ui()->CallJavascriptFunction(EnableNewKioskUI() ? | 113 web_ui()->CallJavascriptFunction(EnableNewKioskUI() ? |
132 kKioskSetAppsNewAPI : kKioskSetAppsOldAPI, | 114 kKioskSetAppsNewAPI : kKioskSetAppsOldAPI, |
133 apps_list); | 115 apps_list); |
134 } | 116 } |
135 | 117 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { | 151 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { |
170 SendKioskApps(); | 152 SendKioskApps(); |
171 } | 153 } |
172 | 154 |
173 void KioskAppMenuHandler::UpdateState(ErrorScreenActor::ErrorReason reason) { | 155 void KioskAppMenuHandler::UpdateState(ErrorScreenActor::ErrorReason reason) { |
174 if (network_state_informer_->state() == NetworkStateInformer::ONLINE) | 156 if (network_state_informer_->state() == NetworkStateInformer::ONLINE) |
175 KioskAppManager::Get()->RetryFailedAppDataFetch(); | 157 KioskAppManager::Get()->RetryFailedAppDataFetch(); |
176 } | 158 } |
177 | 159 |
178 } // namespace chromeos | 160 } // namespace chromeos |
OLD | NEW |