[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" |
Gyuyoung Kim | f9d551d | 2020-02-20 00:50:21 | [diff] [blame] | 10 | #include "components/printing/common/print.mojom-forward.h" |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 11 | #include "content/public/browser/web_contents_user_data.h" |
Julie Jeongeun Kim | 52b2da7 | 2019-11-20 00:02:35 | [diff] [blame] | 12 | #include "mojo/public/cpp/bindings/pending_associated_remote.h" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 13 | #include "printing/buildflags/buildflags.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 15 | namespace content { |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 16 | class RenderFrameHost; |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 17 | class RenderProcessHost; |
| 18 | } |
| 19 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | namespace printing { |
| 21 | |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 22 | // Manages the print commands for a WebContents. |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 23 | class PrintViewManager : public PrintViewManagerBase, |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 24 | public content::WebContentsUserData<PrintViewManager> { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | public: |
dcheng | df7e44a7 | 2014-10-21 23:50:19 | [diff] [blame] | 26 | ~PrintViewManager() override; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | |
[email protected] | 3121c76b | 2011-07-22 02:34:32 | [diff] [blame] | 28 | // Same as PrintNow(), but for the case where a user prints with the system |
| 29 | // dialog from print preview. |
thestig | f811720 | 2016-02-26 19:05:14 | [diff] [blame] | 30 | // |dialog_shown_callback| is called when the print dialog is shown. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 31 | bool PrintForSystemDialogNow(base::OnceClosure dialog_shown_callback); |
[email protected] | 3121c76b | 2011-07-22 02:34:32 | [diff] [blame] | 32 | |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 33 | // 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] | 34 | // show the native system dialog. This can happen from both initiator and |
[email protected] | c248f555 | 2013-01-26 01:58:49 | [diff] [blame] | 35 | // preview dialog. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 36 | bool BasicPrint(content::RenderFrameHost* rfh); |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 37 | |
Jesse Schettler | fd3df7e8 | 2019-09-16 23:23:18 | [diff] [blame] | 38 | // Initiate print preview of the current document and specify whether a |
| 39 | // selection or the entire frame is being printed. |
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 | |
Jesse Schettler | fd3df7e8 | 2019-09-16 23:23:18 | [diff] [blame] | 42 | // Initiate print preview of the current document and provide the renderer |
| 43 | // a printing::mojom::PrintRenderer to perform the actual rendering of |
| 44 | // the print document. |
| 45 | bool PrintPreviewWithPrintRenderer( |
| 46 | content::RenderFrameHost* rfh, |
Julie Jeongeun Kim | 52b2da7 | 2019-11-20 00:02:35 | [diff] [blame] | 47 | mojo::PendingAssociatedRemote<mojom::PrintRenderer> print_renderer); |
Jesse Schettler | fd3df7e8 | 2019-09-16 23:23:18 | [diff] [blame] | 48 | |
[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 49 | // Notify PrintViewManager that print preview is starting in the renderer for |
| 50 | // a particular WebNode. |
thestig | 4665756 | 2016-11-21 21:35:22 | [diff] [blame] | 51 | void PrintPreviewForWebNode(content::RenderFrameHost* rfh); |
[email protected] | 9a26bb2 | 2012-01-24 23:50:25 | [diff] [blame] | 52 | |
Lei Zhang | 218f742d0 | 2019-03-05 05:18:40 | [diff] [blame] | 53 | // Notify PrintViewManager that print preview is about to finish. Unblock the |
| 54 | // renderer in the case of scripted print preview if needed. |
| 55 | void PrintPreviewAlmostDone(); |
| 56 | |
| 57 | // Notify PrintViewManager that print preview has finished. Unblock the |
| 58 | // renderer in the case of scripted print preview if needed. |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 59 | void PrintPreviewDone(); |
| 60 | |
Sergey Poromov | a47abfc8 | 2020-09-24 10:16:24 | [diff] [blame] | 61 | // Checks whether printing is currently restricted and aborts print preview if |
| 62 | // needed. |
| 63 | bool RejectPrintPreviewRequestIfRestricted(content::RenderFrameHost* rfh); |
| 64 | |
Julie Jeongeun Kim | a75e43f | 2020-08-25 07:21:32 | [diff] [blame] | 65 | // mojom::PrintManagerHost: |
| 66 | void DidShowPrintDialog() override; |
Julie Jeongeun Kim | ec9f86b | 2020-12-08 03:32:35 | [diff] [blame] | 67 | void ShowScriptedPrintPreview(bool source_is_modifiable) override; |
Julie Jeongeun Kim | a75e43f | 2020-08-25 07:21:32 | [diff] [blame] | 68 | |
[email protected] | 08ad957 | 2012-07-26 21:03:39 | [diff] [blame] | 69 | // content::WebContentsObserver implementation. |
sgurun | 356feed5 | 2016-11-16 16:13:06 | [diff] [blame] | 70 | void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 71 | void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 72 | bool OnMessageReceived(const IPC::Message& message, |
| 73 | content::RenderFrameHost* render_frame_host) override; |
sgurun | 356feed5 | 2016-11-16 16:13:06 | [diff] [blame] | 74 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 75 | content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; } |
[email protected] | 2e3f457 | 2011-03-25 19:24:47 | [diff] [blame] | 76 | |
rbpotter | fdff067 | 2018-04-12 20:46:58 | [diff] [blame] | 77 | protected: |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 78 | explicit PrintViewManager(content::WebContents* web_contents); |
rbpotter | fdff067 | 2018-04-12 20:46:58 | [diff] [blame] | 79 | |
| 80 | private: |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 81 | friend class content::WebContentsUserData<PrintViewManager>; |
[email protected] | e3a7e6f | 2012-09-18 22:44:31 | [diff] [blame] | 82 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 83 | enum PrintPreviewState { |
| 84 | NOT_PREVIEWING, |
| 85 | USER_INITIATED_PREVIEW, |
| 86 | SCRIPTED_PREVIEW, |
| 87 | }; |
| 88 | |
Lukasz Anforowicz | f4357ca | 2017-09-07 01:43:32 | [diff] [blame] | 89 | struct FrameDispatchHelper; |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 90 | |
Jesse Schettler | fd3df7e8 | 2019-09-16 23:23:18 | [diff] [blame] | 91 | // Helper method for PrintPreviewNow() and PrintPreviewWithRenderer(). |
| 92 | // Initiate print preview of the current document by first notifying the |
| 93 | // renderer. Since this happens asynchronously, the print preview dialog |
| 94 | // creation will not be completed on the return of this function. Returns |
| 95 | // false if print preview is impossible at the moment. |
Julie Jeongeun Kim | 52b2da7 | 2019-11-20 00:02:35 | [diff] [blame] | 96 | bool PrintPreview( |
| 97 | content::RenderFrameHost* rfh, |
| 98 | mojo::PendingAssociatedRemote<mojom::PrintRenderer> print_renderer, |
| 99 | bool has_selection); |
Jesse Schettler | fd3df7e8 | 2019-09-16 23:23:18 | [diff] [blame] | 100 | |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 101 | // IPC Message handlers. |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 102 | void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, |
| 103 | IPC::Message* reply_msg); |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 104 | void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); |
| 105 | |
Lei Zhang | 218f742d0 | 2019-03-05 05:18:40 | [diff] [blame] | 106 | void MaybeUnblockScriptedPreviewRPH(); |
| 107 | |
Sergey Poromov | a47abfc8 | 2020-09-24 10:16:24 | [diff] [blame] | 108 | // Checks whether printing is restricted due to Data Leak Protection rules. |
| 109 | bool IsPrintingRestricted() const; |
| 110 | |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 111 | base::OnceClosure on_print_dialog_shown_callback_; |
[email protected] | 0b481bf | 2011-06-29 20:33:00 | [diff] [blame] | 112 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 113 | // Current state of print preview for this view. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 114 | PrintPreviewState print_preview_state_ = NOT_PREVIEWING; |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 115 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 116 | // The current RFH that is print previewing. It should be a nullptr when |
| 117 | // |print_preview_state_| is NOT_PREVIEWING. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 118 | content::RenderFrameHost* print_preview_rfh_ = nullptr; |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 119 | |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 120 | // Keeps track of the pending callback during scripted print preview. |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 121 | content::RenderProcessHost* scripted_print_preview_rph_ = nullptr; |
[email protected] | a9c3683 | 2011-11-23 08:55:24 | [diff] [blame] | 122 | |
Lei Zhang | 218f742d0 | 2019-03-05 05:18:40 | [diff] [blame] | 123 | // True if |scripted_print_preview_rph_| needs to be unblocked. |
| 124 | bool scripted_print_preview_rph_set_blocked_ = false; |
| 125 | |
Kent Tamura | 18c99f9a | 2017-09-25 05:39:32 | [diff] [blame] | 126 | // Indicates whether we're switching from print preview to system dialog. This |
| 127 | // flag is true between PrintForSystemDialogNow() and PrintPreviewDone(). |
Lei Zhang | 3398fa5 | 2018-10-31 18:27:11 | [diff] [blame] | 128 | bool is_switching_to_system_dialog_ = false; |
Kent Tamura | 18c99f9a | 2017-09-25 05:39:32 | [diff] [blame] | 129 | |
François Doray | 4f51d5d | 2018-12-03 22:26:24 | [diff] [blame] | 130 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| 131 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 132 | DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } // namespace printing |
| 136 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 137 | #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |