1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
16 struct FileDescriptor
;
23 namespace android_webview
{
25 class PrintManagerDelegate
{
27 virtual ~PrintManagerDelegate() { }
28 virtual void DidExportPdf(bool success
) = 0;
29 virtual bool IsCancelled() = 0;
32 // Provides RenderViewHost wrapper functionality for sending WebView-specific
33 // IPC messages to the renderer and from there to WebKit.
35 // Note for android_webview:
36 // This class manages the print (an export to PDF file essentially) task for
37 // a webview. There can be at most one active print task per webview.
38 class PrintManager
: public content::WebContentsObserver
,
39 public content::WebContentsUserData
<PrintManager
>,
40 public base::NonThreadSafe
{
42 // Creates a PrintManager for the provided webcontents. If the printmanager
43 // already exists, it is destroyed and a new one is created.
44 static PrintManager
* CreateForWebContents(
45 content::WebContents
* contents
,
46 printing::PrintSettings
* settings
,
48 PrintManagerDelegate
* delegate
);
50 ~PrintManager() override
;
52 // Prints the current document immediately. Since the rendering is
53 // asynchronous, the actual printing will not be completed on the return of
54 // this function. Returns false if printing is impossible at the moment.
56 // Note for webview: Returns false immediately if this print manager is
57 // already busy printing.
60 void OnAllocateTempFileForPrinting(base::FileDescriptor
* temp_file_fd
,
61 int* sequence_number
);
62 void OnTempFileForPrintingWritten(int sequence_number
);
64 // To send receive messages to a RenderView we take the WebContents instance,
65 // as it internally handles RenderViewHost instances changing underneath us.
66 PrintManager(content::WebContents
* contents
,
67 printing::PrintSettings
* settings
,
69 PrintManagerDelegate
* delegate
);
70 friend class content::WebContentsUserData
<PrintManager
>;
72 bool OnMessageReceived(const IPC::Message
& message
) override
;
73 void OnDidGetPrintedPagesCount(int cookie
, int number_pages
);
74 void OnDidGetDocumentCookie(int cookie
);
75 void OnPrintingFailed(int cookie
);
76 void OnGetDefaultPrintSettingsReply(IPC::Message
* reply_msg
);
77 void OnGetDefaultPrintSettings(IPC::Message
* reply_msg
);
80 printing::PrintSettings
* settings_
;
82 // File descriptor to export to.
84 // Print manager delegate
85 PrintManagerDelegate
* delegate_
;
86 // Number of pages to print in the print job.
88 // The document cookie of the current PrinterQuery.
90 // Whether a print task is pending.
93 DISALLOW_COPY_AND_ASSIGN(PrintManager
);
96 } // namespace android_webview
98 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_