WebKit policy delegate should suggest if a navigation should be allowed to open URLs...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jun 2015 18:43:13 +0000 (18:43 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jun 2015 18:43:13 +0000 (18:43 +0000)
commita7d051dcfaf4794c69540e0b2823a2e5fb7c84e7
tree954cf3ab5d5ce1c9edea5c745ffc2196868dbd5d
parent7b325af6c1deb78c4a6c49448e18e969d354c6f8
WebKit policy delegate should suggest if a navigation should be allowed to open URLs externally.
rdar://problem/21025301 and https://bugs.webkit.org/show_bug.cgi?id=145280
Source/WebCore:

Reviewed by Alex Christensen.

Tests: loader/navigation-policy/should-open-external-urls/main-frame-click.html
       loader/navigation-policy/should-open-external-urls/main-frame-navigated-programatically-by-subframe.html
       loader/navigation-policy/should-open-external-urls/main-frame-with-flag-progamatic.html
       loader/navigation-policy/should-open-external-urls/main-frame-without-flag-programatic.html
       loader/navigation-policy/should-open-external-urls/subframe-click-target-self.html
       loader/navigation-policy/should-open-external-urls/subframe-click-target-top.html
       loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-from-subframe.html
       loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag.html
       loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-from-subframe.html
       loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag.html
       loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-from-subframe.html
       loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag.html
       loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-from-subframe.html
       loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag.html
       loader/navigation-policy/should-open-external-urls/window-open-with-flag-from-subframe.html
       loader/navigation-policy/should-open-external-urls/window-open-with-flag.html
       loader/navigation-policy/should-open-external-urls/window-open-without-flag-from-subframe.html
       loader/navigation-policy/should-open-external-urls/window-open-without-flag.html

The "should open external URLs" flag is only for main frames.
It doesn't enforce any sort of policy internal to WebKit, but rather is for notifications to the policy delegate.

It is set from one of two places:
1 - A main frame is navigated by any frame as the result of a user gesture.
2 - WebKit2 API explicitly states the flag is true.

The flag value propagates when:
1 - When a main frame document is navigated to a new main frame document.
2 - When a new window is opened from a page whose main frame had the flag set.
3 - When a new window is opened as the result of a user gesture.

The flag resets to false when:
1 - A subframe navigates a main frame without a user gesture.

This patch is large, but does little more than the following:
1 - Adds a ShouldOpenExternalURLs flag to both FrameLoadRequest and NavigationAction.
2 - Makes sure anybody who creates either of those objects sets a sensible for that flag.
3 - When FrameLoader creates a new DocumentLoader, it sets its flag based on whether or not the load is in a main frame,
    whether or not the load is from a user gesture, and based on the initiator's value of the flag.

* dom/Document.cpp:
(WebCore::Document::processHttpEquiv):
(WebCore::Document::shouldOpenExternalURLsPolicyToPropagate):
* dom/Document.h:

* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::handleClick):

* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::handleClick):

* html/parser/XSSAuditorDelegate.cpp:
(WebCore::XSSAuditorDelegate::didBlockScript):

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

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

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::setTriggeringAction):
(WebCore::DocumentLoader::shouldOpenExternalURLsPolicyToPropagate):
* loader/DocumentLoader.h:
(WebCore::DocumentLoader::shouldOpenExternalURLsPolicy): Deleted.

* loader/FrameLoadRequest.cpp:
(WebCore::FrameLoadRequest::FrameLoadRequest):
* loader/FrameLoadRequest.h:
(WebCore::FrameLoadRequest::FrameLoadRequest):

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::urlSelected):
(WebCore::FrameLoader::receivedFirstData):
(WebCore::FrameLoader::loadURLIntoChildFrame):
(WebCore::FrameLoader::loadURL):
(WebCore::FrameLoader::load):
(WebCore::FrameLoader::loadWithNavigationAction):
(WebCore::FrameLoader::reloadWithOverrideEncoding):
(WebCore::FrameLoader::reload):
(WebCore::FrameLoader::loadPostRequest):
(WebCore::FrameLoader::continueLoadAfterNewWindowPolicy):
(WebCore::FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader):
* loader/FrameLoader.h:

* loader/NavigationAction.cpp:
(WebCore::NavigationAction::NavigationAction):
(WebCore::NavigationAction::copyWithShouldOpenExternalURLsPolicy):
* loader/NavigationAction.h:
(WebCore::NavigationAction::setShouldOpenExternalURLsPolicy): Deleted.

* loader/NavigationScheduler.cpp:
(WebCore::ScheduledURLNavigation::ScheduledURLNavigation):
(WebCore::ScheduledRedirect::ScheduledRedirect):
(WebCore::ScheduledLocationChange::ScheduledLocationChange):
(WebCore::ScheduledRefresh::ScheduledRefresh):
(WebCore::ScheduledFormSubmission::ScheduledFormSubmission):
(WebCore::NavigationScheduler::scheduleRedirect):
(WebCore::NavigationScheduler::scheduleLocationChange):
(WebCore::NavigationScheduler::scheduleRefresh):
* loader/NavigationScheduler.h:

* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkNavigationPolicy):

* loader/SubframeLoader.cpp:
(WebCore::SubframeLoader::loadOrRedirectSubframe):

* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::selectCache):

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

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

* page/DragController.cpp:
(WebCore::DragController::performDragOperation):

* page/Location.cpp:
(WebCore::Location::reload):

* replay/ReplayInputDispatchMethods.cpp:
(WebCore::InitialNavigation::dispatch):

