Diff
Modified: trunk/Source/WebKit/ChangeLog (221872 => 221873)
--- trunk/Source/WebKit/ChangeLog 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/ChangeLog 2017-09-11 20:45:26 UTC (rev 221873)
@@ -1,3 +1,18 @@
+2017-09-11 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForGeolocationPermissionRequest
+ https://bugs.webkit.org/show_bug.cgi?id=176642
+ <rdar://problem/29270035>
+
+ Reviewed by Darin Adler.
+
+ * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::setDelegate):
+ (WebKit::UIDelegate::UIClient::runJavaScriptPrompt):
+ (WebKit::Function<void):
+
2017-09-11 Wenson Hsieh <[email protected]>
[iOS DnD] Elements in the DOM with the `draggable` attribute should be draggable
Modified: trunk/Source/WebKit/UIProcess/API/APIUIClient.h (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/API/APIUIClient.h 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/API/APIUIClient.h 2017-09-11 20:45:26 UTC (rev 221873)
@@ -126,7 +126,7 @@
}
virtual bool runOpenPanel(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, OpenPanelParameters*, WebKit::WebOpenPanelResultListenerProxy*) { return false; }
- virtual Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, Function<void(bool)>&& completionHandler) { return WTFMove(completionHandler); }
+ virtual void decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, Function<void(bool)>&) { }
virtual bool decidePolicyForUserMediaPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionRequestProxy&) { return false; }
virtual bool checkUserMediaPermissionForOrigin(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionCheckProxy&) { return false; }
virtual bool decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy*, SecurityOrigin*, WebKit::NotificationPermissionRequest*) { return false; }
Modified: trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp 2017-09-11 20:45:26 UTC (rev 221873)
@@ -1953,13 +1953,12 @@
return true;
}
- Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>&& completionHandler) final
+ void decidePolicyForGeolocationPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler) final
{
if (!m_client.decidePolicyForGeolocationPermissionRequest)
- return WTFMove(completionHandler);
+ return;
- m_client.decidePolicyForGeolocationPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(GeolocationPermissionRequest::create(WTFMove(completionHandler)).ptr()), m_client.base.clientInfo);
- return nullptr;
+ m_client.decidePolicyForGeolocationPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(GeolocationPermissionRequest::create(std::exchange(completionHandler, nullptr)).ptr()), m_client.base.clientInfo);
}
bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionRequestProxy& permissionRequest) final
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-09-11 20:45:26 UTC (rev 221873)
@@ -105,6 +105,7 @@
- (void)_webView:(WKWebView *)webView mediaCaptureStateDidChange:(_WKMediaCaptureState)state WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
- (WKDragDestinationAction)_webView:(WKWebView *)webView dragDestinationActionMaskForDraggingInfo:(id)draggingInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures completionHandler:(void (^)(WKWebView *webView))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_webView:(WKWebView *)webView requestGeolocationPermissionForFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL allowed))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_webView:(WKWebView *)webView runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_webView:(WKWebView *)webView editorStateDidChange:(NSDictionary *)editorState WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp 2017-09-11 20:45:26 UTC (rev 221873)
@@ -182,11 +182,10 @@
return true;
}
- Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&& completionHandler) final
+ void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>& completionHandler) final
{
- GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(GeolocationPermissionRequest::create(WTFMove(completionHandler)).ptr()));
+ GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(GeolocationPermissionRequest::create(std::exchange(completionHandler, nullptr)).ptr()));
webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get()));
- return nullptr;
}
bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionRequestProxy& permissionRequest) override
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-09-11 20:45:26 UTC (rev 221873)
@@ -90,7 +90,8 @@
void didExitFullscreen(WebPageProxy*) final;
void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final;
void runJavaScriptConfirm(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
- void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&& completionHandler) final;
+ void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&&) final;
+ void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) final;
bool canRunBeforeUnloadConfirmPanel() const final;
void runBeforeUnloadConfirmPanel(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin*, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, Function<void(unsigned long long)>&& completionHandler) final;
@@ -103,10 +104,10 @@
void pageDidScroll(WebPageProxy*) final;
void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
- void unavailablePluginButtonClicked(WebKit::WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
+ void unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, WebEvent::Modifiers, API::Object*);
void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
- void toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&&) final;
+ void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&&) final;
bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, API::Data&) final;
@@ -148,6 +149,7 @@
bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
+ bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
#if PLATFORM(MAC)
bool showWebView : 1;
bool focusWebView : 1;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-09-11 20:45:26 UTC (rev 221873)
@@ -103,6 +103,7 @@
m_delegateMethods.webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
+ m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)];
#if PLATFORM(MAC)
m_delegateMethods.showWebView = [delegate respondsToSelector:@selector(_showWebView:)];
@@ -324,7 +325,7 @@
return;
}
- RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:));
+ auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:));
[delegate webView:m_uiDelegate.m_webView runJavaScriptTextInputPanelWithPrompt:message defaultText:defaultValue initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:BlockPtr<void (NSString *)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](NSString *result) {
if (checker->completionHandlerHasBeenCalled())
return;
@@ -333,6 +334,24 @@
}).get()];
}
+void UIDelegate::UIClient::decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy& frame, API::SecurityOrigin& securityOrigin, Function<void(bool)>& completionHandler)
+{
+ if (!m_uiDelegate.m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler)
+ return;
+
+ auto delegate = m_uiDelegate.m_delegate.get();
+ if (!delegate)
+ return;
+
+ auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:));
+ [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestGeolocationPermissionForFrame:wrapper(API::FrameInfo::create(frame, securityOrigin.securityOrigin())) decisionHandler:BlockPtr<void(BOOL)>::fromCallable([completionHandler = std::exchange(completionHandler, nullptr), checker = WTFMove(checker)](BOOL result) {
+ if (checker->completionHandlerHasBeenCalled())
+ return;
+ checker->didCallCompletionHandler();
+ completionHandler(result);
+ }).get()];
+}
+
bool UIDelegate::UIClient::canRunBeforeUnloadConfirmPanel() const
{
return m_uiDelegate.m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler;
Modified: trunk/Source/WebKit/UIProcess/PageClient.h (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/PageClient.h 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/PageClient.h 2017-09-11 20:45:26 UTC (rev 221873)
@@ -143,7 +143,7 @@
#if PLATFORM(IOS)
// FIXME: Adopt the WKUIDelegatePrivate callback on iOS and remove this.
- virtual Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&&) = 0;
+ virtual void decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) = 0;
#endif
virtual void didStartProvisionalLoadForMainFrame() { };
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2017-09-11 20:45:26 UTC (rev 221873)
@@ -5822,10 +5822,10 @@
// and make it one UIClient call that calls the completionHandler with false
// if there is no delegate instead of returning the completionHandler
// for other code paths to try.
- completionHandler = m_uiClient->decidePolicyForGeolocationPermissionRequest(*this, *frame, origin.get(), WTFMove(completionHandler));
+ m_uiClient->decidePolicyForGeolocationPermissionRequest(*this, *frame, origin.get(), completionHandler);
#if PLATFORM(IOS)
if (completionHandler)
- completionHandler = m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, origin.get(), WTFMove(completionHandler));
+ m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, origin.get(), completionHandler);
#endif
if (completionHandler)
completionHandler(false);
Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h 2017-09-11 20:45:26 UTC (rev 221873)
@@ -63,7 +63,7 @@
void pageClosed() override;
void preferencesDidChange() override;
void toolTipChanged(const String&, const String&) override;
- Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&&) override;
+ void decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) override;
void didStartProvisionalLoadForMainFrame() override;
void didFailProvisionalLoadForMainFrame() override;
void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) override;
Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (221872 => 221873)
--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm 2017-09-11 20:45:26 UTC (rev 221873)
@@ -237,10 +237,9 @@
[m_contentView _didCompleteSyntheticClick];
}
-Function<void(bool)> PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>&& completionHandler)
+void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler)
{
- [[wrapper(m_webView->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:WTFMove(completionHandler) view:m_webView];
- return nullptr;
+ [[wrapper(m_webView->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:std::exchange(completionHandler, nullptr) view:m_webView];
}
void PageClientImpl::didStartProvisionalLoadForMainFrame()
Modified: trunk/Tools/ChangeLog (221872 => 221873)
--- trunk/Tools/ChangeLog 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Tools/ChangeLog 2017-09-11 20:45:26 UTC (rev 221873)
@@ -1,3 +1,17 @@
+2017-09-11 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForGeolocationPermissionRequest
+ https://bugs.webkit.org/show_bug.cgi?id=176642
+ <rdar://problem/29270035>
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+ (-[GeolocationDelegate initWithAllowGeolocation:]):
+ (-[GeolocationDelegate _webView:requestGeolocationPermissionForFrame:decisionHandler:]):
+ (-[GeolocationDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+ (TEST):
+
2017-09-11 Wenson Hsieh <[email protected]>
[iOS DnD] Elements in the DOM with the `draggable` attribute should be draggable
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm (221872 => 221873)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm 2017-09-11 19:39:46 UTC (rev 221872)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm 2017-09-11 20:45:26 UTC (rev 221873)
@@ -27,10 +27,14 @@
#if WK_API_ENABLED
+#import "PlatformUtilities.h"
#import "TestWKWebView.h"
#import "Utilities.h"
#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKContext.h>
#import <WebKit/WKContextPrivateMac.h>
+#import <WebKit/WKGeolocationManager.h>
+#import <WebKit/WKGeolocationPosition.h>
#import <WebKit/WKPreferencesPrivate.h>
#import <WebKit/WKRetainPtr.h>
#import <WebKit/WKUIDelegatePrivate.h>
@@ -72,6 +76,79 @@
TestWebKitAPI::Util::run(&done);
}
+@interface GeolocationDelegate : NSObject <WKUIDelegatePrivate> {
+ bool _allowGeolocation;
+}
+
+- (id)initWithAllowGeolocation:(bool)allowGeolocation;
+
+@end
+
+@implementation GeolocationDelegate
+
+- (id)initWithAllowGeolocation:(bool)allowGeolocation
+{
+ if (!(self = [super init]))
+ return nil;
+ _allowGeolocation = allowGeolocation;
+ return self;
+}
+
+- (void)_webView:(WKWebView *)webView requestGeolocationPermissionForFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL allowed))decisionHandler
+{
+ EXPECT_TRUE(frame.isMainFrame);
+ EXPECT_STREQ(frame.request.URL.absoluteString.UTF8String, _allowGeolocation ? "https://example.org/" : "https://example.com/");
+ EXPECT_EQ(frame.securityOrigin.port, 0);
+ EXPECT_STREQ(frame.securityOrigin.protocol.UTF8String, "https");
+ EXPECT_STREQ(frame.securityOrigin.host.UTF8String, _allowGeolocation ? "example.org" : "example.com");
+ decisionHandler(_allowGeolocation);
+}
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+ if (_allowGeolocation)
+ EXPECT_STREQ(message.UTF8String, "position 50.644358 3.345453");
+ else
+ EXPECT_STREQ(message.UTF8String, "error 1 User denied Geolocation");
+ completionHandler();
+ done = true;
+}
+
+@end
+
+TEST(WebKit, GeolocationPermission)
+{
+ NSString *html = @"<script>navigator.geolocation.watchPosition("
+ "function(p) { alert('position ' + p.coords.latitude + ' ' + p.coords.longitude) },"
+ "function(e) { alert('error ' + e.code + ' ' + e.message) })"
+ "</script>";
+
+ auto pool = adoptNS([[WKProcessPool alloc] init]);
+
+ WKGeolocationProviderV1 providerCallback;
+ memset(&providerCallback, 0, sizeof(WKGeolocationProviderV1));
+ providerCallback.base.version = 1;
+ providerCallback.startUpdating = [] (WKGeolocationManagerRef manager, const void*) {
+ WKGeolocationManagerProviderDidChangePosition(manager, adoptWK(WKGeolocationPositionCreate(0, 50.644358, 3.345453, 2.53)).get());
+ };
+ WKGeolocationManagerSetProvider(WKContextGetGeolocationManager((WKContextRef)pool.get()), &providerCallback.base);
+
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ configuration.get().processPool = pool.get();
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+ auto delegate1 = adoptNS([[GeolocationDelegate alloc] initWithAllowGeolocation:false]);
+ [webView setUIDelegate:delegate1.get()];
+ [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://example.com/"]];
+ TestWebKitAPI::Util::run(&done);
+
+ done = false;
+ auto delegate2 = adoptNS([[GeolocationDelegate alloc] initWithAllowGeolocation:true]);
+ [webView setUIDelegate:delegate2.get()];
+ [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://example.org/"]];
+ TestWebKitAPI::Util::run(&done);
+}
+
+
#if PLATFORM(MAC)
@class UITestDelegate;