author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 3 | 41300fa6a67c |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
|
3 |
* Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
|
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 |
#include "config.h" |
|
31 |
#include "MainResourceLoader.h" |
|
32 |
||
33 |
#include "ApplicationCacheHost.h" |
|
34 |
#include "DocumentLoader.h" |
|
35 |
#include "FormState.h" |
|
36 |
#include "Frame.h" |
|
37 |
#include "FrameLoader.h" |
|
38 |
#include "FrameLoaderClient.h" |
|
39 |
#include "HTMLFormElement.h" |
|
40 |
#include "Page.h" |
|
41 |
#include "ResourceError.h" |
|
42 |
#include "ResourceHandle.h" |
|
43 |
#include "Settings.h" |
|
44 |
||
45 |
// FIXME: More that is in common with SubresourceLoader should move up into ResourceLoader. |
|
46 |
||
47 |
namespace WebCore { |
|
48 |
||
49 |
MainResourceLoader::MainResourceLoader(Frame* frame) |
|
50 |
: ResourceLoader(frame, true, true) |
|
51 |
, m_dataLoadTimer(this, &MainResourceLoader::handleDataLoadNow) |
|
52 |
, m_loadingMultipartContent(false) |
|
53 |
, m_waitingForContentPolicy(false) |
|
54 |
{ |
|
55 |
} |
|
56 |
||
57 |
MainResourceLoader::~MainResourceLoader() |
|
58 |
{ |
|
59 |
} |
|
60 |
||
61 |
PassRefPtr<MainResourceLoader> MainResourceLoader::create(Frame* frame) |
|
62 |
{ |
|
63 |
return adoptRef(new MainResourceLoader(frame)); |
|
64 |
} |
|
65 |
||
66 |
void MainResourceLoader::receivedError(const ResourceError& error) |
|
67 |
{ |
|
68 |
// Calling receivedMainResourceError will likely result in the last reference to this object to go away. |
|
69 |
RefPtr<MainResourceLoader> protect(this); |
|
70 |
RefPtr<Frame> protectFrame(m_frame); |
|
71 |
||
72 |
// It is important that we call FrameLoader::receivedMainResourceError before calling |
|
73 |
// FrameLoader::didFailToLoad because receivedMainResourceError clears out the relevant |
|
74 |
// document loaders. Also, receivedMainResourceError ends up calling a FrameLoadDelegate method |
|
75 |
// and didFailToLoad calls a ResourceLoadDelegate method and they need to be in the correct order. |
|
76 |
frameLoader()->receivedMainResourceError(error, true); |
|
77 |
||
78 |
if (!cancelled()) { |
|
79 |
ASSERT(!reachedTerminalState()); |
|
80 |
frameLoader()->notifier()->didFailToLoad(this, error); |
|
81 |
||
82 |
releaseResources(); |
|
83 |
} |
|
84 |
||
85 |
ASSERT(reachedTerminalState()); |
|
86 |
} |
|
87 |
||
88 |
void MainResourceLoader::didCancel(const ResourceError& error) |
|
89 |
{ |
|
90 |
m_dataLoadTimer.stop(); |
|
91 |
||
92 |
// Calling receivedMainResourceError will likely result in the last reference to this object to go away. |
|
93 |
RefPtr<MainResourceLoader> protect(this); |
|
94 |
||
95 |
if (m_waitingForContentPolicy) { |
|
96 |
frameLoader()->policyChecker()->cancelCheck(); |
|
97 |
ASSERT(m_waitingForContentPolicy); |
|
98 |
m_waitingForContentPolicy = false; |
|
99 |
deref(); // balances ref in didReceiveResponse |
|
100 |
} |
|
101 |
frameLoader()->receivedMainResourceError(error, true); |
|
102 |
ResourceLoader::didCancel(error); |
|
103 |
} |
|
104 |
||
105 |
ResourceError MainResourceLoader::interruptionForPolicyChangeError() const |
|
106 |
{ |
|
107 |
return frameLoader()->interruptionForPolicyChangeError(request()); |
|
108 |
} |
|
109 |
||
110 |
void MainResourceLoader::stopLoadingForPolicyChange() |
|
111 |
{ |
|
112 |
cancel(interruptionForPolicyChangeError()); |
|
113 |
} |
|
114 |
||
115 |
void MainResourceLoader::callContinueAfterNavigationPolicy(void* argument, const ResourceRequest& request, PassRefPtr<FormState>, bool shouldContinue) |
|
116 |
{ |
|
117 |
static_cast<MainResourceLoader*>(argument)->continueAfterNavigationPolicy(request, shouldContinue); |
|
118 |
} |
|
119 |
||
120 |
void MainResourceLoader::continueAfterNavigationPolicy(const ResourceRequest&, bool shouldContinue) |
|
121 |
{ |
|
122 |
if (!shouldContinue) |
|
123 |
stopLoadingForPolicyChange(); |
|
124 |
deref(); // balances ref in willSendRequest |
|
125 |
} |
|
126 |
||
127 |
bool MainResourceLoader::isPostOrRedirectAfterPost(const ResourceRequest& newRequest, const ResourceResponse& redirectResponse) |
|
128 |
{ |
|
129 |
if (newRequest.httpMethod() == "POST") |
|
130 |
return true; |
|
131 |
||
132 |
int status = redirectResponse.httpStatusCode(); |
|
133 |
if (((status >= 301 && status <= 303) || status == 307) |
|
134 |
&& frameLoader()->initialRequest().httpMethod() == "POST") |
|
135 |
return true; |
|
136 |
||
137 |
return false; |
|
138 |
} |
|
139 |
||
140 |
void MainResourceLoader::addData(const char* data, int length, bool allAtOnce) |
|
141 |
{ |
|
142 |
ResourceLoader::addData(data, length, allAtOnce); |
|
143 |
frameLoader()->receivedData(data, length); |
|
144 |
} |
|
145 |
||
146 |
void MainResourceLoader::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse) |
|
147 |
{ |
|
148 |
// Note that there are no asserts here as there are for the other callbacks. This is due to the |
|
149 |
// fact that this "callback" is sent when starting every load, and the state of callback |
|
150 |
// deferrals plays less of a part in this function in preventing the bad behavior deferring |
|
151 |
// callbacks is meant to prevent. |
|
152 |
ASSERT(!newRequest.isNull()); |
|
153 |
||
154 |
// The additional processing can do anything including possibly removing the last |
|
155 |
// reference to this object; one example of this is 3266216. |
|
156 |
RefPtr<MainResourceLoader> protect(this); |
|
157 |
||
158 |
// Update cookie policy base URL as URL changes, except for subframes, which use the |
|
159 |
// URL of the main frame which doesn't change when we redirect. |
|
160 |
if (frameLoader()->isLoadingMainFrame()) |
|
161 |
newRequest.setFirstPartyForCookies(newRequest.url()); |
|
162 |
||
163 |
// If we're fielding a redirect in response to a POST, force a load from origin, since |
|
164 |
// this is a common site technique to return to a page viewing some data that the POST |
|
165 |
// just modified. |
|
166 |
// Also, POST requests always load from origin, but this does not affect subresources. |
|
167 |
if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAfterPost(newRequest, redirectResponse)) |
|
168 |
newRequest.setCachePolicy(ReloadIgnoringCacheData); |
|
169 |
||
170 |
ResourceLoader::willSendRequest(newRequest, redirectResponse); |
|
171 |
||
172 |
// Don't set this on the first request. It is set when the main load was started. |
|
173 |
m_documentLoader->setRequest(newRequest); |
|
174 |
||
175 |
Frame* top = m_frame->tree()->top(); |
|
176 |
if (top != m_frame) |
|
177 |
frameLoader()->checkIfDisplayInsecureContent(top->document()->securityOrigin(), newRequest.url()); |
|
178 |
||
179 |
// FIXME: Ideally we'd stop the I/O until we hear back from the navigation policy delegate |
|
180 |
// listener. But there's no way to do that in practice. So instead we cancel later if the |
|
181 |
// listener tells us to. In practice that means the navigation policy needs to be decided |
|
182 |
// synchronously for these redirect cases. |
|
183 |
if (!redirectResponse.isNull()) { |
|
184 |
ref(); // balanced by deref in continueAfterNavigationPolicy |
|
185 |
frameLoader()->policyChecker()->checkNavigationPolicy(newRequest, callContinueAfterNavigationPolicy, this); |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
static bool shouldLoadAsEmptyDocument(const KURL& url) |
|
190 |
{ |
|
191 |
#if PLATFORM(TORCHMOBILE) |
|
192 |
return url.isEmpty() || (url.protocolIs("about") && equalIgnoringRef(url, blankURL())); |
|
193 |
#else |
|
194 |
return url.isEmpty() || url.protocolIs("about"); |
|
195 |
#endif |
|
196 |
} |
|
197 |
||
198 |
void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy, const ResourceResponse& r) |
|
199 |
{ |
|
200 |
KURL url = request().url(); |
|
201 |
const String& mimeType = r.mimeType(); |
|
202 |
||
203 |
switch (contentPolicy) { |
|
204 |
case PolicyUse: { |
|
205 |
// Prevent remote web archives from loading because they can claim to be from any domain and thus avoid cross-domain security checks (4120255). |
|
206 |
bool isRemoteWebArchive = equalIgnoringCase("application/x-webarchive", mimeType) && !m_substituteData.isValid() && !url.isLocalFile(); |
|
207 |
if (!frameLoader()->canShowMIMEType(mimeType) || isRemoteWebArchive) { |
|
208 |
frameLoader()->policyChecker()->cannotShowMIMEType(r); |
|
209 |
// Check reachedTerminalState since the load may have already been cancelled inside of _handleUnimplementablePolicyWithErrorCode::. |
|
210 |
if (!reachedTerminalState()) |
|
211 |
stopLoadingForPolicyChange(); |
|
212 |
return; |
|
213 |
} |
|
214 |
break; |
|
215 |
} |
|
216 |
||
217 |
case PolicyDownload: |
|
218 |
// m_handle can be null, e.g. when loading a substitute resource from application cache. |
|
219 |
if (!m_handle) { |
|
220 |
receivedError(cannotShowURLError()); |
|
221 |
return; |
|
222 |
} |
|
223 |
frameLoader()->client()->download(m_handle.get(), request(), m_handle.get()->request(), r); |
|
224 |
// It might have gone missing |
|
225 |
if (frameLoader()) |
|
226 |
receivedError(interruptionForPolicyChangeError()); |
|
227 |
return; |
|
228 |
||
229 |
case PolicyIgnore: |
|
230 |
stopLoadingForPolicyChange(); |
|
231 |
return; |
|
232 |
||
233 |
default: |
|
234 |
ASSERT_NOT_REACHED(); |
|
235 |
} |
|
236 |
||
237 |
RefPtr<MainResourceLoader> protect(this); |
|
238 |
||
239 |
if (r.isHTTP()) { |
|
240 |
int status = r.httpStatusCode(); |
|
241 |
if (status < 200 || status >= 300) { |
|
242 |
bool hostedByObject = frameLoader()->isHostedByObjectElement(); |
|
243 |
||
244 |
frameLoader()->handleFallbackContent(); |
|
245 |
// object elements are no longer rendered after we fallback, so don't |
|
246 |
// keep trying to process data from their load |
|
247 |
||
248 |
if (hostedByObject) |
|
249 |
cancel(); |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
// we may have cancelled this load as part of switching to fallback content |
|
254 |
if (!reachedTerminalState()) |
|
255 |
ResourceLoader::didReceiveResponse(r); |
|
256 |
||
257 |
if (frameLoader() && !frameLoader()->isStopping()) { |
|
258 |
if (m_substituteData.isValid()) { |
|
259 |
if (m_substituteData.content()->size()) |
|
260 |
didReceiveData(m_substituteData.content()->data(), m_substituteData.content()->size(), m_substituteData.content()->size(), true); |
|
261 |
if (frameLoader() && !frameLoader()->isStopping()) |
|
262 |
didFinishLoading(); |
|
263 |
} else if (shouldLoadAsEmptyDocument(url) || frameLoader()->representationExistsForURLScheme(url.protocol())) |
|
264 |
didFinishLoading(); |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
void MainResourceLoader::callContinueAfterContentPolicy(void* argument, PolicyAction policy) |
|
269 |
{ |
|
270 |
static_cast<MainResourceLoader*>(argument)->continueAfterContentPolicy(policy); |
|
271 |
} |
|
272 |
||
273 |
void MainResourceLoader::continueAfterContentPolicy(PolicyAction policy) |
|
274 |
{ |
|
275 |
ASSERT(m_waitingForContentPolicy); |
|
276 |
m_waitingForContentPolicy = false; |
|
277 |
if (frameLoader() && !frameLoader()->isStopping()) |
|
278 |
continueAfterContentPolicy(policy, m_response); |
|
279 |
deref(); // balances ref in didReceiveResponse |
|
280 |
} |
|
281 |
||
282 |
void MainResourceLoader::didReceiveResponse(const ResourceResponse& r) |
|
283 |
{ |
|
284 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
285 |
if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainResponse(request(), r)) |
|
286 |
return; |
|
287 |
#endif |
|
288 |
||
289 |
HTTPHeaderMap::const_iterator it = r.httpHeaderFields().find(AtomicString("x-frame-options")); |
|
290 |
if (it != r.httpHeaderFields().end()) { |
|
291 |
String content = it->second; |
|
292 |
if (m_frame->loader()->shouldInterruptLoadForXFrameOptions(content, r.url())) { |
|
293 |
cancel(); |
|
294 |
return; |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
// There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. |
|
299 |
// See <rdar://problem/6304600> for more details. |
|
300 |
#if !PLATFORM(CF) |
|
301 |
ASSERT(shouldLoadAsEmptyDocument(r.url()) || !defersLoading()); |
|
302 |
#endif |
|
303 |
||
304 |
if (m_loadingMultipartContent) { |
|
305 |
frameLoader()->setupForReplaceByMIMEType(r.mimeType()); |
|
306 |
clearResourceData(); |
|
307 |
} |
|
308 |
||
309 |
if (r.isMultipart()) |
|
310 |
m_loadingMultipartContent = true; |
|
311 |
||
312 |
// The additional processing can do anything including possibly removing the last |
|
313 |
// reference to this object; one example of this is 3266216. |
|
314 |
RefPtr<MainResourceLoader> protect(this); |
|
315 |
||
316 |
m_documentLoader->setResponse(r); |
|
317 |
||
318 |
m_response = r; |
|
319 |
||
320 |
ASSERT(!m_waitingForContentPolicy); |
|
321 |
m_waitingForContentPolicy = true; |
|
322 |
ref(); // balanced by deref in continueAfterContentPolicy and didCancel |
|
323 |
||
324 |
ASSERT(frameLoader()->activeDocumentLoader()); |
|
325 |
||
326 |
// Always show content with valid substitute data. |
|
327 |
if (frameLoader()->activeDocumentLoader()->substituteData().isValid()) { |
|
328 |
callContinueAfterContentPolicy(this, PolicyUse); |
|
329 |
return; |
|
330 |
} |
|
331 |
||
332 |
#if ENABLE(FTPDIR) |
|
333 |
// Respect the hidden FTP Directory Listing pref so it can be tested even if the policy delegate might otherwise disallow it |
|
334 |
Settings* settings = m_frame->settings(); |
|
335 |
if (settings && settings->forceFTPDirectoryListings() && m_response.mimeType() == "application/x-ftp-directory") { |
|
336 |
callContinueAfterContentPolicy(this, PolicyUse); |
|
337 |
return; |
|
338 |
} |
|
339 |
#endif |
|
340 |
||
341 |
frameLoader()->policyChecker()->checkContentPolicy(m_response.mimeType(), callContinueAfterContentPolicy, this); |
|
342 |
} |
|
343 |
||
344 |
void MainResourceLoader::didReceiveData(const char* data, int length, long long lengthReceived, bool allAtOnce) |
|
345 |
{ |
|
346 |
ASSERT(data); |
|
347 |
ASSERT(length != 0); |
|
348 |
||
349 |
ASSERT(!m_response.isNull()); |
|
350 |
||
351 |
#if USE(CFNETWORK) || (PLATFORM(MAC) && !defined(BUILDING_ON_TIGER)) |
|
352 |
// Workaround for <rdar://problem/6060782> |
|
353 |
if (m_response.isNull()) { |
|
354 |
m_response = ResourceResponse(KURL(), "text/html", 0, String(), String()); |
|
355 |
if (DocumentLoader* documentLoader = frameLoader()->activeDocumentLoader()) |
|
356 |
documentLoader->setResponse(m_response); |
|
357 |
} |
|
358 |
#endif |
|
359 |
||
360 |
// There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. |
|
361 |
// See <rdar://problem/6304600> for more details. |
|
362 |
#if !PLATFORM(CF) |
|
363 |
ASSERT(!defersLoading()); |
|
364 |
#endif |
|
365 |
||
366 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
367 |
documentLoader()->applicationCacheHost()->mainResourceDataReceived(data, length, lengthReceived, allAtOnce); |
|
368 |
#endif |
|
369 |
||
370 |
// The additional processing can do anything including possibly removing the last |
|
371 |
// reference to this object; one example of this is 3266216. |
|
372 |
RefPtr<MainResourceLoader> protect(this); |
|
373 |
||
374 |
ResourceLoader::didReceiveData(data, length, lengthReceived, allAtOnce); |
|
375 |
} |
|
376 |
||
377 |
void MainResourceLoader::didFinishLoading() |
|
378 |
{ |
|
379 |
// There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. |
|
380 |
// See <rdar://problem/6304600> for more details. |
|
381 |
#if !PLATFORM(CF) |
|
382 |
ASSERT(shouldLoadAsEmptyDocument(frameLoader()->activeDocumentLoader()->url()) || !defersLoading()); |
|
383 |
#endif |
|
384 |
||
385 |
// The additional processing can do anything including possibly removing the last |
|
386 |
// reference to this object. |
|
387 |
RefPtr<MainResourceLoader> protect(this); |
|
388 |
||
389 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
390 |
RefPtr<DocumentLoader> dl = documentLoader(); |
|
391 |
#endif |
|
392 |
||
393 |
frameLoader()->finishedLoading(); |
|
394 |
ResourceLoader::didFinishLoading(); |
|
395 |
||
396 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
397 |
dl->applicationCacheHost()->finishedLoadingMainResource(); |
|
398 |
#endif |
|
399 |
} |
|
400 |
||
401 |
void MainResourceLoader::didFail(const ResourceError& error) |
|
402 |
{ |
|
403 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
404 |
if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainError(request(), error)) |
|
405 |
return; |
|
406 |
#endif |
|
407 |
||
408 |
// There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. |
|
409 |
// See <rdar://problem/6304600> for more details. |
|
410 |
#if !PLATFORM(CF) |
|
411 |
ASSERT(!defersLoading()); |
|
412 |
#endif |
|
413 |
||
414 |
receivedError(error); |
|
415 |
} |
|
416 |
||
417 |
void MainResourceLoader::handleEmptyLoad(const KURL& url, bool forURLScheme) |
|
418 |
{ |
|
419 |
String mimeType; |
|
420 |
if (forURLScheme) |
|
421 |
mimeType = frameLoader()->generatedMIMETypeForURLScheme(url.protocol()); |
|
422 |
else |
|
423 |
mimeType = "text/html"; |
|
424 |
||
425 |
ResourceResponse response(url, mimeType, 0, String(), String()); |
|
426 |
didReceiveResponse(response); |
|
427 |
} |
|
428 |
||
429 |
void MainResourceLoader::handleDataLoadNow(MainResourceLoaderTimer*) |
|
430 |
{ |
|
431 |
RefPtr<MainResourceLoader> protect(this); |
|
432 |
||
433 |
KURL url = m_substituteData.responseURL(); |
|
434 |
if (url.isEmpty()) |
|
435 |
url = m_initialRequest.url(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
// Clear the initial request here so that subsequent entries into the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
// loader will not think there's still a deferred load left to do. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
m_initialRequest = ResourceRequest(); |
0 | 440 |
|
441 |
ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding(), ""); |
|
442 |
didReceiveResponse(response); |
|
443 |
} |
|
444 |
||
445 |
void MainResourceLoader::startDataLoadTimer() |
|
446 |
{ |
|
447 |
m_dataLoadTimer.startOneShot(0); |
|
448 |
||
449 |
#if HAVE(RUNLOOP_TIMER) |
|
450 |
if (SchedulePairHashSet* scheduledPairs = m_frame->page()->scheduledRunLoopPairs()) |
|
451 |
m_dataLoadTimer.schedule(*scheduledPairs); |
|
452 |
#endif |
|
453 |
} |
|
454 |
||
455 |
void MainResourceLoader::handleDataLoadSoon(ResourceRequest& r) |
|
456 |
{ |
|
457 |
m_initialRequest = r; |
|
458 |
||
459 |
if (m_documentLoader->deferMainResourceDataLoad()) |
|
460 |
startDataLoadTimer(); |
|
461 |
else |
|
462 |
handleDataLoadNow(0); |
|
463 |
} |
|
464 |
||
465 |
bool MainResourceLoader::loadNow(ResourceRequest& r) |
|
466 |
{ |
|
467 |
bool shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument(r.url()); |
|
468 |
||
469 |
ASSERT(!m_handle); |
|
470 |
ASSERT(shouldLoadEmptyBeforeRedirect || !defersLoading()); |
|
471 |
||
472 |
// Send this synthetic delegate callback since clients expect it, and |
|
473 |
// we no longer send the callback from within NSURLConnection for |
|
474 |
// initial requests. |
|
475 |
willSendRequest(r, ResourceResponse()); |
|
476 |
||
477 |
// <rdar://problem/4801066> |
|
478 |
// willSendRequest() is liable to make the call to frameLoader() return NULL, so we need to check that here |
|
479 |
if (!frameLoader()) |
|
480 |
return false; |
|
481 |
||
482 |
const KURL& url = r.url(); |
|
483 |
bool shouldLoadEmpty = shouldLoadAsEmptyDocument(url) && !m_substituteData.isValid(); |
|
484 |
||
485 |
if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && defersLoading()) |
|
486 |
return true; |
|
487 |
||
488 |
if (m_substituteData.isValid()) |
|
489 |
handleDataLoadSoon(r); |
|
490 |
else if (shouldLoadEmpty || frameLoader()->representationExistsForURLScheme(url.protocol())) |
|
491 |
handleEmptyLoad(url, !shouldLoadEmpty); |
|
492 |
else |
|
493 |
m_handle = ResourceHandle::create(r, this, m_frame.get(), false, true, true); |
|
494 |
||
495 |
return false; |
|
496 |
} |
|
497 |
||
498 |
bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& substituteData) |
|
499 |
{ |
|
500 |
ASSERT(!m_handle); |
|
501 |
||
502 |
m_substituteData = substituteData; |
|
503 |
||
504 |
ResourceRequest request(r); |
|
505 |
||
506 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
507 |
documentLoader()->applicationCacheHost()->maybeLoadMainResource(request, m_substituteData); |
|
508 |
#endif |
|
509 |
||
510 |
bool defer = defersLoading(); |
|
511 |
if (defer) { |
|
512 |
bool shouldLoadEmpty = shouldLoadAsEmptyDocument(request.url()); |
|
513 |
if (shouldLoadEmpty) |
|
514 |
defer = false; |
|
515 |
} |
|
516 |
if (!defer) { |
|
517 |
if (loadNow(request)) { |
|
518 |
// Started as an empty document, but was redirected to something non-empty. |
|
519 |
ASSERT(defersLoading()); |
|
520 |
defer = true; |
|
521 |
} |
|
522 |
} |
|
523 |
if (defer) |
|
524 |
m_initialRequest = request; |
|
525 |
||
526 |
return true; |
|
527 |
} |
|
528 |
||
529 |
void MainResourceLoader::setDefersLoading(bool defers) |
|
530 |
{ |
|
531 |
ResourceLoader::setDefersLoading(defers); |
|
532 |
||
533 |
if (defers) { |
|
534 |
if (m_dataLoadTimer.isActive()) |
|
535 |
m_dataLoadTimer.stop(); |
|
536 |
} else { |
|
537 |
if (m_initialRequest.isNull()) |
|
538 |
return; |
|
539 |
||
540 |
if (m_substituteData.isValid() && m_documentLoader->deferMainResourceDataLoad()) |
|
541 |
startDataLoadTimer(); |
|
542 |
else { |
|
543 |
ResourceRequest r(m_initialRequest); |
|
544 |
m_initialRequest = ResourceRequest(); |
|
545 |
loadNow(r); |
|
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
} |