mjs | 9561158 | 2006-10-09 09:53:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Apple Computer, 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 | |
darin | 27bd662 | 2006-10-30 01:16:42 +0000 | [diff] [blame] | 29 | #include "config.h" |
| 30 | #include "MainResourceLoader.h" |
mjs | 9561158 | 2006-10-09 09:53:40 +0000 | [diff] [blame] | 31 | |
andersca | 2dbcee8 | 2007-03-07 19:31:55 +0000 | [diff] [blame] | 32 | #include "DocumentLoader.h" |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 33 | #include "Frame.h" |
| 34 | #include "FrameLoader.h" |
| 35 | #include "FrameLoaderClient.h" |
| 36 | #include "HTMLFormElement.h" |
| 37 | #include "ResourceError.h" |
| 38 | #include "ResourceHandle.h" |
| 39 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 40 | // FIXME: More that is in common with SubresourceLoader should move up into ResourceLoader. |
| 41 | |
darin | 9ab4ef2 | 2006-10-13 17:07:20 +0000 | [diff] [blame] | 42 | namespace WebCore { |
mjs | 9561158 | 2006-10-09 09:53:40 +0000 | [diff] [blame] | 43 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 44 | MainResourceLoader::MainResourceLoader(Frame* frame) |
andersca | d92451d | 2007-06-22 19:04:58 +0000 | [diff] [blame] | 45 | : ResourceLoader(frame, true) |
mjs | 074dfb3 | 2007-01-31 02:40:54 +0000 | [diff] [blame] | 46 | , m_dataLoadTimer(this, &MainResourceLoader::handleDataLoadNow) |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 47 | , m_loadingMultipartContent(false) |
| 48 | , m_waitingForContentPolicy(false) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | MainResourceLoader::~MainResourceLoader() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | PassRefPtr<MainResourceLoader> MainResourceLoader::create(Frame* frame) |
| 57 | { |
| 58 | return new MainResourceLoader(frame); |
| 59 | } |
| 60 | |
| 61 | void MainResourceLoader::receivedError(const ResourceError& error) |
| 62 | { |
| 63 | // Calling receivedMainResourceError will likely result in the last reference to this object to go away. |
| 64 | RefPtr<MainResourceLoader> protect(this); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 65 | RefPtr<Frame> protectFrame(m_frame); |
andersca | 5d5f802 | 2007-02-28 00:38:00 +0000 | [diff] [blame] | 66 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 67 | if (!cancelled()) { |
| 68 | ASSERT(!reachedTerminalState()); |
| 69 | frameLoader()->didFailToLoad(this, error); |
andersca | 5d5f802 | 2007-02-28 00:38:00 +0000 | [diff] [blame] | 70 | } |
| 71 | |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 72 | frameLoader()->receivedMainResourceError(error, true); |
| 73 | |
| 74 | if (!cancelled()) { |
| 75 | releaseResources(); |
| 76 | } |
| 77 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 78 | ASSERT(reachedTerminalState()); |
| 79 | } |
| 80 | |
| 81 | void MainResourceLoader::didCancel(const ResourceError& error) |
| 82 | { |
mjs | 074dfb3 | 2007-01-31 02:40:54 +0000 | [diff] [blame] | 83 | m_dataLoadTimer.stop(); |
| 84 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 85 | // Calling receivedMainResourceError will likely result in the last reference to this object to go away. |
| 86 | RefPtr<MainResourceLoader> protect(this); |
| 87 | |
| 88 | if (m_waitingForContentPolicy) { |
| 89 | frameLoader()->cancelContentPolicyCheck(); |
| 90 | ASSERT(m_waitingForContentPolicy); |
| 91 | m_waitingForContentPolicy = false; |
| 92 | deref(); // balances ref in didReceiveResponse |
| 93 | } |
| 94 | frameLoader()->receivedMainResourceError(error, true); |
| 95 | ResourceLoader::didCancel(error); |
| 96 | } |
| 97 | |
| 98 | ResourceError MainResourceLoader::interruptionForPolicyChangeError() const |
| 99 | { |
| 100 | return frameLoader()->interruptionForPolicyChangeError(request()); |
| 101 | } |
| 102 | |
| 103 | void MainResourceLoader::stopLoadingForPolicyChange() |
| 104 | { |
| 105 | cancel(interruptionForPolicyChangeError()); |
| 106 | } |
| 107 | |
| 108 | void MainResourceLoader::callContinueAfterNavigationPolicy(void* argument, const ResourceRequest& request, PassRefPtr<FormState>, bool shouldContinue) |
| 109 | { |
| 110 | static_cast<MainResourceLoader*>(argument)->continueAfterNavigationPolicy(request, shouldContinue); |
| 111 | } |
| 112 | |
| 113 | void MainResourceLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue) |
| 114 | { |
| 115 | if (!shouldContinue) |
| 116 | stopLoadingForPolicyChange(); |
| 117 | deref(); // balances ref in willSendRequest |
| 118 | } |
| 119 | |
| 120 | bool MainResourceLoader::isPostOrRedirectAfterPost(const ResourceRequest& newRequest, const ResourceResponse& redirectResponse) |
| 121 | { |
| 122 | if (newRequest.httpMethod() == "POST") |
| 123 | return true; |
| 124 | |
| 125 | int status = redirectResponse.httpStatusCode(); |
| 126 | if (((status >= 301 && status <= 303) || status == 307) |
| 127 | && frameLoader()->initialRequest().httpMethod() == "POST") |
| 128 | return true; |
| 129 | |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | void MainResourceLoader::addData(const char* data, int length, bool allAtOnce) |
| 134 | { |
| 135 | ResourceLoader::addData(data, length, allAtOnce); |
| 136 | frameLoader()->receivedData(data, length); |
| 137 | } |
| 138 | |
| 139 | void MainResourceLoader::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse) |
| 140 | { |
| 141 | // Note that there are no asserts here as there are for the other callbacks. This is due to the |
| 142 | // fact that this "callback" is sent when starting every load, and the state of callback |
| 143 | // deferrals plays less of a part in this function in preventing the bad behavior deferring |
| 144 | // callbacks is meant to prevent. |
| 145 | ASSERT(!newRequest.isNull()); |
| 146 | |
| 147 | // The additional processing can do anything including possibly removing the last |
| 148 | // reference to this object; one example of this is 3266216. |
| 149 | RefPtr<MainResourceLoader> protect(this); |
| 150 | |
| 151 | // Update cookie policy base URL as URL changes, except for subframes, which use the |
| 152 | // URL of the main frame which doesn't change when we redirect. |
| 153 | if (frameLoader()->isLoadingMainFrame()) |
| 154 | newRequest.setMainDocumentURL(newRequest.url()); |
| 155 | |
| 156 | // If we're fielding a redirect in response to a POST, force a load from origin, since |
| 157 | // this is a common site technique to return to a page viewing some data that the POST |
| 158 | // just modified. |
| 159 | // Also, POST requests always load from origin, but this does not affect subresources. |
| 160 | if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAfterPost(newRequest, redirectResponse)) |
| 161 | newRequest.setCachePolicy(ReloadIgnoringCacheData); |
| 162 | |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 163 | if (!newRequest.isNull()) { |
| 164 | ResourceLoader::willSendRequest(newRequest, redirectResponse); |
| 165 | setRequest(newRequest); |
| 166 | } |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 167 | |
| 168 | // Don't set this on the first request. It is set when the main load was started. |
andersca | 2dbcee8 | 2007-03-07 19:31:55 +0000 | [diff] [blame] | 169 | m_documentLoader->setRequest(newRequest); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 170 | |
| 171 | ref(); // balanced by deref in continueAfterNavigationPolicy |
| 172 | frameLoader()->checkNavigationPolicy(newRequest, callContinueAfterNavigationPolicy, this); |
| 173 | } |
| 174 | |
| 175 | static bool shouldLoadAsEmptyDocument(const KURL& URL) |
| 176 | { |
| 177 | return URL.isEmpty() || equalIgnoringCase(String(URL.protocol()), "about"); |
| 178 | } |
| 179 | |
| 180 | void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy, const ResourceResponse& r) |
| 181 | { |
| 182 | KURL url = request().url(); |
| 183 | const String& mimeType = r.mimeType(); |
| 184 | |
| 185 | switch (contentPolicy) { |
| 186 | case PolicyUse: { |
| 187 | // Prevent remote web archives from loading because they can claim to be from any domain and thus avoid cross-domain security checks (4120255). |
kmccullo | adfd67d | 2007-03-03 02:18:43 +0000 | [diff] [blame] | 188 | bool isRemoteWebArchive = equalIgnoringCase("application/x-webarchive", mimeType) && !m_substituteData.isValid() && !url.isLocalFile(); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 189 | if (!frameLoader()->canShowMIMEType(mimeType) || isRemoteWebArchive) { |
| 190 | frameLoader()->cannotShowMIMEType(r); |
| 191 | // Check reachedTerminalState since the load may have already been cancelled inside of _handleUnimplementablePolicyWithErrorCode::. |
| 192 | if (!reachedTerminalState()) |
| 193 | stopLoadingForPolicyChange(); |
| 194 | return; |
| 195 | } |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | case PolicyDownload: |
tristan | ee758b1 | 2007-07-17 18:27:04 +0000 | [diff] [blame] | 200 | frameLoader()->client()->download(m_handle.get(), request(), m_handle.get()->request(), r); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 201 | receivedError(interruptionForPolicyChangeError()); |
| 202 | return; |
| 203 | |
| 204 | case PolicyIgnore: |
| 205 | stopLoadingForPolicyChange(); |
| 206 | return; |
| 207 | |
| 208 | default: |
| 209 | ASSERT_NOT_REACHED(); |
| 210 | } |
| 211 | |
| 212 | RefPtr<MainResourceLoader> protect(this); |
| 213 | |
| 214 | if (r.isHTTP()) { |
| 215 | int status = r.httpStatusCode(); |
| 216 | if (status < 200 || status >= 300) { |
| 217 | bool hostedByObject = frameLoader()->isHostedByObjectElement(); |
| 218 | |
| 219 | frameLoader()->handleFallbackContent(); |
| 220 | // object elements are no longer rendered after we fallback, so don't |
| 221 | // keep trying to process data from their load |
| 222 | |
| 223 | if (hostedByObject) |
| 224 | cancel(); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // we may have cancelled this load as part of switching to fallback content |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 229 | if (!reachedTerminalState()) |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 230 | ResourceLoader::didReceiveResponse(r); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 231 | |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 232 | if (frameLoader() && !frameLoader()->isStopping()) |
| 233 | if (m_substituteData.isValid()) { |
mjs | 71fc41d | 2007-02-09 10:44:41 +0000 | [diff] [blame] | 234 | if (m_substituteData.content()->size()) |
| 235 | didReceiveData(m_substituteData.content()->data(), m_substituteData.content()->size(), m_substituteData.content()->size(), true); |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 236 | if (frameLoader() && !frameLoader()->isStopping()) |
| 237 | didFinishLoading(); |
| 238 | } else if (shouldLoadAsEmptyDocument(url) || frameLoader()->representationExistsForURLScheme(url.protocol())) |
| 239 | didFinishLoading(); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void MainResourceLoader::callContinueAfterContentPolicy(void* argument, PolicyAction policy) |
| 243 | { |
| 244 | static_cast<MainResourceLoader*>(argument)->continueAfterContentPolicy(policy); |
| 245 | } |
| 246 | |
| 247 | void MainResourceLoader::continueAfterContentPolicy(PolicyAction policy) |
| 248 | { |
| 249 | ASSERT(m_waitingForContentPolicy); |
| 250 | m_waitingForContentPolicy = false; |
adele | 31ccc45 | 2007-07-30 23:56:19 +0000 | [diff] [blame] | 251 | if (frameLoader() && !frameLoader()->isStopping()) |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 252 | continueAfterContentPolicy(policy, m_response); |
| 253 | deref(); // balances ref in didReceiveResponse |
| 254 | } |
| 255 | |
| 256 | void MainResourceLoader::didReceiveResponse(const ResourceResponse& r) |
| 257 | { |
| 258 | ASSERT(shouldLoadAsEmptyDocument(r.url()) || !defersLoading()); |
| 259 | |
| 260 | if (m_loadingMultipartContent) { |
| 261 | frameLoader()->setupForReplaceByMIMEType(r.mimeType()); |
| 262 | clearResourceData(); |
| 263 | } |
| 264 | |
| 265 | if (r.isMultipart()) |
| 266 | m_loadingMultipartContent = true; |
| 267 | |
| 268 | // The additional processing can do anything including possibly removing the last |
| 269 | // reference to this object; one example of this is 3266216. |
| 270 | RefPtr<MainResourceLoader> protect(this); |
| 271 | |
andersca | 2dbcee8 | 2007-03-07 19:31:55 +0000 | [diff] [blame] | 272 | m_documentLoader->setResponse(r); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 273 | |
| 274 | m_response = r; |
| 275 | |
| 276 | ASSERT(!m_waitingForContentPolicy); |
| 277 | m_waitingForContentPolicy = true; |
| 278 | ref(); // balanced by deref in continueAfterContentPolicy and didCancel |
| 279 | frameLoader()->checkContentPolicy(m_response.mimeType(), callContinueAfterContentPolicy, this); |
| 280 | } |
| 281 | |
| 282 | void MainResourceLoader::didReceiveData(const char* data, int length, long long lengthReceived, bool allAtOnce) |
| 283 | { |
| 284 | ASSERT(data); |
| 285 | ASSERT(length != 0); |
| 286 | ASSERT(!defersLoading()); |
| 287 | |
| 288 | // The additional processing can do anything including possibly removing the last |
| 289 | // reference to this object; one example of this is 3266216. |
| 290 | RefPtr<MainResourceLoader> protect(this); |
| 291 | |
| 292 | ResourceLoader::didReceiveData(data, length, lengthReceived, allAtOnce); |
| 293 | } |
| 294 | |
| 295 | void MainResourceLoader::didFinishLoading() |
| 296 | { |
| 297 | ASSERT(shouldLoadAsEmptyDocument(frameLoader()->URL()) || !defersLoading()); |
| 298 | |
| 299 | // The additional processing can do anything including possibly removing the last |
| 300 | // reference to this object. |
| 301 | RefPtr<MainResourceLoader> protect(this); |
| 302 | |
| 303 | frameLoader()->finishedLoading(); |
| 304 | ResourceLoader::didFinishLoading(); |
| 305 | } |
| 306 | |
| 307 | void MainResourceLoader::didFail(const ResourceError& error) |
| 308 | { |
| 309 | ASSERT(!defersLoading()); |
| 310 | |
| 311 | receivedError(error); |
| 312 | } |
| 313 | |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 314 | void MainResourceLoader::handleEmptyLoad(const KURL& url, bool forURLScheme) |
| 315 | { |
| 316 | String mimeType; |
| 317 | if (forURLScheme) |
| 318 | mimeType = frameLoader()->generatedMIMETypeForURLScheme(url.protocol()); |
| 319 | else |
| 320 | mimeType = "text/html"; |
| 321 | |
| 322 | ResourceResponse response(url, mimeType, 0, String(), String()); |
| 323 | didReceiveResponse(response); |
| 324 | } |
| 325 | |
mjs | 074dfb3 | 2007-01-31 02:40:54 +0000 | [diff] [blame] | 326 | void MainResourceLoader::handleDataLoadNow(Timer<MainResourceLoader>*) |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 327 | { |
| 328 | RefPtr<MainResourceLoader> protect(this); |
| 329 | |
bdash | ec5a79e | 2007-05-04 16:42:11 +0000 | [diff] [blame] | 330 | KURL url = m_substituteData.responseURL(); |
| 331 | if (url.isEmpty()) |
| 332 | url = m_initialRequest.url(); |
| 333 | |
| 334 | ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding(), ""); |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 335 | didReceiveResponse(response); |
| 336 | } |
| 337 | |
mjs | 074dfb3 | 2007-01-31 02:40:54 +0000 | [diff] [blame] | 338 | void MainResourceLoader::handleDataLoadSoon(ResourceRequest& r) |
| 339 | { |
| 340 | m_initialRequest = r; |
andersca | e894632 | 2007-06-20 00:23:48 +0000 | [diff] [blame] | 341 | |
| 342 | if (m_documentLoader->deferMainResourceDataLoad()) |
| 343 | m_dataLoadTimer.startOneShot(0); |
| 344 | else |
| 345 | handleDataLoadNow(0); |
mjs | 074dfb3 | 2007-01-31 02:40:54 +0000 | [diff] [blame] | 346 | } |
| 347 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 348 | bool MainResourceLoader::loadNow(ResourceRequest& r) |
| 349 | { |
| 350 | bool shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument(r.url()); |
| 351 | |
| 352 | ASSERT(!m_handle); |
| 353 | ASSERT(shouldLoadEmptyBeforeRedirect || !defersLoading()); |
| 354 | |
| 355 | // Send this synthetic delegate callback since clients expect it, and |
| 356 | // we no longer send the callback from within NSURLConnection for |
| 357 | // initial requests. |
| 358 | willSendRequest(r, ResourceResponse()); |
| 359 | |
| 360 | // <rdar://problem/4801066> |
| 361 | // willSendRequest() is liable to make the call to frameLoader() return NULL, so we need to check that here |
| 362 | if (!frameLoader()) |
| 363 | return false; |
| 364 | |
| 365 | const KURL& url = r.url(); |
bdash | ec5a79e | 2007-05-04 16:42:11 +0000 | [diff] [blame] | 366 | bool shouldLoadEmpty = shouldLoadAsEmptyDocument(url) && !m_substituteData.isValid(); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 367 | |
| 368 | if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && defersLoading()) |
| 369 | return true; |
| 370 | |
andersca | e894632 | 2007-06-20 00:23:48 +0000 | [diff] [blame] | 371 | if (m_substituteData.isValid()) |
mjs | 074dfb3 | 2007-01-31 02:40:54 +0000 | [diff] [blame] | 372 | handleDataLoadSoon(r); |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 373 | else if (shouldLoadEmpty || frameLoader()->representationExistsForURLScheme(url.protocol())) |
| 374 | handleEmptyLoad(url, !shouldLoadEmpty); |
| 375 | else |
andersca | 14a0254 | 2007-01-30 22:04:28 +0000 | [diff] [blame] | 376 | m_handle = ResourceHandle::create(r, this, m_frame.get(), false, true); |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 377 | |
| 378 | return false; |
| 379 | } |
| 380 | |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 381 | bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& substituteData) |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 382 | { |
| 383 | ASSERT(!m_handle); |
| 384 | |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 385 | m_substituteData = substituteData; |
| 386 | |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 387 | ResourceRequest request(r); |
| 388 | bool defer = defersLoading(); |
| 389 | if (defer) { |
| 390 | bool shouldLoadEmpty = shouldLoadAsEmptyDocument(r.url()); |
| 391 | if (shouldLoadEmpty) |
| 392 | defer = false; |
| 393 | } |
| 394 | if (!defer) { |
| 395 | if (loadNow(request)) { |
| 396 | // Started as an empty document, but was redirected to something non-empty. |
| 397 | ASSERT(defersLoading()); |
| 398 | defer = true; |
| 399 | } |
| 400 | } |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 401 | if (defer) |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 402 | m_initialRequest = request; |
| 403 | |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | void MainResourceLoader::setDefersLoading(bool defers) |
| 408 | { |
| 409 | ResourceLoader::setDefersLoading(defers); |
andersca | 14cd912 | 2007-03-08 07:15:04 +0000 | [diff] [blame] | 410 | |
| 411 | if (defers) { |
| 412 | if (m_dataLoadTimer.isActive()) |
| 413 | m_dataLoadTimer.stop(); |
| 414 | } else { |
| 415 | if (m_initialRequest.isNull()) |
| 416 | return; |
| 417 | |
andersca | e894632 | 2007-06-20 00:23:48 +0000 | [diff] [blame] | 418 | if (m_substituteData.isValid() && |
| 419 | m_documentLoader->deferMainResourceDataLoad()) |
| 420 | m_dataLoadTimer.startOneShot(0); |
andersca | 14cd912 | 2007-03-08 07:15:04 +0000 | [diff] [blame] | 421 | else { |
andersca | 8f7934f | 2007-01-10 19:39:07 +0000 | [diff] [blame] | 422 | ResourceRequest r(m_initialRequest); |
| 423 | m_initialRequest = ResourceRequest(); |
| 424 | loadNow(r); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
darin | 9ab4ef2 | 2006-10-13 17:07:20 +0000 | [diff] [blame] | 429 | } |