Commit 10d377be authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

printing: Mojofy PrintMsg_* in PrintViewManagerBase

Replace PrintMsg_PrintingDone, PrintMsg_PrintPages, and
PrintMsg_SetPrintingEnabled IPC messages with new Mojo methods. Update
AwPrintManager and HeadlessPrintManager to also use these new methods.

Bug: 1008939
Test: Print a webpage and PDF
Change-Id: I3a403dd47ffc9c4debe819d26b00eccbd24b1180
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876473
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710576}
parent b87db175
...@@ -214,6 +214,7 @@ source_set("browser") { ...@@ -214,6 +214,7 @@ source_set("browser") {
"//components/prefs", "//components/prefs",
"//components/printing/browser", "//components/printing/browser",
"//components/printing/common", "//components/printing/common",
"//components/printing/common:mojo_interfaces",
"//components/safe_browsing", "//components/safe_browsing",
"//components/safe_browsing:features", "//components/safe_browsing:features",
"//components/safe_browsing:ping_manager", "//components/safe_browsing:ping_manager",
......
...@@ -72,7 +72,8 @@ void AwPrintManager::PdfWritingDone(int page_count) { ...@@ -72,7 +72,8 @@ void AwPrintManager::PdfWritingDone(int page_count) {
bool AwPrintManager::PrintNow() { bool AwPrintManager::PrintNow() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto* rfh = web_contents()->GetMainFrame(); auto* rfh = web_contents()->GetMainFrame();
return rfh->Send(new PrintMsg_PrintPages(rfh->GetRoutingID())); GetPrintRenderFrame(rfh)->PrintRequestedPages();
return true;
} }
void AwPrintManager::OnGetDefaultPrintSettings( void AwPrintManager::OnGetDefaultPrintSettings(
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "chrome/browser/printing/print_preview_dialog_controller.h" #include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.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_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/plugin_service.h" #include "content/public/browser/plugin_service.h"
...@@ -27,7 +26,6 @@ ...@@ -27,7 +26,6 @@
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
#include "printing/buildflags/buildflags.h" #include "printing/buildflags/buildflags.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -194,21 +192,6 @@ void PrintViewManager::RenderFrameDeleted( ...@@ -194,21 +192,6 @@ void PrintViewManager::RenderFrameDeleted(
PrintViewManagerBase::RenderFrameDeleted(render_frame_host); PrintViewManagerBase::RenderFrameDeleted(render_frame_host);
} }
const mojo::AssociatedRemote<printing::mojom::PrintRenderFrame>&
PrintViewManager::GetPrintRenderFrame(content::RenderFrameHost* rfh) {
if (!print_render_frame_.is_bound()) {
rfh->GetRemoteAssociatedInterfaces()->GetInterface(&print_render_frame_);
print_render_frame_.set_disconnect_handler(
base::BindOnce(&PrintViewManager::OnPrintRenderFrameDisconnected,
base::Unretained(this)));
}
return print_render_frame_;
}
void PrintViewManager::OnPrintRenderFrameDisconnected() {
print_render_frame_.reset();
}
bool PrintViewManager::PrintPreview( bool PrintViewManager::PrintPreview(
content::RenderFrameHost* rfh, content::RenderFrameHost* rfh,
mojom::PrintRendererAssociatedPtrInfo print_renderer, mojom::PrintRendererAssociatedPtrInfo print_renderer,
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "chrome/browser/printing/print_view_manager_base.h" #include "chrome/browser/printing/print_view_manager_base.h"
#include "components/printing/common/print.mojom.h" #include "components/printing/common/print.mojom.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 "printing/buildflags/buildflags.h" #include "printing/buildflags/buildflags.h"
namespace content { namespace content {
...@@ -80,15 +79,6 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -80,15 +79,6 @@ class PrintViewManager : public PrintViewManagerBase,
struct FrameDispatchHelper; struct FrameDispatchHelper;
// Helper method to fetch the PrintRenderFrame associated remote interface
// pointer.
const mojo::AssociatedRemote<printing::mojom::PrintRenderFrame>&
GetPrintRenderFrame(content::RenderFrameHost* rfh);
// Resets the PrintRenderFrame associated remote when it's disconnected from
// its receiver.
void OnPrintRenderFrameDisconnected();
// Helper method for PrintPreviewNow() and PrintPreviewWithRenderer(). // Helper method for PrintPreviewNow() and PrintPreviewWithRenderer().
// Initiate print preview of the current document by first notifying the // Initiate print preview of the current document by first notifying the
// renderer. Since this happens asynchronously, the print preview dialog // renderer. Since this happens asynchronously, the print preview dialog
...@@ -127,10 +117,6 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -127,10 +117,6 @@ class PrintViewManager : public PrintViewManagerBase,
// flag is true between PrintForSystemDialogNow() and PrintPreviewDone(). // flag is true between PrintForSystemDialogNow() and PrintPreviewDone().
bool is_switching_to_system_dialog_ = false; bool is_switching_to_system_dialog_ = false;
// Used to transmit mojom interface method calls to the PrintRenderFrame
// associated remote.
mojo::AssociatedRemote<printing::mojom::PrintRenderFrame> print_render_frame_;
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(PrintViewManager); DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
......
...@@ -126,9 +126,13 @@ PrintViewManagerBase::~PrintViewManagerBase() { ...@@ -126,9 +126,13 @@ PrintViewManagerBase::~PrintViewManagerBase() {
bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) { bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) {
DisconnectFromCurrentPrintJob(); DisconnectFromCurrentPrintJob();
// Don't print / print preview interstitials or crashed tabs.
if (IsInterstitialOrCrashed())
return false;
SetPrintingRFH(rfh); SetPrintingRFH(rfh);
int32_t id = rfh->GetRoutingID(); GetPrintRenderFrame(rfh)->PrintRequestedPages();
return PrintNowInternal(rfh, std::make_unique<PrintMsg_PrintPages>(id)); return true;
} }
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
...@@ -611,11 +615,8 @@ void PrintViewManagerBase::ReleasePrintJob() { ...@@ -611,11 +615,8 @@ void PrintViewManagerBase::ReleasePrintJob() {
if (!print_job_) if (!print_job_)
return; return;
if (rfh) { if (rfh)
auto msg = std::make_unique<PrintMsg_PrintingDone>(rfh->GetRoutingID(), GetPrintRenderFrame(rfh)->PrintingDone(printing_succeeded_);
printing_succeeded_);
rfh->Send(msg.release());
}
registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(print_job_.get())); content::Source<PrintJob>(print_job_.get()));
...@@ -723,7 +724,7 @@ void PrintViewManagerBase::ReleasePrinterQuery() { ...@@ -723,7 +724,7 @@ void PrintViewManagerBase::ReleasePrinterQuery() {
void PrintViewManagerBase::SendPrintingEnabled(bool enabled, void PrintViewManagerBase::SendPrintingEnabled(bool enabled,
content::RenderFrameHost* rfh) { content::RenderFrameHost* rfh) {
rfh->Send(new PrintMsg_SetPrintingEnabled(rfh->GetRoutingID(), enabled)); GetPrintRenderFrame(rfh)->SetPrintingEnabled(enabled);
} }
} // namespace printing } // namespace printing
...@@ -39,6 +39,7 @@ static_library("browser") { ...@@ -39,6 +39,7 @@ static_library("browser") {
"//components/crash/core/common", "//components/crash/core/common",
"//components/discardable_memory/service", "//components/discardable_memory/service",
"//components/printing/common", "//components/printing/common",
"//components/printing/common:mojo_interfaces",
"//components/services/pdf_compositor/public/cpp", "//components/services/pdf_compositor/public/cpp",
"//components/services/pdf_compositor/public/mojom", "//components/services/pdf_compositor/public/mojom",
"//components/strings:components_strings_grit", "//components/strings:components_strings_grit",
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "components/printing/browser/print_manager.h" #include "components/printing/browser/print_manager.h"
#include "base/bind.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/printing/common/print_messages.h" #include "components/printing/common/print_messages.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
namespace printing { namespace printing {
...@@ -110,6 +112,19 @@ void PrintManager::OnPrintingFailed(int cookie) { ...@@ -110,6 +112,19 @@ void PrintManager::OnPrintingFailed(int cookie) {
#endif #endif
} }
const mojo::AssociatedRemote<printing::mojom::PrintRenderFrame>&
PrintManager::GetPrintRenderFrame(content::RenderFrameHost* rfh) {
// When print preview is closed, the remote is disconnected from the receiver.
// Reset a disconnected remote before using it again.
if (print_render_frame_.is_bound() && !print_render_frame_.is_connected())
print_render_frame_.reset();
if (!print_render_frame_.is_bound())
rfh->GetRemoteAssociatedInterfaces()->GetInterface(&print_render_frame_);
return print_render_frame_;
}
void PrintManager::PrintingRenderFrameDeleted() { void PrintManager::PrintingRenderFrameDeleted() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
PdfWritingDone(0); PdfWritingDone(0);
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #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_observer.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/callback.h" #include "base/callback.h"
...@@ -39,6 +41,11 @@ class PrintManager : public content::WebContentsObserver { ...@@ -39,6 +41,11 @@ class PrintManager : public content::WebContentsObserver {
protected: protected:
explicit PrintManager(content::WebContents* contents); explicit PrintManager(content::WebContents* contents);
// 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. // Terminates or cancels the print job if one was pending.
void PrintingRenderFrameDeleted(); void PrintingRenderFrameDeleted();
...@@ -96,6 +103,10 @@ class PrintManager : public content::WebContentsObserver { ...@@ -96,6 +103,10 @@ class PrintManager : public content::WebContentsObserver {
private: private:
void OnDidGetDocumentCookie(int cookie); void OnDidGetDocumentCookie(int cookie);
// Used to transmit mojom interface method calls to the PrintRenderFrame
// associated remote.
mojo::AssociatedRemote<printing::mojom::PrintRenderFrame> print_render_frame_;
DISALLOW_COPY_AND_ASSIGN(PrintManager); DISALLOW_COPY_AND_ASSIGN(PrintManager);
}; };
......
...@@ -14,6 +14,10 @@ interface PrintRenderer { ...@@ -14,6 +14,10 @@ interface PrintRenderer {
// Render process interface exposed to the browser to handle most of the // Render process interface exposed to the browser to handle most of the
// printing grunt work for RenderView. // printing grunt work for RenderView.
interface PrintRenderFrame { interface PrintRenderFrame {
// Tells the RenderFrame to switch the CSS to print media type, render every
// requested page, and then switch back the CSS to display media type.
PrintRequestedPages();
// Tells the RenderFrame to switch the CSS to print media type, render every // Tells the RenderFrame to switch the CSS to print media type, render every
// requested page using the print preview document's frame/node, and then // requested page using the print preview document's frame/node, and then
// switch the CSS back to display media type. // switch the CSS back to display media type.
...@@ -28,4 +32,10 @@ interface PrintRenderFrame { ...@@ -28,4 +32,10 @@ interface PrintRenderFrame {
// Tells the RenderFrame that the print preview dialog was closed. // Tells the RenderFrame that the print preview dialog was closed.
[EnableIf=enable_print_preview] [EnableIf=enable_print_preview]
OnPrintPreviewDialogClosed(); OnPrintPreviewDialogClosed();
// Tells the RenderFrame whether printing is enabled or not.
SetPrintingEnabled(bool enabled);
// Tells the RenderFrame that printing is done so it can clean up.
PrintingDone(bool success);
}; };
...@@ -362,22 +362,9 @@ IPC_STRUCT_END() ...@@ -362,22 +362,9 @@ 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)
#if BUILDFLAG(ENABLE_PRINTING)
// Tells the RenderFrame to switch the CSS to print media type, renders every
// requested pages and switch back the CSS to display media type.
IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages)
#endif
// Print content of an out-of-process subframe. // Print content of an out-of-process subframe.
IPC_MESSAGE_ROUTED1(PrintMsg_PrintFrameContent, PrintMsg_PrintFrame_Params) IPC_MESSAGE_ROUTED1(PrintMsg_PrintFrameContent, PrintMsg_PrintFrame_Params)
// Tells the RenderFrame that printing is done so it can clean up.
IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone,
bool /* success */)
// Tells the RenderFrame whether printing is enabled or not.
IPC_MESSAGE_ROUTED1(PrintMsg_SetPrintingEnabled, bool /* enabled */)
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
// Tells the RenderFrame to switch the CSS to print media type, renders every // Tells the RenderFrame to switch the CSS to print media type, renders every
// requested pages for print preview using the given |settings|. This gets // requested pages for print preview using the given |settings|. This gets
......
...@@ -1174,13 +1174,10 @@ bool PrintRenderFrameHelper::OnMessageReceived(const IPC::Message& message) { ...@@ -1174,13 +1174,10 @@ bool PrintRenderFrameHelper::OnMessageReceived(const IPC::Message& message) {
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintRenderFrameHelper, message) IPC_BEGIN_MESSAGE_MAP(PrintRenderFrameHelper, message)
IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone)
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
IPC_MESSAGE_HANDLER(PrintMsg_PrintFrameContent, OnPrintFrameContent) IPC_MESSAGE_HANDLER(PrintMsg_PrintFrameContent, OnPrintFrameContent)
IPC_MESSAGE_HANDLER(PrintMsg_SetPrintingEnabled, OnSetPrintingEnabled)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
...@@ -1200,6 +1197,27 @@ void PrintRenderFrameHelper::BindPrintRenderFrameReceiver( ...@@ -1200,6 +1197,27 @@ void PrintRenderFrameHelper::BindPrintRenderFrameReceiver(
receivers_.Add(this, std::move(receiver)); receivers_.Add(this, std::move(receiver));
} }
void PrintRenderFrameHelper::PrintRequestedPages() {
ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
if (ipc_nesting_level_ > 1)
return;
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
frame->DispatchBeforePrintEvent();
// Don't print if the RenderFrame is gone.
if (render_frame_gone_)
return;
// If we are printing a PDF extension frame, find the plugin node and print
// that instead.
auto plugin = delegate_->GetPdfElement(frame);
Print(frame, plugin, PrintRequestType::kRegular);
if (!render_frame_gone_)
frame->DispatchAfterPrintEvent();
// WARNING: |this| may be gone at this point. Do not do any more work here and
// just return.
}
void PrintRenderFrameHelper::PrintForSystemDialog() { void PrintRenderFrameHelper::PrintForSystemDialog() {
ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr()); ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
if (ipc_nesting_level_ > 1) if (ipc_nesting_level_ > 1)
...@@ -1209,10 +1227,9 @@ void PrintRenderFrameHelper::PrintForSystemDialog() { ...@@ -1209,10 +1227,9 @@ void PrintRenderFrameHelper::PrintForSystemDialog() {
NOTREACHED(); NOTREACHED();
return; return;
} }
auto weak_this = weak_ptr_factory_.GetWeakPtr();
Print(frame, print_preview_context_.source_node(), Print(frame, print_preview_context_.source_node(),
PrintRequestType::kRegular); PrintRequestType::kRegular);
if (weak_this) if (!render_frame_gone_)
frame->DispatchAfterPrintEvent(); frame->DispatchAfterPrintEvent();
// WARNING: |this| may be gone at this point. Do not do any more work here and // WARNING: |this| may be gone at this point. Do not do any more work here and
// just return. // just return.
...@@ -1250,24 +1267,17 @@ void PrintRenderFrameHelper::OnPrintPreviewDialogClosed() { ...@@ -1250,24 +1267,17 @@ void PrintRenderFrameHelper::OnPrintPreviewDialogClosed() {
} }
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintRenderFrameHelper::OnPrintPages() { void PrintRenderFrameHelper::PrintingDone(bool success) {
ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
if (ipc_nesting_level_ > 1) if (ipc_nesting_level_ > 1)
return; return;
notify_browser_of_print_failure_ = false;
DidFinishPrinting(success ? OK : FAIL_PRINT);
}
auto weak_this = weak_ptr_factory_.GetWeakPtr(); void PrintRenderFrameHelper::SetPrintingEnabled(bool enabled) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
frame->DispatchBeforePrintEvent(); is_printing_enabled_ = enabled;
if (!weak_this)
return;
// If we are printing a PDF extension frame, find the plugin node and print
// that instead.
auto plugin = delegate_->GetPdfElement(frame);
Print(frame, plugin, PrintRequestType::kRegular);
if (weak_this)
frame->DispatchAfterPrintEvent();
// WARNING: |this| may be gone at this point. Do not do any more work here and
// just return.
} }
void PrintRenderFrameHelper::GetPageSizeAndContentAreaFromPageLayout( void PrintRenderFrameHelper::GetPageSizeAndContentAreaFromPageLayout(
...@@ -1558,19 +1568,6 @@ int PrintRenderFrameHelper::GetFitToPageScaleFactor( ...@@ -1558,19 +1568,6 @@ int PrintRenderFrameHelper::GetFitToPageScaleFactor(
} }
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintRenderFrameHelper::OnPrintingDone(bool success) {
if (ipc_nesting_level_ > 1)
return;
notify_browser_of_print_failure_ = false;
if (!success)
LOG(ERROR) << "Failure in OnPrintingDone";
DidFinishPrinting(success ? OK : FAIL_PRINT);
}
void PrintRenderFrameHelper::OnSetPrintingEnabled(bool enabled) {
is_printing_enabled_ = enabled;
}
void PrintRenderFrameHelper::OnPrintFrameContent( void PrintRenderFrameHelper::OnPrintFrameContent(
const PrintMsg_PrintFrame_Params& params) { const PrintMsg_PrintFrame_Params& params) {
if (ipc_nesting_level_ > 1) if (ipc_nesting_level_ > 1)
......
...@@ -139,7 +139,8 @@ class PrintRenderFrameHelper ...@@ -139,7 +139,8 @@ class PrintRenderFrameHelper
friend class PrintRenderFrameHelperTestBase; friend class PrintRenderFrameHelperTestBase;
FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperPreviewTest, FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperPreviewTest,
BlockScriptInitiatedPrinting); BlockScriptInitiatedPrinting);
FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperTest, OnPrintPages); FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperTest,
PrintRequestedPages);
FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperTest, FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperTest,
BlockScriptInitiatedPrinting); BlockScriptInitiatedPrinting);
FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperTest, FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintRenderFrameHelperTest,
...@@ -211,6 +212,7 @@ class PrintRenderFrameHelper ...@@ -211,6 +212,7 @@ class PrintRenderFrameHelper
mojo::PendingAssociatedReceiver<mojom::PrintRenderFrame> receiver); mojo::PendingAssociatedReceiver<mojom::PrintRenderFrame> receiver);
// printing::mojom::PrintRenderFrame: // printing::mojom::PrintRenderFrame:
void PrintRequestedPages() override;
void PrintForSystemDialog() override; void PrintForSystemDialog() override;
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void InitiatePrintPreview( void InitiatePrintPreview(
...@@ -218,14 +220,14 @@ class PrintRenderFrameHelper ...@@ -218,14 +220,14 @@ class PrintRenderFrameHelper
bool has_selection) override; bool has_selection) override;
void OnPrintPreviewDialogClosed() override; void OnPrintPreviewDialogClosed() override;
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintingDone(bool success) override;
void SetPrintingEnabled(bool enabled) override;
// Message handlers --------------------------------------------------------- // Message handlers ---------------------------------------------------------
void OnPrintPages();
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void OnPrintPreview(const base::DictionaryValue& settings); void OnPrintPreview(const base::DictionaryValue& settings);
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void OnPrintFrameContent(const PrintMsg_PrintFrame_Params& params); void OnPrintFrameContent(const PrintMsg_PrintFrame_Params& params);
void OnPrintingDone(bool success);
// Get |page_size| and |content_area| information from // Get |page_size| and |content_area| information from
// |page_layout_in_points|. // |page_layout_in_points|.
...@@ -258,9 +260,6 @@ class PrintRenderFrameHelper ...@@ -258,9 +260,6 @@ class PrintRenderFrameHelper
int GetFitToPageScaleFactor(const gfx::Rect& printable_area_in_points); int GetFitToPageScaleFactor(const gfx::Rect& printable_area_in_points);
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
// Enable/Disable printing.
void OnSetPrintingEnabled(bool enabled);
// Main printing code ------------------------------------------------------- // Main printing code -------------------------------------------------------
// Print with the system dialog. // Print with the system dialog.
......
...@@ -237,7 +237,7 @@ class PrintRenderFrameHelperTestBase : public content::RenderViewTest { ...@@ -237,7 +237,7 @@ class PrintRenderFrameHelperTestBase : public content::RenderViewTest {
} }
void OnPrintPages() { void OnPrintPages() {
GetPrintRenderFrameHelper()->OnPrintPages(); GetPrintRenderFrameHelper()->PrintRequestedPages();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -245,7 +245,7 @@ class PrintRenderFrameHelperTestBase : public content::RenderViewTest { ...@@ -245,7 +245,7 @@ class PrintRenderFrameHelperTestBase : public content::RenderViewTest {
PrintRenderFrameHelper* helper = PrintRenderFrameHelper* helper =
GetPrintRenderFrameHelperForFrame(frame_name); GetPrintRenderFrameHelperForFrame(frame_name);
ASSERT_TRUE(helper); ASSERT_TRUE(helper);
helper->OnPrintPages(); helper->PrintRequestedPages();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -741,11 +741,11 @@ TEST_F(MAYBE_PrintRenderFrameHelperPreviewTest, BlockScriptInitiatedPrinting) { ...@@ -741,11 +741,11 @@ TEST_F(MAYBE_PrintRenderFrameHelperPreviewTest, BlockScriptInitiatedPrinting) {
LoadHTML(kHelloWorldHTML); LoadHTML(kHelloWorldHTML);
PrintRenderFrameHelper* print_render_frame_helper = PrintRenderFrameHelper* print_render_frame_helper =
GetPrintRenderFrameHelper(); GetPrintRenderFrameHelper();
print_render_frame_helper->OnSetPrintingEnabled(false); print_render_frame_helper->SetPrintingEnabled(false);
PrintWithJavaScript(); PrintWithJavaScript();
VerifyPreviewRequest(false); VerifyPreviewRequest(false);
print_render_frame_helper->OnSetPrintingEnabled(true); print_render_frame_helper->SetPrintingEnabled(true);
PrintWithJavaScript(); PrintWithJavaScript();
VerifyPreviewRequest(true); VerifyPreviewRequest(true);
} }
......
...@@ -139,7 +139,7 @@ void HeadlessPrintManager::GetPDFContents(content::RenderFrameHost* rfh, ...@@ -139,7 +139,7 @@ void HeadlessPrintManager::GetPDFContents(content::RenderFrameHost* rfh,
print_params_ = GetPrintParamsFromSettings(settings); print_params_ = GetPrintParamsFromSettings(settings);
page_ranges_text_ = settings.page_ranges; page_ranges_text_ = settings.page_ranges;
ignore_invalid_page_ranges_ = settings.ignore_invalid_page_ranges; ignore_invalid_page_ranges_ = settings.ignore_invalid_page_ranges;
rfh->Send(new PrintMsg_PrintPages(rfh->GetRoutingID())); GetPrintRenderFrame(rfh)->PrintRequestedPages();
} }
std::unique_ptr<PrintMsg_PrintPages_Params> std::unique_ptr<PrintMsg_PrintPages_Params>
...@@ -307,8 +307,7 @@ void HeadlessPrintManager::ReleaseJob(PrintResult result) { ...@@ -307,8 +307,7 @@ void HeadlessPrintManager::ReleaseJob(PrintResult result) {
std::move(callback_).Run(result, std::move(callback_).Run(result,
base::MakeRefCounted<base::RefCountedString>()); base::MakeRefCounted<base::RefCountedString>());
} }
printing_rfh_->Send(new PrintMsg_PrintingDone(printing_rfh_->GetRoutingID(), GetPrintRenderFrame(printing_rfh_)->PrintingDone(result == PRINT_SUCCESS);
result == PRINT_SUCCESS));
Reset(); Reset();
} }
......
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