Bug 215792 - Trying to lookup when WebView is in a popover causes process to hang. Fix for Legacy WebView.
Summary: Trying to lookup when WebView is in a popover causes process to hang. Fix for...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Megan Gardner
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-08-24 19:51 PDT by Megan Gardner
Modified: 2020-08-25 14:34 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.71 KB, patch)
2020-08-24 19:53 PDT, Megan Gardner
thorton: review+
Details | Formatted Diff | Diff
Patch (4.68 KB, patch)
2020-08-25 10:36 PDT, Megan Gardner
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Megan Gardner 2020-08-24 19:51:23 PDT
Trying to lookup when WebView is in a popover causes process to hang. Fix for Legacy WebView.
Comment 1 Megan Gardner 2020-08-24 19:53:52 PDT
Created attachment 407163 [details]
Patch
Comment 2 Megan Gardner 2020-08-24 19:54:10 PDT
<rdar://problem/52317762>
Comment 3 Darin Adler 2020-08-24 20:03:44 PDT
Comment on attachment 407163 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=407163&action=review

> Source/WebKitLegacy/mac/WebView/WebHTMLView.mm:3682
> -    auto defaultMenuItems = createMenuItems(hitTestResult, defaultMenu.items());
> +    Vector<WebCore::ContextMenuItem> filteredItems;
> +    filteredItems.reserveInitialCapacity(defaultMenu.items().size());
> +    
> +    bool isPopover = webView.window._childWindowOrderingPriority == NSWindowChildOrderingPriorityPopover;
> +    bool isLookupDisabled = [NSUserDefaults.standardUserDefaults boolForKey:@"LULookupDisabled"];
>  
> +    for (WebCore::ContextMenuItem item : defaultMenu.items()) {
> +        if (item.action() != WebCore::ContextMenuItemTagLookUpInDictionary || (!isLookupDisabled && !isPopover))
> +            filteredItems.uncheckedAppend(item);
> +    }
> +    
> +    auto defaultMenuItems = createMenuItems(hitTestResult, filteredItems);

Here’s a simpler way to write it (roughly, not sure I have the syntax right:

    auto filteredItems = defaultMenu.items();
    if (!isLookupDisabled && !isPopover) {
        filteredItems.removeAllMatching([] (auto& item) {
            return item.action() == WebCore::ContextMenuItemTagLookUpInDictionary;
        });
    }
    auto defaultMenuItems = createMenuItems(hitTestResult, filteredItems);
Comment 4 Darin Adler 2020-08-24 20:04:22 PDT
Not a lot simpler (I accidentally left out the isPopover and isLookupDisabled part), but still I think it’s better than writing our own loop.
Comment 5 Megan Gardner 2020-08-25 10:36:58 PDT
Created attachment 407206 [details]
Patch
Comment 6 EWS 2020-08-25 14:34:23 PDT
Committed r266143: <https://trac.webkit.org/changeset/266143>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 407206 [details].