⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277479 in webkit


Ignore:
Timestamp:
May 13, 2021, 9:06:37 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[Cocoa] Plumb data detector results through some platform objects
​https://bugs.webkit.org/show_bug.cgi?id=225775
Work towards rdar://75504956

Reviewed by Tim Horton and Devin Rousso.

Source/WebCore:

Introduce a new struct to hold data detection results, and add it to the existing results object when
ENABLE(DATA_DETECTION) is defined.

No change in behavior.

  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • editing/cocoa/DataDetection.mm:

(WebCore::DataDetection::canBePresentedByDataDetectors):
(WebCore::DataDetection::canPresentDataDetectorsUIForElement):
(WebCore::resultIsURL):
(WebCore::constructURLStringForResult):
(WebCore::buildQuery):
(WebCore::DataDetection::detectContentInRange):

Add a PAL namespace to each of these DataDetectorsCore softlinking call sites, since the soft link header now
exists in PAL.

  • platform/ImageExtractionResult.h:

(WebCore::ImageExtractionDataDetectorInfo::ImageExtractionDataDetectorInfo):
(WebCore::ImageExtractionResult::isEmpty const):
(WebCore::ImageExtractionResult::encode const):
(WebCore::ImageExtractionResult::decode):

  • platform/cocoa/DataDetectorsCoreSoftLink.h: Removed.
  • platform/cocoa/DataDetectorsCoreSoftLink.mm: Removed.

Additionally, move DataDetectorsCoreSoftLink.{h|mm} out of WebCore/platform and into PAL as softlinking
headers, so that they can be imported in WebKit as well as WebCore.

Source/WebCore/PAL:

Move DataDetectorsCoreSoftLink.{h|mm} into PAL, so that it can be used in WebKit as well.

  • PAL.xcodeproj/project.pbxproj:
  • pal/PlatformMac.cmake:

Add the header and source file to the CMake build.

  • pal/cocoa/DataDetectorsCoreSoftLink.h: Added.
  • pal/cocoa/DataDetectorsCoreSoftLink.mm: Added.
  • pal/spi/cocoa/DataDetectorsCoreSPI.h:

Explicitly import Foundation headers here, so that the forward declarations don't cause compilation failures in
non-internal SDKs.

Source/WebKit:

Add IPC encoding and decoding support for the new struct.

  • Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:

(IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::encodePlatformData):
(IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::decodePlatformData):

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::encode):
(IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::decode):

  • Shared/WebCoreArgumentCoders.h:
