Commit 86e9f145 authored by Bruno Santos's avatar Bruno Santos Committed by Commit Bot

Implement method to launch prefixed URLs in Kiosk Next Home.

Bug: 927809
Change-Id: I0fe5c9c5763e39948d26b6f8d69764a9cd5dd4e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538888
Commit-Queue: Bruno Santos <brunoad@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644617}
parent bce2ece3
...@@ -4,11 +4,14 @@ ...@@ -4,11 +4,14 @@
#include "chrome/browser/chromeos/kiosk_next_home/app_controller_impl.h" #include "chrome/browser/chromeos/kiosk_next_home/app_controller_impl.h"
#include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h"
#include "base/optional.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h" #include "chrome/browser/apps/app_service/app_service_proxy.h"
...@@ -16,15 +19,22 @@ ...@@ -16,15 +19,22 @@
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h" #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h" #include "chrome/services/app_service/public/mojom/types.mojom.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/common/app.mojom.h"
#include "components/arc/session/arc_bridge_service.h"
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/events/event_constants.h" #include "ui/events/event_constants.h"
#include "url/gurl.h"
namespace chromeos { namespace chromeos {
namespace kiosk_next_home { namespace kiosk_next_home {
AppControllerImpl::AppControllerImpl(Profile* profile) AppControllerImpl::AppControllerImpl(Profile* profile)
: profile_(profile), : profile_(profile),
app_service_proxy_(apps::AppServiceProxy::Get(profile)) { app_service_proxy_(apps::AppServiceProxy::Get(profile)),
url_prefix_(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
chromeos::switches::kKioskNextHomeUrlPrefix)) {
app_service_proxy_->AppRegistryCache().AddObserver(this); app_service_proxy_->AppRegistryCache().AddObserver(this);
} }
...@@ -75,6 +85,35 @@ void AppControllerImpl::GetArcAndroidId( ...@@ -75,6 +85,35 @@ void AppControllerImpl::GetArcAndroidId(
std::move(callback))); std::move(callback)));
} }
void AppControllerImpl::LaunchHomeUrl(const std::string& suffix,
LaunchHomeUrlCallback callback) {
if (url_prefix_.empty()) {
std::move(callback).Run(false, "No URL prefix.");
return;
}
GURL url(url_prefix_ + suffix);
if (!url.is_valid()) {
std::move(callback).Run(false, "Invalid URL.");
return;
}
arc::mojom::AppInstance* app_instance =
arc::ArcServiceManager::Get()
? ARC_GET_INSTANCE_FOR_METHOD(
arc::ArcServiceManager::Get()->arc_bridge_service()->app(),
LaunchIntent)
: nullptr;
if (!app_instance) {
std::move(callback).Run(false, "ARC bridge not available.");
return;
}
app_instance->LaunchIntent(url.spec(), display::kDefaultDisplayId);
std::move(callback).Run(true, base::nullopt);
}
void AppControllerImpl::OnAppUpdate(const apps::AppUpdate& update) { void AppControllerImpl::OnAppUpdate(const apps::AppUpdate& update) {
// Skip this event if no relevant fields have changed. // Skip this event if no relevant fields have changed.
if (!update.StateIsNull() && !update.NameChanged() && if (!update.StateIsNull() && !update.NameChanged() &&
......
...@@ -42,6 +42,8 @@ class AppControllerImpl : public mojom::AppController, ...@@ -42,6 +42,8 @@ class AppControllerImpl : public mojom::AppController,
void LaunchApp(const std::string& app_id) override; void LaunchApp(const std::string& app_id) override;
void GetArcAndroidId( void GetArcAndroidId(
mojom::AppController::GetArcAndroidIdCallback callback) override; mojom::AppController::GetArcAndroidIdCallback callback) override;
void LaunchHomeUrl(const std::string& suffix,
LaunchHomeUrlCallback callback) override;
// apps::AppRegistryCache::Observer: // apps::AppRegistryCache::Observer:
void OnAppUpdate(const apps::AppUpdate& update) override; void OnAppUpdate(const apps::AppUpdate& update) override;
...@@ -72,6 +74,9 @@ class AppControllerImpl : public mojom::AppController, ...@@ -72,6 +74,9 @@ class AppControllerImpl : public mojom::AppController,
// is necessary. // is necessary.
std::map<std::string, std::string> android_package_map_; std::map<std::string, std::string> android_package_map_;
// URL prefix that can be launched by Kiosk Next Home.
const std::string url_prefix_;
DISALLOW_COPY_AND_ASSIGN(AppControllerImpl); DISALLOW_COPY_AND_ASSIGN(AppControllerImpl);
}; };
......
...@@ -52,4 +52,8 @@ interface AppController { ...@@ -52,4 +52,8 @@ interface AppController {
// Gets the Android ID for the ARC container. // Gets the Android ID for the ARC container.
GetArcAndroidId() => (bool success, string android_id); GetArcAndroidId() => (bool success, string android_id);
// Launches URL prefixed by chromeos::switches::kKioskNextHomeUrlPrefix with
// the given suffix.
LaunchHomeUrl(string suffix) => (bool launched, string? error_message);
}; };
...@@ -64,12 +64,13 @@ kioskNextHome.Bridge = class { ...@@ -64,12 +64,13 @@ kioskNextHome.Bridge = class {
launchApp(appId) {} launchApp(appId) {}
/** /**
* Launches an ARC++ intent. * Launches a URL prefixed by chromeos::switches::kKioskNextHomeUrlPrefix with
* @param {string} intent The URI of an ARC++ intent. * the given suffix.
* @return {!Promise} Resolves when intent is launched, or rejects in case of * @param {string} suffix
* @return {!Promise} Resolves if URL is launched, or rejects in case of
* failures. * failures.
*/ */
launchIntent(intent) {} launchHomeUrl(suffix) {}
/** /**
* Uninstalls an app. * Uninstalls an app.
......
...@@ -62,17 +62,14 @@ function buildApp(mojoApp) { ...@@ -62,17 +62,14 @@ function buildApp(mojoApp) {
/** @implements {kioskNextHome.Bridge} */ /** @implements {kioskNextHome.Bridge} */
class KioskNextHomeBridge { class KioskNextHomeBridge {
constructor() { constructor() {
/** /** @private @const {!Array<!kioskNextHome.Listener>} */
* @private
* @const {!Array<!kioskNextHome.Listener>}
*/
this.listeners_ = []; this.listeners_ = [];
/** @private */ /** @private @const */
this.identityAccessorProxy_ = new identity.mojom.IdentityAccessorProxy(); this.identityAccessorProxy_ = new identity.mojom.IdentityAccessorProxy();
/** @private */ /** @private @const */
this.appControllerProxy_ = this.appControllerProxy_ =
new chromeos.kioskNextHome.mojom.AppControllerProxy(); new chromeos.kioskNextHome.mojom.AppControllerProxy();
/** @private */ /** @private @const */
this.appControllerClientCallbackRouter_ = this.appControllerClientCallbackRouter_ =
new chromeos.kioskNextHome.mojom.AppControllerClientCallbackRouter(); new chromeos.kioskNextHome.mojom.AppControllerClientCallbackRouter();
...@@ -156,9 +153,12 @@ class KioskNextHomeBridge { ...@@ -156,9 +153,12 @@ class KioskNextHomeBridge {
} }
/** @override */ /** @override */
launchIntent(intent) { launchHomeUrl(suffix) {
// TODO(brunoad): Implement this method. return this.appControllerProxy_.launchHomeUrl(suffix).then(result => {
return Promise.reject('Not implemented.'); if (!result.launched) {
throw result.errorMessage;
}
});
} }
/** @override */ /** @override */
......
...@@ -443,6 +443,9 @@ const char kHomedir[] = "homedir"; ...@@ -443,6 +443,9 @@ const char kHomedir[] = "homedir";
const char kIgnoreUserProfileMappingForTests[] = const char kIgnoreUserProfileMappingForTests[] =
"ignore-user-profile-mapping-for-tests"; "ignore-user-profile-mapping-for-tests";
// URL prefix that can be launched by Kiosk Next Home.
const char kKioskNextHomeUrlPrefix[] = "kiosk-next-home-url-prefix";
// Enables Chrome-as-a-login-manager behavior. // Enables Chrome-as-a-login-manager behavior.
const char kLoginManager[] = "login-manager"; const char kLoginManager[] = "login-manager";
......
...@@ -179,6 +179,8 @@ extern const char kHideAndroidFilesInFilesApp[]; ...@@ -179,6 +179,8 @@ extern const char kHideAndroidFilesInFilesApp[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kHomedir[]; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kHomedir[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kIgnoreUserProfileMappingForTests[]; extern const char kIgnoreUserProfileMappingForTests[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kKioskNextHomeUrlPrefix[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kLoginManager[]; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kLoginManager[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kLoginProfile[]; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kLoginProfile[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kLoginUser[]; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kLoginUser[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment