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

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

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

Powered by Google App Engine
This is Rietveld 408576698