Add a "should open urls externally" flag to DocumentLoader.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 May 2015 04:52:25 +0000 (04:52 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 May 2015 04:52:25 +0000 (04:52 +0000)
rdar://problem/21025301 and https://bugs.webkit.org/show_bug.cgi?id=145417

Reviewed by Geoff Garen.

Source/WebCore:

No new tests (No change in behavior, testable at API level with a followup patch)

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::setTriggeringAction): Apply the current flag value to the
  new NavigationAction so it can be used later.
* loader/DocumentLoader.h:
(WebCore::DocumentLoader::setShouldOpenExternalURLsPolicy):
(WebCore::DocumentLoader::shouldOpenExternalURLsPolicy):
(WebCore::DocumentLoader::setTriggeringAction): Deleted.

FrameLoadRequest should hold the new flag to pass into FrameLoader machinery:
* loader/FrameLoadRequest.h:
(WebCore::FrameLoadRequest::setShouldOpenExternalURLsPolicy):
(WebCore::FrameLoadRequest::shouldOpenExternalURLsPolicy):

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::load): Set the flag on the newly created DocumentLoader but
  only if it is for the main frame.

* loader/FrameLoaderTypes.h: Add a new enum for the flag.

Navigation action should hold the new flag to pass to the policy delegate:
* loader/NavigationAction.cpp:
(WebCore::NavigationAction::NavigationAction):
* loader/NavigationAction.h:
(WebCore::NavigationAction::shouldOpenExternalURLsPolicy):
(WebCore::NavigationAction::setShouldOpenExternalURLsPolicy):

* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkNavigationPolicy): Include the flag from the DocumentLoader
  in the NavigationAction.

Source/WebKit2:

Rename "user initiated" to "should open external URLs":
* Shared/API/Cocoa/_WKNSURLRequestExtras.h:
* Shared/API/Cocoa/_WKNSURLRequestExtras.mm:
(-[NSURLRequest _web_shouldOpenExternalURLs]):
(-[NSMutableURLRequest _web_setShouldOpenExternalURLs:]):
(-[NSURLRequest _web_isUserInitiated]): Deleted.
(-[NSMutableURLRequest _web_setIsUserInitiated:]): Deleted.

Hold the new flag as a bool, and encode/decode it across IPC:
* Shared/NavigationActionData.cpp:
(WebKit::NavigationActionData::encode):
(WebKit::NavigationActionData::decode):
(WebKit::NavigationActionData::NavigationActionData): Deleted.
* Shared/NavigationActionData.h:

* UIProcess/API/APINavigationAction.h: Add accessor for the bool flag.

* UIProcess/API/C/WKPage.cpp:
(WKPageLoadURLWithUserData): Use "ShouldNotAllow" in the legacy C API for now.
(WKPageLoadURLRequestWithUserData): Ditto.

* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(-[WKBrowsingContextController loadRequest:userData:]): Set the value of the flag
  based on whether or not the initiating NSURLRequest was user initiated.

* UIProcess/API/Cocoa/WKNavigationAction.mm:
(-[WKNavigationAction _shouldOpenExternalURLs]): Add accessor for the bool flag.
* UIProcess/API/Cocoa/WKNavigationActionPrivate.h:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadRequest:]): Set the value of the flag based on whether or not the
  initiating NSURLRequest was user initiated.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::loadRequest): Pass the value down to the WebProcess to load.
(WebKit::WebPageProxy::loadFile): Ditto, but always with "ShouldNotAllow".
* UIProcess/WebPageProxy.h:

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Translate
  the NavigationAction flag to a bool in the NavigationActionData object.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadRequest): Set the value of the flag in the FrameLoadRequest that
  will be loaded.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184941 268f45cc-cd09-0410-ab3c-d52691b4dbfc

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/FrameLoadRequest.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoaderTypes.h
Source/WebCore/loader/NavigationAction.cpp
Source/WebCore/loader/NavigationAction.h
Source/WebCore/loader/PolicyChecker.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/Cocoa/_WKNSURLRequestExtras.h
Source/WebKit2/Shared/API/Cocoa/_WKNSURLRequestExtras.mm
Source/WebKit2/Shared/NavigationActionData.cpp
Source/WebKit2/Shared/NavigationActionData.h
Source/WebKit2/UIProcess/API/APINavigationAction.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/API/Cocoa/WKNavigationAction.mm
Source/WebKit2/UIProcess/API/Cocoa/WKNavigationActionPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 76a970c..310accb 100644 (file)
@@ -1,3 +1,42 @@
+2015-05-27  Brady Eidson  <beidson@apple.com>
+
+        Add a "should open urls externally" flag to DocumentLoader.
+        rdar://problem/21025301 and https://bugs.webkit.org/show_bug.cgi?id=145417
+
+        Reviewed by Geoff Garen.
+
+        No new tests (No change in behavior, testable at API level with a followup patch)
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::setTriggeringAction): Apply the current flag value to the 
+          new NavigationAction so it can be used later.
+        * loader/DocumentLoader.h:
+        (WebCore::DocumentLoader::setShouldOpenExternalURLsPolicy):
+        (WebCore::DocumentLoader::shouldOpenExternalURLsPolicy):
+        (WebCore::DocumentLoader::setTriggeringAction): Deleted.
+
+        FrameLoadRequest should hold the new flag to pass into FrameLoader machinery:
+        * loader/FrameLoadRequest.h:
+        (WebCore::FrameLoadRequest::setShouldOpenExternalURLsPolicy):
+        (WebCore::FrameLoadRequest::shouldOpenExternalURLsPolicy):
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::load): Set the flag on the newly created DocumentLoader but
+          only if it is for the main frame.
+
+        * loader/FrameLoaderTypes.h: Add a new enum for the flag.
+
+        Navigation action should hold the new flag to pass to the policy delegate:
+        * loader/NavigationAction.cpp:
+        (WebCore::NavigationAction::NavigationAction):
+        * loader/NavigationAction.h:
+        (WebCore::NavigationAction::shouldOpenExternalURLsPolicy):
+        (WebCore::NavigationAction::setShouldOpenExternalURLsPolicy):
+
+        * loader/PolicyChecker.cpp:
+        (WebCore::PolicyChecker::checkNavigationPolicy): Include the flag from the DocumentLoader
+          in the NavigationAction.
+
 2015-05-27  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
 
         Purge PassRefPtr in WebCore/Modules - 2
index ad52864..9a0f3af 100644 (file)
@@ -1553,6 +1553,13 @@ void DocumentLoader::handledOnloadEvents()
     applicationCacheHost()->stopDeferringEvents();
 }
 
