| Index: content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| index 367fa644a0a51ab6ae18f33ae221eaa7601ac5db..a39d4bf3d726e1cd3b09bcb9685fa49c7b0f8d54 100644
|
| --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| @@ -93,7 +93,6 @@
|
| #include "ppapi/shared_impl/var.h"
|
| #include "ppapi/thunk/enter.h"
|
| #include "ppapi/thunk/ppb_buffer_api.h"
|
| -#include "printing/features/features.h"
|
| #include "skia/ext/platform_canvas.h"
|
| #include "third_party/WebKit/public/platform/URLConversion.h"
|
| #include "third_party/WebKit/public/platform/WebCursorInfo.h"
|
| @@ -1774,6 +1773,7 @@ bool PepperPluginInstanceImpl::IsPrintScalingDisabled() {
|
| }
|
|
|
| int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) {
|
| +#if BUILDFLAG(ENABLE_PRINTING)
|
| // Keep a reference on the stack. See NOTE above.
|
| scoped_refptr<PepperPluginInstanceImpl> ref(this);
|
| PP_PrintOutputFormat_Dev format;
|
| @@ -1798,9 +1798,13 @@ int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) {
|
| if (!num_pages)
|
| return 0;
|
| current_print_settings_ = print_settings;
|
| - canvas_ = nullptr;
|
| + metafile_wrapper_.reset();
|
| ranges_.clear();
|
| return num_pages;
|
| +#else
|
| + NOTREACHED();
|
| + return 0;
|
| +#endif // BUILDFLAG(ENABLE_PRINTING)
|
| }
|
|
|
| void PepperPluginInstanceImpl::PrintPage(int page_number,
|
| @@ -1810,24 +1814,27 @@ void PepperPluginInstanceImpl::PrintPage(int page_number,
|
| PP_PrintPageNumberRange_Dev page_range;
|
| page_range.first_page_number = page_range.last_page_number = page_number;
|
| // The canvas only has a metafile on it for print preview.
|
| - bool save_for_later =
|
| - (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL);
|
| + sk_sp<printing::MetafileSkiaWrapper> wrapper =
|
| + printing::MetafileSkiaWrapper::RefFromCanvas(*canvas);
|
| + bool save_for_later = wrapper && wrapper->metafile();
|
| #if defined(OS_MACOSX)
|
| save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas);
|
| #endif // defined(OS_MACOSX)
|
| +
|
| if (save_for_later) {
|
| ranges_.push_back(page_range);
|
| - canvas_ = canvas;
|
| + metafile_wrapper_ = wrapper;
|
| } else {
|
| - PrintPageHelper(&page_range, 1, canvas);
|
| + PrintPageHelper(&page_range, 1, wrapper.get());
|
| }
|
| -#endif
|
| +#endif // BUILDFLAG(ENABLE_PRINTING)
|
| }
|
|
|
| +#if BUILDFLAG(ENABLE_PRINTING)
|
| void PepperPluginInstanceImpl::PrintPageHelper(
|
| PP_PrintPageNumberRange_Dev* page_ranges,
|
| int num_ranges,
|
| - blink::WebCanvas* canvas) {
|
| + printing::MetafileSkiaWrapper* wrapper) {
|
| // Keep a reference on the stack. See NOTE above.
|
| scoped_refptr<PepperPluginInstanceImpl> ref(this);
|
| DCHECK(plugin_print_interface_);
|
| @@ -1839,18 +1846,22 @@ void PepperPluginInstanceImpl::PrintPageHelper(
|
| return;
|
|
|
| if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF)
|
| - PrintPDFOutput(print_output, canvas);
|
| + PrintPDFOutput(print_output, wrapper);
|
|
|
| // Now we need to release the print output resource.
|
| PluginModule::GetCore()->ReleaseResource(print_output);
|
| }
|
| +#endif // BUILDFLAG(ENABLE_PRINTING)
|
|
|
| void PepperPluginInstanceImpl::PrintEnd() {
|
| +#if BUILDFLAG(ENABLE_PRINTING)
|
| // Keep a reference on the stack. See NOTE above.
|
| scoped_refptr<PepperPluginInstanceImpl> ref(this);
|
| - if (!ranges_.empty())
|
| - PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_);
|
| - canvas_ = nullptr;
|
| + if (!ranges_.empty()) {
|
| + PrintPageHelper(&(ranges_.front()), ranges_.size(),
|
| + metafile_wrapper_.get());
|
| + }
|
| + metafile_wrapper_.reset();
|
| ranges_.clear();
|
|
|
| DCHECK(plugin_print_interface_);
|
| @@ -1861,6 +1872,9 @@ void PepperPluginInstanceImpl::PrintEnd() {
|
| #if defined(OS_MACOSX)
|
| last_printed_page_ = NULL;
|
| #endif // defined(OS_MACOSX)
|
| +#else
|
| + NOTREACHED();
|
| +#endif // BUILDFLAG(ENABLE_PRINTING)
|
| }
|
|
|
| bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument(
|
| @@ -2017,8 +2031,9 @@ bool PepperPluginInstanceImpl::IsViewAccelerated() {
|
| return view->isAcceleratedCompositingActive();
|
| }
|
|
|
| -bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output,
|
| - blink::WebCanvas* canvas) {
|
| +bool PepperPluginInstanceImpl::PrintPDFOutput(
|
| + PP_Resource print_output,
|
| + printing::MetafileSkiaWrapper* wrapper) {
|
| #if BUILDFLAG(ENABLE_PRINTING)
|
| ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true);
|
| if (enter.failed())
|
| @@ -2030,13 +2045,11 @@ bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output,
|
| return false;
|
| }
|
|
|
| - printing::PdfMetafileSkia* metafile =
|
| - printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas);
|
| - if (metafile)
|
| - return metafile->InitFromData(mapper.data(), mapper.size());
|
| + if (wrapper && wrapper->metafile())
|
| + return wrapper->metafile()->InitFromData(mapper.data(), mapper.size());
|
|
|
| NOTREACHED();
|
| -#endif // ENABLE_PRINTING
|
| +#endif // BUILDFLAG(ENABLE_PRINTING)
|
| return false;
|
| }
|
|
|
|
|