Title: [186964] trunk
Revision
186964
Author
[email protected]
Date
2015-07-17 14:16:09 -0700 (Fri, 17 Jul 2015)

Log Message

Source/WebCore:
WebCore part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
https://bugs.webkit.org/show_bug.cgi?id=147040

Reviewed by Dean Jackson.

Test: TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm

* loader/FrameLoader.cpp:
(WebCore::shouldOpenExternalURLsPolicyToApply): Pulled the logic out of
applyShouldOpenExternalURLsPolicyToNewDocumentLoader into this new helper.
(WebCore::FrameLoader::loadURL): When targeting a new frame, apply the external URLs policy
to the action passed to checkNewWindowPolicy.
(WebCore::FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader): Call the new
helper function.
(WebCore::createWindow): Include the external URL policy in the action passed to
createWindow.

Source/WebKit2:
WebKit2 part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
https://bugs.webkit.org/show_bug.cgi?id=147040

Reviewed by Dean Jackson.

* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::createNewPage): Disallow App Links if the new page is for the
same protocol, host and port as the main frame of this page.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForNavigationAction): Disallow App Links if
m_shouldSuppressAppLinksInNextNavigationPolicyDecision is set, and reset it. See below for
when we set it.
(WebKit::WebPageProxy::decidePolicyForNewWindowAction): Disallow App Links if the new window
is for the same protocol, host and port as the main frame of this page.
(WebKit::WebPageProxy::createNewPage): Make the new page disallow App Links in the first
policy decision if it is for the same protocol, host and port as the main frame of this
page.
* UIProcess/WebPageProxy.h: Added m_shouldSuppressAppLinksInNextNavigationPolicyDecision
member variable.

* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::createWindow): Pass the shouldOpenExternalURLsPolicy.

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction): Ditto.

Tools:
Tests for <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
https://bugs.webkit.org/show_bug.cgi?id=147040

Reviewed by Dean Jackson.

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

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (186963 => 186964)


--- trunk/Source/WebCore/ChangeLog	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebCore/ChangeLog	2015-07-17 21:16:09 UTC (rev 186964)
@@ -1,3 +1,22 @@
+2015-07-17  Dan Bernstein  <[email protected]>
+
+        WebCore part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
+        https://bugs.webkit.org/show_bug.cgi?id=147040
+
+        Reviewed by Dean Jackson.
+
+        Test: TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm
+
+        * loader/FrameLoader.cpp:
+        (WebCore::shouldOpenExternalURLsPolicyToApply): Pulled the logic out of
+        applyShouldOpenExternalURLsPolicyToNewDocumentLoader into this new helper.
+        (WebCore::FrameLoader::loadURL): When targeting a new frame, apply the external URLs policy
+        to the action passed to checkNewWindowPolicy.
+        (WebCore::FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader): Call the new
+        helper function.
+        (WebCore::createWindow): Include the external URL policy in the action passed to
+        createWindow.
+
 2015-07-17  Anders Carlsson  <[email protected]>
 
         ScrollView.h should be self-contained

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (186963 => 186964)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2015-07-17 21:16:09 UTC (rev 186964)
@@ -1187,6 +1187,15 @@
     }
 }
 
+static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& sourceFrame, ShouldOpenExternalURLsPolicy propagatedPolicy)
+{
+    if (!sourceFrame.isMainFrame())
+        return ShouldOpenExternalURLsPolicy::ShouldNotAllow;
+    if (ScriptController::processingUserGesture())
+        return ShouldOpenExternalURLsPolicy::ShouldAllow;
+    return propagatedPolicy;
+}
+
 void FrameLoader::loadURL(const FrameLoadRequest& frameLoadRequest, const String& referrer, FrameLoadType newLoadType, Event* event, PassRefPtr<FormState> prpFormState)
 {
     if (m_inStopAllLoaders)
@@ -1233,6 +1242,7 @@
     NavigationAction action(request, newLoadType, isFormSubmission, event, frameLoadRequest.shouldOpenExternalURLsPolicy());
 
     if (!targetFrame && !frameName.isEmpty()) {
+        action = "" frameLoadRequest.shouldOpenExternalURLsPolicy()));
         policyChecker().checkNewWindowPolicy(action, request, formState.release(), frameName, [this, allowNavigationToInvalidURL, openerPolicy](const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, const NavigationAction& action, bool shouldContinue) {
             continueLoadAfterNewWindowPolicy(request, formState, frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy);
         });
@@ -3457,12 +3467,7 @@
 
 void FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader(DocumentLoader& documentLoader, ShouldOpenExternalURLsPolicy propagatedPolicy)
 {
-    if (!m_frame.isMainFrame())
-        documentLoader.setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy::ShouldNotAllow);
-    else if (ScriptController::processingUserGesture())
-        documentLoader.setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy::ShouldAllow);
-    else
-        documentLoader.setShouldOpenExternalURLsPolicy(propagatedPolicy);
+    documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, propagatedPolicy));
 }
 
 bool FrameLoaderClient::hasHTMLView() const
