Commit 296bf0c3 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

[printing] Reuse AwPrintManager with introducing UpdateParam()

This CL introduces AwPrintManager::UpdateParam() which updates
|settings_|, |fd_|, and |pdf_writing_done_callback_| in order
to reuse AwPrintManager avoiding creating it every time.

It fixes a regression issue by crrev.com/c/2326857. The
problem is that WebContentsFrameReceiverSet is created always
along with AwPrintManager but WebContentsImpl::AddReceiverSet()
expects that it's called once for an each interface. So, this
CL doesn't create AwPrintManager always like other print
managers such as PrintViewManager or HeadlessPrintManager.

Bug: 1137016
Change-Id: I11c176009ccdad643ebf495cc4b983209ba8b1c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463270Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#816141}
parent f36b2eb7
...@@ -66,10 +66,18 @@ void AwPdfExporter::ExportToPdf(JNIEnv* env, ...@@ -66,10 +66,18 @@ void AwPdfExporter::ExportToPdf(JNIEnv* env,
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
printing::PageRanges page_ranges; printing::PageRanges page_ranges;
JNI_AwPdfExporter_GetPageRanges(env, pages, &page_ranges); JNI_AwPdfExporter_GetPageRanges(env, pages, &page_ranges);
AwPrintManager* print_manager = AwPrintManager::CreateForWebContents(
web_contents_, CreatePdfSettings(env, obj, page_ranges), fd, // Create an AwPrintManager for the provided WebContents if the
base::BindRepeating(&AwPdfExporter::DidExportPdf, // AwPrintManager doesn't exist.
base::Unretained(this))); if (!AwPrintManager::FromWebContents(web_contents_))
AwPrintManager::CreateForWebContents(web_contents_);
// Update the parameters of the current print manager.
AwPrintManager* print_manager =
AwPrintManager::FromWebContents(web_contents_);
print_manager->UpdateParam(CreatePdfSettings(env, obj, page_ranges), fd,
base::BindRepeating(&AwPdfExporter::DidExportPdf,
base::Unretained(this)));
if (!print_manager->PrintNow()) if (!print_manager->PrintNow())
DidExportPdf(0); DidExportPdf(0);
......
...@@ -38,31 +38,8 @@ uint32_t SaveDataToFd(int fd, ...@@ -38,31 +38,8 @@ uint32_t SaveDataToFd(int fd,
} // namespace } // namespace
// static AwPrintManager::AwPrintManager(content::WebContents* contents)
AwPrintManager* AwPrintManager::CreateForWebContents( : PrintManager(contents) {}
content::WebContents* contents,
std::unique_ptr<printing::PrintSettings> settings,
int file_descriptor,
PrintManager::PdfWritingDoneCallback callback) {
AwPrintManager* print_manager = new AwPrintManager(
contents, std::move(settings), file_descriptor, std::move(callback));
contents->SetUserData(UserDataKey(), base::WrapUnique(print_manager));
return print_manager;
}
AwPrintManager::AwPrintManager(
content::WebContents* contents,
std::unique_ptr<printing::PrintSettings> settings,
int file_descriptor,
PdfWritingDoneCallback callback)
: PrintManager(contents),
settings_(std::move(settings)),
fd_(file_descriptor) {
DCHECK(settings_);
pdf_writing_done_callback_ = std::move(callback);
DCHECK(pdf_writing_done_callback_);
cookie_ = 1; // Set a valid dummy cookie value.
}
AwPrintManager::~AwPrintManager() = default; AwPrintManager::~AwPrintManager() = default;
...@@ -89,6 +66,18 @@ void AwPrintManager::GetDefaultPrintSettings( ...@@ -89,6 +66,18 @@ void AwPrintManager::GetDefaultPrintSettings(
std::move(callback).Run(std::move(params)); std::move(callback).Run(std::move(params));
} }
void AwPrintManager::UpdateParam(
std::unique_ptr<printing::PrintSettings> settings,
int file_descriptor,
PrintManager::PdfWritingDoneCallback callback) {
settings_ = std::move(settings);
DCHECK(settings_);
fd_ = file_descriptor;
pdf_writing_done_callback_ = std::move(callback);
DCHECK(pdf_writing_done_callback_);
cookie_ = 1; // Set a valid dummy cookie value.
}
void AwPrintManager::OnScriptedPrint( void AwPrintManager::OnScriptedPrint(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const printing::mojom::ScriptedPrintParams& scripted_params, const printing::mojom::ScriptedPrintParams& scripted_params,
......
...@@ -19,15 +19,6 @@ namespace android_webview { ...@@ -19,15 +19,6 @@ namespace android_webview {
class AwPrintManager : public printing::PrintManager, class AwPrintManager : public printing::PrintManager,
public content::WebContentsUserData<AwPrintManager> { public content::WebContentsUserData<AwPrintManager> {
public: public:
// Creates an AwPrintManager for the provided WebContents. If the
// AwPrintManager already exists, it is destroyed and a new one is created.
// The returned pointer is owned by |contents|.
static AwPrintManager* CreateForWebContents(
content::WebContents* contents,
std::unique_ptr<printing::PrintSettings> settings,
int file_descriptor,
PdfWritingDoneCallback callback);
~AwPrintManager() override; ~AwPrintManager() override;
// mojom::PrintManagerHost: // mojom::PrintManagerHost:
...@@ -39,13 +30,15 @@ class AwPrintManager : public printing::PrintManager, ...@@ -39,13 +30,15 @@ class AwPrintManager : public printing::PrintManager,
bool PrintNow(); bool PrintNow();
// Updates the parameters for printing.
void UpdateParam(std::unique_ptr<printing::PrintSettings> settings,
int file_descriptor,
PdfWritingDoneCallback callback);
private: private:
friend class content::WebContentsUserData<AwPrintManager>; friend class content::WebContentsUserData<AwPrintManager>;
AwPrintManager(content::WebContents* contents, explicit AwPrintManager(content::WebContents* contents);
std::unique_ptr<printing::PrintSettings> settings,
int file_descriptor,
PdfWritingDoneCallback callback);
// printing::PrintManager: // printing::PrintManager:
void OnDidPrintDocument( void OnDidPrintDocument(
...@@ -61,10 +54,10 @@ class AwPrintManager : public printing::PrintManager, ...@@ -61,10 +54,10 @@ class AwPrintManager : public printing::PrintManager,
std::unique_ptr<DelayedFrameDispatchHelper> helper, std::unique_ptr<DelayedFrameDispatchHelper> helper,
uint32_t page_count); uint32_t page_count);
const std::unique_ptr<printing::PrintSettings> settings_; std::unique_ptr<printing::PrintSettings> settings_;
// The file descriptor into which the PDF of the document will be written. // The file descriptor into which the PDF of the document will be written.
int fd_; int fd_ = -1;
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment