2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "DocumentThreadableLoader.h"
34 #include "AuthenticationChallenge.h"
36 #include "ResourceRequest.h"
37 #include "SecurityOrigin.h"
38 #include "SubresourceLoader.h"
39 #include "ThreadableLoaderClient.h"
43 PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document* document, ThreadableLoaderClient* client, const ResourceRequest& request, LoadCallbacks callbacksSetting, ContentSniff contentSniff)
45 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, request, callbacksSetting, contentSniff));
46 if (!loader->m_loader)
48 return loader.release();
51 DocumentThreadableLoader::DocumentThreadableLoader(Document* document, ThreadableLoaderClient* client, const ResourceRequest& request, LoadCallbacks callbacksSetting, ContentSniff contentSniff)
53 , m_document(document)
57 m_loader = SubresourceLoader::create(document->frame(), this, request, false, callbacksSetting == SendLoadCallbacks, contentSniff == SniffContent);
60 DocumentThreadableLoader::~DocumentThreadableLoader()
63 m_loader->clearClient();
66 void DocumentThreadableLoader::cancel()
72 m_loader->clearClient();
77 void DocumentThreadableLoader::willSendRequest(SubresourceLoader*, ResourceRequest& request, const ResourceResponse&)
81 // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.
82 if (!m_document->securityOrigin()->canRequest(request.url())) {
83 RefPtr<DocumentThreadableLoader> protect(this);
89 void DocumentThreadableLoader::didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
92 m_client->didSendData(bytesSent, totalBytesToBeSent);
95 void DocumentThreadableLoader::didReceiveResponse(SubresourceLoader*, const ResourceResponse& response)
98 m_client->didReceiveResponse(response);
101 void DocumentThreadableLoader::didReceiveData(SubresourceLoader*, const char* data, int lengthReceived)
104 m_client->didReceiveData(data, lengthReceived);
107 void DocumentThreadableLoader::didFinishLoading(SubresourceLoader* loader)
111 m_client->didFinishLoading(loader->identifier());
114 void DocumentThreadableLoader::didFail(SubresourceLoader*, const ResourceError& error)
117 if (error.isCancellation())
118 m_client->didGetCancelled();
123 void DocumentThreadableLoader::receivedCancellation(SubresourceLoader*, const AuthenticationChallenge& challenge)
126 m_client->didReceiveAuthenticationCancellation(challenge.failureResponse());
129 } // namespace WebCore