Title: [270946] trunk/Source/WebKit
Revision
270946
Author
[email protected]
Date
2020-12-17 14:21:07 -0800 (Thu, 17 Dec 2020)

Log 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 <[email protected]> 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (270945 => 270946)


--- trunk/Source/WebKit/ChangeLog	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/ChangeLog	2020-12-17 22:21:07 UTC (rev 270946)
@@ -1,3 +1,26 @@
+2020-12-17  Alex Christensen  <[email protected]>
+
+        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>
+
+        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):
+
 2020-12-17  Kate Cheney  <[email protected]>
 
         Followup patch: Still can't login to my.playstation.com

Modified: trunk/Source/WebKit/Shared/mac/PDFContextMenu.h (270945 => 270946)


--- trunk/Source/WebKit/Shared/mac/PDFContextMenu.h	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/Shared/mac/PDFContextMenu.h	2020-12-17 22:21:07 UTC (rev 270946)
@@ -78,12 +78,13 @@
 };
 
 struct PDFContextMenu {
-    WebCore::IntPoint m_point;
-    Vector<PDFContextMenuItem> m_items;
+    WebCore::IntPoint point;
+    Vector<PDFContextMenuItem> items;
+    Optional<int> openInPreviewIndex;
     
     template<class Encoder> void encode(Encoder& encoder) const
     {
-        encoder << m_point << m_items;
+        encoder << point << items << openInPreviewIndex;
     }
     
     template<class Decoder> static Optional<PDFContextMenu> decode(Decoder& decoder)
@@ -97,8 +98,17 @@
         decoder >> items;
         if (!items)
             return WTF::nullopt;
-        
-        return { { WTFMove(*point), WTFMove(*items) } };
+
+        Optional<Optional<int>> openInPreviewIndex;
+        decoder >> openInPreviewIndex;
+        if (!openInPreviewIndex)
+            return WTF::nullopt;
+
+        return {{
+            WTFMove(*point),
+            WTFMove(*items),
+            WTFMove(*openInPreviewIndex)
+        }};
     }
 
 };

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (270945 => 270946)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-12-17 22:21:07 UTC (rev 270946)
@@ -1334,7 +1334,7 @@
 #endif
 
 #if ENABLE(PDFKIT_PLUGIN)
-    void showPDFContextMenu(const WebKit::PDFContextMenu&, CompletionHandler<void(Optional<int32_t>&&)>&&);
+    void showPDFContextMenu(const WebKit::PDFContextMenu&, PDFPluginIdentifier, CompletionHandler<void(Optional<int32_t>&&)>&&);
 #endif
     WebCore::IntRect visibleScrollerThumbRect() const { return m_visibleScrollerThumbRect; }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (270945 => 270946)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2020-12-17 22:21:07 UTC (rev 270946)
@@ -440,7 +440,7 @@
 #endif
 
 #if ENABLE(PDFKIT_PLUGIN)
-    ShowPDFContextMenu(struct WebKit::PDFContextMenu contextMenu) -> (Optional<int32_t> selectedItem) Synchronous
+    ShowPDFContextMenu(struct WebKit::PDFContextMenu contextMenu, WebKit::PDFPluginIdentifier identifier) -> (Optional<int32_t> selectedItem) Synchronous
 #endif
 
 #if ENABLE(NETSCAPE_PLUGIN_API)

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (270945 => 270946)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2020-12-17 22:21:07 UTC (rev 270946)
@@ -540,16 +540,16 @@
 #endif
 
 #if ENABLE(PDFKIT_PLUGIN)
