Rename PDFEngine::Client to PDFiumEngineClient
Take a step towards removing PDFEngine by first moving PDFEngine::Client out. Since pdfium_engine.h is quite big as-is, split PDFiumEngineClient into its own header file. Bug: 40128715 Low-Coverage-Reason: TRIVIAL_CHANGE just moving code around Change-Id: I3d2830e49a2ca5ceda3c7b921b155ae071f7f7eb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5714799 Reviewed-by: Alan Screen <awscreen@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1329699}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9de720cb96
commit
cc902e266f
@ -119,6 +119,7 @@ if (enable_pdf) {
|
||||
"pdfium/pdfium_document_metadata.h",
|
||||
"pdfium/pdfium_engine.cc",
|
||||
"pdfium/pdfium_engine.h",
|
||||
"pdfium/pdfium_engine_client.h",
|
||||
"pdfium/pdfium_engine_exports.cc",
|
||||
"pdfium/pdfium_engine_exports.h",
|
||||
"pdfium/pdfium_form_filler.cc",
|
||||
|
179
pdf/pdf_engine.h
179
pdf/pdf_engine.h
@ -20,13 +20,9 @@
|
||||
#include "pdf/document_layout.h"
|
||||
#include "printing/mojom/print.mojom-forward.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h"
|
||||
#include "ui/base/window_open_disposition.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "v8/include/v8-forward.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include <windows.h>
|
||||
@ -49,7 +45,6 @@ struct WebPrintParams;
|
||||
|
||||
namespace gfx {
|
||||
class Point;
|
||||
class Rect;
|
||||
class Size;
|
||||
class SizeF;
|
||||
class Vector2d;
|
||||
@ -58,7 +53,6 @@ class Vector2d;
|
||||
namespace chrome_pdf {
|
||||
|
||||
class Thumbnail;
|
||||
class UrlLoader;
|
||||
struct AccessibilityActionData;
|
||||
struct AccessibilityFocusInfo;
|
||||
struct AccessibilityLinkInfo;
|
||||
@ -106,15 +100,6 @@ class PDFEngine {
|
||||
// Maximum number of parameters a nameddest view can contain.
|
||||
static constexpr size_t kMaxViewParams = 4;
|
||||
|
||||
enum class FocusFieldType {
|
||||
// Focus is not on any form field.
|
||||
kNoFocus,
|
||||
// Focus is on a form text field or form combobox text field.
|
||||
kText,
|
||||
// Focus is on a non-text field.
|
||||
kNonText,
|
||||
};
|
||||
|
||||
// Named destination in a document.
|
||||
struct NamedDestination {
|
||||
// 0-based page number.
|
||||
@ -142,168 +127,6 @@ class PDFEngine {
|
||||
std::string xyz_params;
|
||||
};
|
||||
|
||||
// The interface that's provided to the rendering engine.
|
||||
class Client {
|
||||
public:
|
||||
virtual ~Client() = default;
|
||||
|
||||
// Proposes a document layout to the client. For the proposed layout to
|
||||
// become effective, the client must call PDFEngine::ApplyDocumentLayout()
|
||||
// with the new layout options (although this call can be asynchronous).
|
||||
virtual void ProposeDocumentLayout(const DocumentLayout& layout) = 0;
|
||||
|
||||
// Informs the client that the given rect needs to be repainted.
|
||||
virtual void Invalidate(const gfx::Rect& rect) {}
|
||||
|
||||
// Informs the client to scroll the plugin area by the given offset.
|
||||
virtual void DidScroll(const gfx::Vector2d& offset) {}
|
||||
|
||||
// Scroll the horizontal/vertical scrollbars to a given position.
|
||||
// Values are in screen coordinates, where 0 is the top/left of the document
|
||||
// and a positive value is the distance in pixels from that line.
|
||||
virtual void ScrollToX(int x_screen_coords) {}
|
||||
virtual void ScrollToY(int y_screen_coords) {}
|
||||
|
||||
// Scroll by a given delta relative to the current position.
|
||||
virtual void ScrollBy(const gfx::Vector2d& delta) {}
|
||||
|
||||
// Scroll to zero-based `page`.
|
||||
virtual void ScrollToPage(int page) {}
|
||||
|
||||
// Navigate to the given url.
|
||||
virtual void NavigateTo(const std::string& url,
|
||||
WindowOpenDisposition disposition) {}
|
||||
|
||||
// Navigate to the given destination. Zero-based `page` index. `x`, `y` and
|
||||
// `zoom` are optional and can be nullptr.
|
||||
virtual void NavigateToDestination(int page,
|
||||
const float* x,
|
||||
const float* y,
|
||||
const float* zoom) {}
|
||||
|
||||
// Updates the cursor.
|
||||
virtual void UpdateCursor(ui::mojom::CursorType new_cursor_type) {}
|
||||
|
||||
// Updates the tick marks in the vertical scrollbar.
|
||||
virtual void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) {}
|
||||
|
||||
// Updates the number of find results for the current search term. If
|
||||
// there are no matches 0 should be passed in. Only when the plugin has
|
||||
// finished searching should it pass in the final count with `final_result`
|
||||
// set to true.
|
||||
virtual void NotifyNumberOfFindResultsChanged(int total,
|
||||
bool final_result) {}
|
||||
|
||||
// Updates the index of the currently selected search item. Set
|
||||
// `final_result` to true only when there is no subsequent
|
||||
// `NotifyNumberOfFindResultsChanged()` call.
|
||||
virtual void NotifySelectedFindResultChanged(int current_find_index,
|
||||
bool final_result) {}
|
||||
|
||||
virtual void NotifyTouchSelectionOccurred() {}
|
||||
|
||||
// Prompts the user for a password to open this document. The callback is
|
||||
// called when the password is retrieved.
|
||||
virtual void GetDocumentPassword(
|
||||
base::OnceCallback<void(const std::string&)> callback) {}
|
||||
|
||||
// Play a "beeping" sound.
|
||||
virtual void Beep() {}
|
||||
|
||||
// Puts up an alert with the given message.
|
||||
virtual void Alert(const std::string& message) {}
|
||||
|
||||
// Puts up a confirm with the given message, and returns true if the user
|
||||
// presses OK, or false if they press cancel.
|
||||
virtual bool Confirm(const std::string& message) = 0;
|
||||
|
||||
// Puts up a prompt with the given message and default answer and returns
|
||||
// the answer.
|
||||
virtual std::string Prompt(const std::string& question,
|
||||
const std::string& default_answer) = 0;
|
||||
|
||||
// Returns the url of the pdf.
|
||||
virtual std::string GetURL() = 0;
|
||||
|
||||
// Send an email.
|
||||
virtual void Email(const std::string& to,
|
||||
const std::string& cc,
|
||||
const std::string& bcc,
|
||||
const std::string& subject,
|
||||
const std::string& body) {}
|
||||
|
||||
// Put up the print dialog.
|
||||
virtual void Print() {}
|
||||
|
||||
// Submit the data using HTTP POST.
|
||||
virtual void SubmitForm(const std::string& url,
|
||||
const void* data,
|
||||
int length) {}
|
||||
|
||||
// Creates and returns new URL loader for partial document requests.
|
||||
virtual std::unique_ptr<UrlLoader> CreateUrlLoader() = 0;
|
||||
|
||||
// Returns the current V8 isolate, if any.
|
||||
virtual v8::Isolate* GetIsolate() = 0;
|
||||
|
||||
// Searches the given string for "term" and returns the results. Unicode-
|
||||
// aware.
|
||||
struct SearchStringResult {
|
||||
int start_index;
|
||||
int length;
|
||||
};
|
||||
virtual std::vector<SearchStringResult> SearchString(
|
||||
const char16_t* string,
|
||||
const char16_t* term,
|
||||
bool case_sensitive) = 0;
|
||||
|
||||
// Notifies the client that the document has finished loading.
|
||||
virtual void DocumentLoadComplete() {}
|
||||
|
||||
// Notifies the client that the document has failed to load.
|
||||
virtual void DocumentLoadFailed() {}
|
||||
|
||||
// Notifies that an unsupported feature in the PDF was encountered.
|
||||
virtual void DocumentHasUnsupportedFeature(const std::string& feature) {}
|
||||
|
||||
// Notifies the client about document load progress.
|
||||
virtual void DocumentLoadProgress(uint32_t available, uint32_t doc_size) {}
|
||||
|
||||
// Notifies the client about focus changes for form fields.
|
||||
virtual void FormFieldFocusChange(FocusFieldType type) {}
|
||||
|
||||
// Returns true if the plugin has been opened within print preview.
|
||||
virtual bool IsPrintPreview() const = 0;
|
||||
|
||||
// Get the background color of the PDF.
|
||||
virtual SkColor GetBackgroundColor() const = 0;
|
||||
|
||||
// Sets selection status.
|
||||
virtual void SelectionChanged(const gfx::Rect& left,
|
||||
const gfx::Rect& right) {}
|
||||
|
||||
// The caret position in the editable form (if applicable) changed.
|
||||
virtual void CaretChanged(const gfx::Rect& caret_rect) {}
|
||||
|
||||
// Notifies the client that the PDF has been edited.
|
||||
virtual void EnteredEditMode() {}
|
||||
|
||||
// Notifies the client about focus changes for the document.
|
||||
virtual void DocumentFocusChanged(bool document_has_focus) {}
|
||||
|
||||
// Sets selected text.
|
||||
virtual void SetSelectedText(const std::string& selected_text) = 0;
|
||||
|
||||
// Sets the link under cursor.
|
||||
virtual void SetLinkUnderCursor(const std::string& link_under_cursor) = 0;
|
||||
|
||||
// If the link cannot be converted to JS payload struct, then it is not
|
||||
// possible to pass it to JS. In this case, ignore the link like other PDF
|
||||
// viewers.
|
||||
// See https://crbug.com/312882 for an example.
|
||||
virtual bool IsValidLink(const std::string& url) = 0;
|
||||
};
|
||||
|
||||
virtual ~PDFEngine() = default;
|
||||
|
||||
// Most of these functions are similar to the Pepper functions of the same
|
||||
@ -338,7 +161,7 @@ class PDFEngine {
|
||||
virtual void DisplayAnnotations(bool display) = 0;
|
||||
|
||||
// Applies the document layout options proposed by a call to
|
||||
// PDFEngine::Client::ProposeDocumentLayout(), returning the overall size of
|
||||
// PDFiumEngineClient::ProposeDocumentLayout(), returning the overall size of
|
||||
// the new effective layout.
|
||||
virtual gfx::Size ApplyDocumentLayout(
|
||||
const DocumentLayout::Options& options) = 0;
|
||||
|
@ -285,7 +285,7 @@ std::unique_ptr<PdfInkModule> MaybeCreatePdfInkModule(
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<PDFiumEngine> PdfViewWebPlugin::Client::CreateEngine(
|
||||
PDFEngine::Client* client,
|
||||
PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option) {
|
||||
return std::make_unique<PDFiumEngine>(client, script_option);
|
||||
}
|
||||
@ -1121,7 +1121,7 @@ v8::Isolate* PdfViewWebPlugin::GetIsolate() {
|
||||
return client_->GetIsolate();
|
||||
}
|
||||
|
||||
std::vector<PDFEngine::Client::SearchStringResult>
|
||||
std::vector<PDFiumEngineClient::SearchStringResult>
|
||||
PdfViewWebPlugin::SearchString(const char16_t* string,
|
||||
const char16_t* term,
|
||||
bool case_sensitive) {
|
||||
@ -1142,7 +1142,7 @@ void PdfViewWebPlugin::DocumentLoadComplete() {
|
||||
client_->RecordComputedAction("PDF.LoadSuccess");
|
||||
|
||||
// Clear the focus state for on-screen keyboards.
|
||||
FormFieldFocusChange(PDFEngine::FocusFieldType::kNoFocus);
|
||||
FormFieldFocusChange(PDFiumEngineClient::FocusFieldType::kNoFocus);
|
||||
|
||||
if (IsPrintPreview()) {
|
||||
// Scroll location is retained across document loads in Print Preview, so
|
||||
@ -1232,13 +1232,14 @@ void PdfViewWebPlugin::DocumentLoadProgress(uint32_t available,
|
||||
SendLoadingProgress(progress);
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::FormFieldFocusChange(PDFEngine::FocusFieldType type) {
|
||||
void PdfViewWebPlugin::FormFieldFocusChange(
|
||||
PDFiumEngineClient::FocusFieldType type) {
|
||||
base::Value::Dict message;
|
||||
message.Set("type", "formFocusChange");
|
||||
message.Set("focused", type != PDFEngine::FocusFieldType::kNoFocus);
|
||||
message.Set("focused", type != PDFiumEngineClient::FocusFieldType::kNoFocus);
|
||||
client_->PostMessage(std::move(message));
|
||||
|
||||
text_input_type_ = type == PDFEngine::FocusFieldType::kText
|
||||
text_input_type_ = type == PDFiumEngineClient::FocusFieldType::kText
|
||||
? blink::WebTextInputType::kWebTextInputTypeText
|
||||
: blink::WebTextInputType::kWebTextInputTypeNone;
|
||||
client_->UpdateTextInputState();
|
||||
|
@ -30,6 +30,7 @@
|
||||
#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"
|
||||
#include "pdf/preview_mode_client.h"
|
||||
@ -81,7 +82,7 @@ class PDFiumEngine;
|
||||
class PdfAccessibilityDataHandler;
|
||||
class Thumbnail;
|
||||
|
||||
class PdfViewWebPlugin final : public PDFEngine::Client,
|
||||
class PdfViewWebPlugin final : public PDFiumEngineClient,
|
||||
public blink::WebPlugin,
|
||||
public pdf::mojom::PdfListener,
|
||||
public UrlLoader::Client,
|
||||
@ -120,7 +121,7 @@ class PdfViewWebPlugin final : public PDFEngine::Client,
|
||||
|
||||
// Creates a new `PDFiumEngine`.
|
||||
virtual std::unique_ptr<PDFiumEngine> CreateEngine(
|
||||
PDFEngine::Client* client,
|
||||
PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option);
|
||||
|
||||
// Passes the plugin container to the client. This is first called in
|
||||
@ -305,7 +306,7 @@ class PdfViewWebPlugin final : public PDFEngine::Client,
|
||||
int relative_cursor_pos) override;
|
||||
void ImeFinishComposingTextForPlugin(bool keep_selection) override;
|
||||
|
||||
// PDFEngine::Client:
|
||||
// PDFiumEngineClient:
|
||||
void ProposeDocumentLayout(const DocumentLayout& layout) override;
|
||||
void Invalidate(const gfx::Rect& rect) override;
|
||||
void DidScroll(const gfx::Vector2d& offset) override;
|
||||
@ -351,7 +352,7 @@ class PdfViewWebPlugin final : public PDFEngine::Client,
|
||||
void DocumentLoadFailed() override;
|
||||
void DocumentHasUnsupportedFeature(const std::string& feature) override;
|
||||
void DocumentLoadProgress(uint32_t available, uint32_t doc_size) override;
|
||||
void FormFieldFocusChange(PDFEngine::FocusFieldType type) override;
|
||||
void FormFieldFocusChange(PDFiumEngineClient::FocusFieldType type) override;
|
||||
bool IsPrintPreview() const override;
|
||||
SkColor GetBackgroundColor() const override;
|
||||
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
|
||||
|
@ -132,8 +132,8 @@ struct PaintParams {
|
||||
};
|
||||
|
||||
MATCHER(SearchStringResultEq, "") {
|
||||
PDFEngine::Client::SearchStringResult l = std::get<0>(arg);
|
||||
PDFEngine::Client::SearchStringResult r = std::get<1>(arg);
|
||||
PDFiumEngineClient::SearchStringResult l = std::get<0>(arg);
|
||||
PDFiumEngineClient::SearchStringResult r = std::get<1>(arg);
|
||||
return l.start_index == r.start_index && l.length == r.length;
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ class FakePdfViewWebPluginClient : public PdfViewWebPlugin::Client {
|
||||
|
||||
MOCK_METHOD(std::unique_ptr<PDFiumEngine>,
|
||||
CreateEngine,
|
||||
(PDFEngine::Client*, PDFiumFormFiller::ScriptOption),
|
||||
(PDFiumEngineClient*, PDFiumFormFiller::ScriptOption),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void,
|
||||
@ -367,7 +367,7 @@ class PdfViewWebPluginWithoutInitializeTest
|
||||
});
|
||||
ON_CALL(*client_ptr_, CreateEngine)
|
||||
.WillByDefault([this](
|
||||
PDFEngine::Client* client,
|
||||
PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption /*script_option*/) {
|
||||
auto engine = std::make_unique<NiceMock<TestPDFiumEngine>>(client);
|
||||
engine_ptr_ = engine.get();
|
||||
@ -1605,16 +1605,16 @@ TEST_F(PdfViewWebPluginTest, FormTextFieldFocusChangeUpdatesTextInputType) {
|
||||
plugin_->GetPluginTextInputType());
|
||||
|
||||
ExpectUpdateTextInputState(blink::WebTextInputType::kWebTextInputTypeText);
|
||||
plugin_->FormFieldFocusChange(PDFEngine::FocusFieldType::kText);
|
||||
plugin_->FormFieldFocusChange(PDFiumEngineClient::FocusFieldType::kText);
|
||||
|
||||
ExpectUpdateTextInputState(blink::WebTextInputType::kWebTextInputTypeNone);
|
||||
plugin_->FormFieldFocusChange(PDFEngine::FocusFieldType::kNoFocus);
|
||||
plugin_->FormFieldFocusChange(PDFiumEngineClient::FocusFieldType::kNoFocus);
|
||||
|
||||
ExpectUpdateTextInputState(blink::WebTextInputType::kWebTextInputTypeText);
|
||||
plugin_->FormFieldFocusChange(PDFEngine::FocusFieldType::kText);
|
||||
plugin_->FormFieldFocusChange(PDFiumEngineClient::FocusFieldType::kText);
|
||||
|
||||
ExpectUpdateTextInputState(blink::WebTextInputType::kWebTextInputTypeNone);
|
||||
plugin_->FormFieldFocusChange(PDFEngine::FocusFieldType::kNonText);
|
||||
plugin_->FormFieldFocusChange(PDFiumEngineClient::FocusFieldType::kNonText);
|
||||
}
|
||||
|
||||
TEST_F(PdfViewWebPluginTest, SearchString) {
|
||||
@ -1623,14 +1623,14 @@ TEST_F(PdfViewWebPluginTest, SearchString) {
|
||||
u"The quick brown fox jumped over the lazy Fox";
|
||||
|
||||
{
|
||||
static constexpr PDFEngine::Client::SearchStringResult kExpectation[] = {
|
||||
static constexpr PDFiumEngineClient::SearchStringResult kExpectation[] = {
|
||||
{16, 3}};
|
||||
EXPECT_THAT(
|
||||
plugin_->SearchString(kTarget, kPattern, /*case_sensitive=*/true),
|
||||
Pointwise(SearchStringResultEq(), kExpectation));
|
||||
}
|
||||
{
|
||||
static constexpr PDFEngine::Client::SearchStringResult kExpectation[] = {
|
||||
static constexpr PDFiumEngineClient::SearchStringResult kExpectation[] = {
|
||||
{16, 3}, {41, 3}};
|
||||
EXPECT_THAT(
|
||||
plugin_->SearchString(kTarget, kPattern, /*case_sensitive=*/false),
|
||||
@ -1743,7 +1743,7 @@ class PdfViewWebPluginWithDocInfoTest : public PdfViewWebPluginTest {
|
||||
protected:
|
||||
class TestPDFiumEngineWithDocInfo : public TestPDFiumEngine {
|
||||
public:
|
||||
explicit TestPDFiumEngineWithDocInfo(PDFEngine::Client* client)
|
||||
explicit TestPDFiumEngineWithDocInfo(PDFiumEngineClient* client)
|
||||
: TestPDFiumEngine(client) {
|
||||
InitializeDocumentAttachments();
|
||||
InitializeDocumentMetadata();
|
||||
@ -2285,7 +2285,7 @@ class PdfViewWebPluginPrintPreviewTest : public PdfViewWebPluginTest {
|
||||
|
||||
TEST_F(PdfViewWebPluginPrintPreviewTest, HandleResetPrintPreviewModeMessage) {
|
||||
EXPECT_CALL(*client_ptr_, CreateEngine)
|
||||
.WillOnce([](PDFEngine::Client* client,
|
||||
.WillOnce([](PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option) {
|
||||
EXPECT_EQ(PDFiumFormFiller::ScriptOption::kNoJavaScript, script_option);
|
||||
|
||||
@ -2308,7 +2308,7 @@ TEST_F(PdfViewWebPluginPrintPreviewTest, HandleResetPrintPreviewModeMessage) {
|
||||
TEST_F(PdfViewWebPluginPrintPreviewTest,
|
||||
HandleResetPrintPreviewModeMessageForPdf) {
|
||||
EXPECT_CALL(*client_ptr_, CreateEngine)
|
||||
.WillOnce([](PDFEngine::Client* client,
|
||||
.WillOnce([](PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option) {
|
||||
EXPECT_EQ(PDFiumFormFiller::ScriptOption::kNoJavaScript, script_option);
|
||||
|
||||
@ -2335,7 +2335,7 @@ TEST_F(PdfViewWebPluginPrintPreviewTest,
|
||||
TEST_F(PdfViewWebPluginPrintPreviewTest,
|
||||
HandleResetPrintPreviewModeMessageSetGrayscale) {
|
||||
EXPECT_CALL(*client_ptr_, CreateEngine)
|
||||
.WillOnce([](PDFEngine::Client* client,
|
||||
.WillOnce([](PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption /*script_option*/) {
|
||||
auto engine = std::make_unique<NiceMock<TestPDFiumEngine>>(client);
|
||||
EXPECT_CALL(*engine, SetGrayscale(true));
|
||||
|
@ -27,7 +27,7 @@ class FindTextTestClient : public TestClient {
|
||||
FindTextTestClient& operator=(const FindTextTestClient&) = delete;
|
||||
~FindTextTestClient() override = default;
|
||||
|
||||
// PDFEngine::Client:
|
||||
// PDFiumEngineClient:
|
||||
MOCK_METHOD(void, NotifyNumberOfFindResultsChanged, (int, bool), (override));
|
||||
MOCK_METHOD(void, NotifySelectedFindResultChanged, (int, bool), (override));
|
||||
|
||||
|
@ -108,6 +108,8 @@ using printing::kPointsPerInch;
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
using FocusFieldType = PDFiumEngineClient::FocusFieldType;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr SkColor kHighlightColor = SkColorSetRGB(153, 193, 218);
|
||||
@ -546,7 +548,7 @@ void ShutdownSDK() {
|
||||
#endif // defined(PDF_ENABLE_V8)
|
||||
}
|
||||
|
||||
PDFiumEngine::PDFiumEngine(PDFEngine::Client* client,
|
||||
PDFiumEngine::PDFiumEngine(PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option)
|
||||
: client_(client),
|
||||
form_filler_(this, script_option),
|
||||
@ -1976,7 +1978,7 @@ void PDFiumEngine::SearchUsingICU(const std::u16string& term,
|
||||
if (adjusted_page_text.empty())
|
||||
return;
|
||||
|
||||
std::vector<PDFEngine::Client::SearchStringResult> results =
|
||||
std::vector<PDFiumEngineClient::SearchStringResult> results =
|
||||
client_->SearchString(adjusted_page_text.c_str(), adjusted_term.c_str(),
|
||||
case_sensitive);
|
||||
for (const auto& result : results) {
|
||||
@ -3840,7 +3842,7 @@ void PDFiumEngine::EnteredEditMode() {
|
||||
client_->EnteredEditMode();
|
||||
}
|
||||
|
||||
void PDFiumEngine::SetFieldFocus(PDFEngine::FocusFieldType type) {
|
||||
void PDFiumEngine::SetFieldFocus(PDFiumEngineClient::FocusFieldType type) {
|
||||
// If focus was previously in form text area, clear form text selection.
|
||||
// Clearing needs to be done before changing focus to ensure the correct
|
||||
// observer is notified of the change in selection. When `focus_field_type_`
|
||||
|
@ -27,6 +27,7 @@
|
||||
#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"
|
||||
@ -74,7 +75,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
enum class FocusElementType { kNone, kDocument, kPage };
|
||||
|
||||
// NOTE: `script_option` is ignored when PDF_ENABLE_V8 is not defined.
|
||||
PDFiumEngine(PDFEngine::Client* client,
|
||||
PDFiumEngine(PDFiumEngineClient* client,
|
||||
PDFiumFormFiller::ScriptOption script_option);
|
||||
PDFiumEngine(const PDFiumEngine&) = delete;
|
||||
PDFiumEngine& operator=(const PDFiumEngine&) = delete;
|
||||
@ -549,7 +550,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
void SetSelecting(bool selecting);
|
||||
|
||||
// Sets the type of field that has focus.
|
||||
void SetFieldFocus(PDFEngine::FocusFieldType type);
|
||||
void SetFieldFocus(PDFiumEngineClient::FocusFieldType type);
|
||||
|
||||
// Sets whether or not left mouse button is currently being held down.
|
||||
void SetMouseLeftButtonDown(bool is_mouse_left_button_down);
|
||||
@ -639,7 +640,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
// requests the thumbnail for that page.
|
||||
void MaybeRequestPendingThumbnail(int page_index);
|
||||
|
||||
const raw_ptr<PDFEngine::Client> client_;
|
||||
const raw_ptr<PDFiumEngineClient> client_;
|
||||
|
||||
// The current document layout.
|
||||
DocumentLayout layout_;
|
||||
@ -748,7 +749,8 @@ class PDFiumEngine : public PDFEngine,
|
||||
bool editable_form_text_area_ = false;
|
||||
|
||||
// The type of the currently focused form field.
|
||||
FocusFieldType focus_field_type_ = FocusFieldType::kNoFocus;
|
||||
PDFiumEngineClient::FocusFieldType focus_field_type_ =
|
||||
PDFiumEngineClient::FocusFieldType::kNoFocus;
|
||||
|
||||
// The focus element type for the currently focused object.
|
||||
FocusElementType focus_element_type_ = FocusElementType::kNone;
|
||||
|
202
pdf/pdfium/pdfium_engine_client.h
Normal file
202
pdf/pdfium/pdfium_engine_client.h
Normal file
@ -0,0 +1,202 @@
|
||||
// Copyright 2024 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_PDFIUM_PDFIUM_ENGINE_CLIENT_H_
|
||||
#define PDF_PDFIUM_PDFIUM_ENGINE_CLIENT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <uchar.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/functional/callback.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h"
|
||||
#include "ui/base/window_open_disposition.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "v8/include/v8-forward.h"
|
||||
|
||||
namespace gfx {
|
||||
class Vector2d;
|
||||
} // namespace gfx
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
class DocumentLayout;
|
||||
class UrlLoader;
|
||||
|
||||
// The interface that's provided to the PDFium rendering engine.
|
||||
class PDFiumEngineClient {
|
||||
public:
|
||||
enum class FocusFieldType {
|
||||
// Focus is not on any form field.
|
||||
kNoFocus,
|
||||
// Focus is on a form text field or form combobox text field.
|
||||
kText,
|
||||
// Focus is on a non-text field.
|
||||
kNonText,
|
||||
};
|
||||
|
||||
virtual ~PDFiumEngineClient() = default;
|
||||
|
||||
// Proposes a document layout to the client. For the proposed layout to
|
||||
// become effective, the client must call PDFEngine::ApplyDocumentLayout()
|
||||
// with the new layout options (although this call can be asynchronous).
|
||||
virtual void ProposeDocumentLayout(const DocumentLayout& layout) = 0;
|
||||
|
||||
// Informs the client that the given rect needs to be repainted.
|
||||
virtual void Invalidate(const gfx::Rect& rect) {}
|
||||
|
||||
// Informs the client to scroll the plugin area by the given offset.
|
||||
virtual void DidScroll(const gfx::Vector2d& offset) {}
|
||||
|
||||
// Scroll the horizontal/vertical scrollbars to a given position.
|
||||
// Values are in screen coordinates, where 0 is the top/left of the document
|
||||
// and a positive value is the distance in pixels from that line.
|
||||
virtual void ScrollToX(int x_screen_coords) {}
|
||||
virtual void ScrollToY(int y_screen_coords) {}
|
||||
|
||||
// Scroll by a given delta relative to the current position.
|
||||
virtual void ScrollBy(const gfx::Vector2d& delta) {}
|
||||
|
||||
// Scroll to zero-based `page`.
|
||||
virtual void ScrollToPage(int page) {}
|
||||
|
||||
// Navigate to the given url.
|
||||
virtual void NavigateTo(const std::string& url,
|
||||
WindowOpenDisposition disposition) {}
|
||||
|
||||
// Navigate to the given destination. Zero-based `page` index. `x`, `y` and
|
||||
// `zoom` are optional and can be nullptr.
|
||||
virtual void NavigateToDestination(int page,
|
||||
const float* x,
|
||||
const float* y,
|
||||
const float* zoom) {}
|
||||
|
||||
// Updates the cursor.
|
||||
virtual void UpdateCursor(ui::mojom::CursorType new_cursor_type) {}
|
||||
|
||||
// Updates the tick marks in the vertical scrollbar.
|
||||
virtual void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) {}
|
||||
|
||||
// Updates the number of find results for the current search term. If
|
||||
// there are no matches 0 should be passed in. Only when the plugin has
|
||||
// finished searching should it pass in the final count with `final_result`
|
||||
// set to true.
|
||||
virtual void NotifyNumberOfFindResultsChanged(int total, bool final_result) {}
|
||||
|
||||
// Updates the index of the currently selected search item. Set
|
||||
// `final_result` to true only when there is no subsequent
|
||||
// `NotifyNumberOfFindResultsChanged()` call.
|
||||
virtual void NotifySelectedFindResultChanged(int current_find_index,
|
||||
bool final_result) {}
|
||||
|
||||
virtual void NotifyTouchSelectionOccurred() {}
|
||||
|
||||
// Prompts the user for a password to open this document. The callback is
|
||||
// called when the password is retrieved.
|
||||
virtual void GetDocumentPassword(
|
||||
base::OnceCallback<void(const std::string&)> callback) {}
|
||||
|
||||
// Play a "beeping" sound.
|
||||
virtual void Beep() {}
|
||||
|
||||
// Puts up an alert with the given message.
|
||||
virtual void Alert(const std::string& message) {}
|
||||
|
||||
// Puts up a confirm with the given message, and returns true if the user
|
||||
// presses OK, or false if they press cancel.
|
||||
virtual bool Confirm(const std::string& message) = 0;
|
||||
|
||||
// Puts up a prompt with the given message and default answer and returns
|
||||
// the answer.
|
||||
virtual std::string Prompt(const std::string& question,
|
||||
const std::string& default_answer) = 0;
|
||||
|
||||
// Returns the url of the pdf.
|
||||
virtual std::string GetURL() = 0;
|
||||
|
||||
// Send an email.
|
||||
virtual void Email(const std::string& to,
|
||||
const std::string& cc,
|
||||
const std::string& bcc,
|
||||
const std::string& subject,
|
||||
const std::string& body) {}
|
||||
|
||||
// Put up the print dialog.
|
||||
virtual void Print() {}
|
||||
|
||||
// Submit the data using HTTP POST.
|
||||
virtual void SubmitForm(const std::string& url,
|
||||
const void* data,
|
||||
int length) {}
|
||||
|
||||
// Creates and returns new URL loader for partial document requests.
|
||||
virtual std::unique_ptr<UrlLoader> CreateUrlLoader() = 0;
|
||||
|
||||
// Returns the current V8 isolate, if any.
|
||||
virtual v8::Isolate* GetIsolate() = 0;
|
||||
|
||||
// Searches the given string for "term" and returns the results. Unicode-
|
||||
// aware.
|
||||
struct SearchStringResult {
|
||||
int start_index;
|
||||
int length;
|
||||
};
|
||||
virtual std::vector<SearchStringResult> SearchString(const char16_t* string,
|
||||
const char16_t* term,
|
||||
bool case_sensitive) = 0;
|
||||
|
||||
// Notifies the client that the document has finished loading.
|
||||
virtual void DocumentLoadComplete() {}
|
||||
|
||||
// Notifies the client that the document has failed to load.
|
||||
virtual void DocumentLoadFailed() {}
|
||||
|
||||
// Notifies that an unsupported feature in the PDF was encountered.
|
||||
virtual void DocumentHasUnsupportedFeature(const std::string& feature) {}
|
||||
|
||||
// Notifies the client about document load progress.
|
||||
virtual void DocumentLoadProgress(uint32_t available, uint32_t doc_size) {}
|
||||
|
||||
// Notifies the client about focus changes for form fields.
|
||||
virtual void FormFieldFocusChange(FocusFieldType type) {}
|
||||
|
||||
// Returns true if the plugin has been opened within print preview.
|
||||
virtual bool IsPrintPreview() const = 0;
|
||||
|
||||
// Get the background color of the PDF.
|
||||
virtual SkColor GetBackgroundColor() const = 0;
|
||||
|
||||
// Sets selection status.
|
||||
virtual void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) {
|
||||
}
|
||||
|
||||
// The caret position in the editable form (if applicable) changed.
|
||||
virtual void CaretChanged(const gfx::Rect& caret_rect) {}
|
||||
|
||||
// Notifies the client that the PDF has been edited.
|
||||
virtual void EnteredEditMode() {}
|
||||
|
||||
// Notifies the client about focus changes for the document.
|
||||
virtual void DocumentFocusChanged(bool document_has_focus) {}
|
||||
|
||||
// Sets selected text.
|
||||
virtual void SetSelectedText(const std::string& selected_text) = 0;
|
||||
|
||||
// Sets the link under cursor.
|
||||
virtual void SetLinkUnderCursor(const std::string& link_under_cursor) = 0;
|
||||
|
||||
// If the link cannot be converted to JS payload struct, then it is not
|
||||
// possible to pass it to JS. In this case, ignore the link like other PDF
|
||||
// viewers.
|
||||
// See https://crbug.com/312882 for an example.
|
||||
virtual bool IsValidLink(const std::string& url) = 0;
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
#endif // PDF_PDFIUM_PDFIUM_ENGINE_CLIENT_H_
|
@ -1120,7 +1120,7 @@ class PDFiumEngineTabbingTest : public PDFiumTestBase {
|
||||
return engine->last_focused_annot_index_;
|
||||
}
|
||||
|
||||
PDFEngine::FocusFieldType FormFocusFieldType(PDFiumEngine* engine) {
|
||||
PDFiumEngineClient::FocusFieldType FormFocusFieldType(PDFiumEngine* engine) {
|
||||
return engine->focus_field_type_;
|
||||
}
|
||||
|
||||
@ -1591,7 +1591,7 @@ TEST_P(PDFiumEngineTabbingTest, VerifyFormFieldStatesOnTabbing) {
|
||||
ASSERT_TRUE(HandleTabEvent(engine.get(), 0));
|
||||
EXPECT_EQ(PDFiumEngine::FocusElementType::kDocument,
|
||||
GetFocusedElementType(engine.get()));
|
||||
EXPECT_EQ(PDFEngine::FocusFieldType::kNoFocus,
|
||||
EXPECT_EQ(PDFiumEngineClient::FocusFieldType::kNoFocus,
|
||||
FormFocusFieldType(engine.get()));
|
||||
EXPECT_FALSE(engine->CanEditText());
|
||||
|
||||
@ -1600,7 +1600,8 @@ TEST_P(PDFiumEngineTabbingTest, VerifyFormFieldStatesOnTabbing) {
|
||||
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
|
||||
GetFocusedElementType(engine.get()));
|
||||
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
|
||||
EXPECT_EQ(PDFEngine::FocusFieldType::kText, FormFocusFieldType(engine.get()));
|
||||
EXPECT_EQ(PDFiumEngineClient::FocusFieldType::kText,
|
||||
FormFocusFieldType(engine.get()));
|
||||
EXPECT_TRUE(engine->CanEditText());
|
||||
|
||||
// Bring focus to the button on the page.
|
||||
@ -1608,7 +1609,7 @@ TEST_P(PDFiumEngineTabbingTest, VerifyFormFieldStatesOnTabbing) {
|
||||
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
|
||||
GetFocusedElementType(engine.get()));
|
||||
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
|
||||
EXPECT_EQ(PDFEngine::FocusFieldType::kNonText,
|
||||
EXPECT_EQ(PDFiumEngineClient::FocusFieldType::kNonText,
|
||||
FormFocusFieldType(engine.get()));
|
||||
EXPECT_FALSE(engine->CanEditText());
|
||||
}
|
||||
@ -1668,7 +1669,7 @@ class ScrollingTestClient : public TestClient {
|
||||
ScrollingTestClient(const ScrollingTestClient&) = delete;
|
||||
ScrollingTestClient& operator=(const ScrollingTestClient&) = delete;
|
||||
|
||||
// Mock PDFEngine::Client methods.
|
||||
// Mock PDFiumEngineClient methods.
|
||||
MOCK_METHOD(void, ScrollToX, (int), (override));
|
||||
MOCK_METHOD(void, ScrollToY, (int), (override));
|
||||
};
|
||||
@ -1782,10 +1783,10 @@ class ReadOnlyTestClient : public TestClient {
|
||||
ReadOnlyTestClient(const ReadOnlyTestClient&) = delete;
|
||||
ReadOnlyTestClient& operator=(const ReadOnlyTestClient&) = delete;
|
||||
|
||||
// Mock PDFEngine::Client methods.
|
||||
// Mock PDFiumEngineClient methods.
|
||||
MOCK_METHOD(void,
|
||||
FormFieldFocusChange,
|
||||
(PDFEngine::FocusFieldType),
|
||||
(PDFiumEngineClient::FocusFieldType),
|
||||
(override));
|
||||
MOCK_METHOD(void, SetSelectedText, (const std::string&), (override));
|
||||
};
|
||||
@ -1800,15 +1801,15 @@ TEST_P(PDFiumEngineReadOnlyTest, KillFormFocus) {
|
||||
|
||||
// Setting read-only mode should kill form focus.
|
||||
EXPECT_FALSE(engine->IsReadOnly());
|
||||
EXPECT_CALL(client,
|
||||
FormFieldFocusChange(PDFEngine::FocusFieldType::kNoFocus));
|
||||
EXPECT_CALL(client, FormFieldFocusChange(
|
||||
PDFiumEngineClient::FocusFieldType::kNoFocus));
|
||||
engine->SetReadOnly(true);
|
||||
|
||||
// Attempting to focus during read-only mode should once more trigger a
|
||||
// killing of form focus.
|
||||
EXPECT_TRUE(engine->IsReadOnly());
|
||||
EXPECT_CALL(client,
|
||||
FormFieldFocusChange(PDFEngine::FocusFieldType::kNoFocus));
|
||||
EXPECT_CALL(client, FormFieldFocusChange(
|
||||
PDFiumEngineClient::FocusFieldType::kNoFocus));
|
||||
engine->UpdateFocus(true);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class FormFillerTestClient : public TestClient {
|
||||
FormFillerTestClient(const FormFillerTestClient&) = delete;
|
||||
FormFillerTestClient& operator=(const FormFillerTestClient&) = delete;
|
||||
|
||||
// Mock PDFEngine::Client methods.
|
||||
// Mock PDFiumEngineClient methods.
|
||||
MOCK_METHOD(void, Beep, (), (override));
|
||||
MOCK_METHOD(std::string, GetURL, (), (override));
|
||||
MOCK_METHOD(void, ScrollToX, (int), (override));
|
||||
|
@ -129,7 +129,7 @@ v8::Isolate* PreviewModeClient::GetIsolate() {
|
||||
NOTREACHED_NORETURN();
|
||||
}
|
||||
|
||||
std::vector<PDFEngine::Client::SearchStringResult>
|
||||
std::vector<PDFiumEngineClient::SearchStringResult>
|
||||
PreviewModeClient::SearchString(const char16_t* string,
|
||||
const char16_t* term,
|
||||
bool case_sensitive) {
|
||||
@ -150,7 +150,8 @@ void PreviewModeClient::DocumentHasUnsupportedFeature(
|
||||
NOTREACHED_IN_MIGRATION();
|
||||
}
|
||||
|
||||
void PreviewModeClient::FormFieldFocusChange(PDFEngine::FocusFieldType type) {
|
||||
void PreviewModeClient::FormFieldFocusChange(
|
||||
PDFiumEngineClient::FocusFieldType type) {
|
||||
NOTREACHED_IN_MIGRATION();
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,12 @@
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_client.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
// The interface that's provided to the print preview rendering engine.
|
||||
class PreviewModeClient : public PDFEngine::Client {
|
||||
class PreviewModeClient : public PDFiumEngineClient {
|
||||
public:
|
||||
class Client {
|
||||
public:
|
||||
@ -28,7 +28,7 @@ class PreviewModeClient : public PDFEngine::Client {
|
||||
explicit PreviewModeClient(Client* client);
|
||||
~PreviewModeClient() override;
|
||||
|
||||
// PDFEngine::Client implementation.
|
||||
// PDFiumEngineClient:
|
||||
void ProposeDocumentLayout(const DocumentLayout& layout) override;
|
||||
void Invalidate(const gfx::Rect& rect) override;
|
||||
void DidScroll(const gfx::Vector2d& offset) override;
|
||||
@ -67,7 +67,7 @@ class PreviewModeClient : public PDFEngine::Client {
|
||||
void DocumentLoadComplete() override;
|
||||
void DocumentLoadFailed() override;
|
||||
void DocumentHasUnsupportedFeature(const std::string& feature) override;
|
||||
void FormFieldFocusChange(PDFEngine::FocusFieldType type) override;
|
||||
void FormFieldFocusChange(FocusFieldType type) override;
|
||||
bool IsPrintPreview() const override;
|
||||
SkColor GetBackgroundColor() const override;
|
||||
void SetSelectedText(const std::string& selected_text) override;
|
||||
|
@ -47,7 +47,7 @@ v8::Isolate* TestClient::GetIsolate() {
|
||||
return GetBlinkIsolate();
|
||||
}
|
||||
|
||||
std::vector<PDFEngine::Client::SearchStringResult> TestClient::SearchString(
|
||||
std::vector<PDFiumEngineClient::SearchStringResult> TestClient::SearchString(
|
||||
const char16_t* string,
|
||||
const char16_t* term,
|
||||
bool case_sensitive) {
|
||||
|
@ -10,10 +10,11 @@
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_client.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
class TestClient : public PDFEngine::Client {
|
||||
class TestClient : public PDFiumEngineClient {
|
||||
public:
|
||||
TestClient();
|
||||
|
||||
@ -25,7 +26,7 @@ class TestClient : public PDFEngine::Client {
|
||||
PDFEngine* engine() const { return engine_; }
|
||||
void set_engine(PDFEngine* engine) { engine_ = engine; }
|
||||
|
||||
// PDFEngine::Client:
|
||||
// PDFiumEngineClient:
|
||||
void ProposeDocumentLayout(const DocumentLayout& layout) override;
|
||||
bool Confirm(const std::string& message) override;
|
||||
std::string Prompt(const std::string& question,
|
||||
|
@ -29,7 +29,7 @@ const uint8_t TestPDFiumEngine::kLoadedData[];
|
||||
// static
|
||||
const uint8_t TestPDFiumEngine::kSaveData[];
|
||||
|
||||
TestPDFiumEngine::TestPDFiumEngine(PDFEngine::Client* client)
|
||||
TestPDFiumEngine::TestPDFiumEngine(PDFiumEngineClient* client)
|
||||
: PDFiumEngine(client, PDFiumFormFiller::ScriptOption::kNoJavaScript) {}
|
||||
|
||||
TestPDFiumEngine::~TestPDFiumEngine() = default;
|
||||
|
@ -29,7 +29,7 @@ class TestPDFiumEngine : public PDFiumEngine {
|
||||
// Dummy save data.
|
||||
static constexpr uint8_t kSaveData[] = {'s', 'a', 'v', 'e'};
|
||||
|
||||
explicit TestPDFiumEngine(PDFEngine::Client* client);
|
||||
explicit TestPDFiumEngine(PDFiumEngineClient* client);
|
||||
|
||||
TestPDFiumEngine(const TestPDFiumEngine&) = delete;
|
||||
|
||||
|
Reference in New Issue
Block a user