Commit 8c7cf637 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Simplify PrintCompositeClient.

- Reduce number of parameters to DoComposite{Document,Page}ToPdf().
- Move ConvertContentInfoMap() into an anonymous namespace and remove
  unused parameter.
- Change GenerateFrameGuid() so callers only pass a single parameter.

Change-Id: I22d94f988ba64ba72a1fa9bea7190cf2b812b336
Reviewed-on: https://chromium-review.googlesource.com/1183022
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585054}
parent fe0ff89e
...@@ -141,9 +141,7 @@ void PrintPreviewMessageHandler::OnDidPreviewPage( ...@@ -141,9 +141,7 @@ void PrintPreviewMessageHandler::OnDidPreviewPage(
// Use utility process to convert skia metafile to pdf. // Use utility process to convert skia metafile to pdf.
client->DoCompositePageToPdf( client->DoCompositePageToPdf(
params.document_cookie, render_frame_host, page_number, params.document_cookie, render_frame_host, page_number, content,
content.metafile_data_handle, content.data_size,
content.subframe_content_info,
base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfPageDone, base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfPageDone,
weak_ptr_factory_.GetWeakPtr(), page_number, ids)); weak_ptr_factory_.GetWeakPtr(), page_number, ids));
} else { } else {
...@@ -175,8 +173,7 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting( ...@@ -175,8 +173,7 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting(
DCHECK(client); DCHECK(client);
client->DoCompositeDocumentToPdf( client->DoCompositeDocumentToPdf(
params.document_cookie, render_frame_host, content.metafile_data_handle, params.document_cookie, render_frame_host, content,
content.data_size, content.subframe_content_info,
base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfDocumentDone, base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfDocumentDone,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
params.expected_pages_count, ids)); params.expected_pages_count, ids));
......
...@@ -317,8 +317,7 @@ void PrintViewManagerBase::OnDidPrintDocument( ...@@ -317,8 +317,7 @@ void PrintViewManagerBase::OnDidPrintDocument(
auto* client = PrintCompositeClient::FromWebContents(web_contents()); auto* client = PrintCompositeClient::FromWebContents(web_contents());
if (IsOopifEnabled() && print_job_->document()->settings().is_modifiable()) { if (IsOopifEnabled() && print_job_->document()->settings().is_modifiable()) {
client->DoCompositeDocumentToPdf( client->DoCompositeDocumentToPdf(
params.document_cookie, render_frame_host, content.metafile_data_handle, params.document_cookie, render_frame_host, content,
content.data_size, content.subframe_content_info,
base::BindOnce(&PrintViewManagerBase::OnComposePdfDone, base::BindOnce(&PrintViewManagerBase::OnComposePdfDone,
weak_ptr_factory_.GetWeakPtr(), params)); weak_ptr_factory_.GetWeakPtr(), params));
return; return;
......
...@@ -9,16 +9,16 @@ ...@@ -9,16 +9,16 @@
#include <memory> #include <memory>
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/optional.h"
#include "components/services/pdf_compositor/public/cpp/pdf_service_mojo_types.h"
#include "components/services/pdf_compositor/public/interfaces/pdf_compositor.mojom.h" #include "components/services/pdf_compositor/public/interfaces/pdf_compositor.mojom.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#include "printing/common/pdf_metafile_utils.h"
#include "services/service_manager/public/cpp/connector.h"
struct PrintHostMsg_DidPrintContent_Params; struct PrintHostMsg_DidPrintContent_Params;
namespace service_manager {
class Connector;
}
namespace printing { namespace printing {
// Class to manage print requests and their communication with pdf // Class to manage print requests and their communication with pdf
...@@ -49,8 +49,9 @@ class PrintCompositeClient ...@@ -49,8 +49,9 @@ class PrintCompositeClient
int document_cookie, int document_cookie,
content::RenderFrameHost* subframe_host); content::RenderFrameHost* subframe_host);
// NOTE: |handle| must be a READ-ONLY base::SharedMemoryHandle, i.e. one // NOTE: |content.metafile_data_handle| must be a READ-ONLY
// acquired by base::SharedMemory::GetReadOnlyHandle(). // base::SharedMemoryHandle, i.e. one acquired by
// base::SharedMemory::GetReadOnlyHandle().
// Printing single pages is only used by print preview for early return of // Printing single pages is only used by print preview for early return of
// rendered results. In this case, the pages share the content with printed // rendered results. In this case, the pages share the content with printed
...@@ -60,9 +61,7 @@ class PrintCompositeClient ...@@ -60,9 +61,7 @@ class PrintCompositeClient
int cookie, int cookie,
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
int page_num, int page_num,
base::SharedMemoryHandle handle, const PrintHostMsg_DidPrintContent_Params& content,
uint32_t data_size,
const ContentToProxyIdMap& subframe_content_info,
mojom::PdfCompositor::CompositePageToPdfCallback callback); mojom::PdfCompositor::CompositePageToPdfCallback callback);
// Used for compositing the entire document for print preview or actual // Used for compositing the entire document for print preview or actual
...@@ -70,37 +69,20 @@ class PrintCompositeClient ...@@ -70,37 +69,20 @@ class PrintCompositeClient
void DoCompositeDocumentToPdf( void DoCompositeDocumentToPdf(
int cookie, int cookie,
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
base::SharedMemoryHandle handle, const PrintHostMsg_DidPrintContent_Params& content,
uint32_t data_size,
const ContentToProxyIdMap& subframe_content_info,
mojom::PdfCompositor::CompositeDocumentToPdfCallback callback); mojom::PdfCompositor::CompositeDocumentToPdfCallback callback);
// Converts a ContentToProxyIdMap to ContentToFrameMap.
// ContentToProxyIdMap maps content id to its corresponding render frame proxy
// routing id. This is generated when the content holder was created;
// ContentToFrameMap maps content id to its render frame's global unique id.
// The global unique id has the render process id concatenated with render
// frame routing id, which can uniquely identify a render frame.
static ContentToFrameMap ConvertContentInfoMap(
content::WebContents* web_contents,
content::RenderFrameHost* render_frame_host,
const ContentToProxyIdMap& content_proxy_map);
private: private:
// Since page number is always non-negative, use this value to indicate it is
// for the whole document -- no page number specified.
static constexpr int kPageNumForWholeDoc = -1;
// Callback functions for getting the replies. // Callback functions for getting the replies.
void OnDidCompositePageToPdf( static void OnDidCompositePageToPdf(
printing::mojom::PdfCompositor::CompositePageToPdfCallback callback, mojom::PdfCompositor::CompositePageToPdfCallback callback,
printing::mojom::PdfCompositor::Status status, mojom::PdfCompositor::Status status,
base::ReadOnlySharedMemoryRegion region); base::ReadOnlySharedMemoryRegion region);
void OnDidCompositeDocumentToPdf( void OnDidCompositeDocumentToPdf(
int document_cookie, int document_cookie,
printing::mojom::PdfCompositor::CompositeDocumentToPdfCallback callback, mojom::PdfCompositor::CompositeDocumentToPdfCallback callback,
printing::mojom::PdfCompositor::Status status, mojom::PdfCompositor::Status status,
base::ReadOnlySharedMemoryRegion region); base::ReadOnlySharedMemoryRegion region);
// Get the request or create a new one if none exists. // Get the request or create a new one if none exists.
......
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