| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/device_stylus_handler.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/device_stylus_handler.h" |
| 6 | 6 |
| 7 #include "ash/common/system/chromeos/palette/palette_utils.h" | 7 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "chrome/browser/chromeos/arc/arc_util.h" | 9 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 dict->SetString(kAppNameKey, info.name); | 77 dict->SetString(kAppNameKey, info.name); |
| 78 dict->SetString(kAppIdKey, info.app_id); | 78 dict->SetString(kAppIdKey, info.app_id); |
| 79 dict->SetBoolean(kAppPreferredKey, info.preferred); | 79 dict->SetBoolean(kAppPreferredKey, info.preferred); |
| 80 apps_list.Append(std::move(dict)); | 80 apps_list.Append(std::move(dict)); |
| 81 | 81 |
| 82 note_taking_app_ids_.insert(info.app_id); | 82 note_taking_app_ids_.insert(info.app_id); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 AllowJavascript(); | 86 AllowJavascript(); |
| 87 CallJavascriptFunction( | 87 CallJavascriptFunction("cr.webUIListenerCallback", |
| 88 "cr.webUIListenerCallback", base::StringValue("onNoteTakingAppsUpdated"), | 88 base::StringValue("onNoteTakingAppsUpdated"), |
| 89 apps_list, base::FundamentalValue(waiting_for_android)); | 89 apps_list, base::Value(waiting_for_android)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void StylusHandler::RequestApps(const base::ListValue* unused_args) { | 92 void StylusHandler::RequestApps(const base::ListValue* unused_args) { |
| 93 UpdateNoteTakingApps(); | 93 UpdateNoteTakingApps(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) { | 96 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) { |
| 97 std::string app_id; | 97 std::string app_id; |
| 98 CHECK(args->GetString(0, &app_id)); | 98 CHECK(args->GetString(0, &app_id)); |
| 99 | 99 |
| 100 // Sanity check: make sure that the ID we got back from WebUI is in the | 100 // Sanity check: make sure that the ID we got back from WebUI is in the |
| 101 // currently-available set. | 101 // currently-available set. |
| 102 if (!note_taking_app_ids_.count(app_id)) { | 102 if (!note_taking_app_ids_.count(app_id)) { |
| 103 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; | 103 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), | 107 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), |
| 108 app_id); | 108 app_id); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void StylusHandler::HandleInitialize(const base::ListValue* args) { | 111 void StylusHandler::HandleInitialize(const base::ListValue* args) { |
| 112 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) | 112 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) |
| 113 SendHasStylus(); | 113 SendHasStylus(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void StylusHandler::SendHasStylus() { | 116 void StylusHandler::SendHasStylus() { |
| 117 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); | 117 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); |
| 118 AllowJavascript(); | 118 AllowJavascript(); |
| 119 CallJavascriptFunction( | 119 CallJavascriptFunction("cr.webUIListenerCallback", |
| 120 "cr.webUIListenerCallback", base::StringValue("has-stylus-changed"), | 120 base::StringValue("has-stylus-changed"), |
| 121 base::FundamentalValue(ash::palette_utils::HasStylusInput())); | 121 base::Value(ash::palette_utils::HasStylusInput())); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void StylusHandler::ShowPlayStoreApps(const base::ListValue* args) { | 124 void StylusHandler::ShowPlayStoreApps(const base::ListValue* args) { |
| 125 std::string apps_url; | 125 std::string apps_url; |
| 126 args->GetString(0, &apps_url); | 126 args->GetString(0, &apps_url); |
| 127 Profile* profile = Profile::FromWebUI(web_ui()); | 127 Profile* profile = Profile::FromWebUI(web_ui()); |
| 128 if (!arc::IsArcAllowedForProfile(profile)) { | 128 if (!arc::IsArcAllowedForProfile(profile)) { |
| 129 VLOG(1) << "ARC is not enabled for this profile"; | 129 VLOG(1) << "ARC is not enabled for this profile"; |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 | 132 |
| 133 arc::LaunchPlayStoreWithUrl(apps_url); | 133 arc::LaunchPlayStoreWithUrl(apps_url); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace settings | 136 } // namespace settings |
| 137 } // namespace chromeos | 137 } // namespace chromeos |
| OLD | NEW |