Add support for BeforeUnloadEvent interface
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
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 116ebbc..b7cb78b 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,22 @@
+2013-09-09  Christophe Dumez  <ch.dumez@sisa.samsung.com>
+
+        Add support for BeforeUnloadEvent interface
+        https://bugs.webkit.org/show_bug.cgi?id=120849
+
+        Reviewed by Darin Adler.
+
+        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:
+
 2013-09-09  ChangSeok Oh  <changseok.oh@collabora.com>
 
         [WK2] Assertion failure in WebCore::Page::checkSubframeCountConsistency when going back
diff --git a/LayoutTests/fast/events/before-unload-returnValue-expected.txt b/LayoutTests/fast/events/before-unload-returnValue-expected.txt
new file mode 100644
index 0000000..6dd0a55
--- /dev/null
+++ b/LayoutTests/fast/events/before-unload-returnValue-expected.txt
@@ -0,0 +1,13 @@
+CONFIRM NAVIGATION: This is beforeunload from the top level frame.
+Tests the returnValue attribute of the BeforeUnloadEvent.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testEvent.__proto__ is testIframe.contentWindow.BeforeUnloadEvent.prototype
+PASS testEvent.returnValue is ""
+PASS testEvent.returnValue is "This is beforeunload from the top level frame."
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/before-unload-returnValue.html b/LayoutTests/fast/events/before-unload-returnValue.html
new file mode 100644
index 0000000..786cda8
--- /dev/null
+++ b/LayoutTests/fast/events/before-unload-returnValue.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+<script>
+if (window.testRunner)
+    testRunner.setShouldStayOnPageAfterHandlingBeforeUnload(true);
+
+function test(iframe) {
+    iframe.contentWindow.location.href = "resources/does-not-exist.html";
+}
+
+</script>
+</head>
+<body>
+<iframe id="testIframe" onload="test(this)" src="resources/onclick.html"></iframe>
+<script>
+description("Tests the returnValue attribute of the BeforeUnloadEvent.");
+self.jsTestIsAsync = true;
+
+var testIframe = document.getElementById("testIframe");
+
+var testEvent;
+testIframe.contentWindow.onbeforeunload = function(event) {
+    if (testIframe.done) {
+        finishJSTest();
+        return;
+    }
+    testIframe.done = true;
+    testEvent = event;
+    shouldBe("testEvent.__proto__", "testIframe.contentWindow.BeforeUnloadEvent.prototype");
+    shouldBeEqualToString("testEvent.returnValue", "");
+    event.returnValue = "This is beforeunload from the top level frame.";
+    shouldBeEqualToString("testEvent.returnValue", "This is beforeunload from the top level frame.");
+
+    setTimeout(function() {
+        if (window.testRunner)
+            testRunner.setShouldStayOnPageAfterHandlingBeforeUnload(false);
+        testIframe.contentWindow.location.href = "resources/does-not-exist.html";
+    }, 0);
+}
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/fast/js/global-constructors-attributes-expected.txt b/LayoutTests/fast/js/global-constructors-attributes-expected.txt
index fd18b60..b0971bf 100644
--- a/LayoutTests/fast/js/global-constructors-attributes-expected.txt
+++ b/LayoutTests/fast/js/global-constructors-attributes-expected.txt
@@ -63,6 +63,11 @@
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').value is BeforeUnloadEvent
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').value is BiquadFilterNode
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('set') is false
diff --git a/LayoutTests/platform/efl/fast/js/global-constructors-attributes-expected.txt b/LayoutTests/platform/efl/fast/js/global-constructors-attributes-expected.txt
index 5c892d6..3d00a2f 100644
--- a/LayoutTests/platform/efl/fast/js/global-constructors-attributes-expected.txt
+++ b/LayoutTests/platform/efl/fast/js/global-constructors-attributes-expected.txt
@@ -73,6 +73,11 @@
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').value is BeforeUnloadEvent
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').value is BiquadFilterNode
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('set') is false
diff --git a/LayoutTests/platform/gtk/fast/js/global-constructors-attributes-expected.txt b/LayoutTests/platform/gtk/fast/js/global-constructors-attributes-expected.txt
index 874b5e1..1c26946 100644
--- a/LayoutTests/platform/gtk/fast/js/global-constructors-attributes-expected.txt
+++ b/LayoutTests/platform/gtk/fast/js/global-constructors-attributes-expected.txt
@@ -63,6 +63,11 @@
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').value is BeforeUnloadEvent
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').value is BiquadFilterNode
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('set') is false
diff --git a/LayoutTests/platform/mac-lion/fast/js/global-constructors-attributes-expected.txt b/LayoutTests/platform/mac-lion/fast/js/global-constructors-attributes-expected.txt
index 2a01d2f..0f54aa9 100644
--- a/LayoutTests/platform/mac-lion/fast/js/global-constructors-attributes-expected.txt
+++ b/LayoutTests/platform/mac-lion/fast/js/global-constructors-attributes-expected.txt
@@ -63,6 +63,11 @@
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').value is BeforeUnloadEvent
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').value is BiquadFilterNode
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BiquadFilterNode').hasOwnProperty('set') is false
diff --git a/LayoutTests/platform/qt/fast/js/global-constructors-attributes-expected.txt b/LayoutTests/platform/qt/fast/js/global-constructors-attributes-expected.txt
index ff1cec3..bd59963 100644
--- a/LayoutTests/platform/qt/fast/js/global-constructors-attributes-expected.txt
+++ b/LayoutTests/platform/qt/fast/js/global-constructors-attributes-expected.txt
@@ -23,6 +23,11 @@
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'BeforeLoadEvent').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').value is BeforeUnloadEvent
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'BeforeUnloadEvent').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'Blob').value is Blob
 PASS Object.getOwnPropertyDescriptor(global, 'Blob').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Blob').hasOwnProperty('set') is false
diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt
index e6b6789..3efda65 100644
--- a/Source/WebCore/CMakeLists.txt
+++ b/Source/WebCore/CMakeLists.txt
@@ -335,6 +335,7 @@
 
     dom/Attr.idl
     dom/BeforeLoadEvent.idl
+    dom/BeforeUnloadEvent.idl
     dom/CDATASection.idl
     dom/CharacterData.idl
     dom/ChildNode.idl
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 04d7520..ba5b09f 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,57 @@
+2013-09-09  Christophe Dumez  <ch.dumez@sisa.samsung.com>
+
+        Add support for BeforeUnloadEvent interface
+        https://bugs.webkit.org/show_bug.cgi?id=120849
+
+        Reviewed by Darin Adler.
+
+        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):
+
 2013-09-06  David Hyatt  <hyatt@apple.com>
 
         Get rid of isBlockFlowFlexBoxOrGrid().
diff --git a/Source/WebCore/DerivedSources.cpp b/Source/WebCore/DerivedSources.cpp
index bdcef5c..01f7429 100644
--- a/Source/WebCore/DerivedSources.cpp
+++ b/Source/WebCore/DerivedSources.cpp
@@ -31,6 +31,7 @@
 #include "JSAttr.cpp"
 #include "JSBarProp.cpp"
 #include "JSBeforeLoadEvent.cpp"
+#include "JSBeforeUnloadEvent.cpp"
 #include "JSBlob.cpp"
 #include "JSCanvasGradient.cpp"
 #include "JSCanvasPattern.cpp"
diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make
index 877fced..ab5eee6 100644
--- a/Source/WebCore/DerivedSources.make
+++ b/Source/WebCore/DerivedSources.make
@@ -240,6 +240,7 @@
     $(WebCore)/css/WebKitCSSViewportRule.idl \
     $(WebCore)/dom/Attr.idl \
     $(WebCore)/dom/BeforeLoadEvent.idl \
+    $(WebCore)/dom/BeforeUnloadEvent.idl \
     $(WebCore)/dom/CDATASection.idl \
     $(WebCore)/dom/CharacterData.idl \
     $(WebCore)/dom/ChildNode.idl \
diff --git a/Source/WebCore/DerivedSources.pri b/Source/WebCore/DerivedSources.pri
index 67344dc..0340bff 100644
--- a/Source/WebCore/DerivedSources.pri
+++ b/Source/WebCore/DerivedSources.pri
@@ -226,6 +226,7 @@
     $$PWD/css/WebKitCSSViewportRule.idl \
     $$PWD/dom/Attr.idl \
     $$PWD/dom/BeforeLoadEvent.idl \
