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