| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
| 6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chrome/browser/printing/print_view_manager_base.h" | 9 #include "chrome/browser/printing/print_view_manager_base.h" |
| 10 #include "content/public/browser/web_contents_user_data.h" | 10 #include "content/public/browser/web_contents_user_data.h" |
| 11 #include "printing/features/features.h" | 11 #include "printing/features/features.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 class RenderFrameHost; |
| 14 class RenderProcessHost; | 15 class RenderProcessHost; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace printing { | 18 namespace printing { |
| 18 | 19 |
| 19 // Manages the print commands for a WebContents. | 20 // Manages the print commands for a WebContents. |
| 20 class PrintViewManager : public PrintViewManagerBase, | 21 class PrintViewManager : public PrintViewManagerBase, |
| 21 public content::WebContentsUserData<PrintViewManager> { | 22 public content::WebContentsUserData<PrintViewManager> { |
| 22 public: | 23 public: |
| 23 ~PrintViewManager() override; | 24 ~PrintViewManager() override; |
| 24 | 25 |
| 25 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 26 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 26 // Same as PrintNow(), but for the case where a user prints with the system | 27 // Same as PrintNow(), but for the case where a user prints with the system |
| 27 // dialog from print preview. | 28 // dialog from print preview. |
| 28 // |dialog_shown_callback| is called when the print dialog is shown. | 29 // |dialog_shown_callback| is called when the print dialog is shown. |
| 29 bool PrintForSystemDialogNow(const base::Closure& dialog_shown_callback); | 30 bool PrintForSystemDialogNow(const base::Closure& dialog_shown_callback); |
| 30 | 31 |
| 31 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to | 32 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to |
| 32 // show the native system dialog. This can happen from both initiator and | 33 // show the native system dialog. This can happen from both initiator and |
| 33 // preview dialog. | 34 // preview dialog. |
| 34 bool BasicPrint(); | 35 bool BasicPrint(content::RenderFrameHost* rfh); |
| 35 #endif // ENABLE_BASIC_PRINTING | 36 #endif // ENABLE_BASIC_PRINTING |
| 36 | 37 |
| 37 // Initiate print preview of the current document by first notifying the | 38 // Initiate print preview of the current document by first notifying the |
| 38 // renderer. Since this happens asynchronous, the print preview dialog | 39 // renderer. Since this happens asynchronous, the print preview dialog |
| 39 // creation will not be completed on the return of this function. Returns | 40 // creation will not be completed on the return of this function. Returns |
| 40 // false if print preview is impossible at the moment. | 41 // false if print preview is impossible at the moment. |
| 41 bool PrintPreviewNow(bool selection_only); | 42 bool PrintPreviewNow(content::RenderFrameHost* rfh, bool has_selection); |
| 42 | 43 |
| 43 // Notify PrintViewManager that print preview is starting in the renderer for | 44 // Notify PrintViewManager that print preview is starting in the renderer for |
| 44 // a particular WebNode. | 45 // a particular WebNode. |
| 45 void PrintPreviewForWebNode(); | 46 void PrintPreviewForWebNode(); |
| 46 | 47 |
| 47 // Notify PrintViewManager that print preview has finished. Unfreeze the | 48 // Notify PrintViewManager that print preview has finished. Unfreeze the |
| 48 // renderer in the case of scripted print preview. | 49 // renderer in the case of scripted print preview. |
| 49 void PrintPreviewDone(); | 50 void PrintPreviewDone(); |
| 50 | 51 |
| 51 // content::WebContentsObserver implementation. | 52 // content::WebContentsObserver implementation. |
| 52 bool OnMessageReceived(const IPC::Message& message) override; | 53 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
| 54 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 55 bool OnMessageReceived(const IPC::Message& message, |
| 56 content::RenderFrameHost* render_frame_host) override; |
| 53 | 57 |
| 54 // content::WebContentsObserver implementation. | 58 content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; } |
| 55 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | |
| 56 | |
| 57 // content::WebContentsObserver implementation. | |
| 58 // Terminates or cancels the print job if one was pending. | |
| 59 void RenderProcessGone(base::TerminationStatus status) override; | |
| 60 | 59 |
| 61 private: | 60 private: |
| 62 explicit PrintViewManager(content::WebContents* web_contents); | 61 explicit PrintViewManager(content::WebContents* web_contents); |
| 63 friend class content::WebContentsUserData<PrintViewManager>; | 62 friend class content::WebContentsUserData<PrintViewManager>; |
| 64 | 63 |
| 65 enum PrintPreviewState { | 64 enum PrintPreviewState { |
| 66 NOT_PREVIEWING, | 65 NOT_PREVIEWING, |
| 67 USER_INITIATED_PREVIEW, | 66 USER_INITIATED_PREVIEW, |
| 68 SCRIPTED_PREVIEW, | 67 SCRIPTED_PREVIEW, |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 // IPC Message handlers. | 70 // IPC Message handlers. |
| 72 void OnDidShowPrintDialog(); | 71 void OnDidShowPrintDialog(content::RenderFrameHost* rfh); |
| 73 void OnSetupScriptedPrintPreview(IPC::Message* reply_msg); | 72 void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 74 void OnShowScriptedPrintPreview(bool source_is_modifiable); | 73 IPC::Message* reply_msg); |
| 74 void OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 75 bool source_is_modifiable); |
| 75 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); | 76 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); |
| 76 | 77 |
| 77 base::Closure on_print_dialog_shown_callback_; | 78 base::Closure on_print_dialog_shown_callback_; |
| 78 | 79 |
| 79 // Current state of print preview for this view. | 80 // Current state of print preview for this view. |
| 80 PrintPreviewState print_preview_state_; | 81 PrintPreviewState print_preview_state_; |
| 81 | 82 |
| 83 // The current RFH that is print previewing. It should be a nullptr when |
| 84 // |print_preview_state_| is NOT_PREVIEWING. |
| 85 content::RenderFrameHost* print_preview_rfh_; |
| 86 |
| 82 // Keeps track of the pending callback during scripted print preview. | 87 // Keeps track of the pending callback during scripted print preview. |
| 83 content::RenderProcessHost* scripted_print_preview_rph_; | 88 content::RenderProcessHost* scripted_print_preview_rph_; |
| 84 | 89 |
| 85 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); | 90 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
| 86 }; | 91 }; |
| 87 | 92 |
| 88 } // namespace printing | 93 } // namespace printing |
| 89 | 94 |
| 90 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ | 95 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
| OLD | NEW |