+void DocumentLoader::setTriggeringAction(const NavigationAction& action)
+{
+    m_triggeringAction = action;
+    if (!m_triggeringAction.isEmpty())
+        m_triggeringAction.setShouldOpenExternalURLsPolicy(m_shouldOpenExternalURLsPolicy);
+}
+
 #if ENABLE(CONTENT_EXTENSIONS)
 void DocumentLoader::addPendingContentExtensionSheet(const String& identifier, StyleSheetContents& sheet)
 {
index 6328764..19802b4 100644 (file)
@@ -178,7 +178,7 @@ namespace WebCore {
         const ResponseVector& responses() const { return m_responses; }
 
         const NavigationAction& triggeringAction() const { return m_triggeringAction; }
-        void setTriggeringAction(const NavigationAction& action) { m_triggeringAction = action; }
+        void setTriggeringAction(const NavigationAction&);
         void setOverrideEncoding(const String& encoding) { m_overrideEncoding = encoding; }
         void setLastCheckedRequest(const ResourceRequest& request) { m_lastCheckedRequest = request; }
         const ResourceRequest& lastCheckedRequest()  { return m_lastCheckedRequest; }
@@ -274,6 +274,9 @@ namespace WebCore {
         void addPendingContentExtensionDisplayNoneSelector(const String& identifier, const String& selector, uint32_t selectorID);
 #endif
 
+        void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy) { m_shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicy; }
+        ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy() const { return m_shouldOpenExternalURLsPolicy; }
+
     protected:
         WEBCORE_EXPORT DocumentLoader(const ResourceRequest&, const SubstituteData&);
 
@@ -426,6 +429,7 @@ namespace WebCore {
         RefPtr<IconDataCallback> m_iconDataCallback;
 
         bool m_subresourceLoadersArePageCacheAcceptable;
+        ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow };
 
         friend class ApplicationCacheHost;  // for substitute resource delivery
         std::unique_ptr<ApplicationCacheHost> m_applicationCacheHost;
index 64588d1..2c8159e 100644 (file)
@@ -104,6 +104,9 @@ public:
     // corresponding parameter from ScriptController::executeIfJavaScriptURL() is addressed.
     ShouldReplaceDocumentIfJavaScriptURL shouldReplaceDocumentIfJavaScriptURL() const { return m_shouldReplaceDocumentIfJavaScriptURL; }
 
+    void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy policy) { m_shouldOpenExternalURLsPolicy = policy; }
+    ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy() const { return m_shouldOpenExternalURLsPolicy; }
+
 private:
     RefPtr<SecurityOrigin> m_requester;
     ResourceRequest m_resourceRequest;
@@ -117,6 +120,7 @@ private:
     AllowNavigationToInvalidURL m_allowNavigationToInvalidURL;
     NewFrameOpenerPolicy m_newFrameOpenerPolicy;
     ShouldReplaceDocumentIfJavaScriptURL m_shouldReplaceDocumentIfJavaScriptURL;
+    ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow };
 };
 
 }
index 85b1f87..f3b698a 100644 (file)
@@ -1308,6 +1308,9 @@ void FrameLoader::load(const FrameLoadRequest& passedRequest)
         request.setSubstituteData(defaultSubstituteDataForURL(request.resourceRequest().url()));
 
     RefPtr<DocumentLoader> loader = m_client.createDocumentLoader(request.resourceRequest(), request.substituteData());
+    if (m_frame.isMainFrame())
+        loader->setShouldOpenExternalURLsPolicy(request.shouldOpenExternalURLsPolicy());
+
     load(loader.get());
 }
 
index 4ef8ab6..12cbefb 100644 (file)
@@ -71,6 +71,11 @@ enum class NavigationType {
     Other
 };
 
