Bug 22720: Make XMLHttpRequest work in Workers
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Jan 2009 00:22:45 +0000 (00:22 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Jan 2009 00:22:45 +0000 (00:22 +0000)
<https://bugs.webkit.org/show_bug.cgi?id=22720>

Contributed by David Levin.

Reviewed by Alexey Proskuryakov

More removal of document usage from XMLHttpRequest.
* Abstracted away the sync and async requests behind the ThreadableLoader class, which
  will get an implementation for Workers.  It follows the same model as SubresourceLoader, since
  it is a thin wrapper around it.
* Consolidated dashboard compatibility checks into usesDashboardBackwardCompatibilityMode
  which handles workers.

No observable change in behavior, so no test.

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

15 files changed:
WebCore/ChangeLog
WebCore/GNUmakefile.am
WebCore/WebCore.pro
WebCore/WebCore.scons
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/WebCoreSources.bkl
WebCore/loader/DocumentThreadableLoader.cpp [new file with mode: 0644]
WebCore/loader/DocumentThreadableLoader.h [new file with mode: 0644]
WebCore/loader/SubresourceLoaderClient.h
WebCore/loader/ThreadableLoader.cpp [new file with mode: 0644]
WebCore/loader/ThreadableLoader.h [new file with mode: 0644]
WebCore/loader/ThreadableLoaderClient.h [new file with mode: 0644]
WebCore/xml/XMLHttpRequest.cpp
WebCore/xml/XMLHttpRequest.h

index b233460..12f4d73 100644 (file)
@@ -1,3 +1,78 @@
+2009-01-20  David Levin  <levin@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Bug 22720: Make XMLHttpRequest work in Workers
+        <https://bugs.webkit.org/show_bug.cgi?id=22720>
+
+        More removal of document usage from XMLHttpRequest.
+        * Abstracted away the sync and async requests behind the ThreadableLoader class, which
+          will get an implementation for Workers.  It follows the same model as SubresourceLoader, since
+          it is a thin wrapper around it.
+        * Consolidated dashboard compatibility checks into usesDashboardBackwardCompatibilityMode
+          which handles workers.
+
+        No observable change in behavior, so no test.
+
+        * GNUmakefile.am:
+        * WebCore.pro:
+        * WebCore.scons:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * WebCoreSources.bkl:
+        * loader/DocumentThreadableLoader.cpp: Added.
+        (WebCore::DocumentThreadableLoader::create):
+        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
+        (WebCore::DocumentThreadableLoader::~DocumentThreadableLoader):
+        (WebCore::DocumentThreadableLoader::cancel):
+        (WebCore::DocumentThreadableLoader::willSendRequest):
+        (WebCore::DocumentThreadableLoader::didSendData):
+        (WebCore::DocumentThreadableLoader::didReceiveResponse):
+        (WebCore::DocumentThreadableLoader::didReceiveData):
+        (WebCore::DocumentThreadableLoader::didFinishLoading):
+        (WebCore::DocumentThreadableLoader::didFail):
+        (WebCore::DocumentThreadableLoader::receivedCancellation):
+        * loader/DocumentThreadableLoader.h: Added.
+        (WebCore::DocumentThreadableLoader::refThreadableLoader):
+        (WebCore::DocumentThreadableLoader::derefThreadableLoader):
+        * loader/SubresourceLoaderClient.h:
+        (WebCore::SubresourceLoaderClient::didReceiveData):
+        * loader/ThreadableLoader.cpp: Added.
+        (WebCore::ThreadableLoader::create):
+        (WebCore::ThreadableLoader::loadResourceSynchronously):
+        * loader/ThreadableLoader.h: Added.
+        (WebCore::):
+        (WebCore::ThreadableLoader::ref):
+        (WebCore::ThreadableLoader::deref):
+        (WebCore::ThreadableLoader::~ThreadableLoader):
+        * loader/ThreadableLoaderClient.h: Added.
+        (WebCore::ThreadableLoaderClient::didSendData):
+        (WebCore::ThreadableLoaderClient::didReceiveResponse):
+        (WebCore::ThreadableLoaderClient::didReceiveData):
+        (WebCore::ThreadableLoaderClient::didFinishLoading):
+        (WebCore::ThreadableLoaderClient::didFail):
+        (WebCore::ThreadableLoaderClient::didGetCancelled):
+        (WebCore::ThreadableLoaderClient::didReceiveAuthenticationCancellation):
+        (WebCore::ThreadableLoaderClient::~ThreadableLoaderClient):
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::XMLHttpRequest):
+        (WebCore::XMLHttpRequest::usesDashboardBackwardCompatibilityMode):
+        (WebCore::XMLHttpRequest::send):
+        (WebCore::XMLHttpRequest::loadRequestSynchronously):
+        (WebCore::XMLHttpRequest::loadRequestAsynchronously):
+        (WebCore::XMLHttpRequest::setRequestHeader):
+        (WebCore::XMLHttpRequest::processSyncLoadResults):
+        (WebCore::XMLHttpRequest::didFail):
+        (WebCore::XMLHttpRequest::didGetCancelled):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        (WebCore::XMLHttpRequest::didFinishLoadingPreflight):
+        (WebCore::XMLHttpRequest::didSendData):
+        (WebCore::XMLHttpRequest::didReceiveResponse):
+        (WebCore::XMLHttpRequest::didReceiveResponsePreflight):
+        (WebCore::XMLHttpRequest::didReceiveAuthenticationCancellation):
+        (WebCore::XMLHttpRequest::didReceiveData):
+        * xml/XMLHttpRequest.h:
+
 2009-01-19  Chris Marrin  <cmarrin@apple.com>
 
         Reviewed by David Hyatt.
index 79f55a7..d16832c 100644 (file)
@@ -1043,6 +1043,8 @@ webcore_sources += \
        WebCore/loader/DocLoader.h \
        WebCore/loader/DocumentLoader.cpp \
        WebCore/loader/DocumentLoader.h \
+       WebCore/loader/DocumentThreadableLoader.cpp \
+       WebCore/loader/DocumentThreadableLoader.h \
        WebCore/loader/EmptyClients.h \
        WebCore/loader/FTPDirectoryDocument.cpp \
        WebCore/loader/FTPDirectoryDocument.h \
@@ -1084,6 +1086,9 @@ webcore_sources += \
        WebCore/loader/TextDocument.h \
        WebCore/loader/TextResourceDecoder.cpp \
        WebCore/loader/TextResourceDecoder.h \
+       WebCore/loader/ThreadableLoader.cpp \
+       WebCore/loader/ThreadableLoader.h \
+       WebCore/loader/ThreadableLoaderClient.h \
        WebCore/loader/archive/Archive.h \
        WebCore/loader/archive/ArchiveFactory.cpp \
        WebCore/loader/archive/ArchiveFactory.h \
index 64b98f7..16defe0 100644 (file)
@@ -786,6 +786,7 @@ SOURCES += \
     loader/CachedXSLStyleSheet.cpp \
     loader/DocLoader.cpp \
     loader/DocumentLoader.cpp \
+    loader/DocumentThreadableLoader.cpp \
     loader/FormState.cpp \
     loader/FrameLoader.cpp \
     loader/FrameLoaderClient.cpp \
@@ -806,6 +807,7 @@ SOURCES += \
     loader/SubresourceLoader.cpp \
     loader/TextDocument.cpp \
     loader/TextResourceDecoder.cpp \
+    loader/ThreadableLoader.cpp \
     page/AccessibilityImageMapLink.cpp \
     page/AccessibilityObject.cpp \    
     page/AccessibilityList.cpp \    
index c981c73..2c4007a 100644 (file)
@@ -335,6 +335,7 @@ sources['loader'] = [
     'loader/CachedXSLStyleSheet.cpp',
     'loader/DocLoader.cpp',
     'loader/DocumentLoader.cpp',
+    'loader/DocumentThreadableLoader.cpp',
     'loader/FormState.cpp',
     'loader/FrameLoader.cpp',
     'loader/FTPDirectoryDocument.cpp',
@@ -353,6 +354,7 @@ sources['loader'] = [
     'loader/SubresourceLoader.cpp',
     'loader/TextDocument.cpp',
     'loader/TextResourceDecoder.cpp',
+    'loader/ThreadableLoader.cpp',
     'loader/UserStyleSheetLoader.cpp',
 ]
 sources['page'] = [
index 1a0aad0..cce4ac7 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\loader\DocumentThreadableLoader.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\loader\DocumentThreadableLoader.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="..\loader\FormState.cpp"\r
                                >\r
                        </File>\r
                                RelativePath="..\loader\TextResourceDecoder.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\loader\ThreadableLoader.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\loader\ThreadableLoader.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\loader\ThreadableLoaderClient.h"\r
+                               >\r
+                       </File>\r
                        <Filter\r
                                Name="icon"\r
                                >\r
index 702ec7c..abc7a99 100644 (file)
                08E6E0F10EFF42BA00029FBF /* WMLFieldSetElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08E6E0EF0EFF42BA00029FBF /* WMLFieldSetElement.cpp */; };
                08E6E0F20EFF42BA00029FBF /* WMLFieldSetElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 08E6E0F00EFF42BA00029FBF /* WMLFieldSetElement.h */; };
                0A4844990CA44CB200B7BD48 /* SoftLinking.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A4844980CA44CB200B7BD48 /* SoftLinking.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               0B9056190F2578BE0095FF6A /* DocumentThreadableLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B9056150F2578BE0095FF6A /* DocumentThreadableLoader.cpp */; };
+               0B90561A0F2578BF0095FF6A /* DocumentThreadableLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B9056160F2578BE0095FF6A /* DocumentThreadableLoader.h */; settings = {ATTRIBUTES = (); }; };
+               0B90561B0F2578BF0095FF6A /* ThreadableLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B9056170F2578BE0095FF6A /* ThreadableLoader.h */; settings = {ATTRIBUTES = (); }; };
+               0B90561C0F2578BF0095FF6A /* ThreadableLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B9056180F2578BE0095FF6A /* ThreadableLoaderClient.h */; settings = {ATTRIBUTES = (); }; };
+               0B90561E0F257E930095FF6A /* ThreadableLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B90561D0F257E930095FF6A /* ThreadableLoader.cpp */; };
                0BA5D3860F240FB4009B870B /* GenericWorkerTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 0BA5D3850F240FB4009B870B /* GenericWorkerTask.h */; };
                0F56028F0E4B76580065B038 /* RenderMarquee.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F56028D0E4B76580065B038 /* RenderMarquee.h */; };
                0F5602900E4B76580065B038 /* RenderMarquee.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F56028E0E4B76580065B038 /* RenderMarquee.cpp */; };
                08FB84B00ECE373300DC064E /* WMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLElementFactory.cpp; sourceTree = "<group>"; };
                08FB84B10ECE373300DC064E /* WMLElementFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLElementFactory.h; sourceTree = "<group>"; };
                0A4844980CA44CB200B7BD48 /* SoftLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SoftLinking.h; sourceTree = "<group>"; };
+               0B9056150F2578BE0095FF6A /* DocumentThreadableLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentThreadableLoader.cpp; sourceTree = "<group>"; };
+               0B9056160F2578BE0095FF6A /* DocumentThreadableLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentThreadableLoader.h; sourceTree = "<group>"; };
+               0B9056170F2578BE0095FF6A /* ThreadableLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadableLoader.h; sourceTree = "<group>"; };
+               0B9056180F2578BE0095FF6A /* ThreadableLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadableLoaderClient.h; sourceTree = "<group>"; };
+               0B90561D0F257E930095FF6A /* ThreadableLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadableLoader.cpp; sourceTree = "<group>"; };
                0BA5D3850F240FB4009B870B /* GenericWorkerTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GenericWorkerTask.h; sourceTree = "<group>"; };
                0F56028D0E4B76580065B038 /* RenderMarquee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMarquee.h; sourceTree = "<group>"; };
                0F56028E0E4B76580065B038 /* RenderMarquee.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMarquee.cpp; sourceTree = "<group>"; };
                                BCB16C110979C3BD00467741 /* DocLoader.h */,
                                93E227DB0AF589AD00D48324 /* DocumentLoader.cpp */,
                                656D371E0ADBA5DE00A4554D /* DocumentLoader.h */,
+                               0B9056150F2578BE0095FF6A /* DocumentThreadableLoader.cpp */,
+                               0B9056160F2578BE0095FF6A /* DocumentThreadableLoader.h */,
                                B255990D0D00D8B900BB825C /* EmptyClients.h */,
                                51E4ADB20C42B4CF0042BC55 /* FTPDirectoryDocument.cpp */,
                                51E4ADB30C42B4CF0042BC55 /* FTPDirectoryDocument.h */,
                                1A6938000A11100A00C127FE /* TextDocument.h */,
                                F523D27802DE43D7018635CA /* TextResourceDecoder.cpp */,
                                F523D27902DE43D7018635CA /* TextResourceDecoder.h */,
+                               0B90561D0F257E930095FF6A /* ThreadableLoader.cpp */,
+                               0B9056170F2578BE0095FF6A /* ThreadableLoader.h */,
+                               0B9056180F2578BE0095FF6A /* ThreadableLoaderClient.h */,
                                7284ADDB0E6FEB31002EEFBD /* UserStyleSheetLoader.cpp */,
                                7284ADDC0E6FEB31002EEFBD /* UserStyleSheetLoader.h */,
                                BCB16C130979C3BD00467741 /* loader.cpp */,
                                A8185F3D09765766005826D9 /* DocumentFragment.h in Headers */,
                                656D37360ADBA5DE00A4554D /* DocumentLoader.h in Headers */,
                                ED2BA83C09A24B91006C0AC4 /* DocumentMarker.h in Headers */,
+                               0B90561A0F2578BF0095FF6A /* DocumentThreadableLoader.h in Headers */,
                                A8185F3909765766005826D9 /* DocumentType.h in Headers */,
                                A718760E0B2A120100A16ECE /* DragActions.h in Headers */,
                                A7CA59630B27C1F200FA021D /* DragClient.h in Headers */,
                                BCE659A90EA927B9007E4533 /* ThemeTypes.h in Headers */,
                                51DF6D7E0B92A16D00C2DC85 /* ThreadCheck.h in Headers */,
                                E1FF57A30F01255B00891EBB /* ThreadGlobalData.h in Headers */,
+                               0B90561B0F2578BF0095FF6A /* ThreadableLoader.h in Headers */,
+                               0B90561C0F2578BF0095FF6A /* ThreadableLoaderClient.h in Headers */,
                                E44613B00CD6331000FADA75 /* TimeRanges.h in Headers */,
                                9305B24D098F1B6B00C28855 /* Timer.h in Headers */,
                                49E912AE0EFAC906009D0CAF /* TimingFunction.h in Headers */,
                                A8185F3F09765766005826D9 /* DocumentFragment.cpp in Sources */,
                                93E227E00AF589AD00D48324 /* DocumentLoader.cpp in Sources */,
                                1C26497A0D7E248A00BD10F2 /* DocumentLoaderMac.cpp in Sources */,
+                               0B9056190F2578BE0095FF6A /* DocumentThreadableLoader.cpp in Sources */,
                                A8185F3A09765766005826D9 /* DocumentType.cpp in Sources */,
                                A7CA595E0B27BD9E00FA021D /* DragController.cpp in Sources */,
                                A71878900B2D04AC00A16ECE /* DragControllerMac.mm in Sources */,
                                BCE659E90EA92FFA007E4533 /* ThemeMac.mm in Sources */,
                                51DF6D800B92A18E00C2DC85 /* ThreadCheck.mm in Sources */,
                                E1FF57A60F01256B00891EBB /* ThreadGlobalData.cpp in Sources */,
+                               0B90561E0F257E930095FF6A /* ThreadableLoader.cpp in Sources */,
                                E44613AF0CD6331000FADA75 /* TimeRanges.cpp in Sources */,
                                93309EA4099EB78C0056E581 /* Timer.cpp in Sources */,
                                49E911CF0EF86D47009D0CAF /* TransformOperations.cpp in Sources */,
index 48cf6fd..94b782e 100644 (file)
@@ -635,6 +635,7 @@ This file contains the list of files needed to build WebCore.
         loader/CachedXSLStyleSheet.cpp
         loader/DocLoader.cpp
         loader/DocumentLoader.cpp
+        loader/DocumentThreadableLoader.cpp
         loader/FormState.cpp
         loader/FrameLoader.cpp
         loader/FrameLoaderClient.cpp
@@ -653,6 +654,7 @@ This file contains the list of files needed to build WebCore.
         loader/SubresourceLoader.cpp
         loader/TextDocument.cpp
         loader/TextResourceDecoder.cpp
+        loader/ThreadableLoader.cpp
         loader/loader.cpp
     </set>
     
diff --git a/WebCore/loader/DocumentThreadableLoader.cpp b/WebCore/loader/DocumentThreadableLoader.cpp
new file mode 100644 (file)
index 0000000..05f8667
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DocumentThreadableLoader.h"
+
+#include "AuthenticationChallenge.h"
+#include "Document.h"
+#include "ResourceRequest.h"
+#include "SecurityOrigin.h"
+#include "SubresourceLoader.h"
+#include "ThreadableLoaderClient.h"
+
+namespace WebCore {
+
+PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document* document, ThreadableLoaderClient* client, const ResourceRequest& request, LoadCallbacks callbacksSetting, ContentSniff contentSniff)
+{
+    RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, request, callbacksSetting, contentSniff));
+    if (!loader->m_loader)
+        loader = 0;
+    return loader.release();
+}
+
+DocumentThreadableLoader::DocumentThreadableLoader(Document* document, ThreadableLoaderClient* client, const ResourceRequest& request, LoadCallbacks callbacksSetting, ContentSniff contentSniff)
+    : m_client(client)
+    , m_document(document)
+{
+    ASSERT(document);
+    ASSERT(client);
+    m_loader = SubresourceLoader::create(document->frame(), this, request, false, callbacksSetting == SendLoadCallbacks, contentSniff == SniffContent);
+}
+
+DocumentThreadableLoader::~DocumentThreadableLoader()
+{
+    if (m_loader)
+        m_loader->clearClient();
+}
+
+void DocumentThreadableLoader::cancel()
+{
+    if (!m_loader)
+        return;
+
+    m_loader->cancel();
+    m_loader->clearClient();
+    m_loader = 0;
+    m_client = 0;
+}
+
+void DocumentThreadableLoader::willSendRequest(SubresourceLoader*, ResourceRequest& request, const ResourceResponse&)
+{
+    ASSERT(m_client);
+
+    // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.
+    if (!m_document->securityOrigin()->canRequest(request.url())) {
+        RefPtr<DocumentThreadableLoader> protect(this);
+        m_client->didFail();
+        cancel();
+    }
+}
+
+void DocumentThreadableLoader::didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
+{
+    ASSERT(m_client);
+    m_client->didSendData(bytesSent, totalBytesToBeSent);
+}
+
+void DocumentThreadableLoader::didReceiveResponse(SubresourceLoader*, const ResourceResponse& response)
+{
+    ASSERT(m_client);
+    m_client->didReceiveResponse(response);
+}
+
+void DocumentThreadableLoader::didReceiveData(SubresourceLoader*, const char* data, int lengthReceived)
+{
+    ASSERT(m_client);
+    m_client->didReceiveData(data, lengthReceived);
+}
+
+void DocumentThreadableLoader::didFinishLoading(SubresourceLoader* loader)
+{
+    ASSERT(loader);
+    ASSERT(m_client);
+    m_client->didFinishLoading(loader->identifier());
+}
+
+void DocumentThreadableLoader::didFail(SubresourceLoader*, const ResourceError& error)
+{
+    ASSERT(m_client);
+    if (error.isCancellation())
+        m_client->didGetCancelled();
+    else
+        m_client->didFail();
+}
+
+void DocumentThreadableLoader::receivedCancellation(SubresourceLoader*, const AuthenticationChallenge& challenge)
+{
+    ASSERT(m_client);
+    m_client->didReceiveAuthenticationCancellation(challenge.failureResponse());
+}
+
+} // namespace WebCore
diff --git a/WebCore/loader/DocumentThreadableLoader.h b/WebCore/loader/DocumentThreadableLoader.h
new file mode 100644 (file)
index 0000000..d909091
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DocumentThreadableLoader_h
+#define DocumentThreadableLoader_h
+
+#include "SubresourceLoaderClient.h"
+#include "ThreadableLoader.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+    class Document;
+    class ResourceRequest;
+    class ThreadableLoaderClient;
+
+    class DocumentThreadableLoader : public RefCounted<DocumentThreadableLoader>, public ThreadableLoader, private SubresourceLoaderClient  {
+    public:
+        static PassRefPtr<DocumentThreadableLoader> create(Document*, ThreadableLoaderClient*, const ResourceRequest&, LoadCallbacks, ContentSniff);
+        virtual ~DocumentThreadableLoader();
+
+        virtual void cancel();
+
+        using RefCounted<DocumentThreadableLoader>::ref;
+        using RefCounted<DocumentThreadableLoader>::deref;
+
+    protected:
+        virtual void refThreadableLoader() { ref(); }
+        virtual void derefThreadableLoader() { deref(); }
+
+    private:
+        DocumentThreadableLoader(Document*, ThreadableLoaderClient*, const ResourceRequest&, LoadCallbacks, ContentSniff);
+        virtual void willSendRequest(SubresourceLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
+        virtual void didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
+
+        virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
+        virtual void didReceiveData(SubresourceLoader*, const char*, int lengthReceived);
+        virtual void didFinishLoading(SubresourceLoader*);
+        virtual void didFail(SubresourceLoader*, const ResourceError&);
+
+        virtual void receivedCancellation(SubresourceLoader*, const AuthenticationChallenge&);
+
+        RefPtr<SubresourceLoader> m_loader;
+        ThreadableLoaderClient* m_client;
+        Document* m_document;
+    };
+
+} // namespace WebCore
+
+#endif // DocumentThreadableLoader_h
index 4e14dea..76fde47 100644 (file)
@@ -46,7 +46,7 @@ public:
     virtual void didSendData(SubresourceLoader*, unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { }
 
     virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&) { }
-    virtual void didReceiveData(SubresourceLoader*, const char*, int) { }
+    virtual void didReceiveData(SubresourceLoader*, const char*, int /*lengthReceived*/) { }
     virtual void didFinishLoading(SubresourceLoader*) { }
     virtual void didFail(SubresourceLoader*, const ResourceError&) { }
     
diff --git a/WebCore/loader/ThreadableLoader.cpp b/WebCore/loader/ThreadableLoader.cpp
new file mode 100644 (file)
index 0000000..0f22fbe
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ThreadableLoader.h"
+
+#include "DocumentThreadableLoader.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+PassRefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext* context, ThreadableLoaderClient* client, const ResourceRequest& request, LoadCallbacks callbacksSetting, ContentSniff contentSniff) 
+{
+    ASSERT(client);
+    ASSERT(context);
+    ASSERT(context->isDocument());
+
+    return DocumentThreadableLoader::create(static_cast<Document*>(context), client, request, callbacksSetting, contentSniff);
+}
+
+unsigned long ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context, const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& data)
+{
+    ASSERT(context);
+    ASSERT(context->isDocument());
+
+    Document* document = static_cast<Document*>(context);
+    if (!document->frame())
+        return std::numeric_limits<unsigned long>::max();
+    return document->frame()->loader()->loadResourceSynchronously(request, error, response, data);
+}
+
+} // namespace WebCore
diff --git a/WebCore/loader/ThreadableLoader.h b/WebCore/loader/ThreadableLoader.h
new file mode 100644 (file)
index 0000000..e8ff058
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ThreadableLoader_h
+#define ThreadableLoader_h
+
+#include <wtf/Noncopyable.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+    class ResourceError;
+    class ResourceRequest;
+    class ResourceResponse;
+    class ScriptExecutionContext;
+    class ThreadableLoaderClient;
+
+    enum LoadCallbacks {
+        SendLoadCallbacks,
+        DoNotSendLoadCallbacks
+    };
+
+    enum ContentSniff {
+        SniffContent,
+        DoNotSniffContent
+    };
+
+    // Useful for doing loader operations from any thread (not threadsafe, 
+    // just able to run on threads other than the main thread).
+    class ThreadableLoader : Noncopyable {
+    public:
+        static PassRefPtr<ThreadableLoader> create(ScriptExecutionContext*, ThreadableLoaderClient*, const ResourceRequest&, LoadCallbacks, ContentSniff);
+        static unsigned long loadResourceSynchronously(ScriptExecutionContext*, const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data);
+
+        virtual void cancel() = 0;
+        void ref() { refThreadableLoader(); }
+        void deref() { derefThreadableLoader(); }
+
+    protected:
+        virtual ~ThreadableLoader() { }
+        virtual void refThreadableLoader() = 0;
+        virtual void derefThreadableLoader() = 0;
+    };
+
+} // namespace WebCore
+
+#endif // ThreadableLoader_h
diff --git a/WebCore/loader/ThreadableLoaderClient.h b/WebCore/loader/ThreadableLoaderClient.h
new file mode 100644 (file)
index 0000000..4fde404
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ThreadableLoaderClient_h
+#define ThreadableLoaderClient_h
+
+namespace WebCore {
+
+    class ResourceResponse;
+
+    class ThreadableLoaderClient {
+    public:
+        virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { }
+
+        virtual void didReceiveResponse(const ResourceResponse&) { }
+        virtual void didReceiveData(const char*, int /*lengthReceived*/) { }
+        virtual void didFinishLoading(unsigned long /*identifer*/) { }
+        virtual void didFail() { }
+        virtual void didGetCancelled() { }
+
+        virtual void didReceiveAuthenticationCancellation(const ResourceResponse&) { }
+
+    protected:
+        virtual ~ThreadableLoaderClient() { }
+    };
+
+} // namespace WebCore
+
+#endif // ThreadableLoaderClient_h
index 3328f63..e484686 100644 (file)
 #include "XMLHttpRequest.h"
 
 #include "CString.h"
-#include "Console.h"
 #include "DOMImplementation.h"
-#include "DOMWindow.h"
+#include "Document.h"
 #include "Event.h"
 #include "EventException.h"
 #include "EventListener.h"
 #include "EventNames.h"
 #include "File.h"
-#include "Frame.h"
-#include "FrameLoader.h"
 #include "HTTPParsers.h"
-#include "InspectorController.h"
 #include "KURL.h"
 #include "KURLHash.h"
-#include "Page.h"
+#include "ResourceError.h"
+#include "ResourceRequest.h"
+#include "ScriptExecutionContext.h"
 #include "Settings.h"
-#include "SubresourceLoader.h"
+#include "SystemTime.h"
 #include "TextResourceDecoder.h"
+#include "ThreadableLoader.h"
 #include "XMLHttpRequestException.h"
 #include "XMLHttpRequestProgressEvent.h"
 #include "XMLHttpRequestUpload.h"
@@ -323,7 +322,6 @@ XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext* context)
     , m_async(true)
     , m_includeCredentials(false)
     , m_state(UNSENT)
-    , m_identifier(std::numeric_limits<unsigned long>::max())
     , m_responseText("")
     , m_createdDocument(false)
     , m_error(false)
@@ -348,6 +346,16 @@ Document* XMLHttpRequest::document() const
     return static_cast<Document*>(scriptExecutionContext());
 }
 
+#if ENABLE(DASHBOARD_SUPPORT)
+bool XMLHttpRequest::usesDashboardBackwardCompatibilityMode() const
+{
+    if (scriptExecutionContext()->isWorkerContext())
+        return false;
+    Settings* settings = document()->settings();
+    return settings && settings->usesDashboardBackwardCompatibilityMode();
+}
+#endif
+
 XMLHttpRequest::State XMLHttpRequest::readyState() const
 {
     return m_state;
@@ -558,8 +566,7 @@ void XMLHttpRequest::send(Document* document, ExceptionCode& ec)
         String contentType = getRequestHeader("Content-Type");
         if (contentType.isEmpty()) {
 #if ENABLE(DASHBOARD_SUPPORT)
-            Settings* settings = document->settings();
-            if (settings && settings->usesDashboardBackwardCompatibilityMode())
+            if (usesDashboardBackwardCompatibilityMode())
                 setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded");
             else
 #endif
@@ -590,8 +597,7 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         String contentType = getRequestHeader("Content-Type");
         if (contentType.isEmpty()) {
 #if ENABLE(DASHBOARD_SUPPORT)
-            Settings* settings = document()->settings();
-            if (settings && settings->usesDashboardBackwardCompatibilityMode())
+            if (usesDashboardBackwardCompatibilityMode())
                 setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded");
             else
 #endif
@@ -805,15 +811,13 @@ void XMLHttpRequest::loadRequestSynchronously(ResourceRequest& request, Exceptio
     ResourceError error;
     ResourceResponse response;
 
-    if (document()->frame())
-        m_identifier = document()->frame()->loader()->loadResourceSynchronously(request, error, response, data);
-
+    unsigned long identifier = ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), request, error, response, data);
     m_loader = 0;
 
     // No exception for file:/// resources, see <rdar://problem/4962298>.
     // Also, if we have an HTTP response, then it wasn't a network error in fact.
     if (error.isNull() || request.url().isLocalFile() || response.httpStatusCode() > 0) {
-        processSyncLoadResults(data, response, ec);
+        processSyncLoadResults(identifier, data, response, ec);
         return;
     }
 
@@ -837,8 +841,9 @@ void XMLHttpRequest::loadRequestAsynchronously(ResourceRequest& request)
     // FIXME: Maybe create can return null for other reasons too?
     // We need to keep content sniffing enabled for local files due to CFNetwork not providing a MIME type
     // for local files otherwise, <rdar://problem/5671813>.
-    bool sendResourceLoadCallbacks = !m_inPreflight;
-    m_loader = SubresourceLoader::create(document()->frame(), this, request, false, sendResourceLoadCallbacks, request.url().isLocalFile());
+    LoadCallbacks callbacks = m_inPreflight ? DoNotSendLoadCallbacks : SendLoadCallbacks;
+    ContentSniff contentSniff =  request.url().isLocalFile() ? SniffContent : DoNotSniffContent;
+    m_loader = ThreadableLoader::create(scriptExecutionContext(), this, request, callbacks, contentSniff);
 
     if (m_loader) {
         // Neither this object nor the JavaScript wrapper should be deleted while
@@ -978,8 +983,7 @@ void XMLHttpRequest::setRequestHeader(const AtomicString& name, const String& va
 {
     if (m_state != OPENED || m_loader) {
 #if ENABLE(DASHBOARD_SUPPORT)
-        Settings* settings = document() ? document()->settings() : 0;
-        if (settings && settings->usesDashboardBackwardCompatibilityMode())
+        if (usesDashboardBackwardCompatibilityMode())
             return;
 #endif
 
@@ -1130,59 +1134,61 @@ String XMLHttpRequest::statusText(ExceptionCode& ec) const
     return String();
 }
 
-void XMLHttpRequest::processSyncLoadResults(const Vector<char>& data, const ResourceResponse& response, ExceptionCode& ec)
+void XMLHttpRequest::processSyncLoadResults(unsigned long identifier, const Vector<char>& data, const ResourceResponse& response, ExceptionCode& ec)
 {
     if (m_sameOriginRequest && !scriptExecutionContext()->securityOrigin()->canRequest(response.url())) {
         abort();
         return;
     }
     
-    didReceiveResponse(0, response);
+    didReceiveResponse(response);
     changeState(HEADERS_RECEIVED);
 
     const char* bytes = static_cast<const char*>(data.data());
     int len = static_cast<int>(data.size());
-    didReceiveData(0, bytes, len);
+    didReceiveData(bytes, len);
 
-    didFinishLoading(0);
+    didFinishLoading(identifier);
     if (m_error)
         ec = XMLHttpRequestException::NETWORK_ERR;
 }
 
-void XMLHttpRequest::didFail(SubresourceLoader*, const ResourceError& error)
+void XMLHttpRequest::didFail()
 {
     // If we are already in an error state, for instance we called abort(), bail out early.
     if (m_error)
         return;
 
-    if (error.isCancellation()) {
-        abortError();
+    internalAbort();
+    networkError();
+}
+
+void XMLHttpRequest::didGetCancelled()
+{
+    // If we are already in an error state, for instance we called abort(), bail out early.
+    if (m_error)
         return;
-    }
 
-    networkError();
-    return;
+    abortError();
 }
 
-void XMLHttpRequest::didFinishLoading(SubresourceLoader* loader)
+void XMLHttpRequest::didFinishLoading(unsigned long identifier)
 {
     if (m_error)
         return;
 
     if (m_inPreflight) {
-        didFinishLoadingPreflight(loader);
+        didFinishLoadingPreflight();
         return;
     }
 
-    ASSERT(loader == m_loader);
-
     if (m_state < HEADERS_RECEIVED)
         changeState(HEADERS_RECEIVED);
 
     if (m_decoder)
         m_responseText += m_decoder->flush();
 
-    scriptExecutionContext()->resourceRetrievedByXMLHttpRequest(m_loader ? m_loader->identifier() : m_identifier, m_responseText);
+    scriptExecutionContext()->resourceRetrievedByXMLHttpRequest(identifier, m_responseText);
     scriptExecutionContext()->addMessage(InspectorControllerDestination, JSMessageSource, LogMessageLevel, "XHR finished loading: \"" + m_url + "\".", m_lastSendLineNumber, m_lastSendURL);
 
     bool hadLoader = m_loader;
@@ -1195,7 +1201,7 @@ void XMLHttpRequest::didFinishLoading(SubresourceLoader* loader)
         dropProtection();
 }
 
-void XMLHttpRequest::didFinishLoadingPreflight(SubresourceLoader*)
+void XMLHttpRequest::didFinishLoadingPreflight()
 {
     ASSERT(m_inPreflight);
     ASSERT(!m_sameOriginRequest);
@@ -1208,16 +1214,7 @@ void XMLHttpRequest::didFinishLoadingPreflight(SubresourceLoader*)
         unsetPendingActivity(this);
 }
 
-void XMLHttpRequest::willSendRequest(SubresourceLoader*, ResourceRequest& request, const ResourceResponse&)
-{
-    // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.
-    if (!scriptExecutionContext()->securityOrigin()->canRequest(request.url())) {
-        internalAbort();
-        networkError();
-    }
-}
-
-void XMLHttpRequest::didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
+void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
 {
     if (!m_upload)
         return;
@@ -1253,10 +1250,10 @@ bool XMLHttpRequest::accessControlCheck(const ResourceResponse& response)
     return true;
 }
 
-void XMLHttpRequest::didReceiveResponse(SubresourceLoader* loader, const ResourceResponse& response)
+void XMLHttpRequest::didReceiveResponse(const ResourceResponse& response)
 {
     if (m_inPreflight) {
-        didReceiveResponsePreflight(loader, response);
+        didReceiveResponsePreflight(response);
         return;
     }
 
@@ -1273,7 +1270,7 @@ void XMLHttpRequest::didReceiveResponse(SubresourceLoader* loader, const Resourc
         m_responseEncoding = response.textEncodingName();
 }
 
-void XMLHttpRequest::didReceiveResponsePreflight(SubresourceLoader*, const ResourceResponse& response)
+void XMLHttpRequest::didReceiveResponsePreflight(const ResourceResponse& response)
 {
     ASSERT(m_inPreflight);
     ASSERT(!m_sameOriginRequest);
@@ -1284,17 +1281,9 @@ void XMLHttpRequest::didReceiveResponsePreflight(SubresourceLoader*, const Resou
     }
 
     OwnPtr<PreflightResultCacheItem> preflightResult(new PreflightResultCacheItem(m_includeCredentials));
-    if (!preflightResult->parse(response))  {
-        networkError();
-        return;
-    }
-
-    if (!preflightResult->allowsCrossSiteMethod(m_method)) {
-        networkError();
-        return;
-    }
-
-    if (!preflightResult->allowsCrossSiteHeaders(m_requestHeaders)) {
+    if (!preflightResult->parse(response)
+        || !preflightResult->allowsCrossSiteMethod(m_method)
+        || !preflightResult->allowsCrossSiteHeaders(m_requestHeaders)) {
         networkError();
         return;
     }
@@ -1302,12 +1291,12 @@ void XMLHttpRequest::didReceiveResponsePreflight(SubresourceLoader*, const Resou
     PreflightResultCache::shared().appendEntry(scriptExecutionContext()->securityOrigin()->toString(), m_url, preflightResult.release());
 }
 
-void XMLHttpRequest::receivedCancellation(SubresourceLoader*, const AuthenticationChallenge& challenge)
+void XMLHttpRequest::didReceiveAuthenticationCancellation(const ResourceResponse& failureResponse)
 {
-    m_response = challenge.failureResponse();
+    m_response = failureResponse;
 }
 
-void XMLHttpRequest::didReceiveData(SubresourceLoader*, const char* data, int len)
+void XMLHttpRequest::didReceiveData(const char* data, int len)
 {
     if (m_inPreflight)
         return;
@@ -1326,7 +1315,7 @@ void XMLHttpRequest::didReceiveData(SubresourceLoader*, const char* data, int le
         else
             m_decoder = TextResourceDecoder::create("text/plain", "UTF-8");
     }
-    if (len == 0)
+    if (!len)
         return;
 
     if (len == -1)
index 8d6cd30..d7c0d36 100644 (file)
 #include "EventTarget.h"
 #include "FormData.h"
 #include "ResourceResponse.h"
-#include "SubresourceLoaderClient.h"
 #include "ScriptString.h"
+#include "ThreadableLoaderClient.h"
 #include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
 class Document;
 class File;
+class ResourceRequest;
 class TextResourceDecoder;
+class ThreadableLoader;
 
-class XMLHttpRequest : public RefCounted<XMLHttpRequest>, public EventTarget, private SubresourceLoaderClient, public ActiveDOMObject {
+class XMLHttpRequest : public RefCounted<XMLHttpRequest>, public EventTarget, private ThreadableLoaderClient, public ActiveDOMObject {
 public:
     static PassRefPtr<XMLHttpRequest> create(ScriptExecutionContext* context) { return adoptRef(new XMLHttpRequest(context)); }
     ~XMLHttpRequest();
@@ -119,19 +121,23 @@ private:
 
     Document* document() const;
 
-    virtual void willSendRequest(SubresourceLoader*, ResourceRequest& request, const ResourceResponse& redirectResponse);
-    virtual void didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
-    virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
-    virtual void didReceiveData(SubresourceLoader*, const char* data, int size);
-    virtual void didFail(SubresourceLoader*, const ResourceError&);
-    virtual void didFinishLoading(SubresourceLoader*);
-    virtual void receivedCancellation(SubresourceLoader*, const AuthenticationChallenge&);
+#if ENABLE(DASHBOARD_SUPPORT)
+    bool usesDashboardBackwardCompatibilityMode() const;
+#endif
+
+    virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
+    virtual void didReceiveResponse(const ResourceResponse&);
+    virtual void didReceiveData(const char* data, int lengthReceived);
+    virtual void didFinishLoading(unsigned long identifier);
+    virtual void didFail();
+    virtual void didGetCancelled();
+    virtual void didReceiveAuthenticationCancellation(const ResourceResponse&);
 
     // Special versions for the preflight
-    void didReceiveResponsePreflight(SubresourceLoader*, const ResourceResponse&);
-    void didFinishLoadingPreflight(SubresourceLoader*);
+    void didReceiveResponsePreflight(const ResourceResponse&);
+    void didFinishLoadingPreflight();
 
-    void processSyncLoadResults(const Vector<char>& data, const ResourceResponse&, ExceptionCode&);
+    void processSyncLoadResults(unsigned long identifier, const Vector<char>& data, const ResourceResponse&, ExceptionCode&);
     void updateAndDispatchOnProgress(unsigned int len);
 
     String responseMIMEType() const;
@@ -198,16 +204,15 @@ private:
     bool m_async;
     bool m_includeCredentials;
 
-    RefPtr<SubresourceLoader> m_loader;
+    RefPtr<ThreadableLoader> m_loader;
     State m_state;
 
     ResourceResponse m_response;
     String m_responseEncoding;
 
     RefPtr<TextResourceDecoder> m_decoder;
-    unsigned long m_identifier;
 
-    // Unlike most strings in the DOM, we keep this as a JSC::UString, not a WebCore::String.
+    // Unlike most strings in the DOM, we keep this as a ScriptString, not a WebCore::String.
     // That's because these strings can easily get huge (they are filled from the network with
     // no parsing) and because JS can easily observe many intermediate states, so it's very useful
     // to be able to share the buffer with JavaScript versions of the whole or partial string.