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/app_list/arc/arc_app_utils.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_writer.h" | |
12 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/values.h" | |
13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 15 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
14 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
16 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
17 #include "chromeos/dbus/session_manager_client.h" | 19 #include "chromeos/dbus/session_manager_client.h" |
18 #include "components/arc/arc_bridge_service.h" | 20 #include "components/arc/arc_bridge_service.h" |
19 #include "components/arc/common/intent_helper.mojom.h" | 21 #include "components/arc/common/intent_helper.mojom.h" |
20 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
21 #include "ui/display/display.h" | 23 #include "ui/display/display.h" |
22 #include "ui/display/screen.h" | 24 #include "ui/display/screen.h" |
25 #include "ui/events/event_constants.h" | |
23 | 26 |
24 namespace arc { | 27 namespace arc { |
25 | 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 // Default sizes to use. | 31 // Default sizes to use. |
29 constexpr int kNexus7Width = 960; | 32 constexpr int kNexus7Width = 960; |
30 constexpr int kNexus7Height = 600; | 33 constexpr int kNexus7Height = 600; |
31 constexpr int kNexus5Width = 410; | 34 constexpr int kNexus5Width = 410; |
32 constexpr int kNexus5Height = 690; | 35 constexpr int kNexus5Height = 690; |
(...skipping 10 matching lines...) Expand all Loading... | |
43 | 46 |
44 // Service name strings. | 47 // Service name strings. |
45 constexpr char kCanHandleResolutionStr[] = "get resolution capability"; | 48 constexpr char kCanHandleResolutionStr[] = "get resolution capability"; |
46 constexpr char kCloseTaskStr[] = "close task"; | 49 constexpr char kCloseTaskStr[] = "close task"; |
47 constexpr char kLaunchAppStr[] = "launch app"; | 50 constexpr char kLaunchAppStr[] = "launch app"; |
48 constexpr char kRemoveIconStr[] = "remove icon"; | 51 constexpr char kRemoveIconStr[] = "remove icon"; |
49 constexpr char kSetActiveTaskStr[] = "set active task"; | 52 constexpr char kSetActiveTaskStr[] = "set active task"; |
50 constexpr char kShowPackageInfoStr[] = "show package info"; | 53 constexpr char kShowPackageInfoStr[] = "show package info"; |
51 constexpr char kUninstallPackageStr[] = "uninstall package"; | 54 constexpr char kUninstallPackageStr[] = "uninstall package"; |
52 | 55 |
56 // Intent helper strings. | |
57 constexpr char kIntentHelperPackageName[] = "org.chromium.arc.intent_helper"; | |
58 constexpr char kIntentHelperClassName[] = | |
59 "org.chromium.arc.intent_helper.SettingsReceiver"; | |
60 | |
53 // Helper function which returns the AppInstance. Create related logs when error | 61 // Helper function which returns the AppInstance. Create related logs when error |
54 // happens. | 62 // happens. |
55 arc::mojom::AppInstance* GetAppInstance(uint32_t required_version, | 63 arc::mojom::AppInstance* GetAppInstance(uint32_t required_version, |
56 const std::string& service_name) { | 64 const std::string& service_name) { |
57 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 65 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
58 if (!bridge_service) { | 66 if (!bridge_service) { |
59 VLOG(2) << "Request to " << service_name | 67 VLOG(2) << "Request to " << service_name |
60 << " when bridge service is not ready."; | 68 << " when bridge service is not ready."; |
61 return nullptr; | 69 return nullptr; |
62 } | 70 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // WindowPositioner::GetDefaultWindowBounds does for now. | 103 // WindowPositioner::GetDefaultWindowBounds does for now. |
96 // Note: Android's positioning will not overlap the shelf - as such we can | 104 // Note: Android's positioning will not overlap the shelf - as such we can |
97 // ignore the given workspace inset. | 105 // ignore the given workspace inset. |
98 // TODO(skuhne): Replace this with some more useful logic from the | 106 // TODO(skuhne): Replace this with some more useful logic from the |
99 // WindowPositioner. | 107 // WindowPositioner. |
100 result.set_x((work_area.width() - result.width()) / 2); | 108 result.set_x((work_area.width() - result.width()) / 2); |
101 result.set_y((work_area.height() - result.height()) / 2); | 109 result.set_y((work_area.height() - result.height()) / 2); |
102 return result; | 110 return result; |
103 } | 111 } |
104 | 112 |
113 // Returns true if |event_flags| came from a mouse or touch event. | |
114 bool IsMouseOrTouchEventFromFlags(int event_flags) { | |
115 return (event_flags & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON | | |
116 ui::EF_RIGHT_MOUSE_BUTTON | ui::EF_BACK_MOUSE_BUTTON | | |
117 ui::EF_FORWARD_MOUSE_BUTTON | ui::EF_FROM_TOUCH)) != 0; | |
118 } | |
119 | |
105 // A class which handles the asynchronous ARC runtime callback to figure out if | 120 // A class which handles the asynchronous ARC runtime callback to figure out if |
106 // an app can handle a certain resolution or not. | 121 // an app can handle a certain resolution or not. |
107 // After LaunchAndRelease() got called, the object will destroy itself once | 122 // After LaunchAndRelease() got called, the object will destroy itself once |
108 // done. | 123 // done. |
109 class LaunchAppWithoutSize { | 124 class LaunchAppWithoutSize { |
110 public: | 125 public: |
111 LaunchAppWithoutSize(content::BrowserContext* context, | 126 LaunchAppWithoutSize(content::BrowserContext* context, |
112 const std::string& app_id, | 127 const std::string& app_id, |
113 bool landscape_mode) | 128 bool landscape_mode, |
114 : context_(context), app_id_(app_id), landscape_mode_(landscape_mode) {} | 129 int event_flags) |
130 : context_(context), | |
131 app_id_(app_id), | |
132 landscape_mode_(landscape_mode), | |
133 event_flags_(event_flags) {} | |
115 | 134 |
116 // This will launch the request and after the return the creator does not | 135 // This will launch the request and after the return the creator does not |
117 // need to delete the object anymore. | 136 // need to delete the object anymore. |
118 bool LaunchAndRelease() { | 137 bool LaunchAndRelease() { |
119 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) | 138 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) |
120 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); | 139 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); |
121 if (!ash::Shell::HasInstance()) { | 140 if (!ash::Shell::HasInstance()) { |
122 // Skip this if there is no Ash shell. | 141 // Skip this if there is no Ash shell. |
123 LaunchAppWithRect(context_, app_id_, landscape_); | 142 LaunchAppWithRect(context_, app_id_, landscape_, event_flags_); |
124 delete this; | 143 delete this; |
125 return true; | 144 return true; |
126 } | 145 } |
127 | 146 |
128 // TODO(skuhne): Change CanHandleResolution into a call which returns | 147 // TODO(skuhne): Change CanHandleResolution into a call which returns |
129 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which | 148 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which |
130 // might also return the used DP->PIX conversion constant to do better | 149 // might also return the used DP->PIX conversion constant to do better |
131 // size calculations. | 150 // size calculations. |
132 bool result = CanHandleResolution( | 151 bool result = CanHandleResolution( |
133 context_, app_id_, landscape_, | 152 context_, app_id_, landscape_, |
134 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); | 153 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); |
135 if (!result) | 154 if (!result) |
136 delete this; | 155 delete this; |
137 | 156 |
138 return result; | 157 return result; |
139 } | 158 } |
140 | 159 |
141 private: | 160 private: |
142 content::BrowserContext* context_; | 161 content::BrowserContext* context_; |
143 const std::string app_id_; | 162 const std::string app_id_; |
144 const bool landscape_mode_; | 163 const bool landscape_mode_; |
145 gfx::Rect landscape_; | 164 gfx::Rect landscape_; |
165 const int event_flags_; | |
146 | 166 |
147 // The callback handler which gets called from the CanHandleResolution | 167 // The callback handler which gets called from the CanHandleResolution |
148 // function. | 168 // function. |
149 void Callback(bool can_handle) { | 169 void Callback(bool can_handle) { |
150 gfx::Size target_size = | 170 gfx::Size target_size = |
151 can_handle ? landscape_.size() : gfx::Size(kNexus5Width, kNexus5Height); | 171 can_handle ? landscape_.size() : gfx::Size(kNexus5Width, kNexus5Height); |
152 LaunchAppWithRect(context_, app_id_, GetTargetRect(target_size)); | 172 LaunchAppWithRect(context_, app_id_, GetTargetRect(target_size), |
173 event_flags_); | |
153 // Now that we are done, we can delete ourselves. | 174 // Now that we are done, we can delete ourselves. |
154 delete this; | 175 delete this; |
155 } | 176 } |
156 | 177 |
157 DISALLOW_COPY_AND_ASSIGN(LaunchAppWithoutSize); | 178 DISALLOW_COPY_AND_ASSIGN(LaunchAppWithoutSize); |
158 }; | 179 }; |
159 | 180 |
160 } // namespace | 181 } // namespace |
161 | 182 |
162 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; | 183 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; |
163 const char kPlayStorePackage[] = "com.android.vending"; | 184 const char kPlayStorePackage[] = "com.android.vending"; |
164 const char kPlayStoreActivity[] = "com.android.vending.AssetBrowserActivity"; | 185 const char kPlayStoreActivity[] = "com.android.vending.AssetBrowserActivity"; |
165 const char kSettingsAppId[] = "mconboelelhjpkbdhhiijkgcimoangdj"; | 186 const char kSettingsAppId[] = "mconboelelhjpkbdhhiijkgcimoangdj"; |
166 | 187 |
167 bool ShouldShowInLauncher(const std::string& app_id) { | 188 bool ShouldShowInLauncher(const std::string& app_id) { |
168 return (app_id != kSettingsAppId); | 189 return (app_id != kSettingsAppId); |
169 } | 190 } |
170 | 191 |
171 bool LaunchAppWithRect(content::BrowserContext* context, | 192 bool LaunchAppWithRect(content::BrowserContext* context, |
172 const std::string& app_id, | 193 const std::string& app_id, |
173 const gfx::Rect& target_rect) { | 194 const gfx::Rect& target_rect, |
195 int event_flags) { | |
174 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 196 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
175 CHECK(prefs); | 197 CHECK(prefs); |
176 | 198 |
177 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 199 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
178 if (!app_info) { | 200 if (!app_info) { |
179 VLOG(2) << "Cannot launch unavailable app: " << app_id << "."; | 201 VLOG(2) << "Cannot launch unavailable app: " << app_id << "."; |
180 return false; | 202 return false; |
181 } | 203 } |
182 | 204 |
183 if (!app_info->ready) { | 205 if (!app_info->ready) { |
184 VLOG(2) << "Cannot launch not-ready app: " << app_id << "."; | 206 VLOG(2) << "Cannot launch not-ready app: " << app_id << "."; |
185 return false; | 207 return false; |
186 } | 208 } |
187 | 209 |
188 if (!app_info->launchable) { | 210 if (!app_info->launchable) { |
189 VLOG(2) << "Cannot launch non-launchable app: " << app_id << "."; | 211 VLOG(2) << "Cannot launch non-launchable app: " << app_id << "."; |
190 return false; | 212 return false; |
191 } | 213 } |
192 | 214 |
193 arc::mojom::AppInstance* app_instance = | 215 arc::mojom::AppInstance* app_instance = |
194 GetAppInstance(kMinVersion, kLaunchAppStr); | 216 GetAppInstance(kMinVersion, kLaunchAppStr); |
195 if (!app_instance) | 217 if (!app_instance) |
196 return false; | 218 return false; |
197 | 219 |
220 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
221 DCHECK(bridge_service); | |
222 auto* intent_helper_instance = | |
223 bridge_service->intent_helper()->GetInstanceForMethod( | |
224 "SendBroadcast", kSendBroadcastMinVersion); | |
225 if (intent_helper_instance) { | |
khmel
2016/11/28 22:08:51
Nit: please log error if instance is not available
Luis Héctor Chávez
2016/11/28 22:50:00
GetInstanceForMethod already performs logging. We
| |
226 base::DictionaryValue extras; | |
227 extras.SetBoolean("inTouchMode", IsMouseOrTouchEventFromFlags(event_flags)); | |
228 std::string extras_string; | |
229 base::JSONWriter::Write(extras, &extras_string); | |
230 intent_helper_instance->SendBroadcast( | |
231 "org.chromium.arc.intent_helper.SET_IN_TOUCH_MODE", | |
232 kIntentHelperPackageName, kIntentHelperClassName, extras_string); | |
233 } | |
234 | |
198 if (app_info->shortcut) { | 235 if (app_info->shortcut) { |
199 app_instance->LaunchIntent(app_info->intent_uri, target_rect); | 236 app_instance->LaunchIntent(app_info->intent_uri, target_rect); |
200 } else { | 237 } else { |
201 app_instance->LaunchApp(app_info->package_name, app_info->activity, | 238 app_instance->LaunchApp(app_info->package_name, app_info->activity, |
202 target_rect); | 239 target_rect); |
203 } | 240 } |
204 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 241 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
205 | 242 |
206 return true; | 243 return true; |
207 } | 244 } |
208 | 245 |
209 bool LaunchAndroidSettingsApp(content::BrowserContext* context) { | 246 bool LaunchAndroidSettingsApp(content::BrowserContext* context, |
247 int event_flags) { | |
210 constexpr bool kUseLandscapeLayout = true; | 248 constexpr bool kUseLandscapeLayout = true; |
211 return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout); | 249 return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout, |
212 } | 250 event_flags); |
213 | |
214 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { | |
215 return LaunchApp(context, app_id, true); | |
216 } | 251 } |
217 | 252 |
218 bool LaunchApp(content::BrowserContext* context, | 253 bool LaunchApp(content::BrowserContext* context, |
219 const std::string& app_id, | 254 const std::string& app_id, |
220 bool landscape_layout) { | 255 int event_flags) { |
256 constexpr bool kUseLandscapeLayout = true; | |
257 return LaunchApp(context, app_id, kUseLandscapeLayout, event_flags); | |
258 } | |
259 | |
260 bool LaunchApp(content::BrowserContext* context, | |
261 const std::string& app_id, | |
262 bool landscape_layout, | |
263 int event_flags) { | |
221 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 264 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
222 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 265 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
223 if (app_info && !app_info->ready) { | 266 if (app_info && !app_info->ready) { |
224 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); | 267 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); |
225 DCHECK(arc_session_manager); | 268 DCHECK(arc_session_manager); |
226 | 269 |
227 bool arc_activated = false; | 270 bool arc_activated = false; |
228 if (!arc_session_manager->IsArcEnabled()) { | 271 if (!arc_session_manager->IsArcEnabled()) { |
229 if (!prefs->IsDefault(app_id)) { | 272 if (!prefs->IsDefault(app_id)) { |
230 NOTREACHED(); | 273 NOTREACHED(); |
(...skipping 27 matching lines...) Expand all Loading... | |
258 chromeos::SessionManagerClient* session_manager_client = | 301 chromeos::SessionManagerClient* session_manager_client = |
259 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 302 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
260 session_manager_client->PrioritizeArcInstance( | 303 session_manager_client->PrioritizeArcInstance( |
261 base::Bind(PrioritizeArcInstanceCallback)); | 304 base::Bind(PrioritizeArcInstanceCallback)); |
262 } | 305 } |
263 } | 306 } |
264 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 307 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
265 return true; | 308 return true; |
266 } | 309 } |
267 | 310 |
268 return (new LaunchAppWithoutSize(context, app_id, landscape_layout)) | 311 return (new LaunchAppWithoutSize(context, app_id, landscape_layout, |
312 event_flags)) | |
269 ->LaunchAndRelease(); | 313 ->LaunchAndRelease(); |
270 } | 314 } |
271 | 315 |
272 void SetTaskActive(int task_id) { | 316 void SetTaskActive(int task_id) { |
273 arc::mojom::AppInstance* app_instance = | 317 arc::mojom::AppInstance* app_instance = |
274 GetAppInstance(kTaskSupportMinVersion, kSetActiveTaskStr); | 318 GetAppInstance(kTaskSupportMinVersion, kSetActiveTaskStr); |
275 if (!app_instance) | 319 if (!app_instance) |
276 return; | 320 return; |
277 app_instance->SetTaskActive(task_id); | 321 app_instance->SetTaskActive(task_id); |
278 } | 322 } |
(...skipping 13 matching lines...) Expand all Loading... | |
292 return; | 336 return; |
293 } | 337 } |
294 | 338 |
295 auto* intent_helper_instance = | 339 auto* intent_helper_instance = |
296 bridge_service->intent_helper()->GetInstanceForMethod( | 340 bridge_service->intent_helper()->GetInstanceForMethod( |
297 "SendBroadcast", kSendBroadcastMinVersion); | 341 "SendBroadcast", kSendBroadcastMinVersion); |
298 if (!intent_helper_instance) | 342 if (!intent_helper_instance) |
299 return; | 343 return; |
300 | 344 |
301 intent_helper_instance->SendBroadcast( | 345 intent_helper_instance->SendBroadcast( |
302 "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS", | 346 "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS", |
303 "org.chromium.arc.intent_helper", | 347 kIntentHelperPackageName, kIntentHelperClassName, "{}"); |
304 "org.chromium.arc.intent_helper.SettingsReceiver", | |
305 "{}"); | |
306 } | 348 } |
307 | 349 |
308 bool CanHandleResolution(content::BrowserContext* context, | 350 bool CanHandleResolution(content::BrowserContext* context, |
309 const std::string& app_id, | 351 const std::string& app_id, |
310 const gfx::Rect& rect, | 352 const gfx::Rect& rect, |
311 const CanHandleResolutionCallback& callback) { | 353 const CanHandleResolutionCallback& callback) { |
312 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 354 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
313 DCHECK(prefs); | 355 DCHECK(prefs); |
314 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 356 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
315 if (!app_info) { | 357 if (!app_info) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 if (!app_instance) | 415 if (!app_instance) |
374 return false; | 416 return false; |
375 | 417 |
376 app_instance->ShowPackageInfoOnPage( | 418 app_instance->ShowPackageInfoOnPage( |
377 package_name, page, | 419 package_name, page, |
378 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); | 420 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); |
379 return true; | 421 return true; |
380 } | 422 } |
381 | 423 |
382 } // namespace arc | 424 } // namespace arc |
OLD | NEW |