Changeset 244600 in webkit


Ignore:
Timestamp:
Apr 24, 2019 12:07:38 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

Clean up WKActionSheetAssistant's use of LaunchServices
https://bugs.webkit.org/show_bug.cgi?id=194645
<rdar://problem/47707952>

Reviewed by Andy Estes.

Source/WebCore/PAL:

  • pal/spi/cocoa/LaunchServicesSPI.h:

Source/WebKit:

  • UIProcess/ios/WKActionSheetAssistant.mm:

(applicationHasAppLinkEntitlements):
(-[WKActionSheetAssistant _appendAppLinkOpenActionsForURL:actions:elementInfo:]):
(-[WKActionSheetAssistant _appendOpenActionsForURL:actions:elementInfo:]):
(appLinkForURL): Deleted.
Make this function much more early-returny and flat.
Adopt LS sync SPI instead of using a semaphore ourselves.
Adopt modern open SPI.

Source/WTF:

  • wtf/Platform.h:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r244582 r244600  
     12019-04-24  Tim Horton  <timothy_horton@apple.com>
     2
     3        Clean up WKActionSheetAssistant's use of LaunchServices
     4        https://bugs.webkit.org/show_bug.cgi?id=194645
     5        <rdar://problem/47707952>
     6
     7        Reviewed by Andy Estes.
     8
     9        * wtf/Platform.h:
     10
    1112019-04-24  chris fleizach  <cfleizach@apple.com>
    212
  • trunk/Source/WTF/wtf/Platform.h

    r244582 r244600  
    15251525
    15261526#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
     1527#define HAVE_APP_LINKS_WITH_ISENABLED 1
    15271528#define HAVE_ROUTE_SHARING_POLICY_LONG_FORM_VIDEO 1
    15281529#endif
  • trunk/Source/WebCore/PAL/ChangeLog

    r244567 r244600  
     12019-04-24  Tim Horton  <timothy_horton@apple.com>
     2
     3        Clean up WKActionSheetAssistant's use of LaunchServices
     4        https://bugs.webkit.org/show_bug.cgi?id=194645
     5        <rdar://problem/47707952>
     6
     7        Reviewed by Andy Estes.
     8
     9        * pal/spi/cocoa/LaunchServicesSPI.h:
     10
    1112019-04-23  Commit Queue  <commit-queue@webkit.org>
    212
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h

    r240211 r244600  
    6161
    6262@interface LSAppLink ()
     63#if HAVE(APP_LINKS_WITH_ISENABLED)
     64+ (NSArray<LSAppLink *> *)appLinksWithURL:(NSURL *)aURL limit:(NSUInteger)limit error:(NSError **)outError;
     65- (void)openWithCompletionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
     66@property (nonatomic, getter=isEnabled) BOOL enabled;
     67#else
    6368+ (void)getAppLinkWithURL:(NSURL *)aURL completionHandler:(LSAppLinkCompletionHandler)completionHandler;
     69- (void)openInWebBrowser:(BOOL)inWebBrowser setAppropriateOpenStrategyAndWebBrowserState:(NSDictionary<NSString *, id> *)state completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
     70#endif
    6471+ (void)openWithURL:(NSURL *)aURL completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
    65 - (void)openInWebBrowser:(BOOL)inWebBrowser setAppropriateOpenStrategyAndWebBrowserState:(NSDictionary<NSString *, id> *)state completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
    6672@property (readonly, strong) LSApplicationProxy *targetApplicationProxy;
    6773@end
  • trunk/Source/WebKit/ChangeLog

    r244599 r244600  
     12019-04-24  Tim Horton  <timothy_horton@apple.com>
     2
     3        Clean up WKActionSheetAssistant's use of LaunchServices
     4        https://bugs.webkit.org/show_bug.cgi?id=194645
     5        <rdar://problem/47707952>
     6
     7        Reviewed by Andy Estes.
     8
     9        * UIProcess/ios/WKActionSheetAssistant.mm:
     10        (applicationHasAppLinkEntitlements):
     11        (-[WKActionSheetAssistant _appendAppLinkOpenActionsForURL:actions:elementInfo:]):
     12        (-[WKActionSheetAssistant _appendOpenActionsForURL:actions:elementInfo:]):
     13        (appLinkForURL): Deleted.
     14        Make this function much more early-returny and flat.
     15        Adopt LS sync SPI instead of using a semaphore ourselves.
     16        Adopt modern open SPI.
     17
    1182019-04-24  Simon Fraser  <simon.fraser@apple.com>
    219
  • trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm

    r244368 r244600  
    7474static LSAppLink *appLinkForURL(NSURL *url)
    7575{
     76#if HAVE(APP_LINKS_WITH_ISENABLED)
     77    NSArray<LSAppLink *> *appLinks = [LSAppLink appLinksWithURL:url limit:1 error:nil];
     78    return appLinks.firstObject;
     79#else
    7680    BinarySemaphore semaphore;
    7781    __block LSAppLink *syncAppLink = nil;
     
    8589
    8690    return [syncAppLink autorelease];
     91#endif
    8792}
    8893#endif
     
    473478}
    474479
     480#if HAVE(APP_LINKS)
     481- (BOOL)_appendAppLinkOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
     482{
     483    ASSERT(_delegate);
     484
     485    if (!applicationHasAppLinkEntitlements() || ![_delegate.get() actionSheetAssistant:self shouldIncludeAppLinkActionsForElement:elementInfo])
     486        return NO;
     487
     488    LSAppLink *appLink = appLinkForURL(url);
     489    if (!appLink)
     490        return NO;
     491
     492    NSString *openInDefaultBrowserTitle = WEB_UI_STRING("Open in Safari", "Title for Open in Safari Link action button");
     493    _WKElementAction *openInDefaultBrowserAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInDefaultBrowser title:openInDefaultBrowserTitle actionHandler:^(_WKActivatedElementInfo *) {
     494#if HAVE(APP_LINKS_WITH_ISENABLED)
     495        appLink.enabled = NO;
     496        [appLink openWithCompletionHandler:nil];
     497#else
     498        [appLink openInWebBrowser:YES setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
     499#endif
     500    }];
     501    [defaultActions addObject:openInDefaultBrowserAction];
     502
     503    NSString *externalApplicationName = [appLink.targetApplicationProxy localizedNameForContext:nil];
     504    if (!externalApplicationName)
     505        return YES;
     506
     507    NSString *openInExternalApplicationTitle = [NSString stringWithFormat:WEB_UI_STRING("Open in “%@”", "Title for Open in External Application Link action button"), externalApplicationName];
     508    _WKElementAction *openInExternalApplicationAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInExternalApplication title:openInExternalApplicationTitle actionHandler:^(_WKActivatedElementInfo *) {
     509#if HAVE(APP_LINKS_WITH_ISENABLED)
     510        appLink.enabled = YES;
     511        [appLink openWithCompletionHandler:nil];
     512#else
     513        [appLink openInWebBrowser:NO setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
     514#endif
     515    }];
     516    [defaultActions addObject:openInExternalApplicationAction];
     517
     518    return YES;
     519}
     520#endif
     521
    475522- (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
    476523{
    477524#if HAVE(APP_LINKS)
    478     ASSERT(_delegate);
    479     if (applicationHasAppLinkEntitlements() && [_delegate.get() actionSheetAssistant:self shouldIncludeAppLinkActionsForElement:elementInfo]) {
    480         LSAppLink *appLink = appLinkForURL(url);
    481         if (appLink) {
    482             NSString *title = WEB_UI_STRING("Open in Safari", "Title for Open in Safari Link action button");
    483             _WKElementAction *openInDefaultBrowserAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInDefaultBrowser title:title actionHandler:^(_WKActivatedElementInfo *) {
    484 #pragma clang diagnostic push
    485 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    486                 [appLink openInWebBrowser:YES setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
    487 #pragma clang diagnostic pop
    488             }];
    489             [defaultActions addObject:openInDefaultBrowserAction];
    490 
    491             NSString *externalApplicationName = [appLink.targetApplicationProxy localizedNameForContext:nil];
    492             if (externalApplicationName) {
    493                 NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Open in “%@”", "Title for Open in External Application Link action button"), externalApplicationName];
    494                 _WKElementAction *openInExternalApplicationAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInExternalApplication title:title actionHandler:^(_WKActivatedElementInfo *) {
    495 #pragma clang diagnostic push
    496 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    497                     [appLink openInWebBrowser:NO setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
    498 #pragma clang diagnostic pop
    499                 }];
    500                 [defaultActions addObject:openInExternalApplicationAction];
    501             }
    502         } else
    503             [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];
    504     } else
    505         [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];
    506 #else
     525    if ([self _appendAppLinkOpenActionsForURL:url actions:defaultActions elementInfo:elementInfo])
     526        return;
     527#endif
     528
    507529    [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];
    508 #endif
    509530}
    510531
Note: See TracChangeset for help on using the changeset viewer.