0

[unseasoned-pdf] Implement common method to query print preset options

Implement PdfViewPluginBase::GetPrintPresetOptions() which returns
a `blink::WebPrintPresetOptions`, allowing for common use by both PDF
plugin implementations. Also, introduce a function to convert the Blink
struct to a Pepper equivalent, so that it may be used by
OutOfProcessInstance.

Bug: 1200000
Change-Id: I016692cf6432e7f0436fa05551c566d51c92cd16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2962319
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892632}
This commit is contained in:
Daniel Hosseinian
2021-06-15 17:37:59 +00:00
committed by Chromium LUCI CQ
parent 4f9be441fa
commit a7da5b6603
8 changed files with 64 additions and 25 deletions

@ -325,8 +325,8 @@ if (enable_pdf) {
"//pdf:buildflags",
"//ppapi/cpp:objects",
"//ppapi/cpp/private:internal_module",
"//printing/mojom",
"//skia",
"//third_party/blink/public:blink_headers",
"//third_party/blink/public/common:headers",
"//ui/base",
"//ui/base/cursor/mojom:cursor_type",

@ -59,9 +59,9 @@
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/var_dictionary.h"
#include "printing/mojom/print.mojom-shared.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/web/web_print_preset_options.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
@ -622,29 +622,8 @@ void OutOfProcessInstance::DidChangeFocus(bool has_focus) {
void OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
PP_PdfPrintPresetOptions_Dev* options) {
options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled());
options->copies = engine()->GetCopiesToPrint();
switch (engine()->GetDuplexMode()) {
case printing::mojom::DuplexMode::kUnknownDuplexMode:
options->duplex = PP_PRIVATEDUPLEXMODE_NONE;
break;
case printing::mojom::DuplexMode::kSimplex:
options->duplex = PP_PRIVATEDUPLEXMODE_SIMPLEX;
break;
case printing::mojom::DuplexMode::kLongEdge:
options->duplex = PP_PRIVATEDUPLEXMODE_LONG_EDGE;
break;
case printing::mojom::DuplexMode::kShortEdge:
options->duplex = PP_PRIVATEDUPLEXMODE_SHORT_EDGE;
break;
}
absl::optional<gfx::Size> uniform_page_size =
engine()->GetUniformPageSizePoints();
options->is_page_size_uniform = PP_FromBool(uniform_page_size.has_value());
options->uniform_page_size = PPSizeFromSize(
uniform_page_size.has_value() ? uniform_page_size.value() : gfx::Size());
*options =
PPPdfPrintPresetOptionsFromWebPrintPresetOptions(GetPrintPresetOptions());
}
void OutOfProcessInstance::SelectionChanged(const gfx::Rect& left,

@ -50,6 +50,7 @@
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/blink/public/common/input/web_touch_event.h"
#include "third_party/blink/public/web/web_print_preset_options.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/text/bytes_formatting.h"
@ -561,6 +562,15 @@ void PdfViewPluginBase::OnGeometryChanged(double old_zoom,
PrepareAndSetAccessibilityViewportInfo();
}
blink::WebPrintPresetOptions PdfViewPluginBase::GetPrintPresetOptions() {
blink::WebPrintPresetOptions options;
options.is_scaling_disabled = !engine_->GetPrintScaling();
options.copies = engine_->GetCopiesToPrint();
options.duplex_mode = engine_->GetDuplexMode();
options.uniform_page_size = engine_->GetUniformPageSizePoints();
return options;
}
int PdfViewPluginBase::PrintBegin(const blink::WebPrintParams& print_params) {
// The returned value is always equal to the number of pages in the PDF
// document irrespective of the printable area.

@ -31,6 +31,7 @@ class Value;
namespace blink {
class WebInputEvent;
struct WebPrintPresetOptions;
} // namespace blink
namespace chrome_pdf {
@ -256,6 +257,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
virtual void SetAccessibilityViewportInfo(
const AccessibilityViewportInfo& viewport_info) = 0;
// Returns the print preset options for the document.
blink::WebPrintPresetOptions GetPrintPresetOptions();
// Begins a print session with the given `print_params`. A call to
// `PrintPages()` can only be made after after a successful call to
// `PrintBegin()`. Returns the number of pages required for the print output.

@ -61,6 +61,7 @@
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_plugin_container.h"
#include "third_party/blink/public/web/web_plugin_params.h"
#include "third_party/blink/public/web/web_print_preset_options.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/base/cursor/cursor.h"
@ -320,6 +321,12 @@ bool PdfViewWebPlugin::SupportsPaginatedPrint() {
return true;
}
bool PdfViewWebPlugin::GetPrintPresetOptionsFromDocument(
blink::WebPrintPresetOptions* print_preset_options) {
*print_preset_options = GetPrintPresetOptions();
return true;
}
int PdfViewWebPlugin::PrintBegin(const blink::WebPrintParams& print_params) {
return PdfViewPluginBase::PrintBegin(print_params);
}

@ -110,6 +110,8 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void DidFinishLoading() override;
void DidFailLoading(const blink::WebURLError& error) override;
bool SupportsPaginatedPrint() override;
bool GetPrintPresetOptionsFromDocument(
blink::WebPrintPresetOptions* print_preset_options) override;
int PrintBegin(const blink::WebPrintParams& print_params) override;
void PrintPage(int page_number, cc::PaintCanvas* canvas) override;
void PrintEnd() override;

@ -12,9 +12,11 @@
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/c/dev/pp_print_settings_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/private/ppp_pdf.h"
#include "printing/mojom/print.mojom.h"
#include "third_party/blink/public/web/web_print_params.h"
#include "third_party/blink/public/web/web_print_preset_options.h"
namespace chrome_pdf {
@ -34,6 +36,36 @@ std::vector<int> PageNumbersFromPPPrintPageNumberRange(
return page_numbers;
}
PP_PdfPrintPresetOptions_Dev PPPdfPrintPresetOptionsFromWebPrintPresetOptions(
const blink::WebPrintPresetOptions& print_preset_options) {
PP_PdfPrintPresetOptions_Dev options;
options.is_scaling_disabled =
PP_FromBool(print_preset_options.is_scaling_disabled);
options.copies = print_preset_options.copies;
switch (print_preset_options.duplex_mode) {
case printing::mojom::DuplexMode::kUnknownDuplexMode:
options.duplex = PP_PRIVATEDUPLEXMODE_NONE;
break;
case printing::mojom::DuplexMode::kSimplex:
options.duplex = PP_PRIVATEDUPLEXMODE_SIMPLEX;
break;
case printing::mojom::DuplexMode::kLongEdge:
options.duplex = PP_PRIVATEDUPLEXMODE_LONG_EDGE;
break;
case printing::mojom::DuplexMode::kShortEdge:
options.duplex = PP_PRIVATEDUPLEXMODE_SHORT_EDGE;
break;
}
options.is_page_size_uniform =
PP_FromBool(print_preset_options.uniform_page_size.has_value());
options.uniform_page_size = PPSizeFromSize(
print_preset_options.uniform_page_size.value_or(gfx::Size()));
return options;
}
blink::WebPrintParams WebPrintParamsFromPPPrintSettings(
const PP_PrintSettings_Dev& print_settings,
const PP_PdfPrintSettings_Dev& pdf_print_settings) {

@ -11,10 +11,12 @@
struct PP_PrintPageNumberRange_Dev;
struct PP_PrintSettings_Dev;
struct PP_PdfPrintPresetOptions_Dev;
struct PP_PdfPrintSettings_Dev;
namespace blink {
struct WebPrintParams;
struct WebPrintPresetOptions;
} // namespace blink
namespace chrome_pdf {
@ -23,6 +25,9 @@ std::vector<int> PageNumbersFromPPPrintPageNumberRange(
const PP_PrintPageNumberRange_Dev* page_ranges,
uint32_t page_range_count);
PP_PdfPrintPresetOptions_Dev PPPdfPrintPresetOptionsFromWebPrintPresetOptions(
const blink::WebPrintPresetOptions& print_preset_options);
blink::WebPrintParams WebPrintParamsFromPPPrintSettings(
const PP_PrintSettings_Dev& print_settings,
const PP_PdfPrintSettings_Dev& pdf_print_settings);