Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 13 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 13 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
| 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 15 #include "components/arc/arc_bridge_service.h" | 15 #include "components/arc/arc_bridge_service.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
| 18 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
| 19 | 19 |
| 20 namespace arc { | 20 namespace arc { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 constexpr bool kUseLandscapeLayout = true; | |
|
hidehiko
2016/07/12 16:25:14
optional: as this is constexpr, and used only in L
Luis Héctor Chávez
2016/07/12 18:00:24
Looks cleaner, so done.
| |
| 25 | |
| 24 // Default sizes to use. | 26 // Default sizes to use. |
| 25 constexpr int kNexus7Width = 960; | 27 constexpr int kNexus7Width = 960; |
| 26 constexpr int kNexus7Height = 600; | 28 constexpr int kNexus7Height = 600; |
| 27 constexpr int kNexus5Width = 410; | 29 constexpr int kNexus5Width = 410; |
| 28 constexpr int kNexus5Height = 690; | 30 constexpr int kNexus5Height = 690; |
| 29 | 31 |
| 30 // Minimum required versions. | 32 // Minimum required versions. |
| 31 constexpr int kMinVersion = 0; | 33 constexpr int kMinVersion = 0; |
| 32 constexpr int kCanHandleResolutionMinVersion = 1; | 34 constexpr int kCanHandleResolutionMinVersion = 1; |
| 33 constexpr int kUninstallPackageMinVersion = 2; | 35 constexpr int kUninstallPackageMinVersion = 2; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 46 // happens. | 48 // happens. |
| 47 arc::mojom::AppInstance* GetAppInstance(int required_version, | 49 arc::mojom::AppInstance* GetAppInstance(int required_version, |
| 48 const std::string& service_name) { | 50 const std::string& service_name) { |
| 49 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 51 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 50 if (!bridge_service) { | 52 if (!bridge_service) { |
| 51 VLOG(2) << "Request to " << service_name | 53 VLOG(2) << "Request to " << service_name |
| 52 << " when bridge service is not ready."; | 54 << " when bridge service is not ready."; |
| 53 return nullptr; | 55 return nullptr; |
| 54 } | 56 } |
| 55 | 57 |
| 56 arc::mojom::AppInstance* app_instance = bridge_service->app_instance(); | 58 arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
| 57 if (!app_instance) { | 59 if (!app_instance) { |
| 58 VLOG(2) << "Request to " << service_name | 60 VLOG(2) << "Request to " << service_name |
| 59 << " when mojom::app_instance is not ready."; | 61 << " when mojom::app_instance is not ready."; |
| 60 return nullptr; | 62 return nullptr; |
| 61 } | 63 } |
| 62 | 64 |
| 63 int bridge_version = bridge_service->app_version(); | 65 int bridge_version = bridge_service->app()->version(); |
| 64 if (bridge_version < required_version) { | 66 if (bridge_version < required_version) { |
| 65 VLOG(2) << "Request to " << service_name << " when Arc version " | 67 VLOG(2) << "Request to " << service_name << " when Arc version " |
| 66 << bridge_version << " does not support it."; | 68 << bridge_version << " does not support it."; |
| 67 return nullptr; | 69 return nullptr; |
| 68 } | 70 } |
| 69 | 71 |
| 70 return app_instance; | 72 return app_instance; |
| 71 } | 73 } |
| 72 | 74 |
| 73 // Find a proper size and position for a given rectangle on the screen. | 75 // Find a proper size and position for a given rectangle on the screen. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 102 } | 104 } |
| 103 | 105 |
| 104 // A class which handles the asynchronous ARC runtime callback to figure out if | 106 // A class which handles the asynchronous ARC runtime callback to figure out if |
| 105 // an app can handle a certain resolution or not. | 107 // an app can handle a certain resolution or not. |
| 106 // After LaunchAndRelease() got called, the object will destroy itself once | 108 // After LaunchAndRelease() got called, the object will destroy itself once |
| 107 // done. | 109 // done. |
| 108 class LaunchAppWithoutSize { | 110 class LaunchAppWithoutSize { |
| 109 public: | 111 public: |
| 110 LaunchAppWithoutSize(content::BrowserContext* context, | 112 LaunchAppWithoutSize(content::BrowserContext* context, |
| 111 const std::string& app_id, | 113 const std::string& app_id, |
| 112 bool landscape_mode) : | 114 bool landscape_mode) |
| 113 context_(context), | 115 : context_(context), app_id_(app_id), landscape_mode_(landscape_mode) {} |
| 114 app_id_(app_id), | |
| 115 landscape_mode_(landscape_mode) {} | |
| 116 | 116 |
| 117 // This will launch the request and after the return the creator does not | 117 // This will launch the request and after the return the creator does not |
| 118 // need to delete the object anymore. | 118 // need to delete the object anymore. |
| 119 bool LaunchAndRelease() { | 119 bool LaunchAndRelease() { |
| 120 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) | 120 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) |
| 121 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); | 121 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); |
| 122 if (!ash::Shell::HasInstance()) { | 122 if (!ash::Shell::HasInstance()) { |
| 123 // Skip this if there is no Ash shell. | 123 // Skip this if there is no Ash shell. |
| 124 LaunchAppWithRect(context_, app_id_, landscape_); | 124 LaunchAppWithRect(context_, app_id_, landscape_); |
| 125 delete this; | 125 delete this; |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // TODO(skuhne): Change CanHandleResolution into a call which returns | 129 // TODO(skuhne): Change CanHandleResolution into a call which returns |
| 130 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which | 130 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which |
| 131 // might also return the used DP->PIX conversion constant to do better | 131 // might also return the used DP->PIX conversion constant to do better |
| 132 // size calculations. | 132 // size calculations. |
| 133 bool result = CanHandleResolution(context_, app_id_, landscape_, | 133 bool result = CanHandleResolution( |
| 134 context_, app_id_, landscape_, | |
| 134 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); | 135 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); |
| 135 if (!result) | 136 if (!result) |
| 136 delete this; | 137 delete this; |
| 137 | 138 |
| 138 return result; | 139 return result; |
| 139 } | 140 } |
| 140 | 141 |
| 141 private: | 142 private: |
| 142 content::BrowserContext* context_; | 143 content::BrowserContext* context_; |
| 143 const std::string app_id_; | 144 const std::string app_id_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 } else { | 194 } else { |
| 194 app_instance->LaunchApp(app_info->package_name, app_info->activity, | 195 app_instance->LaunchApp(app_info->package_name, app_info->activity, |
| 195 target_rect); | 196 target_rect); |
| 196 } | 197 } |
| 197 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 198 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
| 198 | 199 |
| 199 return true; | 200 return true; |
| 200 } | 201 } |
| 201 | 202 |
| 202 bool LaunchAndroidSettingsApp(content::BrowserContext* context) { | 203 bool LaunchAndroidSettingsApp(content::BrowserContext* context) { |
| 203 return arc::LaunchApp(context, | 204 return arc::LaunchApp(context, kSettingsAppId, kUseLandscapeLayout); |
| 204 kSettingsAppId, | |
| 205 true); // landscape_layout | |
| 206 } | 205 } |
| 207 | 206 |
| 208 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { | 207 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { |
| 209 return LaunchApp(context, app_id, true); | 208 return LaunchApp(context, app_id, true); |
| 210 } | 209 } |
| 211 | 210 |
| 212 bool LaunchApp(content::BrowserContext* context, | 211 bool LaunchApp(content::BrowserContext* context, |
| 213 const std::string& app_id, | 212 const std::string& app_id, |
| 214 bool landscape_layout) { | 213 bool landscape_layout) { |
| 215 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 214 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
| 216 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 215 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
| 217 if (app_info && !app_info->ready) { | 216 if (app_info && !app_info->ready) { |
| 218 if (!ash::Shell::HasInstance()) | 217 if (!ash::Shell::HasInstance()) |
| 219 return false; | 218 return false; |
| 220 | 219 |
| 221 ChromeLauncherController* chrome_controller = | 220 ChromeLauncherController* chrome_controller = |
| 222 ChromeLauncherController::instance(); | 221 ChromeLauncherController::instance(); |
| 223 DCHECK(chrome_controller); | 222 DCHECK(chrome_controller); |
| 224 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch(app_id); | 223 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch(app_id); |
| 225 return true; | 224 return true; |
| 226 } | 225 } |
| 227 | 226 |
| 228 return (new LaunchAppWithoutSize(context, | 227 return (new LaunchAppWithoutSize(context, app_id, landscape_layout)) |
| 229 app_id, | 228 ->LaunchAndRelease(); |
| 230 landscape_layout))->LaunchAndRelease(); | |
| 231 } | 229 } |
| 232 | 230 |
| 233 bool CanHandleResolution(content::BrowserContext* context, | 231 bool CanHandleResolution(content::BrowserContext* context, |
| 234 const std::string& app_id, | 232 const std::string& app_id, |
| 235 const gfx::Rect& rect, | 233 const gfx::Rect& rect, |
| 236 const CanHandleResolutionCallback& callback) { | 234 const CanHandleResolutionCallback& callback) { |
| 237 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 235 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
| 238 DCHECK(prefs); | 236 DCHECK(prefs); |
| 239 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 237 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
| 240 if (!app_info) { | 238 if (!app_info) { |
| 241 VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id | 239 VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id |
| 242 << "."; | 240 << "."; |
| 243 return false; | 241 return false; |
| 244 } | 242 } |
| 245 | 243 |
| 246 arc::mojom::AppInstance* app_instance = | 244 arc::mojom::AppInstance* app_instance = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 if (!app_instance) | 296 if (!app_instance) |
| 299 return false; | 297 return false; |
| 300 | 298 |
| 301 app_instance->ShowPackageInfoOnPage( | 299 app_instance->ShowPackageInfoOnPage( |
| 302 package_name, page, | 300 package_name, page, |
| 303 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); | 301 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); |
| 304 return true; | 302 return true; |
| 305 } | 303 } |
| 306 | 304 |
| 307 } // namespace arc | 305 } // namespace arc |
| OLD | NEW |