<!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>[284122] trunk/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/284122">284122</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2021-10-13 13:35:45 -0700 (Wed, 13 Oct 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Support both VK and VKC-prefixed SPI when softlinking VisionKitCore classes
https://bugs.webkit.org/show_bug.cgi?id=231683
rdar://83744729

Reviewed by Tim Horton.

Source/WebCore/PAL:

See WebKit/ChangeLog for more details.

* pal/cocoa/VisionKitCoreSoftLink.h:
* pal/cocoa/VisionKitCoreSoftLink.mm:

Source/WebKit:

Several SPI classes in VisionKitCore are going to be renamed to be prefixed with VKC- rather than VK-, with a
`@compatibility_alias` for the existing SPI names. Refactor Live Text support in WebKit to be both binary and
source compatible with this future version of VisionKitCore, by checking for the existence of both class names
when softlinking VKImageAnalyzer and VKImageAnalyzerRequest. See below for more details.

* Platform/cocoa/TextRecognitionUtilities.h:
* Platform/cocoa/TextRecognitionUtilities.mm:
(WebKit::hasVisionKitCorePrefixedClasses):
(WebKit::createImageAnalyzer):
(WebKit::createImageAnalyzerRequest):

Instead of calling into PAL softlinking functions to allocate VKImageAnalyzer, put this logic behind a helper
function in TextRecognitionUtilities, which knows how to check for either class.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::ensureImageAnalyzer):
(WebKit::createImageAnalyzerRequest):
(WebKit::WebViewImpl::requestTextRecognition):
(WebKit::WebViewImpl::computeHasImageAnalysisResults):
(WebKit::createImageAnalysisRequest): Deleted.

Use the helper functions declared in TextRecognitionUtilities.h.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView imageAnalyzer]):
(-[WKContentView createImageAnalyzerRequest:image:imageURL:]):
(-[WKContentView createImageAnalyzerRequest:image:]):
(-[WKContentView requestTextRecognition:imageData:completionHandler:]):
(-[WKContentView imageAnalysisGestureDidBegin:]):
(-[WKContentView imageAnalysisGestureDidTimeOut:]):
(-[WKContentView createImageAnalysisRequest:image:imageURL:]): Deleted.
(-[WKContentView createImageAnalysisRequest:image:]): Deleted.

Use the helper functions declared in TextRecognitionUtilities.h, instead of using PAL softlinking directly. We
also refactor this code to pass a CGImageRef instead of a UIImage when initializing the image analyzer request,
such that the helper functions can work across macOS and iOS.

