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 #include "url/gurl.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 class RenderFrameHost; | 15 class RenderFrameHost; |
15 class RenderProcessHost; | 16 class RenderProcessHost; |
16 } | 17 } |
17 | 18 |
18 namespace printing { | 19 namespace printing { |
19 | 20 |
20 // Manages the print commands for a WebContents. | 21 // Manages the print commands for a WebContents. |
21 class PrintViewManager : public PrintViewManagerBase, | 22 class PrintViewManager : public PrintViewManagerBase, |
22 public content::WebContentsUserData<PrintViewManager> { | 23 public content::WebContentsUserData<PrintViewManager> { |
23 public: | 24 public: |
| 25 class TestDelegate { |
| 26 public: |
| 27 virtual ~TestDelegate() {} |
| 28 |
| 29 // Called when the given RFH performs a JS window.print() call. Returns true |
| 30 // to continue processing window.print() normally, or false to immediately |
| 31 // issue an IPC reply. |
| 32 virtual bool ScriptedPrint( |
| 33 const content::RenderFrameHost* render_frame_host); |
| 34 }; |
| 35 |
24 ~PrintViewManager() override; | 36 ~PrintViewManager() override; |
25 | 37 |
26 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 38 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
27 // Same as PrintNow(), but for the case where a user prints with the system | 39 // Same as PrintNow(), but for the case where a user prints with the system |
28 // dialog from print preview. | 40 // dialog from print preview. |
29 // |dialog_shown_callback| is called when the print dialog is shown. | 41 // |dialog_shown_callback| is called when the print dialog is shown. |
30 bool PrintForSystemDialogNow(const base::Closure& dialog_shown_callback); | 42 bool PrintForSystemDialogNow(const base::Closure& dialog_shown_callback); |
31 | 43 |
32 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to | 44 // 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 | 45 // show the native system dialog. This can happen from both initiator and |
(...skipping 16 matching lines...) Expand all Loading... |
50 void PrintPreviewDone(); | 62 void PrintPreviewDone(); |
51 | 63 |
52 // content::WebContentsObserver implementation. | 64 // content::WebContentsObserver implementation. |
53 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | 65 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
54 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 66 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
55 bool OnMessageReceived(const IPC::Message& message, | 67 bool OnMessageReceived(const IPC::Message& message, |
56 content::RenderFrameHost* render_frame_host) override; | 68 content::RenderFrameHost* render_frame_host) override; |
57 | 69 |
58 content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; } | 70 content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; } |
59 | 71 |
| 72 // Used in tests to observe and/or override behavior. |
| 73 void SetTestDelegate(TestDelegate* delegate); |
| 74 |
60 private: | 75 private: |
61 explicit PrintViewManager(content::WebContents* web_contents); | 76 explicit PrintViewManager(content::WebContents* web_contents); |
62 friend class content::WebContentsUserData<PrintViewManager>; | 77 friend class content::WebContentsUserData<PrintViewManager>; |
63 | 78 |
64 enum PrintPreviewState { | 79 enum PrintPreviewState { |
65 NOT_PREVIEWING, | 80 NOT_PREVIEWING, |
66 USER_INITIATED_PREVIEW, | 81 USER_INITIATED_PREVIEW, |
67 SCRIPTED_PREVIEW, | 82 SCRIPTED_PREVIEW, |
68 }; | 83 }; |
69 | 84 |
70 // IPC Message handlers. | 85 // IPC Message handlers. |
71 void OnDidShowPrintDialog(content::RenderFrameHost* rfh); | 86 void OnDidShowPrintDialog(content::RenderFrameHost* rfh); |
72 void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, | 87 void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, |
73 IPC::Message* reply_msg); | 88 IPC::Message* reply_msg); |
74 void OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, | 89 void OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, |
75 bool source_is_modifiable); | 90 bool source_is_modifiable); |
76 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); | 91 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); |
77 | 92 |
78 base::Closure on_print_dialog_shown_callback_; | 93 base::Closure on_print_dialog_shown_callback_; |
79 | 94 |
80 // Current state of print preview for this view. | 95 // Current state of print preview for this view. |
81 PrintPreviewState print_preview_state_; | 96 PrintPreviewState print_preview_state_ = NOT_PREVIEWING; |
82 | 97 |
83 // The current RFH that is print previewing. It should be a nullptr when | 98 // The current RFH that is print previewing. It should be a nullptr when |
84 // |print_preview_state_| is NOT_PREVIEWING. | 99 // |print_preview_state_| is NOT_PREVIEWING. |
85 content::RenderFrameHost* print_preview_rfh_; | 100 content::RenderFrameHost* print_preview_rfh_ = nullptr; |
86 | 101 |
87 // Keeps track of the pending callback during scripted print preview. | 102 // Keeps track of the pending callback during scripted print preview. |
88 content::RenderProcessHost* scripted_print_preview_rph_; | 103 content::RenderProcessHost* scripted_print_preview_rph_ = nullptr; |
| 104 |
| 105 TestDelegate* test_delegate_ = nullptr; |
89 | 106 |
90 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); | 107 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
91 }; | 108 }; |
92 | 109 |
93 } // namespace printing | 110 } // namespace printing |
94 | 111 |
95 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ | 112 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
OLD | NEW |