Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / AssociatedURLLoader.cpp
index fee8295..de009eb 100644 (file)
@@ -35,7 +35,6 @@
 #include "core/fetch/FetchUtils.h"
 #include "core/loader/DocumentThreadableLoader.h"
 #include "core/loader/DocumentThreadableLoaderClient.h"
-#include "core/xml/XMLHttpRequest.h"
 #include "platform/Timer.h"
 #include "platform/exported/WrappedResourceRequest.h"
 #include "platform/exported/WrappedResourceResponse.h"
@@ -50,6 +49,7 @@
 #include "web/WebLocalFrameImpl.h"
 #include "wtf/HashSet.h"
 #include "wtf/text/WTFString.h"
+#include <limits.h>
 
 namespace blink {
 
@@ -117,21 +117,22 @@ const HTTPHeaderSet& HTTPResponseHeaderValidator::blockedHeaders()
 
 // This class bridges the interface differences between WebCore and WebKit loader clients.
 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient.
-class AssociatedURLLoader::ClientAdapter FINAL : public DocumentThreadableLoaderClient {
+class AssociatedURLLoader::ClientAdapter final : public DocumentThreadableLoaderClient {
     WTF_MAKE_NONCOPYABLE(ClientAdapter);
 public:
     static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderClient*, const WebURLLoaderOptions&);
 
-    virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) OVERRIDE;
-    virtual void willSendRequest(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/) OVERRIDE;
-
-    virtual void didReceiveResponse(unsigned long, const ResourceResponse&) OVERRIDE;
-    virtual void didDownloadData(int /*dataLength*/) OVERRIDE;
-    virtual void didReceiveData(const char*, int /*dataLength*/) OVERRIDE;
-    virtual void didReceiveCachedMetadata(const char*, int /*dataLength*/) OVERRIDE;
-    virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) OVERRIDE;
-    virtual void didFail(const ResourceError&) OVERRIDE;
-    virtual void didFailRedirectCheck() OVERRIDE;
+    // ThreadableLoaderClient
+    void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) override;
+    void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<WebDataConsumerHandle>) override;
+    void didDownloadData(int /*dataLength*/) override;
+    void didReceiveData(const char*, unsigned /*dataLength*/) override;
+    void didReceiveCachedMetadata(const char*, int /*dataLength*/) override;
+    void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) override;
+    void didFail(const ResourceError&) override;
+    void didFailRedirectCheck() override;
+    // DocumentThreadableLoaderClient
+    void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/) override;
 
     // Sets an error to be reported back to the client, asychronously.
     void setDelayedError(const ResourceError&);
@@ -175,7 +176,7 @@ AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, W
     ASSERT(m_client);
 }
 
-void AssociatedURLLoader::ClientAdapter::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
+void AssociatedURLLoader::ClientAdapter::willFollowRedirect(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
 {
     if (!m_client)
         return;
@@ -193,8 +194,9 @@ void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSen
     m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent);
 }
 
-void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const ResourceResponse& response)
+void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
 {
+    ASSERT_UNUSED(handle, !handle);
     if (!m_client)
         return;
 
@@ -223,11 +225,13 @@ void AssociatedURLLoader::ClientAdapter::didDownloadData(int dataLength)
     m_client->didDownloadData(m_loader, dataLength, -1);
 }
 
-void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, int dataLength)
+void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, unsigned dataLength)
 {
     if (!m_client)
         return;
 
+    RELEASE_ASSERT(dataLength <= static_cast<unsigned>(std::numeric_limits<int>::max()));
+
     m_client->didReceiveData(m_loader, data, dataLength, -1);
 }
 
@@ -260,7 +264,7 @@ void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error)
 
 void AssociatedURLLoader::ClientAdapter::didFailRedirectCheck()
 {
-    m_loader->cancel();
+    didFail(ResourceError());
 }
 
 void AssociatedURLLoader::ClientAdapter::setDelayedError(const ResourceError& error)
@@ -315,6 +319,7 @@ void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURL
 
 void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client)
 {
+    ASSERT(!m_loader);
     ASSERT(!m_client);
 
     m_client = client;
@@ -326,7 +331,7 @@ void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebUR
         WebString method = newRequest.httpMethod();
         allowLoad = isValidHTTPToken(method) && FetchUtils::isUsefulMethod(method);
         if (allowLoad) {
-            newRequest.setHTTPMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(method));
+            newRequest.setHTTPMethod(FetchUtils::normalizeMethod(method));
             HTTPRequestHeaderValidator validator;
             newRequest.visitHTTPHeaderFields(&validator);
             allowLoad = validator.isSafe();
@@ -355,7 +360,9 @@ void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebUR
         Document* webcoreDocument = m_frameImpl->frame()->document();
         ASSERT(webcoreDocument);
         m_loader = DocumentThreadableLoader::create(*webcoreDocument, m_clientAdapter.get(), webcoreRequest, options, resourceLoaderOptions);
-    } else {
+    }
+
+    if (!m_loader) {
         // FIXME: return meaningful error codes.
         m_clientAdapter->setDelayedError(ResourceError());
     }