[GTK] Fix platformDefersLoading to handle non-http requests, and
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Nov 2011 18:20:49 +0000 (18:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Nov 2011 18:20:49 +0000 (18:20 +0000)
to not use broken-ish libsoup APIs.
https://bugs.webkit.org/show_bug.cgi?id=72227

Patch by Dan Winship <danw@gnome.org> on 2011-11-16
Reviewed by Martin Robinson.

* platform/network/ResourceHandleInternal.h:
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::sendRequestCallback):
(WebCore::startHTTPRequest):
(WebCore::hasBeenSent):
(WebCore::ResourceHandle::platformSetDefersLoading):
(WebCore::readCallback): rather than deferring by using
soup_session_pause_message(), let the read complete, but just don't
process the result until we're no longer deferred.
(WebCore::startNonHTTPRequest): Don't start the request if
it's deferred.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/ResourceHandleInternal.h
Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp

index 942462e0f49a644dd6ba87a91a09ae99e7f131d9..cb8cae18deab12941a1527b47ef36057b022204c 100644 (file)
@@ -1,3 +1,23 @@
+2011-11-16  Dan Winship  <danw@gnome.org>
+
+        [GTK] Fix platformDefersLoading to handle non-http requests, and
+        to not use broken-ish libsoup APIs.
+        https://bugs.webkit.org/show_bug.cgi?id=72227
+
+        Reviewed by Martin Robinson.
+
+        * platform/network/ResourceHandleInternal.h:
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::sendRequestCallback):
+        (WebCore::startHTTPRequest):
+        (WebCore::hasBeenSent):
+        (WebCore::ResourceHandle::platformSetDefersLoading):
+        (WebCore::readCallback): rather than deferring by using
+        soup_session_pause_message(), let the read complete, but just don't
+        process the result until we're no longer deferred.
+        (WebCore::startNonHTTPRequest): Don't start the request if
+        it's deferred.
+
 2011-11-16  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: Application cache status should be updated after swapCache().
index a868f573bbcd1779ffb0757bbb0e490a8343af31..5df4cc99d626f8e0370b33924726f029a33548ea 100644 (file)
@@ -194,6 +194,7 @@ namespace WebCore {
         GRefPtr<SoupRequest> m_soupRequest;
         GRefPtr<GInputStream> m_inputStream;
         GRefPtr<GCancellable> m_cancellable;
+        GRefPtr<GAsyncResult> m_deferredResult;
         char* m_buffer;
         unsigned long m_bodySize;
         unsigned long m_bodyDataSent;
index a9b07d26f94eecb7638c1a5db3b457b43ff17ed7..da9beb661ec9fa459033b88d1f0022099d95bf36 100644 (file)
@@ -502,9 +502,6 @@ static void sendRequestCallback(GObject* source, GAsyncResult* res, gpointer dat
         }
     }
 
-    if (d->m_defersLoading)
-         soup_session_pause_message(handle->defaultSession(), d->m_soupMessage.get());
-
     g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, READ_BUFFER_SIZE,
                               G_PRIORITY_DEFAULT, d->m_cancellable.get(), readCallback, handle.get());
 }
@@ -678,7 +675,7 @@ static bool startHTTPRequest(ResourceHandle* handle)
     if (!soup_message_headers_get_one(soupMessage->request_headers, "Accept"))
         soup_message_headers_append(soupMessage->request_headers, "Accept", "*/*");
 
-    // Send the request only if it's not been explicitely deferred.
+    // Send the request only if it's not been explicitly deferred.
     if (!d->m_defersLoading) {
         d->m_cancellable = adoptGRef(g_cancellable_new());
         soup_request_send_async(d->m_soupRequest.get(), d->m_cancellable.get(), sendRequestCallback, handle);
@@ -738,34 +735,33 @@ void ResourceHandle::cancel()
         g_cancellable_cancel(d->m_cancellable.get());
 }
 
-void ResourceHandle::platformSetDefersLoading(bool defersLoading)
+static bool hasBeenSent(ResourceHandle* handle)
 {
-    // Initial implementation of this method was required for bug #44157.
+    ResourceHandleInternal* d = handle->getInternal();
 
+    return d->m_cancellable;
+}
+
+void ResourceHandle::platformSetDefersLoading(bool defersLoading)
+{
     if (d->m_cancelled)
         return;
 
-    if (!defersLoading && !d->m_cancellable && d->m_soupRequest.get()) {
+    // We only need to take action here to UN-defer loading.
+    if (defersLoading)
+        return;
+
+    if (!hasBeenSent(this)) {
+        ASSERT(d->m_soupRequest);
         d->m_cancellable = adoptGRef(g_cancellable_new());
         soup_request_send_async(d->m_soupRequest.get(), d->m_cancellable.get(), sendRequestCallback, this);
         return;
     }
 
-    // Only supported for http(s) transfers. Something similar would
-    // probably be needed for data transfers done with GIO.
-    if (!d->m_soupMessage)
-        return;
-
-    // Do not pause or unpause operations that are completed or have not reached
-    // sendRequestCallback yet. If m_defersLoading is true at that point, we'll pause.
-    SoupMessage* soupMessage = d->m_soupMessage.get();
-    if (d->m_finished || !d->m_inputStream)
-        return;
-
-    if (defersLoading)
-        soup_session_pause_message(defaultSession(), soupMessage);
-    else
-        soup_session_unpause_message(defaultSession(), soupMessage);
+    if (d->m_deferredResult) {
+        GRefPtr<GAsyncResult> asyncResult = adoptGRef(d->m_deferredResult.leakRef());
+        readCallback(G_OBJECT(d->m_inputStream.get()), asyncResult.get(), this);
+    }
 }
 
 bool ResourceHandle::loadsBlocked()
@@ -823,6 +819,11 @@ static void readCallback(GObject* source, GAsyncResult* asyncResult, gpointer da
         return;
     }
 
+    if (d->m_defersLoading) {
+        d->m_deferredResult = asyncResult;
+        return;
+    }
+
     GOwnPtr<GError> error;
     gssize bytesRead = g_input_stream_read_finish(d->m_inputStream.get(), asyncResult, &error.outPtr());
     if (error) {
@@ -878,8 +879,11 @@ static bool startNonHTTPRequest(ResourceHandle* handle, KURL url)
     // balanced by a deref() in cleanupSoupRequestOperation, which should always run
     handle->ref();
 
-    d->m_cancellable = adoptGRef(g_cancellable_new());
-    soup_request_send_async(d->m_soupRequest.get(), d->m_cancellable.get(), sendRequestCallback, handle);
+    // Send the request only if it's not been explicitly deferred.
+    if (!d->m_defersLoading) {
+        d->m_cancellable = adoptGRef(g_cancellable_new());
+        soup_request_send_async(d->m_soupRequest.get(), d->m_cancellable.get(), sendRequestCallback, handle);
+    }
 
     return true;
 }