Reviewed by John.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 May 2005 17:44:19 +0000 (17:44 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 May 2005 17:44:19 +0000 (17:44 +0000)
- fixed <rdar://problem/3598589> onunload handler doesn't fire when a window is closed

        Test cases added:
        * layout-tests/fast/events/onunload-expected.txt: Added.
        * layout-tests/fast/events/onunload.html: Added.

        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::detach): Don't remove all event handlers from the document here...
        * khtml/khtml_part.cpp:
        (KHTMLPart::closeURL): ...instead do it here, after firing the unload event, but only
if the document is not in the back/forward cache...
        * kwq/KWQPageState.mm:
        (-[KWQPageState finalize]): ...and take care of the back/forward cache case here.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9200 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/fast/events/onunload-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/onunload.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/khtml_part.cpp
WebCore/khtml/xml/dom_docimpl.cpp
WebCore/kwq/KWQPageState.mm

diff --git a/LayoutTests/fast/events/onunload-expected.txt b/LayoutTests/fast/events/onunload-expected.txt
new file mode 100644 (file)
index 0000000..16f486d
--- /dev/null
@@ -0,0 +1,15 @@
+ALERT: unload
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x34
+  RenderBlock {HTML} at (0,0) size 800x34
+    RenderBody {BODY} at (8,8) size 784x18
+      RenderText {TEXT} at (0,0) size 287x18
+        text run at (0,0) width 287: "You should have seen an unload alert appear."
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x34
+  RenderBlock {HTML} at (0,0) size 800x34
+    RenderBody {BODY} at (8,8) size 784x18
+      RenderText {TEXT} at (0,0) size 287x18
+        text run at (0,0) width 287: "You should have seen an unload alert appear."
diff --git a/LayoutTests/fast/events/onunload.html b/LayoutTests/fast/events/onunload.html
new file mode 100644 (file)
index 0000000..8822078
--- /dev/null
@@ -0,0 +1,19 @@
+<html>
+<body onunload="unload()" onload="load()">
+<script>
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+function load()
+{
+    location = "data:text/html,You should have seen an unload alert appear.<script>if (window.layoutTestController) layoutTestController.notifyDone(); </" + "script>";
+}
+
+function unload()
+{
+    alert("unload");
+}
+</script>
+start document
+</body>
+</html>
index 6c67b17cd3e6dce301c994a246f71fa42886414e..53dbb395e3c77b3b6946e5f7a4d15cf72be98b62 100644 (file)
@@ -1,3 +1,21 @@
+2005-05-24  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by John.
+
+       - fixed <rdar://problem/3598589> onunload handler doesn't fire when a window is closed
+
+        Test cases added: 
+        * layout-tests/fast/events/onunload-expected.txt: Added.
+        * layout-tests/fast/events/onunload.html: Added.
+
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::detach): Don't remove all event handlers from the document here...
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::closeURL): ...instead do it here, after firing the unload event, but only
+       if the document is not in the back/forward cache...
+        * kwq/KWQPageState.mm:
+        (-[KWQPageState finalize]): ...and take care of the back/forward cache case here.
+
 2005-05-24  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Kevin.
index de2f5964150a74df54b2b70b14c83f3f35e2d1c5..edcb507e7297d8373e840312f69d81aa6d218a9a 100644 (file)
@@ -608,6 +608,9 @@ bool KHTMLPart::closeURL()
       d->m_bUnloadEventEmitted = true;
     }
   }
+
+  if (d->m_doc && !d->m_doc->inPageCache())
+    d->m_doc->removeAllEventListenersFromAllNodes();
     
   d->m_bComplete = true; // to avoid emitting completed() in slotFinishedParsing() (David)
   d->m_bLoadingMainResource = false;
index 9a2483add847c230ab8633b0a86f8dff2dcdb1da..345c85c9c321d43eaf894f77ea58496c319a79cd 100644 (file)
@@ -1241,10 +1241,6 @@ void DocumentImpl::detach()
     m_imageLoadEventDispatchSoonList.clear();
     m_imageLoadEventDispatchingList.clear();
     
-    
-    // FIXME: UNLOAD_EVENT will not dispatch due to deleting event listeners prior to closeURL(). 
-    removeAllEventListenersFromAllNodes();
-
     ContainerNodeImpl::detach();
 
     if ( render )
index e7548e243b8c61cf4aeb407663618c57cdc8bcd0..110cd5bd9616edb40196a0cb63c14e4c9acace65 100644 (file)
@@ -134,6 +134,7 @@ using KJS::SavedBuiltins;
         document->setInPageCache(NO);
         if (detached) {
             document->detach();
+            document->removeAllEventListenersFromAllNodes();
         }
         document->deref();
         
@@ -169,6 +170,7 @@ using KJS::SavedBuiltins;
         document->setInPageCache(NO);
         if (detached) {
             document->detach();
+            document->removeAllEventListenersFromAllNodes();
         }
         document->deref();