| 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" | |
| 16 #include "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
| 17 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 20 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/webui/web_ui_util.h" | 21 #include "ui/base/webui/web_ui_util.h" |
| 23 | 22 |
| 24 namespace chromeos { | 23 namespace chromeos { |
| 25 | 24 |
| 26 KioskAppMenuHandler::KioskAppMenuHandler() | 25 KioskAppMenuHandler::KioskAppMenuHandler() |
| 27 : initialized_(false), | 26 : weak_ptr_factory_(this) { |
| 28 weak_ptr_factory_(this) { | |
| 29 KioskAppManager::Get()->AddObserver(this); | 27 KioskAppManager::Get()->AddObserver(this); |
| 30 } | 28 } |
| 31 | 29 |
| 32 KioskAppMenuHandler::~KioskAppMenuHandler() { | 30 KioskAppMenuHandler::~KioskAppMenuHandler() { |
| 33 KioskAppManager::Get()->RemoveObserver(this); | 31 KioskAppManager::Get()->RemoveObserver(this); |
| 34 } | 32 } |
| 35 | 33 |
| 36 void KioskAppMenuHandler::GetLocalizedStrings( | 34 void KioskAppMenuHandler::GetLocalizedStrings( |
| 37 base::DictionaryValue* localized_strings) { | 35 base::DictionaryValue* localized_strings) { |
| 38 localized_strings->SetString( | 36 localized_strings->SetString( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 base::Unretained(this))); | 53 base::Unretained(this))); |
| 56 web_ui()->RegisterMessageCallback("kioskAppsLoaded", | 54 web_ui()->RegisterMessageCallback("kioskAppsLoaded", |
| 57 base::Bind(&KioskAppMenuHandler::HandleKioskAppsLoaded, | 55 base::Bind(&KioskAppMenuHandler::HandleKioskAppsLoaded, |
| 58 base::Unretained(this))); | 56 base::Unretained(this))); |
| 59 web_ui()->RegisterMessageCallback("checkKioskAppLaunchError", | 57 web_ui()->RegisterMessageCallback("checkKioskAppLaunchError", |
| 60 base::Bind(&KioskAppMenuHandler::HandleCheckKioskAppLaunchError, | 58 base::Bind(&KioskAppMenuHandler::HandleCheckKioskAppLaunchError, |
| 61 base::Unretained(this))); | 59 base::Unretained(this))); |
| 62 } | 60 } |
| 63 | 61 |
| 64 void KioskAppMenuHandler::SendKioskApps() { | 62 void KioskAppMenuHandler::SendKioskApps() { |
| 65 if (!initialized_) | |
| 66 return; | |
| 67 | |
| 68 KioskAppManager::Apps apps; | 63 KioskAppManager::Apps apps; |
| 69 KioskAppManager::Get()->GetApps(&apps); | 64 KioskAppManager::Get()->GetApps(&apps); |
| 70 | 65 |
| 71 base::ListValue apps_list; | 66 base::ListValue apps_list; |
| 72 for (size_t i = 0; i < apps.size(); ++i) { | 67 for (size_t i = 0; i < apps.size(); ++i) { |
| 73 const KioskAppManager::App& app_data = apps[i]; | 68 const KioskAppManager::App& app_data = apps[i]; |
| 74 | 69 |
| 75 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 70 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
| 76 app_info->SetString("id", app_data.app_id); | 71 app_info->SetString("id", app_data.app_id); |
| 77 app_info->SetString("label", app_data.name); | 72 app_info->SetString("label", app_data.name); |
| 78 | 73 |
| 79 // TODO(xiyuan): Replace data url with a URLDataSource. | 74 // TODO(xiyuan): Replace data url with a URLDataSource. |
| 80 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 75 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
| 81 if (!app_data.icon.isNull()) | 76 if (!app_data.icon.isNull()) |
| 82 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); | 77 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); |
| 83 app_info->SetString("iconUrl", icon_url); | 78 app_info->SetString("iconUrl", icon_url); |
| 84 | 79 |
| 85 apps_list.Append(app_info.release()); | 80 apps_list.Append(app_info.release()); |
| 86 } | 81 } |
| 87 | 82 |
| 88 web_ui()->CallJavascriptFunction("login.AppsMenuButton.setApps", | 83 web_ui()->CallJavascriptFunction("login.AppsMenuButton.setApps", |
| 89 apps_list); | 84 apps_list); |
| 90 } | 85 } |
| 91 | 86 |
| 92 void KioskAppMenuHandler::HandleInitializeKioskApps( | 87 void KioskAppMenuHandler::HandleInitializeKioskApps( |
| 93 const base::ListValue* args) { | 88 const base::ListValue* args) { |
| 94 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 95 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 96 if (!base::SysInfo::IsRunningOnChromeOS() || | |
| 97 connector->IsEnterpriseManaged()) { | |
| 98 initialized_ = true; | |
| 99 SendKioskApps(); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 KioskAppManager::Get()->GetConsumerKioskModeStatus( | |
| 104 base::Bind(&KioskAppMenuHandler::OnGetConsumerKioskModeStatus, | |
| 105 weak_ptr_factory_.GetWeakPtr())); | |
| 106 } | |
| 107 | |
| 108 void KioskAppMenuHandler::OnGetConsumerKioskModeStatus( | |
| 109 KioskAppManager::ConsumerKioskModeStatus status) { | |
| 110 initialized_ = | |
| 111 status == KioskAppManager::CONSUMER_KIOSK_MODE_ENABLED; | |
| 112 SendKioskApps(); | 89 SendKioskApps(); |
| 113 } | 90 } |
| 114 | 91 |
| 115 void KioskAppMenuHandler::HandleKioskAppsLoaded( | 92 void KioskAppMenuHandler::HandleKioskAppsLoaded( |
| 116 const base::ListValue* args) { | 93 const base::ListValue* args) { |
| 117 content::NotificationService::current()->Notify( | 94 content::NotificationService::current()->Notify( |
| 118 chrome::NOTIFICATION_KIOSK_APPS_LOADED, | 95 chrome::NOTIFICATION_KIOSK_APPS_LOADED, |
| 119 content::NotificationService::AllSources(), | 96 content::NotificationService::AllSources(), |
| 120 content::NotificationService::NoDetails()); | 97 content::NotificationService::NoDetails()); |
| 121 } | 98 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 | 111 |
| 135 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { | 112 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { |
| 136 SendKioskApps(); | 113 SendKioskApps(); |
| 137 } | 114 } |
| 138 | 115 |
| 139 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { | 116 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { |
| 140 SendKioskApps(); | 117 SendKioskApps(); |
| 141 } | 118 } |
| 142 | 119 |
| 143 } // namespace chromeos | 120 } // namespace chromeos |
| OLD | NEW |