Compare commits

...

1 Commits

Author SHA1 Message Date
Keeley Hammond
5fb20732d5 Revert "feat: add support for associating a Menu with a WebFrameMain (#45138)"
This reverts commit 49aba471dc.
2025-04-08 14:58:01 -07:00
12 changed files with 16 additions and 104 deletions

View File

@@ -73,8 +73,6 @@ The `menu` object has the following instance methods:
* `options` Object (optional)
* `window` [BaseWindow](base-window.md) (optional) - Default is the focused window.
* `frame` [WebFrameMain](web-frame-main.md) (optional) - Provide the relevant frame
if you want certain OS-level features such as Writing Tools on macOS to function correctly. Typically, this should be `params.frame` from the [`context-menu` event](web-contents.md#event-context-menu) on a WebContents.
* `x` number (optional) - Default is the current mouse cursor position.
Must be declared if `y` is declared.
* `y` number (optional) - Default is the current mouse cursor position.

View File

@@ -93,7 +93,7 @@ Menu.prototype.popup = function (options = {}) {
}
}
this.popupAt(window as unknown as BaseWindow, options.frame, x, y, positioningItem, sourceType, callback);
this.popupAt(window as unknown as BaseWindow, x, y, positioningItem, sourceType, callback);
return { browserWindow: window, x, y, position: positioningItem };
};

View File

@@ -136,7 +136,6 @@ refactor_unfilter_unresponsive_events.patch
build_disable_thin_lto_mac.patch
feat_corner_smoothing_css_rule_and_blink_painting.patch
build_add_public_config_simdutf_config.patch
fix_multiple_scopedpumpmessagesinprivatemodes_instances.patch
revert_code_health_clean_up_stale_macwebcontentsocclusion.patch
ignore_parse_errors_for_resolveshortcutproperties.patch
feat_add_signals_when_embedder_cleanup_callbacks_run_for.patch

View File