Location:
trunk/Source
Files:
2 added
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277463 r277479  
     12021-05-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Cocoa] Plumb data detector results through some platform objects
     4        https://bugs.webkit.org/show_bug.cgi?id=225775
     5        Work towards rdar://75504956
     6
     7        Reviewed by Tim Horton and Devin Rousso.
     8
     9        Introduce a new struct to hold data detection results, and add it to the existing results object when
     10        `ENABLE(DATA_DETECTION)` is defined.
     11
     12        No change in behavior.
     13
     14        * SourcesCocoa.txt:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * editing/cocoa/DataDetection.mm:
     17        (WebCore::DataDetection::canBePresentedByDataDetectors):
     18        (WebCore::DataDetection::canPresentDataDetectorsUIForElement):
     19        (WebCore::resultIsURL):
     20        (WebCore::constructURLStringForResult):
     21        (WebCore::buildQuery):
     22        (WebCore::DataDetection::detectContentInRange):
     23
     24        Add a `PAL` namespace to each of these DataDetectorsCore softlinking call sites, since the soft link header now
     25        exists in PAL.
     26
     27        * platform/ImageExtractionResult.h:
     28        (WebCore::ImageExtractionDataDetectorInfo::ImageExtractionDataDetectorInfo):
     29        (WebCore::ImageExtractionResult::isEmpty const):
     30        (WebCore::ImageExtractionResult::encode const):
     31        (WebCore::ImageExtractionResult::decode):
     32        * platform/cocoa/DataDetectorsCoreSoftLink.h: Removed.
     33        * platform/cocoa/DataDetectorsCoreSoftLink.mm: Removed.
     34
     35        Additionally, move `DataDetectorsCoreSoftLink.{h|mm}` out of `WebCore/platform` and into PAL as softlinking
     36        headers, so that they can be imported in WebKit as well as WebCore.
     37
    1382021-05-13  Devin Rousso  <drousso@apple.com>
    239
  • trunk/Source/WebCore/PAL/ChangeLog

    r277464 r277479  
     12021-05-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Cocoa] Plumb data detector results through some platform objects
     4        https://bugs.webkit.org/show_bug.cgi?id=225775
     5        Work towards rdar://75504956
     6
     7        Reviewed by Tim Horton and Devin Rousso.
     8
     9        Move `DataDetectorsCoreSoftLink.{h|mm}` into PAL, so that it can be used in WebKit as well.
     10
     11        * PAL.xcodeproj/project.pbxproj:
     12        * pal/PlatformMac.cmake:
     13
     14        Add the header and source file to the CMake build.
     15
     16        * pal/cocoa/DataDetectorsCoreSoftLink.h: Added.
     17        * pal/cocoa/DataDetectorsCoreSoftLink.mm: Added.
     18        * pal/spi/cocoa/DataDetectorsCoreSPI.h:
     19
     20        Explicitly import Foundation headers here, so that the forward declarations don't cause compilation failures in
     21        non-internal SDKs.
     22
    1232021-05-13  Tim Horton  <timothy_horton@apple.com>
    224
  • trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

    r276615 r277479  
    208208                F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44291621FA52670002CC93E /* FileSizeFormatter.cpp */; };
    209209                F44291681FA52705002CC93E /* FileSizeFormatterCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */; };
     210                F4DDD01B264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4DDD019264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.mm */; };
     211                F4DDD01C264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = F4DDD01A264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.h */; };
    210212/* End PBXBuildFile section */
    211213
    … …  
    421423                F44291621FA52670002CC93E /* FileSizeFormatter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileSizeFormatter.cpp; sourceTree = "<group>"; };
    422424                F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSizeFormatterCocoa.mm; sourceTree = "<group>"; };
     425                F4DDD019264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorsCoreSoftLink.mm; sourceTree = "<group>"; };
     426                F4DDD01A264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsCoreSoftLink.h; sourceTree = "<group>"; };
    423427/* End PBXFileReference section */
    424428
    … …  
    708712                                57F1C90725DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h */,
    709713                                57F1C90825DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm */,
     714                                F4DDD01A264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.h */,
     715                                F4DDD019264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.mm */,
    710716                                F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */,
    711717                                1C022EFC22CFE8E0006DF01B /* Gunzip.cpp */,
    … …  
    848854                                57F1C90925DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h in Headers */,
    849855                                DF83E209263734F1000825EF /* CryptoKitCBridgingSPI.h in Headers */,
     856                                F4DDD01C264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.h in Headers */,
    850857                                0C2DA1411F3BEB4900DBC317 /* DataDetectorsCoreSPI.h in Headers */,
    851858                                0C77858A1F45130F00F4EBB6 /* DataDetectorsSPI.h in Headers */,
    … …  
    10601067                                1C09D0561E31C46500725F18 /* CryptoDigestCommonCrypto.cpp in Sources */,
    10611068                                57F1C90A25DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm in Sources */,
     1069                                F4DDD01B264DC69E00EF1B91 /* DataDetectorsCoreSoftLink.mm in Sources */,
    10621070                                A1175B581F6B470500C4B9F0 /* DefaultSearchProvider.cpp in Sources */,
    10631071                                F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */,
  • trunk/Source/WebCore/PAL/pal/PlatformMac.cmake

    r276614 r277479  
    1313    cocoa/AVFoundationSoftLink.h
    1414    cocoa/CryptoKitCBridgingSoftLink.h
     15    cocoa/DataDetectorsCoreSoftLink.h
    1516    cocoa/MediaToolboxSoftLink.h
    1617    cocoa/OpenGLSoftLinkCocoa.h
    … …  
    149150    cocoa/AVFoundationSoftLink.mm
    150151    cocoa/CryptoKitCBridgingSoftLink.mm
     152    cocoa/DataDetectorsCoreSoftLink.mm
    151153    cocoa/FileSizeFormatterCocoa.mm
    152154    cocoa/Gunzip.cpp
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/DataDetectorsCoreSPI.h

    r260366 r277479  
    4040
    4141#else // !USE(APPLE_INTERNAL_SDK)
     42
     43#import <Foundation/Foundation.h>
    4244
    4345typedef enum {
  • trunk/Source/WebCore/SourcesCocoa.txt

    r277364 r277479  
    238238platform/cocoa/ContentFilterUnblockHandlerCocoa.mm @no-unify
    239239platform/cocoa/CoreVideoSoftLink.cpp
    240 platform/cocoa/DataDetectorsCoreSoftLink.mm @no-unify
    241240platform/cocoa/DragDataCocoa.mm
    242241platform/cocoa/DragImageCocoa.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r277450 r277479  
    12581258                445210DF25D61F00003A2ED8 /* AppHighlight.h in Headers */ = {isa = PBXBuildFile; fileRef = 445210DD25D61EFF003A2ED8 /* AppHighlight.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12591259                445775E520472F73008DCE5D /* LocalDefaultSystemAppearance.h in Headers */ = {isa = PBXBuildFile; fileRef = 445775E420472F73008DCE5D /* LocalDefaultSystemAppearance.h */; settings = {ATTRIBUTES = (Private, ); }; };
    1260                 4463CF682212FA68001A8577 /* DataDetectorsCoreSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C7941E21C56C29300A4C58E /* DataDetectorsCoreSoftLink.mm */; };
    12611260                4465D7BD2536D05E0016666D /* SelectionRangeData.h in Headers */ = {isa = PBXBuildFile; fileRef = 44B38BF42536901A00A4458D /* SelectionRangeData.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12621261                446DC64824A29DAB0061F390 /* PlaybackTargetClientContextIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 446DC64624A29D9B0061F390 /* PlaybackTargetClientContextIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
    … …  
    23912390                7C77C3DC1DEF86D700A50BFA /* JSEndingType.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C77C3DA1DEF86D700A50BFA /* JSEndingType.h */; };
    23922391                7C7903B31F86F95C00463A70 /* ImageBitmapRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C7903B01F86F95C00463A70 /* ImageBitmapRenderingContext.h */; };
    2393                 7C7941E51C56C29300A4C58E /* DataDetectorsCoreSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C7941E31C56C29300A4C58E /* DataDetectorsCoreSoftLink.h */; };
    23942392                7C7BF9422516C90C00808682 /* PerformanceMarkOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C7BF93E2516C8BC00808682 /* PerformanceMarkOptions.h */; };
    23952393                7C7BF94C2516FA5400808682 /* PerformanceMeasureOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C7BF9492516FA5400808682 /* PerformanceMeasureOptions.h */; };
    … …  
    1070110699                7C7903BA1F86FF3300463A70 /* PlaceholderRenderingContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlaceholderRenderingContext.cpp; sourceTree = "<group>"; };
    1070210700                7C7903BC1F86FF3400463A70 /* PlaceholderRenderingContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlaceholderRenderingContext.h; sourceTree = "<group>"; };
    10703                 7C7941E21C56C29300A4C58E /* DataDetectorsCoreSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorsCoreSoftLink.mm; sourceTree = "<group>"; };
    10704                 7C7941E31C56C29300A4C58E /* DataDetectorsCoreSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsCoreSoftLink.h; sourceTree = "<group>"; };
    1070510701                7C7BF93E2516C8BC00808682 /* PerformanceMarkOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PerformanceMarkOptions.h; sourceTree = "<group>"; };
    1070610702                7C7BF9402516C8BC00808682 /* PerformanceMarkOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PerformanceMarkOptions.idl; sourceTree = "<group>"; };
    … …  
    2489024886                                CD7D33451C7A16BF00041293 /* CoreVideoSoftLink.cpp */,
    2489124887                                CD7D33461C7A16BF00041293 /* CoreVideoSoftLink.h */,
    24892                                 7C7941E31C56C29300A4C58E /* DataDetectorsCoreSoftLink.h */,
    24893                                 7C7941E21C56C29300A4C58E /* DataDetectorsCoreSoftLink.mm */,
    2489424888                                F462E79F242ADA3C00204DDD /* DragDataCocoa.mm */,
    2489524889                                F462E7A0242ADA3D00204DDD /* DragImageCocoa.mm */,
    … …  
    3216032154                                BE23480D18A9871400E4B6E8 /* DataCue.h in Headers */,
    3216132155                                C5227DF11C3C6DF100F5ED54 /* DataDetection.h in Headers */,
    32162                                 7C7941E51C56C29300A4C58E /* DataDetectorsCoreSoftLink.h in Headers */,
    3216332156                                BC4A533525605A560028C592 /* DataDetectorType.h in Headers */,
    3216432157                                E58B45BA20AD07DD00991025 /* DataListButtonElement.h in Headers */,
    … …  
    3646736460                                2D22830323A8470700364B7E /* CursorMac.mm in Sources */,
    3646836461                                5CBD59592280E926002B22AA /* CustomHeaderFields.cpp in Sources */,
    36469                                 4463CF682212FA68001A8577 /* DataDetectorsCoreSoftLink.mm in Sources */,
    3647036462                                6E72F54C229DCD0C00B3E151 /* ExtensionsGLANGLE.cpp in Sources */,
    3647136463                                7CE6CBFD187F394900D46BF5 /* FormatConverter.cpp in Sources */,
  • trunk/Source/WebCore/editing/cocoa/DataDetection.mm

    r277437 r277479  
    5151#import "VisiblePosition.h"
    5252#import "VisibleUnits.h"
     53#import <pal/cocoa/DataDetectorsCoreSoftLink.h>
    5354#import <pal/spi/ios/DataDetectorsUISPI.h>
    5455#import <pal/spi/mac/DataDetectorsSPI.h>
    … …  
    5657#import <wtf/text/StringBuilder.h>
    5758#import <wtf/text/StringToIntegerConversion.h>
    58 
    59 #import "DataDetectorsCoreSoftLink.h"
    6059
    6160#if PLATFORM(MAC)
    … …  
    167166bool DataDetection::canBePresentedByDataDetectors(const URL& url)
    168167{
    169     return [softLink_DataDetectorsCore_DDURLTapAndHoldSchemes() containsObject:(NSString *)url.protocol().toStringWithoutCopying().convertToASCIILowercase()];
     168    return [PAL::softLink_DataDetectorsCore_DDURLTapAndHoldSchemes() containsObject:(NSString *)url.protocol().toStringWithoutCopying().convertToASCIILowercase()];
    170169}
    171170
    … …  
    193192        return false;
    194193   
    195     if (softLink_DataDetectorsCore_DDShouldImmediatelyShowActionSheetForURL(downcast<HTMLAnchorElement>(element).href()))
     194    if (PAL::softLink_DataDetectorsCore_DDShouldImmediatelyShowActionSheetForURL(downcast<HTMLAnchorElement>(element).href()))
    196195        return true;
    197196   
    … …  
    209208    // Handle the case of a signature block, where we need to follow the path down one or more subresult levels.
    210209    while (++indexIterator != resultIndices.end()) {
    211         results = (__bridge NSArray *)softLink_DataDetectorsCore_DDResultGetSubResults(result);
     210        results = (__bridge NSArray *)PAL::softLink_DataDetectorsCore_DDResultGetSubResults(result);
    212211        result = (__bridge DDResultRef)results[parseIntegerAllowingTrailingJunk<int>(*indexIterator).valueOr(0)];
    213212    }
    214213
    215     return softLink_DataDetectorsCore_DDShouldImmediatelyShowActionSheetForResult(result);
     214    return PAL::softLink_DataDetectorsCore_DDShouldImmediatelyShowActionSheetForResult(result);
    216215}
    217216
    … …  
    222221   
    223222    static NeverDestroyed<RetainPtr<NSSet>> urlTypes = [NSSet setWithObjects:
    224         (NSString *)get_DataDetectorsCore_DDBinderHttpURLKey(),
    225         (NSString *)get_DataDetectorsCore_DDBinderWebURLKey(),
    226         (NSString *)get_DataDetectorsCore_DDBinderMailURLKey(),
    227         (NSString *)get_DataDetectorsCore_DDBinderGenericURLKey(),
    228         (NSString *)get_DataDetectorsCore_DDBinderEmailKey(), nil];
    229     return [urlTypes.get() containsObject:(NSString *)softLink_DataDetectorsCore_DDResultGetType(result)];
     223        (NSString *)PAL::get_DataDetectorsCore_DDBinderHttpURLKey(),
     224        (NSString *)PAL::get_DataDetectorsCore_DDBinderWebURLKey(),
     225        (NSString *)PAL::get_DataDetectorsCore_DDBinderMailURLKey(),
     226        (NSString *)PAL::get_DataDetectorsCore_DDBinderGenericURLKey(),
     227        (NSString *)PAL::get_DataDetectorsCore_DDBinderEmailKey(), nil];
     228    return [urlTypes.get() containsObject:(NSString *)PAL::softLink_DataDetectorsCore_DDResultGetType(result)];
    230229}
    231230
    232231static NSString *constructURLStringForResult(DDResultRef currentResult, NSString *resultIdentifier, NSDate *referenceDate, NSTimeZone *referenceTimeZone, OptionSet<DataDetectorType> detectionTypes)
    233232{
    234     if (!softLink_DataDetectorsCore_DDResultHasProperties(currentResult, DDResultPropertyPassiveDisplay))
     233    if (!PAL::softLink_DataDetectorsCore_DDResultHasProperties(currentResult, DDResultPropertyPassiveDisplay))
    235234        return nil;
    236235
    237236    auto phoneTypes = detectionTypes.contains(DataDetectorType::PhoneNumber) ? DDURLifierPhoneNumberDetectionRegular : DDURLifierPhoneNumberDetectionNone;
    238     auto category = softLink_DataDetectorsCore_DDResultGetCategory(currentResult);
    239     auto type = softLink_DataDetectorsCore_DDResultGetType(currentResult);
     237    auto category = PAL::softLink_DataDetectorsCore_DDResultGetCategory(currentResult);
     238    auto type = PAL::softLink_DataDetectorsCore_DDResultGetType(currentResult);
    240239
    241240    if ((detectionTypes.contains(DataDetectorType::Address) && DDResultCategoryAddress == category)
    242         || (detectionTypes.contains(DataDetectorType::TrackingNumber) && CFEqual(get_DataDetectorsCore_DDBinderTrackingNumberKey(), type))
    243         || (detectionTypes.contains(DataDetectorType::FlightNumber) && CFEqual(get_DataDetectorsCore_DDBinderFlightInformationKey(), type))
    244         || (detectionTypes.contains(DataDetectorType::LookupSuggestion) && CFEqual(get_DataDetectorsCore_DDBinderParsecSourceKey(), type))
     241        || (detectionTypes.contains(DataDetectorType::TrackingNumber) && CFEqual(PAL::get_DataDetectorsCore_DDBinderTrackingNumberKey(), type))
     242        || (detectionTypes.contains(DataDetectorType::FlightNumber) && CFEqual(PAL::get_DataDetectorsCore_DDBinderFlightInformationKey(), type))
     243        || (detectionTypes.contains(DataDetectorType::LookupSuggestion) && CFEqual(PAL::get_DataDetectorsCore_DDBinderParsecSourceKey(), type))
    245244        || (detectionTypes.contains(DataDetectorType::PhoneNumber) && DDResultCategoryPhoneNumber == category)
    246245        || (detectionTypes.contains(DataDetectorType::Link) && resultIsURL(currentResult))) {
    247         return softLink_DataDetectorsCore_DDURLStringForResult(currentResult, resultIdentifier, phoneTypes, referenceDate, referenceTimeZone);
     246        return PAL::softLink_DataDetectorsCore_DDURLStringForResult(currentResult, resultIdentifier, phoneTypes, referenceDate, referenceTimeZone);
    248247    }
    249248    if (detectionTypes.contains(DataDetectorType::CalendarEvent) && DDResultCategoryCalendarEvent == category) {
    250         if (!softLink_DataDetectorsCore_DDResultIsPastDate(currentResult, (CFDateRef)referenceDate, (CFTimeZoneRef)referenceTimeZone))
    251             return softLink_DataDetectorsCore_DDURLStringForResult(currentResult, resultIdentifier, phoneTypes, referenceDate, referenceTimeZone);
     249        if (!PAL::softLink_DataDetectorsCore_DDResultIsPastDate(currentResult, (CFDateRef)referenceDate, (CFTimeZoneRef)referenceTimeZone))
     250            return PAL::softLink_DataDetectorsCore_DDURLStringForResult(currentResult, resultIdentifier, phoneTypes, referenceDate, referenceTimeZone);
    252251    }
    253252    return nil;
    … …  
    360359        size_t currentTextLength = currentText.length();
    361360        if (!currentTextLength) {
    362             softLink_DataDetectorsCore_DDScanQueryAddSeparator(scanQuery, DDTextCoalescingTypeHardBreak);
     361            PAL::softLink_DataDetectorsCore_DDScanQueryAddSeparator(scanQuery, DDTextCoalescingTypeHardBreak);
    363362            if (iteratorCount > maxFragmentWithHardBreak)
    364363                break;
    … …  
    395394        if (containsOnlyWhiteSpace) {
    396395            if (hasNewline) {
    397                 softLink_DataDetectorsCore_DDScanQueryAddLineBreak(scanQuery);
     396                PAL::softLink_DataDetectorsCore_DDScanQueryAddLineBreak(scanQuery);
    398397                if (iteratorCount > maxFragmentWithLinebreak)
    399398                    break;
    400399            } else {
    401                 softLink_DataDetectorsCore_DDScanQueryAddSeparator(scanQuery, hasTab ? DDTextCoalescingTypeTab : DDTextCoalescingTypeSpace);
     400                PAL::softLink_DataDetectorsCore_DDScanQueryAddSeparator(scanQuery, hasTab ? DDTextCoalescingTypeTab : DDTextCoalescingTypeSpace);
    402401                if (iteratorCount > maxFragmentSpace)
    403402                    break;
    … …  
    407406       
    408407        auto currentTextCFString = adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(currentTextUpconvertedCharacters.get()), currentTextLength));
    409         softLink_DataDetectorsCore_DDScanQueryAddTextFragment(scanQuery, currentTextCFString.get(), CFRangeMake(0, currentTextLength), (void *)iteratorCount, (DDTextFragmentMode)0, DDTextCoalescingTypeNone);
     408        PAL::softLink_DataDetectorsCore_DDScanQueryAddTextFragment(scanQuery, currentTextCFString.get(), CFRangeMake(0, currentTextLength), (void *)iteratorCount, (DDTextFragmentMode)0, DDTextCoalescingTypeNone);
    410409        fragmentCount++;
    411410    }
    … …  
    437436NSArray *DataDetection::detectContentInRange(const SimpleRange& contextRange, OptionSet<DataDetectorType> types, NSDictionary *context)
    438437{
    439     auto scanner = adoptCF(softLink_DataDetectorsCore_DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
    440     auto scanQuery = adoptCF(softLink_DataDetectorsCore_DDScanQueryCreate(NULL));
     438    auto scanner = adoptCF(PAL::softLink_DataDetectorsCore_DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
     439    auto scanQuery = adoptCF(PAL::softLink_DataDetectorsCore_DDScanQueryCreate(NULL));
    441440    buildQuery(scanQuery.get(), contextRange);
    442441   
    443442    if (types.contains(DataDetectorType::LookupSuggestion))
    444         softLink_DataDetectorsCore_DDScannerEnableOptionalSource(scanner.get(), DDScannerSourceSpotlight, true);
     443        PAL::softLink_DataDetectorsCore_DDScannerEnableOptionalSource(scanner.get(), DDScannerSourceSpotlight, true);
    445444
    446445    // FIXME: we should add a timeout to this call to make sure it doesn't take too much time.
    447     if (!softLink_DataDetectorsCore_DDScannerScanQuery(scanner.get(), scanQuery.get()))
     446    if (!PAL::softLink_DataDetectorsCore_DDScannerScanQuery(scanner.get(), scanQuery.get()))
    448447        return nil;
    449448
    450     auto scannerResults = adoptCF(softLink_DataDetectorsCore_DDScannerCopyResultsWithOptions(scanner.get(), get_DataDetectorsCore_DDScannerCopyResultsOptionsForPassiveUse() | DDScannerCopyResultsOptionsCoalesceSignatures));
     449    auto scannerResults = adoptCF(PAL::softLink_DataDetectorsCore_DDScannerCopyResultsWithOptions(scanner.get(), PAL::get_DataDetectorsCore_DDScannerCopyResultsOptionsForPassiveUse() | DDScannerCopyResultsOptionsCoalesceSignatures));
    451450    if (!scannerResults)
    452451        return nil;
    … …  
    464463        DDResultRef result = (DDResultRef)resultObject;
    465464        NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:currentTopLevelIndex];
    466         if (CFEqual(softLink_DataDetectorsCore_DDResultGetType(result), get_DataDetectorsCore_DDBinderSignatureBlockKey())) {
    467             NSArray *subresults = (NSArray *)softLink_DataDetectorsCore_DDResultGetSubResults(result);
     465        if (CFEqual(PAL::softLink_DataDetectorsCore_DDResultGetType(result), PAL::get_DataDetectorsCore_DDBinderSignatureBlockKey())) {
     466            NSArray *subresults = (NSArray *)PAL::softLink_DataDetectorsCore_DDResultGetSubResults(result);
    468467           
    469468            for (NSUInteger subResultIndex = 0 ; subResultIndex < [subresults count] ; subResultIndex++) {
    … …  
    486485    // Each result can be contained all in one text node or can span multiple text nodes.
    487486    for (auto& result : allResults) {
    488         DDQueryRange queryRange = softLink_DataDetectorsCore_DDResultGetQueryRangeForURLification(result.get());
    489         CFIndex iteratorTargetAdvanceCount = (CFIndex)softLink_DataDetectorsCore_DDScanQueryGetFragmentMetaData(scanQuery.get(), queryRange.start.queryIndex);
     487        DDQueryRange queryRange = PAL::softLink_DataDetectorsCore_DDResultGetQueryRangeForURLification(result.get());
     488        CFIndex iteratorTargetAdvanceCount = (CFIndex)PAL::softLink_DataDetectorsCore_DDScanQueryGetFragmentMetaData(scanQuery.get(), queryRange.start.queryIndex);
    490489        for (; iteratorCount < iteratorTargetAdvanceCount; ++iteratorCount)
    491490            iterator.advance();
    … …  
    506505        while (fragmentIndex < queryRange.end.queryIndex) {
    507506            ++fragmentIndex;
    508             iteratorTargetAdvanceCount = (CFIndex)softLink_DataDetectorsCore_DDScanQueryGetFragmentMetaData(scanQuery.get(), fragmentIndex);
     507            iteratorTargetAdvanceCount = (CFIndex)PAL::softLink_DataDetectorsCore_DDScanQueryGetFragmentMetaData(scanQuery.get(), fragmentIndex);
    509508            for (; iteratorCount < iteratorTargetAdvanceCount; ++iteratorCount)
    510509                iterator.advance();
    … …  
    535534    for (CFIndex resultIndex = 0; resultIndex < resultCount; ++resultIndex) {
    536535        DDResultRef coreResult = allResults[resultIndex].get();
    537         DDQueryRange queryRange = softLink_DataDetectorsCore_DDResultGetQueryRangeForURLification(coreResult);
     536        DDQueryRange queryRange = PAL::softLink_DataDetectorsCore_DDResultGetQueryRangeForURLification(coreResult);
    538537        auto& resultRanges = allResultRanges[resultIndex];
    539538
    … …  
    552551
    553552        lastModifiedQueryOffset = queryRange.end;
    554         BOOL shouldUseLightLinks = softLink_DataDetectorsCore_DDShouldUseLightLinksForResult(coreResult, [indexPaths[resultIndex] length] > 1);
     553        BOOL shouldUseLightLinks = PAL::softLink_DataDetectorsCore_DDShouldUseLightLinksForResult(coreResult, [indexPaths[resultIndex] length] > 1);
    555554
    556555        for (auto& range : resultRanges) {
    … …  
    617616            // Add a special attribute to mark this URLification as the result of data detectors.
    618617            anchorElement->setAttributeWithoutSynchronization(x_apple_data_detectorsAttr, AtomString("true", AtomString::ConstructFromLiteral));
    619             anchorElement->setAttributeWithoutSynchronization(x_apple_data_detectors_typeAttr, dataDetectorTypeForCategory(softLink_DataDetectorsCore_DDResultGetCategory(coreResult)));
     618            anchorElement->setAttributeWithoutSynchronization(x_apple_data_detectors_typeAttr, dataDetectorTypeForCategory(PAL::softLink_DataDetectorsCore_DDResultGetCategory(coreResult)));
    620619            anchorElement->setAttributeWithoutSynchronization(x_apple_data_detectors_resultAttr, identifier);
    621620
    … …  
    632631        lastTextNodeToUpdate->setData(lastNodeContent);
    633632
    634     return [getDDScannerResultClass() resultsFromCoreResults:scannerResults.get()];
     633    return [PAL::getDDScannerResultClass() resultsFromCoreResults:scannerResults.get()];
    635634}
    636635
  • trunk/Source/WebCore/platform/ImageExtractionResult.h

    r276626 r277479  
    2828#if ENABLE(IMAGE_EXTRACTION)
    2929
     30#if ENABLE(DATA_DETECTION)
     31OBJC_CLASS DDScannerResult;
     32#endif
     33
    3034#include "FloatQuad.h"
    3135#include <wtf/Optional.h>
     36#include <wtf/RetainPtr.h>
    3237#include <wtf/text/WTFString.h>
    3338
    … …  
    8388};
    8489
     90#if ENABLE(DATA_DETECTION)
     91
     92struct ImageExtractionDataDetectorInfo {
     93    ImageExtractionDataDetectorInfo() = default;
     94    ImageExtractionDataDetectorInfo(DDScannerResult *scannerResult, Vector<FloatQuad>&& quads)
     95        : result(scannerResult)
     96        , normalizedQuads(WTFMove(quads))
     97    {
     98    }
     99
     100    RetainPtr<DDScannerResult> result;
     101    Vector<FloatQuad> normalizedQuads;
     102};
     103
     104#endif // ENABLE(DATA_DETECTION)
     105
    85106template<class Encoder> void ImageExtractionLineData::encode(Encoder& encoder) const
    86107{
    … …  
    107128    Vector<ImageExtractionLineData> lines;
    108129
    109     bool isEmpty() const { return lines.isEmpty(); }
     130#if ENABLE(DATA_DETECTION)
     131    Vector<ImageExtractionDataDetectorInfo> dataDetectors;
     132#endif
     133
     134    bool isEmpty() const
     135    {
     136        if (!lines.isEmpty())
     137            return false;
     138
     139#if ENABLE(DATA_DETECTION)
     140        if (!dataDetectors.isEmpty())
     141            return false;
     142#endif
     143
     144        return true;
     145    }
    110146
    111147    template<class Encoder> void encode(Encoder&) const;
    … …  
    116152{
    117153    encoder << lines;
     154#if ENABLE(DATA_DETECTION)
     155    encoder << dataDetectors;
     156#endif
    118157}
    119158
    … …  
    125164        return WTF::nullopt;
    126165
    127     return {{ WTFMove(*lines) }};
     166#if ENABLE(DATA_DETECTION)
     167    Optional<Vector<ImageExtractionDataDetectorInfo>> dataDetectors;
     168    decoder >> dataDetectors;
     169    if (!dataDetectors)
     170        return WTF::nullopt;
     171#endif
     172
     173    return {{
     174        WTFMove(*lines),
     175#if ENABLE(DATA_DETECTION)
     176        WTFMove(*dataDetectors),
     177#endif
     178    }};
    128179}
    129180
  • trunk/Source/WebKit/ChangeLog

    r277468 r277479  
     12021-05-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Cocoa] Plumb data detector results through some platform objects
     4        https://bugs.webkit.org/show_bug.cgi?id=225775
     5        Work towards rdar://75504956
     6
     7        Reviewed by Tim Horton and Devin Rousso.
     8
     9        Add IPC encoding and decoding support for the new struct.
     10
     11        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
     12        (IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::encodePlatformData):
     13        (IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::decodePlatformData):
     14        * Shared/WebCoreArgumentCoders.cpp:
     15        (IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::encode):
     16        (IPC::ArgumentCoder<ImageExtractionDataDetectorInfo>::decode):
     17        * Shared/WebCoreArgumentCoders.h:
     18
    1192021-05-13  Dean Jackson  <dino@apple.com>
    220
  • trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm

    r276510 r277479  
    5151#endif
    5252
     53#if ENABLE(IMAGE_EXTRACTION)
     54#import <WebCore/ImageExtractionResult.h>
     55#endif
     56
    5357#if ENABLE(APPLE_PAY)
    5458#import "DataReference.h"
    … …  
    5963#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    6064#import <pal/cocoa/AVFoundationSoftLink.h>
     65#endif
     66
     67#if ENABLE(DATA_DETECTION)
     68#import <pal/cocoa/DataDetectorsCoreSoftLink.h>
    6169#endif
    6270
    … …  
    652660#endif
    653661
     662#if ENABLE(IMAGE_EXTRACTION) && ENABLE(DATA_DETECTION)
     663
     664void ArgumentCoder<ImageExtractionDataDetectorInfo>::encodePlatformData(Encoder& encoder, const ImageExtractionDataDetectorInfo& info)
     665{
     666    encoder << info.result.get();
     667}
     668
     669bool ArgumentCoder<ImageExtractionDataDetectorInfo>::decodePlatformData(Decoder& decoder, ImageExtractionDataDetectorInfo& result)
     670{
     671    auto scannerResult = IPC::decode<DDScannerResult>(decoder, @[ PAL::getDDScannerResultClass() ]);
     672    if (!scannerResult)
     673        return false;
     674
     675    result.result = WTFMove(*scannerResult);
     676    return true;
     677}
     678
     679#endif // ENABLE(IMAGE_EXTRACTION) && ENABLE(DATA_DETECTION)
     680
    654681} // namespace IPC
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r277313 r277479  
    5454#include <WebCore/FilterOperation.h>
    5555#include <WebCore/FilterOperations.h>
     56#include <WebCore/FloatQuad.h>
    5657#include <WebCore/Font.h>
    5758#include <WebCore/FontAttributes.h>
    … …  
    103104
    104105#if PLATFORM(IOS_FAMILY)
    105 #include <WebCore/FloatQuad.h>
    106106#include <WebCore/SelectionGeometry.h>
    107107#include <WebCore/SharedBuffer.h>
    … …  
    115115#include <WebCore/CaptureDevice.h>
    116116#include <WebCore/MediaConstraints.h>
     117#endif
     118
     119#if ENABLE(IMAGE_EXTRACTION)
     120#include <WebCore/ImageExtractionResult.h>
    117121#endif
    118122
    … …  
    31993203#endif
    32003204
     3205#if ENABLE(IMAGE_EXTRACTION) && ENABLE(DATA_DETECTION)
     3206
     3207void ArgumentCoder<ImageExtractionDataDetectorInfo>::encode(Encoder& encoder, const ImageExtractionDataDetectorInfo& info)
     3208{
     3209    encodePlatformData(encoder, info);
     3210    encoder << info.normalizedQuads;
     3211}
     3212
     3213Optional<ImageExtractionDataDetectorInfo> ArgumentCoder<ImageExtractionDataDetectorInfo>::decode(Decoder& decoder)
     3214{
     3215    ImageExtractionDataDetectorInfo result;
     3216    if (!decodePlatformData(decoder, result))
     3217        return WTF::nullopt;
     3218
     3219    Optional<Vector<FloatQuad>> normalizedQuads;
     3220    decoder >> normalizedQuads;
     3221    if (!normalizedQuads)
     3222        return WTF::nullopt;
     3223
     3224    result.normalizedQuads = WTFMove(*normalizedQuads);
     3225    return WTFMove(result);
     3226}
     3227
     3228#endif // ENABLE(IMAGE_EXTRACTION) && ENABLE(DATA_DETECTION)
     3229
    32013230} // namespace IPC
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h

    r277362 r277479  
    148148struct FontAttributes;
    149149struct FileChooserSettings;
     150struct ImageExtractionDataDetectorInfo;
    150151struct RawFile;
    151152struct ShareData;
    … …  
    825826#endif
    826827
     828#if ENABLE(IMAGE_EXTRACTION) && ENABLE(DATA_DETECTION)
     829
     830template<> struct ArgumentCoder<WebCore::ImageExtractionDataDetectorInfo> {
     831    static void encode(Encoder&, const WebCore::ImageExtractionDataDetectorInfo&);
     832    static WARN_UNUSED_RETURN Optional<WebCore::ImageExtractionDataDetectorInfo> decode(Decoder&);
     833    static void encodePlatformData(Encoder&, const WebCore::ImageExtractionDataDetectorInfo&);
     834    static WARN_UNUSED_RETURN bool decodePlatformData(Decoder&, WebCore::ImageExtractionDataDetectorInfo&);
     835};
     836
     837#endif // ENABLE(IMAGE_EXTRACTION) && ENABLE(DATA_DETECTION)
     838
    827839} // namespace IPC
    828840
Note: See TracChangeset for help on using the changeset viewer.