Reviewed by Darin, Geoff.
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Dec 2006 23:26:05 +0000 (23:26 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Dec 2006 23:26:05 +0000 (23:26 +0000)
        Get rid of ResourceHandle::kill(), all it did was to balance out a ref() in ResourceHandle::start().
        We use RefPtrs to ResourceHandle instead.

        * loader/icon/IconLoader.cpp:
        (WebCore::IconLoader::~IconLoader):
        (WebCore::IconLoader::stopLoading):
        (WebCore::IconLoader::didReceiveResponse):
        * loader/loader.cpp:
        (WebCore::Loader::servePendingRequests):
        (WebCore::Loader::cancelRequests):
        (WebCore::Loader::jobForRequest):
        * loader/loader.h:
        * platform/network/ResourceHandle.cpp:
        * platform/network/ResourceHandle.h:
        * platform/network/mac/ResourceHandleMac.mm:
        (WebCore::ResourceHandle::start):
        (WebCore::ResourceHandle::finishJobAndHandle):
        (WebCore::ResourceHandle::reportError):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::abort):
        (WebCore::XMLHttpRequest::didFinishLoading):

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

WebCore/ChangeLog
WebCore/loader/icon/IconLoader.cpp
WebCore/loader/loader.cpp
WebCore/loader/loader.h
WebCore/platform/network/ResourceHandle.cpp
WebCore/platform/network/ResourceHandle.h
WebCore/platform/network/mac/ResourceHandleMac.mm
WebCore/xml/xmlhttprequest.cpp

index a955b567b015589c4ae2fd97c396793fb3779452..72b19c5a1acc6b21d78537d4bef56a4fac7c2f74 100644 (file)
@@ -1,3 +1,29 @@
+2006-12-04  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Darin, Geoff.
+
+        Get rid of ResourceHandle::kill(), all it did was to balance out a ref() in ResourceHandle::start().
+        We use RefPtrs to ResourceHandle instead.
+
+        * loader/icon/IconLoader.cpp:
+        (WebCore::IconLoader::~IconLoader):
+        (WebCore::IconLoader::stopLoading):
+        (WebCore::IconLoader::didReceiveResponse):
+        * loader/loader.cpp:
+        (WebCore::Loader::servePendingRequests):
+        (WebCore::Loader::cancelRequests):
+        (WebCore::Loader::jobForRequest):
+        * loader/loader.h:
+        * platform/network/ResourceHandle.cpp:
+        * platform/network/ResourceHandle.h:
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandle::start):
+        (WebCore::ResourceHandle::finishJobAndHandle):
+        (WebCore::ResourceHandle::reportError):
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::abort):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+
 2006-12-04  Oliver Hunt  <oliver@apple.com>
 
         Build fix for non-SVG builds
index 53aad06385f9c29b0f5e2c52abcfa082c0c0e0f7..798082a1d1ac2026733f9455e55b6ced7efeab45 100644 (file)
@@ -55,8 +55,6 @@ auto_ptr<IconLoader> IconLoader::create(Frame* frame)
 
 IconLoader::~IconLoader()
 {
-    if (m_handle)
-        m_handle->kill();
 }
 
 void IconLoader::startLoading()
@@ -90,8 +88,7 @@ void IconLoader::startLoading()
 
 void IconLoader::stopLoading()
 {
-    if (m_handle)
-        m_handle->kill();
+    m_handle = 0;
     clearLoadingState();
 }
 
@@ -102,7 +99,7 @@ void IconLoader::didReceiveResponse(ResourceHandle* handle, const ResourceRespon
     int status = response.httpStatusCode();
     if (status && (status < 200 || status > 299)) {
         KURL iconURL = handle->url();
-        handle->kill();
+        m_handle = 0;
         finishLoading(iconURL);
     }
 }
index e92f0adc69dbfc3c5036607bf4537886e86c7d7b..0bb606d12dd3abc18fc9e5afa7cac5363cdace6b 100644 (file)
@@ -88,7 +88,7 @@ void Loader::servePendingRequests()
     RefPtr<ResourceHandle> loader = ResourceHandle::create(request, this, req->docLoader());
 
     if (loader)
-        m_requestsLoading.add(loader.get(), req);
+        m_requestsLoading.add(loader.release(), req);
 }
 
 void Loader::receivedAllData(ResourceHandle* job, PlatformData allData)
@@ -221,7 +221,7 @@ void Loader::cancelRequests(DocLoader* dl)
     for (RequestMap::iterator i = m_requestsLoading.begin(); i != end; ++i) {
         Request* r = i->second;
         if (r->docLoader() == dl)
-            jobsToCancel.append(i->first);
+            jobsToCancel.append(i->first.get());
     }
 
     for (unsigned i = 0; i < jobsToCancel.size(); ++i) {
@@ -229,7 +229,6 @@ void Loader::cancelRequests(DocLoader* dl)
         Request* r = m_requestsLoading.get(job);
         m_requestsLoading.remove(job);
         cache()->remove(r->cachedResource());
-        job->kill();
     }
 
     DeprecatedPtrListIterator<Request> bdIt(m_requestsBackgroundDecoding);
