summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2017-12-29 00:06:56 -0800
committerJake Petroules <jake.petroules@qt.io>2018-01-02 22:59:23 +0000
commita14f37e76b429876015ee96cc4adb97ed4c9fbed (patch)
tree29ad0f6540749634ee384e6c7a8a403836e2ac35
parent8059e2d9b874cbcebc76adf77b89f0cedf6e623d (diff)
WKWebView: try to pass URLs with unrecognized schemes down to the OS
This more closely matches the behavior of the Android implementation, which attempts to launch an Intent to handle URLs with schemes not directly handled by the web view itself. The QtWebEngine implementation similarly passes URLs with unhandled schemes down to QDesktopServices. For the native web view API we'll go directly to the system URL handling APIs instead of through QDesktopServices again in order to match the Android implementation which uses the native API (Intents). Change-Id: Ie2881bf17f3b057cc053c9a4faa8cd81d6f6faca Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--src/webview/qwebview_darwin.mm40
-rw-r--r--src/webview/webview-lib.pri1
2 files changed, 41 insertions, 0 deletions
diff --git a/src/webview/qwebview_darwin.mm b/src/webview/qwebview_darwin.mm
index 35fc726..90f6551 100644
--- a/src/webview/qwebview_darwin.mm
+++ b/src/webview/qwebview_darwin.mm
@@ -202,6 +202,46 @@ QT_END_NAMESPACE
}
}
+- (void)webView:(WKWebView *)webView
+decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
+ decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+ __attribute__((availability(ios_app_extension,unavailable)))
+{
+ Q_UNUSED(webView);
+ NSURL *url = navigationAction.request.URL;
+ const BOOL handled = (^{
+#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(101300, 110000)
+ if (__builtin_available(macOS 10.13, iOS 11.0, *)) {
+ return [WKWebView handlesURLScheme:url.scheme];
+ } else
+#endif
+ {
+ // +[WKWebView handlesURLScheme:] is a stub that calls
+ // WebCore::SchemeRegistry::isBuiltinScheme();
+ // replicate that as closely as possible
+ return [@[
+ @"about", @"applewebdata", @"blob", @"data",
+ @"file", @"http", @"https", @"javascript",
+#ifdef Q_OS_MACOS
+ @"safari-extension",
+#endif
+ @"webkit-fake-url", @"wss", @"x-apple-content-filter",
+#ifdef Q_OS_MACOS
+ @"x-apple-ql-id"
+#endif
+ ] containsObject:url.scheme];
+ }
+ })();
+ if (!handled) {
+#ifdef Q_OS_MACOS
+ [[NSWorkspace sharedWorkspace] openURL:url];
+#elif defined(Q_OS_IOS)
+ [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
+#endif
+ }
+ decisionHandler(handled ? WKNavigationActionPolicyAllow : WKNavigationActionPolicyCancel);
+}
+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change
context:(void *)context {
Q_UNUSED(object);
diff --git a/src/webview/webview-lib.pri b/src/webview/webview-lib.pri
index f5d6774..1af6dcf 100644
--- a/src/webview/webview-lib.pri
+++ b/src/webview/webview-lib.pri
@@ -51,6 +51,7 @@ android {
$$COMMON_HEADERS \
qwebview_darwin_p.h
LIBS_PRIVATE += -framework Foundation -framework WebKit
+ macos: LIBS_PRIVATE += -framework AppKit
ios: LIBS_PRIVATE += -framework UIKit
macos: CONFIG += use_webengine_backend