Diff
Modified: trunk/Source/WebCore/ChangeLog (274468 => 274469)
--- trunk/Source/WebCore/ChangeLog 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebCore/ChangeLog 2021-03-16 08:25:52 UTC (rev 274469)
@@ -1,3 +1,15 @@
+2021-03-16 Youenn Fablet <[email protected]>
+
+ Add a new delegate for geolocation permission
+ https://bugs.webkit.org/show_bug.cgi?id=223183
+
+ Reviewed by Eric Carlson.
+
+ Add strings for a default geolocation prompt.
+ Covered by API tests.
+
+ * en.lproj/Localizable.strings:
+
2021-03-15 Rob Buis <[email protected]>
Fix table-element-001.html
Modified: trunk/Source/WebCore/en.lproj/Localizable.strings (274468 => 274469)
--- trunk/Source/WebCore/en.lproj/Localizable.strings 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebCore/en.lproj/Localizable.strings 2021-03-16 08:25:52 UTC (rev 274469)
@@ -124,6 +124,9 @@
/* Button title in Device Orientation Permission API prompt */
"Allow (device motion and orientation access)" = "Allow";
+/* Allow button title in geolocation prompt */
+"Allow (geolocation)" = "Allow";
+
/* Allow button title in speech recognition prompt */
"Allow (speechrecognition)" = "Allow";
@@ -133,6 +136,9 @@
/* Message for requesting cross-site cookie and website data access. */
"Allow “%@” and “%@” to use cookies and website data while browsing “%@”?" = "Allow “%@” and “%@” to use cookies and website data while browsing “%@”?";
+/* Message for geolocation prompt */
+"Allow “%@” to use your current location?" = "Allow “%@” to use your current location?";
+
/* Message for spechrecognition prompt */
"Allow “%@” to capture your audio and use it for speech recognition?" = "Allow “%@” to capture your audio and use it for speech recognition?";
@@ -331,6 +337,9 @@
/* Title of the Done button for zoomed form controls. */
"Done" = "Done";
+/* Disallow button title in geolocation prompt */
+"Don’t Allow (geolocation)" = "Don’t Allow";
+
/* Disallow button title in speech recognition prompt */
"Don’t Allow (speechrecognition)" = "Don’t Allow";
Modified: trunk/Source/WebKit/ChangeLog (274468 => 274469)
--- trunk/Source/WebKit/ChangeLog 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/ChangeLog 2021-03-16 08:25:52 UTC (rev 274469)
@@ -1,3 +1,33 @@
+2021-03-16 Youenn Fablet <[email protected]>
+
+ Add a new delegate for geolocation permission
+ https://bugs.webkit.org/show_bug.cgi?id=223183
+
+ Reviewed by Eric Carlson.
+
+ Refactoring to reuse media capture prompt for geolocation with updated prompt strings.
+ Introduce a new permission delegate for geolocation which provides both the top level origin as well as frame info.
+ The decision handler can get grant, deny or prompt.
+ In case of prompt, we use the updated prompt to get grant or deny decision from the user.
+
+ * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+ * UIProcess/Cocoa/MediaPermissionUtilities.mm:
+ (WebKit::alertMessageText):
+ (WebKit::allowButtonText):
+ (WebKit::doNotAllowButtonText):
+ (WebKit::alertForPermission):
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::setDelegate):
+ (WebKit::UIDelegate::UIClient::decidePolicyForGeolocationPermissionRequest):
+ * UIProcess/MediaPermissionUtilities.h:
+ * UIProcess/SpeechRecognitionPermissionManager.cpp:
+ (WebKit::SpeechRecognitionPermissionManager::decideByDefaultAction):
+ * UIProcess/UserMediaPermissionRequestProxy.cpp:
+ (WebKit::UserMediaPermissionRequestProxy::prompt):
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::requestGeolocationPermissionForFrame):
+
2021-03-15 Chris Dumez <[email protected]>
Unreviewed, revert r272629 as it caused regressions in some apps
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2021-03-16 08:25:52 UTC (rev 274469)
@@ -130,6 +130,7 @@
- (WKDragDestinationAction)_webView:(WKWebView *)webView dragDestinationActionMaskForDraggingInfo:(id)draggingInfo WK_API_AVAILABLE(macos(10.13), ios(11.0));
- (void)_webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures completionHandler:(void (^)(WKWebView *webView))completionHandler WK_API_AVAILABLE(macos(10.13), ios(11.0));
- (void)_webView:(WKWebView *)webView requestGeolocationPermissionForFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL allowed))decisionHandler WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
+- (void)_webView:(WKWebView *)webView requestGeolocationPermissionForOrigin:(WKSecurityOrigin*)origin initiatedByFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(_WKPermissionDecision decision))decisionHandler WK_API_AVAILABLE(macos(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(macos(10.13), ios(11.0));
- (void)_webView:(WKWebView *)webView editorStateDidChange:(NSDictionary *)editorState WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
Modified: trunk/Source/WebKit/UIProcess/Cocoa/MediaPermissionUtilities.mm (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/Cocoa/MediaPermissionUtilities.mm 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/Cocoa/MediaPermissionUtilities.mm 2021-03-16 08:25:52 UTC (rev 274469)
@@ -117,7 +117,7 @@
return startsWithLettersIgnoringASCIICase(domain, "www.") ? domain.substring(4) : domain;
}
-static NSString *alertMessageText(MediaPermissionReason reason, OptionSet<MediaPermissionType> types, const WebCore::SecurityOriginData& origin)
+static NSString *alertMessageText(MediaPermissionReason reason, const WebCore::SecurityOriginData& origin)
{
NSString *visibleOrigin;
if (origin.protocol != "http" && origin.protocol != "https") {
@@ -129,14 +129,14 @@
visibleOrigin = visibleDomain(origin.host);
switch (reason) {
- case MediaPermissionReason::UserMedia:
- if (types.contains(MediaPermissionType::Audio) && types.contains(MediaPermissionType::Video))
- return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your camera and microphone?", @"Message for user media prompt"), visibleOrigin];
- if (types.contains(MediaPermissionType::Audio))
- return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your microphone?", @"Message for user microphone access prompt"), visibleOrigin];
- if (types.contains(MediaPermissionType::Video))
- return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your camera?", @"Message for user camera access prompt"), visibleOrigin];
- return nil;
+ case MediaPermissionReason::Camera:
+ return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your camera?", @"Message for user camera access prompt"), visibleOrigin];
+ case MediaPermissionReason::CameraAndMicrophone:
+ return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your camera and microphone?", @"Message for user media prompt"), visibleOrigin];
+ case MediaPermissionReason::Microphone:
+ return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your microphone?", @"Message for user microphone access prompt"), visibleOrigin];
+ case MediaPermissionReason::Geolocation:
+ return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your current location?", @"Message for geolocation prompt"), visibleDomain(origin.host)];
case MediaPermissionReason::SpeechRecognition:
return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to capture your audio and use it for speech recognition?", @"Message for spechrecognition prompt"), visibleDomain(origin.host)];
}
@@ -145,8 +145,12 @@
static NSString *allowButtonText(MediaPermissionReason reason)
{
switch (reason) {
- case MediaPermissionReason::UserMedia:
+ case MediaPermissionReason::Camera:
+ case MediaPermissionReason::CameraAndMicrophone:
+ case MediaPermissionReason::Microphone:
return WEB_UI_STRING_KEY(@"Allow", "Allow (usermedia)", @"Allow button title in user media prompt");
+ case MediaPermissionReason::Geolocation:
+ return WEB_UI_STRING_KEY(@"Allow", "Allow (geolocation)", @"Allow button title in geolocation prompt");
case MediaPermissionReason::SpeechRecognition:
return WEB_UI_STRING_KEY(@"Allow", "Allow (speechrecognition)", @"Allow button title in speech recognition prompt");
}
@@ -155,14 +159,18 @@
static NSString *doNotAllowButtonText(MediaPermissionReason reason)
{
switch (reason) {
- case MediaPermissionReason::UserMedia:
+ case MediaPermissionReason::Camera:
+ case MediaPermissionReason::CameraAndMicrophone:
+ case MediaPermissionReason::Microphone:
return WEB_UI_STRING_KEY(@"Don’t Allow", "Don’t Allow (usermedia)", @"Disallow button title in user media prompt");
+ case MediaPermissionReason::Geolocation:
+ return WEB_UI_STRING_KEY(@"Don’t Allow", "Don’t Allow (geolocation)", @"Disallow button title in geolocation prompt");
case MediaPermissionReason::SpeechRecognition:
return WEB_UI_STRING_KEY(@"Don’t Allow", "Don’t Allow (speechrecognition)", @"Disallow button title in speech recognition prompt");
}
}
-void alertForPermission(WebPageProxy& page, MediaPermissionReason reason, OptionSet<MediaPermissionType> types, const WebCore::SecurityOriginData& origin, CompletionHandler<void(bool)>&& completionHandler)
+void alertForPermission(WebPageProxy& page, MediaPermissionReason reason, const WebCore::SecurityOriginData& origin, CompletionHandler<void(bool)>&& completionHandler)
{
auto *webView = fromWebPageProxy(page);
if (!webView) {
@@ -170,7 +178,7 @@
return;
}
- auto *alertTitle = alertMessageText(reason, types, origin);
+ auto *alertTitle = alertMessageText(reason, origin);
if (!alertTitle) {
completionHandler(false);
return;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2021-03-16 08:25:52 UTC (rev 274469)
@@ -181,6 +181,7 @@
bool webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler : 1;
bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
+ bool webViewRequestGeolocationPermissionForOriginDecisionHandler : 1;
bool webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo : 1;
bool webViewTakeFocus : 1;
bool webViewHandleAutoplayEventWithFlags : 1;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2021-03-16 08:25:52 UTC (rev 274469)
@@ -31,6 +31,7 @@
#import "APIHitTestResult.h"
#import "APIInspectorConfiguration.h"
#import "CompletionHandlerCallChecker.h"
+#import "MediaPermissionUtilities.h"
#import "MediaUtilities.h"
#import "NativeWebWheelEvent.h"
#import "NavigationActionData.h"
@@ -61,7 +62,7 @@
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import <WebCore/FontAttributes.h>
-#import <WebCore/SecurityOriginData.h>
+#import <WebCore/SecurityOrigin.h>
#import <wtf/BlockPtr.h>
#import <wtf/URL.h>
@@ -106,6 +107,7 @@
m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
m_delegateMethods.webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler = [delegate respondsToSelector:@selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:)];
m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
+ m_delegateMethods.webViewRequestGeolocationPermissionForOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForOrigin:initiatedByFrame:decisionHandler:)];
m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)];
m_delegateMethods.webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo = [delegate respondsToSelector:@selector(_webView:didResignInputElementStrongPasswordAppearanceWithUserInfo:)];
m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
@@ -400,16 +402,40 @@
void UIDelegate::UIClient::decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy& page, WebKit::WebFrameProxy& frame, const FrameInfoData& frameInfo, Function<void(bool)>& completionHandler)
{
- if (!m_uiDelegate)
+ if (!m_uiDelegate || (!m_uiDelegate->m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler && !m_uiDelegate->m_delegateMethods.webViewRequestGeolocationPermissionForOriginDecisionHandler))
return;
- if (!m_uiDelegate->m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler)
- return;
-
auto delegate = m_uiDelegate->m_delegate.get();
if (!delegate)
return;
+ if (m_uiDelegate->m_delegateMethods.webViewRequestGeolocationPermissionForOriginDecisionHandler) {
+ auto securityOrigin = WebCore::SecurityOrigin::createFromString(page.pageLoadState().activeURL());
+ auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestGeolocationPermissionForOrigin:initiatedByFrame:decisionHandler:));
+ auto decisionHandler = makeBlockPtr([completionHandler = std::exchange(completionHandler, nullptr), securityOrigin = securityOrigin->data(), checker = WTFMove(checker), page = makeWeakPtr(page)] (_WKPermissionDecision decision) mutable {
+ if (checker->completionHandlerHasBeenCalled())
+ return;
+ checker->didCallCompletionHandler();
+ if (!page) {
+ completionHandler(false);
+ return;
+ }
+ switch (decision) {
+ case _WKPermissionDecisionPrompt:
+ alertForPermission(*page, MediaPermissionReason::Geolocation, securityOrigin, WTFMove(completionHandler));
+ break;
+ case _WKPermissionDecisionGrant:
+ completionHandler(true);
+ break;
+ case _WKPermissionDecisionDeny:
+ completionHandler(false);
+ break;
+ }
+ });
+ [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestGeolocationPermissionForOrigin:wrapper(API::SecurityOrigin::create(securityOrigin.get())) initiatedByFrame:wrapper(API::FrameInfo::create(FrameInfoData { frameInfo }, &page)) decisionHandler:decisionHandler.get()];
+ return;
+ }
+
auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:));
[(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestGeolocationPermissionForFrame:wrapper(API::FrameInfo::create(FrameInfoData { frameInfo }, &page)) decisionHandler:makeBlockPtr([completionHandler = std::exchange(completionHandler, nullptr), checker = WTFMove(checker)] (BOOL result) mutable {
if (checker->completionHandlerHasBeenCalled())
Modified: trunk/Source/WebKit/UIProcess/MediaPermissionUtilities.h (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/MediaPermissionUtilities.h 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/MediaPermissionUtilities.h 2021-03-16 08:25:52 UTC (rev 274469)
@@ -49,8 +49,11 @@
};
enum class MediaPermissionReason {
- UserMedia,
- SpeechRecognition,
+ Camera,
+ CameraAndMicrophone,
+ Microphone,
+ Geolocation,
+ SpeechRecognition
};
#if PLATFORM(COCOA)
@@ -58,7 +61,7 @@
bool checkUsageDescriptionStringForType(MediaPermissionType);
bool checkUsageDescriptionStringForSpeechRecognition();
-void alertForPermission(WebPageProxy&, MediaPermissionReason, OptionSet<MediaPermissionType>, const WebCore::SecurityOriginData&, CompletionHandler<void(bool)>&&);
+void alertForPermission(WebPageProxy&, MediaPermissionReason, const WebCore::SecurityOriginData&, CompletionHandler<void(bool)>&&);
#endif
#if HAVE(AVCAPTUREDEVICE)
Modified: trunk/Source/WebKit/UIProcess/SpeechRecognitionPermissionManager.cpp (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/SpeechRecognitionPermissionManager.cpp 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/SpeechRecognitionPermissionManager.cpp 2021-03-16 08:25:52 UTC (rev 274469)
@@ -243,8 +243,7 @@
void SpeechRecognitionPermissionManager::decideByDefaultAction(const WebCore::SecurityOriginData& origin, CompletionHandler<void(bool)>&& completionHandler)
{
#if PLATFORM(COCOA)
- OptionSet<MediaPermissionType> type = MediaPermissionType::Audio;
- alertForPermission(m_page, MediaPermissionReason::SpeechRecognition, type, origin, WTFMove(completionHandler));
+ alertForPermission(m_page, MediaPermissionReason::SpeechRecognition, origin, WTFMove(completionHandler));
#else
completionHandler(false);
#endif
Modified: trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.cpp (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.cpp 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.cpp 2021-03-16 08:25:52 UTC (rev 274469)
@@ -155,12 +155,10 @@
return;
}
- OptionSet<MediaPermissionType> requestedTypes;
+ MediaPermissionReason reason = MediaPermissionReason::Camera;
if (requiresAudioCapture())
- requestedTypes.add(MediaPermissionType::Audio);
- if (requiresVideoCapture())
- requestedTypes.add(MediaPermissionType::Video);
- alertForPermission(m_manager->page(), MediaPermissionReason::UserMedia, requestedTypes, topLevelDocumentSecurityOrigin().data(), [this, protectedThis = makeRef(*this)](bool granted) {
+ reason = requiresVideoCapture() ? MediaPermissionReason::CameraAndMicrophone : MediaPermissionReason::Microphone;
+ alertForPermission(m_manager->page(), reason, topLevelDocumentSecurityOrigin().data(), [this, protectedThis = makeRef(*this)](bool granted) {
if (!granted)
deny(UserMediaAccessDenialReason::PermissionDenied);
else
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (274468 => 274469)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2021-03-16 08:25:52 UTC (rev 274469)
@@ -8081,8 +8081,6 @@
auto* frame = m_process->webFrame(*frameInfo.frameID);
MESSAGE_CHECK(m_process, frame);
- // FIXME: Geolocation should probably be using toString() as its string representation instead of databaseIdentifier().
- auto origin = API::SecurityOrigin::create(frameInfo.securityOrigin.securityOrigin());
auto request = m_geolocationPermissionRequestManager.createRequest(geolocationID);
Function<void(bool)> completionHandler = [request = WTFMove(request)](bool allowed) {
if (allowed)
Modified: trunk/Tools/ChangeLog (274468 => 274469)
--- trunk/Tools/ChangeLog 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Tools/ChangeLog 2021-03-16 08:25:52 UTC (rev 274469)
@@ -1,3 +1,17 @@
+2021-03-16 Youenn Fablet <[email protected]>
+
+ Add a new delegate for geolocation permission
+ https://bugs.webkit.org/show_bug.cgi?id=223183
+
+ Reviewed by Eric Carlson.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+ (-[GeolocationDelegateNew _webView:requestGeolocationPermissionForOrigin:initiatedByFrame:decisionHandler:]):
+ (testDidResignInputElementStrongPasswordAppearanceAfterEvaluatingJavaScript): Deleted.
+ (tabEvent): Deleted.
+ (synthesizeTab): Deleted.
+ (synthesizeWheelEvents): Deleted.
+
2021-03-15 Alex Christensen <[email protected]>
REGRESSION: (r255611) [ Mac ] 3 lldb tests failing related to HashMap
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm (274468 => 274469)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm 2021-03-16 08:07:55 UTC (rev 274468)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm 2021-03-16 08:25:52 UTC (rev 274469)
@@ -25,7 +25,9 @@
#import "config.h"
+#import "HTTPServer.h"
#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
#import "Utilities.h"
#import "WKWebViewConfigurationExtras.h"
@@ -170,6 +172,75 @@
TestWebKitAPI::Util::run(&done);
}
+@interface GeolocationDelegateNew : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation GeolocationDelegateNew
+- (void)_webView:(WKWebView *)webView requestGeolocationPermissionForOrigin:(WKSecurityOrigin*)origin initiatedByFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(_WKPermissionDecision decision))decisionHandler {
+ EXPECT_WK_STREQ(origin.protocol, @"https");
+ EXPECT_WK_STREQ(origin.host, @"127.0.0.1");
+ EXPECT_EQ(origin.port, 9090);
+
+ EXPECT_WK_STREQ(frame.securityOrigin.protocol, @"https");
+ EXPECT_WK_STREQ(frame.securityOrigin.host, @"127.0.0.1");
+ EXPECT_EQ(frame.securityOrigin.port, 9091);
+ EXPECT_FALSE(frame.isMainFrame);
+ EXPECT_TRUE(frame.webView == webView);
+
+ done = true;
+ decisionHandler(_WKPermissionDecisionGrant);
+}
+@end
+
+static const char* mainFrameText = R"DOCDOCDOC(
+<html><body>
+<iframe src='' allow='camera:https://127.0.0.1:9091'></iframe>
+</body></html>
+)DOCDOCDOC";
+static const char* frameText = R"DOCDOCDOC(
+<html><body><script>
+navigator.geolocation.getCurrentPosition(() => { });
+</script></body></html>
+)DOCDOCDOC";
+
+TEST(WebKit, GeolocationPermissionInIFrame)
+{
+ TestWebKitAPI::HTTPServer server1({
+ { "/", { mainFrameText } }
+ }, TestWebKitAPI::HTTPServer::Protocol::Https, nullptr, nullptr, 9090);
+
+ TestWebKitAPI::HTTPServer server2({
+ { "/frame", { frameText } },
+ }, TestWebKitAPI::HTTPServer::Protocol::Https, nullptr, nullptr, 9091);
+
+ 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 delegate = adoptNS([[GeolocationDelegateNew alloc] init]);
+ [webView setUIDelegate:delegate.get()];
+
+ auto navigationDelegate = adoptNS([TestNavigationDelegate new]);
+ [navigationDelegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^callback)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
+ EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);
+ callback(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
+ }];
+ webView.get().navigationDelegate = navigationDelegate.get();
+
+ [webView loadRequest:server1.request()];
+ TestWebKitAPI::Util::run(&done);
+}
+
@interface InjectedBundleNodeHandleIsSelectElementDelegate : NSObject <WKUIDelegatePrivate>
@end