Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentLoader.cpp

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

Powered by Google App Engine
This is Rietveld 408576698