[Extensions] Fix anchor view for MV2 deprecation disabled dialog
ShowDialog(ExtensionsToolbarContainer* container) retrieves the anchored view from the container and uses it to display the dialog. However, container may not be visible since it can be hidden when there are no enabled extensions. This causes a bug when the MV2 deprecation disabled dialog is shown when all installed extension are disabled (and hence extensions container is not visible). For this, we introduce a new method that takes in browser instead of the toolbar container so we can retrieve the correct anchor view. This is also preferred, because there is no reason to pass the native window (see crbug.com/355578898). The anchor view is provided by ToolbarButtonProvider::GetDefaultExtensionDialogAnchorView. We updated its implementations to returns the extensions toolbar button if the extensions toolbar container is existent and visible, or the app menu button. Screenshot: https://drive.google.com/file/d/1okVpwbKXVlD7x7vXS9BdJ_zunrlrsWpT/view?usp=sharing Bug: 355630549 Change-Id: Ic3b0c1dd77926c6cc6295dac69a80de5ea1df20d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5754644 Commit-Queue: Emilia Paz <emiliapaz@chromium.org> Reviewed-by: Erik Chen <erikchen@chromium.org> Cr-Commit-Position: refs/heads/main@{#1335828}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
cd27e70355
commit
708304a827
chrome/browser/ui
@ -81,8 +81,7 @@ void ShowExtensionMultipleUninstallDialog(
|
||||
|
||||
// Shows a dialog when `extension_ids` were disabled due to the MV2 deprecation.
|
||||
void ShowMv2DeprecationDisabledDialog(
|
||||
Profile* profile,
|
||||
gfx::NativeWindow parent,
|
||||
Browser* browser,
|
||||
const std::vector<ExtensionId>& extension_ids,
|
||||
base::OnceClosure remove_callback,
|
||||
base::OnceClosure manage_callback,
|
||||
|
@ -105,10 +105,8 @@ void Mv2DisabledDialogController::MaybeShowDisabledDialog() {
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(browser_->window());
|
||||
gfx::NativeWindow parent = browser_->window()->GetNativeWindow();
|
||||
ShowMv2DeprecationDisabledDialog(
|
||||
browser_->profile(), parent, extensions_to_include,
|
||||
browser_, extensions_to_include,
|
||||
base::BindOnce(&Mv2DisabledDialogController::OnRemoveSelected,
|
||||
weak_ptr_factory_.GetWeakPtr(), extensions_to_include),
|
||||
base::BindOnce(&Mv2DisabledDialogController::OnManageSelected,
|
||||
|
@ -113,3 +113,20 @@ void ShowDialog(ExtensionsToolbarContainer* container,
|
||||
widget->Show();
|
||||
}
|
||||
}
|
||||
|
||||
void ShowDialog(Browser* browser,
|
||||
std::unique_ptr<ui::DialogModel> dialog_model) {
|
||||
ToolbarButtonProvider* toolbar_button_provider =
|
||||
BrowserView::GetBrowserViewForBrowser(browser)->toolbar_button_provider();
|
||||
CHECK(toolbar_button_provider);
|
||||
|
||||
views::View* const anchor_view =
|
||||
toolbar_button_provider->GetDefaultExtensionDialogAnchorView();
|
||||
auto bubble = std::make_unique<views::BubbleDialogModelHost>(
|
||||
std::move(dialog_model), std::move(anchor_view),
|
||||
views::BubbleBorder::TOP_RIGHT);
|
||||
views::Widget* widget =
|
||||
views::BubbleDialogDelegate::CreateBubble(std::move(bubble));
|
||||
|
||||
widget->Show();
|
||||
}
|
||||
|
@ -45,4 +45,8 @@ void ShowDialog(ExtensionsToolbarContainer* container,
|
||||
const std::vector<extensions::ExtensionId>& extension_ids,
|
||||
std::unique_ptr<ui::DialogModel> dialog_model);
|
||||
|
||||
// Shows the dialog constructed from `dialog_model` in `browser`.
|
||||
void ShowDialog(Browser* browser,
|
||||
std::unique_ptr<ui::DialogModel> dialog_model);
|
||||
|
||||
#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSIONS_DIALOGS_UTILS_H_
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "chrome/browser/extensions/manifest_v2_experiment_manager.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_element_identifiers.h"
|
||||
#include "chrome/browser/ui/views/extensions/extensions_dialogs_utils.h"
|
||||
#include "chrome/grit/branded_strings.h"
|
||||
@ -18,8 +19,7 @@
|
||||
namespace extensions {
|
||||
|
||||
void ShowMv2DeprecationDisabledDialog(
|
||||
Profile* profile,
|
||||
gfx::NativeWindow parent,
|
||||
Browser* browser,
|
||||
const std::vector<ExtensionId>& extension_ids,
|
||||
base::OnceClosure remove_callback,
|
||||
base::OnceClosure manage_callback,
|
||||
@ -51,8 +51,8 @@ void ShowMv2DeprecationDisabledDialog(
|
||||
.DisableCloseOnDeactivate()
|
||||
.SetCloseActionCallback(std::move(close_callback));
|
||||
|
||||
auto* extension_registry = ExtensionRegistry::Get(profile);
|
||||
auto* extension_prefs = ExtensionPrefs::Get(profile);
|
||||
auto* extension_registry = ExtensionRegistry::Get(browser->profile());
|
||||
auto* extension_prefs = ExtensionPrefs::Get(browser->profile());
|
||||
|
||||
if (extensions_size == 1) {
|
||||
const Extension* extension =
|
||||
@ -83,11 +83,7 @@ void ShowMv2DeprecationDisabledDialog(
|
||||
}
|
||||
}
|
||||
|
||||
ExtensionsToolbarContainer* const extensions_container =
|
||||
parent ? GetExtensionsToolbarContainer(parent) : nullptr;
|
||||
DCHECK(extensions_container);
|
||||
|
||||
ShowDialog(extensions_container, extension_ids, dialog_builder.Build());
|
||||
ShowDialog(browser, dialog_builder.Build());
|
||||
}
|
||||
|
||||
} // namespace extensions
|
||||
|
@ -38,8 +38,7 @@ class Mv2DeprecationDisabledDialogBrowserTest
|
||||
scoped_refptr<const extensions::Extension> extension_B =
|
||||
AddMV2ExtensionAndDisable(u"Extension A");
|
||||
extensions::ShowMv2DeprecationDisabledDialog(
|
||||
browser()->profile(), browser()->window()->GetNativeWindow(),
|
||||
{extension_A->id(), extension_B->id()},
|
||||
browser(), {extension_A->id(), extension_B->id()},
|
||||
/*remove_callback=*/base::DoNothing(),
|
||||
/*manage_callback=*/base::DoNothing(),
|
||||
/*close_callback=*/base::DoNothing());
|
||||
|
@ -1145,8 +1145,9 @@ gfx::Size ToolbarView::GetToolbarButtonSize() const {
|
||||
}
|
||||
|
||||
views::View* ToolbarView::GetDefaultExtensionDialogAnchorView() {
|
||||
if (extensions_container_)
|
||||
if (extensions_container_ && extensions_container_->GetVisible()) {
|
||||
return extensions_container_->GetExtensionsButton();
|
||||
}
|
||||
return GetAppMenuButton();
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,12 @@ gfx::Size WebAppFrameToolbarView::GetToolbarButtonSize() const {
|
||||
}
|
||||
|
||||
views::View* WebAppFrameToolbarView::GetDefaultExtensionDialogAnchorView() {
|
||||
return right_container_->extensions_container()->GetExtensionsButton();
|
||||
ExtensionsToolbarContainer* extensions_container =
|
||||
GetExtensionsToolbarContainer();
|
||||
if (extensions_container && extensions_container->GetVisible()) {
|
||||
return extensions_container->GetExtensionsButton();
|
||||
}
|
||||
return GetAppMenuButton();
|
||||
}
|
||||
|
||||
PageActionIconView* WebAppFrameToolbarView::GetPageActionIconView(
|
||||
|
Reference in New Issue
Block a user