blob: 1d7de8c4e926a08e1d8a5151d1086c4fc27912c7 [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"
Gyuyoung Kimf9d551d2020-02-20 00:50:2110#include "components/printing/common/print.mojom-forward.h"
[email protected]46b3c982012-10-09 18:38:3011#include "content/public/browser/web_contents_user_data.h"
Julie Jeongeun Kim52b2da72019-11-20 00:02:3512#include "mojo/public/cpp/bindings/pending_associated_remote.h"
Scott Violet318a55f2018-03-30 19:08:1913#include "printing/buildflags/buildflags.h"
initial.commit09911bf2008-07-26 23:55:2914
[email protected]a9c36832011-11-23 08:55:2415namespace content {
thestigcb959ce2016-11-17 05:56:3216class RenderFrameHost;
[email protected]a9c36832011-11-23 08:55:2417class RenderProcessHost;
18}
19
initial.commit09911bf2008-07-26 23:55:2920namespace printing {
21
[email protected]e3a7e6f2012-09-18 22:44:3122// Manages the print commands for a WebContents.
[email protected]1e54c1c2013-08-12 17:16:0523class PrintViewManager : public PrintViewManagerBase,
[email protected]46b3c982012-10-09 18:38:3024 public content::WebContentsUserData<PrintViewManager> {
initial.commit09911bf2008-07-26 23:55:2925 public:
dchengdf7e44a72014-10-21 23:50:1926 ~PrintViewManager() override;
initial.commit09911bf2008-07-26 23:55:2927
[email protected]3121c76b2011-07-22 02:34:3228 // Same as PrintNow(), but for the case where a user prints with the system
29 // dialog from print preview.
thestigf8117202016-02-26 19:05:1430 // |dialog_shown_callback| is called when the print dialog is shown.
Lei Zhang3398fa52018-10-31 18:27:1131 bool PrintForSystemDialogNow(base::OnceClosure dialog_shown_callback);
[email protected]3121c76b2011-07-22 02:34:3232
[email protected]0996e9b2011-08-26 17:59:0133 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
[email protected]e6c97f6d2013-08-02 00:47:0534 // show the native system dialog. This can happen from both initiator and
[email protected]c248f5552013-01-26 01:58:4935 // preview dialog.
thestigcb959ce2016-11-17 05:56:3236 bool BasicPrint(content::RenderFrameHost* rfh);
[email protected]0996e9b2011-08-26 17:59:0137
Jesse Schettlerfd3df7e82019-09-16 23:23:1838 // Initiate print preview of the current document and specify whether a
39 // selection or the entire frame is being printed.
thestigcb959ce2016-11-17 05:56:3240 bool PrintPreviewNow(content::RenderFrameHost* rfh, bool has_selection);
[email protected]8980e0d2011-05-27 19:16:2341
Jesse Schettlerfd3df7e82019-09-16 23:23:1842 // 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 Kim52b2da72019-11-20 00:02:3547 mojo::PendingAssociatedRemote<mojom::PrintRenderer> print_renderer);
Jesse Schettlerfd3df7e82019-09-16 23:23:1848
[email protected]9a26bb22012-01-24 23:50:2549 // Notify PrintViewManager that print preview is starting in the renderer for
50 // a particular WebNode.
thestig46657562016-11-21 21:35:2251 void PrintPreviewForWebNode(content::RenderFrameHost* rfh);
[email protected]9a26bb22012-01-24 23:50:2552
Lei Zhang218f742d02019-03-05 05:18:4053 // 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]a9c36832011-11-23 08:55:2459 void PrintPreviewDone();
60
Julie Jeongeun Kima75e43f2020-08-25 07:21:3261 // mojom::PrintManagerHost:
62 void DidShowPrintDialog() override;
Julie Jeongeun Kimec9f86b2020-12-08 03:32:3563 void ShowScriptedPrintPreview(bool source_is_modifiable) override;
Julie Jeongeun Kim514a77b2021-01-07 06:05:0364 void RequestPrintPreview(mojom::RequestPrintPreviewParamsPtr params) override;
Julie Jeongeun Kima75e43f2020-08-25 07:21:3265
[email protected]08ad9572012-07-26 21:03:3966 // content::WebContentsObserver implementation.
sgurun356feed52016-11-16 16:13:0667 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
thestigcb959ce2016-11-17 05:56:3268 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
69 bool OnMessageReceived(const IPC::Message& message,
70 content::RenderFrameHost* render_frame_host) override;
sgurun356feed52016-11-16 16:13:0671
thestigcb959ce2016-11-17 05:56:3272 content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; }
[email protected]2e3f4572011-03-25 19:24:4773
rbpotterfdff0672018-04-12 20:46:5874 protected:
[email protected]e3a7e6f2012-09-18 22:44:3175 explicit PrintViewManager(content::WebContents* web_contents);
rbpotterfdff0672018-04-12 20:46:5876
77 private:
[email protected]46b3c982012-10-09 18:38:3078 friend class content::WebContentsUserData<PrintViewManager>;
[email protected]e3a7e6f2012-09-18 22:44:3179
[email protected]a9c36832011-11-23 08:55:2480 enum PrintPreviewState {
81 NOT_PREVIEWING,
82 USER_INITIATED_PREVIEW,
83 SCRIPTED_PREVIEW,
84 };
85
Lukasz Anforowiczf4357ca2017-09-07 01:43:3286 struct FrameDispatchHelper;
Lei Zhang3398fa52018-10-31 18:27:1187
Jesse Schettlerfd3df7e82019-09-16 23:23:1888 // Helper method for PrintPreviewNow() and PrintPreviewWithRenderer().
89 // Initiate print preview of the current document by first notifying the
90 // renderer. Since this happens asynchronously, the print preview dialog
91 // creation will not be completed on the return of this function. Returns
92 // false if print preview is impossible at the moment.
Julie Jeongeun Kim52b2da72019-11-20 00:02:3593 bool PrintPreview(
94 content::RenderFrameHost* rfh,
95 mojo::PendingAssociatedRemote<mojom::PrintRenderer> print_renderer,
96 bool has_selection);
Jesse Schettlerfd3df7e82019-09-16 23:23:1897
Lei Zhang3398fa52018-10-31 18:27:1198 // IPC Message handlers.
thestigcb959ce2016-11-17 05:56:3299 void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh,
100 IPC::Message* reply_msg);
[email protected]a9c36832011-11-23 08:55:24101 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
102
Lei Zhang218f742d02019-03-05 05:18:40103 void MaybeUnblockScriptedPreviewRPH();
104
Sergey Poromova47abfc82020-09-24 10:16:24105 // Checks whether printing is restricted due to Data Leak Protection rules.
106 bool IsPrintingRestricted() const;
107
Julie Jeongeun Kim514a77b2021-01-07 06:05:03108 // Checks whether printing is currently restricted and aborts print preview if
109 // needed.
110 bool RejectPrintPreviewRequestIfRestricted(content::RenderFrameHost* rfh);
111
Lei Zhang3398fa52018-10-31 18:27:11112 base::OnceClosure on_print_dialog_shown_callback_;
[email protected]0b481bf2011-06-29 20:33:00113
[email protected]a9c36832011-11-23 08:55:24114 // Current state of print preview for this view.
Lei Zhang3398fa52018-10-31 18:27:11115 PrintPreviewState print_preview_state_ = NOT_PREVIEWING;
[email protected]a9c36832011-11-23 08:55:24116
thestigcb959ce2016-11-17 05:56:32117 // The current RFH that is print previewing. It should be a nullptr when
118 // |print_preview_state_| is NOT_PREVIEWING.
Lei Zhang3398fa52018-10-31 18:27:11119 content::RenderFrameHost* print_preview_rfh_ = nullptr;
thestigcb959ce2016-11-17 05:56:32120
[email protected]a9c36832011-11-23 08:55:24121 // Keeps track of the pending callback during scripted print preview.
Lei Zhang3398fa52018-10-31 18:27:11122 content::RenderProcessHost* scripted_print_preview_rph_ = nullptr;
[email protected]a9c36832011-11-23 08:55:24123
Lei Zhang218f742d02019-03-05 05:18:40124 // True if |scripted_print_preview_rph_| needs to be unblocked.
125 bool scripted_print_preview_rph_set_blocked_ = false;
126
Kent Tamura18c99f9a2017-09-25 05:39:32127 // Indicates whether we're switching from print preview to system dialog. This
128 // flag is true between PrintForSystemDialogNow() and PrintPreviewDone().
Lei Zhang3398fa52018-10-31 18:27:11129 bool is_switching_to_system_dialog_ = false;
Kent Tamura18c99f9a2017-09-25 05:39:32130
François Doray4f51d5d2018-12-03 22:26:24131 WEB_CONTENTS_USER_DATA_KEY_DECL();
132
[email protected]bfd04a62009-02-01 18:16:56133 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29134};
135
136} // namespace printing
137
[email protected]bfd04a62009-02-01 18:16:56138#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_