Skip to content
Permalink
Browse files
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:


Canonical link: https://commits.webkit.org/211460@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244600 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
hortont424 committed Apr 24, 2019
1 parent 0d5920c commit 68f03c9d83d54add54f7741f0fe0502cfcd18970
Showing 6 changed files with 96 additions and 31 deletions.
@@ -1,3 +1,13 @@
2019-04-24 Tim Horton <timothy_horton@apple.com>

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

Reviewed by Andy Estes.

* wtf/Platform.h:

2019-04-24 chris fleizach <cfleizach@apple.com>

AX: Remove deprecated Accessibility Object Model events
@@ -1524,5 +1524,6 @@
#endif

#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
#define HAVE_APP_LINKS_WITH_ISENABLED 1
#define HAVE_ROUTE_SHARING_POLICY_LONG_FORM_VIDEO 1
#endif
@@ -1,3 +1,13 @@
2019-04-24 Tim Horton <timothy_horton@apple.com>

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

Reviewed by Andy Estes.

* pal/spi/cocoa/LaunchServicesSPI.h:

2019-04-23 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r244556.
@@ -60,9 +60,15 @@ typedef void (^LSAppLinkOpenCompletionHandler)(BOOL success, NSError *error);
@end

@interface LSAppLink ()
#if HAVE(APP_LINKS_WITH_ISENABLED)
+ (NSArray<LSAppLink *> *)appLinksWithURL:(NSURL *)aURL limit:(NSUInteger)limit error:(NSError **)outError;
- (void)openWithCompletionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
@property (nonatomic, getter=isEnabled) BOOL enabled;
#else
+ (void)getAppLinkWithURL:(NSURL *)aURL completionHandler:(LSAppLinkCompletionHandler)completionHandler;
+ (void)openWithURL:(NSURL *)aURL completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
- (void)openInWebBrowser:(BOOL)inWebBrowser setAppropriateOpenStrategyAndWebBrowserState:(NSDictionary<NSString *, id> *)state completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
#endif
+ (void)openWithURL:(NSURL *)aURL completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
@property (readonly, strong) LSApplicationProxy *targetApplicationProxy;
@end
#endif
@@ -1,3 +1,20 @@
2019-04-24 Tim Horton <timothy_horton@apple.com>

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

Reviewed by Andy Estes.

* 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.

2019-04-24 Simon Fraser <simon.fraser@apple.com>

Make it possible to control the renderTreeAsText output by setting options on testRunner
@@ -73,6 +73,10 @@ static bool applicationHasAppLinkEntitlements()

static LSAppLink *appLinkForURL(NSURL *url)
{
#if HAVE(APP_LINKS_WITH_ISENABLED)
NSArray<LSAppLink *> *appLinks = [LSAppLink appLinksWithURL:url limit:1 error:nil];
return appLinks.firstObject;
#else
BinarySemaphore semaphore;
__block LSAppLink *syncAppLink = nil;
__block BinarySemaphore* semaphorePtr = &semaphore;
@@ -84,6 +88,7 @@ static bool applicationHasAppLinkEntitlements()
semaphore.wait();

return [syncAppLink autorelease];
#endif
}
#endif

@@ -472,40 +477,56 @@ - (WKActionSheetPresentationStyle)_presentationStyleForPositionInfo:(const WebKi
return WKActionSheetPresentAtElementRect;
}

- (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
{
#if HAVE(APP_LINKS)
- (BOOL)_appendAppLinkOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
{
ASSERT(_delegate);
if (applicationHasAppLinkEntitlements() && [_delegate.get() actionSheetAssistant:self shouldIncludeAppLinkActionsForElement:elementInfo]) {
LSAppLink *appLink = appLinkForURL(url);
if (appLink) {
NSString *title = WEB_UI_STRING("Open in Safari", "Title for Open in Safari Link action button");
_WKElementAction *openInDefaultBrowserAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInDefaultBrowser title:title actionHandler:^(_WKActivatedElementInfo *) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[appLink openInWebBrowser:YES setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
#pragma clang diagnostic pop
}];
[defaultActions addObject:openInDefaultBrowserAction];

NSString *externalApplicationName = [appLink.targetApplicationProxy localizedNameForContext:nil];
if (externalApplicationName) {
NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Open in “%@”", "Title for Open in External Application Link action button"), externalApplicationName];
_WKElementAction *openInExternalApplicationAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInExternalApplication title:title actionHandler:^(_WKActivatedElementInfo *) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[appLink openInWebBrowser:NO setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
#pragma clang diagnostic pop
}];
[defaultActions addObject:openInExternalApplicationAction];
}
} else
[defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];
} else
[defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];

if (!applicationHasAppLinkEntitlements() || ![_delegate.get() actionSheetAssistant:self shouldIncludeAppLinkActionsForElement:elementInfo])
return NO;

LSAppLink *appLink = appLinkForURL(url);
if (!appLink)
return NO;

NSString *openInDefaultBrowserTitle = WEB_UI_STRING("Open in Safari", "Title for Open in Safari Link action button");
_WKElementAction *openInDefaultBrowserAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInDefaultBrowser title:openInDefaultBrowserTitle actionHandler:^(_WKActivatedElementInfo *) {
#if HAVE(APP_LINKS_WITH_ISENABLED)
appLink.enabled = NO;
[appLink openWithCompletionHandler:nil];
#else
[defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];
[appLink openInWebBrowser:YES setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
#endif
}];
[defaultActions addObject:openInDefaultBrowserAction];

NSString *externalApplicationName = [appLink.targetApplicationProxy localizedNameForContext:nil];
if (!externalApplicationName)
return YES;

NSString *openInExternalApplicationTitle = [NSString stringWithFormat:WEB_UI_STRING("Open in “%@”", "Title for Open in External Application Link action button"), externalApplicationName];
_WKElementAction *openInExternalApplicationAction = [_WKElementAction _elementActionWithType:_WKElementActionTypeOpenInExternalApplication title:openInExternalApplicationTitle actionHandler:^(_WKActivatedElementInfo *) {
#if HAVE(APP_LINKS_WITH_ISENABLED)
appLink.enabled = YES;
[appLink openWithCompletionHandler:nil];
#else
[appLink openInWebBrowser:NO setAppropriateOpenStrategyAndWebBrowserState:nil completionHandler:^(BOOL success, NSError *error) { }];
#endif
}];
[defaultActions addObject:openInExternalApplicationAction];

return YES;
}
#endif

- (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
{
#if HAVE(APP_LINKS)
if ([self _appendAppLinkOpenActionsForURL:url actions:defaultActions elementInfo:elementInfo])
return;
#endif

[defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeOpen assistant:self]];
}

- (RetainPtr<NSArray>)defaultActionsForLinkSheet:(_WKActivatedElementInfo *)elementInfo

0 comments on commit 68f03c9

Please sign in to comment.