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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// Copyright 2015 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 COMPONENTS_PRINTING_BROWSER_PRINT_MANAGER_H_
#define COMPONENTS_PRINTING_BROWSER_PRINT_MANAGER_H_
#include <map>
#include <memory>
#include "build/build_config.h"
#include "components/printing/common/print.mojom.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_receiver_set.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "printing/buildflags/buildflags.h"
#if defined(OS_ANDROID)
#include "base/callback.h"
#endif
#if BUILDFLAG(ENABLE_TAGGED_PDF)
#include "ui/accessibility/ax_tree_update_forward.h"
#endif
namespace IPC {
class Message;
}
namespace printing {
class PrintManager : public content::WebContentsObserver,
public mojom::PrintManagerHost {
public:
PrintManager(const PrintManager&) = delete;
PrintManager& operator=(const PrintManager&) = delete;
~PrintManager() override;
#if defined(OS_ANDROID)
// TODO(timvolodine): consider introducing PrintManagerAndroid (crbug/500960)
using PdfWritingDoneCallback =
base::RepeatingCallback<void(int /* page count */)>;
virtual void PdfWritingDone(int page_count) = 0;
#endif
// printing::mojom::PrintManagerHost:
void DidGetPrintedPagesCount(int32_t cookie, uint32_t number_pages) override;
void DidGetDocumentCookie(int32_t cookie) override;
#if BUILDFLAG(ENABLE_TAGGED_PDF)
void SetAccessibilityTree(
int32_t cookie,
const ui::AXTreeUpdate& accessibility_tree) override;
#endif
void UpdatePrintSettings(int32_t cookie,
base::Value job_settings,
UpdatePrintSettingsCallback callback) override;
void DidShowPrintDialog() override;
void ShowInvalidPrinterSettingsError() override;
void PrintingFailed(int32_t cookie) override;
protected:
explicit PrintManager(content::WebContents* contents);
// Helper method to determine if PrintRenderFrame associated remote interface
// is still connected.
bool IsPrintRenderFrameConnected(content::RenderFrameHost* rfh);
// Helper method to fetch the PrintRenderFrame associated remote interface
// pointer.
const mojo::AssociatedRemote<printing::mojom::PrintRenderFrame>&
GetPrintRenderFrame(content::RenderFrameHost* rfh);
// Terminates or cancels the print job if one was pending.
void PrintingRenderFrameDeleted();
// content::WebContentsObserver
bool OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* render_frame_host) override;
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
// IPC handling support
struct FrameDispatchHelper;
// IPC message PrintHostMsg_DidPrintDocument can require handling in other
// processes beyond the rendering process running OnMessageReceived(),
// requiring that the renderer needs to wait.
class DelayedFrameDispatchHelper : public content::WebContentsObserver {
public:
DelayedFrameDispatchHelper(content::WebContents* contents,
content::RenderFrameHost* render_frame_host,
IPC::Message* reply_msg);
DelayedFrameDispatchHelper(const DelayedFrameDispatchHelper&) = delete;
~DelayedFrameDispatchHelper() override;
DelayedFrameDispatchHelper& operator=(const DelayedFrameDispatchHelper&) =
delete;
// content::WebContentsObserver
void RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) override;
// SendCompleted() can be called at most once, since it provides the success
// reply for a message. A failure reply for the message is automatically
// sent if this is never called.
void SendCompleted();
private:
content::RenderFrameHost* const render_frame_host_;
IPC::Message* reply_msg_;
};
// IPC handlers
virtual void OnDidPrintDocument(
content::RenderFrameHost* render_frame_host,
const mojom::DidPrintDocumentParams& params,
std::unique_ptr<DelayedFrameDispatchHelper> helper) = 0;
virtual void OnScriptedPrint(content::RenderFrameHost* render_frame_host,
const mojom::ScriptedPrintParams& params,
IPC::Message* reply_msg) = 0;
uint32_t number_pages_ = 0; // Number of pages to print in the print job.
int cookie_ = 0; // The current document cookie.
// Holds WebContents associated mojo receivers.
content::WebContentsFrameReceiverSet<printing::mojom::PrintManagerHost>
print_manager_host_receivers_;
#if defined(OS_ANDROID)
// Callback to execute when done writing pdf.
PdfWritingDoneCallback pdf_writing_done_callback_;
#endif
private:
// Stores a PrintRenderFrame associated remote with the RenderFrameHost used
// to bind it. The PrintRenderFrame is used to transmit mojo interface method
// calls to the associated receiver.
std::map<content::RenderFrameHost*,
mojo::AssociatedRemote<printing::mojom::PrintRenderFrame>>
print_render_frames_;
};
} // namespace printing
#endif // COMPONENTS_PRINTING_BROWSER_PRINT_MANAGER_H_
|