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_utils.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 } | 111 } |
104 | 112 |
105 // A class which handles the asynchronous ARC runtime callback to figure out if | 113 // A class which handles the asynchronous ARC runtime callback to figure out if |
106 // an app can handle a certain resolution or not. | 114 // an app can handle a certain resolution or not. |
107 // After LaunchAndRelease() got called, the object will destroy itself once | 115 // After LaunchAndRelease() got called, the object will destroy itself once |
108 // done. | 116 // done. |
109 class LaunchAppWithoutSize { | 117 class LaunchAppWithoutSize { |
110 public: | 118 public: |
111 LaunchAppWithoutSize(content::BrowserContext* context, | 119 LaunchAppWithoutSize(content::BrowserContext* context, |
112 const std::string& app_id, | 120 const std::string& app_id, |
113 bool landscape_mode) | 121 bool landscape_mode, |
114 : context_(context), app_id_(app_id), landscape_mode_(landscape_mode) {} | 122 int event_flags) |
123 : context_(context), | |
124 app_id_(app_id), | |
125 landscape_mode_(landscape_mode), | |
126 event_flags_(event_flags) {} | |
115 | 127 |
116 // This will launch the request and after the return the creator does not | 128 // This will launch the request and after the return the creator does not |
117 // need to delete the object anymore. | 129 // need to delete the object anymore. |
118 bool LaunchAndRelease() { | 130 bool LaunchAndRelease() { |
119 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) | 131 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) |
120 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); | 132 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); |
121 if (!ash::Shell::HasInstance()) { | 133 if (!ash::Shell::HasInstance()) { |
122 // Skip this if there is no Ash shell. | 134 // Skip this if there is no Ash shell. |
123 LaunchAppWithRect(context_, app_id_, landscape_); | 135 LaunchAppWithRect(context_, app_id_, landscape_, event_flags_); |
124 delete this; | 136 delete this; |
125 return true; | 137 return true; |
126 } | 138 } |
127 | 139 |
128 // TODO(skuhne): Change CanHandleResolution into a call which returns | 140 // TODO(skuhne): Change CanHandleResolution into a call which returns |
129 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which | 141 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which |
130 // might also return the used DP->PIX conversion constant to do better | 142 // might also return the used DP->PIX conversion constant to do better |
131 // size calculations. | 143 // size calculations. |
132 bool result = CanHandleResolution( | 144 bool result = CanHandleResolution( |
133 context_, app_id_, landscape_, | 145 context_, app_id_, landscape_, |
134 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); | 146 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); |
135 if (!result) | 147 if (!result) |
136 delete this; | 148 delete this; |
137 | 149 |
138 return result; | 150 return result; |
139 } | 151 } |
140 | 152 |
141 private: | 153 private: |
142 content::BrowserContext* context_; | 154 content::BrowserContext* context_; |
143 const std::string app_id_; | 155 const std::string app_id_; |
144 const bool landscape_mode_; | 156 const bool landscape_mode_; |
145 gfx::Rect landscape_; | 157 gfx::Rect landscape_; |
158 const int event_flags_; | |
146 | 159 |
147 // The callback handler which gets called from the CanHandleResolution | 160 // The callback handler which gets called from the CanHandleResolution |
148 // function. | 161 // function. |
149 void Callback(bool can_handle) { | 162 void Callback(bool can_handle) { |
150 gfx::Size target_size = | 163 gfx::Size target_size = |
151 can_handle ? landscape_.size() : gfx::Size(kNexus5Width, kNexus5Height); | 164 can_handle ? landscape_.size() : gfx::Size(kNexus5Width, kNexus5Height); |
152 LaunchAppWithRect(context_, app_id_, GetTargetRect(target_size)); | 165 LaunchAppWithRect(context_, app_id_, GetTargetRect(target_size), |
166 event_flags_); | |
153 // Now that we are done, we can delete ourselves. | 167 // Now that we are done, we can delete ourselves. |
154 delete this; | 168 delete this; |
155 } | 169 } |
156 | 170 |
157 DISALLOW_COPY_AND_ASSIGN(LaunchAppWithoutSize); | 171 DISALLOW_COPY_AND_ASSIGN(LaunchAppWithoutSize); |
158 }; | 172 }; |
159 | 173 |
160 } // namespace | 174 } // namespace |
161 | 175 |
162 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; | 176 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; |
163 const char kPlayStorePackage[] = "com.android.vending"; | 177 const char kPlayStorePackage[] = "com.android.vending"; |
164 const char kPlayStoreActivity[] = "com.android.vending.AssetBrowserActivity"; | 178 const char kPlayStoreActivity[] = "com.android.vending.AssetBrowserActivity"; |
165 const char kSettingsAppId[] = "mconboelelhjpkbdhhiijkgcimoangdj"; | 179 const char kSettingsAppId[] = "mconboelelhjpkbdhhiijkgcimoangdj"; |
166 | 180 |
167 bool ShouldShowInLauncher(const std::string& app_id) { | 181 bool ShouldShowInLauncher(const std::string& app_id) { |
168 return (app_id != kSettingsAppId); | 182 return (app_id != kSettingsAppId); |
169 } | 183 } |
170 | 184 |
171 bool LaunchAppWithRect(content::BrowserContext* context, | 185 bool LaunchAppWithRect(content::BrowserContext* context, |
172 const std::string& app_id, | 186 const std::string& app_id, |
173 const gfx::Rect& target_rect) { | 187 const gfx::Rect& target_rect, |
188 int event_flags) { | |
174 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 189 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
175 CHECK(prefs); | 190 CHECK(prefs); |
176 | 191 |
177 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 192 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
178 if (!app_info) { | 193 if (!app_info) { |
179 VLOG(2) << "Cannot launch unavailable app: " << app_id << "."; | 194 VLOG(2) << "Cannot launch unavailable app: " << app_id << "."; |
180 return false; | 195 return false; |
181 } | 196 } |
182 | 197 |
183 if (!app_info->ready) { | 198 if (!app_info->ready) { |
184 VLOG(2) << "Cannot launch not-ready app: " << app_id << "."; | 199 VLOG(2) << "Cannot launch not-ready app: " << app_id << "."; |
185 return false; | 200 return false; |
186 } | 201 } |
187 | 202 |
188 if (!app_info->launchable) { | 203 if (!app_info->launchable) { |
189 VLOG(2) << "Cannot launch non-launchable app: " << app_id << "."; | 204 VLOG(2) << "Cannot launch non-launchable app: " << app_id << "."; |
190 return false; | 205 return false; |
191 } | 206 } |
192 | 207 |
193 arc::mojom::AppInstance* app_instance = | 208 arc::mojom::AppInstance* app_instance = |
194 GetAppInstance(kMinVersion, kLaunchAppStr); | 209 GetAppInstance(kMinVersion, kLaunchAppStr); |
195 if (!app_instance) | 210 if (!app_instance) |
196 return false; | 211 return false; |
197 | 212 |
213 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
214 DCHECK(bridge_service); | |
215 auto* intent_helper_instance = | |
216 bridge_service->intent_helper()->GetInstanceForMethod( | |
217 "SendBroadcast", kSendBroadcastMinVersion); | |
218 if (intent_helper_instance) { | |
219 base::DictionaryValue extras; | |
220 extras.SetBoolean("inTouchMode", | |
khmel
2016/11/28 20:27:02
Can we make sure that sequence of operations is co
Luis Héctor Chávez
2016/11/28 20:30:28
I don't think such a guarantee is possible. Touch
| |
221 ui::IsMouseEventFromFlags(event_flags) || | |
222 ui::IsTouchEventFromFlags(event_flags)); | |
223 std::string extras_string; | |
224 base::JSONWriter::Write(extras, &extras_string); | |
225 intent_helper_instance->SendBroadcast( | |
226 "org.chromium.arc.intent_helper.SET_IN_TOUCH_MODE", | |
227 kIntentHelperPackageName, kIntentHelperClassName, extras_string); | |
228 } | |
229 | |
198 if (app_info->shortcut) { | 230 if (app_info->shortcut) { |
199 app_instance->LaunchIntent(app_info->intent_uri, target_rect); | 231 app_instance->LaunchIntent(app_info->intent_uri, target_rect); |
200 } else { | 232 } else { |
201 app_instance->LaunchApp(app_info->package_name, app_info->activity, | 233 app_instance->LaunchApp(app_info->package_name, app_info->activity, |
202 target_rect); | 234 target_rect); |
203 } | 235 } |
204 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 236 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
205 | 237 |
206 return true; | 238 return true; |
207 } | 239 } |
208 | 240 |
209 bool LaunchAndroidSettingsApp(content::BrowserContext* context) { | 241 bool LaunchAndroidSettingsApp(content::BrowserContext* context, |
242 int event_flags) { | |
210 constexpr bool kUseLandscapeLayout = true; | 243 constexpr bool kUseLandscapeLayout = true; |
211 return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout); | 244 return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout, |
212 } | 245 event_flags); |
213 | |
214 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { | |
215 return LaunchApp(context, app_id, true); | |
216 } | 246 } |
217 | 247 |
218 bool LaunchApp(content::BrowserContext* context, | 248 bool LaunchApp(content::BrowserContext* context, |
219 const std::string& app_id, | 249 const std::string& app_id, |
220 bool landscape_layout) { | 250 int event_flags) { |
251 constexpr bool kUseLandscapeLayout = true; | |
252 return LaunchApp(context, app_id, kUseLandscapeLayout, event_flags); | |
253 } | |
254 | |
255 bool LaunchApp(content::BrowserContext* context, | |
256 const std::string& app_id, | |
257 bool landscape_layout, | |
258 int event_flags) { | |
221 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 259 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
222 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 260 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
223 if (app_info && !app_info->ready) { | 261 if (app_info && !app_info->ready) { |
224 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); | 262 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); |
225 DCHECK(arc_session_manager); | 263 DCHECK(arc_session_manager); |
226 | 264 |
227 bool arc_activated = false; | 265 bool arc_activated = false; |
228 if (!arc_session_manager->IsArcEnabled()) { | 266 if (!arc_session_manager->IsArcEnabled()) { |
229 if (!prefs->IsDefault(app_id)) { | 267 if (!prefs->IsDefault(app_id)) { |
230 NOTREACHED(); | 268 NOTREACHED(); |
(...skipping 27 matching lines...) Expand all Loading... | |
258 chromeos::SessionManagerClient* session_manager_client = | 296 chromeos::SessionManagerClient* session_manager_client = |
259 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 297 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
260 session_manager_client->PrioritizeArcInstance( | 298 session_manager_client->PrioritizeArcInstance( |
261 base::Bind(PrioritizeArcInstanceCallback)); | 299 base::Bind(PrioritizeArcInstanceCallback)); |
262 } | 300 } |
263 } | 301 } |
264 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 302 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
265 return true; | 303 return true; |
266 } | 304 } |
267 | 305 |
268 return (new LaunchAppWithoutSize(context, app_id, landscape_layout)) | 306 return (new LaunchAppWithoutSize(context, app_id, landscape_layout, |
307 event_flags)) | |
269 ->LaunchAndRelease(); | 308 ->LaunchAndRelease(); |
270 } | 309 } |
271 | 310 |
272 void SetTaskActive(int task_id) { | 311 void SetTaskActive(int task_id) { |
273 arc::mojom::AppInstance* app_instance = | 312 arc::mojom::AppInstance* app_instance = |
274 GetAppInstance(kTaskSupportMinVersion, kSetActiveTaskStr); | 313 GetAppInstance(kTaskSupportMinVersion, kSetActiveTaskStr); |
275 if (!app_instance) | 314 if (!app_instance) |
276 return; | 315 return; |
277 app_instance->SetTaskActive(task_id); | 316 app_instance->SetTaskActive(task_id); |
278 } | 317 } |
(...skipping 13 matching lines...) Expand all Loading... | |
292 return; | 331 return; |
293 } | 332 } |
294 | 333 |
295 auto* intent_helper_instance = | 334 auto* intent_helper_instance = |
296 bridge_service->intent_helper()->GetInstanceForMethod( | 335 bridge_service->intent_helper()->GetInstanceForMethod( |
297 "SendBroadcast", kSendBroadcastMinVersion); | 336 "SendBroadcast", kSendBroadcastMinVersion); |
298 if (!intent_helper_instance) | 337 if (!intent_helper_instance) |
299 return; | 338 return; |
300 | 339 |
301 intent_helper_instance->SendBroadcast( | 340 intent_helper_instance->SendBroadcast( |
302 "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS", | 341 "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS", |
303 "org.chromium.arc.intent_helper", | 342 kIntentHelperPackageName, kIntentHelperClassName, "{}"); |
304 "org.chromium.arc.intent_helper.SettingsReceiver", | |
305 "{}"); | |
306 } | 343 } |
307 | 344 |
308 bool CanHandleResolution(content::BrowserContext* context, | 345 bool CanHandleResolution(content::BrowserContext* context, |
309 const std::string& app_id, | 346 const std::string& app_id, |
310 const gfx::Rect& rect, | 347 const gfx::Rect& rect, |
311 const CanHandleResolutionCallback& callback) { | 348 const CanHandleResolutionCallback& callback) { |
312 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 349 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
313 DCHECK(prefs); | 350 DCHECK(prefs); |
314 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 351 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
315 if (!app_info) { | 352 if (!app_info) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 if (!app_instance) | 410 if (!app_instance) |
374 return false; | 411 return false; |
375 | 412 |
376 app_instance->ShowPackageInfoOnPage( | 413 app_instance->ShowPackageInfoOnPage( |
377 package_name, page, | 414 package_name, page, |
378 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); | 415 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); |
379 return true; | 416 return true; |
380 } | 417 } |
381 | 418 |
382 } // namespace arc | 419 } // namespace arc |
OLD | NEW |