[unseasoned-pdf] Propagate printed PDF data as a vector of bytes
Convert the vector of bytes to a pp::Resource inside OutOfProcessInstance rather than PDFiumEngine, thus making PDFiumEngine's printing implementations compatible with the Pepper-free plugin. Bug: 1200000 Change-Id: I2fcc93bef6aee51be0736ee4896da122dfcbeaec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2950322 Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#892244}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4041de9d04
commit
457aa3f7b3
@ -44,6 +44,7 @@
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/c/private/ppb_pdf.h"
|
||||
#include "ppapi/cpp/core.h"
|
||||
#include "ppapi/cpp/dev/buffer_dev.h"
|
||||
#include "ppapi/cpp/dev/memory_dev.h"
|
||||
#include "ppapi/cpp/dev/text_input_dev.h"
|
||||
#include "ppapi/cpp/dev/url_util_dev.h"
|
||||
@ -770,9 +771,18 @@ pp::Resource OutOfProcessInstance::PrintPages(
|
||||
const std::vector<int> page_numbers =
|
||||
PageNumbersFromPPPrintPageNumberRange(page_ranges, page_range_count);
|
||||
|
||||
return engine()->PrintPages(page_numbers,
|
||||
print_settings_.pepper_print_settings,
|
||||
print_settings_.pdf_print_settings);
|
||||
const std::vector<uint8_t> pdf_data =
|
||||
engine()->PrintPages(page_numbers, print_settings_.pepper_print_settings,
|
||||
print_settings_.pdf_print_settings);
|
||||
|
||||
// Convert buffer to Pepper type.
|
||||
pp::Buffer_Dev buffer;
|
||||
if (!pdf_data.empty()) {
|
||||
buffer = pp::Buffer_Dev(GetPluginInstance(), pdf_data.size());
|
||||
if (!buffer.is_null())
|
||||
memcpy(buffer.data(), pdf_data.data(), pdf_data.size());
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::PrintEnd() {
|
||||
|
@ -320,7 +320,7 @@ class PDFEngine {
|
||||
virtual bool HandleDocumentLoad(std::unique_ptr<UrlLoader> loader) = 0;
|
||||
virtual bool HandleInputEvent(const blink::WebInputEvent& event) = 0;
|
||||
virtual void PrintBegin() = 0;
|
||||
virtual pp::Resource PrintPages(
|
||||
virtual std::vector<uint8_t> PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) = 0;
|
||||
|
@ -969,7 +969,7 @@ void PDFiumEngine::PrintBegin() {
|
||||
FORM_DoDocumentAAction(form(), FPDFDOC_AACTION_WP);
|
||||
}
|
||||
|
||||
pp::Resource PDFiumEngine::PrintPages(
|
||||
std::vector<uint8_t> PDFiumEngine::PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
@ -983,26 +983,26 @@ pp::Resource PDFiumEngine::PrintPages(
|
||||
return PrintPagesAsRasterPdf(page_numbers, print_settings,
|
||||
pdf_print_settings);
|
||||
}
|
||||
return pp::Resource();
|
||||
return std::vector<uint8_t>();
|
||||
}
|
||||
|
||||
pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPdf(
|
||||
std::vector<uint8_t> PDFiumEngine::PrintPagesAsRasterPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
// If document is not downloaded yet, disable printing.
|
||||
if (doc() && !doc_loader_->IsDocumentComplete())
|
||||
return pp::Buffer_Dev();
|
||||
return std::vector<uint8_t>();
|
||||
|
||||
KillFormFocus();
|
||||
|
||||
SetLastInstance();
|
||||
|
||||
return ConvertPdfToBufferDev(print_.PrintPagesAsPdf(
|
||||
page_numbers, print_settings, pdf_print_settings, /*raster=*/true));
|
||||
return print_.PrintPagesAsPdf(page_numbers, print_settings,
|
||||
pdf_print_settings, /*raster=*/true);
|
||||
}
|
||||
|
||||
pp::Buffer_Dev PDFiumEngine::PrintPagesAsPdf(
|
||||
std::vector<uint8_t> PDFiumEngine::PrintPagesAsPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
@ -1016,19 +1016,8 @@ pp::Buffer_Dev PDFiumEngine::PrintPagesAsPdf(
|
||||
pages_[page_number]->Unload();
|
||||
}
|
||||
|
||||
return ConvertPdfToBufferDev(print_.PrintPagesAsPdf(
|
||||
page_numbers, print_settings, pdf_print_settings, /*raster=*/false));
|
||||
}
|
||||
|
||||
pp::Buffer_Dev PDFiumEngine::ConvertPdfToBufferDev(
|
||||
const std::vector<uint8_t>& pdf_data) {
|
||||
pp::Buffer_Dev buffer;
|
||||
if (!pdf_data.empty()) {
|
||||
buffer = pp::Buffer_Dev(GetPluginInstance(), pdf_data.size());
|
||||
if (!buffer.is_null())
|
||||
memcpy(buffer.data(), pdf_data.data(), pdf_data.size());
|
||||
}
|
||||
return buffer;
|
||||
return print_.PrintPagesAsPdf(page_numbers, print_settings,
|
||||
pdf_print_settings, /*raster=*/false);
|
||||
}
|
||||
|
||||
void PDFiumEngine::KillFormFocus() {
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "pdf/pdfium/pdfium_print.h"
|
||||
#include "pdf/pdfium/pdfium_range.h"
|
||||
#include "ppapi/c/private/ppp_pdf.h"
|
||||
#include "ppapi/cpp/dev/buffer_dev.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
#include "third_party/pdfium/public/fpdf_formfill.h"
|
||||
@ -98,7 +97,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
bool HandleDocumentLoad(std::unique_ptr<UrlLoader> loader) override;
|
||||
bool HandleInputEvent(const blink::WebInputEvent& event) override;
|
||||
void PrintBegin() override;
|
||||
pp::Resource PrintPages(
|
||||
std::vector<uint8_t> PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) override;
|
||||
@ -414,18 +413,16 @@ class PDFiumEngine : public PDFEngine,
|
||||
|
||||
bool ExtendSelection(int page_index, int char_index);
|
||||
|
||||
pp::Buffer_Dev PrintPagesAsRasterPdf(
|
||||
std::vector<uint8_t> PrintPagesAsRasterPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings);
|
||||
|
||||
pp::Buffer_Dev PrintPagesAsPdf(
|
||||
std::vector<uint8_t> PrintPagesAsPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings);
|
||||
|
||||
pp::Buffer_Dev ConvertPdfToBufferDev(const std::vector<uint8_t>& pdf_data);
|
||||
|
||||
// Checks if `page` has selected text in a form element. If so, sets that as
|
||||
// the plugin's text selection.
|
||||
void SetFormSelectedText(FPDF_FORMHANDLE form_handle, FPDF_PAGE page);
|
||||
|
Reference in New Issue
Block a user