Remove PDFEngine abstraction
PDFiumEngine is the only concrete implementation of the PDFEngine interface. Stop pretending PDFEngine is going to support other implementations and merge the two. Bug: 40128715 Change-Id: Iea3af0d4ce996d0cc9ce46c701444bcdc3b4c479 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5715834 Reviewed-by: Alan Screen <awscreen@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1329883}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
ccc7ce6d1b
commit
3c76daeb7f
pdf
BUILD.gnaccessibility.ccaccessibility.hpdf.ccpdf_engine.hpdf_view_web_plugin.ccpdf_view_web_plugin.h
pdfium
pdfium_engine.ccpdfium_engine.hpdfium_engine_client.hpdfium_engine_exports.hpdfium_engine_exports_unittest.ccpdfium_engine_unittest.ccpdfium_font_win_unittest.ccpdfium_page.hpdfium_permissions.hpdfium_searchify.cc
test
@ -104,7 +104,6 @@ if (enable_pdf) {
|
||||
"paint_ready_rect.h",
|
||||
"parsed_params.cc",
|
||||
"parsed_params.h",
|
||||
"pdf_engine.h",
|
||||
"pdf_init.cc",
|
||||
"pdf_init.h",
|
||||
"pdf_transform.cc",
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "pdf/accessibility_helper.h"
|
||||
#include "pdf/accessibility_structs.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -19,7 +19,7 @@ namespace chrome_pdf {
|
||||
namespace {
|
||||
|
||||
AccessibilityFormFieldInfo GetAccessibilityFormFieldInfo(
|
||||
PDFEngine* engine,
|
||||
PDFiumEngine* engine,
|
||||
int32_t page_index,
|
||||
uint32_t text_run_count) {
|
||||
AccessibilityFormFieldInfo form_field_info;
|
||||
@ -30,7 +30,7 @@ AccessibilityFormFieldInfo GetAccessibilityFormFieldInfo(
|
||||
|
||||
} // namespace
|
||||
|
||||
bool GetAccessibilityInfo(PDFEngine* engine,
|
||||
bool GetAccessibilityInfo(PDFiumEngine* engine,
|
||||
int32_t page_index,
|
||||
AccessibilityPageInfo& page_info,
|
||||
std::vector<AccessibilityTextRunInfo>& text_runs,
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
class PDFEngine;
|
||||
class PDFiumEngine;
|
||||
struct AccessibilityCharInfo;
|
||||
struct AccessibilityPageInfo;
|
||||
struct AccessibilityPageObjects;
|
||||
@ -21,7 +21,7 @@ struct AccessibilityTextRunInfo;
|
||||
// `engine` for the page at 0-indexed `page_index`. Returns true on success with
|
||||
// all out parameters filled, or false on failure with all out parameters
|
||||
// untouched.
|
||||
bool GetAccessibilityInfo(PDFEngine* engine,
|
||||
bool GetAccessibilityInfo(PDFiumEngine* engine,
|
||||
int32_t page_index,
|
||||
AccessibilityPageInfo& page_info,
|
||||
std::vector<AccessibilityTextRunInfo>& text_runs,
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/pdf_features.h"
|
||||
#include "pdf/pdf_init.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_exports.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
310
pdf/pdf_engine.h
310
pdf/pdf_engine.h
@ -1,310 +0,0 @@
|
||||
// Copyright 2012 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef PDF_PDF_ENGINE_H_
|
||||
#define PDF_PDF_ENGINE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/span.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/values.h"
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/document_layout.h"
|
||||
#include "pdf/ui/thumbnail.h"
|
||||
#include "printing/mojom/print.mojom-forward.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom-forward.h"
|
||||
#endif
|
||||
|
||||
class SkBitmap;
|
||||
|
||||
namespace blink {
|
||||
class WebInputEvent;
|
||||
struct WebPrintParams;
|
||||
} // namespace blink
|
||||
|
||||
namespace gfx {
|
||||
class Point;
|
||||
class Size;
|
||||
class Vector2d;
|
||||
} // namespace gfx
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
struct AccessibilityActionData;
|
||||
struct AccessibilityFocusInfo;
|
||||
struct AccessibilityLinkInfo;
|
||||
struct AccessibilityHighlightInfo;
|
||||
struct AccessibilityImageInfo;
|
||||
struct AccessibilityTextFieldInfo;
|
||||
struct AccessibilityTextRunInfo;
|
||||
struct DocumentAttachmentInfo;
|
||||
struct DocumentMetadata;
|
||||
|
||||
enum class FontMappingMode {
|
||||
// Do not perform font mapping.
|
||||
kNoMapping,
|
||||
// Perform font mapping in renderer processes using Blink/content APIs.
|
||||
kBlink,
|
||||
};
|
||||
|
||||
enum class DocumentPermission {
|
||||
kCopy,
|
||||
kCopyAccessible,
|
||||
kPrintLowQuality,
|
||||
kPrintHighQuality,
|
||||
};
|
||||
|
||||
// Do one time initialization of the SDK.
|
||||
// If `enable_v8` is false, then the PDFEngine will not be able to run
|
||||
// JavaScript.
|
||||
// When `use_skia` is true, the PDFEngine will use Skia renderer. Otherwise, it
|
||||
// will use AGG renderer.
|
||||
void InitializeSDK(bool enable_v8,
|
||||
bool use_skia,
|
||||
FontMappingMode font_mapping_mode);
|
||||
// Tells the SDK that we're shutting down.
|
||||
void ShutdownSDK();
|
||||
|
||||
// This class encapsulates a PDF rendering engine.
|
||||
class PDFEngine {
|
||||
public:
|
||||
// Maximum number of parameters a nameddest view can contain.
|
||||
static constexpr size_t kMaxViewParams = 4;
|
||||
|
||||
// Named destination in a document.
|
||||
struct NamedDestination {
|
||||
// 0-based page number.
|
||||
unsigned long page;
|
||||
|
||||
// View fit type (see table 8.2 "Destination syntax" on page 582 of PDF
|
||||
// Reference 1.7). Empty string if not present.
|
||||
std::string view;
|
||||
|
||||
// Number of parameters for the view.
|
||||
unsigned long num_params;
|
||||
|
||||
// Parameters for the view. Their meaning depends on the `view` and their
|
||||
// number is defined by `num_params` but is at most `kMaxViewParams`. Note:
|
||||
// If a parameter stands for the x/y coordinates, it should be transformed
|
||||
// into the corresponding in-screen coordinates before it's sent to the
|
||||
// viewport.
|
||||
float params[kMaxViewParams];
|
||||
|
||||
// A string of parameters for view fit type XYZ in the format of "x,y,zoom",
|
||||
// where x and y parameters are the in-screen coordinates and zoom is the
|
||||
// zoom level. If a parameter is "null", then current value of that
|
||||
// parameter in the viewport should be retained. Note: This string is empty
|
||||
// if the view's fit type is not XYZ.
|
||||
std::string xyz_params;
|
||||
};
|
||||
|
||||
virtual ~PDFEngine() = default;
|
||||
|
||||
// Most of these functions are similar to the Pepper functions of the same
|
||||
// name, so not repeating the description here unless it's different.
|
||||
virtual void PageOffsetUpdated(const gfx::Vector2d& page_offset) = 0;
|
||||
virtual void PluginSizeUpdated(const gfx::Size& size) = 0;
|
||||
virtual void ScrolledToXPosition(int position) = 0;
|
||||
virtual void ScrolledToYPosition(int position) = 0;
|
||||
// Paint is called a series of times. Before these n calls are made, PrePaint
|
||||
// is called once. After Paint is called n times, PostPaint is called once.
|
||||
virtual void PrePaint() = 0;
|
||||
virtual void Paint(const gfx::Rect& rect,
|
||||
SkBitmap& image_data,
|
||||
std::vector<gfx::Rect>& ready,
|
||||
std::vector<gfx::Rect>& pending) = 0;
|
||||
virtual void PostPaint() = 0;
|
||||
virtual bool HandleInputEvent(const blink::WebInputEvent& event) = 0;
|
||||
virtual void PrintBegin() = 0;
|
||||
virtual std::vector<uint8_t> PrintPages(
|
||||
const std::vector<int>& page_index,
|
||||
const blink::WebPrintParams& print_params) = 0;
|
||||
virtual void PrintEnd() = 0;
|
||||
virtual void StartFind(const std::u16string& text, bool case_sensitive) = 0;
|
||||
virtual bool SelectFindResult(bool forward) = 0;
|
||||
virtual void StopFind() = 0;
|
||||
virtual void ZoomUpdated(double new_zoom_level) = 0;
|
||||
virtual void RotateClockwise() = 0;
|
||||
virtual void RotateCounterclockwise() = 0;
|
||||
virtual bool IsReadOnly() const = 0;
|
||||
virtual void SetReadOnly(bool enable) = 0;
|
||||
virtual void SetDocumentLayout(DocumentLayout::PageSpread page_spread) = 0;
|
||||
virtual void DisplayAnnotations(bool display) = 0;
|
||||
|
||||
// Applies the document layout options proposed by a call to
|
||||
// PDFiumEngineClient::ProposeDocumentLayout(), returning the overall size of
|
||||
// the new effective layout.
|
||||
virtual gfx::Size ApplyDocumentLayout(
|
||||
const DocumentLayout::Options& options) = 0;
|
||||
|
||||
virtual std::string GetSelectedText() = 0;
|
||||
// Returns true if focus is within an editable form text area.
|
||||
virtual bool CanEditText() const = 0;
|
||||
// Returns true if focus is within an editable form text area and the text
|
||||
// area has text.
|
||||
virtual bool HasEditableText() const = 0;
|
||||
// Replace selected text within an editable form text area with another
|
||||
// string. If there is no selected text, append the replacement text after the
|
||||
// current caret position.
|
||||
virtual void ReplaceSelection(const std::string& text) = 0;
|
||||
// Methods to check if undo/redo is possible, and to perform them.
|
||||
virtual bool CanUndo() const = 0;
|
||||
virtual bool CanRedo() const = 0;
|
||||
virtual void Undo() = 0;
|
||||
virtual void Redo() = 0;
|
||||
// Handles actions invoked by Accessibility clients.
|
||||
virtual void HandleAccessibilityAction(
|
||||
const AccessibilityActionData& action_data) = 0;
|
||||
virtual std::string GetLinkAtPosition(const gfx::Point& point) = 0;
|
||||
// Checks the permissions associated with this document.
|
||||
virtual bool HasPermission(DocumentPermission permission) const = 0;
|
||||
virtual void SelectAll() = 0;
|
||||
// Gets the list of DocumentAttachmentInfo from the document.
|
||||
virtual const std::vector<DocumentAttachmentInfo>&
|
||||
GetDocumentAttachmentInfoList() const = 0;
|
||||
// Gets the content of an attachment by the attachment's `index`. `index`
|
||||
// must be in the range of [0, attachment_count-1), where `attachment_count`
|
||||
// is the number of attachments embedded in the document.
|
||||
// The caller of this method is responsible for checking whether the
|
||||
// attachment is readable, attachment size is not 0 byte, and the return
|
||||
// value's size matches the corresponding DocumentAttachmentInfo's
|
||||
// `size_bytes`.
|
||||
virtual std::vector<uint8_t> GetAttachmentData(size_t index) = 0;
|
||||
// Gets metadata about the document.
|
||||
virtual const DocumentMetadata& GetDocumentMetadata() const = 0;
|
||||
// Gets the number of pages in the document.
|
||||
virtual int GetNumberOfPages() const = 0;
|
||||
// Gets the named destination by name.
|
||||
virtual std::optional<PDFEngine::NamedDestination> GetNamedDestination(
|
||||
const std::string& destination) = 0;
|
||||
// Gets the index of the most visible page, or -1 if none are visible.
|
||||
virtual int GetMostVisiblePage() = 0;
|
||||
// Returns whether the page at `index` is visible or not.
|
||||
virtual bool IsPageVisible(int index) const = 0;
|
||||
// Gets the current layout orientation.
|
||||
virtual PageOrientation GetCurrentOrientation() const = 0;
|
||||
// Gets the rectangle of the page not including the shadow.
|
||||
virtual gfx::Rect GetPageBoundsRect(int index) = 0;
|
||||
// Gets the rectangle of the page excluding any additional areas.
|
||||
virtual gfx::Rect GetPageContentsRect(int index) = 0;
|
||||
// Returns a page's rect in screen coordinates, as well as its surrounding
|
||||
// border areas and bottom separator.
|
||||
virtual gfx::Rect GetPageScreenRect(int page_index) const = 0;
|
||||
// Return a page's bounding box rectangle, or an empty rectangle if
|
||||
// `page_index` is invalid.
|
||||
virtual gfx::RectF GetPageBoundingBox(int page_index) = 0;
|
||||
// Set color / grayscale rendering modes.
|
||||
virtual void SetGrayscale(bool grayscale) = 0;
|
||||
// Get the number of characters on a given page.
|
||||
virtual int GetCharCount(int page_index) = 0;
|
||||
// Get the bounds in page pixels of a character on a given page.
|
||||
virtual gfx::RectF GetCharBounds(int page_index, int char_index) = 0;
|
||||
// Get a given unicode character on a given page.
|
||||
virtual uint32_t GetCharUnicode(int page_index, int char_index) = 0;
|
||||
// Given a start char index, find the longest continuous run of text that's
|
||||
// in a single direction and with the same text style. Return a filled out
|
||||
// AccessibilityTextRunInfo on success or std::nullopt on failure. e.g. When
|
||||
// `start_char_index` is out of bounds.
|
||||
virtual std::optional<AccessibilityTextRunInfo> GetTextRunInfo(
|
||||
int page_index,
|
||||
int start_char_index) = 0;
|
||||
// For all the links on page `page_index`, get their urls, underlying text
|
||||
// ranges and bounding boxes.
|
||||
virtual std::vector<AccessibilityLinkInfo> GetLinkInfo(
|
||||
int page_index,
|
||||
const std::vector<AccessibilityTextRunInfo>& text_runs) = 0;
|
||||
// For all the images in page `page_index`, get their alt texts and bounding
|
||||
// boxes. If the alt text is empty or unavailable, and if the user has
|
||||
// requested that the OCR service tag the PDF so that it is made accessible,
|
||||
// transfer the raw image pixels in the `image_data` field. Otherwise do not
|
||||
// populate the `image_data` field.
|
||||
virtual std::vector<AccessibilityImageInfo> GetImageInfo(
|
||||
int page_index,
|
||||
uint32_t text_run_count) = 0;
|
||||
// Returns the image as a 32-bit bitmap format for OCR.
|
||||
virtual SkBitmap GetImageForOcr(int page_index, int image_index) = 0;
|
||||
// For all the highlights in page `page_index`, get their underlying text
|
||||
// ranges and bounding boxes.
|
||||
virtual std::vector<AccessibilityHighlightInfo> GetHighlightInfo(
|
||||
int page_index,
|
||||
const std::vector<AccessibilityTextRunInfo>& text_runs) = 0;
|
||||
// For all the text fields in page `page_index`, get their properties like
|
||||
// name, value, bounding boxes etc.
|
||||
virtual std::vector<AccessibilityTextFieldInfo> GetTextFieldInfo(
|
||||
int page_index,
|
||||
uint32_t text_run_count) = 0;
|
||||
|
||||
// Gets the PDF document's print scaling preference. True if the document can
|
||||
// be scaled to fit.
|
||||
virtual bool GetPrintScaling() = 0;
|
||||
// Returns number of copies to be printed.
|
||||
virtual int GetCopiesToPrint() = 0;
|
||||
// Returns the duplex setting.
|
||||
virtual printing::mojom::DuplexMode GetDuplexMode() = 0;
|
||||
// Returns the uniform page size of the document in points. Returns
|
||||
// `std::nullopt` if the document has more than one page size.
|
||||
virtual std::optional<gfx::Size> GetUniformPageSizePoints() = 0;
|
||||
|
||||
// Returns a list of Values of Bookmarks. Each Bookmark is a dictionary Value
|
||||
// which contains the following key/values:
|
||||
// - "title" - a string Value.
|
||||
// - "page" - an int Value.
|
||||
// - "children" - a list of Values, with each entry containing
|
||||
// a dictionary Value of the same structure.
|
||||
virtual base::Value::List GetBookmarks() = 0;
|
||||
|
||||
// Append blank pages to make a 1-page document to a `num_pages` document.
|
||||
// Always retain the first page data.
|
||||
virtual void AppendBlankPages(size_t num_pages) = 0;
|
||||
// Append the first page of the document loaded with the `engine` to this
|
||||
// document at page `index`.
|
||||
virtual void AppendPage(PDFEngine* engine, int index) = 0;
|
||||
|
||||
virtual std::vector<uint8_t> GetSaveData() = 0;
|
||||
|
||||
virtual void SetCaretPosition(const gfx::Point& position) = 0;
|
||||
virtual void MoveRangeSelectionExtent(const gfx::Point& extent) = 0;
|
||||
virtual void SetSelectionBounds(const gfx::Point& base,
|
||||
const gfx::Point& extent) = 0;
|
||||
virtual void GetSelection(uint32_t* selection_start_page_index,
|
||||
uint32_t* selection_start_char_index,
|
||||
uint32_t* selection_end_page_index,
|
||||
uint32_t* selection_end_char_index) = 0;
|
||||
|
||||
// Remove focus from form widgets, consolidating the user input.
|
||||
virtual void KillFormFocus() = 0;
|
||||
|
||||
// Notify whether the PDF currently has the focus or not.
|
||||
virtual void UpdateFocus(bool has_focus) = 0;
|
||||
|
||||
// Returns the focus info of current focus item.
|
||||
virtual AccessibilityFocusInfo GetFocusInfo() = 0;
|
||||
|
||||
virtual bool IsPDFDocTagged() = 0;
|
||||
|
||||
virtual uint32_t GetLoadedByteSize() = 0;
|
||||
virtual bool ReadLoadedBytes(uint32_t length, void* buffer) = 0;
|
||||
|
||||
// Requests for a thumbnail to be sent using a callback when the page is ready
|
||||
// to be rendered. `send_callback` is run with the thumbnail data when ready.
|
||||
virtual void RequestThumbnail(int page_index,
|
||||
float device_pixel_ratio,
|
||||
SendThumbnailCallback send_callback) = 0;
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
#endif // PDF_PDF_ENGINE_H_
|
@ -65,7 +65,6 @@
|
||||
#include "pdf/paint_ready_rect.h"
|
||||
#include "pdf/parsed_params.h"
|
||||
#include "pdf/pdf_accessibility_data_handler.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdf_features.h"
|
||||
#include "pdf/pdf_init.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
@ -425,8 +424,8 @@ void PdfViewWebPlugin::DidOpen(std::unique_ptr<UrlLoader> loader,
|
||||
|
||||
void PdfViewWebPlugin::Destroy() {
|
||||
if (initialized_) {
|
||||
// Explicitly destroy the PDFEngine during destruction as it may call back
|
||||
// into this object.
|
||||
// Explicitly destroy the PDFiumEngine during destruction as it may call
|
||||
// back into this object.
|
||||
preview_engine_.reset();
|
||||
engine_.reset();
|
||||
PerProcessInitializer::GetInstance().Release();
|
||||
@ -1392,7 +1391,7 @@ void PdfViewWebPlugin::HandleDisplayAnnotationsMessage(
|
||||
|
||||
void PdfViewWebPlugin::HandleGetNamedDestinationMessage(
|
||||
const base::Value::Dict& message) {
|
||||
std::optional<PDFEngine::NamedDestination> named_destination =
|
||||
std::optional<PDFiumEngine::NamedDestination> named_destination =
|
||||
engine_->GetNamedDestination(*message.FindString("namedDestination"));
|
||||
|
||||
const int page_number = named_destination.has_value()
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "pdf/paint_manager.h"
|
||||
#include "pdf/pdf_accessibility_action_handler.h"
|
||||
#include "pdf/pdf_accessibility_image_fetcher.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_client.h"
|
||||
#include "pdf/pdfium/pdfium_form_filler.h"
|
||||
#include "pdf/post_message_receiver.h"
|
||||
|
@ -765,7 +765,7 @@ std::unique_ptr<URLLoaderWrapper> PDFiumEngine::CreateURLLoader() {
|
||||
return std::make_unique<URLLoaderWrapperImpl>(client_->CreateUrlLoader());
|
||||
}
|
||||
|
||||
void PDFiumEngine::AppendPage(PDFEngine* engine, int index) {
|
||||
void PDFiumEngine::AppendPage(PDFiumEngine* engine, int index) {
|
||||
CHECK(engine);
|
||||
CHECK(PageIndexInBounds(index));
|
||||
|
||||
@ -2522,7 +2522,7 @@ void PDFiumEngine::ScrollToGlobalPoint(const gfx::Rect& target_rect,
|
||||
client_->ScrollBy(scroll_offset - global_point);
|
||||
}
|
||||
|
||||
std::optional<PDFEngine::NamedDestination> PDFiumEngine::GetNamedDestination(
|
||||
std::optional<PDFiumEngine::NamedDestination> PDFiumEngine::GetNamedDestination(
|
||||
const std::string& destination) {
|
||||
// Look for the destination.
|
||||
FPDF_DEST dest = FPDF_GetNamedDestByName(doc(), destination.c_str());
|
||||
@ -2543,7 +2543,7 @@ std::optional<PDFEngine::NamedDestination> PDFiumEngine::GetNamedDestination(
|
||||
if (!PageIndexInBounds(page))
|
||||
return {};
|
||||
|
||||
PDFEngine::NamedDestination result;
|
||||
NamedDestination result;
|
||||
result.page = page;
|
||||
unsigned long view_int =
|
||||
FPDFDest_GetView(dest, &result.num_params, result.params);
|
||||
|
@ -16,22 +16,25 @@
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/raw_span.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/timer/timer.h"
|
||||
#include "base/values.h"
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/document_attachment_info.h"
|
||||
#include "pdf/document_layout.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/loader/document_loader.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_client.h"
|
||||
#include "pdf/pdfium/pdfium_form_filler.h"
|
||||
#include "pdf/pdfium/pdfium_page.h"
|
||||
#include "pdf/pdfium/pdfium_print.h"
|
||||
#include "pdf/pdfium/pdfium_range.h"
|
||||
#include "printing/mojom/print.mojom-forward.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
#include "third_party/pdfium/public/fpdf_formfill.h"
|
||||
#include "third_party/pdfium/public/fpdf_progressive.h"
|
||||
@ -40,40 +43,121 @@
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/gfx/geometry/insets.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
#include "pdf/flatten_pdf_result.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom-forward.h"
|
||||
#endif
|
||||
|
||||
namespace blink {
|
||||
class WebInputEvent;
|
||||
class WebKeyboardEvent;
|
||||
class WebMouseEvent;
|
||||
class WebTouchEvent;
|
||||
struct WebPrintParams;
|
||||
} // namespace blink
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
enum class AccessibilityScrollAlignment;
|
||||
class PDFiumDocument;
|
||||
class PDFiumPermissions;
|
||||
class Thumbnail;
|
||||
enum class AccessibilityScrollAlignment;
|
||||
struct AccessibilityActionData;
|
||||
struct AccessibilityFocusInfo;
|
||||
struct AccessibilityHighlightInfo;
|
||||
struct AccessibilityImageInfo;
|
||||
struct AccessibilityLinkInfo;
|
||||
struct AccessibilityTextFieldInfo;
|
||||
struct AccessibilityTextRunInfo;
|
||||
struct DocumentAttachmentInfo;
|
||||
struct DocumentMetadata;
|
||||
struct PageCharacterIndex;
|
||||
|
||||
namespace draw_utils {
|
||||
class ShadowMatrix;
|
||||
} // namespace draw_utils
|
||||
|
||||
class PDFiumEngine : public PDFEngine,
|
||||
public DocumentLoader::Client,
|
||||
public IFSDK_PAUSE {
|
||||
enum class FontMappingMode {
|
||||
// Do not perform font mapping.
|
||||
kNoMapping,
|
||||
// Perform font mapping in renderer processes using Blink/content APIs.
|
||||
kBlink,
|
||||
};
|
||||
|
||||
enum class DocumentPermission {
|
||||
kCopy,
|
||||
kCopyAccessible,
|
||||
kPrintLowQuality,
|
||||
kPrintHighQuality,
|
||||
};
|
||||
|
||||
// Do one time initialization of the SDK.
|
||||
// If `enable_v8` is false, then PDFiumEngine will not be able to run
|
||||
// JavaScript.
|
||||
// When `use_skia` is true, the PDFiumEngine will use Skia renderer. Otherwise,
|
||||
// it will use AGG renderer.
|
||||
void InitializeSDK(bool enable_v8,
|
||||
bool use_skia,
|
||||
FontMappingMode font_mapping_mode);
|
||||
// Tells the SDK that we're shutting down.
|
||||
void ShutdownSDK();
|
||||
|
||||
using SendThumbnailCallback = base::OnceCallback<void(Thumbnail)>;
|
||||
|
||||
// This class implements a PDF rendering engine using the PDFium library.
|
||||
//
|
||||
// Many methods in this class are virtual to facilitate testing.
|
||||
class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
|
||||
public:
|
||||
// Maximum number of parameters a nameddest view can contain.
|
||||
static constexpr size_t kMaxViewParams = 4;
|
||||
|
||||
// State transition when tabbing forward:
|
||||
// None -> Document -> Page -> None (when focusable annotations on all pages
|
||||
// are done).
|
||||
// Exposed for testing.
|
||||
enum class FocusElementType { kNone, kDocument, kPage };
|
||||
|
||||
// Named destination in a document.
|
||||
struct NamedDestination {
|
||||
// 0-based page number.
|
||||
unsigned long page;
|
||||
|
||||
// View fit type (see table 8.2 "Destination syntax" on page 582 of PDF
|
||||
// Reference 1.7). Empty string if not present.
|
||||
std::string view;
|
||||
|
||||
// Number of parameters for the view.
|
||||
unsigned long num_params;
|
||||
|
||||
// Parameters for the view. Their meaning depends on the `view` and their
|
||||
// number is defined by `num_params` but is at most `kMaxViewParams`. Note:
|
||||
// If a parameter stands for the x/y coordinates, it should be transformed
|
||||
// into the corresponding in-screen coordinates before it's sent to the
|
||||
// viewport.
|
||||
float params[kMaxViewParams];
|
||||
|
||||
// A string of parameters for view fit type XYZ in the format of "x,y,zoom",
|
||||
// where x and y parameters are the in-screen coordinates and zoom is the
|
||||
// zoom level. If a parameter is "null", then current value of that
|
||||
// parameter in the viewport should be retained. Note: This string is empty
|
||||
// if the view's fit type is not XYZ.
|
||||
std::string xyz_params;
|
||||
};
|
||||
|
||||
// NOTE: `script_option` is ignored when PDF_ENABLE_V8 is not defined.
|
||||
PDFiumEngine(PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option);
|
||||
@ -93,107 +177,228 @@ class PDFiumEngine : public PDFEngine,
|
||||
bool HandleDocumentLoad(std::unique_ptr<UrlLoader> loader,
|
||||
const std::string& original_url);
|
||||
|
||||
// PDFEngine:
|
||||
void PageOffsetUpdated(const gfx::Vector2d& page_offset) override;
|
||||
void PluginSizeUpdated(const gfx::Size& size) override;
|
||||
void ScrolledToXPosition(int position) override;
|
||||
void ScrolledToYPosition(int position) override;
|
||||
void PrePaint() override;
|
||||
void Paint(const gfx::Rect& rect,
|
||||
SkBitmap& image_data,
|
||||
std::vector<gfx::Rect>& ready,
|
||||
std::vector<gfx::Rect>& pending) override;
|
||||
void PostPaint() override;
|
||||
bool HandleInputEvent(const blink::WebInputEvent& event) override;
|
||||
void PrintBegin() override;
|
||||
std::vector<uint8_t> PrintPages(
|
||||
// Most of these functions are similar to the Pepper functions of the same
|
||||
// name, so not repeating the description here unless it's different.
|
||||
virtual void PageOffsetUpdated(const gfx::Vector2d& page_offset);
|
||||
virtual void PluginSizeUpdated(const gfx::Size& size);
|
||||
virtual void ScrolledToXPosition(int position);
|
||||
virtual void ScrolledToYPosition(int position);
|
||||
// Paint is called a series of times. Before these n calls are made, PrePaint
|
||||
// is called once. After Paint is called n times, PostPaint is called once.
|
||||
void PrePaint();
|
||||
virtual void Paint(const gfx::Rect& rect,
|
||||
SkBitmap& image_data,
|
||||
std::vector<gfx::Rect>& ready,
|
||||
std::vector<gfx::Rect>& pending);
|
||||
void PostPaint();
|
||||
virtual bool HandleInputEvent(const blink::WebInputEvent& event);
|
||||
void PrintBegin();
|
||||
virtual std::vector<uint8_t> PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const blink::WebPrintParams& print_params) override;
|
||||
void PrintEnd() override;
|
||||
void StartFind(const std::u16string& text, bool case_sensitive) override;
|
||||
bool SelectFindResult(bool forward) override;
|
||||
void StopFind() override;
|
||||
void ZoomUpdated(double new_zoom_level) override;
|
||||
void RotateClockwise() override;
|
||||
void RotateCounterclockwise() override;
|
||||
bool IsReadOnly() const override;
|
||||
void SetReadOnly(bool enable) override;
|
||||
void SetDocumentLayout(DocumentLayout::PageSpread page_spread) override;
|
||||
void DisplayAnnotations(bool display) override;
|
||||
gfx::Size ApplyDocumentLayout(
|
||||
const DocumentLayout::Options& options) override;
|
||||
std::string GetSelectedText() override;
|
||||
bool CanEditText() const override;
|
||||
bool HasEditableText() const override;
|
||||
void ReplaceSelection(const std::string& text) override;
|
||||
bool CanUndo() const override;
|
||||
bool CanRedo() const override;
|
||||
void Undo() override;
|
||||
void Redo() override;
|
||||
void HandleAccessibilityAction(
|
||||
const AccessibilityActionData& action_data) override;
|
||||
std::string GetLinkAtPosition(const gfx::Point& point) override;
|
||||
bool HasPermission(DocumentPermission permission) const override;
|
||||
void SelectAll() override;
|
||||
const std::vector<DocumentAttachmentInfo>& GetDocumentAttachmentInfoList()
|
||||
const override;
|
||||
std::vector<uint8_t> GetAttachmentData(size_t index) override;
|
||||
const DocumentMetadata& GetDocumentMetadata() const override;
|
||||
int GetNumberOfPages() const override;
|
||||
base::Value::List GetBookmarks() override;
|
||||
std::optional<PDFEngine::NamedDestination> GetNamedDestination(
|
||||
const std::string& destination) override;
|
||||
int GetMostVisiblePage() override;
|
||||
bool IsPageVisible(int index) const override;
|
||||
PageOrientation GetCurrentOrientation() const override;
|
||||
gfx::Rect GetPageBoundsRect(int index) override;
|
||||
gfx::Rect GetPageContentsRect(int index) override;
|
||||
gfx::Rect GetPageScreenRect(int page_index) const override;
|
||||
gfx::RectF GetPageBoundingBox(int page_index) override;
|
||||
void SetGrayscale(bool grayscale) override;
|
||||
int GetCharCount(int page_index) override;
|
||||
gfx::RectF GetCharBounds(int page_index, int char_index) override;
|
||||
uint32_t GetCharUnicode(int page_index, int char_index) override;
|
||||
std::optional<AccessibilityTextRunInfo> GetTextRunInfo(
|
||||
int page_index,
|
||||
int start_char_index) override;
|
||||
const blink::WebPrintParams& print_params);
|
||||
void PrintEnd();
|
||||
void StartFind(const std::u16string& text, bool case_sensitive);
|
||||
bool SelectFindResult(bool forward);
|
||||
void StopFind();
|
||||
virtual void ZoomUpdated(double new_zoom_level);
|
||||
void RotateClockwise();
|
||||
void RotateCounterclockwise();
|
||||
bool IsReadOnly() const;
|
||||
void SetReadOnly(bool enable);
|
||||
void SetDocumentLayout(DocumentLayout::PageSpread page_spread);
|
||||
void DisplayAnnotations(bool display);
|
||||
|
||||
// Applies the document layout options proposed by a call to
|
||||
// PDFiumEngineClient::ProposeDocumentLayout(), returning the overall size of
|
||||
// the new effective layout.
|
||||
virtual gfx::Size ApplyDocumentLayout(const DocumentLayout::Options& options);
|
||||
|
||||
std::string GetSelectedText();
|
||||
// Returns true if focus is within an editable form text area.
|
||||
virtual bool CanEditText() const;
|
||||
|
||||
// Returns true if focus is within an editable form text area and the text
|
||||
// area has text.
|
||||
bool HasEditableText() const;
|
||||
|
||||
// Replace selected text within an editable form text area with another
|
||||
// string. If there is no selected text, append the replacement text after the
|
||||
// current caret position.
|
||||
void ReplaceSelection(const std::string& text);
|
||||
|
||||
// Methods to check if undo/redo is possible, and to perform them.
|
||||
bool CanUndo() const;
|
||||
bool CanRedo() const;
|
||||
void Undo();
|
||||
void Redo();
|
||||
|
||||
// Handles actions invoked by Accessibility clients.
|
||||
void HandleAccessibilityAction(const AccessibilityActionData& action_data);
|
||||
|
||||
std::string GetLinkAtPosition(const gfx::Point& point);
|
||||
|
||||
// Checks the permissions associated with this document.
|
||||
virtual bool HasPermission(DocumentPermission permission) const;
|
||||
|
||||
virtual void SelectAll();
|
||||
|
||||
// Gets the list of DocumentAttachmentInfo from the document.
|
||||
virtual const std::vector<DocumentAttachmentInfo>&
|
||||
GetDocumentAttachmentInfoList() const;
|
||||
|
||||
// Gets the content of an attachment by the attachment's `index`. `index`
|
||||
// must be in the range of [0, attachment_count-1), where `attachment_count`
|
||||
// is the number of attachments embedded in the document.
|
||||
// The caller of this method is responsible for checking whether the
|
||||
// attachment is readable, attachment size is not 0 byte, and the return
|
||||
// value's size matches the corresponding DocumentAttachmentInfo's
|
||||
// `size_bytes`.
|
||||
std::vector<uint8_t> GetAttachmentData(size_t index);
|
||||
|
||||
// Gets metadata about the document.
|
||||
virtual const DocumentMetadata& GetDocumentMetadata() const;
|
||||
|
||||
// Gets the number of pages in the document.
|
||||
virtual int GetNumberOfPages() const;
|
||||
|
||||
// Returns a list of Values of Bookmarks. Each Bookmark is a dictionary Value
|
||||
// which contains the following key/values:
|
||||
// - "title" - a string Value.
|
||||
// - "page" - an int Value.
|
||||
// - "children" - a list of Values, with each entry containing
|
||||
// a dictionary Value of the same structure.
|
||||
virtual base::Value::List GetBookmarks();
|
||||
|
||||
// Gets the named destination by name.
|
||||
std::optional<NamedDestination> GetNamedDestination(
|
||||
const std::string& destination);
|
||||
|
||||
// Gets the index of the most visible page, or -1 if none are visible.
|
||||
int GetMostVisiblePage();
|
||||
|
||||
// Returns whether the page at `index` is visible or not.
|
||||
virtual bool IsPageVisible(int index) const;
|
||||
|
||||
// Gets the current layout orientation.
|
||||
PageOrientation GetCurrentOrientation() const;
|
||||
|
||||
// Gets the rectangle of the page not including the shadow.
|
||||
gfx::Rect GetPageBoundsRect(int index);
|
||||
|
||||
// Gets the rectangle of the page excluding any additional areas.
|
||||
virtual gfx::Rect GetPageContentsRect(int index);
|
||||
|
||||
// Returns a page's rect in screen coordinates, as well as its surrounding
|
||||
// border areas and bottom separator.
|
||||
virtual gfx::Rect GetPageScreenRect(int page_index) const;
|
||||
|
||||
// Return a page's bounding box rectangle, or an empty rectangle if
|
||||
// `page_index` is invalid.
|
||||
gfx::RectF GetPageBoundingBox(int page_index);
|
||||
|
||||
// Set color / grayscale rendering modes.
|
||||
virtual void SetGrayscale(bool grayscale);
|
||||
|
||||
// Get the number of characters on a given page.
|
||||
int GetCharCount(int page_index);
|
||||
|
||||
// Get the bounds in page pixels of a character on a given page.
|
||||
gfx::RectF GetCharBounds(int page_index, int char_index);
|
||||
|
||||
// Get a given unicode character on a given page.
|
||||
uint32_t GetCharUnicode(int page_index, int char_index);
|
||||
|
||||
// Given a start char index, find the longest continuous run of text that's
|
||||
// in a single direction and with the same text style. Return a filled out
|
||||
// AccessibilityTextRunInfo on success or std::nullopt on failure. e.g. When
|
||||
// `start_char_index` is out of bounds.
|
||||
std::optional<AccessibilityTextRunInfo> GetTextRunInfo(int page_index,
|
||||
int start_char_index);
|
||||
|
||||
// For all the links on page `page_index`, get their urls, underlying text
|
||||
// ranges and bounding boxes.
|
||||
std::vector<AccessibilityLinkInfo> GetLinkInfo(
|
||||
int page_index,
|
||||
const std::vector<AccessibilityTextRunInfo>& text_runs) override;
|
||||
std::vector<AccessibilityImageInfo> GetImageInfo(
|
||||
int page_index,
|
||||
uint32_t text_run_count) override;
|
||||
SkBitmap GetImageForOcr(int page_index, int image_index) override;
|
||||
const std::vector<AccessibilityTextRunInfo>& text_runs);
|
||||
|
||||
// For all the images in page `page_index`, get their alt texts and bounding
|
||||
// boxes. If the alt text is empty or unavailable, and if the user has
|
||||
// requested that the OCR service tag the PDF so that it is made accessible,
|
||||
// transfer the raw image pixels in the `image_data` field. Otherwise do not
|
||||
// populate the `image_data` field.
|
||||
std::vector<AccessibilityImageInfo> GetImageInfo(int page_index,
|
||||
uint32_t text_run_count);
|
||||
|
||||
// Returns the image as a 32-bit bitmap format for OCR.
|
||||
SkBitmap GetImageForOcr(int page_index, int image_index);
|
||||
|
||||
// For all the highlights in page `page_index`, get their underlying text
|
||||
// ranges and bounding boxes.
|
||||
std::vector<AccessibilityHighlightInfo> GetHighlightInfo(
|
||||
int page_index,
|
||||
const std::vector<AccessibilityTextRunInfo>& text_runs) override;
|
||||
const std::vector<AccessibilityTextRunInfo>& text_runs);
|
||||
|
||||
// For all the text fields in page `page_index`, get their properties like
|
||||
// name, value, bounding boxes etc.
|
||||
std::vector<AccessibilityTextFieldInfo> GetTextFieldInfo(
|
||||
int page_index,
|
||||
uint32_t text_run_count) override;
|
||||
bool GetPrintScaling() override;
|
||||
int GetCopiesToPrint() override;
|
||||
printing::mojom::DuplexMode GetDuplexMode() override;
|
||||
std::optional<gfx::Size> GetUniformPageSizePoints() override;
|
||||
void AppendBlankPages(size_t num_pages) override;
|
||||
void AppendPage(PDFEngine* engine, int index) override;
|
||||
std::vector<uint8_t> GetSaveData() override;
|
||||
void SetCaretPosition(const gfx::Point& position) override;
|
||||
void MoveRangeSelectionExtent(const gfx::Point& extent) override;
|
||||
void SetSelectionBounds(const gfx::Point& base,
|
||||
const gfx::Point& extent) override;
|
||||
uint32_t text_run_count);
|
||||
|
||||
// Gets the PDF document's print scaling preference. True if the document can
|
||||
// be scaled to fit.
|
||||
bool GetPrintScaling();
|
||||
|
||||
// Returns number of copies to be printed.
|
||||
int GetCopiesToPrint();
|
||||
|
||||
// Returns the duplex setting.
|
||||
printing::mojom::DuplexMode GetDuplexMode();
|
||||
|
||||
// Returns the uniform page size of the document in points. Returns
|
||||
// `std::nullopt` if the document has more than one page size.
|
||||
virtual std::optional<gfx::Size> GetUniformPageSizePoints();
|
||||
|
||||
// Append blank pages to make a 1-page document to a `num_pages` document.
|
||||
// Always retain the first page data.
|
||||
void AppendBlankPages(size_t num_pages);
|
||||
|
||||
// Append the first page of the document loaded with the `engine` to this
|
||||
// document at page `index`.
|
||||
void AppendPage(PDFiumEngine* engine, int index);
|
||||
|
||||
virtual std::vector<uint8_t> GetSaveData();
|
||||
|
||||
virtual void SetCaretPosition(const gfx::Point& position);
|
||||
|
||||
void MoveRangeSelectionExtent(const gfx::Point& extent);
|
||||
|
||||
void SetSelectionBounds(const gfx::Point& base, const gfx::Point& extent);
|
||||
|
||||
void GetSelection(uint32_t* selection_start_page_index,
|
||||
uint32_t* selection_start_char_index,
|
||||
uint32_t* selection_end_page_index,
|
||||
uint32_t* selection_end_char_index) override;
|
||||
void KillFormFocus() override;
|
||||
void UpdateFocus(bool has_focus) override;
|
||||
AccessibilityFocusInfo GetFocusInfo() override;
|
||||
bool IsPDFDocTagged() override;
|
||||
uint32_t GetLoadedByteSize() override;
|
||||
bool ReadLoadedBytes(uint32_t length, void* buffer) override;
|
||||
uint32_t* selection_end_char_index);
|
||||
|
||||
// Remove focus from form widgets, consolidating the user input.
|
||||
void KillFormFocus();
|
||||
|
||||
// Notify whether the PDF currently has the focus or not.
|
||||
void UpdateFocus(bool has_focus);
|
||||
|
||||
// Returns the focus info of current focus item.
|
||||
AccessibilityFocusInfo GetFocusInfo();
|
||||
|
||||
bool IsPDFDocTagged();
|
||||
|
||||
virtual uint32_t GetLoadedByteSize();
|
||||
|
||||
virtual bool ReadLoadedBytes(uint32_t length, void* buffer);
|
||||
|
||||
// Requests for a thumbnail to be sent using a callback when the page is ready
|
||||
// to be rendered. `send_callback` is run with the thumbnail data when ready.
|
||||
void RequestThumbnail(int page_index,
|
||||
float device_pixel_ratio,
|
||||
SendThumbnailCallback send_callback) override;
|
||||
SendThumbnailCallback send_callback);
|
||||
|
||||
// DocumentLoader::Client:
|
||||
std::unique_ptr<URLLoaderWrapper> CreateURLLoader() override;
|
||||
|
@ -43,7 +43,7 @@ class PDFiumEngineClient {
|
||||
virtual ~PDFiumEngineClient() = default;
|
||||
|
||||
// Proposes a document layout to the client. For the proposed layout to
|
||||
// become effective, the client must call PDFEngine::ApplyDocumentLayout()
|
||||
// become effective, the client must call PDFiumEngine::ApplyDocumentLayout()
|
||||
// with the new layout options (although this call can be asynchronous).
|
||||
virtual void ProposeDocumentLayout(const DocumentLayout& layout) = 0;
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/span.h"
|
||||
#include "base/values.h"
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "base/path_service.h"
|
||||
#include "base/test/mock_callback.h"
|
||||
#include "pdf/pdf.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
|
@ -518,7 +518,7 @@ TEST_P(PDFiumEngineTest, GetNamedDestination) {
|
||||
ASSERT_EQ(2, engine->GetNumberOfPages());
|
||||
|
||||
// A destination with a valid page object
|
||||
std::optional<PDFEngine::NamedDestination> valid_page_obj =
|
||||
std::optional<PDFiumEngine::NamedDestination> valid_page_obj =
|
||||
engine->GetNamedDestination("ValidPageObj");
|
||||
ASSERT_TRUE(valid_page_obj.has_value());
|
||||
EXPECT_EQ(0u, valid_page_obj->page);
|
||||
@ -527,18 +527,18 @@ TEST_P(PDFiumEngineTest, GetNamedDestination) {
|
||||
EXPECT_EQ(1.2f, valid_page_obj->params[2]);
|
||||
|
||||
// A destination with an invalid page object
|
||||
std::optional<PDFEngine::NamedDestination> invalid_page_obj =
|
||||
std::optional<PDFiumEngine::NamedDestination> invalid_page_obj =
|
||||
engine->GetNamedDestination("InvalidPageObj");
|
||||
ASSERT_FALSE(invalid_page_obj.has_value());
|
||||
|
||||
// A destination with a valid page number
|
||||
std::optional<PDFEngine::NamedDestination> valid_page_number =
|
||||
std::optional<PDFiumEngine::NamedDestination> valid_page_number =
|
||||
engine->GetNamedDestination("ValidPageNumber");
|
||||
ASSERT_TRUE(valid_page_number.has_value());
|
||||
EXPECT_EQ(1u, valid_page_number->page);
|
||||
|
||||
// A destination with an out-of-range page number
|
||||
std::optional<PDFEngine::NamedDestination> invalid_page_number =
|
||||
std::optional<PDFiumEngine::NamedDestination> invalid_page_number =
|
||||
engine->GetNamedDestination("OutOfRangePageNumber");
|
||||
EXPECT_FALSE(invalid_page_number.has_value());
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include "base/containers/heap_array.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdf_features.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/pdfium/public/fpdf_sysfontinfo.h"
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "base/gtest_prod_util.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "pdf/page_orientation.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/ui/thumbnail.h"
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
#include "third_party/pdfium/public/fpdf_doc.h"
|
||||
@ -70,7 +69,7 @@ class PDFiumPage {
|
||||
// Returns FPDF_TEXTPAGE for the page, loading and parsing it if necessary.
|
||||
FPDF_TEXTPAGE GetTextPage();
|
||||
|
||||
// See definition of PDFEngine::GetTextRunInfo().
|
||||
// See definition of PDFiumEngine::GetTextRunInfo().
|
||||
std::optional<AccessibilityTextRunInfo> GetTextRunInfo(int start_char_index);
|
||||
|
||||
// Get a unicode character from the page.
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "third_party/pdfium/public/fpdfview.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/numerics/angle_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
|
||||
#include "pdf/pdfium/pdfium_ocr.h"
|
||||
#include "pdf/pdfium/pdfium_searchify_font.h"
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "base/time/time.h"
|
||||
#include "pdf/document_layout.h"
|
||||
#include "pdf/loader/url_loader.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/test/test_helpers.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
|
@ -9,11 +9,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_client.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
class PDFiumEngine;
|
||||
|
||||
class TestClient : public PDFiumEngineClient {
|
||||
public:
|
||||
TestClient();
|
||||
@ -23,8 +24,8 @@ class TestClient : public PDFiumEngineClient {
|
||||
|
||||
~TestClient() override;
|
||||
|
||||
PDFEngine* engine() const { return engine_; }
|
||||
void set_engine(PDFEngine* engine) { engine_ = engine; }
|
||||
PDFiumEngine* engine() const { return engine_; }
|
||||
void set_engine(PDFiumEngine* engine) { engine_ = engine; }
|
||||
|
||||
// PDFiumEngineClient:
|
||||
void ProposeDocumentLayout(const DocumentLayout& layout) override;
|
||||
@ -46,7 +47,7 @@ class TestClient : public PDFiumEngineClient {
|
||||
private:
|
||||
// Not owned. Expected to dangle briefly, as the engine usually is destroyed
|
||||
// before the client.
|
||||
raw_ptr<PDFEngine, DisableDanglingPtrDetection> engine_ = nullptr;
|
||||
raw_ptr<PDFiumEngine, DisableDanglingPtrDetection> engine_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "base/values.h"
|
||||
#include "pdf/document_attachment_info.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_form_filler.h"
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "base/values.h"
|
||||
#include "pdf/document_attachment_info.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
|
||||
|
Reference in New Issue
Block a user