+enum class ShouldOpenExternalURLsPolicy {
+    ShouldNotAllow,
+    ShouldAllow,
+};
+
     enum ClearProvisionalItemPolicy {
         ShouldClearProvisionalItem,
         ShouldNotClearProvisionalItem
index 837ebdd..c77fbd0 100644 (file)
@@ -84,6 +84,13 @@ NavigationAction::NavigationAction(const ResourceRequest& resourceRequest, Navig
 {
 }
 
+NavigationAction::NavigationAction(const ResourceRequest& resourceRequest, NavigationType type, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy)
+    : m_resourceRequest(resourceRequest)
+    , m_type(type)
+    , m_shouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicy)
+{
+}
+
 NavigationAction::NavigationAction(const ResourceRequest& resourceRequest, FrameLoadType frameLoadType,
         bool isFormSubmission, PassRefPtr<Event> event)
     : m_resourceRequest(resourceRequest)
index 1b48d0c..cfcccc3 100644 (file)
 
 namespace WebCore {
 
-    class NavigationAction {
-    public:
-        WEBCORE_EXPORT NavigationAction();
-        WEBCORE_EXPORT explicit NavigationAction(const ResourceRequest&);
-        WEBCORE_EXPORT NavigationAction(const ResourceRequest&, NavigationType);
-        WEBCORE_EXPORT NavigationAction(const ResourceRequest&, FrameLoadType, bool isFormSubmission);
-        NavigationAction(const ResourceRequest&, NavigationType, PassRefPtr<Event>);
-        NavigationAction(const ResourceRequest&, FrameLoadType, bool isFormSubmission, PassRefPtr<Event>);
+class NavigationAction {
+public:
+    WEBCORE_EXPORT NavigationAction();
+    WEBCORE_EXPORT explicit NavigationAction(const ResourceRequest&);
+    WEBCORE_EXPORT NavigationAction(const ResourceRequest&, NavigationType);
+    WEBCORE_EXPORT NavigationAction(const ResourceRequest&, FrameLoadType, bool isFormSubmission);
+    NavigationAction(const ResourceRequest&, NavigationType, PassRefPtr<Event>);
+    NavigationAction(const ResourceRequest&, NavigationType, ShouldOpenExternalURLsPolicy);
+    NavigationAction(const ResourceRequest&, FrameLoadType, bool isFormSubmission, PassRefPtr<Event>);
 
-        bool isEmpty() const { return m_resourceRequest.url().isEmpty(); }
+    bool isEmpty() const { return m_resourceRequest.url().isEmpty(); }
 
-        URL url() const { return m_resourceRequest.url(); }
-        const ResourceRequest& resourceRequest() const { return m_resourceRequest; }
+    URL url() const { return m_resourceRequest.url(); }
+    const ResourceRequest& resourceRequest() const { return m_resourceRequest; }
 
-        NavigationType type() const { return m_type; }
-        const Event* event() const { return m_event.get(); }
+    NavigationType type() const { return m_type; }
+    const Event* event() const { return m_event.get(); }
 
-        bool processingUserGesture() const { return m_processingUserGesture; }
+    bool processingUserGesture() const { return m_processingUserGesture; }
 
-    private:
-        ResourceRequest m_resourceRequest;
-        NavigationType m_type;
-        RefPtr<Event> m_event;
-        bool m_processingUserGesture;
-    };
+    ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy() const { return m_shouldOpenExternalURLsPolicy; }
+    void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy policy) { m_shouldOpenExternalURLsPolicy = policy; }
+
+private:
+    ResourceRequest m_resourceRequest;
+    NavigationType m_type;
+    RefPtr<Event> m_event;
+    bool m_processingUserGesture;
+    ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow };
+};
 
 }
 
index 9178b90..1bb99a6 100644 (file)
@@ -65,7 +65,7 @@ void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, Docume
 {
     NavigationAction action = loader->triggeringAction();
     if (action.isEmpty()) {
-        action = NavigationAction(request, NavigationType::Other);
+        action = NavigationAction(request, NavigationType::Other, loader->shouldOpenExternalURLsPolicy());
         loader->setTriggeringAction(action);
     }
 
index 5501138..d71a207 100644 (file)
@@ -1,3 +1,58 @@
+2015-05-27  Brady Eidson  <beidson@apple.com>
+
+        Add a "should open urls externally" flag to DocumentLoader.
+        rdar://problem/21025301 and https://bugs.webkit.org/show_bug.cgi?id=145417
+
+        Reviewed by Geoff Garen.
+
+        Rename "user initiated" to "should open external URLs":
+        * Shared/API/Cocoa/_WKNSURLRequestExtras.h:
+        * Shared/API/Cocoa/_WKNSURLRequestExtras.mm:
+        (-[NSURLRequest _web_shouldOpenExternalURLs]):
+        (-[NSMutableURLRequest _web_setShouldOpenExternalURLs:]):
+        (-[NSURLRequest _web_isUserInitiated]): Deleted.
+        (-[NSMutableURLRequest _web_setIsUserInitiated:]): Deleted.
+        
+        Hold the new flag as a bool, and encode/decode it across IPC:
+        * Shared/NavigationActionData.cpp:
+        (WebKit::NavigationActionData::encode):
+        (WebKit::NavigationActionData::decode):
+        (WebKit::NavigationActionData::NavigationActionData): Deleted.
+        * Shared/NavigationActionData.h:
+
+        * UIProcess/API/APINavigationAction.h: Add accessor for the bool flag.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageLoadURLWithUserData): Use "ShouldNotAllow" in the legacy C API for now.
+        (WKPageLoadURLRequestWithUserData): Ditto.
+
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController loadRequest:userData:]): Set the value of the flag
+          based on whether or not the initiating NSURLRequest was user initiated.
+
+        * UIProcess/API/Cocoa/WKNavigationAction.mm:
+        (-[WKNavigationAction _shouldOpenExternalURLs]): Add accessor for the bool flag.
+        * UIProcess/API/Cocoa/WKNavigationActionPrivate.h:
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView loadRequest:]): Set the value of the flag based on whether or not the
+          initiating NSURLRequest was user initiated.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::loadRequest): Pass the value down to the WebProcess to load.
+        (WebKit::WebPageProxy::loadFile): Ditto, but always with "ShouldNotAllow".
+        * UIProcess/WebPageProxy.h:
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Translate 
+          the NavigationAction flag to a bool in the NavigationActionData object.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::loadRequest): Set the value of the flag in the FrameLoadRequest that
+          will be loaded.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2015-05-27  Anders Carlsson  <andersca@apple.com>
 
         Can't load local files in WKWebView from containerized app
