Chromium Code Reviews| Index: chrome/browser/ui/app_list/arc/arc_app_utils.cc |
| diff --git a/chrome/browser/ui/app_list/arc/arc_app_utils.cc b/chrome/browser/ui/app_list/arc/arc_app_utils.cc |
| index a120f6474a876159f94a80c28195ebb249bf404c..c51a9ac5e093ab5ef32bcb898b05d9622acd7a90 100644 |
| --- a/chrome/browser/ui/app_list/arc/arc_app_utils.cc |
| +++ b/chrome/browser/ui/app_list/arc/arc_app_utils.cc |
| @@ -9,7 +9,9 @@ |
| #include "ash/shell.h" |
| #include "base/bind.h" |
| +#include "base/json/json_writer.h" |
| #include "base/synchronization/waitable_event.h" |
| +#include "base/values.h" |
| #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
| #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| @@ -20,6 +22,7 @@ |
| #include "ui/aura/window.h" |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| +#include "ui/events/event_constants.h" |
| namespace arc { |
| @@ -50,6 +53,12 @@ constexpr char kSetActiveTaskStr[] = "set active task"; |
| constexpr char kShowPackageInfoStr[] = "show package info"; |
| constexpr char kUninstallPackageStr[] = "uninstall package"; |
| +// Intent helper strings. |
| +constexpr char kSendBroadcastStr[] = "SendBroadcast"; |
| +constexpr char kIntentHelperPackageName[] = "org.chromium.arc.intent_helper"; |
| +constexpr char kIntentHelperClassName[] = |
| + "org.chromium.arc.intent_helper.SettingsReceiver"; |
| + |
| // Helper function which returns the AppInstance. Create related logs when error |
| // happens. |
| arc::mojom::AppInstance* GetAppInstance(uint32_t required_version, |
| @@ -65,6 +74,22 @@ arc::mojom::AppInstance* GetAppInstance(uint32_t required_version, |
| required_version); |
| } |
| +// Helper function which returns the IntentHelperInstance. Create related logs |
| +// when error happens. |
| +arc::mojom::IntentHelperInstance* GetIntentHelperInstance( |
| + uint32_t required_version, |
| + const std::string& service_name) { |
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| + if (!bridge_service) { |
| + VLOG(2) << "Request to " << service_name |
| + << " when bridge service is not ready."; |
| + return nullptr; |
| + } |
| + |
| + return bridge_service->intent_helper()->GetInstanceForMethod( |
| + service_name.c_str(), required_version); |
| +} |
| + |
| void PrioritizeArcInstanceCallback(bool success) { |
| VLOG(2) << "Finished prioritizing the instance: result=" << success; |
| if (!success) |
| @@ -102,6 +127,13 @@ gfx::Rect GetTargetRect(const gfx::Size& size) { |
| return result; |
| } |
| +// Returns true if |event_flags| came from a mouse or touch event. |
| +bool IsMouseOrTouchEventFromFlags(int event_flags) { |
| + return (event_flags & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON | |
| + ui::EF_RIGHT_MOUSE_BUTTON | ui::EF_BACK_MOUSE_BUTTON | |
| + ui::EF_FORWARD_MOUSE_BUTTON | ui::EF_FROM_TOUCH)) != 0; |
| +} |
| + |
| // A class which handles the asynchronous ARC runtime callback to figure out if |
| // an app can handle a certain resolution or not. |
| // After LaunchAndRelease() got called, the object will destroy itself once |
| @@ -110,8 +142,12 @@ class LaunchAppWithoutSize { |
| public: |
| LaunchAppWithoutSize(content::BrowserContext* context, |
| const std::string& app_id, |
| - bool landscape_mode) |
| - : context_(context), app_id_(app_id), landscape_mode_(landscape_mode) {} |
| + bool landscape_mode, |
| + int event_flags) |
| + : context_(context), |
| + app_id_(app_id), |
| + landscape_mode_(landscape_mode), |
| + event_flags_(event_flags) {} |
| // This will launch the request and after the return the creator does not |
| // need to delete the object anymore. |
| @@ -120,7 +156,7 @@ class LaunchAppWithoutSize { |
| : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); |
| if (!ash::Shell::HasInstance()) { |
| // Skip this if there is no Ash shell. |
| - LaunchAppWithRect(context_, app_id_, landscape_); |
| + LaunchAppWithRect(context_, app_id_, landscape_, event_flags_); |
| delete this; |
| return true; |
| } |
| @@ -143,13 +179,15 @@ class LaunchAppWithoutSize { |
| const std::string app_id_; |
| const bool landscape_mode_; |
| gfx::Rect landscape_; |
| + const int event_flags_; |
| // The callback handler which gets called from the CanHandleResolution |
| // function. |
| void Callback(bool can_handle) { |
| gfx::Size target_size = |
| can_handle ? landscape_.size() : gfx::Size(kNexus5Width, kNexus5Height); |
| - LaunchAppWithRect(context_, app_id_, GetTargetRect(target_size)); |
| + LaunchAppWithRect(context_, app_id_, GetTargetRect(target_size), |
| + event_flags_); |
| // Now that we are done, we can delete ourselves. |
| delete this; |
| } |
| @@ -170,7 +208,8 @@ bool ShouldShowInLauncher(const std::string& app_id) { |
| bool LaunchAppWithRect(content::BrowserContext* context, |
| const std::string& app_id, |
| - const gfx::Rect& target_rect) { |
| + const gfx::Rect& target_rect, |
| + int event_flags) { |
| ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
| CHECK(prefs); |
| @@ -195,6 +234,18 @@ bool LaunchAppWithRect(content::BrowserContext* context, |
| if (!app_instance) |
| return false; |
| + arc::mojom::IntentHelperInstance* intent_helper_instance = |
| + GetIntentHelperInstance(kSendBroadcastMinVersion, kSendBroadcastStr); |
| + if (intent_helper_instance) { |
| + base::DictionaryValue extras; |
| + extras.SetBoolean("inTouchMode", IsMouseOrTouchEventFromFlags(event_flags)); |
| + std::string extras_string; |
| + base::JSONWriter::Write(extras, &extras_string); |
| + intent_helper_instance->SendBroadcast( |
| + "org.chromium.arc.intent_helper.SET_IN_TOUCH_MODE", |
|
stevenjb
2016/11/29 20:17:10
We should also define this as a constant above.
Luis Héctor Chávez
2016/11/29 20:50:46
Done.
|
| + kIntentHelperPackageName, kIntentHelperClassName, extras_string); |
| + } |
| + |
| if (app_info->shortcut) { |
| app_instance->LaunchIntent(app_info->intent_uri, target_rect); |
| } else { |
| @@ -206,18 +257,24 @@ bool LaunchAppWithRect(content::BrowserContext* context, |
| return true; |
| } |
| -bool LaunchAndroidSettingsApp(content::BrowserContext* context) { |
| +bool LaunchAndroidSettingsApp(content::BrowserContext* context, |
| + int event_flags) { |
| constexpr bool kUseLandscapeLayout = true; |
| - return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout); |
| + return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout, |
| + event_flags); |
| } |
| -bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { |
| - return LaunchApp(context, app_id, true); |
| +bool LaunchApp(content::BrowserContext* context, |
| + const std::string& app_id, |
| + int event_flags) { |
| + constexpr bool kUseLandscapeLayout = true; |
| + return LaunchApp(context, app_id, kUseLandscapeLayout, event_flags); |
| } |
| bool LaunchApp(content::BrowserContext* context, |
| const std::string& app_id, |
| - bool landscape_layout) { |
| + bool landscape_layout, |
| + int event_flags) { |
| ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
| std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
| if (app_info && !app_info->ready) { |
| @@ -248,7 +305,7 @@ bool LaunchApp(content::BrowserContext* context, |
| DCHECK(chrome_controller || !ash::Shell::HasInstance()); |
| if (chrome_controller) { |
| chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch( |
| - app_id); |
| + app_id, event_flags); |
| // On some boards, ARC is booted with a restricted set of resources by |
| // default to avoid slowing down Chrome's user session restoration. |
| @@ -265,7 +322,8 @@ bool LaunchApp(content::BrowserContext* context, |
| return true; |
| } |
| - return (new LaunchAppWithoutSize(context, app_id, landscape_layout)) |
| + return (new LaunchAppWithoutSize(context, app_id, landscape_layout, |
| + event_flags)) |
| ->LaunchAndRelease(); |
| } |
| @@ -286,23 +344,14 @@ void CloseTask(int task_id) { |
| } |
| void ShowTalkBackSettings() { |
| - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| - if (!bridge_service) { |
| - VLOG(2) << "ARC bridge is not ready"; |
| - return; |
| - } |
| - |
| - auto* intent_helper_instance = |
| - bridge_service->intent_helper()->GetInstanceForMethod( |
| - "SendBroadcast", kSendBroadcastMinVersion); |
| + arc::mojom::IntentHelperInstance* intent_helper_instance = |
| + GetIntentHelperInstance(kSendBroadcastMinVersion, kSendBroadcastStr); |
| if (!intent_helper_instance) |
| return; |
| intent_helper_instance->SendBroadcast( |
| - "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS", |
| - "org.chromium.arc.intent_helper", |
| - "org.chromium.arc.intent_helper.SettingsReceiver", |
| - "{}"); |
| + "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS", |
|
stevenjb
2016/11/29 20:17:10
This too.
Luis Héctor Chávez
2016/11/29 20:50:46
Done.
|
| + kIntentHelperPackageName, kIntentHelperClassName, "{}"); |
| } |
| bool CanHandleResolution(content::BrowserContext* context, |