Skip to content

Commit

Permalink
Lacros: Close splash screen window after the main window is ready
Browse files Browse the repository at this point in the history
During the kiosk session startup, a splash screen is displayed which
shows the current initialization status. After the main application
window (at the lacros side) is ready, the splash window (at the ash
side) should be closed.

Current challenge is to know when the main application window is ready.
This CL solves it as follows:
1. Ash uses exo::WMHelper to observe the creation of lacros window.
2. Once the lacros window is created and OnExoWindowCreated is
   triggered, close the splash window by calling
   delegate_->OnAppWindowCreated().

Bug: 1232794
Change-Id: I30d40aad7a35069034b7f1cf0838ef427eef699f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3170393
Commit-Queue: Anqing Zhao <[email protected]>
Reviewed-by: Anatoliy Potapchuk <[email protected]>
Reviewed-by: Nancy Wang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#930288}
  • Loading branch information
ananubis authored and Chromium LUCI CQ committed Oct 11, 2021
1 parent 725be80 commit 77a03cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
13 changes: 10 additions & 3 deletions chrome/browser/ash/app_mode/web_app/web_kiosk_app_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ void WebKioskAppLauncher::OnAppDataObtained(

void WebKioskAppLauncher::OnLacrosWindowCreated(
crosapi::mojom::CreationResult result) {
if (result == crosapi::mojom::CreationResult::kSuccess) {
delegate_->OnAppWindowCreated();
} else {
if (result != crosapi::mojom::CreationResult::kSuccess) {
exo::WMHelper::GetInstance()->RemoveExoWindowObserver(this);
LOG(ERROR) << "The lacros window failed to be created. Result: " << result;
delegate_->OnLaunchFailed(KioskAppLaunchError::Error::kUnableToLaunch);
}
}

void WebKioskAppLauncher::CreateNewLacrosWindow() {
DCHECK(exo::WMHelper::HasInstance());
exo::WMHelper::GetInstance()->AddExoWindowObserver(this);
crosapi::BrowserManager::Get()->NewFullscreenWindow(
GetCurrentApp()->GetLaunchableUrl(),
base::BindOnce(&WebKioskAppLauncher::OnLacrosWindowCreated,
Expand Down Expand Up @@ -169,6 +170,12 @@ void WebKioskAppLauncher::OnStateChanged() {
}
}

void WebKioskAppLauncher::OnExoWindowCreated(aura::Window* window) {
CHECK(crosapi::browser_util::IsLacrosWindow(window));
exo::WMHelper::GetInstance()->RemoveExoWindowObserver(this);
delegate_->OnAppWindowCreated();
}

void WebKioskAppLauncher::SetDataRetrieverFactoryForTesting(
base::RepeatingCallback<std::unique_ptr<web_app::WebAppDataRetriever>()>
data_retriever_factory) {
Expand Down
7 changes: 6 additions & 1 deletion chrome/browser/ash/app_mode/web_app/web_kiosk_app_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_url_loader.h"
#include "components/account_id/account_id.h"
#include "components/exo/wm_helper.h"
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"

Expand All @@ -38,7 +39,8 @@ class WebKioskAppData;
// Object responsible for preparing and launching web kiosk app. Is destroyed
// upon app launch.
class WebKioskAppLauncher : public KioskAppLauncher,
public crosapi::BrowserManagerObserver {
public crosapi::BrowserManagerObserver,
public exo::WMHelper::ExoWindowObserver {
public:
WebKioskAppLauncher(Profile* profile,
Delegate* delegate,
Expand Down Expand Up @@ -69,6 +71,9 @@ class WebKioskAppLauncher : public KioskAppLauncher,
// crosapi::BrowserManagerObserver:
void OnStateChanged() override;

// exo::WMHelper::ExoWindowObserver:
void OnExoWindowCreated(aura::Window* window) override;

// Callback method triggered after web application and its icon are obtained
// from `WebKioskAppManager`.
void OnAppDataObtained(std::unique_ptr<WebApplicationInfo> app_info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/exo/shell_surface_util.h"
#include "components/exo/wm_helper_chromeos.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down Expand Up @@ -56,6 +58,7 @@ const char kAppEmail[] = "[email protected]";
const char kAppInstallUrl[] = "https://example.com";
const char kAppLaunchUrl[] = "https://example.com/launch";
const char kAppLaunchBadUrl[] = "https://badexample.com";
const char kLacrosAppId[] = "org.chromium.lacros.12345";
const char kUserEmail[] = "[email protected]";
const char16_t kAppTitle[] = u"app";

Expand Down Expand Up @@ -365,7 +368,8 @@ class WebKioskAppLauncherUsingLacrosTest : public WebKioskAppLauncherTest {
WebKioskAppLauncherUsingLacrosTest()
: browser_manager_(std::make_unique<crosapi::FakeBrowserManager>()),
fake_user_manager_(new ash::FakeChromeUserManager()),
scoped_user_manager_(base::WrapUnique(fake_user_manager_)) {
scoped_user_manager_(base::WrapUnique(fake_user_manager_)),
wm_helper_(std::make_unique<exo::WMHelperChromeOS>()) {
scoped_feature_list_.InitAndEnableFeature(features::kWebKioskEnableLacros);
crosapi::browser_util::SetLacrosEnabledForTest(true);
crosapi::browser_util::SetLacrosPrimaryBrowserForTest(true);
Expand All @@ -377,6 +381,13 @@ class WebKioskAppLauncherUsingLacrosTest : public WebKioskAppLauncherTest {
fake_user_manager()->LoginUser(account_id);
}

void CreateLacrosWindowAndNotify() {
auto window = std::make_unique<aura::Window>(nullptr);
window->Init(ui::LAYER_SOLID_COLOR);
exo::SetShellApplicationId(window.get(), kLacrosAppId);
wm_helper()->NotifyExoWindowCreated(window.get());
}

crosapi::FakeBrowserManager* browser_manager() const {
return browser_manager_.get();
}
Expand All @@ -385,11 +396,14 @@ class WebKioskAppLauncherUsingLacrosTest : public WebKioskAppLauncherTest {
return fake_user_manager_;
}

exo::WMHelper* wm_helper() const { return wm_helper_.get(); }

private:
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<crosapi::FakeBrowserManager> browser_manager_;
ash::FakeChromeUserManager* fake_user_manager_;
user_manager::ScopedUserManager scoped_user_manager_;
std::unique_ptr<exo::WMHelper> wm_helper_;
};

TEST_F(WebKioskAppLauncherUsingLacrosTest, NormalFlow) {
Expand All @@ -415,6 +429,7 @@ TEST_F(WebKioskAppLauncherUsingLacrosTest, NormalFlow) {
EXPECT_CALL(*delegate(), OnLaunchFailed(_)).Times(0);
browser_manager()->set_is_running(true);
launcher()->LaunchApp();
CreateLacrosWindowAndNotify();
loop2.Run();
}

Expand Down Expand Up @@ -443,6 +458,7 @@ TEST_F(WebKioskAppLauncherUsingLacrosTest, WaitBrowserManagerToRun) {
launcher()->LaunchApp();
browser_manager()->set_is_running(true);
browser_manager()->StartRunning();
CreateLacrosWindowAndNotify();
loop2.Run();
}

Expand Down

0 comments on commit 77a03cc

Please sign in to comment.