<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[248360] branches/safari-608.1-branch/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/248360">248360</a></dd>
<dt>Author</dt> <dd>kocsen_chung@apple.com</dd>
<dt>Date</dt> <dd>2019-08-06 23:53:08 -0700 (Tue, 06 Aug 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/248330">r248330</a>. rdar://problem/54018116

    Context menu on a universal link produces a blank preview
    https://bugs.webkit.org/show_bug.cgi?id=200485
    <rdar://problem/53699620>

    Reviewed by Dean Jackson.

    Source/WebCore/PAL:

    Define iTunesStoreURL from CoreServices.

    * pal/spi/cocoa/LaunchServicesSPI.h:

    Source/WebKit:

    If the context menu is activated on an iTunesStore URL, pass it
    on to DataDetectors, who should know how to handle it.

    Two drive-by fixes:
    - make it clear that early returns do not produce a value. Instead call the
      completion handler first, then return.
    - The new API DataDetectors case doesn't need to worry about hiding link previews
      as DataDetectors itself will handle that.

    * UIProcess/ios/WKContentViewInteraction.mm: If the URL is an iTunesStoreURL
    (as defined by CoreServices), let DataDetectors handle it.
    (-[WKContentView assignLegacyDataForContextMenuInteraction]):
    (-[WKContentView continueContextMenuInteraction:]):
    (-[WKContentView continueContextMenuInteractionWithDataDetectors:]): New method to
    use DataDetectors if possible.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248330 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6081branchSourceWebCorePALChangeLog">branches/safari-608.1-branch/Source/WebCore/PAL/ChangeLog</a></li>
<li><a href="#branchessafari6081branchSourceWebCorePALpalspicocoaLaunchServicesSPIh">branches/safari-608.1-branch/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h</a></li>
<li><a href="#branchessafari6081branchSourceWebKitChangeLog">branches/safari-608.1-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari6081branchSourceWebKitUIProcessiosWKContentViewInteractionmm">branches/safari-608.1-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6081branchSourceWebCorePALChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1-branch/Source/WebCore/PAL/ChangeLog (248359 => 248360)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1-branch/Source/WebCore/PAL/ChangeLog        2019-08-07 06:53:05 UTC (rev 248359)
+++ branches/safari-608.1-branch/Source/WebCore/PAL/ChangeLog   2019-08-07 06:53:08 UTC (rev 248360)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
+
+        Cherry-pick r248330. rdar://problem/54018116
+
+    Context menu on a universal link produces a blank preview
+    https://bugs.webkit.org/show_bug.cgi?id=200485
+    <rdar://problem/53699620>
+    
+    Reviewed by Dean Jackson.
+    
+    Source/WebCore/PAL:
+    
+    Define iTunesStoreURL from CoreServices.
+    
+    * pal/spi/cocoa/LaunchServicesSPI.h:
+    
+    Source/WebKit:
+    
+    If the context menu is activated on an iTunesStore URL, pass it
+    on to DataDetectors, who should know how to handle it.
+    
+    Two drive-by fixes:
+    - make it clear that early returns do not produce a value. Instead call the
+      completion handler first, then return.
+    - The new API DataDetectors case doesn't need to worry about hiding link previews
+      as DataDetectors itself will handle that.
+    
+    * UIProcess/ios/WKContentViewInteraction.mm: If the URL is an iTunesStoreURL
+    (as defined by CoreServices), let DataDetectors handle it.
+    (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+    (-[WKContentView continueContextMenuInteraction:]):
+    (-[WKContentView continueContextMenuInteractionWithDataDetectors:]): New method to
+    use DataDetectors if possible.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248330 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-08-06  Dean Jackson  <dino@apple.com>
+
+            Context menu on a universal link produces a blank preview
+            https://bugs.webkit.org/show_bug.cgi?id=200485
+            <rdar://problem/53699620>
+
+            Reviewed by Dean Jackson.
+
+            Define iTunesStoreURL from CoreServices.
+
+            * pal/spi/cocoa/LaunchServicesSPI.h:
+
</ins><span class="cx"> 2019-07-24  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r247674. rdar://problem/53483295
</span></span></pre></div>
<a id="branchessafari6081branchSourceWebCorePALpalspicocoaLaunchServicesSPIh"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1-branch/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h (248359 => 248360)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1-branch/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h        2019-08-07 06:53:05 UTC (rev 248359)
+++ branches/safari-608.1-branch/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h   2019-08-07 06:53:08 UTC (rev 248360)
</span><span class="lines">@@ -32,10 +32,11 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> #import <CoreServices/CoreServicesPriv.h>
</span><span class="cx"> #elif PLATFORM(IOS_FAMILY)
</span><ins>+#import <CoreServices/LSURLOverridePriv.h>
</ins><span class="cx"> #import <MobileCoreServices/LSAppLinkPriv.h>
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#endif
</del><ins>+#endif // USE(APPLE_INTERNAL_SDK)
</ins><span class="cx"> 
</span><span class="cx"> #if HAVE(APP_LINKS)
</span><span class="cx"> @class LSAppLink;
</span><span class="lines">@@ -73,6 +74,10 @@
</span><span class="cx"> @end
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+@interface NSURL ()
+- (NSURL *)iTunesStoreURL;
+@end
+
</ins><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> enum LSSessionID {
</span><span class="cx">     kLSDefaultSessionID = -2,
</span></span></pre></div>
<a id="branchessafari6081branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1-branch/Source/WebKit/ChangeLog (248359 => 248360)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1-branch/Source/WebKit/ChangeLog     2019-08-07 06:53:05 UTC (rev 248359)
+++ branches/safari-608.1-branch/Source/WebKit/ChangeLog        2019-08-07 06:53:08 UTC (rev 248360)
</span><span class="lines">@@ -1,5 +1,65 @@
</span><span class="cx"> 2019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r248330. rdar://problem/54018116
+
+    Context menu on a universal link produces a blank preview
+    https://bugs.webkit.org/show_bug.cgi?id=200485
+    <rdar://problem/53699620>
+    
+    Reviewed by Dean Jackson.
+    
+    Source/WebCore/PAL:
+    
+    Define iTunesStoreURL from CoreServices.
+    
+    * pal/spi/cocoa/LaunchServicesSPI.h:
+    
+    Source/WebKit:
+    
+    If the context menu is activated on an iTunesStore URL, pass it
+    on to DataDetectors, who should know how to handle it.
+    
+    Two drive-by fixes:
+    - make it clear that early returns do not produce a value. Instead call the
+      completion handler first, then return.
+    - The new API DataDetectors case doesn't need to worry about hiding link previews
+      as DataDetectors itself will handle that.
+    
+    * UIProcess/ios/WKContentViewInteraction.mm: If the URL is an iTunesStoreURL
+    (as defined by CoreServices), let DataDetectors handle it.
+    (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+    (-[WKContentView continueContextMenuInteraction:]):
+    (-[WKContentView continueContextMenuInteractionWithDataDetectors:]): New method to
+    use DataDetectors if possible.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248330 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-08-06  Dean Jackson  <dino@apple.com>
+
+            Context menu on a universal link produces a blank preview
+            https://bugs.webkit.org/show_bug.cgi?id=200485
+            <rdar://problem/53699620>
+
+            Reviewed by Dean Jackson.
+
+            If the context menu is activated on an iTunesStore URL, pass it
+            on to DataDetectors, who should know how to handle it.
+
+            Two drive-by fixes:
+            - make it clear that early returns do not produce a value. Instead call the
+              completion handler first, then return.
+            - The new API DataDetectors case doesn't need to worry about hiding link previews
+              as DataDetectors itself will handle that.
+
+            * UIProcess/ios/WKContentViewInteraction.mm: If the URL is an iTunesStoreURL
+            (as defined by CoreServices), let DataDetectors handle it.
+            (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+            (-[WKContentView continueContextMenuInteraction:]):
+            (-[WKContentView continueContextMenuInteractionWithDataDetectors:]): New method to
+            use DataDetectors if possible.
+
+2019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
+
</ins><span class="cx">         Cherry-pick r248085. rdar://problem/54017902
</span><span class="cx"> 
</span><span class="cx">     WKImagePreviewViewController not being autoreleased
</span></span></pre></div>
<a id="branchessafari6081branchSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (248359 => 248360)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm     2019-08-07 06:53:05 UTC (rev 248359)
+++ branches/safari-608.1-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm        2019-08-07 06:53:08 UTC (rev 248360)
</span><span class="lines">@@ -106,6 +106,7 @@
</span><span class="cx"> #import <WebKit/WebSelectionRect.h> // FIXME: WK2 should not include WebKit headers!
</span><span class="cx"> #import <pal/spi/cg/CoreGraphicsSPI.h>
</span><span class="cx"> #import <pal/spi/cocoa/DataDetectorsCoreSPI.h>
</span><ins>+#import <pal/spi/cocoa/LaunchServicesSPI.h>
</ins><span class="cx"> #import <pal/spi/ios/DataDetectorsUISPI.h>
</span><span class="cx"> #import <pal/spi/ios/GraphicsServicesSPI.h>
</span><span class="cx"> #import <wtf/BlockObjCExceptions.h>
</span><span class="lines">@@ -7790,7 +7791,7 @@
</span><span class="cx"> 
</span><span class="cx">         // Previously, UIPreviewItemController would detect the case where there was no previewViewController
</span><span class="cx">         // and create one. We need to replicate this code for the new API.
</span><del>-        if (!previewViewController) {
</del><ins>+        if (!previewViewController || [(NSURL *)url iTunesStoreURL]) {
</ins><span class="cx">             auto ddContextMenuActionClass = getDDContextMenuActionClass();
</span><span class="cx">             if ([ddContextMenuActionClass respondsToSelector:@selector(contextMenuConfigurationForURL:identifier:selectedText:results:inView:context:menuIdentifier:)]) {
</span><span class="cx">                 BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="lines">@@ -7935,15 +7936,24 @@
</span><span class="cx"> 
</span><span class="cx">         _page->startInteractionWithElementAtPosition(_positionInformation.request.point);
</span><span class="cx"> 
</span><del>-        // FIXME: Should we provide an identifier and ASSERT in delegates if we don't match?
-        return continueWithContextMenuConfiguration([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:contentPreviewProvider actionProvider:actionMenuProvider]);
</del><ins>+        continueWithContextMenuConfiguration([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:contentPreviewProvider actionProvider:actionMenuProvider]);
+        return;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if ENABLE(DATA_DETECTION)
+    if ([(NSURL *)linkURL iTunesStoreURL]) {
+        if ([self continueContextMenuInteractionWithDataDetectors:continueWithContextMenuConfiguration])
+            return;
+    }
+#endif
+
</ins><span class="cx">     auto completionBlock = makeBlockPtr([continueWithContextMenuConfiguration = makeBlockPtr(continueWithContextMenuConfiguration), linkURL = WTFMove(linkURL), weakSelf = WeakObjCPtr<WKContentView>(self)] (UIContextMenuConfiguration *configurationFromWKUIDelegate) mutable {
</span><span class="cx"> 
</span><span class="cx">         auto strongSelf = weakSelf.get();
</span><del>-        if (!strongSelf)
-            return continueWithContextMenuConfiguration(nil);
</del><ins>+        if (!strongSelf) {
+            continueWithContextMenuConfiguration(nil);
+            return;
+        }
</ins><span class="cx"> 
</span><span class="cx">         if (configurationFromWKUIDelegate) {
</span><span class="cx">             strongSelf->_page->startInteractionWithElementAtPosition(strongSelf->_positionInformation.request.point);
</span><span class="lines">@@ -7978,7 +7988,8 @@
</span><span class="cx">                 return [[[WKImagePreviewViewController alloc] initWithCGImage:cgImage defaultActions:nil elementInfo:elementInfo.get()] autorelease];
</span><span class="cx">             };
</span><span class="cx"> 
</span><del>-            return continueWithContextMenuConfiguration([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:contentPreviewProvider actionProvider:actionMenuProvider]);
</del><ins>+            continueWithContextMenuConfiguration([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:contentPreviewProvider actionProvider:actionMenuProvider]);
+            return;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // At this point we have an object we might want to show a context menu for, but the
</span><span class="lines">@@ -7989,23 +8000,15 @@
</span><span class="cx"> #if ENABLE(DATA_DETECTION)
</span><span class="cx">         // FIXME: Support JavaScript urls here. But make sure they don't show a preview.
</span><span class="cx">         // <rdar://problem/50572283>
</span><del>-        if (!linkURL.protocolIsInHTTPFamily() && !WebCore::DataDetection::canBePresentedByDataDetectors(linkURL))
-            return continueWithContextMenuConfiguration(nil);
</del><ins>+        if (!linkURL.protocolIsInHTTPFamily() && !WebCore::DataDetection::canBePresentedByDataDetectors(linkURL)) {
+            continueWithContextMenuConfiguration(nil);
+            return;
+        }
</ins><span class="cx"> 
</span><del>-        BEGIN_BLOCK_OBJC_EXCEPTIONS;
-        auto ddContextMenuActionClass = getDDContextMenuActionClass();
-        if ([ddContextMenuActionClass respondsToSelector:@selector(contextMenuConfigurationWithURL:inView:context:menuIdentifier:)]) {
-            NSDictionary *context = [strongSelf dataDetectionContextForPositionInformation:strongSelf->_positionInformation];
-            UIContextMenuConfiguration *configurationFromDD = [ddContextMenuActionClass contextMenuConfigurationForURL:linkURL identifier:strongSelf->_positionInformation.dataDetectorIdentifier selectedText:[strongSelf selectedText] results:strongSelf->_positionInformation.dataDetectorResults.get() inView:strongSelf.get() context:context menuIdentifier:nil];
-            strongSelf->_contextMenuActionProviderDelegateNeedsOverride = YES;
-            strongSelf->_page->startInteractionWithElementAtPosition(strongSelf->_positionInformation.request.point);
-            if (strongSelf->_showLinkPreviews)
-                return continueWithContextMenuConfiguration(configurationFromDD);
-            return continueWithContextMenuConfiguration([UIContextMenuConfiguration configurationWithIdentifier:[configurationFromDD identifier] previewProvider:nil actionProvider:[configurationFromDD actionProvider]]);
-        }
-        END_BLOCK_OBJC_EXCEPTIONS;
</del><ins>+        if ([strongSelf continueContextMenuInteractionWithDataDetectors:continueWithContextMenuConfiguration.get()])
+            return;
</ins><span class="cx"> #endif
</span><del>-        return continueWithContextMenuConfiguration(nil);
</del><ins>+        continueWithContextMenuConfiguration(nil);
</ins><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     _contextMenuActionProviderDelegateNeedsOverride = NO;
</span><span class="lines">@@ -8030,6 +8033,26 @@
</span><span class="cx">         completionBlock(nil);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(DATA_DETECTION)
+- (BOOL)continueContextMenuInteractionWithDataDetectors:(void(^)(UIContextMenuConfiguration *))continueWithContextMenuConfiguration
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    auto ddContextMenuActionClass = getDDContextMenuActionClass();
+    if ([ddContextMenuActionClass respondsToSelector:@selector(contextMenuConfigurationWithURL:inView:context:menuIdentifier:)]) {
+        URL linkURL = _positionInformation.url;
+        NSDictionary *context = [self dataDetectionContextForPositionInformation:_positionInformation];
+        UIContextMenuConfiguration *configurationFromDD = [ddContextMenuActionClass contextMenuConfigurationForURL:linkURL identifier:_positionInformation.dataDetectorIdentifier selectedText:[self selectedText] results:_positionInformation.dataDetectorResults.get() inView:self context:context menuIdentifier:nil];
+        _contextMenuActionProviderDelegateNeedsOverride = YES;
+        _page->startInteractionWithElementAtPosition(_positionInformation.request.point);
+        continueWithContextMenuConfiguration(configurationFromDD);
+        return YES;
+    }
+    END_BLOCK_OBJC_EXCEPTIONS;
+
+    return NO;
+}
+#endif
+
</ins><span class="cx"> - (NSArray<UIMenuElement *> *)_contextMenuInteraction:(UIContextMenuInteraction *)interaction overrideSuggestedActionsForConfiguration:(UIContextMenuConfiguration *)configuration
</span><span class="cx"> {
</span><span class="cx">     if (_contextMenuActionProviderDelegateNeedsOverride) {
</span></span></pre>
</div>
</div>

</body>
</html>