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

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

Issue 2694013005: Cleanup blink-side PlzNavigate logic (Closed)
Patch Set: Move most of the placeholder handling to startLoad() 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 FrameLoader::FrameLoader(LocalFrame* frame) 183 FrameLoader::FrameLoader(LocalFrame* frame)
184 : m_frame(frame), 184 : m_frame(frame),
185 m_progressTracker(ProgressTracker::create(frame)), 185 m_progressTracker(ProgressTracker::create(frame)),
186 m_inStopAllLoaders(false), 186 m_inStopAllLoaders(false),
187 m_checkTimer(TaskRunnerHelper::get(TaskType::Networking, frame), 187 m_checkTimer(TaskRunnerHelper::get(TaskType::Networking, frame),
188 this, 188 this,
189 &FrameLoader::checkTimerFired), 189 &FrameLoader::checkTimerFired),
190 m_forcedSandboxFlags(SandboxNone), 190 m_forcedSandboxFlags(SandboxNone),
191 m_dispatchingDidClearWindowObjectInMainWorld(false), 191 m_dispatchingDidClearWindowObjectInMainWorld(false),
192 m_protectProvisionalLoader(false), 192 m_protectProvisionalLoader(false) {
193 m_isNavigationHandledByClient(false) {
194 DCHECK(m_frame); 193 DCHECK(m_frame);
195 TRACE_EVENT_OBJECT_CREATED_WITH_ID("loading", "FrameLoader", this); 194 TRACE_EVENT_OBJECT_CREATED_WITH_ID("loading", "FrameLoader", this);
196 takeObjectSnapshot(); 195 takeObjectSnapshot();
197 } 196 }
198 197
199 FrameLoader::~FrameLoader() { 198 FrameLoader::~FrameLoader() {
200 // Verify that this FrameLoader has been detached. 199 // Verify that this FrameLoader has been detached.
201 DCHECK(!m_progressTracker); 200 DCHECK(!m_progressTracker);
202 } 201 }
203 202
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 if (!allDescendantsAreComplete(frame)) 695 if (!allDescendantsAreComplete(frame))
697 return false; 696 return false;
698 697
699 // Don't notify if the frame is being detached. 698 // Don't notify if the frame is being detached.
700 if (frame->isDetaching()) 699 if (frame->isDetaching())
701 return false; 700 return false;
702 701
703 return true; 702 return true;
704 } 703 }
705 704
706 static bool shouldSendCompleteNotification(LocalFrame* frame, 705 static bool shouldSendCompleteNotification(LocalFrame* frame) {
707 bool isNavigationHandledByClient) {
708 // FIXME: We might have already sent stop notifications and be re-completing. 706 // FIXME: We might have already sent stop notifications and be re-completing.
709 if (!frame->isLoading()) 707 if (!frame->isLoading())
710 return false; 708 return false;
711 // Only send didStopLoading() if there are no navigations in progress at all, 709 // Only send didStopLoading() if there are no navigations in progress at all,
712 // whether committed, provisional, or pending. 710 // whether committed, provisional, or pending.
713 return frame->loader().documentLoader()->sentDidFinishLoad() && 711 return frame->loader().documentLoader()->sentDidFinishLoad() &&
714 !frame->loader().hasProvisionalNavigation(); 712 !frame->loader().hasProvisionalNavigation();
715 } 713 }
716 714
717 void FrameLoader::checkCompleted() { 715 void FrameLoader::checkCompleted() {
(...skipping 19 matching lines...) Expand all
737 // Android. 735 // Android.
738 if (m_frame->isMainFrame()) 736 if (m_frame->isMainFrame())
739 m_frame->document()->viewportDescription().reportMobilePageStats(m_frame); 737 m_frame->document()->viewportDescription().reportMobilePageStats(m_frame);
740 m_documentLoader->setSentDidFinishLoad(); 738 m_documentLoader->setSentDidFinishLoad();
741 client()->dispatchDidFinishLoad(); 739 client()->dispatchDidFinishLoad();
742 // Finishing the load can detach the frame when running layout tests. 740 // Finishing the load can detach the frame when running layout tests.
743 if (!m_frame->client()) 741 if (!m_frame->client())
744 return; 742 return;
745 } 743 }
746 744
747 if (shouldSendCompleteNotification(m_frame, m_isNavigationHandledByClient)) { 745 if (shouldSendCompleteNotification(m_frame)) {
748 m_progressTracker->progressCompleted(); 746 m_progressTracker->progressCompleted();
749 // Retry restoring scroll offset since finishing loading disables content 747 // Retry restoring scroll offset since finishing loading disables content
750 // size clamping. 748 // size clamping.
751 restoreScrollPositionAndViewState(); 749 restoreScrollPositionAndViewState();
752 if (m_documentLoader) 750 if (m_documentLoader)
753 m_documentLoader->setLoadType(FrameLoadTypeStandard); 751 m_documentLoader->setLoadType(FrameLoadTypeStandard);
754 m_frame->domWindow()->finishedLoading(); 752 m_frame->domWindow()->finishedLoading();
755 } 753 }
756 754
757 Frame* parent = m_frame->tree().parent(); 755 Frame* parent = m_frame->tree().parent();
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 Document::NoDismissal) 1232 Document::NoDismissal)
1235 return; 1233 return;
1236 1234
1237 // If this method is called from within this method, infinite recursion can 1235 // If this method is called from within this method, infinite recursion can
1238 // occur (3442218). Avoid this. 1236 // occur (3442218). Avoid this.
1239 if (m_inStopAllLoaders) 1237 if (m_inStopAllLoaders)
1240 return; 1238 return;
1241 1239
1242 m_inStopAllLoaders = true; 1240 m_inStopAllLoaders = true;
1243 1241
1244 if (m_isNavigationHandledByClient) {
Nate Chapin 2017/02/24 23:42:06 Because we know have a dummy DocumentLoader for th
clamy 2017/03/02 14:37:18 Acknowledged.
1245 client()->dispatchDidFailProvisionalLoad(
1246 ResourceError::cancelledError(String()), StandardCommit);
1247 }
1248
1249 clearNavigationHandledByClient();
1250
1251 for (Frame* child = m_frame->tree().firstChild(); child; 1242 for (Frame* child = m_frame->tree().firstChild(); child;
1252 child = child->tree().nextSibling()) { 1243 child = child->tree().nextSibling()) {
1253 if (child->isLocalFrame()) 1244 if (child->isLocalFrame())
1254 toLocalFrame(child)->loader().stopAllLoaders(); 1245 toLocalFrame(child)->loader().stopAllLoaders();
1255 } 1246 }
1256 1247
1257 m_frame->document()->suppressLoadEvent(); 1248 m_frame->document()->suppressLoadEvent();
1258 if (m_documentLoader) 1249 if (m_documentLoader)
1259 m_documentLoader->fetcher()->stopFetching(); 1250 m_documentLoader->fetcher()->stopFetching();
1260 m_frame->document()->cancelParsing(); 1251 m_frame->document()->cancelParsing();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 m_frame->page()->chromeClient().setEventListenerProperties( 1363 m_frame->page()->chromeClient().setEventListenerProperties(
1373 m_frame, WebEventListenerClass::MouseWheel, 1364 m_frame, WebEventListenerClass::MouseWheel,
1374 WebEventListenerProperties::Nothing); 1365 WebEventListenerProperties::Nothing);
1375 m_frame->page()->chromeClient().setEventListenerProperties( 1366 m_frame->page()->chromeClient().setEventListenerProperties(
1376 m_frame, WebEventListenerClass::TouchEndOrCancel, 1367 m_frame, WebEventListenerClass::TouchEndOrCancel,
1377 WebEventListenerProperties::Nothing); 1368 WebEventListenerProperties::Nothing);
1378 } 1369 }
1379 1370
1380 client()->transitionToCommittedForNewPage(); 1371 client()->transitionToCommittedForNewPage();
1381 1372
1382 // PlzNavigate: We need to ensure that script initiated navigations are 1373 m_frame->navigationScheduler().cancel();
1383 // honored.
1384 if (!m_isNavigationHandledByClient)
Nate Chapin 2017/02/24 23:42:06 I'm not sure this was right. If we committed a loa
1385 m_frame->navigationScheduler().cancel();
1386 1374
1387 m_frame->editor().clearLastEditCommand(); 1375 m_frame->editor().clearLastEditCommand();
1388 1376
1389 // If we are still in the process of initializing an empty document then its 1377 // If we are still in the process of initializing an empty document then its
1390 // frame is not in a consistent state for rendering, so avoid 1378 // frame is not in a consistent state for rendering, so avoid
1391 // setJSStatusBarText since it may cause clients to attempt to render the 1379 // setJSStatusBarText since it may cause clients to attempt to render the
1392 // frame. 1380 // frame.
1393 if (!m_stateMachine.creatingInitialEmptyDocument()) { 1381 if (!m_stateMachine.creatingInitialEmptyDocument()) {
1394 LocalDOMWindow* window = m_frame->domWindow(); 1382 LocalDOMWindow* window = m_frame->domWindow();
1395 window->setStatus(String()); 1383 window->setStatus(String());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 const ResourceError& error) { 1492 const ResourceError& error) {
1505 if (!error.isCancellation() && m_frame->owner()) { 1493 if (!error.isCancellation() && m_frame->owner()) {
1506 // FIXME: For now, fallback content doesn't work cross process. 1494 // FIXME: For now, fallback content doesn't work cross process.
1507 if (m_frame->owner()->isLocal()) 1495 if (m_frame->owner()->isLocal())
1508 m_frame->deprecatedLocalOwner()->renderFallbackContent(); 1496 m_frame->deprecatedLocalOwner()->renderFallbackContent();
1509 } 1497 }
1510 1498
1511 HistoryCommitType historyCommitType = 1499 HistoryCommitType historyCommitType =
1512 loadTypeToCommitType(loader->loadType()); 1500 loadTypeToCommitType(loader->loadType());
1513 if (loader == m_provisionalDocumentLoader) { 1501 if (loader == m_provisionalDocumentLoader) {
1502 if (!m_provisionalDocumentLoader->didStart())
1503 InspectorInstrumentation::frameClearedScheduledClientNavigation(m_frame);
1514 m_provisionalDocumentLoader->setSentDidFinishLoad(); 1504 m_provisionalDocumentLoader->setSentDidFinishLoad();
1515 client()->dispatchDidFailProvisionalLoad(error, historyCommitType); 1505 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1516 if (loader != m_provisionalDocumentLoader) 1506 if (loader != m_provisionalDocumentLoader)
1517 return; 1507 return;
1518 detachDocumentLoader(m_provisionalDocumentLoader); 1508 detachDocumentLoader(m_provisionalDocumentLoader);
1519 } else { 1509 } else {
1520 DCHECK_EQ(loader, m_documentLoader); 1510 DCHECK_EQ(loader, m_documentLoader);
1521 if (m_frame->document()->parser()) 1511 if (m_frame->document()->parser())
1522 m_frame->document()->parser()->stopParsing(); 1512 m_frame->document()->parser()->stopParsing();
1523 if (!m_documentLoader->sentDidFinishLoad()) { 1513 if (!m_documentLoader->sentDidFinishLoad()) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 break; 1605 break;
1616 } 1606 }
1617 1607
1618 if (i == targetFrames.size()) 1608 if (i == targetFrames.size())
1619 shouldClose = true; 1609 shouldClose = true;
1620 } 1610 }
1621 1611
1622 return shouldClose; 1612 return shouldClose;
1623 } 1613 }
1624 1614
1625 bool FrameLoader::shouldContinueForNavigationPolicy( 1615 NavigationPolicy FrameLoader::shouldContinueForNavigationPolicy(
1626 const ResourceRequest& request, 1616 const ResourceRequest& request,
1627 const SubstituteData& substituteData, 1617 const SubstituteData& substituteData,
1628 DocumentLoader* loader, 1618 DocumentLoader* loader,
1629 ContentSecurityPolicyDisposition shouldCheckMainWorldContentSecurityPolicy, 1619 ContentSecurityPolicyDisposition shouldCheckMainWorldContentSecurityPolicy,
1630 NavigationType type, 1620 NavigationType type,
1631 NavigationPolicy policy, 1621 NavigationPolicy policy,
1632 FrameLoadType frameLoadType, 1622 FrameLoadType frameLoadType,
1633 bool isClientRedirect, 1623 bool isClientRedirect,
1634 HTMLFormElement* form) { 1624 HTMLFormElement* form) {
1635 // Don't ask if we are loading an empty URL. 1625 // Don't ask if we are loading an empty URL.
1636 if (request.url().isEmpty() || substituteData.isValid()) 1626 if (request.url().isEmpty() || substituteData.isValid())
1637 return true; 1627 return NavigationPolicyCurrentTab;
1638 1628
1639 // If we're loading content into |m_frame| (NavigationPolicyCurrentTab), check 1629 // If we're loading content into |m_frame| (NavigationPolicyCurrentTab), check
1640 // against the parent's Content Security Policy and kill the load if that 1630 // against the parent's Content Security Policy and kill the load if that
1641 // check fails, unless we should bypass the main world's CSP. 1631 // check fails, unless we should bypass the main world's CSP.
1642 if (policy == NavigationPolicyCurrentTab && 1632 if (policy == NavigationPolicyCurrentTab &&
1643 shouldCheckMainWorldContentSecurityPolicy == CheckContentSecurityPolicy) { 1633 shouldCheckMainWorldContentSecurityPolicy == CheckContentSecurityPolicy) {
1644 Frame* parentFrame = m_frame->tree().parent(); 1634 Frame* parentFrame = m_frame->tree().parent();
1645 if (parentFrame) { 1635 if (parentFrame) {
1646 ContentSecurityPolicy* parentPolicy = 1636 ContentSecurityPolicy* parentPolicy =
1647 parentFrame->securityContext()->contentSecurityPolicy(); 1637 parentFrame->securityContext()->contentSecurityPolicy();
1648 if (!parentPolicy->allowFrameFromSource(request.url(), 1638 if (!parentPolicy->allowFrameFromSource(request.url(),
1649 request.redirectStatus())) { 1639 request.redirectStatus())) {
1650 // Fire a load event, as timing attacks would otherwise reveal that the 1640 // Fire a load event, as timing attacks would otherwise reveal that the
1651 // frame was blocked. This way, it looks like every other cross-origin 1641 // frame was blocked. This way, it looks like every other cross-origin
1652 // page load. 1642 // page load.
1653 m_frame->document()->enforceSandboxFlags(SandboxOrigin); 1643 m_frame->document()->enforceSandboxFlags(SandboxOrigin);
1654 m_frame->owner()->dispatchLoad(); 1644 m_frame->owner()->dispatchLoad();
1655 return false; 1645 return NavigationPolicyIgnore;
1656 } 1646 }
1657 } 1647 }
1658 } 1648 }
1659 1649
1660 bool isFormSubmission = type == NavigationTypeFormSubmitted || 1650 bool isFormSubmission = type == NavigationTypeFormSubmitted ||
1661 type == NavigationTypeFormResubmitted; 1651 type == NavigationTypeFormResubmitted;
1662 if (isFormSubmission && 1652 if (isFormSubmission &&
1663 !m_frame->document()->contentSecurityPolicy()->allowFormAction( 1653 !m_frame->document()->contentSecurityPolicy()->allowFormAction(
1664 request.url())) 1654 request.url()))
1665 return false; 1655 return NavigationPolicyIgnore;
1666 1656
1667 bool replacesCurrentHistoryItem = 1657 bool replacesCurrentHistoryItem =
1668 frameLoadType == FrameLoadTypeReplaceCurrentItem; 1658 frameLoadType == FrameLoadTypeReplaceCurrentItem;
1669 policy = client()->decidePolicyForNavigation(request, loader, type, policy, 1659 policy = client()->decidePolicyForNavigation(request, loader, type, policy,
1670 replacesCurrentHistoryItem, 1660 replacesCurrentHistoryItem,
1671 isClientRedirect, form); 1661 isClientRedirect, form);
1672 if (policy == NavigationPolicyCurrentTab) 1662 if (policy == NavigationPolicyCurrentTab ||
1673 return true; 1663 policy == NavigationPolicyIgnore ||
1674 if (policy == NavigationPolicyIgnore) 1664 policy == NavigationPolicyHandledByClient ||
1675 return false; 1665 policy == NavigationPolicyHandledByClientForInitialHistory) {
1676 if (policy == NavigationPolicyHandledByClient) { 1666 return policy;
Nate Chapin 2017/02/24 23:42:06 All of this case should be handling in the main st
1677 setNavigationHandledByClient(); 1667 }
1678 // Mark the frame as loading since the embedder is handling the navigation.
1679 m_progressTracker->progressStarted(frameLoadType);
1680 1668
1681 m_frame->navigationScheduler().cancel();
1682
1683 // If this is a form submit, dispatch that a form is being submitted
1684 // since the embedder is handling the navigation.
1685 if (form)
1686 client()->dispatchWillSubmitForm(form);
1687
1688 m_frame->document()->cancelParsing();
1689
1690 return false;
1691 }
1692 if (!LocalDOMWindow::allowPopUp(*m_frame) && 1669 if (!LocalDOMWindow::allowPopUp(*m_frame) &&
1693 !UserGestureIndicator::utilizeUserGesture()) 1670 !UserGestureIndicator::utilizeUserGesture())
1694 return false; 1671 return NavigationPolicyIgnore;
1695 client()->loadURLExternally(request, policy, String(), 1672 client()->loadURLExternally(request, policy, String(),
1696 replacesCurrentHistoryItem); 1673 replacesCurrentHistoryItem);
1697 return false; 1674 return NavigationPolicyIgnore;
1698 } 1675 }
1699 1676
1700 bool FrameLoader::checkLoadCanStart(FrameLoadRequest& frameLoadRequest, 1677 NavigationPolicy FrameLoader::checkLoadCanStart(
1701 FrameLoadType type, 1678 FrameLoadRequest& frameLoadRequest,
1702 NavigationPolicy navigationPolicy, 1679 FrameLoadType type,
1703 NavigationType navigationType) { 1680 NavigationPolicy navigationPolicy,
1681 NavigationType navigationType) {
1704 if (m_frame->document()->pageDismissalEventBeingDispatched() != 1682 if (m_frame->document()->pageDismissalEventBeingDispatched() !=
1705 Document::NoDismissal) { 1683 Document::NoDismissal) {
1706 return false; 1684 return NavigationPolicyIgnore;
1707 } 1685 }
1708 1686
1709 // Record the latest requiredCSP value that will be used when sending this 1687 // Record the latest requiredCSP value that will be used when sending this
1710 // request. 1688 // request.
1711 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest(); 1689 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest();
1712 recordLatestRequiredCSP(); 1690 recordLatestRequiredCSP();
1713 modifyRequestForCSP(resourceRequest, nullptr); 1691 modifyRequestForCSP(resourceRequest, nullptr);
1714 1692
1715 if (!shouldContinueForNavigationPolicy( 1693 return shouldContinueForNavigationPolicy(
1716 resourceRequest, frameLoadRequest.substituteData(), nullptr, 1694 resourceRequest, frameLoadRequest.substituteData(), nullptr,
1717 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(), 1695 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(),
1718 navigationType, navigationPolicy, type, 1696 navigationType, navigationPolicy, type,
1719 frameLoadRequest.clientRedirect() == 1697 frameLoadRequest.clientRedirect() == ClientRedirectPolicy::ClientRedirect,
1720 ClientRedirectPolicy::ClientRedirect, 1698 frameLoadRequest.form());
1721 frameLoadRequest.form())) {
1722 return false;
1723 }
1724
1725 m_frame->document()->cancelParsing();
Nate Chapin 2017/02/24 23:42:06 Here and below moved in to startLoad(), since they
1726 detachDocumentLoader(m_provisionalDocumentLoader);
1727
1728 // beforeunload fired above, and detaching a DocumentLoader can fire events,
1729 // which can detach this frame.
1730 if (!m_frame->host())
1731 return false;
1732
1733 return true;
1734 } 1699 }
1735 1700
1736 void FrameLoader::startLoad(FrameLoadRequest& frameLoadRequest, 1701 void FrameLoader::startLoad(FrameLoadRequest& frameLoadRequest,
1737 FrameLoadType type, 1702 FrameLoadType type,
1738 NavigationPolicy navigationPolicy) { 1703 NavigationPolicy navigationPolicy) {
1739 DCHECK(client()->hasWebView()); 1704 DCHECK(client()->hasWebView());
1740 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest(); 1705 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest();
1741 NavigationType navigationType = determineNavigationType( 1706 NavigationType navigationType = determineNavigationType(
1742 type, resourceRequest.httpBody() || frameLoadRequest.form(), 1707 type, resourceRequest.httpBody() || frameLoadRequest.form(),
1743 frameLoadRequest.triggeringEvent()); 1708 frameLoadRequest.triggeringEvent());
1744 resourceRequest.setRequestContext( 1709 resourceRequest.setRequestContext(
1745 determineRequestContextFromNavigationType(navigationType)); 1710 determineRequestContextFromNavigationType(navigationType));
1746 resourceRequest.setFrameType(m_frame->isMainFrame() 1711 resourceRequest.setFrameType(m_frame->isMainFrame()
1747 ? WebURLRequest::FrameTypeTopLevel 1712 ? WebURLRequest::FrameTypeTopLevel
1748 : WebURLRequest::FrameTypeNested); 1713 : WebURLRequest::FrameTypeNested);
1749 1714
1750 if (!checkLoadCanStart(frameLoadRequest, type, navigationPolicy, 1715 bool hadPlaceholderClientDocumentLoader =
Nate Chapin 2017/02/24 23:42:05 I don't like this name. Suggestions welcome if you
1751 navigationType)) { 1716 m_provisionalDocumentLoader && !m_provisionalDocumentLoader->didStart();
1752 if (m_isNavigationHandledByClient) { 1717 navigationPolicy = checkLoadCanStart(frameLoadRequest, type, navigationPolicy,
1753 // PlzNavigate: if the navigation is a commit of a client-handled 1718 navigationType);
1754 // navigation, record that there is no longer a navigation handled by the 1719 if (navigationPolicy == NavigationPolicyIgnore) {
1755 // client. 1720 if (hadPlaceholderClientDocumentLoader &&
1756 if (!frameLoadRequest.resourceRequest().checkForBrowserSideNavigation()) { 1721 !resourceRequest.checkForBrowserSideNavigation()) {
1757 clearNavigationHandledByClient(); 1722 detachDocumentLoader(m_provisionalDocumentLoader);
1758 } else {
1759 DocumentLoader* loader = createDocumentLoader(
1760 resourceRequest, frameLoadRequest, type, navigationType);
1761 // PlzNavigate: If the navigation is handled by the client, then the
1762 // didFinishDocumentLoad() event occurs before the
1763 // didStartProvisionalLoad() notification which occurs after the
1764 // navigation
1765 // is committed. This causes a number of layout tests to fail. We
1766 // workaround this by invoking the didStartProvisionalLoad()
1767 // notification
1768 // here. Consumers of the didStartProvisionalLoad() notification rely on
1769 // the provisional loader and save navigation state in it. We want to
1770 // avoid
1771 // this dependency on the provisional loader. For now we create a
1772 // temporary
1773 // loader and pass it to the didStartProvisionalLoad() function.
1774 // TODO(ananta)
1775 // We should get rid of the dependency on the DocumentLoader in
1776 // consumers
1777 // of
1778 // the didStartProvisionalLoad() notification.
1779 client()->dispatchDidStartProvisionalLoad(loader);
Nate Chapin 2017/02/24 23:42:06 All of this is handled in the main path below, tho
1780 DCHECK(loader);
1781 loader->setSentDidFinishLoad();
1782 loader->detachFromFrame();
1783 }
1784 } 1723 }
1785 return; 1724 return;
1786 } 1725 }
1787 1726
1727 // For PlzNavigate placeholer DocumentLoaders, don't send failure callbacks
1728 // for a placeholder simply being replaced with a new DocumentLoader.
1729 if (hadPlaceholderClientDocumentLoader)
1730 m_provisionalDocumentLoader->setSentDidFinishLoad();
1731 m_frame->document()->cancelParsing();
1732 detachDocumentLoader(m_provisionalDocumentLoader);
1733
1734 // beforeunload fired above, and detaching a DocumentLoader can fire events,
1735 // which can detach this frame.
1736 if (!m_frame->host())
1737 return;
1738
1739 m_progressTracker->progressStarted(type);
1740 // TODO(japhet): This case wants to flag the frame as loading and do nothing
1741 // else. It'd be nice if it could go through the placeholder DocumentLoader
1742 // path, too.
1743 if (navigationPolicy == NavigationPolicyHandledByClientForInitialHistory)
1744 return;
1745 DCHECK(navigationPolicy == NavigationPolicyCurrentTab ||
1746 navigationPolicy == NavigationPolicyHandledByClient);
1747
1788 m_provisionalDocumentLoader = createDocumentLoader( 1748 m_provisionalDocumentLoader = createDocumentLoader(
1789 resourceRequest, frameLoadRequest, type, navigationType); 1749 resourceRequest, frameLoadRequest, type, navigationType);
1790 1750
1791 // PlzNavigate: We need to ensure that script initiated navigations are 1751 // PlzNavigate: We need to ensure that script initiated navigations are
1792 // honored. 1752 // honored.
1793 if (!m_isNavigationHandledByClient) { 1753 if (!hadPlaceholderClientDocumentLoader ||
1754 navigationPolicy == NavigationPolicyHandledByClient) {
1794 m_frame->navigationScheduler().cancel(); 1755 m_frame->navigationScheduler().cancel();
1795 m_checkTimer.stop(); 1756 m_checkTimer.stop();
1796 } 1757 }
1797 1758
1798 if (frameLoadRequest.form()) 1759 if (frameLoadRequest.form())
1799 client()->dispatchWillSubmitForm(frameLoadRequest.form()); 1760 client()->dispatchWillSubmitForm(frameLoadRequest.form());
1800 1761
1801 bool isNavigationHandledByClient = m_isNavigationHandledByClient;
1802 // If the loader wasn't waiting for the client to handle a navigation, update
1803 // the progress tracker. Otherwise don't, as it was already notified before
1804 // sending the navigation to teh client.
1805 if (!m_isNavigationHandledByClient)
Nate Chapin 2017/02/24 23:42:06 Remove the need for this if() by teaching progress
1806 m_progressTracker->progressStarted(type);
1807 else
1808 m_isNavigationHandledByClient = false;
1809
1810 m_provisionalDocumentLoader->appendRedirect( 1762 m_provisionalDocumentLoader->appendRedirect(
1811 m_provisionalDocumentLoader->getRequest().url()); 1763 m_provisionalDocumentLoader->getRequest().url());
1812 // TODO(ananta) 1764 // TODO(ananta):
1813 // We should get rid of the dependency on the DocumentLoader in consumers of 1765 // We should get rid of the dependency on the DocumentLoader in consumers of
1814 // the didStartProvisionalLoad() notification. 1766 // the didStartProvisionalLoad() notification.
1815 client()->dispatchDidStartProvisionalLoad(m_provisionalDocumentLoader); 1767 client()->dispatchDidStartProvisionalLoad(m_provisionalDocumentLoader);
1816 DCHECK(m_provisionalDocumentLoader); 1768 DCHECK(m_provisionalDocumentLoader);
1817 1769
1818 m_provisionalDocumentLoader->startLoadingMainResource(); 1770 if (navigationPolicy == NavigationPolicyCurrentTab) {
1819 1771 m_provisionalDocumentLoader->startLoadingMainResource();
1820 // This should happen after the request is sent, so we don't use 1772 // This should happen after the request is sent, so that the state
1821 // clearNavigationHandledByClient() above. 1773 // the inspector stored in the matching frameScheduledClientNavigation()
1822 if (isNavigationHandledByClient) 1774 // is available while sending the request.
1823 InspectorInstrumentation::frameClearedScheduledClientNavigation(m_frame); 1775 InspectorInstrumentation::frameClearedScheduledClientNavigation(m_frame);
1776 } else {
1777 InspectorInstrumentation::frameScheduledClientNavigation(m_frame);
1778 }
1824 1779
1825 takeObjectSnapshot(); 1780 takeObjectSnapshot();
1826 } 1781 }
1827 1782
1828 void FrameLoader::applyUserAgent(ResourceRequest& request) { 1783 void FrameLoader::applyUserAgent(ResourceRequest& request) {
1829 String userAgent = this->userAgent(); 1784 String userAgent = this->userAgent();
1830 DCHECK(!userAgent.isNull()); 1785 DCHECK(!userAgent.isNull());
1831 request.setHTTPUserAgent(AtomicString(userAgent)); 1786 request.setHTTPUserAgent(AtomicString(userAgent));
1832 } 1787 }
1833 1788
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 : defaultSubstituteDataForURL(request.url()), 1976 : defaultSubstituteDataForURL(request.url()),
2022 frameLoadRequest.clientRedirect()); 1977 frameLoadRequest.clientRedirect());
2023 1978
2024 loader->setLoadType(loadType); 1979 loader->setLoadType(loadType);
2025 loader->setNavigationType(navigationType); 1980 loader->setNavigationType(navigationType);
2026 loader->setReplacesCurrentHistoryItem(loadType == 1981 loader->setReplacesCurrentHistoryItem(loadType ==
2027 FrameLoadTypeReplaceCurrentItem); 1982 FrameLoadTypeReplaceCurrentItem);
2028 return loader; 1983 return loader;
2029 } 1984 }
2030 1985
2031 void FrameLoader::setNavigationHandledByClient() {
2032 m_isNavigationHandledByClient = true;
2033 InspectorInstrumentation::frameScheduledClientNavigation(m_frame);
2034 }
2035
2036 void FrameLoader::clearNavigationHandledByClient() {
2037 m_isNavigationHandledByClient = false;
2038 InspectorInstrumentation::frameClearedScheduledClientNavigation(m_frame);
2039 }
2040
2041 } // namespace blink 1986 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698