Title: [150076] trunk/Source/WebCore
Revision
150076
Author
commit-qu...@webkit.org
Date
2013-05-14 10:53:46 -0700 (Tue, 14 May 2013)

Log Message

[BlackBerry] Handle network errors when starting a new job
https://bugs.webkit.org/show_bug.cgi?id=116101

Patch by Carlos Garcia Campos <cgar...@igalia.com> on 2013-05-14
Reviewed by Rob Buis.

Make startJob() return a network status that can be used by the
caller to create a network error.

* platform/network/blackberry/NetworkJob.cpp:
(WebCore::NetworkJob::initialize): createNetworkStream() should
always return a valid pointer so use an ASSERT instead of an early
return to make sure we have a valid stream.
(WebCore::NetworkJob::startNewJobWithRequest): Only return true if
the network job was started successfully.
* platform/network/blackberry/NetworkJob.h:
(NetworkJob): Make initialize method void instead of bool since it
can't fail.
* platform/network/blackberry/NetworkManager.cpp:
(WebCore::NetworkManager::startJob): Return a network error or
StatusSuccess.
* platform/network/blackberry/NetworkManager.h:
(NetworkManager):
* platform/network/blackberry/ResourceHandleBlackBerry.cpp:
(WebCore::ResourceHandle::start): Return true if job was started
successfully.
(WebCore::ResourceHandle::platformLoadResourceSynchronously):
Check return value of startJob and fill the ResourceError with the
network status returned to finish the load.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (150075 => 150076)


--- trunk/Source/WebCore/ChangeLog	2013-05-14 17:44:37 UTC (rev 150075)
+++ trunk/Source/WebCore/ChangeLog	2013-05-14 17:53:46 UTC (rev 150076)
@@ -1,3 +1,34 @@
+2013-05-14  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [BlackBerry] Handle network errors when starting a new job
+        https://bugs.webkit.org/show_bug.cgi?id=116101
+
+        Reviewed by Rob Buis.
+
+        Make startJob() return a network status that can be used by the
+        caller to create a network error.
+
+        * platform/network/blackberry/NetworkJob.cpp:
+        (WebCore::NetworkJob::initialize): createNetworkStream() should
+        always return a valid pointer so use an ASSERT instead of an early
+        return to make sure we have a valid stream.
+        (WebCore::NetworkJob::startNewJobWithRequest): Only return true if
+        the network job was started successfully.
+        * platform/network/blackberry/NetworkJob.h:
+        (NetworkJob): Make initialize method void instead of bool since it
+        can't fail.
+        * platform/network/blackberry/NetworkManager.cpp:
+        (WebCore::NetworkManager::startJob): Return a network error or
+        StatusSuccess.
+        * platform/network/blackberry/NetworkManager.h:
+        (NetworkManager):
+        * platform/network/blackberry/ResourceHandleBlackBerry.cpp:
+        (WebCore::ResourceHandle::start): Return true if job was started
+        successfully.
+        (WebCore::ResourceHandle::platformLoadResourceSynchronously):
+        Check return value of startJob and fill the ResourceError with the
+        network status returned to finish the load.
+
 2013-05-14  Antoine Quint  <grao...@apple.com>
 
         [Mac] captions menu is not positioned correctly in full-screen

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp (150075 => 150076)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp	2013-05-14 17:44:37 UTC (rev 150075)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp	2013-05-14 17:53:46 UTC (rev 150076)
@@ -115,7 +115,7 @@
         AuthenticationChallengeManager::instance()->cancelAuthenticationChallenge(this);
 }
 
