Clean up WKActionSheetAssistant's use of LaunchServices
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Apr 2019 19:07:38 +0000 (19:07 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Apr 2019 19:07:38 +0000 (19:07 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244600 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm

index 043fcf5..c38d272 100644 (file)
@@ -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
index dea1e3b..5927cef 100644 (file)
 #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
index 4a28ff6..ce265c2 100644 (file)
@@ -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.
index 69ff852..b6bc370 100644 (file)
@@ -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
index 2d97e4d..270eb51 100644 (file)
@@ -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
index 9f4ed92..82d01af 100644 (file)
@@ -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 LSAppLink *appLinkForURL(NSURL *url)
     semaphore.wait();
 
     return [syncAppLink autorelease];
+#endif
 }
 #endif
 
@@ -472,40 +477,56 @@ ALLOW_DEPRECATED_DECLARATIONS_END
     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