@@ -1,51 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Calvin Watford <watfordcalvin@gmail.com>
Date: Wed, 5 Mar 2025 15:26:28 -0700
Subject: fix: multiple ScopedPumpMessagesInPrivateModes instances
Context: When swapping `Menu.popup` to use `ui::ShowContextMenu`, we
found that its use of `ScopedPumpMessagesInPrivateModes` may potentially
be used multiple times simultaneously. This class was designed to work
with only one global instance.
This patch adds a global reference count to keep track of
`ScopedPumpMessagesInPrivateModes` instances and gate its
enable/disable behavior on this reference count.
diff --git a/base/message_loop/message_pump_apple.mm b/base/message_loop/message_pump_apple.mm
index 52ed68ac3150bdeef3c5032f3f5f7df3d5aaac51..1658aece3e8fbcef89944a849e311f7949a68de9 100644
--- a/base/message_loop/message_pump_apple.mm
+++ b/base/message_loop/message_pump_apple.mm
@@ -760,20 +760,29 @@ explicit OptionalAutoreleasePool(MessagePumpCFRunLoopBase* pump) {
#else
+static int g_private_mode_ref_count = 0;
+
ScopedPumpMessagesInPrivateModes::ScopedPumpMessagesInPrivateModes() {
DCHECK(g_app_pump);
- DCHECK_EQ(kNSApplicationModalSafeModeMask, g_app_pump->GetModeMask());
// Pumping events in private runloop modes is known to interact badly with
// app modal windows like NSAlert.
if (NSApp.modalWindow) {
return;
}
- g_app_pump->SetModeMask(kAllModesMask);
+
+ g_private_mode_ref_count += 1;
+ if (g_private_mode_ref_count == 1) {
+ g_app_pump->SetModeMask(kAllModesMask);
+ }
}
ScopedPumpMessagesInPrivateModes::~ScopedPumpMessagesInPrivateModes() {
DCHECK(g_app_pump);
- g_app_pump->SetModeMask(kNSApplicationModalSafeModeMask);
+ DCHECK(g_private_mode_ref_count > 0);
+ g_private_mode_ref_count -= 1;
+ if (g_private_mode_ref_count == 0) {
+ g_app_pump->SetModeMask(kNSApplicationModalSafeModeMask);
+ }
}
int ScopedPumpMessagesInPrivateModes::GetModeMaskForTest() {

View File

@@ -7,7 +7,6 @@
#include <utility>
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/api/electron_api_web_frame_main.h"
#include "shell/browser/api/ui_event.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/native_window.h"
@@ -17,7 +16,6 @@
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_converters/optional_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"

View File

@@ -22,7 +22,6 @@ class Arguments;
namespace electron::api {
class BaseWindow;
class WebFrameMain;
class Menu : public gin::Wrappable<Menu>,
public gin_helper::EventEmitterMixin<Menu>,
@@ -82,7 +81,6 @@ class Menu : public gin::Wrappable<Menu>,
void OnMenuWillShow(ui::SimpleMenuModel* source) override;
virtual void PopupAt(BaseWindow* window,
std::optional<WebFrameMain*> frame,
int x,
int y,
int positioning_item,

View File

@@ -13,7 +13,6 @@
namespace electron {
class NativeWindow;
class WebFrameMain;
namespace api {
@@ -24,14 +23,12 @@ class MenuMac : public Menu {
// Menu
void PopupAt(BaseWindow* window,
std::optional<WebFrameMain*> frame,
int x,
int y,
int positioning_item,
ui::mojom::MenuSourceType source_type,
base::OnceClosure callback) override;
void PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
const base::WeakPtr<WebFrameMain>& frame,
int32_t window_id,
int x,
int y,

View File

@@ -11,15 +11,11 @@
#include "base/strings/sys_string_conversions.h"
#include "base/task/current_thread.h"
#include "base/task/sequenced_task_runner.h"
#include "content/app_shim_remote_cocoa/render_widget_host_view_cocoa.h" // nogncheck
#include "content/browser/renderer_host/render_widget_host_view_mac.h" // nogncheck
#include "content/public/browser/browser_task_traits.h"
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/api/electron_api_web_frame_main.h"
#include "shell/browser/native_window.h"
#include "shell/common/keyboard_util.h"
#include "shell/common/node_includes.h"
#include "ui/base/cocoa/menu_utils.h"
namespace {
@@ -52,7 +48,6 @@ MenuMac::MenuMac(gin::Arguments* args) : Menu(args) {}
MenuMac::~MenuMac() = default;
void MenuMac::PopupAt(BaseWindow* window,
std::optional<WebFrameMain*> frame,
int x,
int y,
int positioning_item,
@@ -62,19 +57,14 @@ void MenuMac::PopupAt(BaseWindow* window,
if (!native_window)
return;
base::WeakPtr<WebFrameMain> weak_frame;
if (frame && frame.value()) {
weak_frame = frame.value()->GetWeakPtr();
}
// Make sure the Menu object would not be garbage-collected until the callback
// has run.
base::OnceClosure callback_with_ref = BindSelfToClosure(std::move(callback));
auto popup = base::BindOnce(&MenuMac::PopupOnUI, weak_factory_.GetWeakPtr(),
native_window->GetWeakPtr(), weak_frame,
window->weak_map_id(), x, y, positioning_item,
std::move(callback_with_ref));
auto popup =
base::BindOnce(&MenuMac::PopupOnUI, weak_factory_.GetWeakPtr(),
native_window->GetWeakPtr(), window->weak_map_id(), x, y,
positioning_item, std::move(callback_with_ref));
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(FROM_HERE,
std::move(popup));
}
@@ -105,7 +95,6 @@ v8::Local<v8::Value> Menu::GetUserAcceleratorAt(int command_id) const {
}
void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
const base::WeakPtr<WebFrameMain>& frame,
int32_t window_id,
int x,
int y,
@@ -156,27 +145,18 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
position.x = position.x - [menu size].width;
[popup_controllers_[window_id] setCloseCallback:std::move(close_callback)];
// Make sure events can be pumped while the menu is up.
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
if (frame && frame->render_frame_host()) {
auto* rfh = frame->render_frame_host()->GetOutermostMainFrameOrEmbedder();
if (rfh && rfh->IsRenderFrameLive()) {
auto* rwhvm =
static_cast<content::RenderWidgetHostViewMac*>(rfh->GetView());
RenderWidgetHostViewCocoa* cocoa_view = rwhvm->GetInProcessNSView();
view = cocoa_view;
}
}
// One of the events that could be pumped is |window.close()|.
// User-initiated event-tracking loops protect against this by
// setting flags in -[CrApplication sendEvent:], but since
// web-content menus are initiated by IPC message the setup has to
// be done manually.
base::mac::ScopedSendingEvent sendingEventScoper;
NSEvent* dummy_event = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown
location:position
modifierFlags:0
timestamp:0
windowNumber:nswindow.windowNumber
context:nil
eventNumber:0
clickCount:1
pressure:0];
ui::ShowContextMenu(menu, dummy_event, view, true);
// Don't emit unresponsive event when showing menu.
[menu popUpMenuPositioningItem:item atLocation:position inView:view];
}
void MenuMac::ClosePopupAt(int32_t window_id) {

View File

@@ -8,7 +8,6 @@
#include <utility>
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/api/electron_api_web_frame_main.h"
#include "shell/browser/native_window_views.h"
#include "ui/display/screen.h"
@@ -21,7 +20,6 @@ MenuViews::MenuViews(gin::Arguments* args) : Menu(args) {}
MenuViews::~MenuViews() = default;
void MenuViews::PopupAt(BaseWindow* window,
std::optional<WebFrameMain*> frame,
int x,
int y,
int positioning_item,

View File

@@ -22,7 +22,6 @@ class MenuViews : public Menu {
protected:
// Menu
void PopupAt(BaseWindow* window,
std::optional<WebFrameMain*> frame,
int x,
int y,
int positioning_item,

View File

@@ -73,10 +73,6 @@ class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
content::RenderFrameHost* render_frame_host() const;
base::WeakPtr<WebFrameMain> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
// disable copy
WebFrameMain(const WebFrameMain&) = delete;
WebFrameMain& operator=(const WebFrameMain&) = delete;

View File

@@ -166,7 +166,7 @@ declare namespace Electron {
commandsMap: Record<string, MenuItem>;
groupsMap: Record<string, MenuItem[]>;
getItemCount(): number;
popupAt(window: BaseWindow, frame: WebFrameMain | undefined, x: number, y: number, positioning: number, sourceType: Required<Electron.PopupOptions>['sourceType'], callback: () => void): void;
popupAt(window: BaseWindow, x: number, y: number, positioning: number, sourceType: Required<Electron.PopupOptions>['sourceType'], callback: () => void): void;
closePopupAt(id: number): void;
setSublabel(index: number, label: string): void;
setToolTip(index: number, tooltip: string): void;