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

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

Issue 2661743002: PlzNavigate: Invoke didStartProvisionalLoad() when the renderer initiates a navigation in startLoad( (Closed)
Patch Set: Rebased to tip Created 3 years, 10 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, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
10 * Copyright (C) 2011 Google Inc. All rights reserved. 10 * Copyright (C) 2011 Google Inc. All rights reserved.
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 } 1492 }
1493 1493
1494 HistoryCommitType historyCommitType = 1494 HistoryCommitType historyCommitType =
1495 loadTypeToCommitType(loader->loadType()); 1495 loadTypeToCommitType(loader->loadType());
1496 if (loader == m_provisionalDocumentLoader) { 1496 if (loader == m_provisionalDocumentLoader) {
1497 m_provisionalDocumentLoader->setSentDidFinishLoad(); 1497 m_provisionalDocumentLoader->setSentDidFinishLoad();
1498 client()->dispatchDidFailProvisionalLoad(error, historyCommitType); 1498 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1499 if (loader != m_provisionalDocumentLoader) 1499 if (loader != m_provisionalDocumentLoader)
1500 return; 1500 return;
1501 detachDocumentLoader(m_provisionalDocumentLoader); 1501 detachDocumentLoader(m_provisionalDocumentLoader);
1502 } else { 1502 } else if (loader == m_documentLoader) {
1503 DCHECK_EQ(loader, m_documentLoader);
Nate Chapin 2017/02/02 19:16:48 I assume this is because tempLoader->detachFromFra
ananta 2017/02/02 23:54:02 Reverted this change
1504 if (m_frame->document()->parser()) 1503 if (m_frame->document()->parser())
1505 m_frame->document()->parser()->stopParsing(); 1504 m_frame->document()->parser()->stopParsing();
1506 if (!m_documentLoader->sentDidFinishLoad()) { 1505 if (!m_documentLoader->sentDidFinishLoad()) {
1507 m_documentLoader->setSentDidFinishLoad(); 1506 m_documentLoader->setSentDidFinishLoad();
1508 client()->dispatchDidFailLoad(error, historyCommitType); 1507 client()->dispatchDidFailLoad(error, historyCommitType);
1509 } 1508 }
1510 } 1509 }
1511 checkCompleted(); 1510 checkCompleted();
1512 } 1511 }
1513 1512
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 !UserGestureIndicator::utilizeUserGesture()) 1673 !UserGestureIndicator::utilizeUserGesture())
1675 return false; 1674 return false;
1676 client()->loadURLExternally(request, policy, String(), 1675 client()->loadURLExternally(request, policy, String(),
1677 replacesCurrentHistoryItem); 1676 replacesCurrentHistoryItem);
1678 return false; 1677 return false;
1679 } 1678 }
1680 1679
1681 bool FrameLoader::checkLoadCanStart(FrameLoadRequest& frameLoadRequest, 1680 bool FrameLoader::checkLoadCanStart(FrameLoadRequest& frameLoadRequest,
1682 FrameLoadType type, 1681 FrameLoadType type,
1683 NavigationPolicy navigationPolicy, 1682 NavigationPolicy navigationPolicy,
1684 NavigationType navigationType) { 1683 NavigationType navigationType,
1684 DocumentLoader* loader) {
1685 if (m_frame->document()->pageDismissalEventBeingDispatched() != 1685 if (m_frame->document()->pageDismissalEventBeingDispatched() !=
1686 Document::NoDismissal) { 1686 Document::NoDismissal) {
1687 return false; 1687 return false;
1688 } 1688 }
1689 1689
1690 // Record the latest requiredCSP value that will be used when sending this 1690 // Record the latest requiredCSP value that will be used when sending this
1691 // request. 1691 // request.
1692 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest(); 1692 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest();
1693 recordLatestRequiredCSP(); 1693 recordLatestRequiredCSP();
1694 modifyRequestForCSP(resourceRequest, nullptr); 1694 modifyRequestForCSP(resourceRequest, nullptr);
1695 1695
1696 if (!shouldContinueForNavigationPolicy( 1696 if (!shouldContinueForNavigationPolicy(
1697 resourceRequest, frameLoadRequest.substituteData(), nullptr, 1697 resourceRequest, frameLoadRequest.substituteData(), loader,
1698 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(), 1698 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(),
1699 navigationType, navigationPolicy, type, 1699 navigationType, navigationPolicy, type,
1700 frameLoadRequest.clientRedirect() == 1700 frameLoadRequest.clientRedirect() ==
1701 ClientRedirectPolicy::ClientRedirect, 1701 ClientRedirectPolicy::ClientRedirect,
1702 frameLoadRequest.form())) { 1702 frameLoadRequest.form())) {
1703 return false; 1703 return false;
1704 } 1704 }
1705 1705
1706 m_frame->document()->cancelParsing(); 1706 m_frame->document()->cancelParsing();
1707 detachDocumentLoader(m_provisionalDocumentLoader); 1707 detachDocumentLoader(m_provisionalDocumentLoader);
(...skipping 13 matching lines...) Expand all
1721 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest(); 1721 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest();
1722 NavigationType navigationType = determineNavigationType( 1722 NavigationType navigationType = determineNavigationType(
1723 type, resourceRequest.httpBody() || frameLoadRequest.form(), 1723 type, resourceRequest.httpBody() || frameLoadRequest.form(),
1724 frameLoadRequest.triggeringEvent()); 1724 frameLoadRequest.triggeringEvent());
1725 resourceRequest.setRequestContext( 1725 resourceRequest.setRequestContext(
1726 determineRequestContextFromNavigationType(navigationType)); 1726 determineRequestContextFromNavigationType(navigationType));
1727 resourceRequest.setFrameType(m_frame->isMainFrame() 1727 resourceRequest.setFrameType(m_frame->isMainFrame()
1728 ? WebURLRequest::FrameTypeTopLevel 1728 ? WebURLRequest::FrameTypeTopLevel
1729 : WebURLRequest::FrameTypeNested); 1729 : WebURLRequest::FrameTypeNested);
1730 1730
1731 // In PlzNavigate, the didStartProvisionalLoad() notification happens after
1732 // the navigation event, which causes a number of layout tests to fail. We
1733 // can call didStartProvisionalLoad() early before a navigation attempt is
1734 // sent to the browser. This should work correctly in the non PlzNavigate
1735 // case as well. However consumers of didStartProvisionalLoad() rely on the
1736 // provisionalLoader being created and save state in it. To workaround this
1737 // we create a temporary DocumentLoader instance and pass it to the
1738 // didStartProvisionalLoad() function. This is then promoted to be the
1739 // provisional loader if navigation is handled in blink.
1740 // TODO(ananta)
1741 // We should get rid of the dependency on the DocumentLoader in consumers of
1742 // the didStartProvisionalLoad() notification.
1743 DocumentLoader* tempLoader(client()->createDocumentLoader(
Nate Chapin 2017/02/02 19:16:48 I don't love the name tempLoader. newLoader? Just
ananta 2017/02/02 23:54:02 Moved this code to a helper function FrameLoader::
1744 m_frame, resourceRequest,
1745 frameLoadRequest.substituteData().isValid()
1746 ? frameLoadRequest.substituteData()
1747 : defaultSubstituteDataForURL(resourceRequest.url()),
1748 frameLoadRequest.clientRedirect()));
1749 tempLoader->setLoadType(type);
1750 tempLoader->setNavigationType(navigationType);
1751 tempLoader->setReplacesCurrentHistoryItem(type ==
1752 FrameLoadTypeReplaceCurrentItem);
1753
1754 client()->dispatchDidStartProvisionalLoad(tempLoader);
1755 DCHECK(tempLoader);
1756
1731 if (!checkLoadCanStart(frameLoadRequest, type, navigationPolicy, 1757 if (!checkLoadCanStart(frameLoadRequest, type, navigationPolicy,
1732 navigationType)) { 1758 navigationType, tempLoader)) {
1733 // PlzNavigate: if the navigation is a commit of a client-handled 1759 // PlzNavigate: if the navigation is a commit of a client-handled
1734 // navigation, record that there is no longer a navigation handled by the 1760 // navigation, record that there is no longer a navigation handled by the
1735 // client. 1761 // client.
1736 if (m_isNavigationHandledByClient && 1762 if (m_isNavigationHandledByClient &&
1737 !frameLoadRequest.resourceRequest().checkForBrowserSideNavigation()) { 1763 !frameLoadRequest.resourceRequest().checkForBrowserSideNavigation()) {
1738 m_isNavigationHandledByClient = false; 1764 m_isNavigationHandledByClient = false;
1739 } 1765 }
1766 tempLoader->setSentDidFinishLoad();
1767 tempLoader->detachFromFrame();
1740 return; 1768 return;
1741 } 1769 }
1742 1770
1743 m_provisionalDocumentLoader = client()->createDocumentLoader( 1771 m_provisionalDocumentLoader = tempLoader;
1744 m_frame, resourceRequest,
1745 frameLoadRequest.substituteData().isValid()
1746 ? frameLoadRequest.substituteData()
1747 : defaultSubstituteDataForURL(resourceRequest.url()),
1748 frameLoadRequest.clientRedirect());
1749 m_provisionalDocumentLoader->setLoadType(type);
1750 m_provisionalDocumentLoader->setNavigationType(navigationType);
1751 m_provisionalDocumentLoader->setReplacesCurrentHistoryItem(
1752 type == FrameLoadTypeReplaceCurrentItem);
1753 1772
1754 // PlzNavigate: We need to ensure that script initiated navigations are 1773 // PlzNavigate: We need to ensure that script initiated navigations are
1755 // honored. 1774 // honored.
1756 if (!m_isNavigationHandledByClient) { 1775 if (!m_isNavigationHandledByClient) {
1757 m_frame->navigationScheduler().cancel(); 1776 m_frame->navigationScheduler().cancel();
1758 m_checkTimer.stop(); 1777 m_checkTimer.stop();
1759 } 1778 }
1760 1779
1761 if (frameLoadRequest.form()) 1780 if (frameLoadRequest.form())
1762 client()->dispatchWillSubmitForm(frameLoadRequest.form()); 1781 client()->dispatchWillSubmitForm(frameLoadRequest.form());
1763 1782
1764 // If the loader wasn't waiting for the client to handle a navigation, update 1783 // If the loader wasn't waiting for the client to handle a navigation, update
1765 // the progress tracker. Otherwise don't, as it was already notified before 1784 // the progress tracker. Otherwise don't, as it was already notified before
1766 // sending the navigation to teh client. 1785 // sending the navigation to teh client.
1767 if (!m_isNavigationHandledByClient) 1786 if (!m_isNavigationHandledByClient)
1768 m_progressTracker->progressStarted(type); 1787 m_progressTracker->progressStarted(type);
1769 else 1788 else
1770 m_isNavigationHandledByClient = false; 1789 m_isNavigationHandledByClient = false;
1771 1790
1772 m_provisionalDocumentLoader->appendRedirect( 1791 m_provisionalDocumentLoader->appendRedirect(
1773 m_provisionalDocumentLoader->getRequest().url()); 1792 m_provisionalDocumentLoader->getRequest().url());
1774 client()->dispatchDidStartProvisionalLoad(); 1793
1775 DCHECK(m_provisionalDocumentLoader);
1776 m_provisionalDocumentLoader->startLoadingMainResource(); 1794 m_provisionalDocumentLoader->startLoadingMainResource();
1777 1795
1778 takeObjectSnapshot(); 1796 takeObjectSnapshot();
1779 } 1797 }
1780 1798
1781 void FrameLoader::applyUserAgent(ResourceRequest& request) { 1799 void FrameLoader::applyUserAgent(ResourceRequest& request) {
1782 String userAgent = this->userAgent(); 1800 String userAgent = this->userAgent();
1783 DCHECK(!userAgent.isNull()); 1801 DCHECK(!userAgent.isNull());
1784 request.setHTTPUserAgent(AtomicString(userAgent)); 1802 request.setHTTPUserAgent(AtomicString(userAgent));
1785 } 1803 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 m_documentLoader ? m_documentLoader->url() : String()); 1975 m_documentLoader ? m_documentLoader->url() : String());
1958 return tracedValue; 1976 return tracedValue;
1959 } 1977 }
1960 1978
1961 inline void FrameLoader::takeObjectSnapshot() const { 1979 inline void FrameLoader::takeObjectSnapshot() const {
1962 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this, 1980 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this,
1963 toTracedValue()); 1981 toTracedValue());
1964 } 1982 }
1965 1983
1966 } // namespace blink 1984 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698