Revert of ui: Clean up damaged rects and clear them after painting. (patchset #2...
[chromium-blink-merge.git] / android_webview / browser / renderer_host / print_manager.h
blob3cb44955f75e28c07e0facf0b1dd4594e55e946e
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"
13 class GURL;
15 namespace base {
16 struct FileDescriptor;
19 namespace printing {
20 class PrintSettings;
23 namespace android_webview {
25 class PrintManagerDelegate {
26 public:
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 {
41 public:
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,
47 int fd,
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.
58 bool PrintNow();
60 void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
61 int* sequence_number);
62 void OnTempFileForPrintingWritten(int sequence_number);
63 private:
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,
68 int fd,
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);
79 // Print Settings.
80 printing::PrintSettings* settings_;
82 // File descriptor to export to.
83 int fd_;
84 // Print manager delegate
85 PrintManagerDelegate* delegate_;
86 // Number of pages to print in the print job.
87 int number_pages_;
88 // The document cookie of the current PrinterQuery.
89 int cookie_;
90 // Whether a print task is pending.
91 int printing_;
93 DISALLOW_COPY_AND_ASSIGN(PrintManager);
96 } // namespace android_webview
98 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_