index ead9559..3fb071e 100644 (file)
 
 @interface NSURLRequest (WKExtras)
 
-- (BOOL)_web_isUserInitiated;
+- (BOOL)_web_shouldOpenExternalURLs;
 
 @end
 
 @interface NSMutableURLRequest (WKExtras)
 
-- (void)_web_setIsUserInitiated:(BOOL)userInitiated;
+- (void)_web_setShouldOpenExternalURLs:(BOOL)shouldOpenExternalURLs;
 
 @end
index 5f140c0..bd98c67 100644 (file)
 #import "config.h"
 #import "_WKNSURLRequestExtras.h"
 
-#import <WebCore/ResourceRequest.h>
-
 @implementation NSURLRequest (WKExtras)
 
-- (BOOL)_web_isUserInitiated
+- (BOOL)_web_shouldOpenExternalURLs
 {
-    NSNumber *userInitiated = [NSURLProtocol propertyForKey:(NSString *)WebCore::ResourceRequest::isUserInitiatedKey() inRequest:self];
-    return userInitiated.boolValue;
+    NSNumber *shouldOpenExternalURLs = [NSURLProtocol propertyForKey:@"WKNSURLRequestShouldOpenExternalURLsKey" inRequest:self];
+    return shouldOpenExternalURLs.boolValue;
 }
 
 @end
 
 @implementation NSMutableURLRequest (WKExtras)
 
-- (void)_web_setIsUserInitiated:(BOOL)userInitiated
+- (void)_web_setShouldOpenExternalURLs:(BOOL)shouldOpenExternalURLs
 {
-    [NSURLProtocol setProperty:userInitiated ? @YES : @NO forKey:(NSString *)WebCore::ResourceRequest::isUserInitiatedKey() inRequest:self];
+    [NSURLProtocol setProperty:shouldOpenExternalURLs ? @YES : @NO forKey:@"WKNSURLRequestShouldOpenExternalURLsKey" inRequest:self];
 }
 
 @end
index 7327a4e..8598558 100644 (file)
@@ -33,15 +33,6 @@ using namespace WebCore;
 
 namespace WebKit {
 
-NavigationActionData::NavigationActionData()
-    : navigationType(NavigationType::Other)
-    , modifiers()
-    , mouseButton(WebMouseEvent::NoButton)
-    , isProcessingUserGesture(false)
-    , canHandleRequest(false)
-{
-}
-
 void NavigationActionData::encode(IPC::ArgumentEncoder& encoder) const
 {
     encoder.encodeEnum(navigationType);
@@ -49,6 +40,7 @@ void NavigationActionData::encode(IPC::ArgumentEncoder& encoder) const
     encoder.encodeEnum(mouseButton);
     encoder << isProcessingUserGesture;
     encoder << canHandleRequest;
+    encoder << shouldOpenExternalURLs;
 }
 
 bool NavigationActionData::decode(IPC::ArgumentDecoder& decoder, NavigationActionData& result)
@@ -63,6 +55,8 @@ bool NavigationActionData::decode(IPC::ArgumentDecoder& decoder, NavigationActio
         return false;
     if (!decoder.decode(result.canHandleRequest))
         return false;
+    if (!decoder.decode(result.shouldOpenExternalURLs))
+        return false;
 
     return true;
 }
index a8e04e7..6040b1a 100644 (file)
@@ -37,16 +37,15 @@ class ArgumentEncoder;
 namespace WebKit {
 
 struct NavigationActionData {
-    NavigationActionData();
-
     void encode(IPC::ArgumentEncoder&) const;
     static bool decode(IPC::ArgumentDecoder&, NavigationActionData&);
 
-    WebCore::NavigationType navigationType;
-    WebEvent::Modifiers modifiers;
-    WebMouseEvent::Button mouseButton;
-    bool isProcessingUserGesture;
-    bool canHandleRequest;
+    WebCore::NavigationType navigationType { WebCore::NavigationType::Other };
+    WebEvent::Modifiers modifiers { };
+    WebMouseEvent::Button mouseButton { WebMouseEvent::NoButton };
+    bool isProcessingUserGesture { false };
+    bool canHandleRequest { false };
+    bool shouldOpenExternalURLs { false };
 };
 
 }
index 672e90b..f14da10 100644 (file)
@@ -63,6 +63,7 @@ public:
     WebKit::WebMouseEvent::Button mouseButton() const { return m_navigationActionData.mouseButton; }
     bool isProcessingUserGesture() const { return m_navigationActionData.isProcessingUserGesture; }
     bool canHandleRequest() const { return m_navigationActionData.canHandleRequest; }
+    bool shouldOpenExternalURLs() const { return m_navigationActionData.shouldOpenExternalURLs; }
 
 private:
     RefPtr<FrameInfo> m_sourceFrame;
index a7ae2d5..e3dd3fd 100644 (file)
@@ -128,7 +128,7 @@ void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
 
 void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
 {
-    toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), toImpl(userDataRef));
+    toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
 }
 
 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
@@ -138,7 +138,7 @@ void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
 
 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
 {
-    toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), toImpl(userDataRef));
+    toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
 }
 
 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
index 1f42c80..12f7400 100644 (file)
@@ -55,6 +55,7 @@
 #import "WebPageProxy.h"
 #import "WebProcessPool.h"
 #import "WebProtectionSpace.h"
+#import "_WKNSURLRequestExtras.h"
 #import "_WKRemoteObjectRegistryInternal.h"
 #import <wtf/NeverDestroyed.h>
 
@@ -191,7 +192,7 @@ static HashMap<WebPageProxy*, WKBrowsingContextController *>& browsingContextCon
     if (userData)
         wkUserData = ObjCObjectGraph::create(userData);
 
-    _page->loadRequest(request, wkUserData.get());
+    _page->loadRequest(request, [request _web_shouldOpenExternalURLs] ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow, wkUserData.get());
 }
 
 - (void)loadFileURL:(NSURL *)URL restrictToFilesWithin:(NSURL *)allowedDirectory
index 9f61fb7..13b4a6b 100644 (file)
@@ -172,6 +172,11 @@ static NSInteger toNSButtonNumber(WebKit::WebMouseEvent::Button mouseButton)
     return _navigationAction->canHandleRequest();
 }
 
+- (BOOL)_shouldOpenExternalURLs
+{
+    return _navigationAction->shouldOpenExternalURLs();
+}
+
 @end
 
 #endif
index 30ad179..e212c99 100644 (file)
@@ -32,6 +32,7 @@
 @property (nonatomic, readonly) NSURL *_originalURL;
 @property (nonatomic, readonly, getter=_isUserInitiated) BOOL _userInitiated;
 @property (nonatomic, readonly) BOOL _canHandleRequest;
