Closed Bug 1710275 Opened 3 years ago Closed 3 years ago

nsMsgMailSession::GetTopmostMsgWindow() broken since bug 1509060

Categories

(MailNews Core :: General, defect)

defect

Tracking

(thunderbird_esr78 wontfix, thunderbird89 affected)

RESOLVED FIXED
90 Branch
Tracking Status
thunderbird_esr78 --- wontfix
thunderbird89 --- affected

People

(Reporter: jose, Assigned: rnons)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36

Steps to reproduce:

In bug 1708073 comment #13 I noticed that that nsMsgMailSession::GetTopmostMsgWindow() no longer returns the top-most 3pane or stand-alone message window. Most call sites
https://searchfox.org/comm-central/search?q=GetTopmostMsgWindow%28&path=
don't seem to care as long as the get at least a 3pane window, but here
https://searchfox.org/comm-central/rev/dbdd31e28cca8282dc44fd2cc4280af40e1cb50b/mailnews/local/src/nsLocalMailFolder.cpp#2829
it is important to get the correct top-most window in which the user clicked the "download rest of message" link.

I have the impression that this call-site
https://searchfox.org/comm-central/rev/dbdd31e28cca8282dc44fd2cc4280af40e1cb50b/mailnews/base/src/nsMessengerWinIntegration.cpp#131
would prefer the current defective behaviour by activating a 3pane and not a stand-alone window.

In any case, this needs to be fixed as suggested in bug 1509060 comment #1 / bug 1489833 comment #3.

Blocks: 1708073

https://searchfox.org/comm-central/rev/dbdd31e28cca8282dc44fd2cc4280af40e1cb50b/mailnews/compose/src/nsMsgCompose.cpp#156
may also rely on getting the correct top-most window, something like: Open a message in a stand-alone window, correct and incorrect charset, reply or forward/"edit as new". Looks like the code gets the charset from the top-most window.

Further to the previous comment: As predicted, opening a message in a stand-alone window, changing the charset and then replying doesn't pick up the charset that was just set any more. It still works when replying form the main window.

In nsMailSession.cpp, we are using domElement.getAttribute("windowtype") to get the window type, so I was thinking maybe we can use js to detect if a window is active or not, then toggle an attribute on the html element. I open a new msg window, inspect it in devtools, run the following js in the console tab

window.addEventListener('focus', () => console.log('focus'))
window.addEventListener('blur', () => console.log('blur'))

There are sub-frames in msg window, when focusing a sub-frame, the msg window itself loses focus, so we don't really know if msgwindow is active.

I also tried visibilitychange event, but it's not triggered when using cmd+tab to switch window. I have no idea now.

Previously GetTopmostMsgWindow returns the first 3pane or messageWindow found, this patch uses nsIFocusManager to guarantee it's the topmost window.

Assignee: nobody → remotenonsense
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Target Milestone: --- → 90 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/ddee6960495f
Use nsIFocusManager.activeWindow to fix nsIMsgMailSession.topmostMsgWindow. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED

The patch fixes bug 1708073 and the scenario from comment #1. Please make sure that the call site in nsMessengerWinIntegration.cpp still behaves as desired. That code was added after the breakage had occurred in bug 1509060, so there a 3pane window would always have been activated which is now no longer the case.

OK, made a new patch.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/f4d8dbfde1d5
Activate the most recent 3pane window when click the tray icon on Windows. r=mkmelin

Status: REOPENED → RESOLVED
Closed: 3 years ago3 years ago
Resolution: --- → FIXED

Any reason for not calling GetMostRecentWindow(u"mail:3pane", getter_AddRefs(domWindow)); directly like in most other call sites? The wrapper
https://searchfox.org/mozilla-central/rev/048146721b3c1a568257afb4325c7a8d94334e2d/xpfe/appshell/nsWindowMediator.cpp#235
unnecessarily calls GetMostRecentWindow(u"navigator:browser", ...) first. The same comment applies to:
https://searchfox.org/comm-central/rev/b9e78aad665f4d6d159adcb508e1fe55ed7c9ac8/mailnews/base/src/WinUnreadBadge.jsm#199.
I suggest to file another bug to replace those two calls.

Blocks: 1711533
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: