Skip to content

Commit

Permalink
Don't call PAL::getWKDDActionContextClass in macOS base system
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259660
rdar://113156967

Reviewed by Tim Horton and Chris Dumez.

Before 266374@main we would only call PAL::getWKDDActionContextClass if detectedDataActionContext was non-null.
Now we always call it when decoding a WebHitTestResultPlatformData, which causes a crash in the base system
where the framework doesn't exist.  Use Markable to stop the crash.

* Source/WebKit/Shared/WebHitTestResultData.h:
* Source/WebKit/Shared/mac/WebHitTestResultPlatformData.serialization.in:
* Source/WebKit/UIProcess/mac/WKImmediateActionController.mm:
(-[WKImmediateActionController _animationControllerForDataDetectedText]):
* Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performImmediateActionHitTestAtLocation):

Canonical link: https://commits.webkit.org/266459@main
  • Loading branch information
achristensen07 committed Jul 31, 2023
1 parent 39a323e commit e3ec066
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Source/WebKit/Shared/WebHitTestResultData.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ namespace WebKit {

#if PLATFORM(MAC)
struct WebHitTestResultPlatformData {
RetainPtr<WKDDActionContext> detectedDataActionContext;
struct DetectedDataActionContext {
RetainPtr<WKDDActionContext> context;
struct MarkableTraits {
static bool isEmptyValue(const DetectedDataActionContext& context) { return !context.context; }
static DetectedDataActionContext emptyValue() { return { nullptr }; }
};
};
Markable<DetectedDataActionContext> detectedDataActionContext;
WebCore::FloatRect detectedDataBoundingBox;
RefPtr<WebCore::TextIndicator> detectedDataTextIndicator;
WebCore::PageOverlay::PageOverlayID detectedDataOriginatingPageOverlay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ headers: <WebCore/TextIndicator.h>

#if PLATFORM(MAC)
header: "WebHitTestResultData.h" <pal/mac/DataDetectorsSoftLink.h>
[Nested] struct WebKit::WebHitTestResultPlatformData::DetectedDataActionContext {
[SecureCodingAllowed=[PAL::getWKDDActionContextClass()]] RetainPtr<WKDDActionContext> context;
};
[CustomHeader] struct WebKit::WebHitTestResultPlatformData {
[SecureCodingAllowed=[PAL::getWKDDActionContextClass()]] RetainPtr<WKDDActionContext> detectedDataActionContext;
Markable<WebKit::WebHitTestResultPlatformData::DetectedDataActionContext> detectedDataActionContext;
WebCore::FloatRect detectedDataBoundingBox;
RefPtr<WebCore::TextIndicator> detectedDataTextIndicator;
WebCore::PageOverlay::PageOverlayID detectedDataOriginatingPageOverlay;
Expand Down
6 changes: 5 additions & 1 deletion Source/WebKit/UIProcess/mac/WKImmediateActionController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ - (NSSize)menuItem:(NSMenuItem *)menuItem maxSizeForPoint:(NSPoint)point
if (!PAL::isDataDetectorsFrameworkAvailable())
return nil;

WKDDActionContext *actionContext = _hitTestResultData.platformData.detectedDataActionContext.get();
auto& detectedContext = _hitTestResultData.platformData.detectedDataActionContext;
if (!detectedContext)
return nil;

WKDDActionContext *actionContext = detectedContext->context.get();
if (!actionContext)
return nil;

Expand Down
6 changes: 4 additions & 2 deletions Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ static void drawPDFPage(PDFDocument *pdfDocument, CFIndex pageIndex, CGContextRe
continue;

pageOverlayDidOverrideDataDetectors = true;
immediateActionResult.platformData.detectedDataActionContext = actionContext->context.get();
if (auto* detectedContext = actionContext->context.get())
immediateActionResult.platformData.detectedDataActionContext = { { detectedContext } };
immediateActionResult.platformData.detectedDataBoundingBox = view->contentsToWindow(enclosingIntRect(unitedBoundingBoxes(RenderObject::absoluteTextQuads(actionContext->range))));
immediateActionResult.platformData.detectedDataTextIndicator = TextIndicator::createWithRange(actionContext->range, indicatorOptions(actionContext->range), TextIndicatorPresentationTransition::FadeIn);
immediateActionResult.platformData.detectedDataOriginatingPageOverlay = overlay->pageOverlayID();
Expand All @@ -922,7 +923,8 @@ static void drawPDFPage(PDFDocument *pdfDocument, CFIndex pageIndex, CGContextRe
// FIXME: Avoid scanning if we will just throw away the result (e.g. we're over a link).
if (!pageOverlayDidOverrideDataDetectors && hitTestResult.innerNode() && (hitTestResult.innerNode()->isTextNode() || hitTestResult.isOverTextInsideFormControlElement())) {
if (auto result = DataDetection::detectItemAroundHitTestResult(hitTestResult)) {
immediateActionResult.platformData.detectedDataActionContext = WTFMove(result->actionContext);
if (auto detectedContext = WTFMove(result->actionContext))
immediateActionResult.platformData.detectedDataActionContext = { { WTFMove(detectedContext) } };
immediateActionResult.platformData.detectedDataBoundingBox = result->boundingBox;
immediateActionResult.platformData.detectedDataTextIndicator = TextIndicator::createWithRange(result->range, indicatorOptions(result->range), TextIndicatorPresentationTransition::FadeIn);
}
Expand Down

0 comments on commit e3ec066

Please sign in to comment.