API::FrameInfo should know the web page that contains the frame; add API property...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Jun 2017 21:35:23 +0000 (21:35 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Jun 2017 21:35:23 +0000 (21:35 +0000)
commitb9101d13f73253cd0ef71f1d2e573d547e4429ff
treecd6ac8b6bd59cf9d3783f896891e8d5b7caa46fa
parent49dbeaac70ed9c3be55204345627bfe8583fd526
API::FrameInfo should know the web page that contains the frame; add API property webView to WKFrameInfo
https://bugs.webkit.org/show_bug.cgi?id=165160
<rdar://problem/29451999>

Reviewed by Brady Eidson.

Source/WebCore:

Pass the document that is requesting the load to the loader.

* inspector/InspectorFrontendClientLocal.cpp:
(WebCore::InspectorFrontendClientLocal::openInNewTab): Pass the document when instantiating the FrameLoadRequest.
Also use C++11 brace initialization to instantiate ResourceRequest.
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::navigate): Pass the document when instantiating the FrameLoadRequest.
* loader/FrameLoadRequest.cpp:
(WebCore::FrameLoadRequest::FrameLoadRequest): Moved from FrameLoadRequest.h.
(WebCore::FrameLoadRequest::requester): Added.
(WebCore::FrameLoadRequest::requesterSecurityOrigin): Added.
* loader/FrameLoadRequest.h:
(WebCore::FrameLoadRequest::FrameLoadRequest): Marked as WEBCORE_EXPORT and modified to take
the document that requested the load.
(WebCore::FrameLoadRequest::requester): Deleted; made out-of-line/moved to FrameLoadRequest.cpp.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::urlSelected): Pass the document when instantiating the FrameLoadRequest. Also use C++11
brace initialization to instantiate ResourceRequest.
(WebCore::FrameLoader::loadURLIntoChildFrame): Pass the document when instantiating the FrameLoadRequest.
(WebCore::FrameLoader::loadFrameRequest): Substitute FrameLoadRequest::requesterSecurityOrigin() for
FrameLoadRequest::requester() as the former replaces the latter.
(WebCore::FrameLoader::loadURL): Pass the document when instantiating the NavigationAction.
(WebCore::FrameLoader::load): Ditto.
(WebCore::FrameLoader::loadWithDocumentLoader): Pass the document when instantiating the NavigationAction.
Also use C++11 brace initialization syntax to instantiate the NavigationAction.
(WebCore::FrameLoader::reload): Ditto.
(WebCore::FrameLoader::loadPostRequest): Ditto.
(WebCore::FrameLoader::continueLoadAfterNewWindowPolicy): Pass the document when instantiating the NavigationAction.
(WebCore::FrameLoader::loadDifferentDocumentItem): Pass the document when instantiating the NavigationAction.
Also use C++11 brace initialization syntax to instantiate the NavigationAction.
(WebCore::createWindow): Pass the document when instantiating the NavigationAction.
* loader/NavigationAction.cpp:
(WebCore::NavigationAction::NavigationAction): Modified to take the source document.
* loader/NavigationAction.h:
(WebCore::NavigationAction::isEmpty): Consider a NavigationAction empty if does not have a source document
or the associated ResourceRequest has an empty URL.
(WebCore::NavigationAction::sourceDocument): Added.
(WebCore::NavigationAction::NavigationAction): Deleted; made out-of-line/moved to NavigationAction.cpp to
avoid the need to include the header Document.h.
* loader/NavigationScheduler.cpp:
(WebCore::ScheduledURLNavigation::ScheduledURLNavigation): Store the document that scheduled the navigation.
Also use C++11 brace initialization to instantiate in the member initialization list.
(WebCore::ScheduledURLNavigation::initiatingDocument): Added. Retrieves the document that scheduled the navigation.
(WebCore::NavigationScheduler::scheduleLocationChange): Pass the document when instantiating the FrameLoadRequest.
* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkNavigationPolicy): Pass the document when instantiating the NavigationAction.
Also use C++11 brace initialization syntax to instantiate the NavigationAction.
* page/ContextMenuController.cpp:
(WebCore::openNewWindow):
(WebCore::ContextMenuController::contextMenuItemSelected): Pass the document when instantiating the FrameLoadRequest.
Also use C++11 brace initialization syntax to instantiate the FrameLoadRequest.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::createWindow): Pass the document when instantiating the FrameLoadRequest.

