Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: android_webview/browser/renderer_host/print_manager.h

Issue 854513002: Remove the discrepencies between chrome and android_webview print (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_ 5 #ifndef ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/threading/non_thread_safe.h" 9 #include "base/threading/non_thread_safe.h"
10 #include "content/public/browser/web_contents_observer.h" 10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
11 12
12 class GURL; 13 class GURL;
13 14
14 namespace base { 15 namespace base {
15 struct FileDescriptor; 16 struct FileDescriptor;
16 } 17 }
17 18
18 namespace printing { 19 namespace printing {
19 class PrintSettings; 20 class PrintSettings;
20 } 21 }
21 22
22 namespace android_webview { 23 namespace android_webview {
23 24
24 class PrintManagerDelegate { 25 class PrintManagerDelegate {
25 public: 26 public:
26 virtual ~PrintManagerDelegate() { } 27 virtual ~PrintManagerDelegate() { }
27 virtual void DidExportPdf(bool success) = 0; 28 virtual void DidExportPdf(bool success) = 0;
28 virtual bool IsCancelled() = 0; 29 virtual bool IsCancelled() = 0;
29
30 private:
31 // DISALLOW_COPY_AND_ASSIGN(PrintManagerDelegate);
32 }; 30 };
33 31
34 // Provides RenderViewHost wrapper functionality for sending WebView-specific 32 // Provides RenderViewHost wrapper functionality for sending WebView-specific
35 // IPC messages to the renderer and from there to WebKit. 33 // IPC messages to the renderer and from there to WebKit.
36 // 34 //
37 // Note for android_webview: 35 // Note for android_webview:
38 // This class manages the print (an export to PDF file essentially) task for 36 // 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. 37 // a webview. There can be at most one active print task per webview.
40 class PrintManager : public content::WebContentsObserver, 38 class PrintManager : public content::WebContentsObserver,
39 public content::WebContentsUserData<PrintManager>,
41 public base::NonThreadSafe { 40 public base::NonThreadSafe {
42 public: 41 public:
43 // To send receive messages to a RenderView we take the WebContents instance, 42 // Creates a PrintManager for the provided webcontents. If the printmanager
44 // as it internally handles RenderViewHost instances changing underneath us. 43 // already exists, it is destroyed and a new one is created.
45 PrintManager(content::WebContents* contents, 44 static PrintManager* CreateForWebContents(
46 printing::PrintSettings* settings, 45 content::WebContents* contents,
47 int fd, 46 printing::PrintSettings* settings,
48 PrintManagerDelegate* delegate); 47 int fd,
48 PrintManagerDelegate* delegate);
49
49 virtual ~PrintManager(); 50 virtual ~PrintManager();
50 51
51 // Prints the current document immediately. Since the rendering is 52 // Prints the current document immediately. Since the rendering is
52 // asynchronous, the actual printing will not be completed on the return of 53 // asynchronous, the actual printing will not be completed on the return of
53 // this function. Returns false if printing is impossible at the moment. 54 // this function. Returns false if printing is impossible at the moment.
54 // 55 //
55 // Note for webview: Returns false immediately if this print manager is 56 // Note for webview: Returns false immediately if this print manager is
56 // already busy printing. 57 // already busy printing.
57 bool PrintNow(); 58 bool PrintNow();
58 59
60 void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
61 int* sequence_number);
62 void OnTempFileForPrintingWritten(int sequence_number);
59 private: 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>;
71
60 virtual bool OnMessageReceived(const IPC::Message& message) override; 72 virtual bool OnMessageReceived(const IPC::Message& message) override;
61 void OnDidGetPrintedPagesCount(int cookie, int number_pages); 73 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
62 void OnDidGetDocumentCookie(int cookie); 74 void OnDidGetDocumentCookie(int cookie);
63 void OnPrintingFailed(int cookie); 75 void OnPrintingFailed(int cookie);
64 void OnGetDefaultPrintSettingsReply(IPC::Message* reply_msg); 76 void OnGetDefaultPrintSettingsReply(IPC::Message* reply_msg);
65 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); 77 void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
66 void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
67 int* sequence_number);
68 void OnTempFileForPrintingWritten(int sequence_number);
69 78
70 // Print Settings. 79 // Print Settings.
71 printing::PrintSettings* settings_; 80 printing::PrintSettings* settings_;
72 81
73 // File descriptor to export to. 82 // File descriptor to export to.
74 int fd_; 83 int fd_;
75 // Print manager delegate 84 // Print manager delegate
76 PrintManagerDelegate* delegate_; 85 PrintManagerDelegate* delegate_;
77 // Number of pages to print in the print job. 86 // Number of pages to print in the print job.
78 int number_pages_; 87 int number_pages_;
79 // The document cookie of the current PrinterQuery. 88 // The document cookie of the current PrinterQuery.
80 int cookie_; 89 int cookie_;
81 // Whether a print task is pending. 90 // Whether a print task is pending.
82 int printing_; 91 int printing_;
83 92
84 DISALLOW_COPY_AND_ASSIGN(PrintManager); 93 DISALLOW_COPY_AND_ASSIGN(PrintManager);
85 }; 94 };
86 95
87 } // namespace android_webview 96 } // namespace android_webview
88 97
89 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_ 98 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698