Match Firefox restrictions to window.blur and window.focus
authorjochen@chromium.org <jochen@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 May 2012 13:28:13 +0000 (13:28 +0000)
committerjochen@chromium.org <jochen@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 May 2012 13:28:13 +0000 (13:28 +0000)
commit2638b1f65805d0eac5aac2a31924d84940e7ceca
tree0478f35035371ec6ac19a1b2f3fe09d92ce76585
parent07625b52e6214252ed8ad6d79cd3481ccdb3ec0a
Match Firefox restrictions to window.blur and window.focus
https://bugs.webkit.org/show_bug.cgi?id=86969

Reviewed by Adam Barth.

Source/WebCore:

Disallow window.blur altogether, and only allow window.focus to be
invoked from the context that created this very window.

There's a new setting (windowFocusRestricted) that defaults to true. If
false, the new restrictions are lifted. This can be used by ports that
would prefer to stick with the old behavior.

For tests, this setting is accessible in window.internals.settings

To temporarily allow window.focus(), an object of type
WindowFocusAllowedIndicator can be created. It is currently used to
enable window.focus() during dispatch of the click event for
notifications.

Tests: fast/dom/Window/mozilla-focus-blur.html
       fast/notifications/notifications-click-event-focus.html

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* notifications/Notification.cpp:
(WebCore::Notification::dispatchClickEvent):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::focus):
(WebCore::DOMWindow::blur):
* page/DOMWindow.h:
(DOMWindow):
* page/DOMWindow.idl:
* page/Settings.cpp:
(WebCore::Settings::Settings):
* page/Settings.h:
(Settings):
(WebCore::Settings::setWindowFocusRestricted):
(WebCore::Settings::windowFocusRestricted):
* page/WindowFocusAllowedIndicator.cpp: Added.
(WebCore):
(WebCore::WindowFocusAllowedIndicator::windowFocusAllowed):
(WebCore::WindowFocusAllowedIndicator::WindowFocusAllowedIndicator):
(WebCore::WindowFocusAllowedIndicator::~WindowFocusAllowedIndicator):
* page/WindowFocusAllowedIndicator.h: Added.
(WebCore):
(WindowFocusAllowedIndicator):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::InternalSettings):
(WebCore::InternalSettings::restoreTo):
(WebCore::InternalSettings::setWindowFocusRestricted):
(WebCore):
* testing/InternalSettings.h:
(InternalSettings):
* testing/InternalSettings.idl:

Source/WebKit/chromium:

Allow window.focus() during the dispatch of the click event on
notifications.

* src/WebNotification.cpp:
(WebKit::WebNotification::dispatchClickEvent):

LayoutTests:

* fast/dom/HTMLDocument/hasFocus.html:
* fast/dom/Window/mozilla-focus-blur-expected.txt: Added.
* fast/dom/Window/mozilla-focus-blur.html: Added.
* fast/notifications/notifications-click-event-focus-expected.txt: Added.
* fast/notifications/notifications-click-event-focus.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
26 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLDocument/hasFocus.html
LayoutTests/fast/dom/Window/mozilla-focus-blur-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Window/mozilla-focus-blur.html [new file with mode: 0644]
LayoutTests/fast/notifications/notifications-click-event-focus-expected.txt [new file with mode: 0644]
LayoutTests/fast/notifications/notifications-click-event-focus.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/notifications/Notification.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DOMWindow.idl
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/page/WindowFocusAllowedIndicator.cpp [new file with mode: 0644]
Source/WebCore/page/WindowFocusAllowedIndicator.h [new file with mode: 0644]
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebNotification.cpp