feat: add support for associating a Menu with a WebFrameMain (#45138)
* feat: add support for associating a Menu with a WebFrameMain This allows certain OS level features to activate such as Writing Tools, Autofill.. and Services. There appears to be a bug in macOS where the responder chain isn't traversed if the menu is not popped up using an event, as such we spoof a fake mouse event at the write coordinates in the right window and use that to open the menu. * build: fix build on non-mac * build: oops missed a header * fix: safely handle optional T* by checking nullptr too * build: fix gn check and build errors * docs: suggested changes * feat: default `frame` to `window.webContents.mainFrame` when possible * fix: avoid deref nullptr view * Revert "feat: default `frame` to `window.webContents.mainFrame` when possible" This reverts commit 2e888368199317d67f6ad931a7e9eff0295c4b1b. * fix: lint * Remove redundant scoped objects This code, including the comments, matches almost exactly the behavior of this argument to the function. * Add ScopedPumpMessagesInPrivateModes patch * More null pointer safety --------- Co-authored-by: clavin <clavin@electronjs.org>
This commit is contained in:
parent
46b108e9a4
commit
49aba471dc
12 changed files with 104 additions and 16 deletions
|
@ -135,6 +135,7 @@ fix_add_method_which_disables_headless_mode_on_native_widget.patch
|
|||
refactor_unfilter_unresponsive_events.patch
|
||||
build_disable_thin_lto_mac.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
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
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() {
|
Loading…
Add table
Add a link
Reference in a new issue