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