Modified: trunk/Source/WebKit2/ChangeLog (186195 => 186196)
--- trunk/Source/WebKit2/ChangeLog 2015-07-01 21:52:07 UTC (rev 186195)
+++ trunk/Source/WebKit2/ChangeLog 2015-07-01 21:54:59 UTC (rev 186196)
@@ -1,3 +1,14 @@
+2015-07-01 Brady Eidson <beid...@apple.com>
+
+ Never try to pass URLs to LaunchServices when they're the same domain as the current URL.
+ <rdar://problem/20731429> and https://bugs.webkit.org/show_bug.cgi?id=146521
+
+ Reviewed by Alex Christensen.
+
+ * UIProcess/Cocoa/NavigationState.mm:
+ (WebKit::tryAppLink): Compare the proposed URL to the current URL to see if they’re in the same domain.
+ (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+
2015-07-01 Tim Horton <timothy_hor...@apple.com>
WKWebView snapshots have the wrong scale after rotation
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.mm (186195 => 186196)
--- trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.mm 2015-07-01 21:52:07 UTC (rev 186195)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.mm 2015-07-01 21:54:59 UTC (rev 186196)
@@ -63,6 +63,7 @@
#import "_WKRenderingProgressEventsInternal.h"
#import "_WKSameDocumentNavigationTypeInternal.h"
#import <WebCore/Credential.h>
+#import <WebCore/URL.h>
#import <wtf/NeverDestroyed.h>
#if HAVE(APP_LINKS)
@@ -73,6 +74,8 @@
#import "QuickLookDocumentData.h"
#endif
+using namespace WebCore;
+
namespace WebKit {
static HashMap<WebPageProxy*, NavigationState*>& navigationStates()
@@ -230,33 +233,44 @@
{
}
-static void tryAppLink(RefPtr<API::NavigationAction> navigationAction, std::function<void (bool)> completionHandler)
+static void tryAppLink(RefPtr<API::NavigationAction> navigationAction, const String& currentMainFrameURL, std::function<void (bool)> completionHandler)
{
#if HAVE(APP_LINKS)
bool mainFrameNavigation = !navigationAction->targetFrame() || navigationAction->targetFrame()->isMainFrame();
bool shouldOpenExternalURLs = navigationAction->shouldOpenExternalURLs();
- if (mainFrameNavigation && shouldOpenExternalURLs) {
- auto* localCompletionHandler = new std::function<void (bool)>(WTF::move(completionHandler));
- [LSAppLink openWithURL:navigationAction->request().url() completionHandler:[localCompletionHandler](BOOL success, NSError *) {
- dispatch_async(dispatch_get_main_queue(), [localCompletionHandler, success] {
- (*localCompletionHandler)(success);
- delete localCompletionHandler;
- });
- }];
+ if (!mainFrameNavigation || !shouldOpenExternalURLs) {
+ completionHandler(false);
return;
}
-#endif
+ // If the new URL is within the same origin as the current URL, do not try to open it externally.
+ URL currentURL = URL(ParsedURLString, currentMainFrameURL);
+ if (protocolHostAndPortAreEqual(currentURL, navigationAction->request().url())) {
+ completionHandler(false);
+ return;
+ }
+
+ auto* localCompletionHandler = new std::function<void (bool)>(WTF::move(completionHandler));
+ [LSAppLink openWithURL:navigationAction->request().url() completionHandler:[localCompletionHandler](BOOL success, NSError *) {
+ dispatch_async(dispatch_get_main_queue(), [localCompletionHandler, success] {
+ (*localCompletionHandler)(success);
+ delete localCompletionHandler;
+ });
+ }];
+#else
completionHandler(false);
+#endif
}
-void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageProxy&, API::NavigationAction& navigationAction, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData)
+void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageProxy& webPageProxy, API::NavigationAction& navigationAction, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData)
{
+ String mainFrameURLString = webPageProxy.mainFrame()->url();
+
if (!m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandler) {
RefPtr<API::NavigationAction> localNavigationAction = &navigationAction;
RefPtr<WebFramePolicyListenerProxy> localListener = WTF::move(listener);
- tryAppLink(localNavigationAction, [localListener, localNavigationAction] (bool followedLinkToApp) {
+ tryAppLink(localNavigationAction, mainFrameURLString, [localListener, localNavigationAction] (bool followedLinkToApp) {
if (followedLinkToApp) {
localListener->ignore();
return;
@@ -292,12 +306,12 @@
RefPtr<API::NavigationAction> localNavigationAction = &navigationAction;
RefPtr<WebFramePolicyListenerProxy> localListener = WTF::move(listener);
RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(navigationDelegate.get(), @selector(webView:decidePolicyForNavigationAction:decisionHandler:));
- [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) decisionHandler:[localListener, localNavigationAction, checker](WKNavigationActionPolicy actionPolicy) {
+ [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) decisionHandler:[localListener, localNavigationAction, checker, mainFrameURLString](WKNavigationActionPolicy actionPolicy) {
checker->didCallCompletionHandler();
switch (actionPolicy) {
case WKNavigationActionPolicyAllow:
- tryAppLink(localNavigationAction, [localListener](bool followedLinkToApp) {
+ tryAppLink(localNavigationAction, mainFrameURLString, [localListener](bool followedLinkToApp) {
if (followedLinkToApp) {
localListener->ignore();
return;