Hide PWA install icon in the web site which is not surported pwa.
PWA install icons were unconditionally persisting in the omnibox after opening the install dialogue and switching to another tab. This causes the install icon to potentially show for sites that are not installable. This CL fixes this by refreshing the pwa address bar icon when the bubble is closed Add a test case in pwa_install_view_browsertest.cc: IconVisibilityAfterTabSwitchingWhenPWAConfirmationBubbleViewShowing. Add a function with the name "PWAConfirmationBubbleViewShow" which is called in IconVisibilityAfterTabSwitchingWhenPWAConfirmationBubbleViewShowing. Add a static function: GetCallbackForTesting() in PWAConfirmationBubbleView class, which was called at the end of the ShowPWAInstallBubble() function of PWAConfirmationBubbleView class. Add a static function: WaitPwaConfirmationBubbleClosed() in PWAConfirmationBubbleView class, which was called after switching tabs. The new function (WaitPwaConfirmationBubbleClosed) implementation principle is to use the code to close the bubble window after switching Bug: 1298805 Change-Id: I21de691786c25a209599b91cb1ce606791c53605 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3808600 Commit-Queue: Daniel Murphy <dmurph@chromium.org> Reviewed-by: Daniel Murphy <dmurph@chromium.org> Reviewed-by: Alan Cutter <alancutter@chromium.org> Cr-Commit-Position: refs/heads/main@{#1032662}
This commit is contained in:
AUTHORS
chrome/browser/ui/views
1
AUTHORS
1
AUTHORS
@ -1441,6 +1441,7 @@ Wacom <*@wacom.com>
|
||||
Whist Technologies <*@whist.com>
|
||||
Xperi Corporation <*@xperi.com>
|
||||
Yandex LLC <*@yandex-team.ru>
|
||||
Zhou Jun <zhoujun@uniontech.com>
|
||||
Zuckjet <zuckjet@gmail.com>
|
||||
# Please DO NOT APPEND here. See comments at the top of the file.
|
||||
# END organizations section.
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
|
||||
#include "chrome/browser/ui/views/location_bar/star_view.h"
|
||||
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
|
||||
#include "chrome/browser/ui/views/web_apps/pwa_confirmation_bubble_view.h"
|
||||
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
|
||||
#include "chrome/browser/web_applications/install_bounce_metric.h"
|
||||
#include "chrome/browser/web_applications/os_integration/os_integration_manager.h"
|
||||
@ -50,6 +51,7 @@
|
||||
#include "services/network/public/cpp/network_switches.h"
|
||||
#include "ui/gfx/color_utils.h"
|
||||
#include "ui/views/view_observer.h"
|
||||
#include "ui/views/widget/any_widget_observer.h"
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#include "ash/components/arc/test/arc_util_test_support.h"
|
||||
@ -298,6 +300,26 @@ class PwaInstallViewBrowserTest : public extensions::ExtensionBrowserTest {
|
||||
expected_buckets);
|
||||
}
|
||||
|
||||
void WaitPwaConfirmationBubbleViewShown() {
|
||||
views::NamedWidgetShownWaiter pwa_confirmation_bubble_id_waiter(
|
||||
views::test::AnyWidgetTestPasskey(),
|
||||
"PWAConfirmationBubbleView");
|
||||
|
||||
pwa_install_view_->ExecuteForTesting();
|
||||
pwa_confirmation_bubble_id_waiter.WaitIfNeededAndGet();
|
||||
}
|
||||
|
||||
void WaitPwaConfirmationBubbleClosed() {
|
||||
if (PWAConfirmationBubbleView::IsShowing()) {
|
||||
base::RunLoop run_loop;
|
||||
PWAConfirmationBubbleView::GetBubble()->RegisterDeleteDelegateCallback(
|
||||
run_loop.QuitClosure());
|
||||
PWAConfirmationBubbleView::GetBubble()->GetWidget()->CloseWithReason(
|
||||
views::Widget::ClosedReason::kEscKeyPressed);
|
||||
run_loop.Run();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
net::EmbeddedTestServer https_server_;
|
||||
std::string intercept_request_path_;
|
||||
@ -416,6 +438,35 @@ IN_PROC_BROWSER_TEST_F(PwaInstallViewBrowserTest,
|
||||
EXPECT_FALSE(pwa_install_view_->GetVisible());
|
||||
}
|
||||
|
||||
// Tests that the plus icon updates its visibility when PWAConfirmationBubbleView is showing in
|
||||
// installable tab and switching to non-installable tab.
|
||||
IN_PROC_BROWSER_TEST_F(PwaInstallViewBrowserTest,
|
||||
IconVisibilityAfterTabSwitchingWhenPWAConfirmationBubbleViewShowing) {
|
||||
content::WebContents* installable_web_contents;
|
||||
{
|
||||
OpenTabResult result = OpenTab(GetInstallableAppURL());
|
||||
installable_web_contents = result.web_contents;
|
||||
ASSERT_TRUE(result.installable);
|
||||
}
|
||||
content::WebContents* non_installable_web_contents;
|
||||
{
|
||||
OpenTabResult result = OpenTab(GetNonInstallableAppURL());
|
||||
non_installable_web_contents = result.web_contents;
|
||||
ASSERT_FALSE(result.installable);
|
||||
}
|
||||
chrome::SelectPreviousTab(browser());
|
||||
ASSERT_EQ(installable_web_contents, GetCurrentTab());
|
||||
EXPECT_TRUE(pwa_install_view_->GetVisible());
|
||||
|
||||
WaitPwaConfirmationBubbleViewShown();
|
||||
|
||||
chrome::SelectNextTab(browser());
|
||||
WaitPwaConfirmationBubbleClosed();
|
||||
ASSERT_EQ(non_installable_web_contents, GetCurrentTab());
|
||||
EXPECT_FALSE(PWAConfirmationBubbleView::IsShowing());
|
||||
EXPECT_FALSE(pwa_install_view_->GetVisible());
|
||||
}
|
||||
|
||||
// Tests that the install icon updates its visibility when tab crashes.
|
||||
IN_PROC_BROWSER_TEST_F(PwaInstallViewBrowserTest,
|
||||
IconVisibilityAfterTabCrashed) {
|
||||
|
@ -103,13 +103,14 @@ PWAConfirmationBubbleView* PWAConfirmationBubbleView::GetBubble() {
|
||||
|
||||
PWAConfirmationBubbleView::PWAConfirmationBubbleView(
|
||||
views::View* anchor_view,
|
||||
views::Button* highlight_button,
|
||||
PageActionIconView* highlight_icon_button,
|
||||
std::unique_ptr<WebAppInstallInfo> web_app_info,
|
||||
chrome::AppInstallationAcceptanceCallback callback,
|
||||
chrome::PwaInProductHelpState iph_state,
|
||||
PrefService* prefs,
|
||||
feature_engagement::Tracker* tracker)
|
||||
: LocationBarBubbleDelegateView(anchor_view, nullptr),
|
||||
highlight_icon_button_(highlight_icon_button),
|
||||
web_app_info_(std::move(web_app_info)),
|
||||
callback_(std::move(callback)),
|
||||
iph_state_(iph_state),
|
||||
@ -170,7 +171,7 @@ PWAConfirmationBubbleView::PWAConfirmationBubbleView(
|
||||
web_app::UserDisplayMode::kTabbed);
|
||||
}
|
||||
|
||||
SetHighlightedButton(highlight_button);
|
||||
SetHighlightedButton(highlight_icon_button_);
|
||||
}
|
||||
|
||||
PWAConfirmationBubbleView::~PWAConfirmationBubbleView() = default;
|
||||
@ -190,6 +191,9 @@ void PWAConfirmationBubbleView::WindowClosing() {
|
||||
DCHECK_EQ(g_bubble_, this);
|
||||
g_bubble_ = nullptr;
|
||||
|
||||
if (highlight_icon_button_)
|
||||
highlight_icon_button_->Update();
|
||||
|
||||
// If |web_app_info_| is populated, then the bubble was not accepted.
|
||||
if (web_app_info_) {
|
||||
base::RecordAction(base::UserMetricsAction("WebAppInstallCancelled"));
|
||||
@ -226,6 +230,11 @@ bool PWAConfirmationBubbleView::Accept() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PWAConfirmationBubbleView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
|
||||
views::Widget* widget) const {
|
||||
params->name = "PWAConfirmationBubbleView";
|
||||
}
|
||||
|
||||
namespace chrome {
|
||||
|
||||
void ShowPWAInstallBubble(content::WebContents* web_contents,
|
||||
|
@ -21,6 +21,8 @@ namespace feature_engagement {
|
||||
class Tracker;
|
||||
}
|
||||
|
||||
class PageActionIconView;
|
||||
|
||||
// PWAConfirmationBubbleView provides a bubble dialog for accepting or rejecting
|
||||
// the installation of a PWA (Progressive Web App) anchored off the PWA install
|
||||
// icon in the omnibox.
|
||||
@ -30,7 +32,7 @@ class PWAConfirmationBubbleView : public LocationBarBubbleDelegateView {
|
||||
static PWAConfirmationBubbleView* GetBubble();
|
||||
|
||||
PWAConfirmationBubbleView(views::View* anchor_view,
|
||||
views::Button* highlight_button,
|
||||
PageActionIconView* highlight_icon_button,
|
||||
std::unique_ptr<WebAppInstallInfo> web_app_info,
|
||||
chrome::AppInstallationAcceptanceCallback callback,
|
||||
chrome::PwaInProductHelpState iph_state,
|
||||
@ -49,7 +51,11 @@ class PWAConfirmationBubbleView : public LocationBarBubbleDelegateView {
|
||||
void WindowClosing() override;
|
||||
bool Accept() override;
|
||||
|
||||
protected:
|
||||
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
|
||||
views::Widget* widget) const override;
|
||||
private:
|
||||
PageActionIconView* highlight_icon_button_ = nullptr;
|
||||
std::unique_ptr<WebAppInstallInfo> web_app_info_;
|
||||
chrome::AppInstallationAcceptanceCallback callback_;
|
||||
|
||||
|
Reference in New Issue
Block a user