+    $$PWD/dom/BeforeUnloadEvent.idl \
     $$PWD/dom/CharacterData.idl \
     $$PWD/dom/ChildNode.idl \
     $$PWD/dom/ClientRect.idl \
diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am
index 0171493..505284a 100644
--- a/Source/WebCore/GNUmakefile.list.am
+++ b/Source/WebCore/GNUmakefile.list.am
@@ -69,6 +69,8 @@
 	DerivedSources/WebCore/JSBatteryManager.h \
 	DerivedSources/WebCore/JSBeforeLoadEvent.cpp \
 	DerivedSources/WebCore/JSBeforeLoadEvent.h \
+	DerivedSources/WebCore/JSBeforeUnloadEvent.cpp \
+	DerivedSources/WebCore/JSBeforeUnloadEvent.h \
 	DerivedSources/WebCore/JSBiquadFilterNode.cpp \
 	DerivedSources/WebCore/JSBiquadFilterNode.h \
 	DerivedSources/WebCore/JSBlob.cpp \
@@ -1358,6 +1360,7 @@
 	$(WebCore)/css/WebKitCSSViewportRule.idl \
 	$(WebCore)/dom/Attr.idl \
 	$(WebCore)/dom/BeforeLoadEvent.idl \
+	$(WebCore)/dom/BeforeUnloadEvent.idl \
 	$(WebCore)/dom/CDATASection.idl \
 	$(WebCore)/dom/CharacterData.idl \
 	$(WebCore)/dom/ChildNode.idl \
diff --git a/Source/WebCore/WebCore.order b/Source/WebCore/WebCore.order
index 0ad6e7d..8e5e052 100644
--- a/Source/WebCore/WebCore.order
+++ b/Source/WebCore/WebCore.order
@@ -3069,6 +3069,11 @@
 __ZN7WebCore11FrameLoader23handleBeforeUnloadEventERNS_6ChromeEPS0_
 __ZN7WebCore17BeforeUnloadEventC1Ev
 __ZN7WebCore17BeforeUnloadEventC2Ev
+__ZN7WebCore19JSBeforeUnloadEvent15createPrototypeEPN3JSC9ExecStateEPNS1_14JSGlobalObjectE
+__ZN7WebCore19JSBeforeUnloadEvent6s_infoE
+__ZN7WebCore19JSBeforeUnloadEventC1EPN3JSC9StructureEPNS_17JSDOMGlobalObjectEN3WTF10PassRefPtrINS_17BeforeUnloadEventEEE
+__ZN7WebCore19JSBeforeUnloadEvent14finishCreationERN3JSC2VME
+__ZN7WebCore19JSBeforeUnloadEvent14getConstructorEPN3JSC9ExecStateEPNS1_14JSGlobalObjectE
 __ZN7WebCore5EventC2ERKN3WTF12AtomicStringEbb
 __ZN7WebCore4Page44incrementFrameHandlingBeforeUnloadEventCountEv
 __ZNK7WebCore9DOMWindow8documentEv
@@ -9812,7 +9817,6 @@
 __ZN7WebCore17JSHTMLMetaElementC1EPN3JSC9StructureEPNS_17JSDOMGlobalObjectEN3WTF10PassRefPtrINS_15HTMLMetaElementEEE
 __ZN7WebCore17JSHTMLMetaElement14finishCreationERN3JSC2VME
 __ZN7WebCore12cacheWrapperINS_15HTMLMetaElementEEEvPNS_15DOMWrapperWorldEPT_PNS_12JSDOMWrapperE
-__ZNK7WebCore5Event20storesResultAsStringEv
 __ZN3WTF6VectorIN7WebCore13PendingScriptELm0ENS_15CrashOnOverflowEE6removeEmm
 __ZN7WebCore14RenderReplaced15willBeDestroyedEv
 __ZN7WebCore16RenderHTMLCanvasD0Ev
