Commit ad577c62 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Add PDFiumPage::SetIsValidLinkFunctionForTesting().

Make it possible to write pdf_unittests test cases that call
PDFiumPage::CalculateLinks() without requiring PPAPI initialization.

Change-Id: I8433baf810128039efa4705a8862b95f97efd9ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1725427Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683727}
parent 226a360f
......@@ -27,8 +27,21 @@ using printing::ConvertUnitDouble;
using printing::kPointsPerInch;
using printing::kPixelsPerInch;
namespace chrome_pdf {
namespace {
PDFiumPage::IsValidLinkFunction g_is_valid_link_func_for_testing = nullptr;
// If the link cannot be converted to a pp::Var, 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.
// TODO(crbug.com/702993): Get rid of the PPAPI usage here, as well as
// SetIsValidLinkFunctionForTesting() and related code.
bool IsValidLink(const std::string& url) {
return pp::Var(url).is_string();
}
pp::FloatRect FloatPageRectToPixelRect(FPDF_PAGE page,
const pp::FloatRect& input) {
int output_width = FPDF_GetPageWidth(page);
......@@ -81,8 +94,6 @@ bool OverlapsOnYAxis(const pp::FloatRect& a, const pp::FloatRect& b) {
} // namespace
namespace chrome_pdf {
PDFiumPage::LinkTarget::LinkTarget() : page(-1) {}
PDFiumPage::LinkTarget::LinkTarget(const LinkTarget& other) = default;
......@@ -104,6 +115,12 @@ PDFiumPage::~PDFiumPage() {
DCHECK_EQ(0, preventing_unload_count_);
}
// static
void PDFiumPage::SetIsValidLinkFunctionForTesting(
IsValidLinkFunction function) {
g_is_valid_link_func_for_testing = function;
}
void PDFiumPage::Unload() {
// Do not unload while in the middle of a load.
if (preventing_unload_count_)
......@@ -444,11 +461,10 @@ void PDFiumPage::CalculateLinks() {
Link link;
link.url = base::UTF16ToUTF8(url);
// If the link cannot be converted to a pp::Var, then it is not possible to
// pass it to JS. In this case, ignore the link like other PDF viewers.
// See http://crbug.com/312882 for an example.
pp::Var link_var(link.url);
if (!link_var.is_string())
IsValidLinkFunction is_valid_link_func =
g_is_valid_link_func_for_testing ? g_is_valid_link_func_for_testing
: &IsValidLink;
if (!is_valid_link_func(link.url))
continue;
// Make sure all the characters in the URL are valid per RFC 1738.
......
......@@ -29,6 +29,9 @@ class PDFiumPage {
PDFiumPage(PDFiumPage&& that);
~PDFiumPage();
using IsValidLinkFunction = bool (*)(const std::string& url);
static void SetIsValidLinkFunctionForTesting(IsValidLinkFunction function);
// Unloads the PDFium data for this page from memory.
void Unload();
// Gets the FPDF_PAGE for this page, loading and parsing it if necessary.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment