1406584a11bfd900398258c84350db4daa7dce3c
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / loader / DocumentLoader.h
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2011 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef DocumentLoader_h
31 #define DocumentLoader_h
32
33 #include "core/fetch/RawResource.h"
34 #include "core/fetch/ResourceLoaderOptions.h"
35 #include "core/fetch/ResourcePtr.h"
36 #include "core/loader/DocumentLoadTiming.h"
37 #include "core/loader/DocumentWriter.h"
38 #include "core/loader/NavigationAction.h"
39 #include "core/loader/SubstituteData.h"
40 #include "platform/network/ResourceError.h"
41 #include "platform/network/ResourceRequest.h"
42 #include "platform/network/ResourceResponse.h"
43 #include "wtf/HashSet.h"
44 #include "wtf/RefPtr.h"
45
46 namespace blink {
47 class WebThreadedDataReceiver;
48 }
49
50 namespace WTF {
51 class SchedulePair;
52 }
53
54 namespace blink {
55     class ApplicationCacheHost;
56     class ArchiveResource;
57     class ArchiveResourceCollection;
58     class ResourceFetcher;
59     class ContentFilter;
60     class FormState;
61     class LocalFrame;
62     class FrameLoader;
63     class MHTMLArchive;
64     class Page;
65     class ResourceLoader;
66     class SharedBuffer;
67
68     class DocumentLoader : public RefCounted<DocumentLoader>, private RawResourceClient {
69         WTF_MAKE_FAST_ALLOCATED;
70     public:
71         static PassRefPtr<DocumentLoader> create(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data)
72         {
73             return adoptRef(new DocumentLoader(frame, request, data));
74         }
75         virtual ~DocumentLoader();
76
77         LocalFrame* frame() const { return m_frame; }
78
79         void detachFromFrame();
80
81         unsigned long mainResourceIdentifier() const;
82
83         void replaceDocument(const String& source, Document*);
84
85         const AtomicString& mimeType() const;
86
87         void setUserChosenEncoding(const String& charset);
88
89         const ResourceRequest& originalRequest() const;
90
91         const ResourceRequest& request() const;
92
93         ResourceFetcher* fetcher() const { return m_fetcher.get(); }
94
95         const SubstituteData& substituteData() const { return m_substituteData; }
96
97         const KURL& url() const;
98         const KURL& unreachableURL() const;
99         const KURL& urlForHistory() const;
100
101         const AtomicString& responseMIMEType() const;
102
103         void updateForSameDocumentNavigation(const KURL&, SameDocumentNavigationSource);
104         void stopLoading();
105         bool isCommitted() const { return m_committed; }
106         bool isLoading() const;
107         bool isLoadingMainResource() const { return m_loadingMainResource; }
108         const ResourceResponse& response() const { return m_response; }
109         const ResourceError& mainDocumentError() const { return m_mainDocumentError; }
110         bool isClientRedirect() const { return m_isClientRedirect; }
111         void setIsClientRedirect(bool isClientRedirect) { m_isClientRedirect = isClientRedirect; }
112         bool replacesCurrentHistoryItem() const { return m_replacesCurrentHistoryItem; }
113         void setReplacesCurrentHistoryItem(bool replacesCurrentHistoryItem) { m_replacesCurrentHistoryItem = replacesCurrentHistoryItem; }
114         const AtomicString& overrideEncoding() const { return m_overrideEncoding; }
115
116         bool scheduleArchiveLoad(Resource*, const ResourceRequest&);
117
118         bool shouldContinueForNavigationPolicy(const ResourceRequest&, ContentSecurityPolicyCheck shouldCheckMainWorldContentSecurityPolicy, bool isTransitionNavigation = false);
119         const NavigationAction& triggeringAction() const { return m_triggeringAction; }
120         void setTriggeringAction(const NavigationAction& action) { m_triggeringAction = action; }
121
122         void setOverrideEncoding(const AtomicString& encoding) { m_overrideEncoding = encoding; }
123
124         void setDefersLoading(bool);
125
126         void startLoadingMainResource();
127         void cancelMainResourceLoad(const ResourceError&);
128
129         void attachThreadedDataReceiver(PassOwnPtr<blink::WebThreadedDataReceiver>);
130         DocumentLoadTiming* timing() { return &m_documentLoadTiming; }
131
132         ApplicationCacheHost* applicationCacheHost() const { return m_applicationCacheHost.get(); }
133
134         bool isRedirect() const { return m_redirectChain.size() > 1; }
135         void clearRedirectChain();
136         void appendRedirect(const KURL&);
137
138     protected:
139         DocumentLoader(LocalFrame*, const ResourceRequest&, const SubstituteData&);
140
141         Vector<KURL> m_redirectChain;
142
143     private:
144         static PassRefPtrWillBeRawPtr<DocumentWriter> createWriterFor(LocalFrame*, const Document* ownerDocument, const KURL&, const AtomicString& mimeType, const AtomicString& encoding, bool dispatch);
145
146         void ensureWriter(const AtomicString& mimeType, const KURL& overridingURL = KURL());
147         void endWriting(DocumentWriter*);
148
149         Document* document() const;
150         FrameLoader* frameLoader() const;
151
152         void commitIfReady();
153         void commitData(const char* bytes, size_t length);
154         void setMainDocumentError(const ResourceError&);
155         void clearMainResourceLoader();
156         ResourceLoader* mainResourceLoader() const;
157         void clearMainResourceHandle();
158
159         bool maybeCreateArchive();
160
161         void prepareSubframeArchiveLoadIfNeeded();
162         void addAllArchiveResources(MHTMLArchive*);
163
164         void willSendRequest(ResourceRequest&, const ResourceResponse&);
165         void finishedLoading(double finishTime);
166         void mainReceivedError(const ResourceError&);
167         virtual void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&) OVERRIDE FINAL;
168         virtual void updateRequest(Resource*, const ResourceRequest&) OVERRIDE FINAL;
169         virtual void responseReceived(Resource*, const ResourceResponse&) OVERRIDE FINAL;
170         virtual void dataReceived(Resource*, const char* data, int length) OVERRIDE FINAL;
171         virtual void notifyFinished(Resource*) OVERRIDE FINAL;
172
173         bool maybeLoadEmpty();
174
175         bool isRedirectAfterPost(const ResourceRequest&, const ResourceResponse&);
176
177         bool shouldContinueForResponse() const;
178
179         LocalFrame* m_frame;
180         RefPtrWillBePersistent<ResourceFetcher> m_fetcher;
181
182         ResourcePtr<RawResource> m_mainResource;
183
184         RefPtrWillBePersistent<DocumentWriter> m_writer;
185
186         // A reference to actual request used to create the data source.
187         // The only part of this request that should change is the url, and
188         // that only in the case of a same-document navigation.
189         ResourceRequest m_originalRequest;
190
191         SubstituteData m_substituteData;
192
193         // The 'working' request. It may be mutated
194         // several times from the original request to include additional
195         // headers, cookie information, canonicalization and redirects.
196         ResourceRequest m_request;
197
198         ResourceResponse m_response;
199
200         ResourceError m_mainDocumentError;
201
202         bool m_committed;
203         bool m_isClientRedirect;
204         bool m_replacesCurrentHistoryItem;
205
206         AtomicString m_overrideEncoding;
207
208         // The action that triggered loading - we keep this around for the
209         // benefit of the various policy handlers.
210         NavigationAction m_triggeringAction;
211
212         OwnPtrWillBePersistent<ArchiveResourceCollection> m_archiveResourceCollection;
213         RefPtrWillBePersistent<MHTMLArchive> m_archive;
214
215         bool m_loadingMainResource;
216         DocumentLoadTiming m_documentLoadTiming;
217
218         double m_timeOfLastDataReceived;
219
220         friend class ApplicationCacheHost;  // for substitute resource delivery
221         OwnPtr<ApplicationCacheHost> m_applicationCacheHost;
222     };
223 }
224
225 #endif // DocumentLoader_h