[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 9 | #include "chrome/browser/printing/print_view_manager_base.h" |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 10 | #include "content/public/browser/web_contents_user_data.h" |
Brett Wilson | 65f951c | 2016-11-03 22:06:12 | [diff] [blame] | 11 | #include "printing/features/features.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 13 | namespace content { |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 14 | class RenderFrameHost; |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 15 | class RenderProcessHost; |
| 16 | } |
| 17 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | namespace printing { |
| 19 | |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 20 | // Manages the print commands for a WebContents. |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 21 | class PrintViewManager : public PrintViewManagerBase, |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 22 | public content::WebContentsUserData<PrintViewManager> { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | public: |
dcheng | df7e44a7 | 2014-10-21 23:50:19 | [diff] [blame] | 24 | ~PrintViewManager() override; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | |
Brett Wilson | 65f951c | 2016-11-03 22:06:12 | [diff] [blame] | 26 | #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
[email protected] | 3121c76b | 2011-07-22 02:34:32 | [diff] [blame] | 27 | // Same as PrintNow(), but for the case where a user prints with the system |
| 28 | // dialog from print preview. |
thestig | f811720 | 2016-02-26 19:05:14 | [diff] [blame] | 29 | // |dialog_shown_callback| is called when the print dialog is shown. |
| 30 | bool PrintForSystemDialogNow(const base::Closure& dialog_shown_callback); |
[email protected] | 3121c76b | 2011-07-22 02:34:32 | [diff] [blame] | 31 | |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 32 | // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to |
[email protected] | e6c97f6d | 2013-08-02 00:47:05 | [diff] [blame] | 33 | // show the native system dialog. This can happen from both initiator and |
[email protected] | c248f555 | 2013-01-26 01:58:49 | [diff] [blame] | 34 | // preview dialog. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 35 | bool BasicPrint(content::RenderFrameHost* rfh); |
vitalybuka | e29991c | 2014-11-05 21:15:12 | [diff] [blame] | 36 | #endif // ENABLE_BASIC_PRINTING |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 37 | |
[email protected] | 8980e0d | 2011-05-27 19:16:23 | [diff] [blame] | 38 | // Initiate print preview of the current document by first notifying the |
[email protected] | c248f555 | 2013-01-26 01:58:49 | [diff] [blame] | 39 | // renderer. Since this happens asynchronous, the print preview dialog |
| 40 | // creation will not be completed on the return of this function. Returns |
| 41 | // false if print preview is impossible at the moment. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 42 | bool PrintPreviewNow(content::RenderFrameHost* rfh, bool has_selection); |
[email protected] | 8980e0d | 2011-05-27 19:16:23 | [diff] [blame] | 43 | |
[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 44 | // Notify PrintViewManager that print preview is starting in the renderer for |
| 45 | // a particular WebNode. |
thestig | 4665756 | 2016-11-21 21:35:22 | [diff] [blame] | 46 | void PrintPreviewForWebNode(content::RenderFrameHost* rfh); |
[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 47 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 48 | // Notify PrintViewManager that print preview has finished. Unfreeze the |
| 49 | // renderer in the case of scripted print preview. |
| 50 | void PrintPreviewDone(); |
| 51 | |
[email protected] | 08ad957 | 2012-07-26 21:03:39 | [diff] [blame] | 52 | // content::WebContentsObserver implementation. |
sgurun | 356feed5 | 2016-11-16 16:13:06 | [diff] [blame] | 53 | void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 54 | void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 55 | bool OnMessageReceived(const IPC::Message& message, |
| 56 | content::RenderFrameHost* render_frame_host) override; |
sgurun | 356feed5 | 2016-11-16 16:13:06 | [diff] [blame] | 57 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 58 | content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; } |
[email protected] | 2e3f457 | 2011-03-25 19:24:47 | [diff] [blame] | 59 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | private: |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 61 | explicit PrintViewManager(content::WebContents* web_contents); |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 62 | friend class content::WebContentsUserData<PrintViewManager>; |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 63 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 64 | enum PrintPreviewState { |
| 65 | NOT_PREVIEWING, |
| 66 | USER_INITIATED_PREVIEW, |
| 67 | SCRIPTED_PREVIEW, |
| 68 | }; |
| 69 | |
[email protected] | b3ee0b52 | 2011-05-06 04:06:40 | [diff] [blame] | 70 | // IPC Message handlers. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 71 | void OnDidShowPrintDialog(content::RenderFrameHost* rfh); |
| 72 | void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 73 | IPC::Message* reply_msg); |
| 74 | void OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 75 | bool source_is_modifiable); |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 76 | void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); |
| 77 | |
thestig | f811720 | 2016-02-26 19:05:14 | [diff] [blame] | 78 | base::Closure on_print_dialog_shown_callback_; |
[email protected] | 0b481bf | 2011-06-29 20:33:00 | [diff] [blame] | 79 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 80 | // Current state of print preview for this view. |
| 81 | PrintPreviewState print_preview_state_; |
| 82 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 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 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 87 | // Keeps track of the pending callback during scripted print preview. |
| 88 | content::RenderProcessHost* scripted_print_preview_rph_; |
| 89 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 90 | DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace printing |
| 94 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 95 | #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |