<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>12469</bug_id>
          
          <creation_ts>2007-01-29 21:29:18 -0800</creation_ts>
          <short_desc>window.alert from onUnload listener does not show when users close the window</short_desc>
          <delta_ts>2008-07-09 11:59:41 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>419.x</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="George Zhu">george.zhu</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>george.zhu</cc>
    
    <cc>jchaffraix</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>30703</commentid>
    <comment_count>0</comment_count>
    <who name="George Zhu">george.zhu</who>
    <bug_when>2007-01-29 21:29:18 -0800</bug_when>
    <thetext>The window object has an event onUnload, the Mozilla document describe it as:
The unload event is raised when the document is unloaded.
It is true that now this event fires when the document reload, the same as Firefox and IE. (this was fixed in bug 3402)

But the event fail to fire when user close the window. It is well known that closing window also requires unloading of document, so it would be fine if Safari can also support this feature as it is already implemented in Firefox and IE.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30681</commentid>
    <comment_count>1</comment_count>
      <attachid>12774</attachid>
    <who name="George Zhu">george.zhu</who>
    <bug_when>2007-01-29 21:39:06 -0800</bug_when>
    <thetext>Created attachment 12774
Open the page directly and test.

Open the page directly and test.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71794</commentid>
    <comment_count>2</comment_count>
    <who name="Julien Chaffraix">jchaffraix</who>
    <bug_when>2008-02-24 16:00:46 -0800</bug_when>
    <thetext>&gt; But the event fail to fire when user close the window. It is well known that
&gt; closing window also requires unloading of document, so it would be fine if
&gt; Safari can also support this feature as it is already implemented in Firefox
&gt; and IE.

I have done some debugging and the event is dispatched when closing the window. The issue is that the listener try to call window.alert and fails in WebChromeClient::runJavaScriptAlert because the UIDelegate is null.
The cause is that Cocoa calls (void)setUIDelegate:delegate (in WebKit/mac/WebView/WebView.mm) to set it to null *before* sending the unload event.
My knowledge of the mac port is quite limited so I do not who to blame (Cocoa or WebKit)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71985</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-02-26 02:55:27 -0800</bug_when>
    <thetext>In my testing, -[WebView setUIDelegate:] is called from WebKit itself:

#0  -[WebView setUIDelegate:] (self=0x37ed4c0, _cmd=0x3e1ab6, delegate=0x0) at /Users/ap/Safari/OpenSource/WebKit/mac/WebView/WebView.mm:2091
#1  0x003949e6 in -[WebView(WebPrivate) _close] (self=0x37ed4c0, _cmd=0x926aa890) at /Users/ap/Safari/OpenSource/WebKit/mac/WebView/WebView.mm:703
...

I&apos;m not sure why this is classified as a major bug - what kind of important consequences does it have? Does showing an alert from onunload serve any purpose except for annoying the user?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72017</commentid>
    <comment_count>4</comment_count>
    <who name="Julien Chaffraix">jchaffraix</who>
    <bug_when>2008-02-26 09:29:03 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; In my testing, -[WebView setUIDelegate:] is called from WebKit itself:
&gt; 
&gt; #0  -[WebView setUIDelegate:] (self=0x37ed4c0, _cmd=0x3e1ab6, delegate=0x0) at
&gt; /Users/ap/Safari/OpenSource/WebKit/mac/WebView/WebView.mm:2091
&gt; #1  0x003949e6 in -[WebView(WebPrivate) _close] (self=0x37ed4c0,
&gt; _cmd=0x926aa890) at
&gt; /Users/ap/Safari/OpenSource/WebKit/mac/WebView/WebView.mm:703
&gt; ...
&gt; 

Odd, I have another call to setUIDelegate before the one you mention on my machine which originate from Cocoa :