@@ -254,7 +253,7 @@ ResourceHandle* Loader::jobForRequest(const String& URL) const
     for (RequestMap::const_iterator i = m_requestsLoading.begin(); i != end; ++i) {
         CachedResource* obj = i->second->cachedResource();
         if (obj && obj->url() == URL)
-            return i->first;
+            return i->first.get();
     }
     return 0;
 }
index bde04f0759954a2458141a9a6ac321ca3d053257..ae5e4cce4d4be8d6ea04166b520446c490170f17 100644 (file)
@@ -71,7 +71,7 @@ namespace WebCore {
         void servePendingRequests();
 
         DeprecatedPtrList<Request> m_requestsPending;
-        typedef HashMap<ResourceHandle*, Request*> RequestMap;
+        typedef HashMap<RefPtr<ResourceHandle>, Request*> RequestMap;
         RequestMap m_requestsLoading;
 
         DeprecatedPtrList<Request> m_requestsBackgroundDecoding;
index fd091c9f64029bff320418a6426d2033edd607b3..bd85ee103e22a4575ad9f181e7d027a09a3fd500 100644 (file)
@@ -47,16 +47,6 @@ PassRefPtr<ResourceHandle> ResourceHandle::create(const ResourceRequest& request
     return 0;
 }
 
-void ResourceHandle::kill()
-{
-    if (d->m_loading){
-        ASSERT(!d->m_cancelled);
-        d->m_loading = false;
-        d->m_cancelled = true;
-        deref();
-    }
-}
-
 const HTTPHeaderMap& ResourceHandle::requestHeaders() const
 {
     return d->m_request.httpHeaderFields();
index ec0189058778ae63dcd0360c8590735c25c9cb9b..2424cb1533765681f3bcbc8214c1c6b57126638f 100644 (file)
@@ -74,8 +74,6 @@ public:
 
     ~ResourceHandle();
 
-    void kill();
-
 #if PLATFORM(MAC)
     NSURLRequest *willSendRequest(NSURLRequest *, NSURLResponse *);
     void didReceiveResponse(NSURLResponse *);  
index 1b10da96f8e45d0fe96db1e2ecd5d5a3377e1dc7..90a0230c82497d3483830d800cfb650494fc2b36 100644 (file)
@@ -48,16 +48,13 @@ ResourceHandle::~ResourceHandle()
 
 bool ResourceHandle::start(DocLoader* docLoader)
 {
-    ref();
     d->m_loading = true;
 
     ASSERT(docLoader);
     
     FrameMac* frame = Mac(docLoader->frame());
-    if (!frame) {
-        kill();
+    if (!frame)
         return false;
-    }
 
     frame->loader()->didTellBridgeAboutLoad(url().url());
 
@@ -65,10 +62,8 @@ bool ResourceHandle::start(DocLoader* docLoader)
 
     // If we are no longer attached to a Page, this must be an attempted load from an
     // onUnload handler, so let's just block it.
-    if (!frame->page()) {
-        kill();
+    if (!frame->page())
         return false;
-    }
     
     d->m_subresourceLoader = SubresourceLoader::create(frame, this, d->m_request);
 
@@ -77,7 +72,6 @@ bool ResourceHandle::start(DocLoader* docLoader)
 
     END_BLOCK_OBJC_EXCEPTIONS;
 
-    kill();
     return false;
 }
 
@@ -116,17 +110,17 @@ void ResourceHandle::addData(NSData *data)
 void ResourceHandle::finishJobAndHandle(NSData *data)
 {
     if (ResourceHandleClient* c = client()) {
+        // We must protect the resource handle in case the call to receivedAllData causes a deref.
+        RefPtr<ResourceHandle> protect(this);
         c->receivedAllData(this, data);
         c->didFinishLoading(this);
     }
-    kill();
 }
 
 void ResourceHandle::reportError(NSError* error)
 {
     if (ResourceHandleClient* c = client())
         c->didFailWithError(this, error);
-    kill();
 }
 
 } // namespace WebCore
index 22cb4e144353d28333328118bcdf9d25df88d4d0..3c4766493a2ba1ac12c97e2f711b23261bb3044c 100644 (file)
@@ -362,10 +362,9 @@ void XMLHttpRequest::abort()
 {
     bool hadLoader = m_loader;
 
-    if (hadLoader) {
-        m_loader->kill();
+    if (hadLoader)
         m_loader = 0;
-    }
+
     m_decoder = 0;
     m_aborted = true;
 
@@ -496,7 +495,7 @@ void XMLHttpRequest::didFinishLoading(ResourceHandle* handle)
     if (m_aborted)
         return;
         
-    ASSERT(handle == m_loader);
+    ASSERT(handle == m_loader.get());
 
     if (m_state < Sent)
         changeState(Sent);