Also rename `createImageAnalysisRequest` to `createImageAnalyzerRequest` for consistency with the class name.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorePALChangeLog">trunk/Source/WebCore/PAL/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorePALpalcocoaVisionKitCoreSoftLinkh">trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.h</a></li>
<li><a href="#trunkSourceWebCorePALpalcocoaVisionKitCoreSoftLinkmm">trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.mm</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformcocoaTextRecognitionUtilitiesh">trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h</a></li>
<li><a href="#trunkSourceWebKitPlatformcocoaTextRecognitionUtilitiesmm">trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessCocoaWebViewImplmm">trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionh">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCorePALChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PAL/ChangeLog (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PAL/ChangeLog       2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebCore/PAL/ChangeLog  2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-10-13  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Support both VK and VKC-prefixed SPI when softlinking VisionKitCore classes
+        https://bugs.webkit.org/show_bug.cgi?id=231683
+        rdar://83744729
+
+        Reviewed by Tim Horton.
+
+        See WebKit/ChangeLog for more details.
+
+        * pal/cocoa/VisionKitCoreSoftLink.h:
+        * pal/cocoa/VisionKitCoreSoftLink.mm:
+
</ins><span class="cx"> 2021-10-13  Aditya Keerthi  <akeerthi@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [macOS] Add support for accent-color
</span></span></pre></div>
<a id="trunkSourceWebCorePALpalcocoaVisionKitCoreSoftLinkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.h (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.h       2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.h  2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -33,5 +33,7 @@
</span><span class="cx"> SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, VisionKitCore)
</span><span class="cx"> SOFT_LINK_CLASS_FOR_HEADER(PAL, VKImageAnalyzer)
</span><span class="cx"> SOFT_LINK_CLASS_FOR_HEADER(PAL, VKImageAnalyzerRequest)
</span><ins>+SOFT_LINK_CLASS_FOR_HEADER(PAL, VKCImageAnalyzer)
+SOFT_LINK_CLASS_FOR_HEADER(PAL, VKCImageAnalyzerRequest)
</ins><span class="cx"> 
</span><span class="cx"> #endif // HAVE(VK_IMAGE_ANALYSIS)
</span></span></pre></div>
<a id="trunkSourceWebCorePALpalcocoaVisionKitCoreSoftLinkmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.mm (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.mm      2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.mm 2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -31,7 +31,9 @@
</span><span class="cx"> #import <wtf/SoftLinking.h>
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_PRIVATE_FRAMEWORK_FOR_SOURCE_WITH_EXPORT(PAL, VisionKitCore, PAL_EXPORT)
</span><del>-SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, VisionKitCore, VKImageAnalyzer, PAL_EXPORT)
-SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, VisionKitCore, VKImageAnalyzerRequest, PAL_EXPORT)
</del><ins>+SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKImageAnalyzer, PAL_EXPORT, true)
+SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKImageAnalyzerRequest, PAL_EXPORT, true)
+SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKCImageAnalyzer, PAL_EXPORT, true)
+SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKCImageAnalyzerRequest, PAL_EXPORT, true)
</ins><span class="cx"> 
</span><span class="cx"> #endif // HAVE(VK_IMAGE_ANALYSIS)
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebKit/ChangeLog       2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2021-10-13  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Support both VK and VKC-prefixed SPI when softlinking VisionKitCore classes
+        https://bugs.webkit.org/show_bug.cgi?id=231683
+        rdar://83744729
+
+        Reviewed by Tim Horton.
+
+        Several SPI classes in VisionKitCore are going to be renamed to be prefixed with VKC- rather than VK-, with a
+        `@compatibility_alias` for the existing SPI names. Refactor Live Text support in WebKit to be both binary and
+        source compatible with this future version of VisionKitCore, by checking for the existence of both class names
+        when softlinking VKImageAnalyzer and VKImageAnalyzerRequest. See below for more details.
+
+        * Platform/cocoa/TextRecognitionUtilities.h:
+        * Platform/cocoa/TextRecognitionUtilities.mm:
+        (WebKit::hasVisionKitCorePrefixedClasses):
+        (WebKit::createImageAnalyzer):
+        (WebKit::createImageAnalyzerRequest):
+
+        Instead of calling into PAL softlinking functions to allocate VKImageAnalyzer, put this logic behind a helper
+        function in TextRecognitionUtilities, which knows how to check for either class.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::ensureImageAnalyzer):
+        (WebKit::createImageAnalyzerRequest):
+        (WebKit::WebViewImpl::requestTextRecognition):
+        (WebKit::WebViewImpl::computeHasImageAnalysisResults):
+        (WebKit::createImageAnalysisRequest): Deleted.
+
+        Use the helper functions declared in TextRecognitionUtilities.h.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView imageAnalyzer]):
+        (-[WKContentView createImageAnalyzerRequest:image:imageURL:]):
+        (-[WKContentView createImageAnalyzerRequest:image:]):
+        (-[WKContentView requestTextRecognition:imageData:completionHandler:]):
+        (-[WKContentView imageAnalysisGestureDidBegin:]):
+        (-[WKContentView imageAnalysisGestureDidTimeOut:]):
+        (-[WKContentView createImageAnalysisRequest:image:imageURL:]): Deleted.
+        (-[WKContentView createImageAnalysisRequest:image:]): Deleted.
+
+        Use the helper functions declared in TextRecognitionUtilities.h, instead of using PAL softlinking directly. We
+        also refactor this code to pass a CGImageRef instead of a UIImage when initializing the image analyzer request,
+        such that the helper functions can work across macOS and iOS.
+
+        Also rename `createImageAnalysisRequest` to `createImageAnalyzerRequest` for consistency with the class name.
+
</ins><span class="cx"> 2021-10-13  Per Arne  <pvollan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Restrict "darwin-notification-post" to a minimal set in the WP sandbox
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformcocoaTextRecognitionUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h    2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h       2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -27,7 +27,8 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(IMAGE_ANALYSIS)
</span><span class="cx"> 
</span><del>-@class VKImageAnalysis;
</del><ins>+#import <pal/spi/cocoa/VisionKitCoreSPI.h>
+#import <wtf/RetainPtr.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> struct TextRecognitionResult;
</span><span class="lines">@@ -38,6 +39,10 @@
</span><span class="cx"> bool isLiveTextAvailableAndEnabled();
</span><span class="cx"> WebCore::TextRecognitionResult makeTextRecognitionResult(VKImageAnalysis *);
</span><span class="cx"> 
</span><ins>+// FIXME: Replace the return types of these helper functions with VKCImageAnalyzer and VKCImageAnalyzerRequest, respectively.
+RetainPtr<VKImageAnalyzer> createImageAnalyzer();
+RetainPtr<VKImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef, VKAnalysisTypes);
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(IMAGE_ANALYSIS)
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformcocoaTextRecognitionUtilitiesmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm   2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm      2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -35,6 +35,32 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><ins>+static bool hasVisionKitCorePrefixedClasses()
+{
+    static bool result = false;
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [&] {
+        result = !!PAL::getVKCImageAnalyzerClass();
+    });
+    return result;
+}
+
+RetainPtr<VKImageAnalyzer> createImageAnalyzer()
+{
+    if (hasVisionKitCorePrefixedClasses())
+        return adoptNS([static_cast<VKImageAnalyzer *>(PAL::allocVKCImageAnalyzerInstance()) init]);
+
+    return adoptNS([PAL::allocVKImageAnalyzerInstance() init]);
+}
+
+RetainPtr<VKImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef image, VKAnalysisTypes types)
+{
+    if (hasVisionKitCorePrefixedClasses())
+        return adoptNS([static_cast<VKImageAnalyzerRequest *>(PAL::allocVKCImageAnalyzerRequestInstance()) initWithCGImage:image orientation:VKImageOrientationUp requestType:types]);
+
+    return adoptNS([PAL::allocVKImageAnalyzerRequestInstance() initWithCGImage:image orientation:VKImageOrientationUp requestType:types]);
+}
+
</ins><span class="cx"> static FloatQuad floatQuad(VKQuad *quad)
</span><span class="cx"> {
</span><span class="cx">     return { quad.topLeft, quad.topRight, quad.bottomRight, quad.bottomLeft };
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessCocoaWebViewImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm       2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm  2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -190,15 +190,15 @@
</span><span class="cx"> {
</span><span class="cx">     if (!m_imageAnalyzer) {
</span><span class="cx">         m_imageAnalyzerQueue = WorkQueue::create("WebKit image analyzer queue");
</span><del>-        m_imageAnalyzer = adoptNS([PAL::allocVKImageAnalyzerInstance() init]);
</del><ins>+        m_imageAnalyzer = createImageAnalyzer();
</ins><span class="cx">         [m_imageAnalyzer setCallbackQueue:m_imageAnalyzerQueue->dispatchQueue()];
</span><span class="cx">     }
</span><span class="cx">     return m_imageAnalyzer.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static RetainPtr<VKImageAnalyzerRequest> createImageAnalysisRequest(CGImageRef image, const URL& imageURL, const URL& pageURL, VKAnalysisTypes types)
</del><ins>+static RetainPtr<VKImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef image, const URL& imageURL, const URL& pageURL, VKAnalysisTypes types)
</ins><span class="cx"> {
</span><del>-    auto request = adoptNS([PAL::allocVKImageAnalyzerRequestInstance() initWithCGImage:image orientation:VKImageOrientationUp requestType:types]);
</del><ins>+    auto request = createImageAnalyzerRequest(image, types);
</ins><span class="cx">     [request setImageURL:imageURL];
</span><span class="cx">     [request setPageURL:pageURL];
</span><span class="cx">     return request;
</span><span class="lines">@@ -218,7 +218,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto cgImage = imageBitmap->makeCGImage();
</span><del>-    auto request = createImageAnalysisRequest(cgImage.get(), imageURL, [NSURL _web_URLWithWTFString:m_page->currentURL()], VKAnalysisTypeText);
</del><ins>+    auto request = createImageAnalyzerRequest(cgImage.get(), imageURL, [NSURL _web_URLWithWTFString:m_page->currentURL()], VKAnalysisTypeText);
</ins><span class="cx">     auto startTime = MonotonicTime::now();
</span><span class="cx">     [ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime] (VKImageAnalysis *analysis, NSError *) mutable {
</span><span class="cx">         callOnMainRunLoop([completion = WTFMove(completion), result = makeTextRecognitionResult(analysis), startTime] () mutable {
</span><span class="lines">@@ -237,7 +237,7 @@
</span><span class="cx"> 
</span><span class="cx">     auto cgImage = imageBitmap.makeCGImage();
</span><span class="cx">     auto analysisType = type == ImageAnalysisType::VisualSearch ? VKAnalysisTypeVisualSearch : VKAnalysisTypeText;
</span><del>-    auto request = createImageAnalysisRequest(cgImage.get(), imageURL, [NSURL _web_URLWithWTFString:m_page->currentURL()], analysisType);
</del><ins>+    auto request = createImageAnalyzerRequest(cgImage.get(), imageURL, [NSURL _web_URLWithWTFString:m_page->currentURL()], analysisType);
</ins><span class="cx">     auto startTime = MonotonicTime::now();
</span><span class="cx">     [ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime, analysisType] (VKImageAnalysis *analysis, NSError *) mutable {
</span><span class="cx">         BOOL result = [analysis hasResultsForAnalysisTypes:analysisType];
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h     2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h        2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -109,7 +109,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @class QLPreviewController;
</span><del>-@class VKImageAnalyzer;
</del><span class="cx"> @class WebEvent;
</span><span class="cx"> @class WebTextIndicatorLayer;
</span><span class="cx"> @class WKActionSheetAssistant;
</span><span class="lines">@@ -504,7 +503,7 @@
</span><span class="cx">     BOOL _contextMenuWasTriggeredByImageAnalysisTimeout;
</span><span class="cx"> #endif // USE(UICONTEXTMENU)
</span><span class="cx">     BOOL _isProceedingWithTextSelectionInImage;
</span><del>-    RetainPtr<VKImageAnalyzer> _imageAnalyzer;
</del><ins>+    RetainPtr<id> _imageAnalyzer;
</ins><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx">     RetainPtr<QLPreviewController> _visualSearchPreviewController;
</span><span class="cx">     RetainPtr<UIImage> _visualSearchPreviewImage;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (284121 => 284122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm    2021-10-13 19:20:58 UTC (rev 284121)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm       2021-10-13 20:35:45 UTC (rev 284122)
</span><span class="lines">@@ -10020,7 +10020,7 @@
</span><span class="cx"> - (VKImageAnalyzer *)imageAnalyzer
</span><span class="cx"> {
</span><span class="cx">     if (!_imageAnalyzer)
</span><del>-        _imageAnalyzer = adoptNS([PAL::allocVKImageAnalyzerInstance() init]);
</del><ins>+        _imageAnalyzer = WebKit::createImageAnalyzer();
</ins><span class="cx">     return _imageAnalyzer.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -10087,17 +10087,17 @@
</span><span class="cx">     _elementPendingImageAnalysis = std::nullopt;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (RetainPtr<VKImageAnalyzerRequest>)createImageAnalysisRequest:(VKAnalysisTypes)analysisTypes image:(UIImage *)image imageURL:(NSURL *)imageURL
</del><ins>+- (RetainPtr<VKImageAnalyzerRequest>)createImageAnalyzerRequest:(VKAnalysisTypes)analysisTypes image:(CGImageRef)image imageURL:(NSURL *)imageURL
</ins><span class="cx"> {
</span><del>-    auto request = adoptNS([PAL::allocVKImageAnalyzerRequestInstance() initWithImage:image orientation:VKImageOrientationUp requestType:analysisTypes]);
</del><ins>+    auto request = WebKit::createImageAnalyzerRequest(image, analysisTypes);
</ins><span class="cx">     [request setImageURL:imageURL];
</span><span class="cx">     [request setPageURL:[NSURL _web_URLWithWTFString:_page->currentURL()]];
</span><span class="cx">     return request;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (RetainPtr<VKImageAnalyzerRequest>)createImageAnalysisRequest:(VKAnalysisTypes)analysisTypes image:(UIImage *)image
</del><ins>+- (RetainPtr<VKImageAnalyzerRequest>)createImageAnalyzerRequest:(VKAnalysisTypes)analysisTypes image:(CGImageRef)image
</ins><span class="cx"> {
</span><del>-    return [self createImageAnalysisRequest:analysisTypes image:image imageURL:_positionInformation.imageURL];
</del><ins>+    return [self createImageAnalyzerRequest:analysisTypes image:image imageURL:_positionInformation.imageURL];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if USE(UICONTEXTMENU) && ENABLE(IMAGE_ANALYSIS_FOR_MACHINE_READABLE_CODES)
</span><span class="lines">@@ -10139,13 +10139,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    auto image = adoptNS([[UIImage alloc] initWithCGImage:cgImage.get()]);
-    if (!image) {
-        completion({ });
-        return;
-    }
-
-    auto request = [self createImageAnalysisRequest:VKAnalysisTypeText image:image.get()];
</del><ins>+    auto request = [self createImageAnalyzerRequest:VKAnalysisTypeText image:cgImage.get()];
</ins><span class="cx">     [[self imageAnalyzer] processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion)] (VKImageAnalysis *result, NSError *) mutable {
</span><span class="cx">         completion(WebKit::makeTextRecognitionResult(result));
</span><span class="cx">     }).get()];
</span><span class="lines">@@ -10210,12 +10204,6 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        auto image = adoptNS([[UIImage alloc] initWithCGImage:cgImage.get()]);
-        if (!image) {
-            [strongSelf _invokeAllActionsToPerformAfterPendingImageAnalysis:WebKit::ProceedWithTextSelectionInImage::No];
-            return;
-        }
-
</del><span class="cx">         RELEASE_LOG(Images, "Image analysis preflight gesture initiated (request %" PRIu64 ").", requestIdentifier.toUInt64());
</span><span class="cx"> 
</span><span class="cx">         strongSelf->_elementPendingImageAnalysis = information.imageElementContext;
</span><span class="lines">@@ -10223,8 +10211,8 @@
</span><span class="cx">         auto requestLocation = information.request.point;
</span><span class="cx">         WebCore::ElementContext elementContext = *information.imageElementContext;
</span><span class="cx"> 
</span><del>-        auto requestForTextSelection = [strongSelf createImageAnalysisRequest:VKAnalysisTypeText image:image.get()];
-        auto requestForContextMenu = [strongSelf createImageAnalysisRequest:VKAnalysisTypeVisualSearch | VKAnalysisTypeMachineReadableCode | VKAnalysisTypeAppClip image:image.get()];
</del><ins>+        auto requestForTextSelection = [strongSelf createImageAnalyzerRequest:VKAnalysisTypeText image:cgImage.get()];
+        auto requestForContextMenu = [strongSelf createImageAnalyzerRequest:VKAnalysisTypeVisualSearch | VKAnalysisTypeMachineReadableCode | VKAnalysisTypeAppClip image:cgImage.get()];
</ins><span class="cx"> 
</span><span class="cx">         auto textAnalysisStartTime = MonotonicTime::now();
</span><span class="cx">         [[strongSelf imageAnalyzer] processRequest:requestForTextSelection.get() progressHandler:nil completionHandler:[requestIdentifier = WTFMove(requestIdentifier), weakSelf, elementContext, requestLocation, requestForContextMenu, gestureDeferralToken, textAnalysisStartTime] (VKImageAnalysis *result, NSError *error) mutable {
</span><span class="lines">@@ -10320,16 +10308,12 @@
</span><span class="cx">         if (!cgImage)
</span><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        auto image = adoptNS([[UIImage alloc] initWithCGImage:cgImage.get()]);
-        if (!image)
-            return;
-
</del><span class="cx">         RELEASE_LOG(Images, "Image analysis timeout gesture initiated.");
</span><span class="cx">         // FIXME: We need to implement some way to cache image analysis results per element, so that we don't end up
</span><span class="cx">         // making redundant image analysis requests for the same image data.
</span><span class="cx"> 
</span><span class="cx">         auto visualSearchAnalysisStartTime = MonotonicTime::now();
</span><del>-        auto requestForContextMenu = [strongSelf createImageAnalysisRequest:VKAnalysisTypeVisualSearch | VKAnalysisTypeMachineReadableCode | VKAnalysisTypeAppClip image:image.get()];
</del><ins>+        auto requestForContextMenu = [strongSelf createImageAnalyzerRequest:VKAnalysisTypeVisualSearch | VKAnalysisTypeMachineReadableCode | VKAnalysisTypeAppClip image:cgImage.get()];
</ins><span class="cx">         [[strongSelf imageAnalyzer] processRequest:requestForContextMenu.get() progressHandler:nil completionHandler:[weakSelf, location, visualSearchAnalysisStartTime] (VKImageAnalysis *result, NSError *error) {
</span><span class="cx">             auto strongSelf = weakSelf.get();
</span><span class="cx">             if (!strongSelf)
</span></span></pre>
</div>
</div>

</body>
</html>