Returning NULL from willSendRequest should cancel a load from the memory cache
[WebKit-https.git] / Source / WebCore / loader / DocumentThreadableLoader.h
1 /*
2  * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef DocumentThreadableLoader_h
32 #define DocumentThreadableLoader_h
33
34 #include "CachedRawResource.h"
35 #include "CachedResourceHandle.h"
36 #include "FrameLoaderTypes.h"
37 #include "ThreadableLoader.h"
38 #include <wtf/Forward.h>
39 #include <wtf/OwnPtr.h>
40 #include <wtf/PassRefPtr.h>
41 #include <wtf/RefCounted.h>
42 #include <wtf/RefPtr.h>
43 #include <wtf/text/WTFString.h>
44
45 namespace WebCore {
46     class Document;
47     class KURL;
48     class ResourceRequest;
49     class SecurityOrigin;
50     class ThreadableLoaderClient;
51
52     class DocumentThreadableLoader : public RefCounted<DocumentThreadableLoader>, public ThreadableLoader, private CachedRawResourceClient  {
53         WTF_MAKE_FAST_ALLOCATED;
54     public:
55         static void loadResourceSynchronously(Document*, const ResourceRequest&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
56         static PassRefPtr<DocumentThreadableLoader> create(Document*, ThreadableLoaderClient*, const ResourceRequest&, const ThreadableLoaderOptions&);
57         virtual ~DocumentThreadableLoader();
58
59         virtual void cancel();
60         virtual void setDefersLoading(bool);
61
62         using RefCounted<DocumentThreadableLoader>::ref;
63         using RefCounted<DocumentThreadableLoader>::deref;
64
65     protected:
66         virtual void refThreadableLoader() { ref(); }
67         virtual void derefThreadableLoader() { deref(); }
68
69     private:
70         enum BlockingBehavior {
71             LoadSynchronously,
72             LoadAsynchronously
73         };
74
75         DocumentThreadableLoader(Document*, ThreadableLoaderClient*, BlockingBehavior, const ResourceRequest&, const ThreadableLoaderOptions&);
76
77         void clearResource();
78
79         // CachedRawResourceClient
80         virtual void dataSent(CachedResource*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
81         virtual void responseReceived(CachedResource*, const ResourceResponse&);
82         virtual void dataReceived(CachedResource*, const char* data, int dataLength);
83         virtual void redirectReceived(CachedResource*, ResourceRequest&, const ResourceResponse&);
84         virtual void notifyFinished(CachedResource*);
85
86         void didReceiveResponse(unsigned long identifier, const ResourceResponse&);
87         void didReceiveData(unsigned long identifier, const char* data, int dataLength);
88         void didFinishLoading(unsigned long identifier, double finishTime);
89         void didFail(unsigned long identifier, const ResourceError&);
90         void makeCrossOriginAccessRequest(const ResourceRequest&);
91         void makeSimpleCrossOriginAccessRequest(const ResourceRequest& request);
92         void makeCrossOriginAccessRequestWithPreflight(const ResourceRequest& request);
93         void preflightSuccess();
94         void preflightFailure(unsigned long identifier, const String& url, const String& errorDescription);
95
96         void loadRequest(const ResourceRequest&, SecurityCheckPolicy);
97         bool isAllowedRedirect(const KURL&);
98
99         SecurityOrigin* securityOrigin() const;
100
101         CachedResourceHandle<CachedRawResource> m_resource;
102         ThreadableLoaderClient* m_client;
103         Document* m_document;
104         ThreadableLoaderOptions m_options;
105         bool m_sameOriginRequest;
106         bool m_simpleRequest;
107         bool m_async;
108         OwnPtr<ResourceRequest> m_actualRequest;  // non-null during Access Control preflight checks
109     };
110
111 } // namespace WebCore
112
113 #endif // DocumentThreadableLoader_h