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 "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/webui/web_ui_util.h" | 21 #include "ui/base/webui/web_ui_util.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 | 24 |
| 25 namespace { |
| 26 |
| 27 // JS functions that define new and old kiosk UI API. |
| 28 const char kKioskSetAppsNewAPI[] = "login.AccountPickerScreen.setApps"; |
| 29 const char kKioskSetAppsOldAPI[] = "login.AppsMenuButton.setApps"; |
| 30 const char kKioskShowErrorNewAPI[] = "login.AccountPickerScreen.showAppError"; |
| 31 const char kKioskShowErrorOldAPI[] = "login.AppsMenuButton.showError"; |
| 32 |
| 33 } // namespace |
| 34 |
25 KioskAppMenuHandler::KioskAppMenuHandler() | 35 KioskAppMenuHandler::KioskAppMenuHandler() |
26 : weak_ptr_factory_(this) { | 36 : weak_ptr_factory_(this), |
| 37 is_webui_initialized_(false) { |
27 KioskAppManager::Get()->AddObserver(this); | 38 KioskAppManager::Get()->AddObserver(this); |
28 } | 39 } |
29 | 40 |
30 KioskAppMenuHandler::~KioskAppMenuHandler() { | 41 KioskAppMenuHandler::~KioskAppMenuHandler() { |
31 KioskAppManager::Get()->RemoveObserver(this); | 42 KioskAppManager::Get()->RemoveObserver(this); |
32 } | 43 } |
33 | 44 |
34 void KioskAppMenuHandler::GetLocalizedStrings( | 45 void KioskAppMenuHandler::GetLocalizedStrings( |
35 base::DictionaryValue* localized_strings) { | 46 base::DictionaryValue* localized_strings) { |
36 localized_strings->SetString( | 47 localized_strings->SetString( |
(...skipping 16 matching lines...) Expand all Loading... |
53 base::Unretained(this))); | 64 base::Unretained(this))); |
54 web_ui()->RegisterMessageCallback("kioskAppsLoaded", | 65 web_ui()->RegisterMessageCallback("kioskAppsLoaded", |
55 base::Bind(&KioskAppMenuHandler::HandleKioskAppsLoaded, | 66 base::Bind(&KioskAppMenuHandler::HandleKioskAppsLoaded, |
56 base::Unretained(this))); | 67 base::Unretained(this))); |
57 web_ui()->RegisterMessageCallback("checkKioskAppLaunchError", | 68 web_ui()->RegisterMessageCallback("checkKioskAppLaunchError", |
58 base::Bind(&KioskAppMenuHandler::HandleCheckKioskAppLaunchError, | 69 base::Bind(&KioskAppMenuHandler::HandleCheckKioskAppLaunchError, |
59 base::Unretained(this))); | 70 base::Unretained(this))); |
60 } | 71 } |
61 | 72 |
62 void KioskAppMenuHandler::SendKioskApps() { | 73 void KioskAppMenuHandler::SendKioskApps() { |
| 74 if (!is_webui_initialized_) |
| 75 return; |
| 76 |
63 KioskAppManager::Apps apps; | 77 KioskAppManager::Apps apps; |
64 KioskAppManager::Get()->GetApps(&apps); | 78 KioskAppManager::Get()->GetApps(&apps); |
65 | 79 |
66 base::ListValue apps_list; | 80 base::ListValue apps_list; |
67 for (size_t i = 0; i < apps.size(); ++i) { | 81 for (size_t i = 0; i < apps.size(); ++i) { |
68 const KioskAppManager::App& app_data = apps[i]; | 82 const KioskAppManager::App& app_data = apps[i]; |
69 | 83 |
70 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 84 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
| 85 app_info->SetBoolean("isApp", true); |
71 app_info->SetString("id", app_data.app_id); | 86 app_info->SetString("id", app_data.app_id); |
72 app_info->SetString("label", app_data.name); | 87 app_info->SetString("label", app_data.name); |
73 | 88 |
74 // TODO(xiyuan): Replace data url with a URLDataSource. | 89 // TODO(xiyuan): Replace data url with a URLDataSource. |
75 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 90 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
76 if (!app_data.icon.isNull()) | 91 if (!app_data.icon.isNull()) |
77 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); | 92 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); |
78 app_info->SetString("iconUrl", icon_url); | 93 app_info->SetString("iconUrl", icon_url); |
79 | 94 |
80 apps_list.Append(app_info.release()); | 95 apps_list.Append(app_info.release()); |
81 } | 96 } |
82 | 97 |
83 web_ui()->CallJavascriptFunction("login.AppsMenuButton.setApps", | 98 bool new_kiosk_ui = !CommandLine::ForCurrentProcess()-> |
84 apps_list); | 99 HasSwitch(switches::kDisableNewKioskUI); |
| 100 web_ui()->CallJavascriptFunction(new_kiosk_ui ? |
| 101 kKioskSetAppsNewAPI : kKioskSetAppsOldAPI, |
| 102 apps_list); |
85 } | 103 } |
86 | 104 |
87 void KioskAppMenuHandler::HandleInitializeKioskApps( | 105 void KioskAppMenuHandler::HandleInitializeKioskApps( |
88 const base::ListValue* args) { | 106 const base::ListValue* args) { |
| 107 is_webui_initialized_ = true; |
89 SendKioskApps(); | 108 SendKioskApps(); |
90 } | 109 } |
91 | 110 |
92 void KioskAppMenuHandler::HandleKioskAppsLoaded( | 111 void KioskAppMenuHandler::HandleKioskAppsLoaded( |
93 const base::ListValue* args) { | 112 const base::ListValue* args) { |
94 content::NotificationService::current()->Notify( | 113 content::NotificationService::current()->Notify( |
95 chrome::NOTIFICATION_KIOSK_APPS_LOADED, | 114 chrome::NOTIFICATION_KIOSK_APPS_LOADED, |
96 content::NotificationService::AllSources(), | 115 content::NotificationService::AllSources(), |
97 content::NotificationService::NoDetails()); | 116 content::NotificationService::NoDetails()); |
98 } | 117 } |
99 | 118 |
100 void KioskAppMenuHandler::HandleCheckKioskAppLaunchError( | 119 void KioskAppMenuHandler::HandleCheckKioskAppLaunchError( |
101 const base::ListValue* args) { | 120 const base::ListValue* args) { |
102 KioskAppLaunchError::Error error = KioskAppLaunchError::Get(); | 121 KioskAppLaunchError::Error error = KioskAppLaunchError::Get(); |
103 if (error == KioskAppLaunchError::NONE) | 122 if (error == KioskAppLaunchError::NONE) |
104 return; | 123 return; |
105 KioskAppLaunchError::Clear(); | 124 KioskAppLaunchError::Clear(); |
106 | 125 |
107 const std::string error_message = KioskAppLaunchError::GetErrorMessage(error); | 126 const std::string error_message = KioskAppLaunchError::GetErrorMessage(error); |
108 web_ui()->CallJavascriptFunction("login.AppsMenuButton.showError", | 127 bool new_kiosk_ui = !CommandLine::ForCurrentProcess()-> |
109 base::StringValue(error_message)); | 128 HasSwitch(switches::kDisableNewKioskUI); |
| 129 web_ui()->CallJavascriptFunction(new_kiosk_ui ? |
| 130 kKioskShowErrorNewAPI : kKioskShowErrorOldAPI, |
| 131 base::StringValue(error_message)); |
110 } | 132 } |
111 | 133 |
112 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { | 134 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { |
113 SendKioskApps(); | 135 SendKioskApps(); |
114 } | 136 } |
115 | 137 |
116 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { | 138 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { |
117 SendKioskApps(); | 139 SendKioskApps(); |
118 } | 140 } |
119 | 141 |
120 } // namespace chromeos | 142 } // namespace chromeos |
OLD | NEW |