OLD | NEW |
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 CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ |
6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ |
7 | 7 |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | 8 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
12 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
13 #include "build/build_config.h" | 11 #include "build/build_config.h" |
14 #include "components/prefs/pref_member.h" | 12 #include "components/prefs/pref_member.h" |
15 #include "components/printing/browser/print_manager.h" | 13 #include "components/printing/browser/print_manager.h" |
16 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
18 #include "printing/features/features.h" | 16 #include "printing/features/features.h" |
19 #include "printing/printed_pages_source.h" | 17 #include "printing/printed_pages_source.h" |
20 | 18 |
21 struct PrintHostMsg_DidPrintPage_Params; | 19 struct PrintHostMsg_DidPrintPage_Params; |
22 | 20 |
23 namespace content { | |
24 class RenderFrameHost; | |
25 } | |
26 | |
27 namespace printing { | 21 namespace printing { |
28 | 22 |
29 class JobEventDetails; | 23 class JobEventDetails; |
30 class MetafilePlayer; | 24 class MetafilePlayer; |
31 class PrintJob; | 25 class PrintJob; |
32 class PrintJobWorkerOwner; | 26 class PrintJobWorkerOwner; |
33 class PrintQueriesQueue; | 27 class PrintQueriesQueue; |
34 | 28 |
35 // Base class for managing the print commands for a WebContents. | 29 // Base class for managing the print commands for a WebContents. |
36 class PrintViewManagerBase : public content::NotificationObserver, | 30 class PrintViewManagerBase : public content::NotificationObserver, |
37 public PrintedPagesSource, | 31 public PrintedPagesSource, |
38 public PrintManager { | 32 public PrintManager { |
39 public: | 33 public: |
40 ~PrintViewManagerBase() override; | 34 ~PrintViewManagerBase() override; |
41 | 35 |
42 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 36 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
43 // Prints the current document immediately. Since the rendering is | 37 // Prints the current document immediately. Since the rendering is |
44 // asynchronous, the actual printing will not be completed on the return of | 38 // asynchronous, the actual printing will not be completed on the return of |
45 // this function. Returns false if printing is impossible at the moment. | 39 // this function. Returns false if printing is impossible at the moment. |
46 virtual bool PrintNow(content::RenderFrameHost* rfh); | 40 virtual bool PrintNow(); |
47 #endif // ENABLE_BASIC_PRINTING | 41 #endif // ENABLE_BASIC_PRINTING |
48 | 42 |
49 // Whether printing is enabled or not. | 43 // Whether to block scripted printing for our tab or not. |
50 void UpdatePrintingEnabled(); | 44 void UpdateScriptedPrintingBlocked(); |
51 | 45 |
52 // PrintedPagesSource implementation. | 46 // PrintedPagesSource implementation. |
53 base::string16 RenderSourceName() override; | 47 base::string16 RenderSourceName() override; |
54 | 48 |
55 protected: | 49 protected: |
56 explicit PrintViewManagerBase(content::WebContents* web_contents); | 50 explicit PrintViewManagerBase(content::WebContents* web_contents); |
57 | 51 |
58 // Helper method for Print*Now(). | 52 // Helper method for Print*Now(). |
59 bool PrintNowInternal(content::RenderFrameHost* rfh, | 53 bool PrintNowInternal(IPC::Message* message); |
60 std::unique_ptr<IPC::Message> message); | |
61 | 54 |
62 void SetPrintingRFH(content::RenderFrameHost* rfh); | 55 // Terminates or cancels the print job if one was pending. |
| 56 void RenderProcessGone(base::TerminationStatus status) override; |
63 | 57 |
64 // content::WebContentsObserver implementation. | 58 // content::WebContentsObserver implementation. |
65 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 59 bool OnMessageReceived(const IPC::Message& message) override; |
66 bool OnMessageReceived(const IPC::Message& message, | |
67 content::RenderFrameHost* render_frame_host) override; | |
68 | 60 |
69 private: | 61 private: |
70 // content::NotificationObserver implementation. | 62 // content::NotificationObserver implementation. |
71 void Observe(int type, | 63 void Observe(int type, |
72 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
73 const content::NotificationDetails& details) override; | 65 const content::NotificationDetails& details) override; |
74 | 66 |
75 // content::WebContentsObserver implementation. | 67 // content::WebContentsObserver implementation. |
76 void DidStartLoading() override; | 68 void DidStartLoading() override; |
77 | 69 |
(...skipping 24 matching lines...) Expand all Loading... |
102 // Creates a new empty print job. It has no settings loaded. If there is | 94 // Creates a new empty print job. It has no settings loaded. If there is |
103 // currently a print job, safely disconnect from it. Returns false if it is | 95 // currently a print job, safely disconnect from it. Returns false if it is |
104 // impossible to safely disconnect from the current print job or it is | 96 // impossible to safely disconnect from the current print job or it is |
105 // impossible to create a new print job. | 97 // impossible to create a new print job. |
106 bool CreateNewPrintJob(PrintJobWorkerOwner* job); | 98 bool CreateNewPrintJob(PrintJobWorkerOwner* job); |
107 | 99 |
108 // Makes sure the current print_job_ has all its data before continuing, and | 100 // Makes sure the current print_job_ has all its data before continuing, and |
109 // disconnect from it. | 101 // disconnect from it. |
110 void DisconnectFromCurrentPrintJob(); | 102 void DisconnectFromCurrentPrintJob(); |
111 | 103 |
| 104 // Notify that the printing is done. |
| 105 void PrintingDone(bool success); |
| 106 |
112 // Terminates the print job. No-op if no print job has been created. If | 107 // Terminates the print job. No-op if no print job has been created. If |
113 // |cancel| is true, cancel it instead of waiting for the job to finish. Will | 108 // |cancel| is true, cancel it instead of waiting for the job to finish. Will |
114 // call ReleasePrintJob(). | 109 // call ReleasePrintJob(). |
115 void TerminatePrintJob(bool cancel); | 110 void TerminatePrintJob(bool cancel); |
116 | 111 |
117 // Releases print_job_. Correctly deregisters from notifications. No-op if | 112 // Releases print_job_. Correctly deregisters from notifications. No-op if |
118 // no print job has been created. | 113 // no print job has been created. |
119 void ReleasePrintJob(); | 114 void ReleasePrintJob(); |
120 | 115 |
121 // Runs an inner message loop. It will set inside_inner_message_loop_ to true | 116 // Runs an inner message loop. It will set inside_inner_message_loop_ to true |
122 // while the blocking inner message loop is running. This is useful in cases | 117 // while the blocking inner message loop is running. This is useful in cases |
123 // where the RenderView is about to be destroyed while a printing job isn't | 118 // where the RenderView is about to be destroyed while a printing job isn't |
124 // finished. | 119 // finished. |
125 bool RunInnerMessageLoop(); | 120 bool RunInnerMessageLoop(); |
126 | 121 |
127 // In the case of Scripted Printing, where the renderer is controlling the | 122 // In the case of Scripted Printing, where the renderer is controlling the |
128 // control flow, print_job_ is initialized whenever possible. No-op is | 123 // control flow, print_job_ is initialized whenever possible. No-op is |
129 // print_job_ is initialized. | 124 // print_job_ is initialized. |
130 bool OpportunisticallyCreatePrintJob(int cookie); | 125 bool OpportunisticallyCreatePrintJob(int cookie); |
131 | 126 |
132 // Release the PrinterQuery associated with our |cookie_|. | 127 // Release the PrinterQuery associated with our |cookie_|. |
133 void ReleasePrinterQuery(); | 128 void ReleasePrinterQuery(); |
134 | 129 |
135 // Helper method for UpdatePrintingEnabled(). | |
136 void SendPrintingEnabled(bool enabled, content::RenderFrameHost* rfh); | |
137 | |
138 content::NotificationRegistrar registrar_; | 130 content::NotificationRegistrar registrar_; |
139 | 131 |
140 // The current RFH that is printing with a system printing dialog. | |
141 content::RenderFrameHost* printing_rfh_; | |
142 | |
143 // Manages the low-level talk to the printer. | 132 // Manages the low-level talk to the printer. |
144 scoped_refptr<PrintJob> print_job_; | 133 scoped_refptr<PrintJob> print_job_; |
145 | 134 |
146 // Indication of success of the print job. | 135 // Indication of success of the print job. |
147 bool printing_succeeded_; | 136 bool printing_succeeded_; |
148 | 137 |
149 // Running an inner message loop inside RenderAllMissingPagesNow(). This means | 138 // Running an inner message loop inside RenderAllMissingPagesNow(). This means |
150 // we are _blocking_ until all the necessary pages have been rendered or the | 139 // we are _blocking_ until all the necessary pages have been rendered or the |
151 // print settings are being loaded. | 140 // print settings are being loaded. |
152 bool inside_inner_message_loop_; | 141 bool inside_inner_message_loop_; |
153 | 142 |
154 #if !defined(OS_MACOSX) | 143 #if !defined(OS_MACOSX) |
155 // Set to true when OnDidPrintPage() should be expecting the first page. | 144 // Set to true when OnDidPrintPage() should be expecting the first page. |
156 bool expecting_first_page_; | 145 bool expecting_first_page_; |
157 #endif | 146 #endif |
158 | 147 |
159 // Whether printing is enabled. | 148 // Whether printing is enabled. |
160 BooleanPrefMember printing_enabled_; | 149 BooleanPrefMember printing_enabled_; |
161 | 150 |
162 scoped_refptr<printing::PrintQueriesQueue> queue_; | 151 scoped_refptr<printing::PrintQueriesQueue> queue_; |
163 | 152 |
164 DISALLOW_COPY_AND_ASSIGN(PrintViewManagerBase); | 153 DISALLOW_COPY_AND_ASSIGN(PrintViewManagerBase); |
165 }; | 154 }; |
166 | 155 |
167 } // namespace printing | 156 } // namespace printing |
168 | 157 |
169 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ | 158 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ |
OLD | NEW |