Skip to content
  • jochen@chromium.org's avatar
    Match Firefox restrictions to window.blur and window.focus · 1c2dbfb5
    jochen@chromium.org authored
    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: http://svn.webkit.org/repository/webkit/trunk@118916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    1c2dbfb5