Allow navigations in subframes to get a ShouldOpenExternalURLsPolicy of "ShouldAllow".
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jul 2017 00:01:53 +0000 (00:01 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jul 2017 00:01:53 +0000 (00:01 +0000)
commit6004471dc62f38ec92f4ebc73667c4a340c48b6f
treefcbbc2ead3d3c2aa8ea3b1fafe5d63d24265ff29
parentd58826b842e5a51d27a03902a1ca1079b59912a4
Allow navigations in subframes to get a ShouldOpenExternalURLsPolicy of "ShouldAllow".
<rdar://problem/22485589> and https://bugs.webkit.org/show_bug.cgi?id=174178

Reviewed by Alex Christensen.

Source/WebCore:

Test: loader/navigation-policy/should-open-external-urls/subframe-navigated-programatically-by-main-frame.html

This patch introduces a new flag to FrameLoadRequest to track when it is known with certainty that a
FrameLoadRequest originates from the main frame.

Later, when calculating the final ShouldOpenExternalURLsPolicy, main frames navigating iframes get to propagate
their permissions to the iframe.

* bindings/js/CommonVM.cpp:
(WebCore::lexicalFrameFromCommonVM): Helper to grab the current frame associated with the current JS callstack.
* bindings/js/CommonVM.h:

* inspector/InspectorFrontendClientLocal.cpp:
(WebCore::InspectorFrontendClientLocal::openInNewTab):

* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::navigate):

Add the new flag to FrameLoadRequest (and force almost everybody to explicitly include the flag):
* loader/FrameLoadRequest.cpp:
(WebCore::FrameLoadRequest::FrameLoadRequest):
* loader/FrameLoadRequest.h:
(WebCore::FrameLoadRequest::FrameLoadRequest):
(WebCore::FrameLoadRequest::navigationInitiatedByMainFrame):

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::urlSelected):
(WebCore::FrameLoader::loadURLIntoChildFrame):
(WebCore::shouldOpenExternalURLsPolicyToApply): Helper that takes the new flag into account when deciding
  what the final ShouldOpenExternalURLsPolicy will be.
(WebCore::applyShouldOpenExternalURLsPolicyToNewDocumentLoader):
(WebCore::FrameLoader::loadURL):
(WebCore::FrameLoader::load):
(WebCore::FrameLoader::loadWithNavigationAction):
(WebCore::FrameLoader::reloadWithOverrideEncoding):
(WebCore::FrameLoader::reload):
(WebCore::FrameLoader::loadPostRequest):
(WebCore::FrameLoader::continueLoadAfterNewWindowPolicy):
(WebCore::FrameLoader::loadDifferentDocumentItem):
(WebCore::createWindow):
(WebCore::FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader): Deleted.
* loader/FrameLoader.h:

* loader/FrameLoaderTypes.h:

* loader/NavigationAction.h:
(WebCore::NavigationAction::navigationInitiatedByMainFrame):
* loader/NavigationScheduler.cpp:
(WebCore::ScheduledNavigation::ScheduledNavigation): Grab the "initiating frame" at the time the
  ScheduledNavigation is created, as it dictates the policy we decide later.
(WebCore::ScheduledNavigation::navigationInitiatedByMainFrame):
(WebCore::NavigationScheduler::scheduleLocationChange):

* page/ContextMenuController.cpp:
(WebCore::openNewWindow):
(WebCore::ContextMenuController::contextMenuItemSelected):

* page/DOMWindow.cpp:
(WebCore::DOMWindow::createWindow):

Source/WebKit/ios:

Adopt to the new constructor for FrameLoadRequest.

* WebView/WebPDFViewPlaceholder.mm:
(-[WebPDFViewPlaceholder simulateClickOnLinkToURL:]):

Source/WebKit/mac:

Adopt to the new constructor for FrameLoadRequest.

* WebView/WebPDFView.mm:
(-[WebPDFView PDFViewWillClickOnLink:withURL:]):

Source/WebKit/win:

Adopt to the new constructor for FrameLoadRequest.

* Plugins/PluginView.cpp:
(WebCore::PluginView::start):
(WebCore::PluginView::getURLNotify):
(WebCore::PluginView::getURL):
(WebCore::PluginView::handlePost):

Source/WebKit2:

Adopt to the new constructor for FrameLoadRequest.

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::loadURL):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchCreatePage):
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::openInNewTab):

LayoutTests:

Added a new explicit test and updated expectations for an old one.

* loader/navigation-policy/should-open-external-urls/resources/main-frame-with-subframe-main-programatically-navigates-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/subframe-click-target-self-expected.txt:
* loader/navigation-policy/should-open-external-urls/subframe-navigated-programatically-by-main-frame-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/subframe-navigated-programatically-by-main-frame.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219170 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
LayoutTests/ChangeLog
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/main-frame-with-subframe-main-programatically-navigates-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-click-target-self-expected.txt
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-navigated-programatically-by-main-frame-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-navigated-programatically-by-main-frame.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/CommonVM.cpp
Source/WebCore/bindings/js/CommonVM.h
Source/WebCore/inspector/InspectorFrontendClientLocal.cpp
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/loader/FrameLoadRequest.cpp
Source/WebCore/loader/FrameLoadRequest.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h
Source/WebCore/loader/FrameLoaderTypes.h
Source/WebCore/loader/NavigationAction.h
Source/WebCore/loader/NavigationScheduler.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebKit/ios/ChangeLog
Source/WebKit/ios/WebView/WebPDFViewPlaceholder.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebPDFView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/Plugins/PluginView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.cpp