| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/settings/chromeos/android_apps_handler.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/android_apps_handler.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/chromeos/arc/arc_util.h" | 8 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" // kSettingsAppId | 10 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" // kSettingsAppId |
| 11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 namespace settings { | 14 namespace settings { |
| 15 | 15 |
| 16 AndroidAppsHandler::AndroidAppsHandler(Profile* profile) | 16 AndroidAppsHandler::AndroidAppsHandler(Profile* profile) |
| 17 : arc_prefs_observer_(this), profile_(profile), weak_ptr_factory_(this) {} | 17 : arc_prefs_observer_(this), |
| 18 arc_session_manager_observer_(this), |
| 19 profile_(profile), |
| 20 weak_ptr_factory_(this) {} |
| 18 | 21 |
| 19 AndroidAppsHandler::~AndroidAppsHandler() {} | 22 AndroidAppsHandler::~AndroidAppsHandler() {} |
| 20 | 23 |
| 21 void AndroidAppsHandler::RegisterMessages() { | 24 void AndroidAppsHandler::RegisterMessages() { |
| 22 web_ui()->RegisterMessageCallback( | 25 web_ui()->RegisterMessageCallback( |
| 23 "requestAndroidAppsInfo", | 26 "requestAndroidAppsInfo", |
| 24 base::Bind(&AndroidAppsHandler::HandleRequestAndroidAppsInfo, | 27 base::Bind(&AndroidAppsHandler::HandleRequestAndroidAppsInfo, |
| 25 weak_ptr_factory_.GetWeakPtr())); | 28 weak_ptr_factory_.GetWeakPtr())); |
| 26 web_ui()->RegisterMessageCallback( | 29 web_ui()->RegisterMessageCallback( |
| 27 "showAndroidAppsSettings", | 30 "showAndroidAppsSettings", |
| 28 base::Bind(&AndroidAppsHandler::ShowAndroidAppsSettings, | 31 base::Bind(&AndroidAppsHandler::ShowAndroidAppsSettings, |
| 29 weak_ptr_factory_.GetWeakPtr())); | 32 weak_ptr_factory_.GetWeakPtr())); |
| 30 } | 33 } |
| 31 | 34 |
| 32 void AndroidAppsHandler::OnJavascriptAllowed() { | 35 void AndroidAppsHandler::OnJavascriptAllowed() { |
| 33 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); | 36 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); |
| 34 if (arc_prefs) | 37 if (arc_prefs) { |
| 35 arc_prefs_observer_.Add(arc_prefs); | 38 arc_prefs_observer_.Add(arc_prefs); |
| 39 // arc::ArcSessionManager is assosiated with primary profile. |
| 40 arc_session_manager_observer_.Add(arc::ArcSessionManager::Get()); |
| 41 } |
| 36 } | 42 } |
| 37 | 43 |
| 38 void AndroidAppsHandler::OnJavascriptDisallowed() { | 44 void AndroidAppsHandler::OnJavascriptDisallowed() { |
| 39 arc_prefs_observer_.RemoveAll(); | 45 arc_prefs_observer_.RemoveAll(); |
| 46 arc_session_manager_observer_.RemoveAll(); |
| 40 } | 47 } |
| 41 | 48 |
| 42 void AndroidAppsHandler::OnAppRegistered( | 49 void AndroidAppsHandler::OnAppRegistered( |
| 43 const std::string& app_id, | 50 const std::string& app_id, |
| 44 const ArcAppListPrefs::AppInfo& app_info) { | 51 const ArcAppListPrefs::AppInfo& app_info) { |
| 45 OnAppChanged(app_id); | 52 OnAppChanged(app_id); |
| 46 } | 53 } |
| 47 | 54 |
| 48 void AndroidAppsHandler::OnAppRemoved(const std::string& app_id) { | 55 void AndroidAppsHandler::OnAppRemoved(const std::string& app_id) { |
| 49 OnAppChanged(app_id); | 56 OnAppChanged(app_id); |
| 50 } | 57 } |
| 51 | 58 |
| 52 void AndroidAppsHandler::OnAppReadyChanged(const std::string& app_id, | |
| 53 bool ready) { | |
| 54 OnAppChanged(app_id); | |
| 55 } | |
| 56 | |
| 57 void AndroidAppsHandler::OnAppChanged(const std::string& app_id) { | 59 void AndroidAppsHandler::OnAppChanged(const std::string& app_id) { |
| 58 if (app_id != arc::kSettingsAppId) | 60 if (app_id != arc::kSettingsAppId) |
| 59 return; | 61 return; |
| 60 SendAndroidAppsInfo(); | 62 SendAndroidAppsInfo(); |
| 61 } | 63 } |
| 62 | 64 |
| 65 void AndroidAppsHandler::OnArcPlayStoreEnabledChanged(bool enabled) { |
| 66 SendAndroidAppsInfo(); |
| 67 } |
| 68 |
| 63 std::unique_ptr<base::DictionaryValue> | 69 std::unique_ptr<base::DictionaryValue> |
| 64 AndroidAppsHandler::BuildAndroidAppsInfo() { | 70 AndroidAppsHandler::BuildAndroidAppsInfo() { |
| 65 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue); | 71 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue); |
| 66 bool app_ready = false; | 72 info->SetBoolean("playStoreEnabled", |
| 67 if (arc::IsArcPlayStoreEnabledForProfile(profile_)) { | 73 arc::IsArcPlayStoreEnabledForProfile(profile_)); |
| 68 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 74 info->SetBoolean( |
| 69 ArcAppListPrefs::Get(profile_)->GetApp(arc::kSettingsAppId); | 75 "settingsAppAvailable", |
| 70 app_ready = app_info && app_info->ready; | 76 ArcAppListPrefs::Get(profile_)->IsRegistered(arc::kSettingsAppId)); |
| 71 } | |
| 72 info->SetBoolean("appReady", app_ready); | |
| 73 return info; | 77 return info; |
| 74 } | 78 } |
| 75 | 79 |
| 76 void AndroidAppsHandler::HandleRequestAndroidAppsInfo( | 80 void AndroidAppsHandler::HandleRequestAndroidAppsInfo( |
| 77 const base::ListValue* args) { | 81 const base::ListValue* args) { |
| 78 SendAndroidAppsInfo(); | 82 SendAndroidAppsInfo(); |
| 79 } | 83 } |
| 80 | 84 |
| 81 void AndroidAppsHandler::SendAndroidAppsInfo() { | 85 void AndroidAppsHandler::SendAndroidAppsInfo() { |
| 82 AllowJavascript(); | 86 AllowJavascript(); |
| 83 std::unique_ptr<base::DictionaryValue> info = BuildAndroidAppsInfo(); | 87 std::unique_ptr<base::DictionaryValue> info = BuildAndroidAppsInfo(); |
| 84 CallJavascriptFunction("cr.webUIListenerCallback", | 88 CallJavascriptFunction("cr.webUIListenerCallback", |
| 85 base::Value("android-apps-info-update"), *info); | 89 base::Value("android-apps-info-update"), *info); |
| 86 } | 90 } |
| 87 | 91 |
| 88 void AndroidAppsHandler::ShowAndroidAppsSettings(const base::ListValue* args) { | 92 void AndroidAppsHandler::ShowAndroidAppsSettings(const base::ListValue* args) { |
| 89 CHECK_EQ(1U, args->GetSize()); | 93 CHECK_EQ(1U, args->GetSize()); |
| 90 bool activated_from_keyboard = false; | 94 bool activated_from_keyboard = false; |
| 91 args->GetBoolean(0, &activated_from_keyboard); | 95 args->GetBoolean(0, &activated_from_keyboard); |
| 92 int flags = activated_from_keyboard ? ui::EF_NONE : ui::EF_LEFT_MOUSE_BUTTON; | 96 int flags = activated_from_keyboard ? ui::EF_NONE : ui::EF_LEFT_MOUSE_BUTTON; |
| 93 | 97 |
| 94 // Settings in secondary profile cannot access ARC. | 98 // Settings in secondary profile cannot access ARC. |
| 95 CHECK(arc::IsArcAllowedForProfile(profile_)); | 99 CHECK(arc::IsArcAllowedForProfile(profile_)); |
| 96 arc::LaunchAndroidSettingsApp(profile_, flags); | 100 arc::LaunchAndroidSettingsApp(profile_, flags); |
| 97 } | 101 } |
| 98 | 102 |
| 99 } // namespace settings | 103 } // namespace settings |
| 100 } // namespace chromeos | 104 } // namespace chromeos |
| OLD | NEW |