Source/WebKit/ios:

Pass the document that is requesting the load to the loader.

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

Source/WebKit/mac:

Pass the document that is requesting the load to the loader.

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

Source/WebKit/win:

Pass the document that is requesting the load to the loader.

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

Source/WebKit2:

Expose a property on WKFrameInfo to retrieve the WKWebView of the web page that contains the
frame. This will allow an embedding client to know the web view that initiated the navigation
request as well as differentiate between a navigation initiated by web content from one
initiated via API.

The majority of this change is passing the document D that initiated the targeted navigation
or called window.open() through the loading machinery to the FrameLoaderClient. The changes
to pass this information to the FrameLoaderClient when creating a new window are straightforward.
For targeted navigation, the WebKit2 FrameLoaderClient implementation now computes the info
for the originating frame regardless of the navigation type (NavigationAction::type()).
(Currently we only compute the originating frame for hyperlink activated navigations,
form submissions, and form resubmissions). The WebProcess computes the page ID of the page
that contains the originating frame and sends that to the UIProcess so that it can create
an API::FrameInfo for the originating frame and associate the page that contains the frame,
if the navigation was triggered by web content. If the navigation was triggered by API
(e.g. -[WKWebView goBack]) then the created API::FrameInfo does not have an associated page
so that an embedding client can distinguish between a navigation initiated by web content
from a navigation that it initiated via API depending on whether API::FrameInfo::page() is
nullptr. We expose property webView on the Mac and iOS API class WKFrameInfo to return the
WKWebView corresponding to API::FrameInfo::page().

A small change that this patch makes is to have the WebProcess compute the originating frame
info (call WebFrame::info()) and send it over to the UIProcess as opposed to sending the frame
ID of the originating frame and having the UIProcess compute the frame info from it. We do this
because the UIProcess may not be able to compute the frame info for the originating frame if
the window that it was contained in was closed between the time the WebProcess sent the frame
ID to the UIProcess and the UIProcess received it.

* UIProcess/API/APIFrameInfo.cpp:
(API::FrameInfo::create):
(API::FrameInfo::FrameInfo):
(API::FrameInfo::clearPage):
* UIProcess/API/APIFrameInfo.h:
* UIProcess/API/APIUIClient.h:
(API::UIClient::createNewPage):
(API::UIClient::createNewPageAsync):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient):
* UIProcess/API/Cocoa/WKFrameInfo.h:
* UIProcess/API/Cocoa/WKFrameInfo.mm:
(-[WKFrameInfo description]):
(-[WKFrameInfo webView]):
* UIProcess/API/Cocoa/WKUserContentController.mm:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::createNewPageCommon):
(WebKit::UIDelegate::UIClient::createNewPage):
(WebKit::UIDelegate::UIClient::createNewPageAsync):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
(WebKit::WebPageProxy::createNewPage):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::loadURL):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::createWindow):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchCreatePage):
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::openInNewTab):

Tools:

Add tests to ensure that -[WKFrameInfo webView] is computed correctly for the source and target frame
for navigations and window creation.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/DecidePolicyForNavigationAction.mm: Added. Derived from file ShouldOpenExternalURLsInNewWindowActions.mm.
(-[DecidePolicyForNavigationActionController webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[DecidePolicyForNavigationActionController webView:didFinishNavigation:]):
(-[DecidePolicyForNavigationActionController webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219013 268f45cc-cd09-0410-ab3c-d52691b4dbfc
38 files changed:
Source/WebCore/ChangeLog
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/NavigationAction.cpp
Source/WebCore/loader/NavigationAction.h
Source/WebCore/loader/NavigationScheduler.cpp
Source/WebCore/loader/PolicyChecker.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/UIProcess/API/APIFrameInfo.cpp
Source/WebKit2/UIProcess/API/APIFrameInfo.h
Source/WebKit2/UIProcess/API/APIUIClient.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/Cocoa/WKFrameInfo.h
Source/WebKit2/UIProcess/API/Cocoa/WKFrameInfo.mm
Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm
Source/WebKit2/UIProcess/Cocoa/UIDelegate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DecidePolicyForNavigationAction.mm [new file with mode: 0644]