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 @@
#include "chrome/browser/chromeos/kiosk_next_home/app_controller_impl.h"
#include <string>
#include <utility>
#include <vector>
#include "base/bind.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_util.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
......@@ -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_utils.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/events/event_constants.h"
#include "url/gurl.h"
namespace chromeos {
namespace kiosk_next_home {
AppControllerImpl::AppControllerImpl(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);
}
......@@ -75,6 +85,35 @@ void AppControllerImpl::GetArcAndroidId(
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) {
// Skip this event if no relevant fields have changed.
if (!update.StateIsNull() && !update.NameChanged() &&
......
......@@ -42,6 +42,8 @@ class AppControllerImpl : public mojom::AppController,
void LaunchApp(const std::string& app_id) override;
void GetArcAndroidId(
mojom::AppController::GetArcAndroidIdCallback callback) override;
void LaunchHomeUrl(const std::string& suffix,
LaunchHomeUrlCallback callback) override;
// apps::AppRegistryCache::Observer:
void OnAppUpdate(const apps::AppUpdate& update) override;
......@@ -72,6 +74,9 @@ class AppControllerImpl : public mojom::AppController,
// is necessary.
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);
};
......
......@@ -52,4 +52,8 @@ interface AppController {
// Gets the Android ID for the ARC container.
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);
};
......@@ -57,19 +57,20 @@ kioskNextHome.Bridge = class {
/**
* Launches the app with the given appId.
*
* Note: This is a fire and forget operation, given the VMs involved and
* Note: This is a fire and forget operation, given the VMs involved and
* their IPC interfaces, we can't tell if the operation was successful.
* @param {string} appId Chrome OS identifier for the app.
*/
launchApp(appId) {}
/**
* Launches an ARC++ intent.
* @param {string} intent The URI of an ARC++ intent.
* @return {!Promise} Resolves when intent is launched, or rejects in case of
* Launches a URL prefixed by chromeos::switches::kKioskNextHomeUrlPrefix with
* the given suffix.
* @param {string} suffix
* @return {!Promise} Resolves if URL is launched, or rejects in case of
* failures.
*/
launchIntent(intent) {}
launchHomeUrl(suffix) {}
/**
* Uninstalls an app.
......
......@@ -62,17 +62,14 @@ function buildApp(mojoApp) {
/** @implements {kioskNextHome.Bridge} */
class KioskNextHomeBridge {
constructor() {
/**
* @private
* @const {!Array<!kioskNextHome.Listener>}
*/
/** @private @const {!Array<!kioskNextHome.Listener>} */
this.listeners_ = [];
/** @private */
/** @private @const */
this.identityAccessorProxy_ = new identity.mojom.IdentityAccessorProxy();
/** @private */
/** @private @const */
this.appControllerProxy_ =
new chromeos.kioskNextHome.mojom.AppControllerProxy();
/** @private */
/** @private @const */
this.appControllerClientCallbackRouter_ =
new chromeos.kioskNextHome.mojom.AppControllerClientCallbackRouter();
......@@ -156,9 +153,12 @@ class KioskNextHomeBridge {
}
/** @override */
launchIntent(intent) {
// TODO(brunoad): Implement this method.
return Promise.reject('Not implemented.');
launchHomeUrl(suffix) {
return this.appControllerProxy_.launchHomeUrl(suffix).then(result => {
if (!result.launched) {
throw result.errorMessage;
}
});
}
/** @override */
......
......@@ -443,6 +443,9 @@ const char kHomedir[] = "homedir";
const char kIgnoreUserProfileMappingForTests[] =
"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.
const char kLoginManager[] = "login-manager";
......
......@@ -179,6 +179,8 @@ extern const char kHideAndroidFilesInFilesApp[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kHomedir[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
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 kLoginProfile[];
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