| 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/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 12 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| 13 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 13 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 14 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 15 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
| 16 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/webui/web_ui_util.h" | 20 #include "ui/base/webui/web_ui_util.h" |
| 22 | 21 |
| 23 namespace chromeos { | 22 namespace chromeos { |
| 24 | 23 |
| 25 KioskAppMenuHandler::KioskAppMenuHandler() | 24 KioskAppMenuHandler::KioskAppMenuHandler() |
| 26 : initialized_(false), | 25 : weak_ptr_factory_(this) { |
| 27 weak_ptr_factory_(this) { | |
| 28 KioskAppManager::Get()->AddObserver(this); | 26 KioskAppManager::Get()->AddObserver(this); |
| 29 } | 27 } |
| 30 | 28 |
| 31 KioskAppMenuHandler::~KioskAppMenuHandler() { | 29 KioskAppMenuHandler::~KioskAppMenuHandler() { |
| 32 KioskAppManager::Get()->RemoveObserver(this); | 30 KioskAppManager::Get()->RemoveObserver(this); |
| 33 } | 31 } |
| 34 | 32 |
| 35 void KioskAppMenuHandler::GetLocalizedStrings( | 33 void KioskAppMenuHandler::GetLocalizedStrings( |
| 36 base::DictionaryValue* localized_strings) { | 34 base::DictionaryValue* localized_strings) { |
| 37 localized_strings->SetString( | 35 localized_strings->SetString( |
| 38 "showApps", | 36 "showApps", |
| 39 l10n_util::GetStringUTF16(IDS_KIOSK_APPS_BUTTON)); | 37 l10n_util::GetStringUTF16(IDS_KIOSK_APPS_BUTTON)); |
| 40 } | 38 } |
| 41 | 39 |
| 42 void KioskAppMenuHandler::RegisterMessages() { | 40 void KioskAppMenuHandler::RegisterMessages() { |
| 43 web_ui()->RegisterMessageCallback("initializeKioskApps", | 41 web_ui()->RegisterMessageCallback("initializeKioskApps", |
| 44 base::Bind(&KioskAppMenuHandler::HandleInitializeKioskApps, | 42 base::Bind(&KioskAppMenuHandler::HandleInitializeKioskApps, |
| 45 base::Unretained(this))); | 43 base::Unretained(this))); |
| 46 web_ui()->RegisterMessageCallback("kioskAppsLoaded", | 44 web_ui()->RegisterMessageCallback("kioskAppsLoaded", |
| 47 base::Bind(&KioskAppMenuHandler::HandleKioskAppsLoaded, | 45 base::Bind(&KioskAppMenuHandler::HandleKioskAppsLoaded, |
| 48 base::Unretained(this))); | 46 base::Unretained(this))); |
| 49 web_ui()->RegisterMessageCallback("checkKioskAppLaunchError", | 47 web_ui()->RegisterMessageCallback("checkKioskAppLaunchError", |
| 50 base::Bind(&KioskAppMenuHandler::HandleCheckKioskAppLaunchError, | 48 base::Bind(&KioskAppMenuHandler::HandleCheckKioskAppLaunchError, |
| 51 base::Unretained(this))); | 49 base::Unretained(this))); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void KioskAppMenuHandler::SendKioskApps() { | 52 void KioskAppMenuHandler::SendKioskApps() { |
| 55 if (!initialized_) | |
| 56 return; | |
| 57 | |
| 58 KioskAppManager::Apps apps; | 53 KioskAppManager::Apps apps; |
| 59 KioskAppManager::Get()->GetApps(&apps); | 54 KioskAppManager::Get()->GetApps(&apps); |
| 60 | 55 |
| 61 base::ListValue apps_list; | 56 base::ListValue apps_list; |
| 62 for (size_t i = 0; i < apps.size(); ++i) { | 57 for (size_t i = 0; i < apps.size(); ++i) { |
| 63 const KioskAppManager::App& app_data = apps[i]; | 58 const KioskAppManager::App& app_data = apps[i]; |
| 64 | 59 |
| 65 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 60 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
| 66 app_info->SetString("id", app_data.app_id); | 61 app_info->SetString("id", app_data.app_id); |
| 67 app_info->SetString("label", app_data.name); | 62 app_info->SetString("label", app_data.name); |
| 68 | 63 |
| 69 // TODO(xiyuan): Replace data url with a URLDataSource. | 64 // TODO(xiyuan): Replace data url with a URLDataSource. |
| 70 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 65 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
| 71 if (!app_data.icon.isNull()) | 66 if (!app_data.icon.isNull()) |
| 72 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); | 67 icon_url = webui::GetBitmapDataUrl(*app_data.icon.bitmap()); |
| 73 app_info->SetString("iconUrl", icon_url); | 68 app_info->SetString("iconUrl", icon_url); |
| 74 | 69 |
| 75 apps_list.Append(app_info.release()); | 70 apps_list.Append(app_info.release()); |
| 76 } | 71 } |
| 77 | 72 |
| 78 web_ui()->CallJavascriptFunction("login.AppsMenuButton.setApps", | 73 web_ui()->CallJavascriptFunction("login.AppsMenuButton.setApps", |
| 79 apps_list); | 74 apps_list); |
| 80 } | 75 } |
| 81 | 76 |
| 82 void KioskAppMenuHandler::HandleInitializeKioskApps( | 77 void KioskAppMenuHandler::HandleInitializeKioskApps( |
| 83 const base::ListValue* args) { | 78 const base::ListValue* args) { |
| 84 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 85 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 86 if (connector->IsEnterpriseManaged()) { | |
| 87 initialized_ = true; | |
| 88 SendKioskApps(); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 KioskAppManager::Get()->GetConsumerKioskModeStatus( | |
| 93 base::Bind(&KioskAppMenuHandler::OnGetConsumerKioskModeStatus, | |
| 94 weak_ptr_factory_.GetWeakPtr())); | |
| 95 } | |
| 96 | |
| 97 void KioskAppMenuHandler::OnGetConsumerKioskModeStatus( | |
| 98 KioskAppManager::ConsumerKioskModeStatus status) { | |
| 99 initialized_ = | |
| 100 status == KioskAppManager::CONSUMER_KIOSK_MODE_ENABLED; | |
| 101 SendKioskApps(); | 79 SendKioskApps(); |
| 102 } | 80 } |
| 103 | 81 |
| 104 void KioskAppMenuHandler::HandleKioskAppsLoaded( | 82 void KioskAppMenuHandler::HandleKioskAppsLoaded( |
| 105 const base::ListValue* args) { | 83 const base::ListValue* args) { |
| 106 content::NotificationService::current()->Notify( | 84 content::NotificationService::current()->Notify( |
| 107 chrome::NOTIFICATION_KIOSK_APPS_LOADED, | 85 chrome::NOTIFICATION_KIOSK_APPS_LOADED, |
| 108 content::NotificationService::AllSources(), | 86 content::NotificationService::AllSources(), |
| 109 content::NotificationService::NoDetails()); | 87 content::NotificationService::NoDetails()); |
| 110 } | 88 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 | 101 |
| 124 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { | 102 void KioskAppMenuHandler::OnKioskAppsSettingsChanged() { |
| 125 SendKioskApps(); | 103 SendKioskApps(); |
| 126 } | 104 } |
| 127 | 105 |
| 128 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { | 106 void KioskAppMenuHandler::OnKioskAppDataChanged(const std::string& app_id) { |
| 129 SendKioskApps(); | 107 SendKioskApps(); |
| 130 } | 108 } |
| 131 | 109 |
| 132 } // namespace chromeos | 110 } // namespace chromeos |
| OLD | NEW |