Bug 236714 - Add -[WKWebProcessPlugInFrame lookUpFrameFromJSValue:]
Summary: Add -[WKWebProcessPlugInFrame lookUpFrameFromJSValue:]
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Timothy Hatcher
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-16 09:37 PST by Timothy Hatcher
Modified: 2022-02-17 00:01 PST (History)
2 users (show)

See Also:


Attachments
Patch (7.41 KB, patch)
2022-02-16 09:44 PST, Timothy Hatcher
no flags Details | Formatted Diff | Diff
Patch (7.22 KB, patch)
2022-02-16 13:45 PST, Timothy Hatcher
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Hatcher 2022-02-16 09:37:20 PST
Safari needs a way to convert a JS window object or frame DOM element into a WKWebProcessPlugInFrame in the injected bundle for web extensions.
Comment 1 Radar WebKit Bug Importer 2022-02-16 09:37:35 PST
<rdar://problem/89030846>
Comment 2 Timothy Hatcher 2022-02-16 09:44:10 PST
Created attachment 452203 [details]
Patch
Comment 3 Chris Dumez 2022-02-16 09:51:36 PST
Comment on attachment 452203 [details]
Patch

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

> Source/WebCore/page/Frame.cpp:1146
> +    JSC::JSGlobalObject* globalObject = toJS(context);

I would think you should be able to do:
return globalObject  ? activeDOMWindow(*globalObject).frame() : nullptr;

No?
Comment 4 Chris Dumez 2022-02-16 09:52:24 PST
Comment on attachment 452203 [details]
Patch

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

>> Source/WebCore/page/Frame.cpp:1146
>> +    JSC::JSGlobalObject* globalObject = toJS(context);
> 
> I would think you should be able to do:
> return globalObject  ? activeDOMWindow(*globalObject).frame() : nullptr;
> 
> No?

And if so, we probably don't need this new function on the Frame class at all.
Comment 5 Timothy Hatcher 2022-02-16 09:57:03 PST
Comment on attachment 452203 [details]
Patch

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

>>> Source/WebCore/page/Frame.cpp:1146
>>> +    JSC::JSGlobalObject* globalObject = toJS(context);
>> 
>> I would think you should be able to do:
>> return globalObject  ? activeDOMWindow(*globalObject).frame() : nullptr;
>> 
>> No?
> 
> And if so, we probably don't need this new function on the Frame class at all.

We need to be able to get the Frame from a JSHTMLIFrameElement, JSHTMLFrameElement or JSDOMWindow.
Comment 6 Chris Dumez 2022-02-16 10:28:26 PST
Comment on attachment 452203 [details]
Patch

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

> Source/WebCore/page/Frame.cpp:1141
> +Frame* Frame::fromJSValue(JSContextRef context, JSValueRef valueRef)

I think we should rename to make it clear we want a *content* frame, as suggested below.

> Source/WebCore/page/Frame.cpp:1149
> +

We can simplify a bit here:
```
if (auto* window = JSDOMWindow::toWrapped(vm, value))
    return window->frame();
```

> Source/WebCore/page/Frame.cpp:1159
> +    if (auto* frameElement = JSC::jsDynamicCast<JSHTMLIFrameElement*>(vm, value))

I think this may look a bit better:
```
auto* jsNode = JSC::jsDynamicCast<JSNode*>(vm, value);
if (!jsNode || !is<HTMLFrameOwnerElement>(jsNode->wrapped()))
    return nullptr;
return downcast<HTMLFrameOwnerElement>(*jsNode->wrapped()).contentFrame();
```

> Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h:36
> ++ (instancetype)lookUpFrameFromJSValue:(JSValue *)value;

I think we may want to rename this to lookUpContentFrameFromJSValue given the behavior. You don't really want the frame, you want the "content" frame in the case the value is a <frame> / <iframe>.
We may also want to convey the fact that this only works for window and frame elements, maybe something like: lookUpContentFrameForWindowOrFrameElement:
Comment 7 Timothy Hatcher 2022-02-16 13:45:54 PST
Created attachment 452246 [details]
Patch
Comment 8 Chris Dumez 2022-02-16 13:51:45 PST
Comment on attachment 452246 [details]
Patch

r=me
Comment 9 EWS 2022-02-17 00:01:21 PST
Committed r290001 (247387@main): <https://commits.webkit.org/247387@main>

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