Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 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 | 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 | 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. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "core/loader/DocumentLoader.h" | 30 #include "core/loader/DocumentLoader.h" |
| 31 | 31 |
| 32 #include <memory> | 32 #include <memory> |
| 33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "core/dom/DocumentParser.h" | |
| 34 #include "core/dom/WeakIdentifierMap.h" | 35 #include "core/dom/WeakIdentifierMap.h" |
| 35 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
| 36 #include "core/frame/Deprecation.h" | 37 #include "core/frame/Deprecation.h" |
| 37 #include "core/frame/FrameHost.h" | 38 #include "core/frame/FrameHost.h" |
| 38 #include "core/frame/LocalDOMWindow.h" | 39 #include "core/frame/LocalDOMWindow.h" |
| 39 #include "core/frame/LocalFrame.h" | 40 #include "core/frame/LocalFrame.h" |
| 40 #include "core/frame/LocalFrameClient.h" | 41 #include "core/frame/LocalFrameClient.h" |
| 41 #include "core/frame/Settings.h" | 42 #include "core/frame/Settings.h" |
| 42 #include "core/frame/csp/ContentSecurityPolicy.h" | 43 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 43 #include "core/html/HTMLFrameOwnerElement.h" | 44 #include "core/html/HTMLFrameOwnerElement.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 DCHECK(!m_frame); | 152 DCHECK(!m_frame); |
| 152 DCHECK(!m_mainResource); | 153 DCHECK(!m_mainResource); |
| 153 DCHECK(!m_applicationCacheHost); | 154 DCHECK(!m_applicationCacheHost); |
| 154 DCHECK_EQ(m_state, SentDidFinishLoad); | 155 DCHECK_EQ(m_state, SentDidFinishLoad); |
| 155 } | 156 } |
| 156 | 157 |
| 157 DEFINE_TRACE(DocumentLoader) { | 158 DEFINE_TRACE(DocumentLoader) { |
| 158 visitor->trace(m_frame); | 159 visitor->trace(m_frame); |
| 159 visitor->trace(m_fetcher); | 160 visitor->trace(m_fetcher); |
| 160 visitor->trace(m_mainResource); | 161 visitor->trace(m_mainResource); |
| 162 visitor->trace(m_historyItem); | |
| 161 visitor->trace(m_writer); | 163 visitor->trace(m_writer); |
| 162 visitor->trace(m_subresourceFilter); | 164 visitor->trace(m_subresourceFilter); |
| 163 visitor->trace(m_documentLoadTiming); | 165 visitor->trace(m_documentLoadTiming); |
| 164 visitor->trace(m_applicationCacheHost); | 166 visitor->trace(m_applicationCacheHost); |
| 165 visitor->trace(m_contentSecurityPolicy); | 167 visitor->trace(m_contentSecurityPolicy); |
| 166 RawResourceClient::trace(visitor); | 168 RawResourceClient::trace(visitor); |
| 167 } | 169 } |
| 168 | 170 |
| 169 unsigned long DocumentLoader::mainResourceIdentifier() const { | 171 unsigned long DocumentLoader::mainResourceIdentifier() const { |
| 170 return m_mainResource ? m_mainResource->identifier() : 0; | 172 return m_mainResource ? m_mainResource->identifier() : 0; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 268 } |
| 267 | 269 |
| 268 void DocumentLoader::didObserveLoadingBehavior( | 270 void DocumentLoader::didObserveLoadingBehavior( |
| 269 WebLoadingBehaviorFlag behavior) { | 271 WebLoadingBehaviorFlag behavior) { |
| 270 if (m_frame) { | 272 if (m_frame) { |
| 271 DCHECK_GE(m_state, Committed); | 273 DCHECK_GE(m_state, Committed); |
| 272 localFrameClient().didObserveLoadingBehavior(behavior); | 274 localFrameClient().didObserveLoadingBehavior(behavior); |
| 273 } | 275 } |
| 274 } | 276 } |
| 275 | 277 |
| 278 static HistoryCommitType loadTypeToCommitType(FrameLoadType type) { | |
| 279 switch (type) { | |
| 280 case FrameLoadTypeStandard: | |
| 281 return StandardCommit; | |
| 282 case FrameLoadTypeInitialInChildFrame: | |
| 283 case FrameLoadTypeInitialHistoryLoad: | |
| 284 return InitialCommitInChildFrame; | |
| 285 case FrameLoadTypeBackForward: | |
| 286 return BackForwardCommit; | |
| 287 default: | |
| 288 break; | |
| 289 } | |
| 290 return HistoryInertCommit; | |
| 291 } | |
| 292 | |
| 276 void DocumentLoader::updateForSameDocumentNavigation( | 293 void DocumentLoader::updateForSameDocumentNavigation( |
| 277 const KURL& newURL, | 294 const KURL& newURL, |
| 278 SameDocumentNavigationSource sameDocumentNavigationSource) { | 295 SameDocumentNavigationSource sameDocumentNavigationSource, |
| 296 PassRefPtr<SerializedScriptValue> data, | |
| 297 HistoryScrollRestorationType scrollRestorationType, | |
| 298 FrameLoadType type, | |
| 299 Document* initiatingDocument) { | |
| 300 if (m_frame->settings()->getHistoryEntryRequiresUserGesture() && | |
| 301 initiatingDocument && | |
| 302 !initiatingDocument->frame()->hasReceivedUserGesture()) { | |
| 303 type = FrameLoadTypeReplaceCurrentItem; | |
| 304 } | |
| 305 | |
| 279 KURL oldURL = m_request.url(); | 306 KURL oldURL = m_request.url(); |
| 280 m_originalRequest.setURL(newURL); | 307 m_originalRequest.setURL(newURL); |
| 281 m_request.setURL(newURL); | 308 m_request.setURL(newURL); |
| 309 setReplacesCurrentHistoryItem(type != FrameLoadTypeStandard); | |
| 282 if (sameDocumentNavigationSource == SameDocumentNavigationHistoryApi) { | 310 if (sameDocumentNavigationSource == SameDocumentNavigationHistoryApi) { |
| 283 m_request.setHTTPMethod(HTTPNames::GET); | 311 m_request.setHTTPMethod(HTTPNames::GET); |
| 284 m_request.setHTTPBody(nullptr); | 312 m_request.setHTTPBody(nullptr); |
| 285 } | 313 } |
| 286 clearRedirectChain(); | 314 clearRedirectChain(); |
| 287 if (m_isClientRedirect) | 315 if (m_isClientRedirect) |
| 288 appendRedirect(oldURL); | 316 appendRedirect(oldURL); |
| 289 appendRedirect(newURL); | 317 appendRedirect(newURL); |
| 318 | |
| 319 setHistoryItemStateForCommit( | |
| 320 m_historyItem.get(), type, | |
| 321 sameDocumentNavigationSource == SameDocumentNavigationHistoryApi | |
| 322 ? HistoryNavigationType::HistoryApi | |
| 323 : HistoryNavigationType::Fragment); | |
| 324 m_historyItem->setDocumentState(m_frame->document()->formElementsState()); | |
|
Nate Chapin
2017/03/27 21:02:01
This was in FrameLoader::setHistoryItemStateForCom
| |
| 325 if (sameDocumentNavigationSource == SameDocumentNavigationHistoryApi) { | |
| 326 m_historyItem->setStateObject(std::move(data)); | |
| 327 m_historyItem->setScrollRestorationType(scrollRestorationType); | |
| 328 } | |
| 329 localFrameClient().dispatchDidNavigateWithinPage( | |
| 330 m_historyItem.get(), loadTypeToCommitType(type), initiatingDocument); | |
| 290 } | 331 } |
| 291 | 332 |
| 292 const KURL& DocumentLoader::urlForHistory() const { | 333 const KURL& DocumentLoader::urlForHistory() const { |
| 293 return unreachableURL().isEmpty() ? url() : unreachableURL(); | 334 return unreachableURL().isEmpty() ? url() : unreachableURL(); |
| 294 } | 335 } |
| 295 | 336 |
| 296 void DocumentLoader::commitIfReady() { | 337 void DocumentLoader::setHistoryItemStateForCommit( |
| 297 if (m_state < Committed) { | 338 HistoryItem* oldItem, |
| 298 m_state = Committed; | 339 FrameLoadType loadType, |
| 299 frameLoader().commitProvisionalLoad(); | 340 HistoryNavigationType navigationType) { |
| 341 if (!m_historyItem || !isBackForwardLoadType(loadType)) | |
| 342 m_historyItem = HistoryItem::create(); | |
| 343 | |
| 344 m_historyItem->setURL(urlForHistory()); | |
| 345 m_historyItem->setReferrer(SecurityPolicy::generateReferrer( | |
| 346 m_request.getReferrerPolicy(), m_historyItem->url(), | |
| 347 m_request.httpReferrer())); | |
| 348 m_historyItem->setFormInfoFromRequest(m_request); | |
| 349 | |
| 350 // Don't propagate state from the old item to the new item if there isn't an | |
| 351 // old item (obviously), or if this is a back/forward navigation, since we | |
| 352 // explicitly want to restore the state we just committed. | |
| 353 if (!oldItem || isBackForwardLoadType(loadType)) | |
| 354 return; | |
| 355 // Don't propagate state from the old item if this is a different-document | |
| 356 // navigation, unless the before and after pages are logically related. This | |
| 357 // means they have the same url (ignoring fragment) and the new item was | |
| 358 // loaded via reload or client redirect. | |
| 359 HistoryCommitType historyCommitType = loadTypeToCommitType(loadType); | |
| 360 if (navigationType == HistoryNavigationType::DifferentDocument && | |
| 361 (historyCommitType != HistoryInertCommit || | |
| 362 !equalIgnoringFragmentIdentifier(oldItem->url(), m_historyItem->url()))) | |
| 363 return; | |
| 364 m_historyItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber()); | |
| 365 m_historyItem->setScrollOffset(oldItem->getScrollOffset()); | |
| 366 m_historyItem->setDidSaveScrollOrScaleState( | |
| 367 oldItem->didSaveScrollOrScaleState()); | |
| 368 m_historyItem->setVisualViewportScrollOffset( | |
| 369 oldItem->visualViewportScrollOffset()); | |
| 370 m_historyItem->setPageScaleFactor(oldItem->pageScaleFactor()); | |
| 371 m_historyItem->setScrollRestorationType(oldItem->scrollRestorationType()); | |
| 372 | |
| 373 // The item sequence number determines whether items are "the same", such | |
| 374 // back/forward navigation between items with the same item sequence number is | |
| 375 // a no-op. Only treat this as identical if the navigation did not create a | |
| 376 // back/forward entry and the url is identical or it was loaded via | |
| 377 // history.replaceState(). | |
| 378 if (historyCommitType == HistoryInertCommit && | |
| 379 (navigationType == HistoryNavigationType::HistoryApi || | |
| 380 oldItem->url() == m_historyItem->url())) { | |
| 381 m_historyItem->setStateObject(oldItem->stateObject()); | |
| 382 m_historyItem->setItemSequenceNumber(oldItem->itemSequenceNumber()); | |
| 300 } | 383 } |
| 301 } | 384 } |
| 302 | 385 |
| 303 void DocumentLoader::notifyFinished(Resource* resource) { | 386 void DocumentLoader::notifyFinished(Resource* resource) { |
| 304 DCHECK_EQ(m_mainResource, resource); | 387 DCHECK_EQ(m_mainResource, resource); |
| 305 DCHECK(m_mainResource); | 388 DCHECK(m_mainResource); |
| 306 | 389 |
| 307 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { | 390 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { |
| 308 finishedLoading(m_mainResource->loadFinishTime()); | 391 finishedLoading(m_mainResource->loadFinishTime()); |
| 309 return; | 392 return; |
| 310 } | 393 } |
| 311 | 394 |
| 312 if (m_applicationCacheHost) | 395 if (m_applicationCacheHost) |
| 313 m_applicationCacheHost->failedLoadingMainResource(); | 396 m_applicationCacheHost->failedLoadingMainResource(); |
| 314 | 397 |
| 315 if (m_mainResource->resourceError().wasBlockedByResponse()) { | 398 if (m_mainResource->resourceError().wasBlockedByResponse()) { |
| 316 probe::canceledAfterReceivedResourceResponse( | 399 probe::canceledAfterReceivedResourceResponse( |
| 317 m_frame, this, mainResourceIdentifier(), resource->response(), | 400 m_frame, this, mainResourceIdentifier(), resource->response(), |
| 318 m_mainResource.get()); | 401 m_mainResource.get()); |
| 319 } | 402 } |
| 320 | 403 |
| 321 frameLoader().loadFailed(this, m_mainResource->resourceError()); | 404 loadFailed(m_mainResource->resourceError()); |
| 322 clearMainResourceHandle(); | 405 clearMainResourceHandle(); |
| 323 } | 406 } |
| 324 | 407 |
| 408 void DocumentLoader::loadFailed(const ResourceError& error) { | |
| 409 if (!error.isCancellation() && m_frame->owner()) { | |
| 410 // FIXME: For now, fallback content doesn't work cross process. | |
| 411 if (m_frame->owner()->isLocal()) | |
| 412 m_frame->deprecatedLocalOwner()->renderFallbackContent(); | |
| 413 } | |
| 414 | |
| 415 HistoryCommitType historyCommitType = loadTypeToCommitType(m_loadType); | |
| 416 FrameLoader& loader = frameLoader(); | |
| 417 if (m_state < Committed) { | |
| 418 if (m_state == NotStarted) | |
| 419 probe::frameClearedScheduledClientNavigation(m_frame); | |
| 420 m_state = SentDidFinishLoad; | |
| 421 localFrameClient().dispatchDidFailProvisionalLoad(error, historyCommitType); | |
| 422 if (!m_frame) | |
| 423 return; | |
| 424 loader.detachProvisionalDocumentLoader(this); | |
| 425 } else if (m_state == Committed) { | |
| 426 if (m_frame->document()->parser()) | |
| 427 m_frame->document()->parser()->stopParsing(); | |
| 428 m_state = SentDidFinishLoad; | |
| 429 localFrameClient().dispatchDidFailLoad(error, historyCommitType); | |
| 430 } | |
| 431 loader.checkCompleted(); | |
| 432 } | |
| 433 | |
| 325 void DocumentLoader::finishedLoading(double finishTime) { | 434 void DocumentLoader::finishedLoading(double finishTime) { |
| 326 DCHECK(m_frame->loader().stateMachine()->creatingInitialEmptyDocument() || | 435 DCHECK(m_frame->loader().stateMachine()->creatingInitialEmptyDocument() || |
| 327 !m_frame->page()->suspended() || | 436 !m_frame->page()->suspended() || |
| 328 MainThreadDebugger::instance()->isPaused()); | 437 MainThreadDebugger::instance()->isPaused()); |
| 329 | 438 |
| 330 double responseEndTime = finishTime; | 439 double responseEndTime = finishTime; |
| 331 if (!responseEndTime) | 440 if (!responseEndTime) |
| 332 responseEndTime = m_timeOfLastDataReceived; | 441 responseEndTime = m_timeOfLastDataReceived; |
| 333 if (!responseEndTime) | 442 if (!responseEndTime) |
| 334 responseEndTime = monotonicallyIncreasingTime(); | 443 responseEndTime = monotonicallyIncreasingTime(); |
| 335 timing().setResponseEnd(responseEndTime); | 444 timing().setResponseEnd(responseEndTime); |
| 336 | |
| 337 commitIfReady(); | |
|
Nate Chapin
2017/03/27 21:02:01
The equivalent of commitIfReady() now happens in e
| |
| 338 if (!m_frame) | |
| 339 return; | |
| 340 | |
| 341 if (!maybeCreateArchive()) { | 445 if (!maybeCreateArchive()) { |
| 342 // If this is an empty document, it will not have actually been created yet. | 446 // If this is an empty document, it will not have actually been created yet. |
| 343 // Commit dummy data so that DocumentWriter::begin() gets called and creates | 447 // Commit dummy data so that DocumentWriter::begin() gets called and creates |
| 344 // the Document. | 448 // the Document. |
| 345 if (!m_writer) | 449 if (!m_writer) |
| 346 commitData(0, 0); | 450 commitData(0, 0); |
| 347 } | 451 } |
| 348 | 452 |
| 349 if (!m_frame) | 453 if (!m_frame) |
| 350 return; | 454 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 m_navigationType, NavigationPolicyCurrentTab, m_loadType, | 495 m_navigationType, NavigationPolicyCurrentTab, m_loadType, |
| 392 isClientRedirect(), nullptr) != NavigationPolicyCurrentTab) { | 496 isClientRedirect(), nullptr) != NavigationPolicyCurrentTab) { |
| 393 m_fetcher->stopFetching(); | 497 m_fetcher->stopFetching(); |
| 394 return false; | 498 return false; |
| 395 } | 499 } |
| 396 | 500 |
| 397 DCHECK(timing().fetchStart()); | 501 DCHECK(timing().fetchStart()); |
| 398 appendRedirect(requestURL); | 502 appendRedirect(requestURL); |
| 399 timing().addRedirect(redirectResponse.url(), requestURL); | 503 timing().addRedirect(redirectResponse.url(), requestURL); |
| 400 | 504 |
| 401 // If a redirection happens during a back/forward navigation, don't restore | 505 // If a redirection happens during a back/forward navigation, don't restore |
|
yhirano
2017/03/29 09:38:13
Is this comment still valid?
Nate Chapin
2017/03/29 18:23:06
Yes, this is the same behavior as before.
| |
| 402 // any state from the old HistoryItem. There is a provisional history item for | 506 // any state from the old HistoryItem. There is a provisional history item for |
| 403 // back/forward navigation only. In the other case, clearing it is a no-op. | 507 // back/forward navigation only. In the other case, clearing it is a no-op. |
| 404 frameLoader().clearProvisionalHistoryItem(); | 508 m_historyItem.clear(); |
| 405 | 509 |
| 406 localFrameClient().dispatchDidReceiveServerRedirectForProvisionalLoad(); | 510 localFrameClient().dispatchDidReceiveServerRedirectForProvisionalLoad(); |
| 407 | 511 |
| 408 return true; | 512 return true; |
| 409 } | 513 } |
| 410 | 514 |
| 411 static bool canShowMIMEType(const String& mimeType, LocalFrame* frame) { | 515 static bool canShowMIMEType(const String& mimeType, LocalFrame* frame) { |
| 412 if (MIMETypeRegistry::isSupportedMIMEType(mimeType)) | 516 if (MIMETypeRegistry::isSupportedMIMEType(mimeType)) |
| 413 return true; | 517 return true; |
| 414 PluginData* pluginData = frame->pluginData(); | 518 PluginData* pluginData = frame->pluginData(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 if (m_frame->owner() && m_response.isHTTP() && | 644 if (m_frame->owner() && m_response.isHTTP() && |
| 541 !FetchUtils::isOkStatus(m_response.httpStatusCode())) | 645 !FetchUtils::isOkStatus(m_response.httpStatusCode())) |
| 542 m_frame->owner()->renderFallbackContent(); | 646 m_frame->owner()->renderFallbackContent(); |
| 543 } | 647 } |
| 544 | 648 |
| 545 void DocumentLoader::ensureWriter(const AtomicString& mimeType, | 649 void DocumentLoader::ensureWriter(const AtomicString& mimeType, |
| 546 const KURL& overridingURL) { | 650 const KURL& overridingURL) { |
| 547 if (m_writer) | 651 if (m_writer) |
| 548 return; | 652 return; |
| 549 | 653 |
| 654 // Set history state before commitProvisionalLoad() so that we still have | |
| 655 // access to the previous committed DocumentLoader's HistoryItem, in case we | |
| 656 // need to copy state from it. | |
| 657 if (!frameLoader().stateMachine()->creatingInitialEmptyDocument()) { | |
| 658 setHistoryItemStateForCommit(frameLoader().documentLoader()->historyItem(), | |
| 659 m_loadType, | |
| 660 HistoryNavigationType::DifferentDocument); | |
| 661 } | |
| 662 | |
| 663 DCHECK_EQ(m_state, Provisional); | |
| 664 frameLoader().commitProvisionalLoad(); | |
| 665 if (!m_frame) | |
| 666 return; | |
| 667 | |
| 550 const AtomicString& encoding = response().textEncodingName(); | 668 const AtomicString& encoding = response().textEncodingName(); |
| 551 | 669 |
| 552 // Prepare a DocumentInit before clearing the frame, because it may need to | 670 // Prepare a DocumentInit before clearing the frame, because it may need to |
| 553 // inherit an aliased security context. | 671 // inherit an aliased security context. |
| 554 Document* owner = nullptr; | 672 Document* owner = nullptr; |
| 555 // TODO(dcheng): This differs from the behavior of both IE and Firefox: the | 673 // TODO(dcheng): This differs from the behavior of both IE and Firefox: the |
| 556 // origin is inherited from the document that loaded the URL. | 674 // origin is inherited from the document that loaded the URL. |
| 557 if (shouldInheritSecurityOriginFromOwner(url())) { | 675 if (shouldInheritSecurityOriginFromOwner(url())) { |
| 558 Frame* ownerFrame = m_frame->tree().parent(); | 676 Frame* ownerFrame = m_frame->tree().parent(); |
| 559 if (!ownerFrame) | 677 if (!ownerFrame) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 574 installNewDocument(init, mimeType, encoding, | 692 installNewDocument(init, mimeType, encoding, |
| 575 InstallNewDocumentReason::kNavigation, parsingPolicy, | 693 InstallNewDocumentReason::kNavigation, parsingPolicy, |
| 576 overridingURL); | 694 overridingURL); |
| 577 m_writer->setDocumentWasLoadedAsPartOfNavigation(); | 695 m_writer->setDocumentWasLoadedAsPartOfNavigation(); |
| 578 m_frame->document()->maybeHandleHttpRefresh( | 696 m_frame->document()->maybeHandleHttpRefresh( |
| 579 m_response.httpHeaderField(HTTPNames::Refresh), | 697 m_response.httpHeaderField(HTTPNames::Refresh), |
| 580 Document::HttpRefreshFromHeader); | 698 Document::HttpRefreshFromHeader); |
| 581 } | 699 } |
| 582 | 700 |
| 583 void DocumentLoader::commitData(const char* bytes, size_t length) { | 701 void DocumentLoader::commitData(const char* bytes, size_t length) { |
| 584 DCHECK_EQ(m_state, Committed); | |
| 585 ensureWriter(m_response.mimeType()); | 702 ensureWriter(m_response.mimeType()); |
| 703 DCHECK_GE(m_state, Committed); | |
|
yhirano
2017/03/29 09:38:13
There are several early returns in FrameLoader::pr
Nate Chapin
2017/03/29 18:23:06
The early exits are the reason it's DCHECK_GE() in
| |
| 586 | 704 |
| 587 // This can happen if document.close() is called by an event handler while | 705 // This can happen if document.close() is called by an event handler while |
| 588 // there's still pending incoming data. | 706 // there's still pending incoming data. |
| 589 if (m_frame && !m_frame->document()->parsing()) | 707 if (!m_frame || !m_frame->document()->parsing()) |
| 590 return; | 708 return; |
| 591 | 709 |
| 592 if (length) | 710 if (length) |
| 593 m_dataReceived = true; | 711 m_dataReceived = true; |
| 594 | 712 |
| 595 m_writer->addData(bytes, length); | 713 m_writer->addData(bytes, length); |
| 596 } | 714 } |
| 597 | 715 |
| 598 void DocumentLoader::dataReceived(Resource* resource, | 716 void DocumentLoader::dataReceived(Resource* resource, |
| 599 const char* data, | 717 const char* data, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 630 // All data has been consumed, so flush the buffer. | 748 // All data has been consumed, so flush the buffer. |
| 631 m_dataBuffer->clear(); | 749 m_dataBuffer->clear(); |
| 632 } | 750 } |
| 633 | 751 |
| 634 void DocumentLoader::processData(const char* data, size_t length) { | 752 void DocumentLoader::processData(const char* data, size_t length) { |
| 635 m_applicationCacheHost->mainResourceDataReceived(data, length); | 753 m_applicationCacheHost->mainResourceDataReceived(data, length); |
| 636 m_timeOfLastDataReceived = monotonicallyIncreasingTime(); | 754 m_timeOfLastDataReceived = monotonicallyIncreasingTime(); |
| 637 | 755 |
| 638 if (isArchiveMIMEType(response().mimeType())) | 756 if (isArchiveMIMEType(response().mimeType())) |
| 639 return; | 757 return; |
| 640 commitIfReady(); | |
| 641 if (!m_frame) | |
| 642 return; | |
| 643 commitData(data, length); | 758 commitData(data, length); |
| 644 | 759 |
| 645 // If we are sending data to MediaDocument, we should stop here and cancel the | 760 // If we are sending data to MediaDocument, we should stop here and cancel the |
| 646 // request. | 761 // request. |
| 647 if (m_frame && m_frame->document()->isMediaDocument()) | 762 if (m_frame && m_frame->document()->isMediaDocument()) |
| 648 m_fetcher->stopFetching(); | 763 m_fetcher->stopFetching(); |
| 649 } | 764 } |
| 650 | 765 |
| 651 void DocumentLoader::clearRedirectChain() { | 766 void DocumentLoader::clearRedirectChain() { |
| 652 m_redirectChain.clear(); | 767 m_redirectChain.clear(); |
| 653 } | 768 } |
| 654 | 769 |
| 655 void DocumentLoader::appendRedirect(const KURL& url) { | 770 void DocumentLoader::appendRedirect(const KURL& url) { |
| 656 m_redirectChain.push_back(url); | 771 m_redirectChain.push_back(url); |
| 657 } | 772 } |
| 658 | 773 |
| 659 void DocumentLoader::detachFromFrame() { | 774 void DocumentLoader::detachFromFrame() { |
| 660 DCHECK(m_frame); | 775 DCHECK(m_frame); |
| 661 | 776 |
| 662 // It never makes sense to have a document loader that is detached from its | 777 // It never makes sense to have a document loader that is detached from its |
| 663 // frame have any loads active, so go ahead and kill all the loads. | 778 // frame have any loads active, so go ahead and kill all the loads. |
| 664 m_fetcher->stopFetching(); | 779 m_fetcher->stopFetching(); |
| 665 | 780 |
| 666 if (m_frame && !sentDidFinishLoad()) | 781 if (m_frame && !sentDidFinishLoad()) |
| 667 frameLoader().loadFailed(this, ResourceError::cancelledError(url())); | 782 loadFailed(ResourceError::cancelledError(url())); |
| 668 | 783 |
| 669 // If that load cancellation triggered another detach, leave. | 784 // If that load cancellation triggered another detach, leave. |
| 670 // (fast/frames/detach-frame-nested-no-crash.html is an example of this.) | 785 // (fast/frames/detach-frame-nested-no-crash.html is an example of this.) |
| 671 if (!m_frame) | 786 if (!m_frame) |
| 672 return; | 787 return; |
| 673 | 788 |
| 674 m_fetcher->clearContext(); | 789 m_fetcher->clearContext(); |
| 675 m_applicationCacheHost->detachFromDocumentLoader(); | 790 m_applicationCacheHost->detachFromDocumentLoader(); |
| 676 m_applicationCacheHost.clear(); | 791 m_applicationCacheHost.clear(); |
| 677 m_serviceWorkerNetworkProvider = nullptr; | 792 m_serviceWorkerNetworkProvider = nullptr; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 694 return false; | 809 return false; |
| 695 | 810 |
| 696 DCHECK(m_mainResource); | 811 DCHECK(m_mainResource); |
| 697 ArchiveResource* mainResource = | 812 ArchiveResource* mainResource = |
| 698 m_fetcher->createArchive(m_mainResource.get()); | 813 m_fetcher->createArchive(m_mainResource.get()); |
| 699 if (!mainResource) | 814 if (!mainResource) |
| 700 return false; | 815 return false; |
| 701 // The origin is the MHTML file, we need to set the base URL to the document | 816 // The origin is the MHTML file, we need to set the base URL to the document |
| 702 // encoded in the MHTML so relative URLs are resolved properly. | 817 // encoded in the MHTML so relative URLs are resolved properly. |
| 703 ensureWriter(mainResource->mimeType(), mainResource->url()); | 818 ensureWriter(mainResource->mimeType(), mainResource->url()); |
| 819 if (!m_frame) | |
| 820 return false; | |
| 704 | 821 |
| 705 // The Document has now been created. | 822 // The Document has now been created. |
| 706 m_frame->document()->enforceSandboxFlags(SandboxAll); | 823 m_frame->document()->enforceSandboxFlags(SandboxAll); |
| 707 | 824 |
| 708 commitData(mainResource->data()->data(), mainResource->data()->size()); | 825 commitData(mainResource->data()->data(), mainResource->data()->size()); |
| 709 return true; | 826 return true; |
| 710 } | 827 } |
| 711 | 828 |
| 712 const AtomicString& DocumentLoader::responseMIMEType() const { | 829 const AtomicString& DocumentLoader::responseMIMEType() const { |
| 713 return m_response.mimeType(); | 830 return m_response.mimeType(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 | 898 |
| 782 void DocumentLoader::endWriting() { | 899 void DocumentLoader::endWriting() { |
| 783 m_writer->end(); | 900 m_writer->end(); |
| 784 m_writer.clear(); | 901 m_writer.clear(); |
| 785 } | 902 } |
| 786 | 903 |
| 787 void DocumentLoader::didInstallNewDocument(Document* document) { | 904 void DocumentLoader::didInstallNewDocument(Document* document) { |
| 788 document->setReadyState(Document::Loading); | 905 document->setReadyState(Document::Loading); |
| 789 document->initContentSecurityPolicy(m_contentSecurityPolicy.release()); | 906 document->initContentSecurityPolicy(m_contentSecurityPolicy.release()); |
| 790 | 907 |
| 791 frameLoader().didInstallNewDocument(); | 908 if (m_historyItem && isBackForwardLoadType(m_loadType)) |
| 909 document->setStateForNewFormElements(m_historyItem->getDocumentState()); | |
| 792 | 910 |
| 793 String suboriginHeader = m_response.httpHeaderField(HTTPNames::Suborigin); | 911 String suboriginHeader = m_response.httpHeaderField(HTTPNames::Suborigin); |
| 794 if (!suboriginHeader.isNull()) { | 912 if (!suboriginHeader.isNull()) { |
| 795 Vector<String> messages; | 913 Vector<String> messages; |
| 796 Suborigin suborigin; | 914 Suborigin suborigin; |
| 797 if (parseSuboriginHeader(suboriginHeader, &suborigin, messages)) | 915 if (parseSuboriginHeader(suboriginHeader, &suborigin, messages)) |
| 798 document->enforceSuborigin(suborigin); | 916 document->enforceSuborigin(suborigin); |
| 799 | 917 |
| 800 for (auto& message : messages) { | 918 for (auto& message : messages) { |
| 801 document->addConsoleMessage( | 919 document->addConsoleMessage( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 UseCounter::count(*document, UseCounter::ReferrerPolicyHeader); | 954 UseCounter::count(*document, UseCounter::ReferrerPolicyHeader); |
| 837 document->parseAndSetReferrerPolicy(referrerPolicyHeader); | 955 document->parseAndSetReferrerPolicy(referrerPolicyHeader); |
| 838 } | 956 } |
| 839 | 957 |
| 840 localFrameClient().didCreateNewDocument(); | 958 localFrameClient().didCreateNewDocument(); |
| 841 } | 959 } |
| 842 | 960 |
| 843 void DocumentLoader::didCommitNavigation() { | 961 void DocumentLoader::didCommitNavigation() { |
| 844 if (frameLoader().stateMachine()->creatingInitialEmptyDocument()) | 962 if (frameLoader().stateMachine()->creatingInitialEmptyDocument()) |
| 845 return; | 963 return; |
| 846 frameLoader().receivedFirstData(); | 964 |
| 965 localFrameClient().dispatchDidCommitLoad(m_historyItem.get(), | |
| 966 loadTypeToCommitType(m_loadType)); | |
| 967 | |
| 968 // When the embedder gets notified (above) that the new navigation has | |
| 969 // committed, the embedder will drop the old Content Security Policy and | |
| 970 // therefore now is a good time to report to the embedder the Content | |
| 971 // Security Policies that have accumulated so far for the new navigation. | |
| 972 m_frame->securityContext()->contentSecurityPolicy()->reportAccumulatedHeaders( | |
| 973 &localFrameClient()); | |
| 974 | |
| 975 if (!m_frame->loader().stateMachine()->committedMultipleRealLoads() && | |
|
yhirano
2017/03/29 09:38:13
Can you tell my why you changed the calling order
Nate Chapin
2017/03/29 18:23:06
It was accidental, but when we update FrameLoaderS
| |
| 976 m_loadType == FrameLoadTypeStandard) { | |
| 977 m_frame->loader().stateMachine()->advanceTo( | |
| 978 FrameLoaderStateMachine::CommittedMultipleRealLoads); | |
| 979 } | |
| 847 | 980 |
| 848 // didObserveLoadingBehavior() must be called after dispatchDidCommitLoad() is | 981 // didObserveLoadingBehavior() must be called after dispatchDidCommitLoad() is |
| 849 // called for the metrics tracking logic to handle it properly. | 982 // called for the metrics tracking logic to handle it properly. |
| 850 if (m_serviceWorkerNetworkProvider && | 983 if (m_serviceWorkerNetworkProvider && |
| 851 m_serviceWorkerNetworkProvider->isControlledByServiceWorker()) { | 984 m_serviceWorkerNetworkProvider->isControlledByServiceWorker()) { |
| 852 localFrameClient().didObserveLoadingBehavior( | 985 localFrameClient().didObserveLoadingBehavior( |
| 853 WebLoadingBehaviorServiceWorkerControlled); | 986 WebLoadingBehaviorServiceWorkerControlled); |
| 854 } | 987 } |
| 855 | 988 |
| 856 // Links with media values need more information (like viewport information). | 989 // Links with media values need more information (like viewport information). |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 InstallNewDocumentReason::kJavascriptURL, | 1078 InstallNewDocumentReason::kJavascriptURL, |
| 946 ForceSynchronousParsing, KURL()); | 1079 ForceSynchronousParsing, KURL()); |
| 947 if (!source.isNull()) | 1080 if (!source.isNull()) |
| 948 m_writer->appendReplacingData(source); | 1081 m_writer->appendReplacingData(source); |
| 949 endWriting(); | 1082 endWriting(); |
| 950 } | 1083 } |
| 951 | 1084 |
| 952 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); | 1085 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); |
| 953 | 1086 |
| 954 } // namespace blink | 1087 } // namespace blink |
| OLD | NEW |