Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Unified Diff: chrome/browser/ui/app_list/arc/arc_app_utils.cc

Issue 2540433002: Reland "Propagate information about how ARC apps are launched" (Closed)
Patch Set: Fixed use-after-free Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_utils.h ('k') | chrome/browser/ui/app_list/search/arc_app_result.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..12b6727d88b417654d242a7ce1b19c0b02c59981 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,16 @@ constexpr char kSetActiveTaskStr[] = "set active task";
constexpr char kShowPackageInfoStr[] = "show package info";
constexpr char kUninstallPackageStr[] = "uninstall package";
+// Intent helper strings.
+constexpr char kIntentHelperClassName[] =
+ "org.chromium.arc.intent_helper.SettingsReceiver";
+constexpr char kIntentHelperPackageName[] = "org.chromium.arc.intent_helper";
+constexpr char kSendBroadcastStr[] = "SendBroadcast";
+constexpr char kSetInTouchModeIntent[] =
+ "org.chromium.arc.intent_helper.SET_IN_TOUCH_MODE";
+constexpr char kShowTalkbackSettingsIntent[] =
+ "org.chromium.arc.intent_helper.SHOW_TALKBACK_SETTINGS";
+
// Helper function which returns the AppInstance. Create related logs when error
// happens.
arc::mojom::AppInstance* GetAppInstance(uint32_t required_version,
@@ -65,6 +78,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 +131,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 +146,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 +160,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 +183,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 +212,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 +238,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(
+ kSetInTouchModeIntent, kIntentHelperPackageName, kIntentHelperClassName,
+ extras_string);
+ }
+
if (app_info->shortcut) {
app_instance->LaunchIntent(app_info->intent_uri, target_rect);
} else {
@@ -206,18 +261,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 +309,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 +326,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 +348,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",
- "{}");
+ intent_helper_instance->SendBroadcast(kShowTalkbackSettingsIntent,
+ kIntentHelperPackageName,
+ kIntentHelperClassName, "{}");
}
bool CanHandleResolution(content::BrowserContext* context,
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_utils.h ('k') | chrome/browser/ui/app_list/search/arc_app_result.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698