Closed Bug 1586061 Opened 6 years ago Closed 4 years ago

hidden window churn causes app menu to stop working

Categories

(Core :: Widget: Cocoa, defect, P2)

x86_64
macOS
defect

Tracking

()

RESOLVED FIXED
97 Branch
Tracking Status
firefox-esr91 --- fixed
firefox71 --- wontfix
firefox96 --- fixed
firefox97 --- fixed

People

(Reporter: mcs, Assigned: spohl)

References

()

Details

(Whiteboard: [tor 31607])

Attachments

(3 files)

Attached patch tor-31607.patchSplinter Review

Tor Browser 9.0a7 (available at https://dist.torproject.org/torbrowser/9.0a7/) is based on Firefox ESR68. One of the components of Tor Browser is Tor Launcher, a XUL/XPCOM extension that is integrated into the browser similar to how pdfjs is integrated. Tor Launcher is a weird beast: to interact with the user for configuration and to ensure that the Tor proxy is up and running before a browser window opens, Tor Launcher opens a modal window when it receives a profile-after-change notification. On macOS at least, this causes a hidden window to be opened before the call to appStartup->CreateHiddenWindow() inside XREMain::XRE_mainRun() (which is how the one and only hidden window is typically opened).

The problem comes in when the second hidden window is opened from XREMain::XRE_mainRun(): that causes the original hidden window to be freed. Unfortunately, that causes the nsMenuBarX object that is associated with the app menu to be freed which in turn causes all of the app menu items to stop working (the nsMenuBarX destructor clears the menuGroupOwner property within each Cocoa menu items's MenuItemInfo object , and this breaks the link that is necessary for NativeMenuItemTarget's menuItemHit method to dispatch a menu item event).

Our proposed fix for Tor Browser is to add a check to ensure that the hidden window is only created once. We would like to get feedback on this approach; see the attached patch.

See also: https://trac.torproject.org/projects/tor/ticket/31607

It is possible this is a duplicate of bug 1534965 (but it is difficult to tell for sure).

Poking the Mac folks I know - thanks in advance!

Flags: needinfo?(spohl.mozilla.bugs)
Flags: needinfo?(mstange)
Flags: needinfo?(haftandilian)

Sorry, I'm not the right person to review this.

Flags: needinfo?(haftandilian)

Markus, this seems like it would be right in your wheelhouse. Let me know if you'd like me to take this instead.

Flags: needinfo?(spohl.mozilla.bugs)

Markus: any chance to look at this patch soonish? We lack the macOS experience to thoroughly review the approach but will ship the patch in our upcoming alpha to give it a bit more testing until we need to build Tor Browser 9 (based on 68.2.0esr) next week. Having some feedback by then would be neat.

Whiteboard: [tor] → [tor 31607]
Priority: -- → P2

Revisiting this bug. I confirmed that it still exists with the current mozilla-central code running on macOS 10.15.5. This patch adds a built-in extension that opens the migration wizard window at profile-after-change time. When you see the migration wizard, just click Cancel and allow the browser to finish starting up. Notice that choosing any item from the application menu (or pressing its associated command key) has no effect (e.g., choosing Quit and pressing Cmd+Q do not do anything).

I also confirmed that checking for mHiddenWindow inside nsAppShellService::CreateHiddenWindow() and returning early when mHiddenWindow is set is still an effective fix.

(In reply to Stephen A Pohl [:spohl] from comment #4)

Markus, this seems like it would be right in your wheelhouse. Let me know if you'd like me to take this instead.

I'd interpret the two years' silence by Markus as a "yes, please take it instead of me". What do you think, Stpehen? The patch we propose is a 2-3 liner which is working fine for us, so it might not be too difficult to review. As a bonus point we'd carry yet another patch less in our patch set if we'd finally be able to upstream it.

Flags: needinfo?(spohl.mozilla.bugs)
Assignee: nobody → spohl.mozilla.bugs
Status: NEW → ASSIGNED

Thanks for the ping. I sent this for review and we'll iterate on it there, if necessary.

Flags: needinfo?(spohl.mozilla.bugs)
Flags: needinfo?(mstange.moz)

Oh wow, yeah this definitely slipped through the cracks. Thanks for the ping.

Pushed by spohl@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/15b61919eb33 Prevent additional hidden windows from being created if one already exists on macOS. r=mstange
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 97 Branch

Thanks everyone, much appreciated. Stephen: would you be amenable to uplift this patch to ESR 91 as that would mean we'd have to carry one patch less in our patch set? If so, could you file the respective request? The patch seems simple enough...

Flags: needinfo?(spohl.mozilla.bugs)

Comment on attachment 9255765 [details]
Bug 1586061: Prevent additional hidden windows from being created if one already exists on macOS. r=mstange

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: Tor is carrying an extra patch with this workaround in their patch set. This would avoid the need of doing so.
  • User impact if declined: n/a
  • Fix Landed on Version: 97
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Tor has been using this workaround for approximately 2 years. The change consists of only three lines.
Flags: needinfo?(spohl.mozilla.bugs)
Attachment #9255765 - Flags: approval-mozilla-esr91?

Comment on attachment 9255765 [details]
Bug 1586061: Prevent additional hidden windows from being created if one already exists on macOS. r=mstange

Approved for 96.0b8 and 91.5esr.

Attachment #9255765 - Flags: approval-mozilla-esr91?
Attachment #9255765 - Flags: approval-mozilla-esr91+
Attachment #9255765 - Flags: approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: