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"
15 struct FileDescriptor
;
22 namespace android_webview
{
24 class PrintManagerDelegate
{
26 virtual ~PrintManagerDelegate() { }
27 virtual void DidExportPdf(bool success
) = 0;
28 virtual bool IsCancelled() = 0;
31 // DISALLOW_COPY_AND_ASSIGN(PrintManagerDelegate);
34 // Provides RenderViewHost wrapper functionality for sending WebView-specific
35 // IPC messages to the renderer and from there to WebKit.
37 // Note for android_webview:
38 // This class manages the print (an export to PDF file essentially) task for
39 // a webview. There can be at most one active print task per webview.
40 class PrintManager
: public content::WebContentsObserver
,
41 public base::NonThreadSafe
{
43 // To send receive messages to a RenderView we take the WebContents instance,
44 // as it internally handles RenderViewHost instances changing underneath us.
45 PrintManager(content::WebContents
* contents
,
46 printing::PrintSettings
* settings
,
48 PrintManagerDelegate
* delegate
);
49 virtual ~PrintManager();
51 // Prints the current document immediately. Since the rendering is
52 // asynchronous, the actual printing will not be completed on the return of
53 // this function. Returns false if printing is impossible at the moment.
55 // Note for webview: Returns false immediately if this print manager is
56 // already busy printing.
60 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
61 void OnDidGetPrintedPagesCount(int cookie
, int number_pages
);
62 void OnDidGetDocumentCookie(int cookie
);
63 void OnPrintingFailed(int cookie
);
64 void OnGetDefaultPrintSettingsReply(IPC::Message
* reply_msg
);
65 void OnGetDefaultPrintSettings(IPC::Message
* reply_msg
);
66 void OnAllocateTempFileForPrinting(base::FileDescriptor
* temp_file_fd
,
67 int* sequence_number
);
68 void OnTempFileForPrintingWritten(int sequence_number
);
71 printing::PrintSettings
* settings_
;
73 // File descriptor to export to.
75 // Print manager delegate
76 PrintManagerDelegate
* delegate_
;
77 // Number of pages to print in the print job.
79 // The document cookie of the current PrinterQuery.
81 // Whether a print task is pending.
84 DISALLOW_COPY_AND_ASSIGN(PrintManager
);
87 } // namespace android_webview
89 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_