blob: b878a6c6dc0f47f305d1d1a9792bcec9770dc211 [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"
[email protected]46b3c982012-10-09 18:38:3010#include "content/public/browser/web_contents_user_data.h"
Scott Violet318a55f2018-03-30 19:08:1911#include "printing/buildflags/buildflags.h"
initial.commit09911bf2008-07-26 23:55:2912
[email protected]a9c36832011-11-23 08:55:2413namespace content {
thestigcb959ce2016-11-17 05:56:3214class RenderFrameHost;
[email protected]a9c36832011-11-23 08:55:2415class RenderProcessHost;
16}
17
initial.commit09911bf2008-07-26 23:55:2918namespace printing {
19
[email protected]e3a7e6f2012-09-18 22:44:3120// Manages the print commands for a WebContents.
[email protected]1e54c1c2013-08-12 17:16:0521class PrintViewManager : public PrintViewManagerBase,
[email protected]46b3c982012-10-09 18:38:3022 public content::WebContentsUserData<PrintViewManager> {
initial.commit09911bf2008-07-26 23:55:2923 public:
dchengdf7e44a72014-10-21 23:50:1924 ~PrintViewManager() override;
initial.commit09911bf2008-07-26 23:55:2925
[email protected]3121c76b2011-07-22 02:34:3226 // Same as PrintNow(), but for the case where a user prints with the system
27 // dialog from print preview.
thestigf8117202016-02-26 19:05:1428 // |dialog_shown_callback| is called when the print dialog is shown.
Lei Zhang3398fa52018-10-31 18:27:1129 bool PrintForSystemDialogNow(base::OnceClosure dialog_shown_callback);
[email protected]3121c76b2011-07-22 02:34:3230
[email protected]0996e9b2011-08-26 17:59:0131 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
[email protected]e6c97f6d2013-08-02 00:47:0532 // show the native system dialog. This can happen from both initiator and
[email protected]c248f5552013-01-26 01:58:4933 // preview dialog.
thestigcb959ce2016-11-17 05:56:3234 bool BasicPrint(content::RenderFrameHost* rfh);
[email protected]0996e9b2011-08-26 17:59:0135
[email protected]8980e0d2011-05-27 19:16:2336 // Initiate print preview of the current document by first notifying the
[email protected]c248f5552013-01-26 01:58:4937 // 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.
thestigcb959ce2016-11-17 05:56:3240 bool PrintPreviewNow(content::RenderFrameHost* rfh, bool has_selection);
[email protected]8980e0d2011-05-27 19:16:2341
[email protected]9a26bb22012-01-24 23:50:2542 // Notify PrintViewManager that print preview is starting in the renderer for
43 // a particular WebNode.
thestig46657562016-11-21 21:35:2244 void PrintPreviewForWebNode(content::RenderFrameHost* rfh);
[email protected]9a26bb22012-01-24 23:50:2545
[email protected]a9c36832011-11-23 08:55:2446 // Notify PrintViewManager that print preview has finished. Unfreeze the
47 // renderer in the case of scripted print preview.
48 void PrintPreviewDone();
49
[email protected]08ad9572012-07-26 21:03:3950 // content::WebContentsObserver implementation.
sgurun356feed52016-11-16 16:13:0651 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
thestigcb959ce2016-11-17 05:56:3252 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
53 bool OnMessageReceived(const IPC::Message& message,
54 content::RenderFrameHost* render_frame_host) override;
sgurun356feed52016-11-16 16:13:0655
thestigcb959ce2016-11-17 05:56:3256 content::RenderFrameHost* print_preview_rfh() { return print_preview_rfh_; }
[email protected]2e3f4572011-03-25 19:24:4757
rbpotterfdff0672018-04-12 20:46:5858 protected:
[email protected]e3a7e6f2012-09-18 22:44:3159 explicit PrintViewManager(content::WebContents* web_contents);
rbpotterfdff0672018-04-12 20:46:5860
61 private:
[email protected]46b3c982012-10-09 18:38:3062 friend class content::WebContentsUserData<PrintViewManager>;
[email protected]e3a7e6f2012-09-18 22:44:3163
[email protected]a9c36832011-11-23 08:55:2464 enum PrintPreviewState {
65 NOT_PREVIEWING,
66 USER_INITIATED_PREVIEW,
67 SCRIPTED_PREVIEW,
68 };
69
Lukasz Anforowiczf4357ca2017-09-07 01:43:3270 struct FrameDispatchHelper;
Lei Zhang3398fa52018-10-31 18:27:1171
72 // IPC Message handlers.
thestigcb959ce2016-11-17 05:56:3273 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]a9c36832011-11-23 08:55:2478 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
79
Lei Zhang3398fa52018-10-31 18:27:1180 base::OnceClosure on_print_dialog_shown_callback_;
[email protected]0b481bf2011-06-29 20:33:0081
[email protected]a9c36832011-11-23 08:55:2482 // Current state of print preview for this view.
Lei Zhang3398fa52018-10-31 18:27:1183 PrintPreviewState print_preview_state_ = NOT_PREVIEWING;
[email protected]a9c36832011-11-23 08:55:2484
thestigcb959ce2016-11-17 05:56:3285 // The current RFH that is print previewing. It should be a nullptr when
86 // |print_preview_state_| is NOT_PREVIEWING.
Lei Zhang3398fa52018-10-31 18:27:1187 content::RenderFrameHost* print_preview_rfh_ = nullptr;
thestigcb959ce2016-11-17 05:56:3288
[email protected]a9c36832011-11-23 08:55:2489 // Keeps track of the pending callback during scripted print preview.
Lei Zhang3398fa52018-10-31 18:27:1190 content::RenderProcessHost* scripted_print_preview_rph_ = nullptr;
[email protected]a9c36832011-11-23 08:55:2491
Kent Tamura18c99f9a2017-09-25 05:39:3292 // Indicates whether we're switching from print preview to system dialog. This
93 // flag is true between PrintForSystemDialogNow() and PrintPreviewDone().
Lei Zhang3398fa52018-10-31 18:27:1194 bool is_switching_to_system_dialog_ = false;
Kent Tamura18c99f9a2017-09-25 05:39:3295
François Doray4f51d5d2018-12-03 22:26:2496 WEB_CONTENTS_USER_DATA_KEY_DECL();
97
[email protected]bfd04a62009-02-01 18:16:5698 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:2999};
100
101} // namespace printing
102
[email protected]bfd04a62009-02-01 18:16:56103#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_