-void WebPageProxy::showPDFContextMenu(const WebKit::PDFContextMenu& contextMenu, CompletionHandler<void(Optional<int32_t>&&)>&& completionHandler)
+void WebPageProxy::showPDFContextMenu(const WebKit::PDFContextMenu& contextMenu, PDFPluginIdentifier identifier, CompletionHandler<void(Optional<int32_t>&&)>&& completionHandler)
 {
-    if (!contextMenu.m_items.size())
+    if (!contextMenu.items.size())
         return completionHandler(WTF::nullopt);
     
     RetainPtr<WKPDFMenuTarget> menuTarget = adoptNS([[WKPDFMenuTarget alloc] init]);
     RetainPtr<NSMenu> nsMenu = adoptNS([[NSMenu alloc] init]);
     [nsMenu setAllowsContextMenuPlugIns:false];
-    for (unsigned i = 0; i < contextMenu.m_items.size(); i++) {
-        auto& item = contextMenu.m_items[i];
+    for (unsigned i = 0; i < contextMenu.items.size(); i++) {
+        auto& item = contextMenu.items[i];
         
         if (item.separator) {
             [nsMenu insertItem:[NSMenuItem separatorItem] atIndex:i];
@@ -569,14 +569,22 @@
     }
     NSWindow *window = pageClient().platformWindow();
     auto windowNumber = [window windowNumber];
-    auto location = [window convertRectFromScreen: { contextMenu.m_point, NSZeroSize }].origin;
+    auto location = [window convertRectFromScreen: { contextMenu.point, NSZeroSize }].origin;
     NSEvent* event = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown location:location modifierFlags:0 timestamp:0 windowNumber:windowNumber context:0 eventNumber:0 clickCount:1 pressure:1];
 
     auto view = [pageClient().platformWindow() contentView];
     [NSMenu popUpContextMenu:nsMenu.get() withEvent:event forView:view];
 
-    if (auto selectedMenuItem = [menuTarget selectedMenuItem])
-        return completionHandler([selectedMenuItem tag]);
+    if (auto selectedMenuItem = [menuTarget selectedMenuItem]) {
+        NSInteger tag = selectedMenuItem.tag;
+#if ENABLE(UI_PROCESS_PDF_HUD)
+        if (contextMenu.openInPreviewIndex && *contextMenu.openInPreviewIndex == tag)
+            pdfOpenWithPreview(identifier);
+#else
+        UNUSED_PARAM(identifier);
+#endif
+        return completionHandler(tag);
+    }
     completionHandler(WTF::nullopt);
 }
 #endif

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h (270945 => 270946)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-12-17 22:21:07 UTC (rev 270946)
@@ -427,9 +427,7 @@
 #endif
 
 #endif // HAVE(INCREMENTAL_PDF_APIS)
-#if ENABLE(UI_PROCESS_PDF_HUD)
     PDFPluginIdentifier m_identifier;
-#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (270945 => 270946)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-12-17 22:21:07 UTC (rev 270946)
@@ -606,9 +606,7 @@
     , m_streamLoaderClient(adoptRef(*new PDFPluginStreamLoaderClient(*this)))
     , m_incrementalPDFLoadingEnabled(WebCore::RuntimeEnabledFeatures::sharedFeatures().incrementalPDFLoadingEnabled())
 #endif
-#if ENABLE(UI_PROCESS_PDF_HUD)
     , m_identifier(PDFPluginIdentifier::generate())
-#endif
 {
 #if ENABLE(UI_PROCESS_PDF_HUD)
     [m_pdfLayerController setDisplaysPDFHUDController:NO];
@@ -2318,6 +2316,7 @@
     if (!nsMenu)
         return false;
     
+    Optional<int> openInPreviewIndex;
     Vector<PDFContextMenuItem> items;
     auto itemCount = [nsMenu numberOfItems];
     for (int i = 0; i < itemCount; i++) {
@@ -2324,13 +2323,15 @@
         auto item = [nsMenu itemAtIndex:i];
         if ([item submenu])
             continue;
+        if ([NSStringFromSelector(item.action) isEqualToString:@"openWithPreview"])
+            openInPreviewIndex = i;
         PDFContextMenuItem menuItem { String([item title]), !![item isEnabled], !![item isSeparatorItem], static_cast<int>([item state]), !![item action], i };
         items.append(WTFMove(menuItem));
     }
-    PDFContextMenu contextMenu { point, WTFMove(items) };
+    PDFContextMenu contextMenu { point, WTFMove(items), WTFMove(openInPreviewIndex) };
 
     Optional<int> selectedIndex = -1;
-    webPage->sendSync(Messages::WebPageProxy::ShowPDFContextMenu(contextMenu), Messages::WebPageProxy::ShowPDFContextMenu::Reply(selectedIndex));
+    webPage->sendSync(Messages::WebPageProxy::ShowPDFContextMenu(contextMenu, m_identifier), Messages::WebPageProxy::ShowPDFContextMenu::Reply(selectedIndex));
 
     if (selectedIndex && *selectedIndex >= 0 && *selectedIndex < itemCount)
         [nsMenu performActionForItemAtIndex:*selectedIndex];

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDFPluginIdentifier.h (270945 => 270946)


--- trunk/Source/WebKit/WebProcess/Plugins/PDFPluginIdentifier.h	2020-12-17 22:07:46 UTC (rev 270945)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDFPluginIdentifier.h	2020-12-17 22:21:07 UTC (rev 270946)
@@ -29,9 +29,7 @@
 
 namespace WebKit {
 
-#if ENABLE(UI_PROCESS_PDF_HUD)
 enum PDFPluginIdentifierType { };
 using PDFPluginIdentifier = ObjectIdentifier<PDFPluginIdentifierType>;
-#endif
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to