@@ -3504,7 +3509,8 @@
     if (!oldPage)
         return nullptr;
 
-    Page* page = oldPage->chrome().createWindow(&openerFrame, requestWithReferrer, features, NavigationAction(requestWithReferrer.resourceRequest()));
+    ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(openerFrame, request.shouldOpenExternalURLsPolicy());
+    Page* page = oldPage->chrome().createWindow(&openerFrame, requestWithReferrer, features, NavigationAction(requestWithReferrer.resourceRequest(), shouldOpenExternalURLsPolicy));
     if (!page)
         return nullptr;
 

Modified: trunk/Source/WebKit2/ChangeLog (186963 => 186964)


--- trunk/Source/WebKit2/ChangeLog	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebKit2/ChangeLog	2015-07-17 21:16:09 UTC (rev 186964)
@@ -1,3 +1,32 @@
+2015-07-17  Dan Bernstein  <[email protected]>
+
+        WebKit2 part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
+        https://bugs.webkit.org/show_bug.cgi?id=147040
+
+        Reviewed by Dean Jackson.
+
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::UIClient::createNewPage): Disallow App Links if the new page is for the
+        same protocol, host and port as the main frame of this page.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Disallow App Links if
+        m_shouldSuppressAppLinksInNextNavigationPolicyDecision is set, and reset it. See below for
+        when we set it.
+        (WebKit::WebPageProxy::decidePolicyForNewWindowAction): Disallow App Links if the new window
+        is for the same protocol, host and port as the main frame of this page.
+        (WebKit::WebPageProxy::createNewPage): Make the new page disallow App Links in the first
+        policy decision if it is for the same protocol, host and port as the main frame of this
+        page.
+        * UIProcess/WebPageProxy.h: Added m_shouldSuppressAppLinksInNextNavigationPolicyDecision
+        member variable.
+
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::createWindow): Pass the shouldOpenExternalURLsPolicy.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction): Ditto.
+
 2015-07-17  Tim Horton  <[email protected]>
 
         iOS TextIndicators include text that is not supposed to be indicated

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm (186963 => 186964)


--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm	2015-07-17 21:16:09 UTC (rev 186964)
@@ -39,6 +39,7 @@
 #import "WKWindowFeaturesInternal.h"
 #import "WKUIDelegatePrivate.h"
 #import "_WKFrameHandleInternal.h"
+#import <WebCore/URL.h>
 
 namespace WebKit {
 
@@ -108,8 +109,10 @@
     [configuration _setRelatedWebView:m_uiDelegate.m_webView];
 
     auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin());
-    auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, request, WebCore::URL(), true);
 
+    bool shouldOpenAppLinks = !protocolHostAndPortAreEqual(WebCore::URL(WebCore::ParsedURLString, initiatingFrame->url()), request.url());
+    auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, request, WebCore::URL(), shouldOpenAppLinks);
+
     RetainPtr<WKWebView> webView = [delegate.get() webView:m_uiDelegate.m_webView createWebViewWithConfiguration:configuration.get() forNavigationAction:wrapper(navigationAction) windowFeatures:adoptNS([[WKWindowFeatures alloc] _initWithWindowFeatures:windowFeatures]).get()];
 
     if (!webView)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (186963 => 186964)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-07-17 21:16:09 UTC (rev 186964)
@@ -3333,7 +3333,7 @@
         else if (originatingFrame)
             sourceFrameInfo = API::FrameInfo::create(*originatingFrame, originatingFrameSecurityOrigin.securityOrigin());
 
-        bool shouldOpenAppLinks = (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
+        bool shouldOpenAppLinks = !m_shouldSuppressAppLinksInNextNavigationPolicyDecision && (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
 
         auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), destinationFrameInfo.get(), request, originalRequest.url(), shouldOpenAppLinks);
 
@@ -3341,6 +3341,7 @@
     } else
         m_policyClient->decidePolicyForNavigationAction(*this, frame, navigationActionData, originatingFrame, originalRequest, request, WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
 
+    m_shouldSuppressAppLinksInNextNavigationPolicyDecision = false;
     m_inDecidePolicyForNavigationAction = false;
 
     // Check if we received a policy decision already. If we did, we can just pass it back.
@@ -3366,7 +3367,8 @@
         if (frame)
             sourceFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin());
 
-        auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), true);
+        bool shouldOpenAppLinks = !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
+        auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), shouldOpenAppLinks);
 
         m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
 
@@ -3534,6 +3536,7 @@
     newPageParameters = newPage->creationParameters();
 
     WebsiteDataStore::cloneSessionData(*this, *newPage);
