Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: chrome/browser/printing/print_preview_message_handler.cc

Issue 2920013002: Use pdf compositor service for printing when OOPIF is enabled
Patch Set: rebase Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/print_preview_message_handler.cc
diff --git a/chrome/browser/printing/print_preview_message_handler.cc b/chrome/browser/printing/print_preview_message_handler.cc
index a8f84dde601703bd1ef65a4b9442220ce4ac6c46..f86b8e7c3d9f175215b0ff49382ae21e7b268754 100644
--- a/chrome/browser/printing/print_preview_message_handler.cc
+++ b/chrome/browser/printing/print_preview_message_handler.cc
@@ -14,18 +14,22 @@
#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/shared_memory.h"
+#include "base/memory/shared_memory_handle.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/printing/print_view_manager.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
+#include "components/printing/browser/print_composite_client.h"
+#include "components/printing/browser/print_manager_utils.h"
#include "components/printing/common/print_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "printing/page_size_margins.h"
#include "printing/print_job_constants.h"
+#include "printing/print_settings.h"
using content::BrowserThread;
using content::WebContents;
@@ -69,7 +73,7 @@ scoped_refptr<base::RefCountedBytes> GetDataFromHandle(
PrintPreviewMessageHandler::PrintPreviewMessageHandler(
WebContents* web_contents)
- : content::WebContentsObserver(web_contents) {
+ : content::WebContentsObserver(web_contents), weak_ptr_factory_(this) {
DCHECK(web_contents);
}
@@ -125,17 +129,24 @@ void PrintPreviewMessageHandler::OnDidPreviewPage(
if (page_number < FIRST_PAGE_INDEX || !params.data_size)
return;
- PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
- if (!print_preview_ui)
+ if (!GetPrintPreviewUI())
return;
- scoped_refptr<base::RefCountedBytes> data_bytes =
- GetDataFromHandle(params.metafile_data_handle, params.data_size);
- DCHECK(data_bytes);
-
- print_preview_ui->SetPrintPreviewDataForIndex(page_number,
- std::move(data_bytes));
- print_preview_ui->OnDidPreviewPage(page_number, params.preview_request_id);
+ if (IsOopifEnabled()) {
+ auto* client = PrintCompositeClient::FromWebContents(web_contents());
+ DCHECK(client);
+
+ // Use utility process to convert skia metafile to pdf.
+ client->DoComposite(
+ params.metafile_data_handle, params.data_size,
+ base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfPageDone,
+ weak_ptr_factory_.GetWeakPtr(), params.page_number,
+ params.preview_request_id));
+ } else {
+ NotifyUIPreviewPageReady(
+ page_number, params.preview_request_id,
+ GetDataFromHandle(params.metafile_data_handle, params.data_size));
+ }
}
void PrintPreviewMessageHandler::OnMetafileReadyForPrinting(
@@ -148,22 +159,23 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting(
return;
}
- PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
- if (!print_preview_ui)
+ if (!GetPrintPreviewUI())
return;
- // TODO(joth): This seems like a good match for using RefCountedStaticMemory
- // to avoid the memory copy, but the SetPrintPreviewData call chain below
- // needs updating to accept the RefCountedMemory* base class.
- scoped_refptr<base::RefCountedBytes> data_bytes =
- GetDataFromHandle(params.metafile_data_handle, params.data_size);
- if (!data_bytes || !data_bytes->size())
- return;
-
- print_preview_ui->SetPrintPreviewDataForIndex(COMPLETE_PREVIEW_DOCUMENT_INDEX,
- std::move(data_bytes));
- print_preview_ui->OnPreviewDataIsAvailable(
- params.expected_pages_count, params.preview_request_id);
+ if (IsOopifEnabled()) {
+ auto* client = PrintCompositeClient::FromWebContents(web_contents());
+ DCHECK(client);
+
+ client->DoComposite(
+ params.metafile_data_handle, params.data_size,
+ base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfDocumentDone,
+ weak_ptr_factory_.GetWeakPtr(),
+ params.expected_pages_count, params.preview_request_id));
+ } else {
+ NotifyUIPreviewDocumentReady(
+ params.expected_pages_count, params.preview_request_id,
+ GetDataFromHandle(params.metafile_data_handle, params.data_size));
+ }
}
void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) {
@@ -214,6 +226,65 @@ void PrintPreviewMessageHandler::OnSetOptionsFromDocument(
print_preview_ui->OnSetOptionsFromDocument(params);
}
+void PrintPreviewMessageHandler::NotifyUIPreviewPageReady(
+ int page_number,
+ int request_id,
+ scoped_refptr<base::RefCountedBytes> data_bytes) {
+ DCHECK(data_bytes);
+
+ PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
+ if (!print_preview_ui)
+ return;
+ print_preview_ui->SetPrintPreviewDataForIndex(page_number,
+ std::move(data_bytes));
+ print_preview_ui->OnDidPreviewPage(page_number, request_id);
+}
+
+void PrintPreviewMessageHandler::NotifyUIPreviewDocumentReady(
+ int page_count,
+ int request_id,
+ scoped_refptr<base::RefCountedBytes> data_bytes) {
+ if (!data_bytes || !data_bytes->size())
+ return;
+
+ PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
+ if (!print_preview_ui)
+ return;
+ print_preview_ui->SetPrintPreviewDataForIndex(COMPLETE_PREVIEW_DOCUMENT_INDEX,
+ std::move(data_bytes));
+ print_preview_ui->OnPreviewDataIsAvailable(page_count, request_id);
+}
+
+void PrintPreviewMessageHandler::OnCompositePdfPageDone(
+ int page_number,
+ int request_id,
+ mojom::PdfCompositor::Status status,
+ mojo::ScopedSharedBufferHandle handle) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (status != mojom::PdfCompositor::Status::SUCCESS) {
+ DLOG(ERROR) << "Compositing pdf failed with error " << status;
+ return;
+ }
+ NotifyUIPreviewPageReady(
+ page_number, request_id,
+ PrintCompositeClient::GetDataFromMojoHandle(std::move(handle)));
+}
+
+void PrintPreviewMessageHandler::OnCompositePdfDocumentDone(
+ int page_count,
+ int request_id,
+ mojom::PdfCompositor::Status status,
+ mojo::ScopedSharedBufferHandle handle) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (status != mojom::PdfCompositor::Status::SUCCESS) {
+ DLOG(ERROR) << "Compositing pdf failed with error " << status;
+ return;
+ }
+ NotifyUIPreviewDocumentReady(
+ page_count, request_id,
+ PrintCompositeClient::GetDataFromMojoHandle(std::move(handle)));
+}
+
bool PrintPreviewMessageHandler::OnMessageReceived(
const IPC::Message& message,
content::RenderFrameHost* render_frame_host) {
@@ -231,8 +302,7 @@ bool PrintPreviewMessageHandler::OnMessageReceived(
IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount,
OnDidGetPreviewPageCount)
- IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage,
- OnDidPreviewPage)
+ IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, OnDidPreviewPage)
IPC_MESSAGE_HANDLER(PrintHostMsg_MetafileReadyForPrinting,
OnMetafileReadyForPrinting)
IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed,
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.h ('k') | chrome/browser/printing/print_view_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698