Skip to content
  • ch.dumez@sisa.samsung.com's avatar
    Add support for BeforeUnloadEvent interface · 231386f4
    ch.dumez@sisa.samsung.com authored
    https://bugs.webkit.org/show_bug.cgi?id=120849
    
    Reviewed by Darin Adler.
    
    Source/WebCore:
    
    Add support for BeforeUnloadEvent as per the specification:
    http://www.whatwg.org/specs/web-apps/current-work/#beforeunloadevent
    
    BeforeUnloadEvent has a returnValue attribute. Setting returnValue to a non-empty
    string in an event handler causes the user agent should ask the user to confirm
    that they wish to unload the document. This is equivalent to returning a non-empty
    string in the EventHandler:
    http://www.whatwg.org/specs/web-apps/current-work/#onbeforeunloadeventhandler
    
    BeforeUnloadEvent and returnValue are already supported by IE and Firefox. Previously,
    WebKit was passing a base Event type to the beforeunload event handlers instead of
    a BeforeUnloadEvent.
    
    Note that this patch keeps support for the legacy Event.returnValue attribute. This used
    to be an IE extension but this is no longer supported by IE (nor Firefox). The standard
    preventDefault() should be used instead however (supported in IE >= 9).
    
    Test: fast/events/before-unload-returnValue.html
    
    * CMakeLists.txt:
    * DerivedSources.cpp:
    * DerivedSources.make:
    * DerivedSources.pri:
    * GNUmakefile.list.am:
    * WebCore.order:
    * WebCore.vcxproj/WebCore.vcxproj:
    * bindings/js/JSEventListener.cpp:
    (WebCore::JSEventListener::handleEvent):
    * dom/BeforeUnloadEvent.cpp:
    (WebCore::BeforeUnloadEvent::isBeforeUnloadEvent):
    (WebCore::BeforeUnloadEvent::~BeforeUnloadEvent):
    * dom/BeforeUnloadEvent.h:
    (WebCore::BeforeUnloadEvent::create):
    (WebCore::BeforeUnloadEvent::returnValue):
    (WebCore::BeforeUnloadEvent::setReturnValue):
    (WebCore::toBeforeUnloadEvent):
    * dom/BeforeUnloadEvent.idl: Added.
    * dom/Event.cpp:
    (WebCore::Event::isBeforeUnloadEvent):
    * dom/Event.h:
    (WebCore::Event::legacyReturnValue):
    (WebCore::Event::setLegacyReturnValue):
    * dom/Event.idl:
    * dom/EventNames.in:
    * loader/FrameLoader.cpp:
    (WebCore::FrameLoader::handleBeforeUnloadEvent):
    
    LayoutTests:
    
    Add layout test for validate support for the BeforeUnloadEvent.
    Also rebaseline fast/js/global-constructors-attributes.html as
    BeforeUnloadEvent is now exposed on the global Window object.
    
    * fast/events/before-unload-returnValue-expected.txt: Added.
    * fast/events/before-unload-returnValue.html: Added.
    * fast/js/global-constructors-attributes-expected.txt:
    * platform/efl/fast/js/global-constructors-attributes-expected.txt:
    * platform/gtk/fast/js/global-constructors-attributes-expected.txt:
    * platform/mac-lion/fast/js/global-constructors-attributes-expected.txt:
    * platform/qt/fast/js/global-constructors-attributes-expected.txt:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155367 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    231386f4