Question on implementing the print preview dialog in CEF

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Question on implementing the print preview dialog in CEF

Postby ivdone » Thu May 18, 2017 1:35 pm

Since google have open sourced their implementation on print preview and included that in chromium. I am trying to implement the print preview dialog in Cef but was stopped by some problems.

I turned on the print preview build flags. And updated the CefPrintViewManger according to the newer version of it in chromium, to have the support for sending out PrintMsg_InitiatePrintPreview message to the render frame.
Code: Select all
class CefPrintViewManager :
    public CefPrintViewManagerBase,
    public content::WebContentsUserData<CefPrintViewManager> {


The message is received by the render process in PrintWebViewHelper(which has base class content::RenderFrameObserver, content::RenderFrameObserverTracker<PrintWebViewHelper>) and then it will try to send a PrintHostMsg_RequestPrintPreview message to the render frame
Code: Select all
Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params));
. The routing_id is a method of its base "content::RenderFrameObserver", I assume it is trying to send the message to the render frame. But the message is not handled.

Code: Select all
class PrintWebViewHelper
    : public content::RenderFrameObserver,
      public content::RenderFrameObserverTracker<PrintWebViewHelper> {


Read through chromium code. the PrintHostMsg_RequestPrintPreview Message should be handled in

Code: Select all
class PrintPreviewMessageHandler
    : public content::WebContentsObserver,
      public content::WebContentsUserData<PrintPreviewMessageHandler>


I searched for PrintPreviewMessageHandler, found out that "print_preview_message_handler" is attached in "src/chrome/browser/ui/tab_helpers.cc", "src/chrome/browser/ui/apps/chrome_app_delegate.cc", "src/chrome/browser/extensions/api/chrome_extensions_api_client.cc".

Since the behavior right now is that the message is lost, it might because 1. the print_preview_message_handler is not attached at the time we tries to create the print preview. 2. the print_preview_message_handler is not attached to the right webcontent.

I am new to chromium and Cef code, sorry if I didn't understand them correctly. Here are my confusions : 1.why there are three places that tries to attach this handler? 2. when will each class be attaching this handler?

Please let me know if I misunderstood or if you have any suggestions. Any comment will be appreciated!
ivdone
Newbie
 
Posts: 9
Joined: Wed May 17, 2017 12:55 pm

Re: Question on implementing the print preview dialog in CEF

Postby Czarek » Thu May 25, 2017 12:13 pm

Try asking on chromium-dev group.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Question on implementing the print preview dialog in CEF

Postby emerick » Tue Jul 11, 2017 9:40 am

ivdone, did you ever have any luck with this? I'm also looking into a print preview dialog for our CEF-based application, so just curious if you made any progress or ran into issues.
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Question on implementing the print preview dialog in CEF

Postby ivdone » Thu Jul 13, 2017 12:50 pm

emerick wrote:ivdone, did you ever have any luck with this? I'm also looking into a print preview dialog for our CEF-based application, so just curious if you made any progress or ran into issues.


emerick, I am able to get the print preview ui generated by navigating to chrome://print now. This is only showing the ui is available. To make it able to print we have to attach a webcontent which is about to be printed.

The way it should be is : The webcontent will be attached by the PrintPreviewDialogController to create the print preview ui. And a constrained window will be generated to host the print preview ui. But the problem I am facing is that the Constrained Web Dialog rendered but it is empty, the print preview ui is not rendered in it. I suspect this is caused by some window handling nuances between CEF and chromium but I cannot find any examples on how to use the constrained web dialog in CEF.

I am working on debugging through chromium to see what I did I missed.
ivdone
Newbie
 
Posts: 9
Joined: Wed May 17, 2017 12:55 pm

Re: Question on implementing the print preview dialog in CEF

Postby emerick » Thu Jul 13, 2017 12:59 pm

Thanks for the update. That actually sounds like good progress! If you have a diff/patch available, I could certainly try to give a hand with debugging (although I'm currently working on v58).
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Question on implementing the print preview dialog in CEF

Postby ivdone » Sun Jul 23, 2017 11:41 pm

Hi emerick,

I have attached the patch file below.

The changes for cefPrintViewManager and CefPrintWebViewHelperDelegate are just updating it according to new chromium version.

And just for testing purpose, I am not using cefPrintViewManager in browser_host_impl.h instead I used the PrintViewManager.

Right now I am having trouble populating the constrained_window. I have tried to step into the code but everything seems normal.

Thanks for helping out.
Attachments
print_preview_patch.txt
(37.09 KiB) Downloaded 672 times
ivdone
Newbie
 
Posts: 9
Joined: Wed May 17, 2017 12:55 pm

Re: Question on implementing the print preview dialog in CEF

Postby ivdone » Wed Aug 09, 2017 11:19 am

Hi emerick,

Have you got any luck on implementing this?
ivdone
Newbie
 
Posts: 9
Joined: Wed May 17, 2017 12:55 pm

Re: Question on implementing the print preview dialog in CEF

Postby emerick » Wed Aug 09, 2017 12:19 pm

Unfortunately, as soon as I visit chrome://print the client crashes. I haven't been able to track down the root cause yet. I'm not sure if I'm missing some changes or if it's just due to my using version 58.
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Question on implementing the print preview dialog in CEF

Postby ivdone » Mon Aug 21, 2017 6:12 pm

emerick wrote:Unfortunately, as soon as I visit chrome://print the client crashes. I haven't been able to track down the root cause yet. I'm not sure if I'm missing some changes or if it's just due to my using version 58.

Sorry I have missed one patch file for chromium.
I tried a hacky way to avoid some of the crashes. Those should be resolved when cleaning up the code. Just wanted to have a working branch right now.
Please let me know if you are experiencing any other crashes.
ivdone
Newbie
 
Posts: 9
Joined: Wed May 17, 2017 12:55 pm

Re: Question on implementing the print preview dialog in CEF

Postby emerick » Mon Aug 21, 2017 6:22 pm

OK, sounds good. Does that mean you're close to having this working then? That would be wonderful! :)
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 35 guests