Commit dbb6459c authored by Quan Nguyen's avatar Quan Nguyen Committed by Commit Bot

cros: Implement LaunchContainedShell

The widget hosting the ContainedShell webui is launched in fullscreen mode.

Bug: 902571
Change-Id: I8a3010e11cb651d3725a818c2cf7c0f273687c16
Reviewed-on: https://chromium-review.googlesource.com/c/1331878Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Quan Nguyen <qnnguyen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613790}
parent 203c2a5e
......@@ -3,6 +3,9 @@
// found in the LICENSE file.
#include "ash/contained_shell/contained_shell_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "components/account_id/account_id.h"
#include <utility>
......@@ -18,9 +21,10 @@ void ContainedShellController::BindRequest(
}
void ContainedShellController::LaunchContainedShell() {
// TODO(crbug/902571): Implement launch by dispatching to a
// ContainedShellClient method.
NOTIMPLEMENTED();
contained_shell_client_->LaunchContainedShell(Shell::Get()
->session_controller()
->GetPrimaryUserSession()
->user_info->account_id);
}
void ContainedShellController::SetClient(
......
......@@ -9,6 +9,7 @@
#include "ash/public/interfaces/contained_shell.mojom.h"
#include "base/macros.h"
#include "components/account_id/account_id.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -21,6 +22,9 @@ class MockContainedShellClient : public mojom::ContainedShellClient {
mojom::ContainedShellClientPtr CreateInterfacePtrAndBind();
// mojom::ContainedShellClient:
MOCK_METHOD1(LaunchContainedShell, void(const AccountId& account_id));
private:
mojo::Binding<mojom::ContainedShellClient> binding_{this};
......
......@@ -4,9 +4,14 @@
module ash.mojom;
import "components/account_id/interfaces/account_id.mojom";
// Performs browser-side functionality for the ContainedShell feature,
// e.g. launching a WebView to host the ContainedShell.
interface ContainedShellClient {
// Launch a contained shell experience for the current user, identified by
// |account_id|.
LaunchContainedShell(signin.mojom.AccountId account_id);
};
// Allows Ash and its consumers to interact with the ContainedShell
......
......@@ -4,10 +4,13 @@
#include <string>
#include "ash/public/cpp/ash_features.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/screens/gaia_view.h"
......@@ -29,6 +32,10 @@
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h"
#include "rlz/buildflags/buildflags.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_features.h"
#if BUILDFLAG(ENABLE_RLZ)
......@@ -77,6 +84,66 @@ class LoginUtilsTest : public OobeBaseTest {
DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest);
};
class LoginUtilsContainedShellTest : public LoginUtilsTest {
public:
void SetUp() override {
feature_list_.InitAndEnableFeature(ash::features::kContainedShell);
LoginUtilsTest::SetUp();
}
private:
base::test::ScopedFeatureList feature_list_;
};
// This observer is used by LoginUtilsContainedShellTest to keep track of
// whether a Fullscreen window was launched by ash during the test run.
class FullscreenWindowEnvObserver : public aura::EnvObserver,
public aura::WindowObserver {
public:
FullscreenWindowEnvObserver() { env_observer_.Add(aura::Env::GetInstance()); }
bool did_fullscreen_window_launch() const {
return did_fullscreen_window_launch_;
}
// aura::EnvObserver:
void OnWindowInitialized(aura::Window* window) override {
window_observer_.Add(window);
}
// aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override {
did_fullscreen_window_launch_ =
did_fullscreen_window_launch_ ||
window->GetProperty(aura::client::kShowStateKey) ==
ui::SHOW_STATE_FULLSCREEN;
}
private:
bool did_fullscreen_window_launch_ = false;
ScopedObserver<aura::Env, aura::EnvObserver> env_observer_{this};
ScopedObserver<aura::Window, aura::WindowObserver> window_observer_{this};
DISALLOW_COPY_AND_ASSIGN(FullscreenWindowEnvObserver);
};
// Checks that the Contained Experience window is launched on sign-in when the
// feature is enabled.
IN_PROC_BROWSER_TEST_F(LoginUtilsContainedShellTest, ContainedShellLaunch) {
WaitForSigninScreen();
FullscreenWindowEnvObserver fullscreen_observer;
Login("username");
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(fullscreen_observer.did_fullscreen_window_launch());
}
// Exercises login, like the desktopui_MashLogin Chrome OS autotest.
IN_PROC_BROWSER_TEST_F(LoginUtilsTest, MashLogin) {
// Test is relevant for both SingleProcessMash and MultiProcessMash, but
......
......@@ -7,9 +7,22 @@
#include <utility>
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/window_pin_type.mojom.h"
#include "base/command_line.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
namespace {
// TODO(b/119418627): implement the contained shell experience and put its URL
// here.
constexpr char kDefaultContainedShellUrl[] = "about:blank";
} // namespace
ContainedShellClient::ContainedShellClient() {
ash::mojom::ContainedShellControllerPtr contained_shell_controller;
......@@ -23,3 +36,26 @@ ContainedShellClient::ContainedShellClient() {
}
ContainedShellClient::~ContainedShellClient() = default;
void ContainedShellClient::LaunchContainedShell(const AccountId& account_id) {
auto* web_view = new views::WebView(
chromeos::ProfileHelper::Get()->GetProfileByAccountId(account_id));
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
auto* widget = new views::Widget;
widget->Init(params);
widget->SetContentsView(web_view);
const std::string url_flag =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
chromeos::switches::kContainedShellUrl);
if (!url_flag.empty())
web_view->LoadInitialURL(GURL(url_flag));
else
web_view->LoadInitialURL(GURL(kDefaultContainedShellUrl));
widget->SetFullscreen(true);
widget->Show();
}
......@@ -7,6 +7,7 @@
#include "ash/public/interfaces/contained_shell.mojom.h"
#include "base/macros.h"
#include "components/account_id/account_id.h"
#include "mojo/public/cpp/bindings/binding.h"
class ContainedShellClient : public ash::mojom::ContainedShellClient {
......@@ -14,6 +15,9 @@ class ContainedShellClient : public ash::mojom::ContainedShellClient {
ContainedShellClient();
~ContainedShellClient() override;
// mojom::ContainedShellClient:
void LaunchContainedShell(const AccountId& account_id) override;
private:
mojo::Binding<ash::mojom::ContainedShellClient> binding_{this};
......
......@@ -141,6 +141,9 @@ const char kChildWallpaperLarge[] = "child-wallpaper-large";
// non-user-writable JPEG file).
const char kChildWallpaperSmall[] = "child-wallpaper-small";
// URL to display within the Contained Shell widget.
const char kContainedShellUrl[] = "contained-shell-url";
const char kConservativeThreshold[] = "conservative";
// Forces use of Chrome OS Gaia API v1.
......
......@@ -42,6 +42,7 @@ CHROMEOS_EXPORT extern const char kCellularFirst[];
CHROMEOS_EXPORT extern const char kChildWallpaperLarge[];
CHROMEOS_EXPORT extern const char kChildWallpaperSmall[];
CHROMEOS_EXPORT extern const char kConservativeThreshold[];
CHROMEOS_EXPORT extern const char kContainedShellUrl[];
CHROMEOS_EXPORT extern const char kCrosGaiaApiV1[];
CHROMEOS_EXPORT extern const char kCrosRegion[];
CHROMEOS_EXPORT extern const char kCrosRegionsMode[];
......
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