+@property (nonatomic, readonly) BOOL _shouldOpenExternalURLs;
 
 @end
 
index d78fd81..bbe4c4a 100644 (file)
@@ -73,6 +73,7 @@
 #import "_WKDiagnosticLoggingDelegate.h"
 #import "_WKFindDelegate.h"
 #import "_WKFormDelegate.h"
+#import "_WKNSURLRequestExtras.h"
 #import "_WKRemoteObjectRegistryInternal.h"
 #import "_WKSessionStateInternal.h"
 #import "_WKVisitedLinkProviderInternal.h"
 #import "WebVideoFullscreenManagerProxy.h"
 #import <UIKit/UIApplication.h>
 #import <WebCore/CoreGraphicsSPI.h>
+#import <WebCore/FrameLoaderTypes.h>
 #import <WebCore/InspectorOverlay.h>
 #import <WebCore/QuartzCoreSPI.h>
 
@@ -443,7 +445,8 @@ static bool shouldAllowAlternateFullscreen()
 
 - (WKNavigation *)loadRequest:(NSURLRequest *)request
 {
-    auto navigation = _page->loadRequest(request);
+    WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = [request _web_shouldOpenExternalURLs] ? WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow : WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow;
+    auto navigation = _page->loadRequest(request, shouldOpenExternalURLsPolicy);
     if (!navigation)
         return nil;
 
index 98372a4..2644b52 100644 (file)
@@ -838,7 +838,7 @@ bool WebPageProxy::maybeInitializeSandboxExtensionHandle(const URL& url, Sandbox
     return true;
 }
 
-RefPtr<API::Navigation> WebPageProxy::loadRequest(const ResourceRequest& request, API::Object* userData)
+RefPtr<API::Navigation> WebPageProxy::loadRequest(const ResourceRequest& request, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy, API::Object* userData)
 {
     if (m_isClosed)
         return nullptr;
@@ -856,7 +856,7 @@ RefPtr<API::Navigation> WebPageProxy::loadRequest(const ResourceRequest& request
     bool createdExtension = maybeInitializeSandboxExtensionHandle(request.url(), sandboxExtensionHandle);
     if (createdExtension)
         m_process->willAcquireUniversalFileReadSandboxExtension();
-    m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), request, sandboxExtensionHandle, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
+    m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), request, sandboxExtensionHandle, (uint64_t)shouldOpenExternalURLsPolicy, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
     m_process->responsivenessTimer()->start();
 
     return WTF::move(navigation);
@@ -894,7 +894,7 @@ RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, cons
     SandboxExtension::Handle sandboxExtensionHandle;
     SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle);
     m_process->assumeReadAccessToBaseURL(resourceDirectoryURL);
-    m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), fileURL, sandboxExtensionHandle, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
+    m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), fileURL, sandboxExtensionHandle, (uint64_t)ShouldOpenExternalURLsPolicy::ShouldNotAllow, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
     m_process->responsivenessTimer()->start();
 
     return WTF::move(navigation);
index 0d4b47a..0294375 100644 (file)
@@ -65,6 +65,7 @@
 #include "WebProcessLifetimeTracker.h"
 #include <WebCore/Color.h>
 #include <WebCore/DragActions.h>
+#include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/HitTestResult.h>
 #include <WebCore/MediaProducer.h>
 #include <WebCore/Page.h>
@@ -351,7 +352,7 @@ public:
     bool tryClose();
     bool isClosed() const { return m_isClosed; }
 
-    RefPtr<API::Navigation> loadRequest(const WebCore::ResourceRequest&, API::Object* userData = nullptr);
+    RefPtr<API::Navigation> loadRequest(const WebCore::ResourceRequest&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow, API::Object* userData = nullptr);
     RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
     RefPtr<API::Navigation> loadData(API::Data*, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr);
     RefPtr<API::Navigation> loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData = nullptr);
index 1f69989..00dd895 100644 (file)
@@ -800,6 +800,7 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const Navigat
     navigationActionData.mouseButton = action->mouseButton();
     navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
     navigationActionData.canHandleRequest = webPage->canHandleRequest(request);
