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/system/palette/palette_utils.h" | 7 #include "ash/system/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("cr.webUIListenerCallback", | 87 FireWebUIListener("onNoteTakingAppsUpdated", apps_list, |
88 base::Value("onNoteTakingAppsUpdated"), apps_list, | 88 base::Value(waiting_for_android)); |
89 base::Value(waiting_for_android)); | |
90 } | 89 } |
91 | 90 |
92 void StylusHandler::RequestApps(const base::ListValue* unused_args) { | 91 void StylusHandler::RequestApps(const base::ListValue* unused_args) { |
93 UpdateNoteTakingApps(); | 92 UpdateNoteTakingApps(); |
94 } | 93 } |
95 | 94 |
96 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) { | 95 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) { |
97 std::string app_id; | 96 std::string app_id; |
98 CHECK(args->GetString(0, &app_id)); | 97 CHECK(args->GetString(0, &app_id)); |
99 | 98 |
100 // Sanity check: make sure that the ID we got back from WebUI is in the | 99 // Sanity check: make sure that the ID we got back from WebUI is in the |
101 // currently-available set. | 100 // currently-available set. |
102 if (!note_taking_app_ids_.count(app_id)) { | 101 if (!note_taking_app_ids_.count(app_id)) { |
103 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; | 102 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; |
104 return; | 103 return; |
105 } | 104 } |
106 | 105 |
107 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), | 106 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), |
108 app_id); | 107 app_id); |
109 } | 108 } |
110 | 109 |
111 void StylusHandler::HandleInitialize(const base::ListValue* args) { | 110 void StylusHandler::HandleInitialize(const base::ListValue* args) { |
112 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) | 111 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) |
113 SendHasStylus(); | 112 SendHasStylus(); |
114 } | 113 } |
115 | 114 |
116 void StylusHandler::SendHasStylus() { | 115 void StylusHandler::SendHasStylus() { |
117 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); | 116 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); |
118 AllowJavascript(); | 117 AllowJavascript(); |
119 CallJavascriptFunction("cr.webUIListenerCallback", | 118 FireWebUIListener("has-stylus-changed", |
120 base::Value("has-stylus-changed"), | 119 base::Value(ash::palette_utils::HasStylusInput())); |
121 base::Value(ash::palette_utils::HasStylusInput())); | |
122 } | 120 } |
123 | 121 |
124 void StylusHandler::ShowPlayStoreApps(const base::ListValue* args) { | 122 void StylusHandler::ShowPlayStoreApps(const base::ListValue* args) { |
125 std::string apps_url; | 123 std::string apps_url; |
126 args->GetString(0, &apps_url); | 124 args->GetString(0, &apps_url); |
127 Profile* profile = Profile::FromWebUI(web_ui()); | 125 Profile* profile = Profile::FromWebUI(web_ui()); |
128 if (!arc::IsArcAllowedForProfile(profile)) { | 126 if (!arc::IsArcAllowedForProfile(profile)) { |
129 VLOG(1) << "ARC is not enabled for this profile"; | 127 VLOG(1) << "ARC is not enabled for this profile"; |
130 return; | 128 return; |
131 } | 129 } |
132 | 130 |
133 arc::LaunchPlayStoreWithUrl(apps_url); | 131 arc::LaunchPlayStoreWithUrl(apps_url); |
134 } | 132 } |
135 | 133 |
136 } // namespace settings | 134 } // namespace settings |
137 } // namespace chromeos | 135 } // namespace chromeos |
OLD | NEW |