Commit 402e8644 authored by Junyi Xiao's avatar Junyi Xiao Committed by Commit Bot

WebApps: Remove install pwa icon from toolbar when page crashed

This change 1. hides the install pwa page action icon in the toolbar
2. grayed out "create shortcut" and "Install {pwaName}" menu items
when page crashed.

Bug: 1057526

Change-Id: I63d5e3607e9aff71ab2bd799d792f025b142ec42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078771
Commit-Queue: Junyi Xiao <juxiao@microsoft.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746305}
parent aabb568f
......@@ -1666,6 +1666,9 @@ void Browser::NavigationStateChanged(WebContents* source,
content::INVALIDATE_TYPE_TAB))
command_controller_->TabStateChanged();
if (changed_flags & content::INVALIDATE_TYPE_TAB)
UpdateToolbar(false);
if (app_controller_)
app_controller_->UpdateCustomTabBarVisibility(true);
}
......
......@@ -36,6 +36,11 @@ void PwaInstallView::UpdateImpl() {
if (!web_contents)
return;
if (web_contents->IsCrashed()) {
SetVisible(false);
return;
}
auto* manager = banners::AppBannerManager::FromWebContents(web_contents);
// May not be present e.g. in incognito mode.
if (!manager)
......
......@@ -297,6 +297,18 @@ IN_PROC_BROWSER_TEST_P(PwaInstallViewBrowserTest,
EXPECT_FALSE(pwa_install_view_->GetVisible());
}
// Tests that the plus icon updates its visibility when tab crashes
IN_PROC_BROWSER_TEST_P(PwaInstallViewBrowserTest,
IconVisibilityAfterTabCrashed) {
StartNavigateToUrl(GetInstallableAppURL());
ASSERT_TRUE(app_banner_manager_->WaitForInstallableCheck());
EXPECT_TRUE(pwa_install_view_->GetVisible());
web_contents_->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
ASSERT_TRUE(web_contents_->IsCrashed());
EXPECT_FALSE(pwa_install_view_->GetVisible());
}
// Tests that the plus icon updates its visibility once the installability check
// completes.
IN_PROC_BROWSER_TEST_P(PwaInstallViewBrowserTest,
......
......@@ -496,6 +496,22 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest,
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kEnabled);
}
// Tests that both installing a PWA and creating a shortcut app are disabled
// when page crashes.
IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, ShortcutMenuOptionsForCrashedTab) {
ASSERT_TRUE(https_server()->Start());
EXPECT_TRUE(
NavigateAndAwaitInstallabilityCheck(browser(), GetInstallableAppURL()));
content::WebContents* tab_contents =
browser()->tab_strip_model()->GetActiveWebContents();
tab_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
ASSERT_TRUE(tab_contents->IsCrashed());
EXPECT_EQ(GetAppMenuCommandState(IDC_CREATE_SHORTCUT, browser()), kDisabled);
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kDisabled);
}
// Tests that an installed PWA is not used when out of scope by one path level.
IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, MenuOptionsOutsideInstalledPwaScope) {
ASSERT_TRUE(https_server()->Start());
......
......@@ -69,22 +69,22 @@ void OnWebAppInstalled(WebAppInstalledCallback callback,
bool CanCreateWebApp(const Browser* browser) {
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
if (!WebAppProvider::GetForWebContents(web_contents))
if (!WebAppProvider::Get(browser->profile()))
return false;
if (web_contents->IsCrashed())
return false;
content::NavigationEntry* entry =
web_contents->GetController().GetLastCommittedEntry();
bool is_error_page =
entry && entry->GetPageType() == content::PAGE_TYPE_ERROR;
Profile* web_contents_profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
if (entry && entry->GetPageType() == content::PAGE_TYPE_ERROR)
return false;
banners::AppBannerManager* app_banner_manager =
banners::AppBannerManager::FromWebContents(web_contents);
bool externally_installed =
app_banner_manager && app_banner_manager->IsExternallyInstalledWebApp();
return AreWebAppsUserInstallable(web_contents_profile) &&
return AreWebAppsUserInstallable(browser->profile()) &&
IsValidWebAppUrl(web_contents->GetLastCommittedURL()) &&
!is_error_page && !externally_installed;
!externally_installed;
}
bool CanPopOutWebApp(Profile* profile) {
......
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