Containers render view context menu adjustments (#35534)

* Do not fail unit tests when render_view is missing.

* Put "Open in container" below other "Open in..." items on link click.

* Use "Open link in container" text for link context menus.
This commit is contained in:
Aleksei Khoroshilov
2026-04-16 13:02:22 +07:00
committed by GitHub
parent d615f4b477
commit e10da75417
2 changed files with 28 additions and 4 deletions
+6
View File
@@ -950,6 +950,9 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_CXMENU_OPEN_IN_CONTAINER" desc="The label of the 'Open in Container' context menu item">
Open in container
</message>
<message name="IDS_CXMENU_OPEN_LINK_IN_CONTAINER" desc="The label of the 'Open link in container' context menu item">
Open link in container
</message>
<message name="IDS_CXMENU_OPEN_CONTAINERS_SETTINGS" desc="The label of the context menu item for opening the Containers settings page.">
Manage containers
</message>
@@ -985,6 +988,9 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_CXMENU_OPEN_IN_CONTAINER" desc="The label of the 'Open in Container' context menu item">
Open in Container
</message>
<message name="IDS_CXMENU_OPEN_LINK_IN_CONTAINER" desc="The label of the 'Open link in container' context menu item">
Open Link in Container
</message>
<message name="IDS_CXMENU_OPEN_CONTAINERS_SETTINGS" desc="The label of the tab context menu item for opening the Containers settings page.">
Manage Containers
</message>
@@ -8,6 +8,7 @@
#include <optional>
#include "base/check.h"
#include "base/check_is_test.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/fixed_flat_set.h"
#include "base/feature_list.h"
@@ -636,12 +637,26 @@ void RenderViewContextMenu::BuildContainersMenu() {
return;
}
std::optional<size_t> first_separator_index;
for (size_t i = 0; i < menu_model_.GetItemCount(); ++i) {
if (menu_model_.GetTypeAt(i) == ui::MenuModel::TYPE_SEPARATOR) {
first_separator_index = i;
break;
}
}
containers_submenu_model_ =
std::make_unique<containers::ContainersMenuModel>(*this, *service);
menu_model_.AddSubMenuWithStringId(IDC_OPEN_IN_CONTAINER,
IDS_CXMENU_OPEN_IN_CONTAINER,
containers_submenu_model_.get());
if (first_separator_index.has_value()) {
menu_model_.InsertSubMenuWithStringIdAt(
*first_separator_index, IDC_OPEN_IN_CONTAINER,
IDS_CXMENU_OPEN_LINK_IN_CONTAINER, containers_submenu_model_.get());
} else {
menu_model_.AddSubMenuWithStringId(IDC_OPEN_IN_CONTAINER,
IDS_CXMENU_OPEN_LINK_IN_CONTAINER,
containers_submenu_model_.get());
}
}
Browser* RenderViewContextMenu::GetBrowserToOpenSettings() {
@@ -652,7 +667,10 @@ float RenderViewContextMenu::GetScaleFactor() {
auto* render_frame_host = GetRenderFrameHost();
CHECK(render_frame_host);
auto* render_view = render_frame_host->GetView();
CHECK(render_view);
if (!render_view) {
CHECK_IS_TEST();
return 1.0f;
}
return render_view->GetDeviceScaleFactor();
}
#endif // BUILDFLAG(ENABLE_CONTAINERS)