Commit b0a990da authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

printing: Mojofy PrintMsg_PrintFrameContent

Replace the PrintMsg_PrintFrameContent IPC message with a new Mojo
method, and update PrintCompositeClient to use this method.

Bug: 1008939
Test: ./browser_tests --gtest_filter=PrintBrowserTest.*
Change-Id: I6656d5e8c260828a4c940a2111bf51ee3efdb8df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1979327
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728796}
parent f147c654
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "components/printing/browser/features.h" #include "components/printing/browser/features.h"
#include "components/printing/browser/print_composite_client.h" #include "components/printing/browser/print_composite_client.h"
#include "components/printing/browser/print_manager_utils.h" #include "components/printing/browser/print_manager_utils.h"
#include "components/printing/common/print.mojom.h"
#include "components/printing/common/print_messages.h" #include "components/printing/common/print_messages.h"
#include "content/public/browser/browser_message_filter.h" #include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
namespace printing { namespace printing {
...@@ -260,11 +262,16 @@ class PrintBrowserTest : public InProcessBrowserTest { ...@@ -260,11 +262,16 @@ class PrintBrowserTest : public InProcessBrowserTest {
frame_host->GetProcess()->AddFilter(filter.get()); frame_host->GetProcess()->AddFilter(filter.get());
} }
static PrintMsg_PrintFrame_Params GetDefaultPrintFrameParams() { static mojom::PrintFrameContentParamsPtr GetDefaultPrintFrameParams() {
PrintMsg_PrintFrame_Params params; return mojom::PrintFrameContentParams::New(gfx::Rect(800, 600),
params.printable_area = gfx::Rect(800, 600); kDefaultDocumentCookie);
params.document_cookie = kDefaultDocumentCookie; }
return params;
static const mojo::AssociatedRemote<mojom::PrintRenderFrame>
GetPrintRenderFrame(content::RenderFrameHost* rfh) {
mojo::AssociatedRemote<mojom::PrintRenderFrame> remote;
rfh->GetRemoteAssociatedInterfaces()->GetInterface(&remote);
return remote;
} }
private: private:
...@@ -377,8 +384,7 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintFrameContent) { ...@@ -377,8 +384,7 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintFrameContent) {
content::RenderFrameHost* rfh = original_contents->GetMainFrame(); content::RenderFrameHost* rfh = original_contents->GetMainFrame();
AddFilterForFrame(rfh); AddFilterForFrame(rfh);
rfh->Send(new PrintMsg_PrintFrameContent(rfh->GetRoutingID(), GetPrintRenderFrame(rfh)->PrintFrameContent(GetDefaultPrintFrameParams());
GetDefaultPrintFrameParams()));
// The printed result will be received and checked in // The printed result will be received and checked in
// TestPrintFrameContentMsgFilter. // TestPrintFrameContentMsgFilter.
...@@ -402,8 +408,8 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeContent) { ...@@ -402,8 +408,8 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeContent) {
AddFilterForFrame(test_frame); AddFilterForFrame(test_frame);
test_frame->Send(new PrintMsg_PrintFrameContent( GetPrintRenderFrame(test_frame)
test_frame->GetRoutingID(), GetDefaultPrintFrameParams())); ->PrintFrameContent(GetDefaultPrintFrameParams());
// The printed result will be received and checked in // The printed result will be received and checked in
// TestPrintFrameContentMsgFilter. // TestPrintFrameContentMsgFilter.
...@@ -447,8 +453,8 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) { ...@@ -447,8 +453,8 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) {
AddFilterForFrame(grandchild_frame); AddFilterForFrame(grandchild_frame);
} }
main_frame->Send(new PrintMsg_PrintFrameContent( GetPrintRenderFrame(main_frame)
main_frame->GetRoutingID(), GetDefaultPrintFrameParams())); ->PrintFrameContent(GetDefaultPrintFrameParams());
// The printed result will be received and checked in // The printed result will be received and checked in
// TestPrintFrameContentMsgFilter. // TestPrintFrameContentMsgFilter.
...@@ -491,8 +497,8 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeABA) { ...@@ -491,8 +497,8 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeABA) {
if (oopif_enabled) if (oopif_enabled)
AddFilterForFrame(child_frame); AddFilterForFrame(child_frame);
main_frame->Send(new PrintMsg_PrintFrameContent( GetPrintRenderFrame(main_frame)
main_frame->GetRoutingID(), GetDefaultPrintFrameParams())); ->PrintFrameContent(GetDefaultPrintFrameParams());
// The printed result will be received and checked in // The printed result will be received and checked in
// TestPrintFrameContentMsgFilter. // TestPrintFrameContentMsgFilter.
......
...@@ -32,6 +32,9 @@ void FakePrintRenderFrame::PrintPreview(base::Value settings) {} ...@@ -32,6 +32,9 @@ void FakePrintRenderFrame::PrintPreview(base::Value settings) {}
void FakePrintRenderFrame::OnPrintPreviewDialogClosed() {} void FakePrintRenderFrame::OnPrintPreviewDialogClosed() {}
void FakePrintRenderFrame::PrintFrameContent(
mojom::PrintFrameContentParamsPtr params) {}
void FakePrintRenderFrame::PrintingDone(bool success) {} void FakePrintRenderFrame::PrintingDone(bool success) {}
void FakePrintRenderFrame::SetPrintingEnabled(bool enabled) {} void FakePrintRenderFrame::SetPrintingEnabled(bool enabled) {}
......
...@@ -31,6 +31,7 @@ class FakePrintRenderFrame : public mojom::PrintRenderFrame { ...@@ -31,6 +31,7 @@ class FakePrintRenderFrame : public mojom::PrintRenderFrame {
bool has_selection) override; bool has_selection) override;
void PrintPreview(base::Value settings) override; void PrintPreview(base::Value settings) override;
void OnPrintPreviewDialogClosed() override; void OnPrintPreviewDialogClosed() override;
void PrintFrameContent(mojom::PrintFrameContentParamsPtr params) override;
void PrintingDone(bool success) override; void PrintingDone(bool success) override;
void SetPrintingEnabled(bool enabled) override; void SetPrintingEnabled(bool enabled) override;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/service_process_host.h" #include "content/public/browser/service_process_host.h"
#include "printing/printing_utils.h" #include "printing/printing_utils.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
namespace printing { namespace printing {
...@@ -101,6 +102,8 @@ void PrintCompositeClient::RenderFrameDeleted( ...@@ -101,6 +102,8 @@ void PrintCompositeClient::RenderFrameDeleted(
} }
pending_subframe_cookies_.erase(iter); pending_subframe_cookies_.erase(iter);
} }
print_render_frames_.erase(render_frame_host);
} }
void PrintCompositeClient::OnDidPrintFrameContent( void PrintCompositeClient::OnDidPrintFrameContent(
...@@ -143,9 +146,7 @@ void PrintCompositeClient::PrintCrossProcessSubframe( ...@@ -143,9 +146,7 @@ void PrintCompositeClient::PrintCrossProcessSubframe(
const gfx::Rect& rect, const gfx::Rect& rect,
int document_cookie, int document_cookie,
content::RenderFrameHost* subframe_host) { content::RenderFrameHost* subframe_host) {
PrintMsg_PrintFrame_Params params; auto params = mojom::PrintFrameContentParams::New(rect, document_cookie);
params.printable_area = rect;
params.document_cookie = document_cookie;
uint64_t frame_guid = GenerateFrameGuid(subframe_host); uint64_t frame_guid = GenerateFrameGuid(subframe_host);
if (!subframe_host->IsRenderFrameLive()) { if (!subframe_host->IsRenderFrameLive()) {
// When the subframe is dead, no need to send message, // When the subframe is dead, no need to send message,
...@@ -170,8 +171,7 @@ void PrintCompositeClient::PrintCrossProcessSubframe( ...@@ -170,8 +171,7 @@ void PrintCompositeClient::PrintCrossProcessSubframe(
} }
// Send the request to the destination frame. // Send the request to the destination frame.
subframe_host->Send( GetPrintRenderFrame(subframe_host)->PrintFrameContent(std::move(params));
new PrintMsg_PrintFrameContent(subframe_host->GetRoutingID(), params));
pending_subframe_cookies_[frame_guid].insert(document_cookie); pending_subframe_cookies_[frame_guid].insert(document_cookie);
} }
...@@ -328,6 +328,18 @@ PrintCompositeClient::CreateCompositeRequest() { ...@@ -328,6 +328,18 @@ PrintCompositeClient::CreateCompositeRequest() {
return compositor; return compositor;
} }
const mojo::AssociatedRemote<mojom::PrintRenderFrame>&
PrintCompositeClient::GetPrintRenderFrame(content::RenderFrameHost* rfh) {
auto it = print_render_frames_.find(rfh);
if (it == print_render_frames_.end()) {
mojo::AssociatedRemote<mojom::PrintRenderFrame> remote;
rfh->GetRemoteAssociatedInterfaces()->GetInterface(&remote);
it = print_render_frames_.emplace(rfh, std::move(remote)).first;
}
return it->second;
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintCompositeClient) WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintCompositeClient)
} // namespace printing } // namespace printing
...@@ -9,9 +9,11 @@ ...@@ -9,9 +9,11 @@
#include <memory> #include <memory>
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "components/printing/common/print.mojom.h"
#include "components/services/pdf_compositor/public/mojom/pdf_compositor.mojom.h" #include "components/services/pdf_compositor/public/mojom/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 "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
struct PrintHostMsg_DidPrintContent_Params; struct PrintHostMsg_DidPrintContent_Params;
...@@ -120,6 +122,11 @@ class PrintCompositeClient ...@@ -120,6 +122,11 @@ class PrintCompositeClient
mojo::Remote<mojom::PdfCompositor> CreateCompositeRequest(); mojo::Remote<mojom::PdfCompositor> CreateCompositeRequest();
// Helper method to fetch the PrintRenderFrame remote interface pointer
// associated with a given subframe.
const mojo::AssociatedRemote<mojom::PrintRenderFrame>& GetPrintRenderFrame(
content::RenderFrameHost* rfh);
// Stores the mapping between document cookies and their corresponding // Stores the mapping between document cookies and their corresponding
// requests. // requests.
std::map<int, mojo::Remote<mojom::PdfCompositor>> compositor_map_; std::map<int, mojo::Remote<mojom::PdfCompositor>> compositor_map_;
...@@ -139,6 +146,13 @@ class PrintCompositeClient ...@@ -139,6 +146,13 @@ class PrintCompositeClient
std::string user_agent_; std::string user_agent_;
// 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<mojom::PrintRenderFrame>>
print_render_frames_;
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(PrintCompositeClient); DISALLOW_COPY_AND_ASSIGN(PrintCompositeClient);
......
...@@ -35,6 +35,7 @@ mojom("mojo_interfaces") { ...@@ -35,6 +35,7 @@ mojom("mojo_interfaces") {
public_deps = [ public_deps = [
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//ui/gfx/geometry/mojom",
] ]
if (enable_print_preview) { if (enable_print_preview) {
......
...@@ -6,6 +6,17 @@ module printing.mojom; ...@@ -6,6 +6,17 @@ module printing.mojom;
import "mojo/public/mojom/base/shared_memory.mojom"; import "mojo/public/mojom/base/shared_memory.mojom";
import "mojo/public/mojom/base/values.mojom"; import "mojo/public/mojom/base/values.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
// Parameters required to print the content of an out-of-process subframe.
struct PrintFrameContentParams {
// Physical printable area of the page in pixels according to dpi.
gfx.mojom.Rect printable_area;
// Cookie that is unique for each print request. It is used to associate the
// printed frame with its original print request.
int32 document_cookie;
};
// Interface implemented by a class that desires to render print documents for // Interface implemented by a class that desires to render print documents for
// Chrome print preview. // Chrome print preview.
...@@ -47,6 +58,9 @@ interface PrintRenderFrame { ...@@ -47,6 +58,9 @@ interface PrintRenderFrame {
[EnableIf=enable_print_preview] [EnableIf=enable_print_preview]
OnPrintPreviewDialogClosed(); OnPrintPreviewDialogClosed();
// Prints the content of an out-of-process subframe.
PrintFrameContent(PrintFrameContentParams params);
// Tells the RenderFrame whether printing is enabled or not. // Tells the RenderFrame whether printing is enabled or not.
SetPrintingEnabled(bool enabled); SetPrintingEnabled(bool enabled);
......
...@@ -127,10 +127,6 @@ void PrintMsg_PrintPages_Params::Reset() { ...@@ -127,10 +127,6 @@ void PrintMsg_PrintPages_Params::Reset() {
pages = std::vector<int>(); pages = std::vector<int>();
} }
PrintMsg_PrintFrame_Params::PrintMsg_PrintFrame_Params() {}
PrintMsg_PrintFrame_Params::~PrintMsg_PrintFrame_Params() {}
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
PrintHostMsg_RequestPrintPreview_Params:: PrintHostMsg_RequestPrintPreview_Params::
PrintHostMsg_RequestPrintPreview_Params() PrintHostMsg_RequestPrintPreview_Params()
......
...@@ -77,14 +77,6 @@ struct PrintMsg_PrintPages_Params { ...@@ -77,14 +77,6 @@ struct PrintMsg_PrintPages_Params {
std::vector<int> pages; std::vector<int> pages;
}; };
struct PrintMsg_PrintFrame_Params {
PrintMsg_PrintFrame_Params();
~PrintMsg_PrintFrame_Params();
gfx::Rect printable_area;
int document_cookie;
};
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
struct PrintHostMsg_RequestPrintPreview_Params { struct PrintHostMsg_RequestPrintPreview_Params {
PrintHostMsg_RequestPrintPreview_Params(); PrintHostMsg_RequestPrintPreview_Params();
...@@ -261,15 +253,6 @@ IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params) ...@@ -261,15 +253,6 @@ IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params)
IPC_STRUCT_TRAITS_MEMBER(pages) IPC_STRUCT_TRAITS_MEMBER(pages)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintFrame_Params)
// Physical printable area of the page in pixels according to dpi.
IPC_STRUCT_TRAITS_MEMBER(printable_area)
// Cookie that is unique for each print request.
// It is used to associate the printed frame with its original print request.
IPC_STRUCT_TRAITS_MEMBER(document_cookie)
IPC_STRUCT_TRAITS_END()
// Holds the printed content information. // Holds the printed content information.
// The printed content is in shared memory, and passed as a region. // The printed content is in shared memory, and passed as a region.
// A map on out-of-process subframe contents is also included so the printed // A map on out-of-process subframe contents is also included so the printed
...@@ -364,9 +347,6 @@ IPC_STRUCT_END() ...@@ -364,9 +347,6 @@ IPC_STRUCT_END()
// node, depending on which mode the RenderFrame is in. // node, depending on which mode the RenderFrame is in.
IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu) IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu)
// Print content of an out-of-process subframe.
IPC_MESSAGE_ROUTED1(PrintMsg_PrintFrameContent, PrintMsg_PrintFrame_Params)
// Messages sent from the renderer to the browser. // Messages sent from the renderer to the browser.
// Tells the browser that the renderer is done calculating the number of // Tells the browser that the renderer is done calculating the number of
......
...@@ -1170,18 +1170,6 @@ void PrintRenderFrameHelper::ScriptedPrint(bool user_initiated) { ...@@ -1170,18 +1170,6 @@ void PrintRenderFrameHelper::ScriptedPrint(bool user_initiated) {
// just return. // just return.
} }
bool PrintRenderFrameHelper::OnMessageReceived(const IPC::Message& message) {
ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintRenderFrameHelper, message)
IPC_MESSAGE_HANDLER(PrintMsg_PrintFrameContent, OnPrintFrameContent)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PrintRenderFrameHelper::OnDestruct() { void PrintRenderFrameHelper::OnDestruct() {
if (ipc_nesting_level_ > 0) { if (ipc_nesting_level_ > 0) {
render_frame_gone_ = true; render_frame_gone_ = true;
...@@ -1321,6 +1309,69 @@ void PrintRenderFrameHelper::OnPrintPreviewDialogClosed() { ...@@ -1321,6 +1309,69 @@ void PrintRenderFrameHelper::OnPrintPreviewDialogClosed() {
} }
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintRenderFrameHelper::PrintFrameContent(
mojom::PrintFrameContentParamsPtr params) {
ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
if (ipc_nesting_level_ > 1)
return;
// If the last request is not finished yet, do not proceed.
if (prep_frame_view_) {
DLOG(ERROR) << "Previous request is still ongoing";
return;
}
auto weak_this = weak_ptr_factory_.GetWeakPtr();
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
frame->DispatchBeforePrintEvent();
if (!weak_this)
return;
MetafileSkia metafile(SkiaDocumentType::MSKP, params->document_cookie);
gfx::Size area_size = params->printable_area.size();
// Since GetVectorCanvasForNewPage() starts a new recording, it will return
// a valid canvas.
cc::PaintCanvas* canvas =
metafile.GetVectorCanvasForNewPage(area_size, gfx::Rect(area_size), 1.0f);
DCHECK(canvas);
canvas->SetPrintingMetafile(&metafile);
// This subframe doesn't need to fit to the page size, thus we are not using
// printing layout for it. It just prints with the specified size.
blink::WebPrintParams web_print_params(area_size,
/*use_printing_layout=*/false);
// Printing embedded pdf plugin has been broken since pdf plugin viewer was
// moved out-of-process
// (https://bugs.chromium.org/p/chromium/issues/detail?id=464269). So don't
// try to handle pdf plugin element until that bug is fixed.
if (frame->PrintBegin(web_print_params,
/*constrain_to_node=*/blink::WebElement())) {
frame->PrintPage(0, canvas);
}
frame->PrintEnd();
// Done printing. Close the canvas to retrieve the compiled metafile.
bool ret = metafile.FinishPage();
DCHECK(ret);
metafile.FinishFrameContent();
// Send the printed result back.
PrintHostMsg_DidPrintContent_Params printed_frame_params;
if (!CopyMetafileDataToReadOnlySharedMem(metafile, &printed_frame_params)) {
DLOG(ERROR) << "CopyMetafileDataToSharedMem failed";
return;
}
Send(new PrintHostMsg_DidPrintFrameContent(
routing_id(), params->document_cookie, printed_frame_params));
if (!render_frame_gone_)
frame->DispatchAfterPrintEvent();
}
void PrintRenderFrameHelper::PrintingDone(bool success) { void PrintRenderFrameHelper::PrintingDone(bool success) {
ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr()); ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
if (ipc_nesting_level_ > 1) if (ipc_nesting_level_ > 1)
...@@ -1660,68 +1711,6 @@ int PrintRenderFrameHelper::GetFitToPageScaleFactor( ...@@ -1660,68 +1711,6 @@ int PrintRenderFrameHelper::GetFitToPageScaleFactor(
} }
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintRenderFrameHelper::OnPrintFrameContent(
const PrintMsg_PrintFrame_Params& params) {
if (ipc_nesting_level_ > 1)
return;
// If the last request is not finished yet, do not proceed.
if (prep_frame_view_) {
DLOG(ERROR) << "Previous request is still ongoing";
return;
}
auto weak_this = weak_ptr_factory_.GetWeakPtr();
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
frame->DispatchBeforePrintEvent();
if (!weak_this)
return;
MetafileSkia metafile(SkiaDocumentType::MSKP, params.document_cookie);
gfx::Size area_size = params.printable_area.size();
// Since GetVectorCanvasForNewPage() starts a new recording, it will return
// a valid canvas.
cc::PaintCanvas* canvas =
metafile.GetVectorCanvasForNewPage(area_size, gfx::Rect(area_size), 1.0f);
DCHECK(canvas);
canvas->SetPrintingMetafile(&metafile);
// This subframe doesn't need to fit to the page size, thus we are not using
// printing layout for it. It just prints with the specified size.
blink::WebPrintParams web_print_params(area_size,
/*use_printing_layout=*/false);
// Printing embedded pdf plugin has been broken since pdf plugin viewer was
// moved out-of-process
// (https://bugs.chromium.org/p/chromium/issues/detail?id=464269). So don't
// try to handle pdf plugin element until that bug is fixed.
if (frame->PrintBegin(web_print_params,
/*constrain_to_node=*/blink::WebElement())) {
frame->PrintPage(0, canvas);
}
frame->PrintEnd();
// Done printing. Close the canvas to retrieve the compiled metafile.
bool ret = metafile.FinishPage();
DCHECK(ret);
metafile.FinishFrameContent();
// Send the printed result back.
PrintHostMsg_DidPrintContent_Params printed_frame_params;
if (!CopyMetafileDataToReadOnlySharedMem(metafile, &printed_frame_params)) {
DLOG(ERROR) << "CopyMetafileDataToSharedMem failed";
return;
}
Send(new PrintHostMsg_DidPrintFrameContent(
routing_id(), params.document_cookie, printed_frame_params));
if (!render_frame_gone_)
frame->DispatchAfterPrintEvent();
}
bool PrintRenderFrameHelper::IsPrintingEnabled() const { bool PrintRenderFrameHelper::IsPrintingEnabled() const {
return is_printing_enabled_; return is_printing_enabled_;
} }
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
struct PrintMsg_Print_Params; struct PrintMsg_Print_Params;
struct PrintMsg_PrintPages_Params; struct PrintMsg_PrintPages_Params;
struct PrintMsg_PrintFrame_Params;
struct PrintHostMsg_SetOptionsFromDocument_Params; struct PrintHostMsg_SetOptionsFromDocument_Params;
// RenderViewTest-based tests crash on Android // RenderViewTest-based tests crash on Android
...@@ -214,7 +213,6 @@ class PrintRenderFrameHelper ...@@ -214,7 +213,6 @@ class PrintRenderFrameHelper
void DidFailProvisionalLoad() override; void DidFailProvisionalLoad() override;
void DidFinishLoad() override; void DidFinishLoad() override;
void ScriptedPrint(bool user_initiated) override; void ScriptedPrint(bool user_initiated) override;
bool OnMessageReceived(const IPC::Message& message) override;
void BindPrintRenderFrameReceiver( void BindPrintRenderFrameReceiver(
mojo::PendingAssociatedReceiver<mojom::PrintRenderFrame> receiver); mojo::PendingAssociatedReceiver<mojom::PrintRenderFrame> receiver);
...@@ -229,12 +227,10 @@ class PrintRenderFrameHelper ...@@ -229,12 +227,10 @@ class PrintRenderFrameHelper
void PrintPreview(base::Value settings) override; void PrintPreview(base::Value settings) override;
void OnPrintPreviewDialogClosed() override; void OnPrintPreviewDialogClosed() override;
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintFrameContent(mojom::PrintFrameContentParamsPtr params) override;
void PrintingDone(bool success) override; void PrintingDone(bool success) override;
void SetPrintingEnabled(bool enabled) override; void SetPrintingEnabled(bool enabled) override;
// Message handlers ---------------------------------------------------------
void OnPrintFrameContent(const PrintMsg_PrintFrame_Params& params);
// Get |page_size| and |content_area| information from // Get |page_size| and |content_area| information from
// |page_layout_in_points|. // |page_layout_in_points|.
void GetPageSizeAndContentAreaFromPageLayout( void GetPageSizeAndContentAreaFromPageLayout(
......
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