2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef DocumentThreadableLoader_h
33 #define DocumentThreadableLoader_h
35 #include "core/fetch/RawResource.h"
36 #include "core/fetch/ResourceOwner.h"
37 #include "core/loader/ThreadableLoader.h"
38 #include "platform/Timer.h"
39 #include "platform/network/HTTPHeaderMap.h"
40 #include "platform/network/ResourceError.h"
41 #include "wtf/Forward.h"
42 #include "wtf/OwnPtr.h"
43 #include "wtf/PassRefPtr.h"
44 #include "wtf/text/WTFString.h"
50 class ResourceRequest;
52 class ThreadableLoaderClient;
54 class DocumentThreadableLoader FINAL : public ThreadableLoader, private ResourceOwner<RawResource> {
55 WTF_MAKE_FAST_ALLOCATED;
57 static void loadResourceSynchronously(Document&, const ResourceRequest&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoaderOptions&);
58 static PassRefPtr<DocumentThreadableLoader> create(Document&, ThreadableLoaderClient*, const ResourceRequest&, const ThreadableLoaderOptions&, const ResourceLoaderOptions&);
59 virtual ~DocumentThreadableLoader();
61 virtual void cancel() OVERRIDE;
62 void setDefersLoading(bool);
65 enum BlockingBehavior {
70 DocumentThreadableLoader(Document&, ThreadableLoaderClient*, BlockingBehavior, const ResourceRequest&, const ThreadableLoaderOptions&, const ResourceLoaderOptions&);
72 // RawResourceClient implementation
73 virtual void dataSent(Resource*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent) OVERRIDE;
74 virtual void responseReceived(Resource*, const ResourceResponse&) OVERRIDE;
75 virtual void dataReceived(Resource*, const char* data, int dataLength) OVERRIDE;
76 virtual void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&) OVERRIDE;
77 virtual void notifyFinished(Resource*) OVERRIDE;
78 virtual void dataDownloaded(Resource*, int) OVERRIDE;
80 void cancelWithError(const ResourceError&);
82 // Methods containing code to handle resource fetch results which is
83 // common to both sync and async mode.
84 void handleResponse(unsigned long identifier, const ResourceResponse&);
85 void handleReceivedData(const char* data, int dataLength);
86 void handleSuccessfulFinish(unsigned long identifier, double finishTime);
88 void didTimeout(Timer<DocumentThreadableLoader>*);
89 void makeCrossOriginAccessRequest(const ResourceRequest&);
90 // Loads m_actualRequest.
91 void loadActualRequest();
92 // Clears m_actualRequest and reports access control check failure to
94 void handlePreflightFailure(const String& url, const String& errorDescription);
95 // Investigates the response for the preflight request. If successful,
96 // the actual request will be made later in handleSuccessfulFinish().
97 void handlePreflightResponse(unsigned long identifier, const ResourceResponse&);
99 void loadRequest(const ResourceRequest&, ResourceLoaderOptions);
100 bool isAllowedRedirect(const KURL&) const;
101 bool isAllowedByPolicy(const KURL&) const;
102 // Returns DoNotAllowStoredCredentials
103 // if m_forceDoNotAllowStoredCredentials is set. Otherwise, just
104 // returns allowCredentials value of m_resourceLoaderOptions.
105 StoredCredentials effectiveAllowCredentials() const;
107 SecurityOrigin* securityOrigin() const;
109 ThreadableLoaderClient* m_client;
110 Document& m_document;
112 const ThreadableLoaderOptions m_options;
113 // Some items may be overridden by m_forceDoNotAllowStoredCredentials
114 // and m_securityOrigin. In such a case, build a ResourceLoaderOptions
115 // with up-to-date values from them and this variable, and use it.
116 const ResourceLoaderOptions m_resourceLoaderOptions;
118 bool m_forceDoNotAllowStoredCredentials;
119 RefPtr<SecurityOrigin> m_securityOrigin;
121 bool m_sameOriginRequest;
122 bool m_simpleRequest;
125 // Holds the original request and options for it during preflight
126 // request handling phase.
127 OwnPtr<ResourceRequest> m_actualRequest;
128 OwnPtr<ResourceLoaderOptions> m_actualOptions;
130 HTTPHeaderMap m_simpleRequestHeaders; // stores simple request headers in case of a cross-origin redirect.
131 Timer<DocumentThreadableLoader> m_timeoutTimer;
134 } // namespace WebCore
136 #endif // DocumentThreadableLoader_h