diff options
| author | skuhne <skuhne@google.com> | 2016-03-03 14:38:54 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-03-03 22:40:08 +0000 |
| commit | c4c351d99bce831759eead496bc8215d06b36509 (patch) | |
| tree | 0bcdf1a8b84568668ff6eb600a0f0c28b61dedf8 | |
| parent | 025ec1dc16aed7ff9ed633b76a33bd248a7fbaf8 (diff) | |
| download | chromium_src-c4c351d99bce831759eead496bc8215d06b36509.zip chromium_src-c4c351d99bce831759eead496bc8215d06b36509.tar.gz chromium_src-c4c351d99bce831759eead496bc8215d06b36509.tar.bz2 | |
Adding Mojo calls to query possible window sizes & create app with certain size
BUG=26511661
BUG=26510237
TEST=None yet, since there is no functionality on the other side.
Review URL: https://codereview.chromium.org/1704363003
Cr-Commit-Position: refs/heads/master@{#379121}
| -rw-r--r-- | chrome/browser/ui/app_list/arc/arc_app_utils.cc | 57 | ||||
| -rw-r--r-- | chrome/browser/ui/app_list/arc/arc_app_utils.h | 16 | ||||
| -rw-r--r-- | components/arc/common/app.mojom | 22 | ||||
| -rw-r--r-- | components/arc/test/fake_app_instance.cc | 10 | ||||
| -rw-r--r-- | components/arc/test/fake_app_instance.h | 7 |
5 files changed, 106 insertions, 6 deletions
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 1e9e974..3535fd7 100644 --- a/chrome/browser/ui/app_list/arc/arc_app_utils.cc +++ b/chrome/browser/ui/app_list/arc/arc_app_utils.cc @@ -9,6 +9,11 @@ namespace arc { +void GetAndroidAppTargetRect(gfx::Rect& target_rect) { + // TODO: Figure out where to put the android window. + target_rect.SetRect(0, 0, 0, 0); +} + bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); CHECK(prefs); @@ -37,10 +42,60 @@ bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { return false; } - app_instance->LaunchApp(app_info->package_name, app_info->activity); + gfx::Rect target_rect; + GetAndroidAppTargetRect(target_rect); + + arc::ScreenRectPtr rect = arc::ScreenRect::New(); + rect->left = target_rect.x(); + rect->right = target_rect.right(); + rect->top = target_rect.y(); + rect->bottom = target_rect.bottom(); + + app_instance->LaunchApp(app_info->package_name, app_info->activity, + std::move(rect)); prefs->SetLastLaunchTime(app_id, base::Time::Now()); return true; } +bool CanHandleResolution(content::BrowserContext* context, + const std::string& app_id, + const gfx::Rect& rect, + const CanHandleResolutionCallback callback) { + ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); + scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); + if (!app_info) { + VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id + << "."; + return false; + } + + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); + arc::AppInstance* app_instance = + bridge_service ? bridge_service->app_instance() : nullptr; + if (!app_instance) { + VLOG(2) << "Request to get resolution capability when bridge service is " + << "not ready: " << app_id << "."; + return false; + } + + if (bridge_service->app_version() < 1) { + VLOG(2) + << "CanHandleResolution() not supported by ARC app instance version " + << bridge_service->app_version(); + return false; + } + + arc::ScreenRectPtr screen_rect = arc::ScreenRect::New(); + screen_rect->left = rect.x(); + screen_rect->right = rect.right(); + screen_rect->top = rect.y(); + screen_rect->bottom = rect.bottom(); + + app_instance->CanHandleResolution(app_info->package_name, app_info->activity, + std::move(screen_rect), + callback); + return true; +} + } // namespace arc diff --git a/chrome/browser/ui/app_list/arc/arc_app_utils.h b/chrome/browser/ui/app_list/arc/arc_app_utils.h index 4563e5c..bd9ba93 100644 --- a/chrome/browser/ui/app_list/arc/arc_app_utils.h +++ b/chrome/browser/ui/app_list/arc/arc_app_utils.h @@ -7,14 +7,30 @@ #include <string> +#include "base/callback.h" +#include "ui/gfx/geometry/rect.h" + namespace content { class BrowserContext; } namespace arc { +using CanHandleResolutionCallback = base::Callback<void(bool)>; +} + +namespace arc { bool LaunchApp(content::BrowserContext* context, const std::string& app_id); +// Tests if the application can use the given target resolution. +// The callback will receive the information once known. +// A false will get returned if the result cannot be determined in which case +// the callback will not be called. +bool CanHandleResolution(content::BrowserContext* context, + const std::string& app_id, + const gfx::Rect& rect, + const CanHandleResolutionCallback callback); + } // namespace arc #endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_UTILS_H_ diff --git a/components/arc/common/app.mojom b/components/arc/common/app.mojom index 051d904..b18adbe 100644 --- a/components/arc/common/app.mojom +++ b/components/arc/common/app.mojom @@ -27,6 +27,14 @@ struct AppInfo { string activity; }; +// Represents a rectangle to specify screen coordinates. +struct ScreenRect { + int32 left; + int32 top; + int32 right; + int32 bottom; +}; + interface AppHost { // Receives a list of available ARC apps to Chrome. Members of AppInfo must // contain non-empty string. @@ -56,8 +64,10 @@ interface AppInstance { Init(AppHost host_ptr); // Sends a request to ARC to launch an ARC app defined by |package_name| and - // |activity|, which cannot be empty. - LaunchApp(string package_name, string activity); + // |activity|, which cannot be empty. |dimension_on_screen| can be null to + // indicate to use the entire screen. + LaunchApp(string package_name, string activity, + [MinVersion=1] ScreenRect? dimension); // Sends a request to ARC to refresh a list of ARC apps. // OnRefreshAppsList is expected in response to this message. However, @@ -68,5 +78,11 @@ interface AppInstance { // Sends a request to ARC for the ARC app icon of a required scale factor. // Scale factor is an enum defined at ui/base/layout.h. App is defined by // |package_name| and |activity|, which cannot be empty. - RequestAppIcon(string package_name, string activity, ScaleFactor scale_factor); + RequestAppIcon(string package_name, string activity, + ScaleFactor scale_factor); + + // Query if a given resolution can be handled by the application. Returns true + // if it can. + [MinVersion=1] CanHandleResolution(string package_name, string activity, + ScreenRect dimension) => (bool success); }; diff --git a/components/arc/test/fake_app_instance.cc b/components/arc/test/fake_app_instance.cc index f837a7b..8f6fe71 100644 --- a/components/arc/test/fake_app_instance.cc +++ b/components/arc/test/fake_app_instance.cc @@ -37,7 +37,8 @@ void FakeAppInstance::RefreshAppList() { } void FakeAppInstance::LaunchApp(const mojo::String& package_name, - const mojo::String& activity) { + const mojo::String& activity, + ScreenRectPtr dimension) { launch_requests_.push_back(new Request(package_name, activity)); } @@ -125,4 +126,11 @@ void FakeAppInstance::WaitForOnAppInstanceReady() { } } +void FakeAppInstance::CanHandleResolution(const mojo::String& package_name, + const mojo::String& activity, + ScreenRectPtr dimension, + const CanHandleResolutionCallback& callback) { + callback.Run(true); +} + } // namespace arc diff --git a/components/arc/test/fake_app_instance.h b/components/arc/test/fake_app_instance.h index cf2240e..3f29ee8 100644 --- a/components/arc/test/fake_app_instance.h +++ b/components/arc/test/fake_app_instance.h @@ -67,10 +67,15 @@ class FakeAppInstance : public AppInstance { void Init(AppHostPtr host_ptr) override {} void RefreshAppList() override; void LaunchApp(const mojo::String& package_name, - const mojo::String& activity) override; + const mojo::String& activity, + ScreenRectPtr dimension) override; void RequestAppIcon(const mojo::String& package_name, const mojo::String& activity, ScaleFactor scale_factor) override; + void CanHandleResolution(const mojo::String& package_name, + const mojo::String& activity, + ScreenRectPtr dimension, + const CanHandleResolutionCallback& callback) override; // Methods to reply messages. void SendRefreshAppList(const std::vector<AppInfo>& apps); |