diff --git a/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj b/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
index 589b423..b114ff30 100644
--- a/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
+++ b/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
@@ -785,6 +785,20 @@
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     </ClCompile>
+    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBeforeUnloadEvent.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBlob.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -18286,6 +18300,7 @@
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSAttr.h" />
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBarProp.h" />
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBeforeLoadEvent.h" />
+    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBeforeUnloadEvent.h" />
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBlob.h" />
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSCanvasGradient.h" />
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSCanvasPattern.h" />
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index ceda381..483b1ba 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -4955,6 +4955,8 @@
 		BC946348107A936600857193 /* JSBeforeLoadEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = BC946347107A936600857193 /* JSBeforeLoadEvent.h */; };
 		BC946EEF107FDBAC00857193 /* DOMBeforeLoadEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = BC946EED107FDBAC00857193 /* DOMBeforeLoadEvent.h */; };
 		BC946EF0107FDBAC00857193 /* DOMBeforeLoadEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC946EEE107FDBAC00857193 /* DOMBeforeLoadEvent.mm */; };
+		70F546E8B8B5D7DC54EE144E /* JSBeforeUnloadEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8225432CA9D4B4CF4628EC7F /* JSBeforeUnloadEvent.cpp */; };
+		6FA4454E898F2FC168BC38C1 /* JSBeforeUnloadEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E04A27BED2F81F98E9022B /* JSBeforeUnloadEvent.h */; };
 		BC94D1080C274F88006BC617 /* PlatformScreenMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */; };
 		BC94D14E0C275C68006BC617 /* JSHistory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC94D14C0C275C68006BC617 /* JSHistory.cpp */; };
 		BC94D14F0C275C68006BC617 /* JSHistory.h in Headers */ = {isa = PBXBuildFile; fileRef = BC94D14D0C275C68006BC617 /* JSHistory.h */; };
@@ -11778,6 +11780,8 @@
 		BC946347107A936600857193 /* JSBeforeLoadEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBeforeLoadEvent.h; sourceTree = "<group>"; };
 		BC946EED107FDBAC00857193 /* DOMBeforeLoadEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMBeforeLoadEvent.h; sourceTree = "<group>"; };
 		BC946EEE107FDBAC00857193 /* DOMBeforeLoadEvent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMBeforeLoadEvent.mm; sourceTree = "<group>"; };
+		8225432CA9D4B4CF4628EC7F /* JSBeforeUnloadEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSBeforeUnloadEvent.cpp; sourceTree = "<group>"; };
+		29E04A27BED2F81F98E9022B /* JSBeforeUnloadEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBeforeUnloadEvent.h; sourceTree = "<group>"; };
 		BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformScreenMac.mm; sourceTree = "<group>"; };
 		BC94D14C0C275C68006BC617 /* JSHistory.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHistory.cpp; sourceTree = "<group>"; };
 		BC94D14D0C275C68006BC617 /* JSHistory.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHistory.h; sourceTree = "<group>"; };
@@ -17794,6 +17798,8 @@
 			children = (
 				BC946345107A934B00857193 /* JSBeforeLoadEvent.cpp */,
 				BC946347107A936600857193 /* JSBeforeLoadEvent.h */,
+				8225432CA9D4B4CF4628EC7F /* JSBeforeUnloadEvent.cpp */,
+				29E04A27BED2F81F98E9022B /* JSBeforeUnloadEvent.h */,
 				79AC9216109945C80021266E /* JSCompositionEvent.cpp */,
 				79AC9217109945C80021266E /* JSCompositionEvent.h */,
 				E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */,
@@ -22695,6 +22701,7 @@
 				BE8EF045171C8FF9009B48C3 /* JSAudioTrackList.h in Headers */,
 				BC124F000C26447A009E2349 /* JSBarProp.h in Headers */,
 				BC946348107A936600857193 /* JSBeforeLoadEvent.h in Headers */,
+				6FA4454E898F2FC168BC38C1 /* JSBeforeUnloadEvent.h in Headers */,
 				FDF09DC91399B62200688E5B /* JSBiquadFilterNode.h in Headers */,
 				2E2D99CE10E2BBDA00496337 /* JSBlob.h in Headers */,
 				1449E24C107D4A8400B5793F /* JSCallbackData.h in Headers */,
@@ -25898,6 +25905,7 @@
 				BE6DF713171CA2DA00DD52B8 /* JSAudioTrackListCustom.cpp in Sources */,
 				BC124EFF0C26447A009E2349 /* JSBarProp.cpp in Sources */,
 				BC946346107A934B00857193 /* JSBeforeLoadEvent.cpp in Sources */,
