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