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

Changeset 271187 in webkit


Ignore:
Timestamp:
Jan 5, 2021, 7:03:44 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Use sendWithAsyncReply instead of AttributedStringForCharacterRangeCallback and FontAtSelectionCallback
https://bugs.webkit.org/show_bug.cgi?id=220344

Patch by Alex Christensen <achristensen@webkit.org> on 2021-01-05
Reviewed by Geoffrey Garen.

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::updateFontManagerIfNeeded):
(WebKit::WebViewImpl::attributedSubstringForProposedRange):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::attributedSubstringForCharacterRangeAsync):
(WebKit::WebPageProxy::fontAtSelection):
(WebKit::WebPageProxy::attributedStringForCharacterRangeCallback): Deleted.
(WebKit::WebPageProxy::fontAtSelectionCallback): Deleted.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
(WebKit::WebPage::fontAtSelection):

Location:
trunk/Source/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r271184 r271187  
     12021-01-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        Use sendWithAsyncReply instead of AttributedStringForCharacterRangeCallback and FontAtSelectionCallback
     4        https://bugs.webkit.org/show_bug.cgi?id=220344
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * UIProcess/Cocoa/WebViewImpl.mm:
     9        (WebKit::WebViewImpl::updateFontManagerIfNeeded):
     10        (WebKit::WebViewImpl::attributedSubstringForProposedRange):
     11        * UIProcess/WebPageProxy.h:
     12        * UIProcess/WebPageProxy.messages.in:
     13        * UIProcess/mac/WebPageProxyMac.mm:
     14        (WebKit::WebPageProxy::attributedSubstringForCharacterRangeAsync):
     15        (WebKit::WebPageProxy::fontAtSelection):
     16        (WebKit::WebPageProxy::attributedStringForCharacterRangeCallback): Deleted.
     17        (WebKit::WebPageProxy::fontAtSelectionCallback): Deleted.
     18        * WebProcess/WebPage/WebPage.h:
     19        * WebProcess/WebPage/WebPage.messages.in:
     20        * WebProcess/WebPage/mac/WebPageMac.mm:
     21        (WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
     22        (WebKit::WebPage::fontAtSelection):
     23
    1242021-01-05  John Wilander  <wilander@apple.com>
    225
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r271162 r271187  
    29522952        return;
    29532953
    2954     m_page->fontAtSelection([](const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts, CallbackBase::Error error) {
    2955         if (error != CallbackBase::Error::None)
    2956             return;
     2954    m_page->fontAtSelection([](const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts) {
    29572955
    29582956        BEGIN_BLOCK_OBJC_EXCEPTIONS
     
    50265024}
    50275025
    5028 void WebViewImpl::attributedSubstringForProposedRange(NSRange proposedRange, void(^completionHandlerPtr)(NSAttributedString *attrString, NSRange actualRange))
    5029 {
    5030     auto completionHandler = adoptNS([completionHandlerPtr copy]);
    5031 
     5026void WebViewImpl::attributedSubstringForProposedRange(NSRange proposedRange, void(^completionHandler)(NSAttributedString *attrString, NSRange actualRange))
     5027{
    50325028    LOG(TextInput, "attributedSubstringFromRange:(%u, %u)", proposedRange.location, proposedRange.length);
    5033     m_page->attributedSubstringForCharacterRangeAsync(proposedRange, [completionHandler](const WebCore::AttributedString& string, const EditingRange& actualRange, WebKit::CallbackBase::Error error) {
    5034         void (^completionHandlerBlock)(NSAttributedString *, NSRange) = (void (^)(NSAttributedString *, NSRange))completionHandler.get();
    5035         if (error != WebKit::CallbackBase::Error::None) {
    5036             LOG(TextInput, "    ...attributedSubstringFromRange failed.");
    5037             completionHandlerBlock(0, NSMakeRange(NSNotFound, 0));
    5038             return;
    5039         }
     5029    m_page->attributedSubstringForCharacterRangeAsync(proposedRange, [completionHandler = makeBlockPtr(completionHandler)](const WebCore::AttributedString& string, const EditingRange& actualRange) {
    50405030        LOG(TextInput, "    -> attributedSubstringFromRange returned %@", string.string.get());
    5041         completionHandlerBlock(string.string.get(), actualRange);
     5031        completionHandler(string.string.get(), actualRange);
    50425032    });
    50435033}
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r271171 r271187  
    400400#endif
    401401
    402 #if PLATFORM(MAC)
    403 typedef GenericCallback<const WebCore::AttributedString&, const EditingRange&> AttributedStringForCharacterRangeCallback;
    404 typedef GenericCallback<const FontInfo&, double, bool> FontAtSelectionCallback;
    405 #endif
    406 
    407402#if PLATFORM(IOS_FAMILY)
    408403typedef GenericCallback<const WebCore::IntPoint&, GestureType, GestureRecognizerState, OptionSet<SelectionFlags>> GestureCallback;
     
    906901
    907902#if PLATFORM(MAC)
    908     void attributedSubstringForCharacterRangeAsync(const EditingRange&, Function<void(const WebCore::AttributedString&, const EditingRange&, CallbackBase::Error)>&&);
    909     void fontAtSelection(Function<void(const FontInfo&, double, bool, CallbackBase::Error)>&&);
     903    void attributedSubstringForCharacterRangeAsync(const EditingRange&, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&&);
     904    void fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&&);
    910905
    911906    void startWindowDrag();
     
    21592154#endif
    21602155#if PLATFORM(MAC)
    2161     void attributedStringForCharacterRangeCallback(const WebCore::AttributedString&, const EditingRange&, CallbackID);
    21622156    void fontAtSelectionCallback(const FontInfo&, double, bool, CallbackID);
    21632157#endif
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r271162 r271187  
    174174    ApplicationManifestCallback(Optional<WebCore::ApplicationManifest> manifest, WebKit::CallbackID callbackID)
    175175#endif
    176 #if PLATFORM(MAC)
    177     AttributedStringForCharacterRangeCallback(struct WebCore::AttributedString string, struct WebKit::EditingRange actualRange, WebKit::CallbackID callbackID)
    178     FontAtSelectionCallback(struct WebKit::FontInfo fontInfo, double fontSize, bool selectionHasMultipleFonts, WebKit::CallbackID callbackID)
    179 #endif
    180176#if PLATFORM(IOS_FAMILY)
    181177    GestureCallback(WebCore::IntPoint point, enum:uint8_t WebKit::GestureType gestureType, enum:uint8_t WebKit::GestureRecognizerState gestureState, OptionSet<WebKit::SelectionFlags> flags, WebKit::CallbackID callbackID)
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r270946 r271187  
    193193}
    194194
    195 void WebPageProxy::attributedSubstringForCharacterRangeAsync(const EditingRange& range, Function<void(const WebCore::AttributedString&, const EditingRange&, CallbackBase::Error)>&& callbackFunction)
     195void WebPageProxy::attributedSubstringForCharacterRangeAsync(const EditingRange& range, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&& callbackFunction)
    196196{
    197197    if (!hasRunningProcess()) {
    198         callbackFunction({ }, EditingRange(), CallbackBase::Error::Unknown);
    199         return;
    200     }
    201 
    202     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::attributedSubstringForCharacterRangeAsync"_s));
    203 
    204     send(Messages::WebPage::AttributedSubstringForCharacterRangeAsync(range, callbackID));
    205 }
    206 
    207 void WebPageProxy::attributedStringForCharacterRangeCallback(const WebCore::AttributedString& string, const EditingRange& actualRange, CallbackID callbackID)
    208 {
    209     MESSAGE_CHECK(actualRange.isValid());
    210 
    211     auto callback = m_callbacks.take<AttributedStringForCharacterRangeCallback>(callbackID);
    212     if (!callback) {
    213         // FIXME: Log error or assert.
    214         // this can validly happen if a load invalidated the callback, though
    215         return;
    216     }
    217 
    218     callback->performCallbackWithReturnValue(string, actualRange);
    219 }
    220 
    221 void WebPageProxy::fontAtSelection(Function<void(const FontInfo&, double, bool, CallbackBase::Error)>&& callback)
     198        callbackFunction({ }, { });
     199        return;
     200    }
     201
     202    sendWithAsyncReply(Messages::WebPage::AttributedSubstringForCharacterRangeAsync(range), WTFMove(callbackFunction));
     203}
     204
     205void WebPageProxy::fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&& callback)
    222206{
    223207    if (!hasRunningProcess()) {
    224         callback({ }, 0, false, CallbackBase::Error::Unknown);
    225         return;
    226     }
    227 
    228     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::fontAtSelection"_s));
    229     send(Messages::WebPage::FontAtSelection(callbackID));
    230 }
    231 
    232 void WebPageProxy::fontAtSelectionCallback(const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts, CallbackID callbackID)
    233 {
    234     auto callback = m_callbacks.take<FontAtSelectionCallback>(callbackID);
    235     if (!callback) {
    236         // FIXME: Log error or assert.
    237         return;
    238     }
    239 
    240     callback->performCallbackWithReturnValue(fontInfo, fontSize, selectionHasMultipleFonts);
     208        callback({ }, 0, false);
     209        return;
     210    }
     211
     212    sendWithAsyncReply(Messages::WebPage::FontAtSelection(), WTFMove(callback));
    241213}
    242214
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r271171 r271187  
    904904
    905905#if PLATFORM(MAC)
    906     void attributedSubstringForCharacterRangeAsync(const EditingRange&, CallbackID);
    907     void fontAtSelection(CallbackID);
     906    void attributedSubstringForCharacterRangeAsync(const EditingRange&, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&&);
     907    void fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&&);
    908908#endif
    909909
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r271171 r271187  
    458458#endif
    459459#if PLATFORM(MAC)
    460     AttributedSubstringForCharacterRangeAsync(struct WebKit::EditingRange range, WebKit::CallbackID callbackID);
    461     FontAtSelection(WebKit::CallbackID callbackID)
     460    AttributedSubstringForCharacterRangeAsync(struct WebKit::EditingRange range) -> (struct WebCore::AttributedString string, struct WebKit::EditingRange range) Async
     461    FontAtSelection() -> (struct WebKit::FontInfo fontInfo, double fontSize, bool selectionHasMultipleFonts) Async
    462462#endif
    463463
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r268386 r271187  
    330330}
    331331
    332 void WebPage::attributedSubstringForCharacterRangeAsync(const EditingRange& editingRange, CallbackID callbackID)
     332void WebPage::attributedSubstringForCharacterRangeAsync(const EditingRange& editingRange, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&& completionHandler)
    333333{
    334334    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    336336    const VisibleSelection& selection = frame.selection().selection();
    337337    if (selection.isNone() || !selection.isContentEditable() || selection.isInPasswordField()) {
    338         send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID));
     338        completionHandler({ }, { });
    339339        return;
    340340    }
     
    342342    auto range = EditingRange::toRange(frame, editingRange);
    343343    if (!range) {
    344         send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID));
     344        completionHandler({ }, { });
    345345        return;
    346346    }
     
    361361    if (!rangeToSend.isValid()) {
    362362        // Send an empty EditingRange as a last resort for <rdar://problem/27078089>.
    363         send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ WTFMove(attributedString), nil }, EditingRange(), callbackID));
    364         return;
    365     }
    366 
    367     send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ WTFMove(attributedString), nil }, rangeToSend, callbackID));
    368 }
    369 
    370 void WebPage::fontAtSelection(CallbackID callbackID)
     363        completionHandler({ WTFMove(attributedString), nil }, EditingRange());
     364        return;
     365    }
     366
     367    completionHandler({ WTFMove(attributedString), nil }, rangeToSend);
     368}
     369
     370void WebPage::fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&& completionHandler)
    371371{
    372372    bool selectionHasMultipleFonts = false;
     
    374374
    375375    if (frame.selection().selection().isNone()) {
    376         send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));
     376        completionHandler({ }, 0, false);
    377377        return;
    378378    }
     
    380380    auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts);
    381381    if (!font) {
    382         send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));
     382        completionHandler({ }, 0, false);
    383383        return;
    384384    }
     
    386386    auto ctFont = font->getCTFont();
    387387    if (!ctFont) {
    388         send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));
     388        completionHandler({ }, 0, false);
    389389        return;
    390390    }
     
    392392    auto fontDescriptor = adoptCF(CTFontCopyFontDescriptor(ctFont));
    393393    if (!fontDescriptor) {
    394         send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));
    395         return;
    396     }
    397 
    398     send(Messages::WebPageProxy::FontAtSelectionCallback({ adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get())) }, CTFontGetSize(ctFont), selectionHasMultipleFonts, callbackID));
     394        completionHandler({ }, 0, false);
     395        return;
     396    }
     397
     398    completionHandler({ adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get())) }, CTFontGetSize(ctFont), selectionHasMultipleFonts);
    399399}
    400400   
Note: See TracChangeset for help on using the changeset viewer.