[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" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 11 | #include "printing/buildflags/buildflags.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 | |
[email protected] | 3121c76b | 2011-07-22 02:34:32 | [diff] [blame] | 26 | // Same as PrintNow(), but for the case where a user prints with the system |
| 27 | // dialog from print preview. |
thestig | f811720 | 2016-02-26 19:05:14 | [diff] [blame] | 28 | // |dialog_shown_callback| is called when the print dialog is shown. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 29 | bool PrintForSystemDialogNow(base::OnceClosure dialog_shown_callback); |
[email protected] | 3121c76b | 2011-07-22 02:34:32 | [diff] [blame] | 30 | |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 31 | // 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] | 32 | // show the native system dialog. This can happen from both initiator and |
[email protected] | c248f555 | 2013-01-26 01:58:49 | [diff] [blame] | 33 | // preview dialog. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 34 | bool BasicPrint(content::RenderFrameHost* rfh); |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 35 | |
[email protected] | 8980e0d | 2011-05-27 19:16:23 | [diff] [blame] | 36 | // Initiate print preview of the current document by first notifying the |
[email protected] | c248f555 | 2013-01-26 01:58:49 | [diff] [blame] | 37 | // renderer. Since this happens asynchronous, the print preview dialog |
| 38 | // creation will not be completed on the return of this function. Returns |
| 39 | // false if print preview is impossible at the moment. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 40 | bool PrintPreviewNow(content::RenderFrameHost* rfh, bool has_selection); |
[email protected] | 8980e0d | 2011-05-27 19:16:23 | [diff] [blame] | 41 | |
[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 42 | // Notify PrintViewManager that print preview is starting in the renderer for |
| 43 | // a particular WebNode. |
thestig | 4665756 | 2016-11-21 21:35:22 | [diff] [blame] | 44 | void PrintPreviewForWebNode(content::RenderFrameHost* rfh); |
[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 45 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 46 | // Notify PrintViewManager that print preview has finished. Unfreeze the |
| 47 | // renderer in the case of scripted print preview. |
| 48 | void PrintPreviewDone(); |
| 49 | |
[email protected] | 08ad957 | 2012-07-26 21:03:39 | [diff] [blame] | 50 | // content::WebContentsObserver implementation. |
sgurun | 356feed5 | 2016-11-16 16:13:06 | [diff] [blame] | 51 | void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 52 | void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 53 | bool OnMessageReceived(const IPC::Message& message, |
| 54 | content::RenderFrameHost* render_frame_host) override; |
sgurun | 356feed5 | 2016-11-16 16:13:06 | [diff] [blame] | 55 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 56 | content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; } |
[email protected] | 2e3f457 | 2011-03-25 19:24:47 | [diff] [blame] | 57 | |
rbpotter | fdff067 | 2018-04-12 20:46:58 | [diff] [blame] | 58 | protected: |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 59 | explicit PrintViewManager(content::WebContents* web_contents); |
rbpotter | fdff067 | 2018-04-12 20:46:58 | [diff] [blame] | 60 | |
| 61 | private: |
[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 | |
Lukasz Anforowicz | f4357ca | 2017-09-07 01:43:32 | [diff] [blame] | 70 | struct FrameDispatchHelper; |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 71 | |
| 72 | // IPC Message handlers. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 73 | void OnDidShowPrintDialog(content::RenderFrameHost* rfh); |
| 74 | void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 75 | IPC::Message* reply_msg); |
| 76 | void OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 77 | bool source_is_modifiable); |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 78 | void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); |
| 79 | |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 80 | base::OnceClosure on_print_dialog_shown_callback_; |
[email protected] | 0b481bf | 2011-06-29 20:33:00 | [diff] [blame] | 81 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 82 | // Current state of print preview for this view. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 83 | PrintPreviewState print_preview_state_ = NOT_PREVIEWING; |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 84 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 85 | // The current RFH that is print previewing. It should be a nullptr when |
| 86 | // |print_preview_state_| is NOT_PREVIEWING. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 87 | content::RenderFrameHost* print_preview_rfh_ = nullptr; |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 88 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 89 | // Keeps track of the pending callback during scripted print preview. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 90 | content::RenderProcessHost* scripted_print_preview_rph_ = nullptr; |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 91 | |
Kent Tamura | 18c99f9a | 2017-09-25 05:39:32 | [diff] [blame] | 92 | // Indicates whether we're switching from print preview to system dialog. This |
| 93 | // flag is true between PrintForSystemDialogNow() and PrintPreviewDone(). |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 94 | bool is_switching_to_system_dialog_ = false; |
Kent Tamura | 18c99f9a | 2017-09-25 05:39:32 | [diff] [blame] | 95 | |
François Doray | 4f51d5d | 2018-12-03 22:26:24 | [diff] [blame^] | 96 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| 97 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 98 | DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace printing |
| 102 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 103 | #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |