Commit b65adc3b authored by Amanda Baker's avatar Amanda Baker Committed by Commit Bot

dpwas: Support window controls overlay in browser process

This change enables future UI changes based on the
'window-controls-overlay' display override by adding a new method,
`IsWindowControlsOverlayEnabled()`,to the web app controller that
indicates whether or not the WCO should be shown.

Explainer: https://github.com/WICG/window-controls-overlay/blob/master/explainer.md
Design Doc: https://docs.google.com/document/d/1k0YL_-VMLIfjYCgJ2v6cMvuUv2qMKg4BgLI2tJ4qtyo/edit?usp=sharing
I2P: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/cper6nNLFRQ/hU91kfCWBQAJ

Bug: 937121
Change-Id: Ibe5615393e50edc09e2464abe9eaa09e52559be6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2486780Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarLorne Mitchell <lomitch@microsoft.com>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Amanda Baker <ambake@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#821037}
parent de85535c
...@@ -181,9 +181,12 @@ bool DoesManifestContainRequiredIcon(const blink::Manifest& manifest, ...@@ -181,9 +181,12 @@ bool DoesManifestContainRequiredIcon(const blink::Manifest& manifest,
} }
bool ShouldRejectDisplayMode(blink::mojom::DisplayMode display_mode) { bool ShouldRejectDisplayMode(blink::mojom::DisplayMode display_mode) {
return !(display_mode == blink::mojom::DisplayMode::kStandalone || return !(
display_mode == blink::mojom::DisplayMode::kFullscreen || display_mode == blink::mojom::DisplayMode::kStandalone ||
display_mode == blink::mojom::DisplayMode::kMinimalUi); display_mode == blink::mojom::DisplayMode::kFullscreen ||
display_mode == blink::mojom::DisplayMode::kMinimalUi ||
(display_mode == blink::mojom::DisplayMode::kWindowControlsOverlay &&
base::FeatureList::IsEnabled(features::kWebAppWindowControlsOverlay)));
} }
// Returns true if |params| specifies a full PWA check. // Returns true if |params| specifies a full PWA check.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/installable/installable_manager.h" #include "chrome/browser/installable/installable_manager.h"
#include "base/feature_list.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
...@@ -325,6 +326,12 @@ TEST_F(InstallableManagerUnitTest, ManifestDisplayModes) { ...@@ -325,6 +326,12 @@ TEST_F(InstallableManagerUnitTest, ManifestDisplayModes) {
manifest.display = blink::mojom::DisplayMode::kFullscreen; manifest.display = blink::mojom::DisplayMode::kFullscreen;
EXPECT_TRUE(IsManifestValid(manifest)); EXPECT_TRUE(IsManifestValid(manifest));
EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
manifest.display = blink::mojom::DisplayMode::kWindowControlsOverlay;
EXPECT_TRUE(
IsManifestValid(manifest, false /* check_webapp_manifest_display */));
EXPECT_FALSE(IsManifestValid(manifest));
EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
} }
class InstallableManagerUnitTest_DisplayOverride class InstallableManagerUnitTest_DisplayOverride
...@@ -366,6 +373,14 @@ TEST_F(InstallableManagerUnitTest_DisplayOverride, ManifestDisplayOverride) { ...@@ -366,6 +373,14 @@ TEST_F(InstallableManagerUnitTest_DisplayOverride, ManifestDisplayOverride) {
IsManifestValid(manifest, false /* check_webapp_manifest_display */)); IsManifestValid(manifest, false /* check_webapp_manifest_display */));
EXPECT_FALSE(IsManifestValid(manifest)); EXPECT_FALSE(IsManifestValid(manifest));
EXPECT_EQ(MANIFEST_DISPLAY_OVERRIDE_NOT_SUPPORTED, GetErrorCode()); EXPECT_EQ(MANIFEST_DISPLAY_OVERRIDE_NOT_SUPPORTED, GetErrorCode());
manifest.display_override.insert(
manifest.display_override.begin(),
blink::mojom::DisplayMode::kWindowControlsOverlay);
EXPECT_TRUE(
IsManifestValid(manifest, false /* check_webapp_manifest_display */));
EXPECT_FALSE(IsManifestValid(manifest));
EXPECT_EQ(MANIFEST_DISPLAY_OVERRIDE_NOT_SUPPORTED, GetErrorCode());
} }
TEST_F(InstallableManagerUnitTest_DisplayOverride, FallbackToBrowser) { TEST_F(InstallableManagerUnitTest_DisplayOverride, FallbackToBrowser) {
...@@ -376,3 +391,27 @@ TEST_F(InstallableManagerUnitTest_DisplayOverride, FallbackToBrowser) { ...@@ -376,3 +391,27 @@ TEST_F(InstallableManagerUnitTest_DisplayOverride, FallbackToBrowser) {
EXPECT_TRUE(IsManifestValid(manifest)); EXPECT_TRUE(IsManifestValid(manifest));
EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
} }
class InstallableManagerUnitTest_WindowControlsOverlay
: public InstallableManagerUnitTest {
public:
InstallableManagerUnitTest_WindowControlsOverlay() {
scoped_feature_list_.InitWithFeatures(
{features::kWebAppManifestDisplayOverride,
features::kWebAppWindowControlsOverlay},
{});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(InstallableManagerUnitTest_WindowControlsOverlay,
SupportWindowControlsOverlay) {
blink::Manifest manifest = GetValidManifest();
manifest.display_override.push_back(
blink::mojom::DisplayMode::kWindowControlsOverlay);
EXPECT_TRUE(IsManifestValid(manifest));
EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
}
...@@ -322,6 +322,10 @@ AppBrowserController::GetTabMenuModelFactory() const { ...@@ -322,6 +322,10 @@ AppBrowserController::GetTabMenuModelFactory() const {
return nullptr; return nullptr;
} }
bool AppBrowserController::IsWindowControlsOverlayEnabled() const {
return false;
}
bool AppBrowserController::IsHostedApp() const { bool AppBrowserController::IsHostedApp() const {
return false; return false;
} }
......
...@@ -139,6 +139,8 @@ class AppBrowserController : public TabStripModelObserver, ...@@ -139,6 +139,8 @@ class AppBrowserController : public TabStripModelObserver,
virtual std::unique_ptr<TabMenuModelFactory> GetTabMenuModelFactory() const; virtual std::unique_ptr<TabMenuModelFactory> GetTabMenuModelFactory() const;
virtual bool IsWindowControlsOverlayEnabled() const;
// Updates the custom tab bar's visibility based on whether it should be // Updates the custom tab bar's visibility based on whether it should be
// currently visible or not. If |animate| is set, the change will be // currently visible or not. If |animate| is set, the change will be
// animated. // animated.
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -58,6 +59,14 @@ bool WebAppBrowserController::IsHostedApp() const { ...@@ -58,6 +59,14 @@ bool WebAppBrowserController::IsHostedApp() const {
return true; return true;
} }
bool WebAppBrowserController::IsWindowControlsOverlayEnabled() const {
if (!base::FeatureList::IsEnabled(features::kWebAppWindowControlsOverlay))
return false;
DisplayMode display = registrar().GetAppEffectiveDisplayMode(GetAppId());
return display == DisplayMode::kWindowControlsOverlay;
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
bool WebAppBrowserController::ShouldShowCustomTabBar() const { bool WebAppBrowserController::ShouldShowCustomTabBar() const {
if (AppBrowserController::ShouldShowCustomTabBar()) if (AppBrowserController::ShouldShowCustomTabBar())
......
...@@ -67,6 +67,7 @@ class WebAppBrowserController : public AppBrowserController, ...@@ -67,6 +67,7 @@ class WebAppBrowserController : public AppBrowserController,
void Uninstall() override; void Uninstall() override;
bool IsInstalled() const override; bool IsInstalled() const override;
bool IsHostedApp() const override; bool IsHostedApp() const override;
bool IsWindowControlsOverlayEnabled() const override;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
bool ShouldShowCustomTabBar() const override; bool ShouldShowCustomTabBar() const override;
......
...@@ -164,6 +164,21 @@ class WebAppBrowserTest_DisplayOverride : public WebAppBrowserTest { ...@@ -164,6 +164,21 @@ class WebAppBrowserTest_DisplayOverride : public WebAppBrowserTest {
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
}; };
// A dedicated test fixture for WindowControlsOverlay, which requires a command
// line switch to enable manifest parsing.
class WebAppBrowserTest_WindowControlsOverlay : public WebAppBrowserTest {
public:
WebAppBrowserTest_WindowControlsOverlay() {
scoped_feature_list_.InitWithFeatures(
{features::kWebAppManifestDisplayOverride,
features::kWebAppWindowControlsOverlay},
{});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
using WebAppTabRestoreBrowserTest = WebAppBrowserTest; using WebAppTabRestoreBrowserTest = WebAppBrowserTest;
IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, ThemeColor) { IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, ThemeColor) {
...@@ -1083,4 +1098,25 @@ IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, PopupLocationBar) { ...@@ -1083,4 +1098,25 @@ IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, PopupLocationBar) {
popup_browser->CanSupportWindowFeature(Browser::FEATURE_LOCATIONBAR)); popup_browser->CanSupportWindowFeature(Browser::FEATURE_LOCATIONBAR));
} }
IN_PROC_BROWSER_TEST_F(WebAppBrowserTest_WindowControlsOverlay,
WindowControlsOverlay) {
GURL test_url = https_server()->GetURL(
"/banners/"
"manifest_test_page.html?manifest=manifest_window_controls_overlay.json");
NavigateToURLAndWait(browser(), test_url);
const AppId app_id = InstallPwaForCurrentUrl();
auto* provider = WebAppProvider::Get(profile());
std::vector<DisplayMode> app_display_mode_override =
provider->registrar().GetAppDisplayModeOverride(app_id);
ASSERT_EQ(1u, app_display_mode_override.size());
EXPECT_EQ(DisplayMode::kWindowControlsOverlay, app_display_mode_override[0]);
Browser* const app_browser = LaunchWebAppBrowser(app_id);
EXPECT_EQ(true,
app_browser->app_controller()->IsWindowControlsOverlayEnabled());
}
} // namespace web_app } // namespace web_app
...@@ -26,8 +26,12 @@ DisplayMode ResolveAppDisplayModeForStandaloneLaunchContainer( ...@@ -26,8 +26,12 @@ DisplayMode ResolveAppDisplayModeForStandaloneLaunchContainer(
FALLTHROUGH; FALLTHROUGH;
case DisplayMode::kStandalone: case DisplayMode::kStandalone:
case DisplayMode::kFullscreen: case DisplayMode::kFullscreen:
case DisplayMode::kWindowControlsOverlay:
return DisplayMode::kStandalone; return DisplayMode::kStandalone;
case DisplayMode::kWindowControlsOverlay:
if (base::FeatureList::IsEnabled(features::kWebAppWindowControlsOverlay))
return DisplayMode::kWindowControlsOverlay;
else
return DisplayMode::kStandalone;
} }
} }
} // namespace } // namespace
......
{
"name": "Manifest with Window Controls Overlay",
"icons": [
{
"src": "launcher-icon-4x.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "manifest_test_page.html",
"display": "standalone",
"display_override": [ "window-controls-overlay" ]
}
\ No newline at end of file
...@@ -374,6 +374,8 @@ void SetRuntimeFeaturesFromChromiumFeatures() { ...@@ -374,6 +374,8 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
{"UserAgentClientHint", features::kUserAgentClientHint}, {"UserAgentClientHint", features::kUserAgentClientHint},
{"WebAppManifestDisplayOverride", {"WebAppManifestDisplayOverride",
features::kWebAppManifestDisplayOverride}, features::kWebAppManifestDisplayOverride},
{"WebAppWindowControlsOverlay",
features::kWebAppWindowControlsOverlay},
{"WebXRMultiGpu", blink::features::kWebXrMultiGpu}, {"WebXRMultiGpu", blink::features::kWebXrMultiGpu},
}; };
for (const auto& mapping : runtimeFeatureNameToChromiumFeatureMapping) { for (const auto& mapping : runtimeFeatureNameToChromiumFeatureMapping) {
......
...@@ -735,6 +735,10 @@ const base::Feature kV8VmFuture{"V8VmFuture", ...@@ -735,6 +735,10 @@ const base::Feature kV8VmFuture{"V8VmFuture",
const base::Feature kWebAppManifestDisplayOverride{ const base::Feature kWebAppManifestDisplayOverride{
"WebAppManifestDisplayOverride", base::FEATURE_DISABLED_BY_DEFAULT}; "WebAppManifestDisplayOverride", base::FEATURE_DISABLED_BY_DEFAULT};
// Enable window controls overlays for desktop PWAs
const base::Feature kWebAppWindowControlsOverlay{
"WebAppWindowControlsOverlay", base::FEATURE_DISABLED_BY_DEFAULT};
// Enable WebAssembly baseline compilation (Liftoff). // Enable WebAssembly baseline compilation (Liftoff).
const base::Feature kWebAssemblyBaseline{"WebAssemblyBaseline", const base::Feature kWebAssemblyBaseline{"WebAssemblyBaseline",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
......
...@@ -157,6 +157,7 @@ CONTENT_EXPORT extern const base::Feature kUserAgentClientHint; ...@@ -157,6 +157,7 @@ CONTENT_EXPORT extern const base::Feature kUserAgentClientHint;
CONTENT_EXPORT extern const base::Feature kVideoPlaybackQuality; CONTENT_EXPORT extern const base::Feature kVideoPlaybackQuality;
CONTENT_EXPORT extern const base::Feature kV8VmFuture; CONTENT_EXPORT extern const base::Feature kV8VmFuture;
CONTENT_EXPORT extern const base::Feature kWebAppManifestDisplayOverride; CONTENT_EXPORT extern const base::Feature kWebAppManifestDisplayOverride;
CONTENT_EXPORT extern const base::Feature kWebAppWindowControlsOverlay;
CONTENT_EXPORT extern const base::Feature kWebAssemblyBaseline; CONTENT_EXPORT extern const base::Feature kWebAssemblyBaseline;
CONTENT_EXPORT extern const base::Feature kWebAssemblyLazyCompilation; CONTENT_EXPORT extern const base::Feature kWebAssemblyLazyCompilation;
CONTENT_EXPORT extern const base::Feature kWebAssemblySimd; CONTENT_EXPORT extern const base::Feature kWebAssemblySimd;
......
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