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