Bug 33389 - window.focus() should be disabled when not user-initiated
Summary: window.focus() should be disabled when not user-initiated
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on: 33381
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-08 09:37 PST by Steve Block
Modified: 2010-08-17 03:14 PDT (History)
6 users (show)

See Also:


Attachments
Attempt at a patch (1.40 KB, patch)
2010-08-16 14:14 PDT, Jay Civelli
sam: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Block 2010-01-08 09:37:13 PST
Currently, window.focus can be used to shift the focus to another tab or window, even if this is not user-initiated. This can cause a jarring user experience so should be disallowed.

Note that Firefox disables window.focus() when called from a page's onload handler.
Comment 1 Steve Block 2010-01-08 09:41:22 PST
The fix for this will require the ResourceRequest 'userGesture' flag being added in Bug 33381
Comment 2 Sam Weinig 2010-01-10 13:48:49 PST
(In reply to comment #1)
> The fix for this will require the ResourceRequest 'userGesture' flag being
> added in Bug 33381

Why is that?  Could't we just query whether a userGesture (ala popup detection) was taking place when calling window.focus()?
Comment 3 Jay Civelli 2010-08-16 14:14:19 PDT
Created attachment 64522 [details]
Attempt at a patch
Comment 4 Sam Weinig 2010-08-16 23:41:50 PDT
Comment on attachment 64522 [details]
Attempt at a patch

This needs tests. r-.
Comment 5 Jay Civelli 2010-08-17 00:22:14 PDT
I was not sure on how to simulate user gesture in a layout test. The
LayoutTestController does not seem to have anything to that effect.
Do you have any pointers?
Comment 6 Alexey Proskuryakov 2010-08-17 03:14:03 PDT
In most cases, one can simulate a user gesture with eventSender.

For this to go in, we'd need a more extensive research of compatibility issues. Per the description, the proposed behavior doesn't even match Firefox. Are we sure that focusing windows outside of a user gesture is never good?