#0  -[WebView setUIDelegate:] (self=0x2554c10, _cmd=0x3e13f8, delegate=0x0) at /Users/julien/Webkit/WebKit/WebKit/mac/WebView/WebView.mm:2093
#1  0x00049d21 in ?? ()
#2  0x925f3059 in -[NSArray makeObjectsPerformSelector:withObject:] ()
#3  0x925f3059 in -[NSArray makeObjectsPerformSelector:withObject:] ()
#4  0x92603d2d in -[NSArray makeObjectsPerformSelector:] ()
(...)

Beside the one you are pointing at is executed after the unload listener : in WebView _close, the unload event is dispatched in mainLoader-&gt;detachFromParent() and setUIDelegate is called afterwards.

&gt; I&apos;m not sure why this is classified as a major bug - what kind of important
&gt; consequences does it have? Does showing an alert from onunload serve any
&gt; purpose except for annoying the user?
&gt; 

Updated the summary and the severity as the original bug was that we were not dispatching an unload event when closing the window (which is major).

I agree with you about how annoying alert from onunload listener can be but Firefox and Opera have chosen to display those so it is believed we should do the same.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82060</commentid>
    <comment_count>5</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2008-06-01 08:50:48 -0700</bug_when>
    <thetext>See Bug 18341.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85561</commentid>
    <comment_count>6</comment_count>
    <who name="Vicki Murley">vicki</who>
    <bug_when>2008-07-09 11:59:41 -0700</bug_when>
    <thetext>I can&apos;t reproduce this anymore, using WebKit nightly r34367.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>12774</attachid>
            <date>2007-01-29 21:39:06 -0800</date>
            <delta_ts>2007-01-29 21:39:06 -0800</delta_ts>
            <desc>Open the page directly and test.</desc>
            <filename>OnUnload.htm</filename>
            <type>text/html</type>
            <size>717</size>
            <attacher name="George Zhu">george.zhu</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBYSFRNTCAxLjAgVHJhbnNpdGlvbmFs
Ly9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSL3hodG1sMS9EVEQveGh0bWwxLXRyYW5zaXRpb25h
bC5kdGQiPg0KPGh0bWwgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGh0bWwiID4NCjxo
ZWFkPg0KICAgIDx0aXRsZT5VbnRpdGxlZCBQYWdlPC90aXRsZT4NCiAgICA8c2NyaXB0IHR5cGUg
PSJ0ZXh0L2phdmFzY3JpcHQiID4NCiAgICBmdW5jdGlvbiBPblVubG9hZCgpDQogICAgew0KCQlh
bGVydCgnb25VbmxvYWQgZXZlbnQgaXMgZmlyZWQhJyk7DQogICAgfQ0KICAgIDwvc2NyaXB0Pg0K
PC9oZWFkPg0KPGJvZHkgb251bmxvYWQgPSJqYXZhc2NyaXB0Ok9uVW5sb2FkKCk7Ij4NCgk8c3Bh
biBzdHlsZT0iZm9udC1zaXplOiAxNHB0Ij5UbyB0ZXN0IHRoZSBvblVubG9hZCBldmVudCwgcGxl
YXNlIGNsb3NlIHRoZSB3aW5kb3cuDQoJCUlmIHlvdSBnZXQgYSBtZXNzYWdlIGJveCwgaXQgbWVh
bnMgb25VbmxvYWQgZXZlbnQgaXMgZmlyZWQuDQoJCTxiciAvPg0KCQk8YnIgLz4NCgkJSW4gU2Fm
YXJpLCB5b3Ugd2lsbCBmaW5kIG5vdGhpbmcgaGFwcGVuZWQgYWZ0ZXIgeW91IGNsb3NlIHRoZSB3
aW5kb3csIHdoaWxlIGluIEZpcmVmb3gNCgkJYW5kIElFLCBhIG1lc3NhZ2UgYm94IHdpbGwgcHJv
bXB0Ljwvc3Bhbj4NCg0KPC9ib2R5Pg0KPC9odG1sPg0K
</data>

          </attachment>
      

    </bug>

</bugzilla>