+    newPage->m_shouldSuppressAppLinksInNextNavigationPolicyDecision = protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
 }
     
 void WebPageProxy::showPage()

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (186963 => 186964)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-07-17 21:16:09 UTC (rev 186964)
@@ -1640,6 +1640,7 @@
     bool m_syncNavigationActionPolicyActionIsValid;
     WebCore::PolicyAction m_syncNavigationActionPolicyAction;
     uint64_t m_syncNavigationActionPolicyDownloadID;
+    bool m_shouldSuppressAppLinksInNextNavigationPolicyDecision { false };
 
     Deque<NativeWebKeyboardEvent> m_keyEventQueue;
     Deque<NativeWebWheelEvent> m_wheelEventQueue;

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (186963 => 186964)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2015-07-17 21:16:09 UTC (rev 186964)
@@ -218,6 +218,7 @@
     navigationActionData.mouseButton = InjectedBundleNavigationAction::mouseButtonForNavigationAction(navigationAction);
     navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
     navigationActionData.canHandleRequest = m_page->canHandleRequest(request.resourceRequest());
+    navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
 
     uint64_t newPageID = 0;
     WebPageCreationParameters parameters;

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (186963 => 186964)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2015-07-17 21:16:09 UTC (rev 186964)
@@ -738,6 +738,7 @@
     navigationActionData.mouseButton = action->mouseButton();
     navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
     navigationActionData.canHandleRequest = webPage->canHandleRequest(request);
+    navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
 
     webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), SecurityOriginData::fromFrame(m_frame), navigationActionData, request, frameName, listenerID, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
 }

Modified: trunk/Tools/ChangeLog (186963 => 186964)


--- trunk/Tools/ChangeLog	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Tools/ChangeLog	2015-07-17 21:16:09 UTC (rev 186964)
@@ -1,3 +1,17 @@
+2015-07-17  Dan Bernstein  <[email protected]>
+
+        Tests for <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
+        https://bugs.webkit.org/show_bug.cgi?id=147040
+
+        Reviewed by Dean Jackson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm: Added.
+        (-[ShouldOpenExternalURLsInNewWindowActionsController webView:decidePolicyForNavigationAction:decisionHandler:]):
+        (-[ShouldOpenExternalURLsInNewWindowActionsController webView:didFinishNavigation:]):
+        (-[ShouldOpenExternalURLsInNewWindowActionsController webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
+        (TEST):
+
 2015-07-16  Dean Johnson  <[email protected]>
 
         webkit-patch uses incorrect credentials from keychain to login until account lockout

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (186963 => 186964)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2015-07-17 19:35:57 UTC (rev 186963)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2015-07-17 21:16:09 UTC (rev 186964)
@@ -41,6 +41,7 @@
 		378E64771632655E00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378E64751632655D00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp */; };
 		378E64791632707400B6C676 /* link-with-title.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 378E647816326FDF00B6C676 /* link-with-title.html */; };
 		379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */; };
+		37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */; };
 		37D36ED71AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */; };
 		37D36F321B004DD400BAF5D9 /* ProvisionalURLChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */; };
 		37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */; };
@@ -498,6 +499,7 @@
 		379028B814FABE49007E6B43 /* acceptsFirstMouse.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = acceptsFirstMouse.html; sourceTree = "<group>"; };
 		3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringByEvaluatingJavaScriptFromString.mm; sourceTree = "<group>"; };
 		37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SubresourceErrorCrash.mm; sourceTree = "<group>"; };
+		37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShouldOpenExternalURLsInNewWindowActions.mm; sourceTree = "<group>"; };
 		37C784DE197C8F2E0010A496 /* RenderedImageFromDOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageFromDOMNode.mm; sourceTree = "<group>"; };
 		37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadAlternateHTMLString.mm; sourceTree = "<group>"; };
 		37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProvisionalURLChange.mm; sourceTree = "<group>"; };
@@ -858,6 +860,7 @@
 				CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
 				C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
 				37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */,
+				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
 				7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
 				0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
@@ -1472,6 +1475,7 @@
 				7CCE7F231A411AF600447C4C /* Download.mm in Sources */,
 				7CCE7EEE1A411AE600447C4C /* DownloadDecideDestinationCrash.cpp in Sources */,
 				7CCE7EBE1A411A7E00447C4C /* DynamicDeviceScaleFactor.mm in Sources */,
+				37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */,
 				7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */,
 				7CCE7EE01A411A9A00447C4C /* EditorCommands.mm in Sources */,
 				7CCE7EBF1A411A7E00447C4C /* ElementAtPointInWebFrame.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm (0 => 186964)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm	2015-07-17 21:16:09 UTC (rev 186964)
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if PLATFORM(MAC)
+
+#import "PlatformUtilities.h"
+#import <WebKit/WKNavigationActionPrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+static bool createdWebView;
+static bool decidedPolicy;
+static bool finishedNavigation;
+static RetainPtr<WKNavigationAction> action;
+static RetainPtr<WKWebView> newWebView;
+
+@interface ShouldOpenExternalURLsInNewWindowActionsController : NSObject <WKNavigationDelegate, WKUIDelegate>
+@end
+
+@implementation ShouldOpenExternalURLsInNewWindowActionsController
+
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+{
+    decisionHandler(webView == newWebView.get() ? WKNavigationActionPolicyCancel : WKNavigationActionPolicyAllow);
+
+    action = ""
+    decidedPolicy = true;
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    finishedNavigation = true;
+}
+
+- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
+{
+    action = ""
+    newWebView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration]);
+
+    createdWebView = true;
+    return newWebView.get();
+}
+
+@end
+
+TEST(WebKit2, ShouldOpenExternalURLsInWindowOpen)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [[window contentView] addSubview:webView.get()];
+
+    auto controller = adoptNS([[ShouldOpenExternalURLsInNewWindowActionsController alloc] init]);
+    [webView setNavigationDelegate:controller.get()];
+    [webView setUIDelegate:controller.get()];
+
+    [webView loadHTMLString:@"<body _onclick_=\"window.open('http://webkit.org/destination')\">" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+    TestWebKitAPI::Util::run(&finishedNavigation);
+    finishedNavigation = false;
+
+    NSPoint clickPoint = NSMakePoint(100, 100);
+
+    [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    TestWebKitAPI::Util::run(&createdWebView);
+    createdWebView = false;
+
+    // User-initiated window.open to the same scheme, host and port should allow external schemes but not App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+
+    decidedPolicy = false;
+    [newWebView setNavigationDelegate:controller.get()];
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    // User-initiated window.open to the same scheme, host and port should allow external schemes but not App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+
+    [webView loadHTMLString:@"<body _onclick_=\"window.open('https://webkit.org/destination')\">" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+    TestWebKitAPI::Util::run(&finishedNavigation);
+    finishedNavigation = false;
+
+    [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    TestWebKitAPI::Util::run(&createdWebView);
+    createdWebView = false;
+
+    // User-initiated window.open to different scheme, host or port should allow external schemes and App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_TRUE([action _shouldOpenAppLinks]);
+
+    decidedPolicy = false;
+    [newWebView setNavigationDelegate:controller.get()];
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    // User-initiated window.open to different scheme, host or port should allow external schemes and App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_TRUE([action _shouldOpenAppLinks]);
+
+    newWebView = nullptr;
+    action = ""
+}
+
+TEST(WebKit2, ShouldOpenExternalURLsInTargetedLink)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [[window contentView] addSubview:webView.get()];
+
+    auto controller = adoptNS([[ShouldOpenExternalURLsInNewWindowActionsController alloc] init]);
+    [webView setNavigationDelegate:controller.get()];
+    [webView setUIDelegate:controller.get()];
+
+    [webView loadHTMLString:@"<a style=\"display: block; height: 100%\" href="" target=\"_blank\">" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+    TestWebKitAPI::Util::run(&finishedNavigation);
+    finishedNavigation = false;
+
+    NSPoint clickPoint = NSMakePoint(100, 100);
+
+    decidedPolicy = false;
+    [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    // User-initiated targeted navigation to the same scheme, host and port should allow external schemes but not App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+
+    TestWebKitAPI::Util::run(&createdWebView);
+    createdWebView = false;
+
+    // User-initiated targeted navigation to the same scheme, host and port should allow external schemes but not App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+
+    decidedPolicy = false;
+    [newWebView setNavigationDelegate:controller.get()];
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    // User-initiated targeted navigation to the same scheme, host and port should allow external schemes but not App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+
+    [webView loadHTMLString:@"<a style=\"display: block; height: 100%\" href="" target=\"_blank\">" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+    TestWebKitAPI::Util::run(&finishedNavigation);
+    finishedNavigation = false;
+
+    decidedPolicy = false;
+    [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    // User-initiated targeted navigation to different scheme, host or port should allow external schemes and App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_TRUE([action _shouldOpenAppLinks]);
+
+    TestWebKitAPI::Util::run(&createdWebView);
+    createdWebView = false;
+
+    // User-initiated targeted navigation to different scheme, host or port should allow external schemes and App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_TRUE([action _shouldOpenAppLinks]);
+
+    decidedPolicy = false;
+    [newWebView setNavigationDelegate:controller.get()];
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    // User-initiated targeted navigation to different scheme, host or port should allow external schemes and App Links.
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_TRUE([action _shouldOpenAppLinks]);
+
+    newWebView = nullptr;
+    action = ""
+}
+
+#endif
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to