Bug 239933 - [macOS] The "Markup Image" services menu item should be gated on image analysis results
Summary: [macOS] The "Markup Image" services menu item should be gated on image analys...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-04-30 12:54 PDT by Wenson Hsieh
Modified: 2022-05-02 13:30 PDT (History)
6 users (show)

See Also:


Attachments
For EWS (24.04 KB, patch)
2022-04-30 16:55 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch (24.05 KB, patch)
2022-04-30 18:26 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch (23.95 KB, patch)
2022-05-01 10:43 PDT, Wenson Hsieh
katherine_cheney: review+
Details | Formatted Diff | Diff
Patch for landing (24.07 KB, patch)
2022-05-02 11:43 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 2022-04-30 12:54:46 PDT
rdar://92348202
Comment 1 Wenson Hsieh 2022-04-30 16:55:42 PDT
Created attachment 458640 [details]
For EWS
Comment 2 Wenson Hsieh 2022-04-30 18:26:05 PDT
Created attachment 458642 [details]
Patch
Comment 3 Tim Nguyen (:ntim) 2022-05-01 02:52:03 PDT
Comment on attachment 458642 [details]
Patch

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

> Tools/TestWebKitAPI/Tests/WebKitCocoa/image-controls.html:30
> +    await new Promise(async resolve => {
> +        let button = null;
> +        do {
> +            await new Promise(requestAnimationFrame);
> +            button = servicesControlButton();
> +        } while (!button);
> +        resolve();
> +        button.click();
> +    });

You don't need to wrap a Promise object since you're already in an async function, I think this should just work:

```

async function waitForAndClickImageControls() {
   if (!window.internals)
      return;

   let button = null;
   do {
      await new Promise(requestAnimationFrame);
      button = servicesControlButton();
   } while (!button);
   button.click();
}
```
Comment 4 Tim Nguyen (:ntim) 2022-05-01 03:03:33 PDT
Comment on attachment 458642 [details]
Patch

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

>> Tools/TestWebKitAPI/Tests/WebKitCocoa/image-controls.html:30
>> +    });
> 
> You don't need to wrap a Promise object since you're already in an async function, I think this should just work:
> 
> ```
> 
> async function waitForAndClickImageControls() {
>    if (!window.internals)
>       return;
> 
>    let button = null;
>    do {
>       await new Promise(requestAnimationFrame);
>       button = servicesControlButton();
>    } while (!button);
>    button.click();
> }
> ```

or if you really meant to resolve() before the button click (which is pretty weird IMO):

```
function waitForAndClickImageControls() {
    return new Promise(async resolve => {
        if (!window.internals)
            return resolve();
        let button = null;
        do {
            await new Promise(requestAnimationFrame);
            button = servicesControlButton();
        } while (!button);
        resolve();
        button.click();
    });
}
```
Comment 5 Wenson Hsieh 2022-05-01 10:41:28 PDT
Good point! With the current version of the test, we don't need to resolve the promise before clicking because we'll always dispatch the runloop timer before we start spinning the runloop for the context menu.

Changed to simplify waitForAndClickImageControls().
Comment 6 Wenson Hsieh 2022-05-01 10:43:02 PDT
Created attachment 458651 [details]
Patch
Comment 7 Kate Cheney 2022-05-02 11:03:33 PDT
Comment on attachment 458651 [details]
Patch

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

> Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:299
> +    if (!page()->preferences().imageAnalysisMarkupEnabled())

Do we need to check for a null page here?
Comment 8 Wenson Hsieh 2022-05-02 11:34:51 PDT
Comment on attachment 458651 [details]
Patch

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

Thanks for the review!

>> Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:299
>> +    if (!page()->preferences().imageAnalysisMarkupEnabled())
> 
> Do we need to check for a null page here?

Ah, so I think we're technically okay here since this method is only called from `setupServicesMenu()` which already dereferences `page()` (and therefore assumes that it's non-null).

That said, since this is a separate method now, adding an extra null check is probably a good idea — I'll add an early return here for `!page()`.
Comment 9 Wenson Hsieh 2022-05-02 11:43:15 PDT
Created attachment 458697 [details]
Patch for landing
Comment 10 EWS 2022-05-02 13:30:53 PDT
Committed r293681 (250181@main): <https://commits.webkit.org/250181@main>

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