* svg/SVGAElement.cpp:
(WebCore::SVGAElement::defaultEventHandler):

Source/WebKit/ios:

Reviewed by Alex Christensen.

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

Source/WebKit/mac:

Reviewed by Alex Christensen.

* Plugins/WebPluginController.mm:
(-[WebPluginController webPlugInContainerLoadRequest:inFrame:]):

* WebView/WebFrame.mm:
(-[WebFrame loadRequest:]):
(-[WebFrame _loadData:MIMEType:textEncodingName:baseURL:unreachableURL:]):

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

Source/WebKit/win:

Reviewed by Alex Christensen.

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

* WebCoreSupport/WebContextMenuClient.cpp:
(WebContextMenuClient::searchWithGoogle):

* WebFrame.cpp:
(WebFrame::loadRequest):
(WebFrame::loadData):

Source/WebKit2:

Reviewed by Alex Christensen.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::clickedLink):

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::performFrameLoadURLRequest):
(WebKit::PluginView::loadURL):

* WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
(WebKit::WebContextMenuClient::searchWithGoogle):

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchCreatePage):

* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::openInNewTab):

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadURLInFrame):
(WebKit::WebPage::loadRequest):
(WebKit::WebPage::loadDataImpl):
(WebKit::WebPage::navigateToPDFLinkWithSimulatedClick):

LayoutTests:

Reviewed by Alex Christensen.

* loader/navigation-policy/should-open-external-urls/main-frame-click-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-click.html: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-navigated-programatically-by-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-navigated-programatically-by-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-with-flag-progamatic-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-with-flag-progamatic.html: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-without-flag-programatic-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/main-frame-without-flag-programatic.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/click-notify-done-in-main.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/iframe-click-notify-done-target-self.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/iframe-click-notify-done-target-top.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/main-frame-with-subframe-click-targets-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/main-frame-with-subframe-programatically-navigates-main.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/programatically-navigate-to-notify-done-target-top.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/programatically-navigate-to-notify-done.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/user-gesture-target-blank-to-notify-done-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/user-gesture-target-blank-to-notify-done.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/user-gesture-window-open-to-notify-done-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/user-gesture-window-open-to-notify-done.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/window-open-to-notify-done-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/resources/window-open-to-notify-done.html: Added.
* loader/navigation-policy/should-open-external-urls/subframe-click-target-self-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/subframe-click-target-self.html: Added.
* loader/navigation-policy/should-open-external-urls/subframe-click-target-top-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/subframe-click-target-top.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-from-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-from-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-from-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-from-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag.html: Added.
* loader/navigation-policy/should-open-external-urls/window-open-with-flag-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/window-open-with-flag-from-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/window-open-with-flag-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/window-open-with-flag.html: Added.
* loader/navigation-policy/should-open-external-urls/window-open-without-flag-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/window-open-without-flag-from-subframe-expected.txt: Added.
* loader/navigation-policy/should-open-external-urls/window-open-without-flag-from-subframe.html: Added.
* loader/navigation-policy/should-open-external-urls/window-open-without-flag.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185111 268f45cc-cd09-0410-ab3c-d52691b4dbfc
94 files changed:
LayoutTests/ChangeLog
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-click-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-click.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-navigated-programatically-by-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-navigated-programatically-by-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-with-flag-progamatic-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-with-flag-progamatic.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-without-flag-programatic-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/main-frame-without-flag-programatic.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/click-notify-done-in-main.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/iframe-click-notify-done-target-self.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/iframe-click-notify-done-target-top.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/main-frame-with-subframe-click-targets-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/main-frame-with-subframe-programatically-navigates-main.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/programatically-navigate-to-notify-done-target-top.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/programatically-navigate-to-notify-done.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/user-gesture-target-blank-to-notify-done-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/user-gesture-target-blank-to-notify-done.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/user-gesture-window-open-to-notify-done-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/user-gesture-window-open-to-notify-done.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/window-open-to-notify-done-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/resources/window-open-to-notify-done.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-click-target-self-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-click-target-self.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-click-target-top-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/subframe-click-target-top.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-from-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-with-flag.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-from-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-target-blank-without-flag.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-from-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-with-flag.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-from-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/user-gesture-window-open-without-flag.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-with-flag-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-with-flag-from-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-with-flag-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-with-flag.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-without-flag-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-without-flag-from-subframe-expected.txt [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-without-flag-from-subframe.html [new file with mode: 0644]
LayoutTests/loader/navigation-policy/should-open-external-urls/window-open-without-flag.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/parser/XSSAuditorDelegate.cpp
Source/WebCore/inspector/InspectorFrontendClientLocal.cpp
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/FrameLoadRequest.cpp
Source/WebCore/loader/FrameLoadRequest.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h
Source/WebCore/loader/NavigationAction.cpp
Source/WebCore/loader/NavigationAction.h
Source/WebCore/loader/NavigationScheduler.cpp
Source/WebCore/loader/NavigationScheduler.h
Source/WebCore/loader/PolicyChecker.cpp
Source/WebCore/loader/SubframeLoader.cpp
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/Location.cpp
Source/WebCore/replay/ReplayInputDispatchMethods.cpp
Source/WebCore/svg/SVGAElement.cpp
Source/WebKit/ios/ChangeLog
Source/WebKit/ios/WebView/WebPDFViewPlaceholder.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Plugins/WebPluginController.mm
Source/WebKit/mac/WebView/WebFrame.mm
Source/WebKit/mac/WebView/WebPDFView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/Plugins/PluginView.cpp
Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp
Source/WebKit/win/WebFrame.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp