blob: 4cabe91d08ca522e96911803e6203d80bd8895e4 [file] [log] [blame]
[email protected]9a26bb22012-01-24 23:50:251// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]bfd04a62009-02-01 18:16:565#ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
6#define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
initial.commit09911bf2008-07-26 23:55:297
avib896c712015-12-26 02:10:438#include "base/macros.h"
[email protected]1e54c1c2013-08-12 17:16:059#include "chrome/browser/printing/print_view_manager_base.h"
Jesse Schettlerfd3df7e82019-09-16 23:23:1810#include "components/printing/common/print.mojom.h"
[email protected]46b3c982012-10-09 18:38:3011#include "content/public/browser/web_contents_user_data.h"
Scott Violet318a55f2018-03-30 19:08:1912#include "printing/buildflags/buildflags.h"
initial.commit09911bf2008-07-26 23:55:2913
[email protected]a9c36832011-11-23 08:55:2414namespace content {
thestigcb959ce2016-11-17 05:56:3215class RenderFrameHost;
[email protected]a9c36832011-11-23 08:55:2416class RenderProcessHost;
17}
18
initial.commit09911bf2008-07-26 23:55:2919namespace printing {
20
[email protected]e3a7e6f2012-09-18 22:44:3121// Manages the print commands for a WebContents.
[email protected]1e54c1c2013-08-12 17:16:0522class PrintViewManager : public PrintViewManagerBase,
[email protected]46b3c982012-10-09 18:38:3023 public content::WebContentsUserData<PrintViewManager> {
initial.commit09911bf2008-07-26 23:55:2924 public:
dchengdf7e44a72014-10-21 23:50:1925 ~PrintViewManager() override;
initial.commit09911bf2008-07-26 23:55:2926
[email protected]3121c76b2011-07-22 02:34:3227 // Same as PrintNow(), but for the case where a user prints with the system
28 // dialog from print preview.
thestigf8117202016-02-26 19:05:1429 // |dialog_shown_callback| is called when the print dialog is shown.
Lei Zhang3398fa52018-10-31 18:27:1130 bool PrintForSystemDialogNow(base::OnceClosure dialog_shown_callback);
[email protected]3121c76b2011-07-22 02:34:3231
[email protected]0996e9b2011-08-26 17:59:0132 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
[email protected]e6c97f6d2013-08-02 00:47:0533 // show the native system dialog. This can happen from both initiator and
[email protected]c248f5552013-01-26 01:58:4934 // preview dialog.
thestigcb959ce2016-11-17 05:56:3235 bool BasicPrint(content::RenderFrameHost* rfh);
[email protected]0996e9b2011-08-26 17:59:0136
Jesse Schettlerfd3df7e82019-09-16 23:23:1837 // Initiate print preview of the current document and specify whether a
38 // selection or the entire frame is being printed.
thestigcb959ce2016-11-17 05:56:3239 bool PrintPreviewNow(content::RenderFrameHost* rfh, bool has_selection);
[email protected]8980e0d2011-05-27 19:16:2340
Jesse Schettlerfd3df7e82019-09-16 23:23:1841 // Initiate print preview of the current document and provide the renderer
42 // a printing::mojom::PrintRenderer to perform the actual rendering of
43 // the print document.
44 bool PrintPreviewWithPrintRenderer(
45 content::RenderFrameHost* rfh,
46 mojom::PrintRendererAssociatedPtrInfo print_renderer);
47
[email protected]9a26bb22012-01-24 23:50:2548 // Notify PrintViewManager that print preview is starting in the renderer for
49 // a particular WebNode.
thestig46657562016-11-21 21:35:2250 void PrintPreviewForWebNode(content::RenderFrameHost* rfh);
[email protected]9a26bb22012-01-24 23:50:2551
Lei Zhang218f742d02019-03-05 05:18:4052 // Notify PrintViewManager that print preview is about to finish. Unblock the
53 // renderer in the case of scripted print preview if needed.
54 void PrintPreviewAlmostDone();
55
56 // Notify PrintViewManager that print preview has finished. Unblock the
57 // renderer in the case of scripted print preview if needed.
[email protected]a9c36832011-11-23 08:55:2458 void PrintPreviewDone();
59
[email protected]08ad9572012-07-26 21:03:3960 // content::WebContentsObserver implementation.
sgurun356feed52016-11-16 16:13:0661 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
thestigcb959ce2016-11-17 05:56:3262 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
63 bool OnMessageReceived(const IPC::Message& message,
64 content::RenderFrameHost* render_frame_host) override;
sgurun356feed52016-11-16 16:13:0665
thestigcb959ce2016-11-17 05:56:3266 content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; }
[email protected]2e3f4572011-03-25 19:24:4767
rbpotterfdff0672018-04-12 20:46:5868 protected:
[email protected]e3a7e6f2012-09-18 22:44:3169 explicit PrintViewManager(content::WebContents* web_contents);
rbpotterfdff0672018-04-12 20:46:5870
71 private:
[email protected]46b3c982012-10-09 18:38:3072 friend class content::WebContentsUserData<PrintViewManager>;
[email protected]e3a7e6f2012-09-18 22:44:3173
[email protected]a9c36832011-11-23 08:55:2474 enum PrintPreviewState {
75 NOT_PREVIEWING,
76 USER_INITIATED_PREVIEW,
77 SCRIPTED_PREVIEW,
78 };
79
Lukasz Anforowiczf4357ca2017-09-07 01:43:3280 struct FrameDispatchHelper;
Lei Zhang3398fa52018-10-31 18:27:1181
Jesse Schettlerfd3df7e82019-09-16 23:23:1882 // Helper method for PrintPreviewNow() and PrintPreviewWithRenderer().
83 // Initiate print preview of the current document by first notifying the
84 // renderer. Since this happens asynchronously, the print preview dialog
85 // creation will not be completed on the return of this function. Returns
86 // false if print preview is impossible at the moment.
87 bool PrintPreview(content::RenderFrameHost* rfh,
88 mojom::PrintRendererAssociatedPtrInfo print_renderer,
89 bool has_selection);
90
Lei Zhang3398fa52018-10-31 18:27:1191 // IPC Message handlers.
thestigcb959ce2016-11-17 05:56:3292 void OnDidShowPrintDialog(content::RenderFrameHost* rfh);
93 void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh,
94 IPC::Message* reply_msg);
95 void OnShowScriptedPrintPreview(content::RenderFrameHost* rfh,
96 bool source_is_modifiable);
[email protected]a9c36832011-11-23 08:55:2497 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
98
Lei Zhang218f742d02019-03-05 05:18:4099 void MaybeUnblockScriptedPreviewRPH();
100
Lei Zhang3398fa52018-10-31 18:27:11101 base::OnceClosure on_print_dialog_shown_callback_;
[email protected]0b481bf2011-06-29 20:33:00102
[email protected]a9c36832011-11-23 08:55:24103 // Current state of print preview for this view.
Lei Zhang3398fa52018-10-31 18:27:11104 PrintPreviewState print_preview_state_ = NOT_PREVIEWING;
[email protected]a9c36832011-11-23 08:55:24105
thestigcb959ce2016-11-17 05:56:32106 // The current RFH that is print previewing. It should be a nullptr when
107 // |print_preview_state_| is NOT_PREVIEWING.
Lei Zhang3398fa52018-10-31 18:27:11108 content::RenderFrameHost* print_preview_rfh_ = nullptr;
thestigcb959ce2016-11-17 05:56:32109
[email protected]a9c36832011-11-23 08:55:24110 // Keeps track of the pending callback during scripted print preview.
Lei Zhang3398fa52018-10-31 18:27:11111 content::RenderProcessHost* scripted_print_preview_rph_ = nullptr;
[email protected]a9c36832011-11-23 08:55:24112
Lei Zhang218f742d02019-03-05 05:18:40113 // True if |scripted_print_preview_rph_| needs to be unblocked.
114 bool scripted_print_preview_rph_set_blocked_ = false;
115
Kent Tamura18c99f9a2017-09-25 05:39:32116 // Indicates whether we're switching from print preview to system dialog. This
117 // flag is true between PrintForSystemDialogNow() and PrintPreviewDone().
Lei Zhang3398fa52018-10-31 18:27:11118 bool is_switching_to_system_dialog_ = false;
Kent Tamura18c99f9a2017-09-25 05:39:32119
François Doray4f51d5d2018-12-03 22:26:24120 WEB_CONTENTS_USER_DATA_KEY_DECL();
121
[email protected]bfd04a62009-02-01 18:16:56122 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29123};
124
125} // namespace printing
126
[email protected]bfd04a62009-02-01 18:16:56127#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_