Changeset 215246 in webkit


Ignore:
Timestamp:
Apr 11, 2017 11:43:46 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add SPI for handling geolocation authorization requests
https://bugs.webkit.org/show_bug.cgi?id=170362
rdar://problem/17508627

Patch by David Quesada <david_quesada@apple.com> on 2017-04-11
Reviewed by Alex Christensen.

Source/WebKit2:

Add a new WKUIDelegate method for the WKGeolocationProviderIOS to call when a web page
requests geolocation access. To support testing this change, make it possible to override
the CoreLocation abstraction WKGeolocationProviderIOS uses. There is now a configurable
object on the process pool that implements a protocol for providing location updates for
web views in the process pool. If the client doesn't provide this object,
WKGeolocationProviderIOS falls back to an object that wraps the existing WebKit1
WebGeolocationCoreLocationProvider and conforms to the new protocol.

  • Shared/Cocoa/APIObject.mm:

(API::Object::newObject):

  • Shared/WebGeolocationPosition.h:

(WebKit::WebGeolocationPosition::create):

  • UIProcess/API/C/WKGeolocationPosition.cpp:

(WKGeolocationPositionCreate_b):

  • UIProcess/API/Cocoa/WKProcessPool.mm:

(-[WKProcessPool _coreLocationProvider]):
(-[WKProcessPool _setCoreLocationProvider:]):

  • UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/API/Cocoa/_WKGeolocationCoreLocationProvider.h: Copied from Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp.
  • UIProcess/API/Cocoa/_WKGeolocationPosition.h: Copied from Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp.
  • UIProcess/API/Cocoa/_WKGeolocationPosition.mm: Added.

(WebKit::if):
(-[_WKGeolocationPosition dealloc]):
(-[_WKGeolocationPosition _apiObject]):

  • UIProcess/API/Cocoa/_WKGeolocationPositionInternal.h: Copied from Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp.

(WebKit::wrapper):

  • UIProcess/ios/WKGeolocationProviderIOS.mm:

(kit):
(-[WKGeolocationProviderIOS initWithProcessPool:]):
(-[WKGeolocationProviderIOS geolocationAuthorizationGranted]):
(-[WKGeolocationProviderIOS positionChanged:]):
(-[WKLegacyCoreLocationProvider setListener:]):
(-[WKLegacyCoreLocationProvider requestGeolocationAuthorization]):
(-[WKLegacyCoreLocationProvider start]):
(-[WKLegacyCoreLocationProvider stop]):
(-[WKLegacyCoreLocationProvider setEnableHighAccuracy:]):
(-[WKLegacyCoreLocationProvider geolocationAuthorizationGranted]):
(-[WKLegacyCoreLocationProvider geolocationAuthorizationDenied]):
(-[WKLegacyCoreLocationProvider positionChanged:]):
(-[WKLegacyCoreLocationProvider errorOccurred:]):
(-[WKLegacyCoreLocationProvider resetGeolocation]):
Implement a new class that bridges the currently used WebGeolocationCoreLocationProvider
to conform to the _WKGeolocationCoreLocationProvider protocol that WKGeolocationProviderIOS
expects.

  • WebKit2.xcodeproj/project.pbxproj:

Tools:

Add API tests for the new WKUIDelegate SPI for allowing or denying websites permission
to use geolocation. Adopt the new WKProcessPool._coreLocationProvider property to
provide a stub object to simulate the various configurations of geolocation permissions:

  1. The app doesn't have permission to use geolocation.
  2. The app is allowed to use geolocation, but the UI delegate denies the web view permission.
  3. The app is allowed to use geolocation, and the UI delegate allows the web view permission.
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2Cocoa/Geolocation.mm: Added.

(-[TestCoreLocationProvider setListener:]):
(-[TestCoreLocationProvider requestGeolocationAuthorization]):
(-[TestCoreLocationProvider start]):
(-[TestCoreLocationProvider stop]):
(-[TestCoreLocationProvider setEnableHighAccuracy:]):
(expectException):
(-[GeolocationTestUIDelegate _webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:]):
(-[GeolocationTestUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKit2Cocoa/GeolocationGetCurrentPositionResult.html: Added.
Location:
trunk
Files:
3 added
11 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r215242 r215246  
     12017-04-11  David Quesada  <david_quesada@apple.com>
     2
     3        Add SPI for handling geolocation authorization requests
     4        https://bugs.webkit.org/show_bug.cgi?id=170362
     5        rdar://problem/17508627
     6
     7        Reviewed by Alex Christensen.
     8
     9        Add a new WKUIDelegate method for the WKGeolocationProviderIOS to call when a web page
     10        requests geolocation access. To support testing this change, make it possible to override
     11        the CoreLocation abstraction WKGeolocationProviderIOS uses. There is now a configurable
     12        object on the process pool that implements a protocol for providing location updates for
     13        web views in the process pool. If the client doesn't provide this object,
     14        WKGeolocationProviderIOS falls back to an object that wraps the existing WebKit1
     15        WebGeolocationCoreLocationProvider and conforms to the new protocol.
     16
     17        * Shared/Cocoa/APIObject.mm:
     18        (API::Object::newObject):
     19        * Shared/WebGeolocationPosition.h:
     20        (WebKit::WebGeolocationPosition::create):
     21        * UIProcess/API/C/WKGeolocationPosition.cpp:
     22        (WKGeolocationPositionCreate_b):
     23        * UIProcess/API/Cocoa/WKProcessPool.mm:
     24        (-[WKProcessPool _coreLocationProvider]):
     25        (-[WKProcessPool _setCoreLocationProvider:]):
     26        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
     27        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     28        * UIProcess/API/Cocoa/_WKGeolocationCoreLocationProvider.h: Copied from Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp.
     29        * UIProcess/API/Cocoa/_WKGeolocationPosition.h: Copied from Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp.
     30        * UIProcess/API/Cocoa/_WKGeolocationPosition.mm: Added.
     31        (WebKit::if):
     32        (-[_WKGeolocationPosition dealloc]):
     33        (-[_WKGeolocationPosition _apiObject]):
     34        * UIProcess/API/Cocoa/_WKGeolocationPositionInternal.h: Copied from Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp.
     35        (WebKit::wrapper):
     36        * UIProcess/ios/WKGeolocationProviderIOS.mm:
     37        (kit):
     38        (-[WKGeolocationProviderIOS initWithProcessPool:]):
     39        (-[WKGeolocationProviderIOS geolocationAuthorizationGranted]):
     40        (-[WKGeolocationProviderIOS positionChanged:]):
     41        (-[WKLegacyCoreLocationProvider setListener:]):
     42        (-[WKLegacyCoreLocationProvider requestGeolocationAuthorization]):
     43        (-[WKLegacyCoreLocationProvider start]):
     44        (-[WKLegacyCoreLocationProvider stop]):
     45        (-[WKLegacyCoreLocationProvider setEnableHighAccuracy:]):
     46        (-[WKLegacyCoreLocationProvider geolocationAuthorizationGranted]):
     47        (-[WKLegacyCoreLocationProvider geolocationAuthorizationDenied]):
     48        (-[WKLegacyCoreLocationProvider positionChanged:]):
     49        (-[WKLegacyCoreLocationProvider errorOccurred:]):
     50        (-[WKLegacyCoreLocationProvider resetGeolocation]):
     51        Implement a new class that bridges the currently used WebGeolocationCoreLocationProvider
     52        to conform to the _WKGeolocationCoreLocationProvider protocol that WKGeolocationProviderIOS
     53        expects.
     54        * WebKit2.xcodeproj/project.pbxproj:
     55
    1562017-04-11  Eric Carlson  <eric.carlson@apple.com>
    257
  • trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm

    r213947 r215246  
    7373#import "_WKExperimentalFeatureInternal.h"
    7474#import "_WKFrameHandleInternal.h"
     75#import "_WKGeolocationPositionInternal.h"
    7576#import "_WKHitTestResultInternal.h"
    7677#import "_WKProcessPoolConfigurationInternal.h"
     
    180181        break;
    181182
     183#if PLATFORM(IOS)
     184    case Type::GeolocationPosition:
     185        wrapper = [_WKGeolocationPosition alloc];
     186        break;
     187#endif
     188
    182189    case Type::HTTPCookieStore:
    183190        wrapper = [WKHTTPCookieStore alloc];
  • trunk/Source/WebKit2/Shared/WebGeolocationPosition.h

    r204668 r215246  
    5959    };
    6060
    61     static PassRefPtr<WebGeolocationPosition> create(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
     61    static Ref<WebGeolocationPosition> create(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
    6262    {
    63         return adoptRef(new WebGeolocationPosition(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed));
     63        return adoptRef(*new WebGeolocationPosition(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed));
    6464    }
    6565
  • trunk/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp

    r202242 r215246  
    4545{
    4646    auto position = WebGeolocationPosition::create(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
    47     return toAPI(position.leakRef());
     47    return toAPI(&position.leakRef());
    4848}
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm

    r213877 r215246  
    6262#if PLATFORM(IOS)
    6363    RetainPtr<WKGeolocationProviderIOS> _geolocationProvider;
     64    RetainPtr<id <_WKGeolocationCoreLocationProvider>> _coreLocationProvider;
    6465#endif // PLATFORM(IOS)
    6566}
     
    309310}
    310311
     312#if PLATFORM(IOS)
     313- (id <_WKGeolocationCoreLocationProvider>)_coreLocationProvider
     314{
     315    return _coreLocationProvider.get();
     316}
     317
     318- (void)_setCoreLocationProvider:(id<_WKGeolocationCoreLocationProvider>)coreLocationProvider
     319{
     320    if (_geolocationProvider)
     321        [NSException raise:NSGenericException format:@"Changing the location provider is not supported after a web view in the process pool has begun servicing geolocation requests."];
     322
     323    _coreLocationProvider = coreLocationProvider;
     324}
     325#endif // PLATFORM(IOS)
     326
    311327@end
    312328
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h

    r205559 r215246  
    3232@protocol _WKAutomationDelegate;
    3333@protocol _WKDownloadDelegate;
     34@protocol _WKGeolocationCoreLocationProvider;
    3435
    3536@interface WKProcessPool ()
     
    5556@property (nonatomic, weak, setter=_setAutomationDelegate:) id <_WKAutomationDelegate> _automationDelegate WK_API_AVAILABLE(macosx(10.12), ios(10.0));
    5657
     58#if TARGET_OS_IPHONE
     59@property (nonatomic, setter=_setCoreLocationProvider:) id <_WKGeolocationCoreLocationProvider> _coreLocationProvider WK_API_AVAILABLE(ios(WK_IOS_TBA));
     60#endif
     61
    5762+ (NSURL *)_websiteDataURLForContainerWithURL:(NSURL *)containerURL;
    5863+ (NSURL *)_websiteDataURLForContainerWithURL:(NSURL *)containerURL bundleIdentifierIfNotInContainer:(NSString *)bundleIdentifier;
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r214440 r215246  
    3636@class UIScrollView;
    3737@class UIViewController;
     38@class WKFrameInfo;
    3839@class _WKContextMenuElementInfo;
    3940@class _WKActivatedElementInfo;
     
    7374- (void)_webView:(WKWebView *)webView didNotHandleTapAsClickAtPoint:(CGPoint)point;
    7475- (BOOL)_webView:(WKWebView *)webView shouldRequestGeolocationAuthorizationForURL:(NSURL *)url isMainFrame:(BOOL)isMainFrame mainFrameURL:(NSURL *)mainFrameURL;
     76- (void)_webView:(WKWebView *)webView requestGeolocationAuthorizationForURL:(NSURL *)url frame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL authorized))decisionHandler WK_API_AVAILABLE(ios(WK_IOS_TBA));
    7577- (UIViewController *)_webView:(WKWebView *)webView previewViewControllerForURL:(NSURL *)url WK_API_AVAILABLE(ios(9.0));
    7678- (void)_webView:(WKWebView *)webView commitPreviewedViewController:(UIViewController *)previewedViewController WK_API_AVAILABLE(ios(9.0));
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKGeolocationCoreLocationProvider.h

    r215245 r215246  
    11/*
    2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
    27 #include "WKGeolocationPosition.h"
     26#import <WebKit/WKFoundation.h>
    2827
    29 #include "WKAPICast.h"
    30 #include "WebGeolocationPosition.h"
     28#if WK_API_ENABLED && TARGET_OS_IPHONE
    3129
    32 using namespace WebKit;
     30#import <Foundation/NSObject.h>
    3331
    34 WKTypeID WKGeolocationPositionGetTypeID()
    35 {
    36     return toAPI(WebGeolocationPosition::APIType);
    37 }
     32NS_ASSUME_NONNULL_BEGIN
    3833
    39 WKGeolocationPositionRef WKGeolocationPositionCreate(double timestamp, double latitude, double longitude, double accuracy)
    40 {
    41     return WKGeolocationPositionCreate_b(timestamp, latitude, longitude, accuracy, false, 0., false, 0., false, 0., false, 0.);
    42 }
     34@class _WKGeolocationPosition;
    4335
    44 WKGeolocationPositionRef WKGeolocationPositionCreate_b(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
    45 {
    46     auto position = WebGeolocationPosition::create(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
    47     return toAPI(position.leakRef());
    48 }
     36@protocol _WKGeolocationCoreLocationListener <NSObject>
     37- (void)geolocationAuthorizationGranted;
     38- (void)geolocationAuthorizationDenied;
     39- (void)positionChanged:(_WKGeolocationPosition *)position;
     40- (void)errorOccurred:(NSString *)errorMessage;
     41- (void)resetGeolocation;
     42@end
     43
     44@protocol _WKGeolocationCoreLocationProvider <NSObject>
     45- (void)setListener:(id <_WKGeolocationCoreLocationListener>)listener;
     46- (void)requestGeolocationAuthorization;
     47- (void)start;
     48- (void)stop;
     49- (void)setEnableHighAccuracy:(BOOL)flag;
     50@end
     51
     52NS_ASSUME_NONNULL_END
     53
     54#endif // WK_API_ENABLED && TARGET_OS_IPHONE
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKGeolocationPosition.h

    r215245 r215246  
    11/*
    2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
    27 #include "WKGeolocationPosition.h"
     26#import <WebKit/WKFoundation.h>
    2827
    29 #include "WKAPICast.h"
    30 #include "WebGeolocationPosition.h"
     28#if WK_API_ENABLED && TARGET_OS_IPHONE
    3129
    32 using namespace WebKit;
     30#import <Foundation/Foundation.h>
    3331
    34 WKTypeID WKGeolocationPositionGetTypeID()
    35 {
    36     return toAPI(WebGeolocationPosition::APIType);
    37 }
     32@class CLLocation;
    3833
    39 WKGeolocationPositionRef WKGeolocationPositionCreate(double timestamp, double latitude, double longitude, double accuracy)
    40 {
    41     return WKGeolocationPositionCreate_b(timestamp, latitude, longitude, accuracy, false, 0., false, 0., false, 0., false, 0.);
    42 }
     34NS_ASSUME_NONNULL_BEGIN
    4335
    44 WKGeolocationPositionRef WKGeolocationPositionCreate_b(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
    45 {
    46     auto position = WebGeolocationPosition::create(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
    47     return toAPI(position.leakRef());
    48 }
     36WK_CLASS_AVAILABLE(ios(WK_IOS_TBA))
     37@interface _WKGeolocationPosition : NSObject
     38
     39+ (instancetype)positionWithLocation:(CLLocation *)location;
     40
     41@end
     42
     43NS_ASSUME_NONNULL_END
     44
     45#endif // WK_API_ENABLED && TARGET_OS_IPHONE
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKGeolocationPositionInternal.h

    r215245 r215246  
    11/*
    2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
    27 #include "WKGeolocationPosition.h"
     26#import "_WKGeolocationPosition.h"
    2827
    29 #include "WKAPICast.h"
    30 #include "WebGeolocationPosition.h"
     28#if WK_API_ENABLED && TARGET_OS_IPHONE
    3129
    32 using namespace WebKit;
     30#import "WebGeolocationPosition.h"
    3331
    34 WKTypeID WKGeolocationPositionGetTypeID()
     32namespace WebKit {
     33
     34inline _WKGeolocationPosition *wrapper(WebKit::WebGeolocationPosition &position)
    3535{
    36     return toAPI(WebGeolocationPosition::APIType);
     36    ASSERT([position.wrapper() isKindOfClass:[_WKGeolocationPosition class]]);
     37    return (_WKGeolocationPosition *)position.wrapper();
    3738}
    3839
    39 WKGeolocationPositionRef WKGeolocationPositionCreate(double timestamp, double latitude, double longitude, double accuracy)
    40 {
    41     return WKGeolocationPositionCreate_b(timestamp, latitude, longitude, accuracy, false, 0., false, 0., false, 0., false, 0.);
    4240}
    4341
    44 WKGeolocationPositionRef WKGeolocationPositionCreate_b(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
    45 {
    46     auto position = WebGeolocationPosition::create(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
    47     return toAPI(position.leakRef());
     42@interface _WKGeolocationPosition () <WKObject> {
     43@package
     44    API::ObjectStorage<WebKit::WebGeolocationPosition> _geolocationPosition;
    4845}
     46@end
     47
     48#endif // WK_API_ENABLED && TARGET_OS_IPHONE
  • trunk/Source/WebKit2/UIProcess/ios/WKGeolocationProviderIOS.mm

    r208342 r215246  
    2929#if PLATFORM(IOS)
    3030
     31#import "APIFrameInfo.h"
    3132#import "APISecurityOrigin.h"
     33#import "CompletionHandlerCallChecker.h"
    3234#import "GeolocationPermissionRequestProxy.h"
     35#import "WKFrameInfoInternal.h"
     36#import "WKProcessPoolInternal.h"
    3337#import "WKUIDelegatePrivate.h"
    3438#import "WKWebView.h"
    3539#import "WebGeolocationManagerProxy.h"
    3640#import "WebProcessPool.h"
     41#import "_WKGeolocationCoreLocationProvider.h"
     42#import "_WKGeolocationPositionInternal.h"
    3743#import <WebCore/GeolocationPosition.h>
    3844#import <WebCore/URL.h>
    3945#import <WebGeolocationPosition.h>
    4046#import <wtf/Assertions.h>
     47#import <wtf/BlockPtr.h>
    4148#import <wtf/HashSet.h>
    4249#import <wtf/PassRefPtr.h>
     
    5461#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    5562
    56 @interface WKGeolocationProviderIOS (WebGeolocationCoreLocationUpdateListener) <WebGeolocationCoreLocationUpdateListener>
     63@interface WKGeolocationProviderIOS (_WKGeolocationCoreLocationListener) <_WKGeolocationCoreLocationListener>
     64@end
     65
     66@interface WKLegacyCoreLocationProvider : NSObject<_WKGeolocationCoreLocationProvider, WebGeolocationCoreLocationUpdateListener>
    5767@end
    5868
     
    6575void decidePolicyForGeolocationRequestFromOrigin(SecurityOrigin*, const String& urlString, id<WebAllowDenyPolicyListener>, UIWindow*);
    6676};
     77
     78static inline Ref<WebGeolocationPosition> kit(WebCore::GeolocationPosition *position)
     79{
     80    return WebGeolocationPosition::create(position->timestamp(), position->latitude(), position->longitude(), position->accuracy(), position->canProvideAltitude(), position->altitude(), position->canProvideAltitudeAccuracy(), position->altitudeAccuracy(), position->canProvideHeading(), position->heading(), position->canProvideSpeed(), position->speed());
     81}
    6782
    6883struct GeolocationRequestData {
     
    7590@implementation WKGeolocationProviderIOS {
    7691    RefPtr<WebGeolocationManagerProxy> _geolocationManager;
    77     RetainPtr<WebGeolocationCoreLocationProvider> _coreLocationProvider;
     92    RetainPtr<id <_WKGeolocationCoreLocationProvider>> _coreLocationProvider;
    7893    BOOL _isWebCoreGeolocationActive;
    7994    RefPtr<WebGeolocationPosition> _lastActivePosition;
     
    149164    };
    150165    _geolocationManager->initializeProvider(reinterpret_cast<WKGeolocationProviderBase*>(&providerCallback));
    151     _coreLocationProvider = adoptNS([[WebGeolocationCoreLocationProvider alloc] initWithListener:self]);
     166    _coreLocationProvider = wrapper(processPool)._coreLocationProvider ?: adoptNS(static_cast<id <_WKGeolocationCoreLocationProvider>>([[WKLegacyCoreLocationProvider alloc] init]));
     167    [_coreLocationProvider setListener:self];
    152168    return self;
    153169}
     
    178194
    179195        id<WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([request.view UIDelegate]);
     196        if ([uiDelegate respondsToSelector:@selector(_webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:)]) {
     197            URL requestFrameURL(URL(), request.frame->url());
     198            RetainPtr<WKFrameInfo> frameInfo = wrapper(API::FrameInfo::create(*request.frame.get(), *request.origin.get()));
     199            RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:));
     200            [uiDelegate _webView:request.view.get() requestGeolocationAuthorizationForURL:requestFrameURL frame:frameInfo.get() decisionHandler:BlockPtr<void(BOOL)>::fromCallable([request, checker = WTFMove(checker)](BOOL authorized) {
     201                if (checker->completionHandlerHasBeenCalled())
     202                    return;
     203                if (authorized)
     204                    request.permissionRequest->allow();
     205                else
     206                    request.permissionRequest->deny();
     207                checker->didCallCompletionHandler();
     208            }).get()];
     209            return;
     210        }
     211
    180212        if ([uiDelegate respondsToSelector:@selector(_webView:shouldRequestGeolocationAuthorizationForURL:isMainFrame:mainFrameURL:)]) {
    181213            const WebFrameProxy* mainFrame = request.frame->page()->mainFrame();
     
    204236}
    205237
    206 - (void)positionChanged:(GeolocationPosition*)position
    207 {
    208     _lastActivePosition = WebGeolocationPosition::create(position->timestamp(), position->latitude(), position->longitude(), position->accuracy(), position->canProvideAltitude(), position->altitude(), position->canProvideAltitudeAccuracy(), position->altitudeAccuracy(), position->canProvideHeading(), position->heading(), position->canProvideSpeed(), position->speed());
     238- (void)positionChanged:(_WKGeolocationPosition *)position
     239{
     240    _lastActivePosition = position->_geolocationPosition.get();
    209241    _geolocationManager->providerDidChangePosition(_lastActivePosition.get());
    210242}
     
    218250{
    219251    _geolocationManager->resetPermissions();
     252}
     253
     254@end
     255
     256# pragma mark - Implementation of WKLegacyCoreLocationProvider
     257
     258@implementation WKLegacyCoreLocationProvider {
     259    id <_WKGeolocationCoreLocationListener> _listener;
     260    RetainPtr<WebGeolocationCoreLocationProvider> _provider;
     261}
     262
     263// <_WKGeolocationCoreLocationProvider> Methods
     264
     265- (void)setListener:(id<_WKGeolocationCoreLocationListener>)listener
     266{
     267    ASSERT(listener && !_listener && !_provider);
     268    _listener = listener;
     269    _provider = adoptNS([[WebGeolocationCoreLocationProvider alloc] initWithListener:self]);
     270}
     271
     272- (void)requestGeolocationAuthorization
     273{
     274    ASSERT(_provider);
     275    [_provider requestGeolocationAuthorization];
     276}
     277
     278- (void)start
     279{
     280    ASSERT(_provider);
     281    [_provider start];
     282}
     283
     284- (void)stop
     285{
     286    ASSERT(_provider);
     287    [_provider stop];
     288}
     289
     290- (void)setEnableHighAccuracy:(BOOL)flag
     291{
     292    ASSERT(_provider);
     293    [_provider setEnableHighAccuracy:flag];
     294}
     295
     296// <WebGeolocationCoreLocationUpdateListener> Methods
     297
     298- (void)geolocationAuthorizationGranted
     299{
     300    ASSERT(_listener);
     301    [_listener geolocationAuthorizationGranted];
     302}
     303
     304- (void)geolocationAuthorizationDenied
     305{
     306    ASSERT(_listener);
     307    [_listener geolocationAuthorizationDenied];
     308}
     309
     310- (void)positionChanged:(WebCore::GeolocationPosition *)corePosition
     311{
     312    ASSERT(_listener);
     313    auto position = kit(corePosition);
     314    [_listener positionChanged:wrapper(position.get())];
     315}
     316
     317- (void)errorOccurred:(NSString *)errorMessage
     318{
     319    ASSERT(_listener);
     320    [_listener errorOccurred:errorMessage];
     321}
     322
     323- (void)resetGeolocation
     324{
     325    ASSERT(_listener);
     326    [_listener resetGeolocation];
    220327}
    221328
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r214934 r215246  
    11721172                5CE85B201C88E64B0070BFCE /* PingLoad.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CE85B1F1C88E6430070BFCE /* PingLoad.h */; };
    11731173                5CFECB041E1ED1CC00F88504 /* LegacyCustomProtocolManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CFECB031E1ED1C800F88504 /* LegacyCustomProtocolManager.cpp */; };
     1174                636353A51E9858DF0009F8AF /* _WKGeolocationCoreLocationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 63FABE191E970D65003011D5 /* _WKGeolocationCoreLocationProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1175                63C32C251E9810D900699BD0 /* _WKGeolocationPosition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 63C32C231E9810D900699BD0 /* _WKGeolocationPosition.mm */; };
     1176                63C32C261E9810D900699BD0 /* _WKGeolocationPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 63C32C241E9810D900699BD0 /* _WKGeolocationPosition.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1177                63C32C281E98119000699BD0 /* _WKGeolocationPositionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 63C32C271E98119000699BD0 /* _WKGeolocationPositionInternal.h */; };
    11741178                6501BD1A12F1243400E9F248 /* WKBundleInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */; };
    11751179                659C551E130006410025C0C2 /* InjectedBundlePageResourceLoadClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */; };
     
    34323436                5D442A5516D5856700AC3331 /* PluginService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PluginService.entitlements; sourceTree = "<group>"; };
    34333437                5DAD73F1116FF90C00EE5396 /* BaseTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = BaseTarget.xcconfig; sourceTree = "<group>"; };
     3438                63C32C231E9810D900699BD0 /* _WKGeolocationPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKGeolocationPosition.mm; sourceTree = "<group>"; };
     3439                63C32C241E9810D900699BD0 /* _WKGeolocationPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKGeolocationPosition.h; sourceTree = "<group>"; };
     3440                63C32C271E98119000699BD0 /* _WKGeolocationPositionInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKGeolocationPositionInternal.h; sourceTree = "<group>"; };
     3441                63FABE191E970D65003011D5 /* _WKGeolocationCoreLocationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKGeolocationCoreLocationProvider.h; sourceTree = "<group>"; };
    34343442                6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageResourceLoadClient.cpp; sourceTree = "<group>"; };
    34353443                6546A82A13000164000CEB1C /* InjectedBundlePageResourceLoadClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundlePageResourceLoadClient.h; sourceTree = "<group>"; };
     
    55235531                                37A64E5618F38F4600EB30F1 /* _WKFormInputSession.h */,
    55245532                                CD78E1181DB7E5AD0014A2DE /* _WKFullscreenDelegate.h */,
     5533                                63FABE191E970D65003011D5 /* _WKGeolocationCoreLocationProvider.h */,
     5534                                63C32C241E9810D900699BD0 /* _WKGeolocationPosition.h */,
     5535                                63C32C231E9810D900699BD0 /* _WKGeolocationPosition.mm */,
     5536                                63C32C271E98119000699BD0 /* _WKGeolocationPositionInternal.h */,
    55255537                                5143B25E1DDCDFD10014FAC6 /* _WKIconLoadingDelegate.h */,
    55265538                                37A64E5418F38E3C00EB30F1 /* _WKInputDelegate.h */,
     
    80828094                                510F59101DDE296900412FF5 /* _WKIconLoadingDelegate.h in Headers */,
    80838095                                37A64E5518F38E3C00EB30F1 /* _WKInputDelegate.h in Headers */,
     8096                                63C32C281E98119000699BD0 /* _WKGeolocationPositionInternal.h in Headers */,
    80848097                                2D790A9D1AD7050D00AB90B3 /* _WKLayoutMode.h in Headers */,
    80858098                                510F59111DDE297000412FF5 /* _WKLinkIconParameters.h in Headers */,
     
    82788291                                1A1EC69E1872092100B951F0 /* ImportanceAssertion.h in Headers */,
    82798292                                BC204EE311C83E98008F3375 /* InjectedBundle.h in Headers */,
     8293                                636353A51E9858DF0009F8AF /* _WKGeolocationCoreLocationProvider.h in Headers */,
    82808294                                935EEBA2127761D0003322B8 /* InjectedBundleBackForwardList.h in Headers */,
    82818295                                935EEBA4127761D6003322B8 /* InjectedBundleBackForwardListItem.h in Headers */,
     
    87918805                                BC4075F6124FF0270068F20A /* WKCertificateInfo.h in Headers */,
    87928806                                BC407627124FF0400068F20A /* WKCertificateInfoMac.h in Headers */,
     8807                                63C32C261E9810D900699BD0 /* _WKGeolocationPosition.h in Headers */,
    87938808                                BCA284D71492F2C7001F9042 /* WKConnection.h in Headers */,
    87948809                                BC5C75C814954DA600BC4775 /* WKConnectionInternal.h in Headers */,
     
    1032710342                                BCA0EF8012331E78007D3CFB /* WebUndoStep.cpp in Sources */,
    1032810343                                51D124281E6D3F5D002B2820 /* WebURLSchemeHandler.cpp in Sources */,
     10344                                63C32C251E9810D900699BD0 /* _WKGeolocationPosition.mm in Sources */,
    1032910345                                51D124331E6DE6CA002B2820 /* WebURLSchemeHandlerCocoa.mm in Sources */,
    1033010346                                51D1242C1E6D41FD002B2820 /* WebURLSchemeHandlerProxy.cpp in Sources */,
  • trunk/Tools/ChangeLog

    r215243 r215246  
     12017-04-11  David Quesada  <david_quesada@apple.com>
     2
     3        Add SPI for handling geolocation authorization requests
     4        https://bugs.webkit.org/show_bug.cgi?id=170362
     5        rdar://problem/17508627
     6
     7        Reviewed by Alex Christensen.
     8
     9        Add API tests for the new WKUIDelegate SPI for allowing or denying websites permission
     10        to use geolocation. Adopt the new WKProcessPool._coreLocationProvider property to
     11        provide a stub object to simulate the various configurations of geolocation permissions:
     12        1. The app doesn't have permission to use geolocation.
     13        2. The app is allowed to use geolocation, but the UI delegate denies the web view permission.
     14        3. The app is allowed to use geolocation, and the UI delegate allows the web view permission.
     15
     16        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     17        * TestWebKitAPI/Tests/WebKit2Cocoa/Geolocation.mm: Added.
     18        (-[TestCoreLocationProvider setListener:]):
     19        (-[TestCoreLocationProvider requestGeolocationAuthorization]):
     20        (-[TestCoreLocationProvider start]):
     21        (-[TestCoreLocationProvider stop]):
     22        (-[TestCoreLocationProvider setEnableHighAccuracy:]):
     23        (expectException):
     24        (-[GeolocationTestUIDelegate _webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:]):
     25        (-[GeolocationTestUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     26        (TestWebKitAPI::TEST):
     27        * TestWebKitAPI/Tests/WebKit2Cocoa/GeolocationGetCurrentPositionResult.html: Added.
     28
    1292017-04-10  Matt Rajca  <mrajca@apple.com>
    230
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r215243 r215246  
    197197                5CE354D91E70DA5C00BEFE3B /* WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CE354D81E70D9C300BEFE3B /* WKUserContentExtensionStore.mm */; };
    198198                5E4B1D2E1D404C6100053621 /* WKScrollViewDelegateCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E4B1D2C1D404C6100053621 /* WKScrollViewDelegateCrash.mm */; };
     199                631EFFF61E7B5E8D00D2EBB8 /* Geolocation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */; };
     200                634910E01E9D3FF300880309 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 634910DF1E9D3FF300880309 /* CoreLocation.framework */; };
     201                636353A71E98665D0009F8AF /* GeolocationGetCurrentPositionResult.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 636353A61E9861940009F8AF /* GeolocationGetCurrentPositionResult.html */; };
    199202                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
    200203                755A20AF1E6E38630093C69F /* DatabaseTrackerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 755A20AE1E6E38630093C69F /* DatabaseTrackerTest.cpp */; };
     
    670673                                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
    671674                                1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */,
     675                                636353A71E98665D0009F8AF /* GeolocationGetCurrentPositionResult.html in Copy Resources */,
    672676                                C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
    673677                                5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */,
     
    11221126                5CE354D81E70D9C300BEFE3B /* WKUserContentExtensionStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKUserContentExtensionStore.mm; sourceTree = "<group>"; };
    11231127                5E4B1D2C1D404C6100053621 /* WKScrollViewDelegateCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKScrollViewDelegateCrash.mm; path = ../ios/WKScrollViewDelegateCrash.mm; sourceTree = "<group>"; };
     1128                631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Geolocation.mm; sourceTree = "<group>"; };
     1129                634910DF1E9D3FF300880309 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
     1130                636353A61E9861940009F8AF /* GeolocationGetCurrentPositionResult.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = GeolocationGetCurrentPositionResult.html; sourceTree = "<group>"; };
    11241131                755A20AE1E6E38630093C69F /* DatabaseTrackerTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseTrackerTest.cpp; sourceTree = "<group>"; };
    11251132                7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheAddImageToCacheIOS.mm; sourceTree = "<group>"; };
     
    15071514                        buildActionMask = 2147483647;
    15081515                        files = (
     1516                                634910E01E9D3FF300880309 /* CoreLocation.framework in Frameworks */,
    15091517                                7A010BCB1D877C0500EDE72A /* CoreGraphics.framework in Frameworks */,
    15101518                                7C83E03F1D0A61A000FEBCF3 /* libicucore.dylib in Frameworks */,
     
    16461654                                3F1B52681D3D7129008D60C4 /* FullscreenLayoutConstraints.mm */,
    16471655                                CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */,
     1656                                631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */,
    16481657                                510477751D298E03009747EB /* IDBDeleteRecovery.mm */,
    16491658                                5110FCEF1E01CBAA006F8D0B /* IDBIndexUpgradeToV2.mm */,
     
    17881797                        isa = PBXGroup;
    17891798                        children = (
     1799                                634910DF1E9D3FF300880309 /* CoreLocation.framework */,
    17901800                                7A010BCA1D877C0500EDE72A /* CoreGraphics.framework */,
    17911801                                7C83E0331D0A5F2700FEBCF3 /* libicucore.dylib */,
     
    18411851                                3FBD1B491D39D1DB00E6D6FA /* FullscreenLayoutConstraints.html */,
    18421852                                CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */,
     1853                                636353A61E9861940009F8AF /* GeolocationGetCurrentPositionResult.html */,
    18431854                                F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */,
    18441855                                510477761D298E57009747EB /* IDBDeleteRecovery.html */,
     
    27972808                                CDBFCC451A9FF45300A7B691 /* FullscreenZoomInitialFrame.mm in Sources */,
    27982809                                7CCE7EF81A411AE600447C4C /* Geolocation.cpp in Sources */,
     2810                                631EFFF61E7B5E8D00D2EBB8 /* Geolocation.mm in Sources */,
    27992811                                7CCE7EE11A411A9A00447C4C /* GetBackingScaleFactor.mm in Sources */,
    28002812                                7CCE7EF91A411AE600447C4C /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.