Bug 236510 - Inject custom styles into PDF.js to make it look like PDFKit
Summary: Inject custom styles into PDF.js to make it look like PDFKit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: PDF (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Nguyen (:ntim)
URL:
Keywords: InRadar
Depends on:
Blocks: 235969
  Show dependency treegraph
 
Reported: 2022-02-11 07:49 PST by Tim Nguyen (:ntim)
Modified: 2022-02-11 09:54 PST (History)
10 users (show)

See Also:


Attachments
Patch (17.54 KB, patch)
2022-02-11 07:57 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (23.87 KB, patch)
2022-02-11 08:02 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (24.21 KB, patch)
2022-02-11 08:51 PST, Tim Nguyen (:ntim)
thorton: review+
Details | Formatted Diff | Diff
Patch (24.20 KB, patch)
2022-02-11 09:19 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
[fast-cq] Patch for landing (24.20 KB, patch)
2022-02-11 09:25 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
[fast-cq] Patch for landing (24.19 KB, patch)
2022-02-11 09:31 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Nguyen (:ntim) 2022-02-11 07:49:54 PST
<rdar://problem/88457996>
Comment 1 Tim Nguyen (:ntim) 2022-02-11 07:50:01 PST
rdar://88457996
Comment 2 Tim Nguyen (:ntim) 2022-02-11 07:57:12 PST
Created attachment 451696 [details]
Patch
Comment 3 Tim Nguyen (:ntim) 2022-02-11 08:02:34 PST
Created attachment 451698 [details]
Patch
Comment 4 youenn fablet 2022-02-11 08:31:25 PST
Comment on attachment 451698 [details]
Patch

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

> Source/WebCore/ChangeLog:12
> +        (e.g. loading a blob, hooking with find-in-page messages, etc.).

There are other changes in this patch, is it expected?

> Source/WebCore/html/PDFDocument.cpp:58
> +    PDFDocumentEventListener(PDFDocument& document)

explicit.

> Source/WebCore/html/PDFDocument.cpp:67
> +    PDFDocument& m_document;

This is not safe, there is no guarantee m_document is alive during PDFDocumentEventListener lifetime
Comment 5 Tim Nguyen (:ntim) 2022-02-11 08:51:29 PST
Created attachment 451703 [details]
Patch
Comment 6 Tim Horton 2022-02-11 09:07:04 PST
Comment on attachment 451703 [details]
Patch

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

> Source/WebCore/html/PDFDocument.h:51
> +    RefPtr<HTMLIFrameElement> m_iframe;

“m_iFrame” I would imagine given the type’s capitalization, but check what we use elsewhere.
Comment 7 Chris Dumez 2022-02-11 09:14:31 PST
(In reply to Tim Horton from comment #6)
> Comment on attachment 451703 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451703&action=review
> 
> > Source/WebCore/html/PDFDocument.h:51
> > +    RefPtr<HTMLIFrameElement> m_iframe;
> 
> “m_iFrame” I would imagine given the type’s capitalization, but check what
> we use elsewhere.

I have never seen m_iFrame in our code base. I think we consistently use "iframe".
Comment 8 youenn fablet 2022-02-11 09:15:54 PST
Comment on attachment 451703 [details]
Patch

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

> Source/WebCore/html/PDFDocument.cpp:153
> +    m_iframe = iframe.ptr();

m_iframe = WTFMove(iframe)

> Source/WebCore/html/PDFDocument.cpp:170
> +    auto script = HTMLScriptElement::create(scriptTag, *this, false, false);

It is a bit weird to create an element with *this while it will be added to another document.
You can probably pass a Document& to injectContentScript from the event handler, in which case no need to store m_frame at all.
Comment 9 Tim Nguyen (:ntim) 2022-02-11 09:19:39 PST
Created attachment 451705 [details]
Patch
Comment 10 Tim Nguyen (:ntim) 2022-02-11 09:25:39 PST
Created attachment 451707 [details]
[fast-cq] Patch for landing
Comment 11 Tim Nguyen (:ntim) 2022-02-11 09:28:08 PST
(In reply to youenn fablet from comment #8)
> Comment on attachment 451703 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451703&action=review
> 
> > Source/WebCore/html/PDFDocument.cpp:153
> > +    m_iframe = iframe.ptr();
> 
> m_iframe = WTFMove(iframe)
> 
> > Source/WebCore/html/PDFDocument.cpp:170
> > +    auto script = HTMLScriptElement::create(scriptTag, *this, false, false);
> 
> It is a bit weird to create an element with *this while it will be added to
> another document.
> You can probably pass a Document& to injectContentScript from the event
> handler, in which case no need to store m_frame at all.

Done, I've used the contentDocument instead of *this. The m_iframe can't be removed since injectContentScript is called from the event listener. 

Besides that, it's useful to have it to send messages to the iframe if we need to in the future (for find in page for instance)
Comment 12 Tim Nguyen (:ntim) 2022-02-11 09:30:21 PST
Comment on attachment 451707 [details]
[fast-cq] Patch for landing

whoops not up to date
Comment 13 Tim Nguyen (:ntim) 2022-02-11 09:31:08 PST
Created attachment 451708 [details]
[fast-cq] Patch for landing
Comment 14 EWS 2022-02-11 09:32:02 PST
Committed r289627 (247137@main): <https://commits.webkit.org/247137@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451707 [details].
Comment 15 Radar WebKit Bug Importer 2022-02-11 09:33:18 PST
<rdar://problem/88820270>
Comment 16 Tim Nguyen (:ntim) 2022-02-11 09:33:38 PST
Comment on attachment 451708 [details]
[fast-cq] Patch for landing

Welp, fast-cq was faster than me, will address comments manually
Comment 17 youenn fablet 2022-02-11 09:34:42 PST
> Done, I've used the contentDocument instead of *this. The m_iframe can't be
> removed since injectContentScript is called from the event listener. 

The event listener has a ScriptExecutionContext& which is probably the Document& you want to use.
In that case, why would we need m_iframe?
Comment 18 Tim Nguyen (:ntim) 2022-02-11 09:54:05 PST
(In reply to youenn fablet from comment #17)
> > Done, I've used the contentDocument instead of *this. The m_iframe can't be
> > removed since injectContentScript is called from the event listener. 
> 
> The event listener has a ScriptExecutionContext& which is probably the
> Document& you want to use.
> In that case, why would we need m_iframe?

Addressed in https://commits.webkit.org/r289630