Changeset 270946 in webkit


Ignore:
Timestamp:
Dec 17, 2020 2:21:07 PM (19 months ago)
Author:
commit-queue@webkit.org
Message:

Fix "Open with Preview" menu item in PDF context menus on Big Sur
https://bugs.webkit.org/show_bug.cgi?id=219986
<rdar://problem/72406073>

Patch by Alex Christensen <achristensen@webkit.org> on 2020-12-17
Reviewed by Geoffrey Garen.

In r266654 I removed the ability for the web process to open a PDF in Preview on Big Sur.
I overlooked the fact that context menus also allow you to open a PDF in Preview,
which this fixes by having the UI process initiate the Preview opening if the user clicks on
the context menu item with the correct index.

  • Shared/mac/PDFContextMenu.h:

(WebKit::PDFContextMenu::encode const):
(WebKit::PDFContextMenu::decode):

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

(WebKit::WebPageProxy::showPDFContextMenu):

  • WebProcess/Plugins/PDF/PDFPlugin.mm:

(WebKit::PDFPlugin::handleContextMenuEvent):

Location:
trunk/Source/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r270942 r270946  
     12020-12-17  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix "Open with Preview" menu item in PDF context menus on Big Sur
     4        https://bugs.webkit.org/show_bug.cgi?id=219986
     5        <rdar://problem/72406073>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        In r266654 I removed the ability for the web process to open a PDF in Preview on Big Sur.
     10        I overlooked the fact that context menus also allow you to open a PDF in Preview,
     11        which this fixes by having the UI process initiate the Preview opening if the user clicks on
     12        the context menu item with the correct index.
     13
     14        * Shared/mac/PDFContextMenu.h:
     15        (WebKit::PDFContextMenu::encode const):
     16        (WebKit::PDFContextMenu::decode):
     17        * UIProcess/WebPageProxy.h:
     18        * UIProcess/WebPageProxy.messages.in:
     19        * UIProcess/mac/WebPageProxyMac.mm:
     20        (WebKit::WebPageProxy::showPDFContextMenu):
     21        * WebProcess/Plugins/PDF/PDFPlugin.mm:
     22        (WebKit::PDFPlugin::handleContextMenuEvent):
     23
    1242020-12-17  Kate Cheney  <katherine_cheney@apple.com>
    225
  • trunk/Source/WebKit/Shared/mac/PDFContextMenu.h

    r239427 r270946  
    7979
    8080struct PDFContextMenu {
    81     WebCore::IntPoint m_point;
    82     Vector<PDFContextMenuItem> m_items;
     81    WebCore::IntPoint point;
     82    Vector<PDFContextMenuItem> items;
     83    Optional<int> openInPreviewIndex;
    8384   
    8485    template<class Encoder> void encode(Encoder& encoder) const
    8586    {
    86         encoder << m_point << m_items;
     87        encoder << point << items << openInPreviewIndex;
    8788    }
    8889   
     
    9899        if (!items)
    99100            return WTF::nullopt;
    100        
    101         return { { WTFMove(*point), WTFMove(*items) } };
     101
     102        Optional<Optional<int>> openInPreviewIndex;
     103        decoder >> openInPreviewIndex;
     104        if (!openInPreviewIndex)
     105            return WTF::nullopt;
     106
     107        return {{
     108            WTFMove(*point),
     109            WTFMove(*items),
     110            WTFMove(*openInPreviewIndex)
     111        }};
    102112    }
    103113
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r270712 r270946  
    13351335
    13361336#if ENABLE(PDFKIT_PLUGIN)
    1337     void showPDFContextMenu(const WebKit::PDFContextMenu&, CompletionHandler<void(Optional<int32_t>&&)>&&);
     1337    void showPDFContextMenu(const WebKit::PDFContextMenu&, PDFPluginIdentifier, CompletionHandler<void(Optional<int32_t>&&)>&&);
    13381338#endif
    13391339    WebCore::IntRect visibleScrollerThumbRect() const { return m_visibleScrollerThumbRect; }
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r270577 r270946  
    441441
    442442#if ENABLE(PDFKIT_PLUGIN)
    443     ShowPDFContextMenu(struct WebKit::PDFContextMenu contextMenu) -> (Optional<int32_t> selectedItem) Synchronous
     443    ShowPDFContextMenu(struct WebKit::PDFContextMenu contextMenu, WebKit::PDFPluginIdentifier identifier) -> (Optional<int32_t> selectedItem) Synchronous
    444444#endif
    445445
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r270577 r270946  
    541541
    542542#if ENABLE(PDFKIT_PLUGIN)
    543 void WebPageProxy::showPDFContextMenu(const WebKit::PDFContextMenu& contextMenu, CompletionHandler<void(Optional<int32_t>&&)>&& completionHandler)
    544 {
    545     if (!contextMenu.m_items.size())
     543void WebPageProxy::showPDFContextMenu(const WebKit::PDFContextMenu& contextMenu, PDFPluginIdentifier identifier, CompletionHandler<void(Optional<int32_t>&&)>&& completionHandler)
     544{
     545    if (!contextMenu.items.size())
    546546        return completionHandler(WTF::nullopt);
    547547   
     
    549549    RetainPtr<NSMenu> nsMenu = adoptNS([[NSMenu alloc] init]);
    550550    [nsMenu setAllowsContextMenuPlugIns:false];
    551     for (unsigned i = 0; i < contextMenu.m_items.size(); i++) {
    552         auto& item = contextMenu.m_items[i];
     551    for (unsigned i = 0; i < contextMenu.items.size(); i++) {
     552        auto& item = contextMenu.items[i];
    553553       
    554554        if (item.separator) {
     
    570570    NSWindow *window = pageClient().platformWindow();
    571571    auto windowNumber = [window windowNumber];
    572     auto location = [window convertRectFromScreen: { contextMenu.m_point, NSZeroSize }].origin;
     572    auto location = [window convertRectFromScreen: { contextMenu.point, NSZeroSize }].origin;
    573573    NSEvent* event = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown location:location modifierFlags:0 timestamp:0 windowNumber:windowNumber context:0 eventNumber:0 clickCount:1 pressure:1];
    574574
     
    576576    [NSMenu popUpContextMenu:nsMenu.get() withEvent:event forView:view];
    577577
    578     if (auto selectedMenuItem = [menuTarget selectedMenuItem])
    579         return completionHandler([selectedMenuItem tag]);
     578    if (auto selectedMenuItem = [menuTarget selectedMenuItem]) {
     579        NSInteger tag = selectedMenuItem.tag;
     580#if ENABLE(UI_PROCESS_PDF_HUD)
     581        if (contextMenu.openInPreviewIndex && *contextMenu.openInPreviewIndex == tag)
     582            pdfOpenWithPreview(identifier);
     583#else
     584        UNUSED_PARAM(identifier);
     585#endif
     586        return completionHandler(tag);
     587    }
    580588    completionHandler(WTF::nullopt);
    581589}
  • trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h

    r270573 r270946  
    428428
    429429#endif // HAVE(INCREMENTAL_PDF_APIS)
    430 #if ENABLE(UI_PROCESS_PDF_HUD)
    431430    PDFPluginIdentifier m_identifier;
    432 #endif
    433431};
    434432
  • trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm

    r270557 r270946  
    607607    , m_incrementalPDFLoadingEnabled(WebCore::RuntimeEnabledFeatures::sharedFeatures().incrementalPDFLoadingEnabled())
    608608#endif
    609 #if ENABLE(UI_PROCESS_PDF_HUD)
    610609    , m_identifier(PDFPluginIdentifier::generate())
    611 #endif
    612610{
    613611#if ENABLE(UI_PROCESS_PDF_HUD)
     
    23192317        return false;
    23202318   
     2319    Optional<int> openInPreviewIndex;
    23212320    Vector<PDFContextMenuItem> items;
    23222321    auto itemCount = [nsMenu numberOfItems];
     
    23252324        if ([item submenu])
    23262325            continue;
     2326        if ([NSStringFromSelector(item.action) isEqualToString:@"openWithPreview"])
     2327            openInPreviewIndex = i;
    23272328        PDFContextMenuItem menuItem { String([item title]), !![item isEnabled], !![item isSeparatorItem], static_cast<int>([item state]), !![item action], i };
    23282329        items.append(WTFMove(menuItem));
    23292330    }
    2330     PDFContextMenu contextMenu { point, WTFMove(items) };
     2331    PDFContextMenu contextMenu { point, WTFMove(items), WTFMove(openInPreviewIndex) };
    23312332
    23322333    Optional<int> selectedIndex = -1;
    2333     webPage->sendSync(Messages::WebPageProxy::ShowPDFContextMenu(contextMenu), Messages::WebPageProxy::ShowPDFContextMenu::Reply(selectedIndex));
     2334    webPage->sendSync(Messages::WebPageProxy::ShowPDFContextMenu(contextMenu, m_identifier), Messages::WebPageProxy::ShowPDFContextMenu::Reply(selectedIndex));
    23342335
    23352336    if (selectedIndex && *selectedIndex >= 0 && *selectedIndex < itemCount)
  • trunk/Source/WebKit/WebProcess/Plugins/PDFPluginIdentifier.h

    r266654 r270946  
    3030namespace WebKit {
    3131
    32 #if ENABLE(UI_PROCESS_PDF_HUD)
    3332enum PDFPluginIdentifierType { };
    3433using PDFPluginIdentifier = ObjectIdentifier<PDFPluginIdentifierType>;
    35 #endif
    3634
    3735}
Note: See TracChangeset for help on using the changeset viewer.