<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[20039] trunk/WebKit</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/20039">20039</a></dd>
<dt>Author</dt> <dd>andersca</dd>
<dt>Date</dt> <dd>2007-03-07 17:09:50 -0800 (Wed, 07 Mar 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>        Reviewed by Maciej.

        &lt;rdar://problem/4961259&gt; 
        REGRESSION: Bumper Car 2.1.1 - Crash at WebCore::FrameLoader::receivedMainResourceError when encountering a invalid URL address
        
        (The crash was already fixed, this actually makes Bumper Car load the error page correctly.)
        
        This adds a &quot;load counter&quot; to the document loader and keeps the data source retained for as long as something is loading. 
        
        * WebCoreSupport/WebFrameLoaderClient.mm:
        (WebFrameLoaderClient::dispatchWillSendRequest):
        Increase the load counter.
        
        (WebFrameLoaderClient::dispatchDidFinishLoading):
        (WebFrameLoaderClient::dispatchDidFailLoading):
        Decrease the load counter,
        
        * WebView/WebDocumentLoaderMac.h:
        * WebView/WebDocumentLoaderMac.mm:
        (WebDocumentLoaderMac::WebDocumentLoaderMac):
        
        (WebDocumentLoaderMac::attachToFrame):
        If the document loader has been detached, make sure to retain its data source here.
        
        (WebDocumentLoaderMac::detachFromFrame):
        Release the data source.
        
        (WebDocumentLoaderMac::increaseLoadCount):
        Retain the data source if load count was 0.
        
        (WebDocumentLoaderMac::decreaseLoadCount):
        Release the data source if load count becomes 0</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitChangeLog">trunk/WebKit/ChangeLog</a></li>
<li><a href="#trunkWebKitWebCoreSupportWebFrameLoaderClientmm">trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.mm</a></li>
<li><a href="#trunkWebKitWebViewWebDocumentLoaderMach">trunk/WebKit/WebView/WebDocumentLoaderMac.h</a></li>
<li><a href="#trunkWebKitWebViewWebDocumentLoaderMacmm">trunk/WebKit/WebView/WebDocumentLoaderMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/ChangeLog (20038 => 20039)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/ChangeLog        2007-03-08 01:07:17 UTC (rev 20038)
+++ trunk/WebKit/ChangeLog        2007-03-08 01:09:50 UTC (rev 20039)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2007-03-07  Anders Carlsson  &lt;acarlsson@apple.com&gt;
+
+        Reviewed by Maciej.
+
+        &lt;rdar://problem/4961259&gt; 
+        REGRESSION: Bumper Car 2.1.1 - Crash at WebCore::FrameLoader::receivedMainResourceError when encountering a invalid URL address
+        
+        (The crash was already fixed, this actually makes Bumper Car load the error page correctly.)
+        
+        This adds a &quot;load counter&quot; to the document loader and keeps the data source retained for as long as something is loading. 
+        
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::dispatchWillSendRequest):
+        Increase the load counter.
+        
+        (WebFrameLoaderClient::dispatchDidFinishLoading):
+        (WebFrameLoaderClient::dispatchDidFailLoading):
+        Decrease the load counter,
+        
+        * WebView/WebDocumentLoaderMac.h:
+        * WebView/WebDocumentLoaderMac.mm:
+        (WebDocumentLoaderMac::WebDocumentLoaderMac):
+        
+        (WebDocumentLoaderMac::attachToFrame):
+        If the document loader has been detached, make sure to retain its data source here.
+        
+        (WebDocumentLoaderMac::detachFromFrame):
+        Release the data source.
+        
+        (WebDocumentLoaderMac::increaseLoadCount):
+        Retain the data source if load count was 0.
+        
+        (WebDocumentLoaderMac::decreaseLoadCount):
+        Release the data source if load count becomes 0
+
</ins><span class="cx"> 2007-03-07  Adele Peterson  &lt;adele@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Darin.
</span></span></pre></div>
<a id="trunkWebKitWebCoreSupportWebFrameLoaderClientmm"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.mm (20038 => 20039)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.mm        2007-03-08 01:07:17 UTC (rev 20038)
+++ trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.mm        2007-03-08 01:09:50 UTC (rev 20039)
</span><span class="lines">@@ -287,6 +287,9 @@
</span><span class="cx">     id resourceLoadDelegate = WebViewGetResourceLoadDelegate(webView);
</span><span class="cx">     WebResourceDelegateImplementationCache implementations = WebViewGetResourceLoadDelegateImplementations(webView);
</span><span class="cx"> 
</span><ins>+    if (redirectResponse.isNull())
+        static_cast&lt;WebDocumentLoaderMac*&gt;(loader)-&gt;increaseLoadCount();
+
</ins><span class="cx">     if (implementations.delegateImplementsWillSendRequest)
</span><span class="cx">         request = implementations.willSendRequestFunc(resourceLoadDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), webView, [webView _objectForIdentifier:identifier], request.nsURLRequest(), redirectResponse.nsURLResponse(), dataSource(loader));
</span><span class="cx"> }
</span><span class="lines">@@ -353,6 +356,8 @@
</span><span class="cx">     if (implementations.delegateImplementsDidFinishLoadingFromDataSource)
</span><span class="cx">         implementations.didFinishLoadingFromDataSourceFunc(resourceLoadDelegate, @selector(webView:resource:didFinishLoadingFromDataSource:), webView, [webView _objectForIdentifier:identifier], dataSource(loader));
</span><span class="cx">     [webView _removeObjectForIdentifier:identifier];
</span><ins>+
+    static_cast&lt;WebDocumentLoaderMac*&gt;(loader)-&gt;decreaseLoadCount();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, unsigned long identifier, const WebCore::ResourceError&amp; error)
</span><span class="lines">@@ -360,6 +365,8 @@
</span><span class="cx">     WebView *webView = getWebView(m_webFrame.get());
</span><span class="cx">     [[webView _resourceLoadDelegateForwarder] webView:webView resource:[webView _objectForIdentifier:identifier] didFailLoadingWithError:error fromDataSource:dataSource(loader)];
</span><span class="cx">     [webView _removeObjectForIdentifier:identifier];
</span><ins>+
+    static_cast&lt;WebDocumentLoaderMac*&gt;(loader)-&gt;decreaseLoadCount();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
</span></span></pre></div>
<a id="trunkWebKitWebViewWebDocumentLoaderMach"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/WebView/WebDocumentLoaderMac.h (20038 => 20039)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/WebView/WebDocumentLoaderMac.h        2007-03-08 01:07:17 UTC (rev 20038)
+++ trunk/WebKit/WebView/WebDocumentLoaderMac.h        2007-03-08 01:09:50 UTC (rev 20039)
</span><span class="lines">@@ -45,7 +45,10 @@
</span><span class="cx">     virtual void attachToFrame();
</span><span class="cx">     virtual void detachFromFrame();
</span><span class="cx"> 
</span><ins>+    void increaseLoadCount();
+    void decreaseLoadCount();
</ins><span class="cx"> private:
</span><del>-    WebCore::RetainPtr&lt;WebDataSource&gt; m_dataSource;
-    WebDataSource *m_detachedDataSource; // not retained
</del><ins>+    WebDataSource *m_dataSource;
+    bool m_hasEverBeenDetached;
+    unsigned m_loadCount;
</ins><span class="cx"> };
</span></span></pre></div>
<a id="trunkWebKitWebViewWebDocumentLoaderMacmm"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/WebView/WebDocumentLoaderMac.mm (20038 => 20039)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/WebView/WebDocumentLoaderMac.mm        2007-03-08 01:07:17 UTC (rev 20038)
+++ trunk/WebKit/WebView/WebDocumentLoaderMac.mm        2007-03-08 01:09:50 UTC (rev 20039)
</span><span class="lines">@@ -35,33 +35,57 @@
</span><span class="cx"> 
</span><span class="cx"> WebDocumentLoaderMac::WebDocumentLoaderMac(const ResourceRequest&amp; request, const SubstituteData&amp; substituteData)
</span><span class="cx">     : DocumentLoader(request, substituteData)
</span><del>-    , m_detachedDataSource(nil)
</del><ins>+    , m_dataSource(nil)
+    , m_hasEverBeenDetached(false)
+    , m_loadCount(0)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebDocumentLoaderMac::setDataSource(WebDataSource *dataSource)
</span><span class="cx"> {
</span><del>-    m_dataSource = dataSource;    
</del><ins>+    ASSERT(!m_dataSource);
+    [dataSource retain];
+    m_dataSource = dataSource;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebDataSource *WebDocumentLoaderMac::dataSource() const
</span><span class="cx"> {
</span><del>-    return m_dataSource.get();
</del><ins>+    return m_dataSource;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebDocumentLoaderMac::attachToFrame()
</span><span class="cx"> {
</span><span class="cx">     DocumentLoader::attachToFrame();
</span><del>-    if (m_detachedDataSource) {
-        ASSERT(!m_dataSource);
-        m_dataSource = m_detachedDataSource;
-        m_detachedDataSource = nil;
-    }
</del><ins>+    ASSERT(m_loadCount == 0);
+
+    if (m_hasEverBeenDetached)
+        [m_dataSource retain];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebDocumentLoaderMac::detachFromFrame()
</span><span class="cx"> {
</span><span class="cx">     DocumentLoader::detachFromFrame();
</span><del>-    m_detachedDataSource = m_dataSource.get();
-    m_dataSource = nil;
</del><ins>+  
+    m_hasEverBeenDetached = true;
+    [m_dataSource release];
</ins><span class="cx"> }
</span><ins>+
+void WebDocumentLoaderMac::increaseLoadCount()
+{
+    ASSERT(m_dataSource);
+    
+    if (m_loadCount == 0)
+        [m_dataSource retain];
+    
+    m_loadCount++;
+}
+
+void WebDocumentLoaderMac::decreaseLoadCount()
+{
+    ASSERT(m_loadCount &gt; 0);
+
+    m_loadCount--;
+
+    if (m_loadCount == 0)
+        [m_dataSource release];
+}
</ins></span></pre>
</div>
</div>

</body>
</html>