+				70F546E8B8B5D7DC54EE144E /* JSBeforeUnloadEvent.cpp in Sources */,
 				FDF09DC81399B62200688E5B /* JSBiquadFilterNode.cpp in Sources */,
 				FD8AA63C1695148E00D2EA68 /* JSBiquadFilterNodeCustom.cpp in Sources */,
 				2E2D99CD10E2BBDA00496337 /* JSBlob.cpp in Sources */,
diff --git a/Source/WebCore/bindings/js/JSEventListener.cpp b/Source/WebCore/bindings/js/JSEventListener.cpp
index 3935442..6bdc27e 100644
--- a/Source/WebCore/bindings/js/JSEventListener.cpp
+++ b/Source/WebCore/bindings/js/JSEventListener.cpp
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "JSEventListener.h"
 
+#include "BeforeUnloadEvent.h"
 #include "Event.h"
 #include "Frame.h"
 #include "InspectorCounters.h"
@@ -147,8 +148,8 @@
             event->target()->uncaughtExceptionInEventHandler();
             reportCurrentException(exec);
         } else {
-            if (!retval.isUndefinedOrNull() && event->storesResultAsString())
-                event->storeResult(retval.toString(exec)->value(exec));
+            if (!retval.isUndefinedOrNull() && event->isBeforeUnloadEvent())
+                toBeforeUnloadEvent(event)->setReturnValue(retval.toString(exec)->value(exec));
             if (m_isAttribute) {
                 if (retval.isFalse())
                     event->preventDefault();
diff --git a/Source/WebCore/dom/BeforeUnloadEvent.cpp b/Source/WebCore/dom/BeforeUnloadEvent.cpp
index 19adcab..d0a9996 100644
--- a/Source/WebCore/dom/BeforeUnloadEvent.cpp
+++ b/Source/WebCore/dom/BeforeUnloadEvent.cpp
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
  * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
@@ -32,18 +32,13 @@
 {
 }
 
-BeforeUnloadEvent::~BeforeUnloadEvent()
-{
-}
-
-bool BeforeUnloadEvent::storesResultAsString() const
+bool BeforeUnloadEvent::isBeforeUnloadEvent() const
 {
     return true;
 }
 
-void BeforeUnloadEvent::storeResult(const String& s)
+BeforeUnloadEvent::~BeforeUnloadEvent()
 {
-    m_result = s;
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/dom/BeforeUnloadEvent.h b/Source/WebCore/dom/BeforeUnloadEvent.h
index 136e85c..cb50227 100644
--- a/Source/WebCore/dom/BeforeUnloadEvent.h
+++ b/Source/WebCore/dom/BeforeUnloadEvent.h
@@ -3,6 +3,7 @@
  * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
  * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2013 Samsung Electronics
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -28,25 +29,33 @@
 
 namespace WebCore {
 
-    class BeforeUnloadEvent : public Event {
-    public:
-        virtual ~BeforeUnloadEvent();
+class BeforeUnloadEvent FINAL : public Event {
+public:
+    virtual ~BeforeUnloadEvent();
 
-        static PassRefPtr<BeforeUnloadEvent> create()
-        {
-            return adoptRef(new BeforeUnloadEvent);
-        }
+    static PassRefPtr<BeforeUnloadEvent> create()
+    {
+        return adoptRef(new BeforeUnloadEvent);
+    }
 
-        virtual bool storesResultAsString() const;
-        virtual void storeResult(const String&);
+    String returnValue() const { return m_returnValue; }
+    void setReturnValue(const String& returnValue) { m_returnValue = returnValue; }
 
-        String result() const { return m_result; }
+    virtual const AtomicString& interfaceName() const OVERRIDE { return eventNames().interfaceForBeforeUnloadEvent; }
 
-    private:
-        BeforeUnloadEvent();
+private:
+    BeforeUnloadEvent();
 
-        String m_result;
-    };
+    virtual bool isBeforeUnloadEvent() const OVERRIDE;
+
+    String m_returnValue;
+};
+
+inline BeforeUnloadEvent* toBeforeUnloadEvent(Event* event)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!event || event->isBeforeUnloadEvent());
+    return static_cast<BeforeUnloadEvent*>(event);
+}
 
 } // namespace WebCore
 
diff --git a/Source/WebCore/dom/BeforeUnloadEvent.idl b/Source/WebCore/dom/BeforeUnloadEvent.idl
new file mode 100644
index 0000000..3e962ef
--- /dev/null
+++ b/Source/WebCore/dom/BeforeUnloadEvent.idl
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+interface BeforeUnloadEvent : Event {
+    attribute DOMString returnValue;
+};
diff --git a/Source/WebCore/dom/Event.cpp b/Source/WebCore/dom/Event.cpp
index 7435bad..75725ea 100644
--- a/Source/WebCore/dom/Event.cpp
+++ b/Source/WebCore/dom/Event.cpp
@@ -166,18 +166,14 @@
     return false;
 }
 
-bool Event::storesResultAsString() const
-{
-    return false;
-}
-
 bool Event::isBeforeTextInsertedEvent() const
 {
     return false;
 }
 
-void Event::storeResult(const String&)
+bool Event::isBeforeUnloadEvent() const
 {
+    return false;
 }
 
 PassRefPtr<Event> Event::cloneFor(HTMLIFrameElement*) const
diff --git a/Source/WebCore/dom/Event.h b/Source/WebCore/dom/Event.h
index 0beab13..7006cd9 100644
--- a/Source/WebCore/dom/Event.h
+++ b/Source/WebCore/dom/Event.h
@@ -115,8 +115,8 @@
     // IE Extensions
     EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
 
-    bool returnValue() const { return !defaultPrevented(); }
-    void setReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
+    bool legacyReturnValue() const { return !defaultPrevented(); }
+    void setLegacyReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
 
     Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; }
 
@@ -137,6 +137,8 @@
     virtual bool isClipboardEvent() const;
     virtual bool isBeforeTextInsertedEvent() const;
 
+    virtual bool isBeforeUnloadEvent() const;
+
     bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; }
     bool immediatePropagationStopped() const { return m_immediatePropagationStopped; }
 
@@ -157,9 +159,6 @@
     Event* underlyingEvent() const { return m_underlyingEvent.get(); }
     void setUnderlyingEvent(PassRefPtr<Event>);
 
-    virtual bool storesResultAsString() const;
-    virtual void storeResult(const String&);
-
     virtual Clipboard* clipboard() const { return 0; }
 
     bool isBeingDispatched() const { return eventPhase(); }
diff --git a/Source/WebCore/dom/Event.idl b/Source/WebCore/dom/Event.idl
index eea0514..bfb221e 100644
--- a/Source/WebCore/dom/Event.idl
+++ b/Source/WebCore/dom/Event.idl
@@ -72,7 +72,7 @@
 
     // IE Extensions
     readonly attribute EventTarget      srcElement;
-             attribute boolean          returnValue;
+    [ImplementedAs=legacyReturnValue] attribute boolean returnValue;
              attribute boolean          cancelBubble;
 
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
diff --git a/Source/WebCore/dom/EventNames.in b/Source/WebCore/dom/EventNames.in
index feb36ff..398e042 100644
--- a/Source/WebCore/dom/EventNames.in
+++ b/Source/WebCore/dom/EventNames.in
@@ -4,6 +4,7 @@
 Events interfaceName=Event
 HTMLEvents interfaceName=Event
 BeforeLoadEvent
+BeforeUnloadEvent
 CloseEvent
 CompositionEvent
 CustomEvent
diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp
index 7d15668..129d1b0 100644
--- a/Source/WebCore/loader/FrameLoader.cpp
+++ b/Source/WebCore/loader/FrameLoader.cpp
@@ -2774,7 +2774,7 @@
 
     if (!beforeUnloadEvent->defaultPrevented())
         document->defaultEventHandler(beforeUnloadEvent.get());
-    if (beforeUnloadEvent->result().isNull())
+    if (beforeUnloadEvent->returnValue().isNull())
         return true;
 
     // If the navigating FrameLoader has already shown a beforeunload confirmation panel for the current navigation attempt,
@@ -2810,7 +2810,7 @@
 
     frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel = true;
 
-    String text = document->displayStringModifiedByEncoding(beforeUnloadEvent->result());
+    String text = document->displayStringModifiedByEncoding(beforeUnloadEvent->returnValue());
     return chrome.runBeforeUnloadConfirmPanel(text, &m_frame);
 }