Commit f0fe9173 authored by paulzhchen's avatar paulzhchen Committed by Chromium LUCI CQ

Makes SWA non-resizeable.

pass browser_tests --gtest_filter=ApplicationLaunchBrowserTest*,
pass browser_tests --gtest_filter=All/SystemWebAppManagerNonResizeableWindowTest*,

Bug: b/175974902, b/176472645
Test: Tested that SWA is not resizeable,
Change-Id: I9a69d16ce6b7b85ed5b14ed340bf99fe75793308
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2620923
Commit-Queue: Paulz Chen <paulzchen@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarDaniel Nishi <dhnishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845491}
parent 660b7591
......@@ -269,6 +269,9 @@ class Browser : public TabStripModelObserver,
// User-set title of this browser window, if there is one.
std::string user_title;
// True if the browser is resizeable.
bool can_resize = true;
private:
friend class Browser;
friend class WindowSizerChromeOSTest;
......@@ -662,6 +665,9 @@ class Browser : public TabStripModelObserver,
type_ == TYPE_APP_POPUP;
}
// True if the browser is resizeable.
bool can_resize() const { return create_params_.can_resize; }
// True when the mouse cursor is locked.
bool IsMouseLocked() const;
......
......@@ -549,6 +549,9 @@ BrowserView::BrowserView(std::unique_ptr<Browser> browser)
accessibility_mode_observer_(
std::make_unique<AccessibilityModeObserver>(this)) {
SetShowIcon(::ShouldShowWindowIcon(browser_.get()));
SetCanResize(browser_->can_resize());
SetHasWindowSizeControls(!chrome::IsRunningInForcedAppMode());
browser_->tab_strip_model()->AddObserver(this);
......
......@@ -239,11 +239,13 @@ Browser* LaunchSystemWebApp(Profile* profile,
*did_create = !browser;
content::WebContents* web_contents = nullptr;
bool can_resize =
provider->system_web_app_manager().IsResizeableWindow(app_type);
if (!browser) {
browser =
CreateWebApplicationWindow(profile_for_launch, params->app_id,
params->disposition, params->restore_id);
browser = CreateWebApplicationWindow(profile_for_launch, params->app_id,
params->disposition,
params->restore_id, can_resize);
}
// Navigate application window to application's |url| if necessary.
......
......@@ -445,6 +445,28 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
EXPECT_FALSE(app_browser->app_controller()->ShouldShowCustomTabBar());
}
class SystemWebAppManagerNonResizeableWindowTest
: public SystemWebAppManagerBrowserTest {
public:
SystemWebAppManagerNonResizeableWindowTest()
: SystemWebAppManagerBrowserTest(/*install_mock=*/false) {
maybe_installation_ = TestSystemWebAppInstallation::SetUpNonResizeableApp();
}
~SystemWebAppManagerNonResizeableWindowTest() override = default;
};
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNonResizeableWindowTest,
NonResizeableWindow) {
WaitForTestSystemAppInstall();
content::TestNavigationObserver observer(maybe_installation_->GetAppUrl());
observer.StartWatchingNewWebContents();
Browser* app_browser;
LaunchApp(maybe_installation_->GetType(), &app_browser);
EXPECT_FALSE(app_browser->can_resize());
}
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Use LoginManagerTest here instead of SystemWebAppManagerBrowserTest, because
// it's less complicated to add SWA to LoginManagerTest than adding multi-logins
......@@ -716,4 +738,7 @@ INSTANTIATE_SYSTEM_WEB_APP_MANAGER_TEST_SUITE_GUEST_SESSION_P(
SystemWebAppLaunchProfileGuestSessionBrowserTest);
#endif
INSTANTIATE_SYSTEM_WEB_APP_MANAGER_TEST_SUITE_WEB_APP_INFO_INSTALL_P(
SystemWebAppManagerNonResizeableWindowTest);
} // namespace web_app
......@@ -105,7 +105,8 @@ GURL GetLaunchUrl(WebAppProvider& provider,
Browser* CreateWebApplicationWindow(Profile* profile,
const std::string& app_id,
WindowOpenDisposition disposition,
int32_t restore_id) {
int32_t restore_id,
bool can_resize) {
std::string app_name = GenerateApplicationNameFromAppId(app_id);
gfx::Rect initial_bounds;
Browser::CreateParams browser_params =
......@@ -120,6 +121,7 @@ Browser* CreateWebApplicationWindow(Profile* profile,
#if BUILDFLAG(IS_CHROMEOS_ASH)
browser_params.restore_id = restore_id;
#endif
browser_params.can_resize = can_resize;
return Browser::Create(browser_params);
}
......
......@@ -75,7 +75,8 @@ class WebAppLaunchManager {
Browser* CreateWebApplicationWindow(Profile* profile,
const std::string& app_id,
WindowOpenDisposition disposition,
int32_t restore_id);
int32_t restore_id,
bool can_resize = true);
content::WebContents* NavigateWebApplicationWindow(
Browser* browser,
......
......@@ -659,6 +659,14 @@ bool SystemWebAppManager::ShouldShowInSearch(SystemAppType type) const {
return it->second.show_in_search;
}
bool SystemWebAppManager::IsResizeableWindow(SystemAppType type) const {
auto it = system_app_infos_.find(type);
if (it == system_app_infos_.end())
return false;
return it->second.is_resizeable;
}
base::Optional<SystemAppType> SystemWebAppManager::GetCapturingSystemAppForURL(
const GURL& url) const {
if (!HasSystemWebAppScheme(url))
......
......@@ -104,6 +104,9 @@ struct SystemAppInfo {
// browser tab).
bool capture_navigations = false;
// If set to false, the app will non-resizeable.
bool is_resizeable = true;
WebApplicationInfoFactory app_info_factory;
};
......@@ -187,6 +190,9 @@ class SystemWebAppManager {
// Returns whether the app should be shown in search.
bool ShouldShowInSearch(SystemAppType type) const;
// Returns whether the app should be resizeable.
bool IsResizeableWindow(SystemAppType type) const;
// Returns the SystemAppType that should capture the navigation to |url|.
base::Optional<SystemAppType> GetCapturingSystemAppForURL(
const GURL& url) const;
......
......@@ -314,6 +314,16 @@ TestSystemWebAppInstallation::SetUpChromeUntrustedApp(
}
}
// static
std::unique_ptr<TestSystemWebAppInstallation>
TestSystemWebAppInstallation::SetUpNonResizeableApp() {
SystemAppInfo app_info("Test", GURL("chrome://test-system-app/pwa.html"));
app_info.is_resizeable = false;
return base::WrapUnique(new TestSystemWebAppInstallation(
SystemAppType::SAMPLE, std::move(app_info)));
}
std::unique_ptr<KeyedService>
TestSystemWebAppInstallation::CreateWebAppProvider(SystemAppInfo info,
Profile* profile) {
......
......@@ -58,6 +58,8 @@ class TestSystemWebAppInstallation {
static std::unique_ptr<TestSystemWebAppInstallation>
SetUpAppThatCapturesNavigation(const bool use_web_app_info);
static std::unique_ptr<TestSystemWebAppInstallation> SetUpNonResizeableApp();
static std::unique_ptr<TestSystemWebAppInstallation> SetUpChromeUntrustedApp(
const bool use_web_app_info);
......
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