]> git.saurik.com Git - iphone-api.git/blob - WebCore/DocumentLoader.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / DocumentLoader.h
1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Apple 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
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef DocumentLoader_h
30 #define DocumentLoader_h
31
32 #include "NavigationAction.h"
33 #include "ResourceError.h"
34 #include "ResourceRequest.h"
35 #include "ResourceResponse.h"
36 #include "SubstituteData.h"
37 #include "Timer.h"
38
39 namespace WebCore {
40
41 class ApplicationCache;
42 class ApplicationCacheGroup;
43 class ApplicationCacheResource;
44 class Archive;
45 class ArchiveResource;
46 class ArchiveResourceCollection;
47 class CachedPage;
48 class Frame;
49 class FrameLoader;
50 class MainResourceLoader;
51 class ResourceLoader;
52 class SchedulePair;
53 class SharedBuffer;
54 class SubstituteResource;
55
56 typedef HashSet<RefPtr<ResourceLoader> > ResourceLoaderSet;
57 typedef Vector<ResourceResponse> ResponseVector;
58
59 class DocumentLoader : public RefCounted<DocumentLoader> {
60 public:
61 static PassRefPtr<DocumentLoader> create(const ResourceRequest& request, const SubstituteData& data)
62 {
63 return adoptRef(new DocumentLoader(request, data));
64 }
65 virtual ~DocumentLoader();
66
67 void setFrame(Frame*);
68 Frame* frame() const { return m_frame; }
69
70 virtual void attachToFrame();
71 virtual void detachFromFrame();
72
73 FrameLoader* frameLoader() const;
74 MainResourceLoader* mainResourceLoader() const { return m_mainResourceLoader.get(); }
75 PassRefPtr<SharedBuffer> mainResourceData() const;
76
77 const ResourceRequest& originalRequest() const;
78 const ResourceRequest& originalRequestCopy() const;
79
80 const ResourceRequest& request() const;
81 ResourceRequest& request();
82 void setRequest(const ResourceRequest&);
83
84 const SubstituteData& substituteData() const { return m_substituteData; }
85
86 const KURL& url() const;
87 const KURL& unreachableURL() const;
88
89 const KURL& originalURL() const;
90 const KURL& requestURL() const;
91 const KURL& responseURL() const;
92 const String& responseMIMEType() const;
93
94 void replaceRequestURLForAnchorScroll(const KURL&);
95 bool isStopping() const { return m_isStopping; }
96 void stopLoading();
97 void setCommitted(bool committed) { m_committed = committed; }
98 bool isCommitted() const { return m_committed; }
99 bool isLoading() const { return m_loading; }
100 void setLoading(bool loading) { m_loading = loading; }
101 void updateLoading();
102 void receivedData(const char*, int);
103 void setupForReplaceByMIMEType(const String& newMIMEType);
104 void finishedLoading();
105 const ResourceResponse& response() const { return m_response; }
106 const ResourceError& mainDocumentError() const { return m_mainDocumentError; }
107 void mainReceivedError(const ResourceError&, bool isComplete);
108 void setResponse(const ResourceResponse& response) { m_response = response; }
109 void prepareForLoadStart();
110 bool isClientRedirect() const { return m_isClientRedirect; }
111 void setIsClientRedirect(bool isClientRedirect) { m_isClientRedirect = isClientRedirect; }
112 bool isLoadingInAPISense() const;
113 void setPrimaryLoadComplete(bool);
114 void setTitle(const String&);
115 const String& overrideEncoding() const { return m_overrideEncoding; }
116
117 #if PLATFORM(MAC)
118 void schedule(SchedulePair*);
119 void unschedule(SchedulePair*);
120 #endif
121
122 void addAllArchiveResources(Archive*);
123 void addArchiveResource(PassRefPtr<ArchiveResource>);
124
125 // Return an ArchiveResource for the URL, either creating from live data or
126 // pulling from the ArchiveResourceCollection
127 PassRefPtr<ArchiveResource> subresource(const KURL&) const;
128 // Return the ArchiveResource for the URL only when loading an Archive
129 ArchiveResource* archiveResourceForURL(const KURL&) const;
130
131 PassRefPtr<Archive> popArchiveForSubframe(const String& frameName);
132 void clearArchiveResources();
133 void setParsedArchiveData(PassRefPtr<SharedBuffer>);
134 SharedBuffer* parsedArchiveData() const;
135
136 PassRefPtr<ArchiveResource> mainResource() const;
137 void getSubresources(Vector<PassRefPtr<ArchiveResource> >&) const;
138
139 bool scheduleArchiveLoad(ResourceLoader*, const ResourceRequest&, const KURL&);
140 #ifndef NDEBUG
141 bool isSubstituteLoadPending(ResourceLoader*) const;
142 #endif
143 void cancelPendingSubstituteLoad(ResourceLoader*);
144
145 void addResponse(const ResourceResponse&);
146 const ResponseVector& responses() const { return m_responses; }
147
148 const NavigationAction& triggeringAction() const { return m_triggeringAction; }
149 void setTriggeringAction(const NavigationAction& action) { m_triggeringAction = action; }
150 void setOverrideEncoding(const String& encoding) { m_overrideEncoding = encoding; }
151 void setLastCheckedRequest(const ResourceRequest& request) { m_lastCheckedRequest = request; }
152 const ResourceRequest& lastCheckedRequest() { return m_lastCheckedRequest; }
153
154 void stopRecordingResponses();
155 const String& title() const { return m_pageTitle; }
156
157 KURL urlForHistory() const;
158 bool urlForHistoryReflectsFailure() const;
159 bool urlForHistoryReflectsServerRedirect() const { return urlForHistory() != url(); }
160 bool urlForHistoryReflectsClientRedirect() const { return m_urlForHistoryReflectsClientRedirect; }
161 void setURLForHistoryReflectsClientRedirect(bool b) { m_urlForHistoryReflectsClientRedirect = b; }
162
163 void loadFromCachedPage(PassRefPtr<CachedPage>);
164 void setLoadingFromCachedPage(bool loading) { m_loadingFromCachedPage = loading; }
165 bool isLoadingFromCachedPage() const { return m_loadingFromCachedPage; }
166
167 void setDefersLoading(bool);
168
169 bool startLoadingMainResource(unsigned long identifier);
170 void cancelMainResourceLoad(const ResourceError&);
171
172 void iconLoadDecisionAvailable();
173
174 bool isLoadingMainResource() const;
175 bool isLoadingSubresources() const;
176 bool isLoadingPlugIns() const;
177 bool isLoadingMultipartContent() const;
178
179 void stopLoadingPlugIns();
180 void stopLoadingSubresources();
181
182 void addSubresourceLoader(ResourceLoader*);
183 void removeSubresourceLoader(ResourceLoader*);
184 void addPlugInStreamLoader(ResourceLoader*);
185 void removePlugInStreamLoader(ResourceLoader*);
186
187 void subresourceLoaderFinishedLoadingOnePart(ResourceLoader*);
188
189 void setDeferMainResourceDataLoad(bool defer) { m_deferMainResourceDataLoad = defer; }
190 bool deferMainResourceDataLoad() const { return m_deferMainResourceDataLoad; }
191
192 void didTellClientAboutLoad(const String& url) { m_resourcesClientKnowsAbout.add(url); }
193 bool haveToldClientAboutLoad(const String& url) { return m_resourcesClientKnowsAbout.contains(url); }
194 void recordMemoryCacheLoadForFutureClientNotification(const String& url);
195 void takeMemoryCacheLoadsForClientNotification(Vector<String>& loads);
196
197 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
198 bool scheduleApplicationCacheLoad(ResourceLoader*, const ResourceRequest&, const KURL& originalURL);
199 bool scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader*, const ResourceRequest&, ApplicationCache* = 0);
200 bool shouldLoadResourceFromApplicationCache(const ResourceRequest&, ApplicationCacheResource*&);
201 bool getApplicationCacheFallbackResource(const ResourceRequest&, ApplicationCacheResource*&, ApplicationCache* = 0);
202
203 void setCandidateApplicationCacheGroup(ApplicationCacheGroup* group);
204 ApplicationCacheGroup* candidateApplicationCacheGroup() const { return m_candidateApplicationCacheGroup; }
205
206 void setApplicationCache(PassRefPtr<ApplicationCache> applicationCache);
207 ApplicationCache* applicationCache() const { return m_applicationCache.get(); }
208
209 ApplicationCache* mainResourceApplicationCache() const;
210 #endif
211
212 protected:
213 DocumentLoader(const ResourceRequest&, const SubstituteData&);
214
215 bool m_deferMainResourceDataLoad;
216
217 private:
218 void setupForReplace();
219 void commitIfReady();
220 void clearErrors();
221 void setMainDocumentError(const ResourceError&);
222 void commitLoad(const char*, int);
223 bool doesProgressiveLoad(const String& MIMEType) const;
224
225 void deliverSubstituteResourcesAfterDelay();
226 void substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*);
227
228 Frame* m_frame;
229
230 RefPtr<MainResourceLoader> m_mainResourceLoader;
231 ResourceLoaderSet m_subresourceLoaders;
232 ResourceLoaderSet m_multipartSubresourceLoaders;
233 ResourceLoaderSet m_plugInStreamLoaders;
234
235 RefPtr<SharedBuffer> m_mainResourceData;
236
237 // A reference to actual request used to create the data source.
238 // This should only be used by the resourceLoadDelegate's
239 // identifierForInitialRequest:fromDatasource: method. It is
240 // not guaranteed to remain unchanged, as requests are mutable.
241 ResourceRequest m_originalRequest;
242
243 SubstituteData m_substituteData;
244
245 // A copy of the original request used to create the data source.
246 // We have to copy the request because requests are mutable.
247 ResourceRequest m_originalRequestCopy;
248
249 // The 'working' request. It may be mutated
250 // several times from the original request to include additional
251 // headers, cookie information, canonicalization and redirects.
252 ResourceRequest m_request;
253
254 ResourceResponse m_response;
255
256 ResourceError m_mainDocumentError;
257
258 bool m_committed;
259 bool m_isStopping;
260 bool m_loading;
261 bool m_gotFirstByte;
262 bool m_primaryLoadComplete;
263 bool m_isClientRedirect;
264 bool m_loadingFromCachedPage;
265
266 String m_pageTitle;
267
268 String m_overrideEncoding;
269
270 // The action that triggered loading - we keep this around for the
271 // benefit of the various policy handlers.
272 NavigationAction m_triggeringAction;
273
274 // The last request that we checked click policy for - kept around
275 // so we can avoid asking again needlessly.
276 ResourceRequest m_lastCheckedRequest;
277
278 // We retain all the received responses so we can play back the
279 // WebResourceLoadDelegate messages if the item is loaded from the
280 // page cache.
281 ResponseVector m_responses;
282 bool m_stopRecordingResponses;
283
284 typedef HashMap<RefPtr<ResourceLoader>, RefPtr<SubstituteResource> > SubstituteResourceMap;
285 SubstituteResourceMap m_pendingSubstituteResources;
286 Timer<DocumentLoader> m_substituteResourceDeliveryTimer;
287
288 OwnPtr<ArchiveResourceCollection> m_archiveResourceCollection;
289 RefPtr<SharedBuffer> m_parsedArchiveData;
290
291 HashSet<String> m_resourcesClientKnowsAbout;
292 Vector<String> m_resourcesLoadedFromMemoryCacheForClientNotification;
293
294 bool m_urlForHistoryReflectsClientRedirect;
295
296 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
297 // The application cache that the document loader is associated with (if any).
298 RefPtr<ApplicationCache> m_applicationCache;
299
300 // Before an application cache has finished loading, this will be the candidate application
301 // group that the document loader is associated with.
302 ApplicationCacheGroup* m_candidateApplicationCacheGroup;
303
304 // Once the main resource has finished loading, this is the application cache it was loaded from (if any).
305 RefPtr<ApplicationCache> m_mainResourceApplicationCache;
306 #endif
307 };
308
309 inline void DocumentLoader::recordMemoryCacheLoadForFutureClientNotification(const String& url)
310 {
311 m_resourcesLoadedFromMemoryCacheForClientNotification.append(url);
312 }
313
314 inline void DocumentLoader::takeMemoryCacheLoadsForClientNotification(Vector<String>& loadsSet)
315 {
316 loadsSet.swap(m_resourcesLoadedFromMemoryCacheForClientNotification);
317 m_resourcesLoadedFromMemoryCacheForClientNotification.clear();
318 }
319
320 }
321
322 #endif // DocumentLoader_h