Open Bug 500911 Opened 17 years ago Updated 1 month ago

Firefox windows pop up and steal focus against window manager's focus stealing setting in session restore

Categories

(Core :: Widget: Gtk, defect, P5)

x86
Linux
defect

Tracking

()

ASSIGNED

People

(Reporter: 8, Assigned: tao)

References

(Blocks 2 open bugs)

Details

(Keywords: leave-open)

Attachments

(2 external files)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1) Gecko/20090622 Ubuntu/9.04 (jaunty) Shiretoko/3.5 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1) Gecko/20090622 Ubuntu/9.04 (jaunty) Shiretoko/3.5 I frequently restore Firefox session that has many windows. That takes some time. Sometimes I want to use another application meantime. That does not work because windows of the saved Firefox session pop up and steal focus from the other application that I am using. I have Focus stealing prevention setting (in Window Manager Tweaks dialog) of xfwm window manager enabled to prevent that from happening. The problem is that Firefox startup does respect the setting. Reproducible: Always Steps to Reproduce: 1. Enable focus stealing prevention in window manager settings of your window manager 2. Start Firefox that is configured to open saved session. Starting should happen using so called startup notification. 3. Update the time stamp of another application immediately by using it (e.g. by clicking on it or writing in it). Actual Results: Firefox windows steal focus and pop up. Expected Results: Firefox windows should be opened in background after the time stamp is updated; focus should not be stolen from the application that is being used. http://bugzilla.xfce.org/show_bug.cgi?id=4854 Metacity can be more forceful about it settings: http://bugzilla.xfce.org/show_bug.cgi?id=4854#c22 (Firefox session restore does not follow xfwm's disabled new window focus setting either.)
Component: Session Restore → Shell Integration
QA Contact: session.restore → shell.integration
Shell Integration isn't for widget bugs. Moving over to widget
Component: Shell Integration → Widget: Win32
Product: Firefox → Core
QA Contact: shell.integration → win32
Component: Widget: Win32 → Widget: Gtk
QA Contact: win32 → gtk
8@iki.fi do you still see this problem?
Flags: needinfo?(8)
It seems that I said wrong in step 2. Startup notification should not be used in calling, if user wants Firefox to start in background and not to pop up windows over the focused one. Even so, yes, I still see the problem. But the problem has eased a little over the years: Firefox prompts before session restore on startup when it is started automaticly as part of Xfce session. But it would be good, if a Firefox session could be restored or started in background. Acting according to focus stealing prevention setting and startup notification setting is one way to do it, besides there could be a command line option that starts firefox in background, I guess.
Flags: needinfo?(8)
Severity: normal → S3

This seems similar to bug 1658790 ("Firefox restoring sessions steals focus") which is under Toolkit/Startup and Profile System.

Mark additional GTK windows opened by non-interactive bulk SessionStore
restoration so their first map does not request focus.

Replace repeated per-window refocusing with one transaction-local refocus
after all window feature restores complete, unless the originally active
window was blurred or deactivated in the meantime. Clean up transaction
listeners on both success and failure, and keep undo-close and non-GTK
behavior unchanged.

Assignee: nobody → lukas.lipinsky
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Add a privileged, transient chrome flag that disables focus for the first GTK
map of a newly created window. Restore the normal focus-on-map policy after
that map and leave any activation context untouched for the user-initiated
window it belongs to.

Keep the existing always-on-top and Document Picture-in-Picture behavior
unchanged.

I can still reproduce this on Firefox Nightly 155 on Arch Linux with Xfce
4.20/xfwm4 under X11.

In an isolated Xvfb + xfwm4 reproducer, both builds restored 128 browser
windows. After an external GTK window was activated, the unpatched build
changed focus back to Firefox 160 times during the following 75 seconds. The
patched build produced zero Firefox focus transitions during the same
observation interval.

I submitted the fix as two dependent revisions:

  1. D315352 adds a privileged, transient chrome flag that suppresses focus for
    the first GTK map of a non-interactively created window. Normal
    focus-on-map behavior is restored after that map. Importantly, the
    process-wide GTK activation context is left untouched so a later
    user-initiated window can still consume its own token.
  2. D315350 uses that flag for additional windows created during bulk
    SessionStore restoration. It also replaces repeated per-window refocusing
    with one transaction-local refocus after all window-feature restores
    complete, unless the originally active window was blurred or deactivated
    in the meantime.

The submitted D315350 commit explicitly depends on D315352. Validation of the
submitted source tree:

  • full ./mach build -j8: passed
  • targeted lint, formatting, manifest, license, and whitespace checks: passed
  • final X11 tests under isolated Xvfb + xfwm4: 18/18 passed
    (browser_500911_restore_focus.js 14/14 and
    test_suppress_initial_focus.xhtml 4/4)
  • controlled focus comparison: 160 baseline Firefox focus transitions versus
    zero with the patched build

An earlier combined real-session smoke test also restored all 128 windows to
their saved Xfce workspaces (5 on workspace 0, 1 on workspace 1, and 122 on
workspace 4). Show Desktop remained active and no non-iconic Firefox window
was visible on the current workspace after restoration.

Two independent defects discovered while validating this scenario are tracked
separately:

  • Bug 2059452 / D315320: preserve a minimization made while delayed window
    features are pending
  • Bug 1707415 / D315322: allow GTK X11 restoration to workspace zero

No profile data, window titles, cookies, credentials, or raw traces were
uploaded.

Attachment #9619946 - Attachment description: Bug 500911 - Suppress initial GTK focus for non-interactive windows. r?stransky → Bug 500911 - Suppress initial X11 focus for non-interactive windows. r?stransky
Attachment #9619944 - Attachment description: Bug 500911 - Preserve external focus during bulk session restore. r?sfoster → Bug 500911 - Preserve focus during bulk session restore. r?sfoster
Attachment #9619946 - Attachment description: Bug 500911 - Suppress initial X11 focus for non-interactive windows. r?stransky → Bug 500911 - Suppress initial X11 focus during bulk session restore. r?stransky

We have a refactor in-flight for SessionStore.sys.mjs. I'd prefer to land functional changes to Session Restore on top of this to make back-out easier so I'm blocking on bug 1892761.

Depends on: 1892761
See Also: → 2059595
Pushed by sfoster@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e454445c4fa0 https://hg.mozilla.org/integration/autoland/rev/4231f70cd1a2 Preserve focus during bulk session restore. r=sfoster,tabbrowser-reviewers,sthompson
Pushed by smolnar@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/87dc2f195316 https://hg.mozilla.org/integration/autoland/rev/7c77762705f6 Revert "Bug 500911 - Preserve focus during bulk session restore. r=sfoster,tabbrowser-reviewers,sthompson" for causing lint failures

Backed out for causing lint failures @ browser/components/sessionstore/SessionStore.sys

Backout link: https://hg.mozilla.org/integration/autoland/rev/7c77762705f695de98e9f94ab383f271bbeb1e2e

Push with failures

Failure log

Flags: needinfo?(tao)

also these bc failures

Flags: needinfo?(tao) → needinfo?(sfoster)
Pushed by dgottwald@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/43f5a9e0a11d https://hg.mozilla.org/integration/autoland/rev/2e7ad1a4eb5c Preserve focus during bulk session restore. r=sfoster,tabbrowser-reviewers,sthompson
Keywords: leave-open
Pushed by amarc@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/444288ee85a0 https://hg.mozilla.org/integration/autoland/rev/7839634b7f69 Revert "Bug 500911 - Preserve focus during bulk session restore. r=sfoster,tabbrowser-reviewers,sthompson" for causing bc failures @ browser_restore_preserves_focus

Backed out for causing bc failures

Flags: needinfo?(sfoster)

Lukas, do you mind to check the test failures?
Thanks.

Flags: needinfo?(tao)

Thanks, Martin. I checked both September 29/30 autoland browser-test logs. They fail in test_bulk_restore_refocuses_after_delayed_activation: the test assumes nonTargetWindow.focus() has not changed Services.focus.activeWindow yet. That timing assumption does not hold consistently. The subsequent diagnostic test queues the request explicitly, but Sam's Linux opt/debug Try still shows the native non-target activation arriving 21–33 ms after bulk-restore end, with zero target focus calls.

I have now reproduced the latter behavior through a complete programmatic bulk restore in isolated Xvfb/Openbox, using the packaged SessionStore and BrowserWindowTracker modules from that Try. Both modules match the current submitted source byte-for-byte. The two local queued-request cases delivered the non-target activation 40.9 and 129.0 ms after bulk end. One main-thread dispatch therefore does not settle that request.

The same integration also confirms the separate initial-null issue raised in review. When restore begins with no active Firefox window, then an owned window activates and an external application takes focus, final arbitration calls the target's focus once and takes activation back. Both repetitions agree. With an initially active Firefox window, the external intervention is preserved with zero target focus calls. A further pair of cases shows that an external-null sample is not remembered if an owned window becomes active again before completion. All twelve diagnostic cases completed their restore notifications with a paired bulk start/end.

These are full setBrowserState() restore diagnostics on an artifact build, not startup acceptance or an unpatched-baseline comparison. I have left production focus policy unchanged. The remaining questions about pending native activation and initial-null/background restoration are with Emilio in D315350 comment 1765496: https://phabricator.services.mozilla.com/D315350#11560016. The current patch is not ready to reland; I will follow up with the correction and fresh platform tests once that contract is established.

Sam's diagnostic Try: https://treeherder.mozilla.org/jobs?repo=try&revision=7505fb68349bab106c2da3045272921816254f86

Flags: needinfo?(tao)
See Also: → 2087798
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: