Commit 12019c8a authored by Daniel Murphy's avatar Daniel Murphy Committed by Chromium LUCI CQ

[WebApp] Prefix WebApp name in title, and remove origin

Bug: 1151485, 1151483
Change-Id: I6369a73f66e6429ac1d3873760b69f089b050441
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551779
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarChase Phillips <cmp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833526}
parent 1cd55588
......@@ -6,7 +6,9 @@
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/strings/strcat.h"
#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/installable/installable_manager.h"
#include "chrome/browser/profiles/profile.h"
......@@ -283,7 +285,9 @@ bool AppBrowserController::HasTitlebarMenuButton() const {
bool AppBrowserController::HasTitlebarAppOriginText() const {
// Do not show origin text for System Apps.
return !is_for_system_web_app();
bool hide = is_for_system_web_app() ||
base::FeatureList::IsEnabled(features::kHideWebAppOriginText);
return !hide;
}
bool AppBrowserController::HasTitlebarContentSettings() const {
......@@ -448,7 +452,22 @@ base::string16 AppBrowserController::GetTitle() const {
content::NavigationEntry* entry =
web_contents->GetController().GetVisibleEntry();
return entry ? entry->GetTitle() : base::string16();
base::string16 raw_title = entry ? entry->GetTitle() : base::string16();
if (!base::FeatureList::IsEnabled(features::kPrefixWebAppWindowsWithAppName))
return raw_title;
base::string16 app_name =
base::ASCIIToUTF16(WebAppProvider::Get(browser()->profile())
->registrar()
.GetAppShortName(GetAppId()));
if (base::StartsWith(raw_title, app_name)) {
return raw_title;
} else if (raw_title.empty()) {
return app_name;
} else {
return base::StrCat({app_name, base::ASCIIToUTF16(" - "), raw_title});
}
}
void AppBrowserController::OnTabStripModelChanged(
......
......@@ -1022,6 +1022,73 @@ IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, InScopeHttpUrlsDisplayAppTitle) {
EXPECT_EQ(app_title, app_browser->GetWindowTitleForCurrentTab(false));
}
class WebAppBrowserTest_PrefixInTitle : public WebAppBrowserTest {
public:
WebAppBrowserTest_PrefixInTitle() {
scoped_feature_list_.InitAndEnableFeature(
features::kPrefixWebAppWindowsWithAppName);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Ensure that web app windows display the app title as a prefix.
IN_PROC_BROWSER_TEST_F(WebAppBrowserTest_PrefixInTitle, PrefixExistsInTitle) {
const GURL app_url = GetSecureAppURL();
const base::string16 app_title = base::ASCIIToUTF16("A Web App");
auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info->start_url = app_url;
web_app_info->scope = app_url.GetWithoutFilename();
web_app_info->title = app_title;
const AppId app_id = InstallWebApp(std::move(web_app_info));
Browser* const app_browser = LaunchWebAppBrowser(app_id);
content::WebContents* const web_contents =
app_browser->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(content::WaitForLoadStop(web_contents));
// The page title should be the combination of app name and title.
EXPECT_EQ(base::ASCIIToUTF16("A Web App - Google"),
app_browser->GetWindowTitleForCurrentTab(false));
}
// Ensure that web app windows with blank titles only display the app name.
IN_PROC_BROWSER_TEST_F(WebAppBrowserTest_PrefixInTitle,
EmptyTitlesDisplayAppName) {
const GURL app_url = https_server()->GetURL("app.site.com", "/empty.html");
const base::string16 app_title = base::ASCIIToUTF16("A Web App");
auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info->start_url = app_url;
web_app_info->scope = app_url.GetWithoutFilename();
web_app_info->title = app_title;
const AppId app_id = InstallWebApp(std::move(web_app_info));
Browser* const app_browser = LaunchWebAppBrowser(app_id);
content::WebContents* const web_contents =
app_browser->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(content::WaitForLoadStop(web_contents));
EXPECT_EQ(app_title, app_browser->GetWindowTitleForCurrentTab(false));
}
class WebAppBrowserTest_HideOrigin : public WebAppBrowserTest {
public:
WebAppBrowserTest_HideOrigin() {
scoped_feature_list_.InitAndEnableFeature(features::kHideWebAppOriginText);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// WebApps should not have origin text with this feature on.
IN_PROC_BROWSER_TEST_F(WebAppBrowserTest_HideOrigin, OriginTextRemoved) {
const GURL app_url = GetInstallableAppURL();
const AppId app_id = InstallPWA(app_url);
Browser* const app_browser = LaunchWebAppBrowserAndWait(app_id);
EXPECT_FALSE(app_browser->app_controller()->HasTitlebarAppOriginText());
}
// Check that a subframe on a regular web page can navigate to a URL that
// redirects to a web app. https://crbug.com/721949.
IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, SubframeRedirectsToWebApp) {
......
......@@ -516,6 +516,10 @@ const base::Feature kHeavyAdInterventionWarning{
const base::Feature kHeavyAdPrivacyMitigations{
"HeavyAdPrivacyMitigations", base::FEATURE_ENABLED_BY_DEFAULT};
// Hides the origin text from showing up briefly in WebApp windows.
const base::Feature kHideWebAppOriginText{"HideWebAppOriginText",
base::FEATURE_DISABLED_BY_DEFAULT};
#if defined(OS_MAC)
const base::Feature kImmersiveFullscreen{"ImmersiveFullscreen",
base::FEATURE_DISABLED_BY_DEFAULT};
......@@ -695,6 +699,9 @@ const base::Feature kPredictivePrefetchingAllowedOnAllConnectionTypes{
"PredictivePrefetchingAllowedOnAllConnectionTypes",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kPrefixWebAppWindowsWithAppName{
"PrefixWebAppWindowsWithAppName", base::FEATURE_DISABLED_BY_DEFAULT};
// Allows Chrome to do preconnect when prerender fails.
const base::Feature kPrerenderFallbackToPreconnect{
"PrerenderFallbackToPreconnect", base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -340,6 +340,9 @@ extern const base::Feature kHeavyAdInterventionWarning;
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kHeavyAdPrivacyMitigations;
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kHideWebAppOriginText;
#if defined(OS_MAC)
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kImmersiveFullscreen;
......@@ -462,6 +465,9 @@ extern const base::Feature kPluginVm;
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kPredictivePrefetchingAllowedOnAllConnectionTypes;
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kPrefixWebAppWindowsWithAppName;
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kPrerenderFallbackToPreconnect;
......
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