Bug 236714

Summary: Add -[WKWebProcessPlugInFrame lookUpFrameFromJSValue:]
Product: WebKit Reporter: Timothy Hatcher <timothy>
Component: WebKit APIAssignee: Timothy Hatcher <timothy>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

Timothy Hatcher
Reported 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.
Attachments
Patch (7.41 KB, patch)
2022-02-16 09:44 PST, Timothy Hatcher
no flags
Patch (7.22 KB, patch)
2022-02-16 13:45 PST, Timothy Hatcher
no flags
Radar WebKit Bug Importer
Comment 1 2022-02-16 09:37:35 PST
Timothy Hatcher
Comment 2 2022-02-16 09:44:10 PST
Chris Dumez
Comment 3 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?
Chris Dumez
Comment 4 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.
Timothy Hatcher
Comment 5 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.
Chris Dumez
Comment 6 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:
Timothy Hatcher
Comment 7 2022-02-16 13:45:54 PST
Chris Dumez
Comment 8 2022-02-16 13:51:45 PST
Comment on attachment 452246 [details] Patch r=me
EWS
Comment 9 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].
Note You need to log in before you can comment on or make changes to this bug.