Skip to content
Permalink
Browse files
WKWebView with no WKNavigationDelegate does not follow universal links
<rdar://problem/24374110>
https://bugs.webkit.org/show_bug.cgi?id=158997

Patch by Sam Weinig <sam@webkit.org> on 2016-06-21
Reviewed by Dan Bernstein.

Source/WebKit2:

API Test:
     WKWebView.DefaultNavigationDelegate

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
When initializing the WKWebView, set a default navigation client.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setLoaderClient):
Be sure to clear out a navigation client, if present, when setting a loader client,
as they are mutually exclusive.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewDefaultNavigationDelegate.mm: Added.
Add a new test that shows that we have a default navigation delegate by swizzling
-[NSWorkspace openURL:]. This will only be called if there is a default client.

Canonical link: https://commits.webkit.org/177063@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202296 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Sam Weinig authored and webkit-commit-queue committed Jun 21, 2016
1 parent f9d63d3 commit bc2667486df8730fcf6cd8324100f580af8ed176
@@ -1,3 +1,23 @@
2016-06-21 Sam Weinig <sam@webkit.org>

WKWebView with no WKNavigationDelegate does not follow universal links
<rdar://problem/24374110>
https://bugs.webkit.org/show_bug.cgi?id=158997

Reviewed by Dan Bernstein.

API Test:
WKWebView.DefaultNavigationDelegate

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
When initializing the WKWebView, set a default navigation client.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setLoaderClient):
Be sure to clear out a navigation client, if present, when setting a loader client,
as they are mutually exclusive.

2016-06-20 Simon Fraser <simon.fraser@apple.com>

Focus event dispatched in iframe causes parent document to scroll incorrectly
@@ -542,6 +542,8 @@ - (void)_initializeWithConfiguration:(WKWebViewConfiguration *)configuration
_page->setApplicationNameForUserAgent(applicationNameForUserAgent);

_navigationState = std::make_unique<WebKit::NavigationState>(self);
_page->setNavigationClient(_navigationState->createNavigationClient());

_uiDelegate = std::make_unique<WebKit::UIDelegate>(self);
_page->setFindClient(std::make_unique<WebKit::FindClient>(self));
_page->setDiagnosticLoggingClient(std::make_unique<WebKit::DiagnosticLoggingClient>(self));
@@ -569,6 +569,9 @@ void WebPageProxy::setNavigationClient(std::unique_ptr<API::NavigationClient> na

void WebPageProxy::setLoaderClient(std::unique_ptr<API::LoaderClient> loaderClient)
{
if (m_navigationClient && loaderClient)
m_navigationClient = nullptr;

if (!loaderClient) {
m_loaderClient = std::make_unique<API::LoaderClient>();
return;
@@ -1,3 +1,16 @@
2016-06-21 Sam Weinig <sam@webkit.org>

WKWebView with no WKNavigationDelegate does not follow universal links
<rdar://problem/24374110>
https://bugs.webkit.org/show_bug.cgi?id=158997

Reviewed by Dan Bernstein.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewDefaultNavigationDelegate.mm: Added.
Add a new test that shows that we have a default navigation delegate by swizzling
-[NSWorkspace openURL:]. This will only be called if there is a default client.

2016-06-21 Aakash Jain <aakash_jain@apple.com>

run-javascriptcore-tests should have flag to skip mozilla tests
@@ -100,6 +100,7 @@
7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E5081AE5AE8B00CF874B /* test.pdf */; };
7C3965061CDD74F90094DBB8 /* Color.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3965051CDD74F90094DBB8 /* Color.cpp */; };
7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */; };
7C417F331D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C417F311D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm */; };
7C486BA11AA12567003F6F9B /* bundle-file.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7C486BA01AA1254B003F6F9B /* bundle-file.html */; };
7C54A4BE1AA11CCA00380F78 /* WKBundleFileHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C54A4BC1AA11CCA00380F78 /* WKBundleFileHandle.cpp */; };
7C54A4C11AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C54A4BF1AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp */; };
@@ -752,6 +753,7 @@
7AE9E5081AE5AE8B00CF874B /* test.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test.pdf; sourceTree = "<group>"; };
7C3965051CDD74F90094DBB8 /* Color.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Color.cpp; sourceTree = "<group>"; };
7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CommandBackForward.mm; sourceTree = "<group>"; };
7C417F311D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewDefaultNavigationDelegate.mm; sourceTree = "<group>"; };
7C486BA01AA1254B003F6F9B /* bundle-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "bundle-file.html"; sourceTree = "<group>"; };
7C54A4BC1AA11CCA00380F78 /* WKBundleFileHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleFileHandle.cpp; sourceTree = "<group>"; };
7C54A4BF1AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleFileHandle_Bundle.cpp; sourceTree = "<group>"; };
@@ -1166,6 +1168,7 @@
7C882E051C80C624006BF731 /* UserContentWorldProtocol.h */,
93E943F11CD3E87E00AC08C2 /* VideoControlsManager.mm */,
2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */,
7C417F311D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm */,
0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */,
51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */,
@@ -2099,6 +2102,7 @@
7C83E0BB1D0A650000FEBCF3 /* FindInPage.mm in Sources */,
7CCE7EAF1A411A3800447C4C /* PlatformUtilities.cpp in Sources */,
0F139E781A423A6B00F590F5 /* PlatformUtilitiesCocoa.mm in Sources */,
7C417F331D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm in Sources */,
7CCE7EA61A411A0F00447C4C /* PlatformUtilitiesMac.mm in Sources */,
7CCE7EA71A411A1300447C4C /* PlatformWebViewMac.mm in Sources */,
7CCE7F261A411AF600447C4C /* Preferences.mm in Sources */,
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2016 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.
*/

#import "config.h"

#if WK_API_ENABLED
#if PLATFORM(MAC)

#import "InstanceMethodSwizzler.h"
#import "PlatformUtilities.h"
#import "Test.h"
#import <WebKit/WKWebView.h>

static NSString *nonHTTPURLString = @"notreal:/hello";

static bool isDone;

static void newOpenURL(id self, SEL _cmd, NSURL* value)
{
EXPECT_WK_STREQ(nonHTTPURLString, [value absoluteString]);
isDone = true;
}

TEST(WKWebView, DefaultNavigationDelegate)
{
TestWebKitAPI::InstanceMethodSwizzler swizzle([NSWorkspace class], @selector(openURL:), reinterpret_cast<IMP>(newOpenURL));

WKWebView *webView = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"notreal:/hello"]];
[webView loadRequest:request];

TestWebKitAPI::Util::run(&isDone);
}

#endif
#endif

0 comments on commit bc26674

Please sign in to comment.