+    navigationActionData.shouldOpenExternalURLs = navigationAction.shouldOpenExternalURLsPolicy() == ShouldOpenExternalURLsPolicy::ShouldAllow;
 
     WebCore::Frame* coreFrame = m_frame->coreFrame();
     WebDocumentLoader* documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().policyDocumentLoader());
index eb501ac..82353f4 100644 (file)
@@ -1014,7 +1014,7 @@ void WebPage::loadURLInFrame(const String& url, uint64_t frameID)
     frame->coreFrame()->loader().load(FrameLoadRequest(frame->coreFrame(), ResourceRequest(URL(URL(), url))));
 }
 
-void WebPage::loadRequest(uint64_t navigationID, const ResourceRequest& request, const SandboxExtension::Handle& sandboxExtensionHandle, const UserData& userData)
+void WebPage::loadRequest(uint64_t navigationID, const ResourceRequest& request, const SandboxExtension::Handle& sandboxExtensionHandle, uint64_t shouldOpenExternalURLsPolicy, const UserData& userData)
 {
     SendStopResponsivenessTimer stopper(this);
 
@@ -1027,7 +1027,11 @@ void WebPage::loadRequest(uint64_t navigationID, const ResourceRequest& request,
     m_loaderClient.willLoadURLRequest(this, request, WebProcess::singleton().transformHandlesToObjects(userData.object()).get());
 
     // Initate the load in WebCore.
-    corePage()->userInputBridge().loadRequest(FrameLoadRequest(m_mainFrame->coreFrame(), request));
+    FrameLoadRequest frameLoadRequest(m_mainFrame->coreFrame(), request);
+    ShouldOpenExternalURLsPolicy externalURLsPolicy = static_cast<ShouldOpenExternalURLsPolicy>(shouldOpenExternalURLsPolicy);
+    frameLoadRequest.setShouldOpenExternalURLsPolicy(externalURLsPolicy);
+
+    corePage()->userInputBridge().loadRequest(frameLoadRequest);
 
     ASSERT(!m_pendingNavigationID);
 }
index 00073d9..65a7174 100644 (file)
@@ -935,7 +935,7 @@ private:
 
     // Actions
     void tryClose();
-    void loadRequest(uint64_t navigationID, const WebCore::ResourceRequest&, const SandboxExtension::Handle&, const UserData&);
+    void loadRequest(uint64_t navigationID, const WebCore::ResourceRequest&, const SandboxExtension::Handle&, uint64_t shouldOpenExternalURLsPolicy, const UserData&);
     void loadData(const IPC::DataReference&, const String& MIMEType, const String& encodingName, const String& baseURL, const UserData&);
     void loadHTMLString(uint64_t navigationID, const String& htmlString, const String& baseURL, const UserData&);
     void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, const String& provisionalLoadErrorURL, const UserData&);
index 9aff8f2..db638b8 100644 (file)
@@ -125,7 +125,7 @@ messages -> WebPage LegacyReceiver {
     TryRestoreScrollPosition()
 
     LoadURLInFrame(String url, uint64_t frameID)
-    LoadRequest(uint64_t navigationID, WebCore::ResourceRequest request, WebKit::SandboxExtension::Handle sandboxExtensionHandle, WebKit::UserData userData)
+    LoadRequest(uint64_t navigationID, WebCore::ResourceRequest request, WebKit::SandboxExtension::Handle sandboxExtensionHandle, uint64_t shouldOpenExternalURLsPolicy, WebKit::UserData userData)
     LoadData(IPC::DataReference data, String MIMEType, String encoding, String baseURL, WebKit::UserData userData)
     LoadHTMLString(uint64_t navigationID, String htmlString, String baseURL, WebKit::UserData userData)
     LoadAlternateHTMLString(String htmlString, String baseURL, String unreachableURL, String provisionalLoadErrorURL, WebKit::UserData userData)