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/sys_info.h" | 9 #include "base/sys_info.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
14 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 14 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
16 #include "chromeos/chromeos_switches.h" | 16 #include "chromeos/chromeos_switches.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/webui/web_ui_util.h" | 22 #include "ui/base/webui/web_ui_util.h" |
23 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 | 25 |
| 26 namespace { |
| 27 |
| 28 // JS functions that define new and old kiosk UI API. |
| 29 const char kKioskSetAppsNewAPI[] = "login.AccountPickerScreen.setApps"; |
| 30 const char kKioskSetAppsOldAPI[] = "login.AppsMenuButton.setApps"; |
| 31 const char kKioskShowErrorNewAPI[] = "login.AccountPickerScreen.showAppError"; |
| 32 const char kKioskShowErrorOldAPI[] = "login.AppsMenuButton.showError"; |
| 33 |
| 34 } // namespace |
| 35 |
26 KioskAppMenuHandler::KioskAppMenuHandler() | 36 KioskAppMenuHandler::KioskAppMenuHandler() |
27 : initialized_(false), | 37 : initialized_(false), |
28 weak_ptr_factory_(this) { | 38 weak_ptr_factory_(this) { |
29 KioskAppManager::Get()->AddObserver(this); | 39 KioskAppManager::Get()->AddObserver(this); |
30 } | 40 } |
31 | 41 |
32 KioskAppMenuHandler::~KioskAppMenuHandler() { | 42 KioskAppMenuHandler::~KioskAppMenuHandler() { |
33 KioskAppManager::Get()->RemoveObserver(this); | 43 KioskAppManager::Get()->RemoveObserver(this); |
34 } | 44 } |
35 | 45 |
(...skipping 30 matching lines...) Expand all Loading... |
66 return; | 76 return; |
67 | 77 |
68 KioskAppManager::Apps apps; | 78 KioskAppManager::Apps apps; |
69 KioskAppManager::Get()->GetApps(&apps); | 79 KioskAppManager::Get()->GetApps(&apps); |
70 | 80 |
71 base::ListValue apps_list; | 81 base::ListValue apps_list; |
72 for (size_t i = 0; i < apps.size(); ++i) { | 82 for (size_t i = 0; i < apps.size(); ++i) { |
73 const KioskAppManager::App& app_data = apps[i]; | 83 const KioskAppManager::App& app_data = apps[i]; |
74 | 84 |
75 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 85 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
| 86 app_info->SetBoolean("isApp", true); |
76 app_info->SetString("id", app_data.app_id); | 87 app_info->SetString("id", app_data.app_id); |
77 app_info->SetString("label", app_data.name); | 88 app_info->SetString("label", app_data.name); |
78 | 89 |
79 // TODO(xiyuan): Replace data url with a URLDataSource. | 90 // TODO(xiyuan): Replace data url with a URLDataSource. |
80 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 91 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
81 if (!app_data.icon.isNull()) | 92 if (!app_data.icon.isNull()) |
82 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); | 93 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); |
83 app_info->SetString("iconUrl", icon_url); | 94 app_info->SetString("iconUrl", icon_url); |
84 | 95 |
85 apps_list.Append(app_info.release()); | 96 apps_list.Append(app_info.release()); |
86 } | 97 } |
87 | 98 |
88 web_ui()->CallJavascriptFunction("login.AppsMenuButton.setApps", | 99 bool new_kiosk_ui = !CommandLine::ForCurrentProcess()-> |
89 apps_list); | 100 HasSwitch(switches::kDisableNewKioskUI); |
| 101 web_ui()->CallJavascriptFunction(new_kiosk_ui ? |
| 102 kKioskSetAppsNewAPI : kKioskSetAppsOldAPI, |
| 103 apps_list); |
90 } | 104 } |
91 | 105 |
92 void KioskAppMenuHandler::HandleInitializeKioskApps( | 106 void KioskAppMenuHandler::HandleInitializeKioskApps( |
93 const base::ListValue* args) { | 107 const base::ListValue* args) { |
94 policy::BrowserPolicyConnectorChromeOS* connector = | 108 policy::BrowserPolicyConnectorChromeOS* connector = |
95 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 109 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
96 if (!base::SysInfo::IsRunningOnChromeOS() || | 110 if (!base::SysInfo::IsRunningOnChromeOS() || |
97 connector->IsEnterpriseManaged()) { | 111 connector->IsEnterpriseManaged()) { |
98 initialized_ = true; | 112 initialized_ = true; |
99 SendKioskApps(); | 113 SendKioskApps(); |
(...skipping 21 matching lines...) Expand all Loading... |
121 } | 135 } |
122 | 136 |
123 void KioskAppMenuHandler::HandleCheckKioskAppLaunchError( | 137 void KioskAppMenuHandler::HandleCheckKioskAppLaunchError( |
124 const base::ListValue* args) { | 138 const base::ListValue* args) { |
125 KioskAppLaunchError::Error error = KioskAppLaunchError::Get(); | 139 KioskAppLaunchError::Error error = KioskAppLaunchError::Get(); |
126 if (error == KioskAppLaunchError::NONE) | 140 if (error == KioskAppLaunchError::NONE) |
127 return; | 141 return; |
128 KioskAppLaunchError::Clear(); | 142 KioskAppLaunchError::Clear(); |
129 | 143 |
130 const std::string error_message = KioskAppLaunchError::GetErrorMessage(error); | 144 const std::string error_message = KioskAppLaunchError::GetErrorMessage(error); |
131 web_ui()->CallJavascriptFunction("login.AppsMenuButton.showError", | 145 bool new_kiosk_ui = !CommandLine::ForCurrentProcess()-> |
132 base::StringValue(error_message)); | 146 HasSwitch(switches::kDisableNewKioskUI); |
| 147 web_ui()->CallJavascriptFunction(new_kiosk_ui ? |
| 148 kKioskShowErrorNewAPI : kKioskShowErrorOldAPI, |
| 149 base::StringValue(error_message)); |
133 } | 150 } |
134 | 151 |
135 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { | 152 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { |
136 SendKioskApps(); | 153 SendKioskApps(); |
137 } | 154 } |
138 | 155 |
139 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { | 156 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { |
140 SendKioskApps(); | 157 SendKioskApps(); |
141 } | 158 } |
142 | 159 |
143 } // namespace chromeos | 160 } // namespace chromeos |
OLD | NEW |