blob: 45e840b54c97aa45550ae4ec529b738c96036ff9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
#define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
#include "chrome/browser/printing/print_view_manager_base.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class RenderProcessHost;
}
namespace printing {
class PrintViewManagerObserver;
// Manages the print commands for a WebContents.
class PrintViewManager : public PrintViewManagerBase,
public content::WebContentsUserData<PrintViewManager> {
public:
~PrintViewManager() override;
#if defined(ENABLE_BASIC_PRINTING)
// Same as PrintNow(), but for the case where a user prints with the system
// dialog from print preview.
bool PrintForSystemDialogNow();
// Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
// show the native system dialog. This can happen from both initiator and
// preview dialog.
bool BasicPrint();
#endif // ENABLE_BASIC_PRINTING
// Initiate print preview of the current document by first notifying the
// renderer. Since this happens asynchronous, the print preview dialog
// creation will not be completed on the return of this function. Returns
// false if print preview is impossible at the moment.
bool PrintPreviewNow(bool selection_only);
// Notify PrintViewManager that print preview is starting in the renderer for
// a particular WebNode.
void PrintPreviewForWebNode();
// Notify PrintViewManager that print preview has finished. Unfreeze the
// renderer in the case of scripted print preview.
void PrintPreviewDone();
// Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to
// remove the current observer. |observer| may always be NULL, but |observer_|
// must be NULL if |observer| is non-NULL.
void set_observer(PrintViewManagerObserver* observer);
// content::WebContentsObserver implementation.
bool OnMessageReceived(const IPC::Message& message) override;
// content::WebContentsObserver implementation.
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
// content::WebContentsObserver implementation.
// Terminates or cancels the print job if one was pending.
void RenderProcessGone(base::TerminationStatus status) override;
private:
explicit PrintViewManager(content::WebContents* web_contents);
friend class content::WebContentsUserData<PrintViewManager>;
enum PrintPreviewState {
NOT_PREVIEWING,
USER_INITIATED_PREVIEW,
SCRIPTED_PREVIEW,
};
// IPC Message handlers.
void OnDidShowPrintDialog();
void OnSetupScriptedPrintPreview(IPC::Message* reply_msg);
void OnShowScriptedPrintPreview(bool source_is_modifiable);
void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
// Weak pointer to an observer that is notified when the print dialog is
// shown.
PrintViewManagerObserver* observer_;
// Current state of print preview for this view.
PrintPreviewState print_preview_state_;
// Keeps track of the pending callback during scripted print preview.
content::RenderProcessHost* scripted_print_preview_rph_;
DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
};
} // namespace printing
#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
|