-bool NetworkJob::initialize(int playerId,
+void NetworkJob::initialize(int playerId,
     const String& pageGroupName,
     const KURL& url,
     const BlackBerry::Platform::NetworkRequest& request,
@@ -164,8 +164,7 @@
         m_contentDisposition = "filename=" + String(request.getSuggestedSaveName());
 
     BlackBerry::Platform::FilterStream* wrappedStream = m_streamFactory->createNetworkStream(request, m_playerId);
-    if (!wrappedStream)
-        return false;
+    ASSERT(wrappedStream);
 
     BlackBerry::Platform::NetworkRequest::TargetType targetType = request.getTargetType();
     if ((targetType == BlackBerry::Platform::NetworkRequest::TargetIsMainFrame
@@ -177,8 +176,6 @@
     }
 
     setWrappedStream(wrappedStream);
-
-    return true;
 }
 
 int NetworkJob::cancelJob()
@@ -645,7 +642,7 @@
     RefPtr<ResourceHandle> handle = m_handle;
     cancelJob();
 
-    NetworkManager::instance()->startJob(m_playerId,
+    int status = NetworkManager::instance()->startJob(m_playerId,
         m_pageGroupName,
         handle,
         newRequest,
@@ -654,7 +651,7 @@
         m_deferLoadingCount,
         increaseRedirectCount ? m_redirectCount + 1 : m_redirectCount,
         rereadCookies);
-    return true;
+    return status == BlackBerry::Platform::FilterStream::StatusSuccess;
 }
 
 bool NetworkJob::handleRedirect()

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h (150075 => 150076)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h	2013-05-14 17:44:37 UTC (rev 150075)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h	2013-05-14 17:53:46 UTC (rev 150076)
@@ -52,7 +52,7 @@
     NetworkJob();
     ~NetworkJob();
 
-    bool initialize(int playerId,
+    void initialize(int playerId,
         const String& pageGroupName,
         const KURL&,
         const BlackBerry::Platform::NetworkRequest&,

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkManager.cpp (150075 => 150076)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkManager.cpp	2013-05-14 17:44:37 UTC (rev 150075)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkManager.cpp	2013-05-14 17:53:46 UTC (rev 150076)
@@ -40,7 +40,7 @@
 
 SINGLETON_INITIALIZER_THREADUNSAFE(NetworkManager)
 
-bool NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, Frame* frame, bool defersLoading)
+int NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, Frame* frame, bool defersLoading)
 {
     ASSERT(job.get());
     // We shouldn't call methods on PassRefPtr so make a new RefPt.
@@ -48,11 +48,10 @@
     return startJob(playerId, refJob, refJob->firstRequest(), frame, defersLoading);
 }
 
-bool NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, Frame* frame, bool defersLoading)
+int NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, Frame* frame, bool defersLoading)
 {
     Page* page = frame->page();
-    if (!page)
-        return false;
+    ASSERT(page);
     BlackBerry::Platform::NetworkStreamFactory* streamFactory = page->chrome()->platformPageClient()->networkStreamFactory();
     return startJob(playerId, page->groupName(), job, request, streamFactory, frame, defersLoading ? 1 : 0);
 }
@@ -138,7 +137,7 @@
         platformRequest.setCredentials(authType, authProtocol, authScheme, username.utf8().data(), password.utf8().data());
 }
 
-bool NetworkManager::startJob(int playerId, const String& pageGroupName, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, BlackBerry::Platform::NetworkStreamFactory* streamFactory, Frame* frame, int deferLoadingCount, int redirectCount, bool rereadCookies)
+int NetworkManager::startJob(int playerId, const String& pageGroupName, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, BlackBerry::Platform::NetworkStreamFactory* streamFactory, Frame* frame, int deferLoadingCount, int redirectCount, bool rereadCookies)
 {
     // Make sure the ResourceHandle doesn't go out of scope while calling callbacks.
     RefPtr<ResourceHandle> guardJob(job);
@@ -171,23 +170,26 @@
         platformRequest.setOverrideContentType(request.overrideContentType());
 
     NetworkJob* networkJob = new NetworkJob;
-    if (!networkJob)
-        return false;
-    if (!networkJob->initialize(playerId, pageGroupName, url, platformRequest, guardJob, streamFactory, frame, deferLoadingCount, redirectCount)) {
-        delete networkJob;
-        return false;
-    }
+    networkJob->initialize(playerId, pageGroupName, url, platformRequest, guardJob, streamFactory, frame, deferLoadingCount, redirectCount);
 
     // Make sure we have only one NetworkJob for one ResourceHandle.
     ASSERT(!findJobForHandle(guardJob));
 
     m_jobs.append(networkJob);
 
-    int result = networkJob->streamOpen();
-    if (result)
-        return false;
+    switch (networkJob->streamOpen()) {
+    case BlackBerry::Platform::FilterStream::ResultOk:
+        return BlackBerry::Platform::FilterStream::StatusSuccess;
+    case BlackBerry::Platform::FilterStream::ResultNotReady:
+        return BlackBerry::Platform::FilterStream::StatusErrorNotReady;
+    case BlackBerry::Platform::FilterStream::ResultNotHandled:
+    default:
+        // This should never happen.
+        break;
+    }
 
-    return true;
+    ASSERT_NOT_REACHED();
+    return BlackBerry::Platform::FilterStream::StatusErrorConnectionFailed;
 }
 
 bool NetworkManager::stopJob(PassRefPtr<ResourceHandle> job)

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkManager.h (150075 => 150076)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkManager.h	2013-05-14 17:44:37 UTC (rev 150075)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkManager.h	2013-05-14 17:53:46 UTC (rev 150076)
@@ -45,8 +45,8 @@
 public:
     void setInitialURL(const KURL& url) { m_initialURL = url; }
     KURL initialURL() { return m_initialURL; }
-    bool startJob(int playerId, PassRefPtr<ResourceHandle> job, Frame*, bool defersLoading);
-    bool startJob(int playerId, PassRefPtr<ResourceHandle> job, const ResourceRequest&, Frame*, bool defersLoading);
+    int startJob(int playerId, PassRefPtr<ResourceHandle> job, Frame*, bool defersLoading);
+    int startJob(int playerId, PassRefPtr<ResourceHandle> job, const ResourceRequest&, Frame*, bool defersLoading);
     bool stopJob(PassRefPtr<ResourceHandle>);
     void setDefersLoading(PassRefPtr<ResourceHandle> job, bool defersLoading);
     void pauseLoad(PassRefPtr<ResourceHandle> job, bool pause);
@@ -57,7 +57,7 @@
 
     NetworkJob* findJobForHandle(PassRefPtr<ResourceHandle>);
     void deleteJob(NetworkJob*);
-    bool startJob(int playerId, const String& pageGroupName, PassRefPtr<ResourceHandle>, const ResourceRequest&, BlackBerry::Platform::NetworkStreamFactory*, Frame*, int deferLoadingCount = 0, int redirectCount = 0, bool rereadCookies = false);
+    int startJob(int playerId, const String& pageGroupName, PassRefPtr<ResourceHandle>, const ResourceRequest&, BlackBerry::Platform::NetworkStreamFactory*, Frame*, int deferLoadingCount = 0, int redirectCount = 0, bool rereadCookies = false);
 
     Vector<NetworkJob*> m_jobs;
     KURL m_initialURL;

Modified: trunk/Source/WebCore/platform/network/blackberry/ResourceHandleBlackBerry.cpp (150075 => 150076)


--- trunk/Source/WebCore/platform/network/blackberry/ResourceHandleBlackBerry.cpp	2013-05-14 17:44:37 UTC (rev 150075)
+++ trunk/Source/WebCore/platform/network/blackberry/ResourceHandleBlackBerry.cpp	2013-05-14 17:53:46 UTC (rev 150076)
@@ -117,7 +117,7 @@
     if (!frame || !frame->loader() || !frame->loader()->client() || !client())
         return false;
     int playerId = static_cast<FrameLoaderClientBlackBerry*>(frame->loader()->client())->playerId();
-    return NetworkManager::instance()->startJob(playerId, this, frame, d->m_defersLoading);
+    return NetworkManager::instance()->startJob(playerId, this, frame, d->m_defersLoading) == BlackBerry::Platform::FilterStream::StatusSuccess;
 }
 
 void ResourceHandle::pauseLoad(bool pause)
@@ -157,7 +157,12 @@
     bool shouldContentSniff = false;
 
     RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(context, request, &syncLoader, defersLoading, shouldContentSniff));
-    NetworkManager::instance()->startJob(playerId, handle, frame, defersLoading);
+    int status = NetworkManager::instance()->startJob(playerId, handle, frame, defersLoading);
+    if (status != BlackBerry::Platform::FilterStream::StatusSuccess) {
+        handle->cancel();
+        error = ResourceError(ResourceError::platformErrorDomain, status, request.url().string(), BlackBerry::Platform::String::emptyString());
+        return;
+    }
 
     const double syncLoadTimeOut = 60; // seconds
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to