Skip to content

Commit

Permalink
Split unsupported features code out of pdfium_engine.cc.
Browse files Browse the repository at this point in the history
Change-Id: I39005eb8a1c016a6b402fdac3c6484d6db430bb1
Reviewed-on: https://chromium-review.googlesource.com/1081196
Reviewed-by: dsinclair <[email protected]>
Commit-Queue: Lei Zhang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#563371}
  • Loading branch information
leizleiz authored and Commit Bot committed May 31, 2018
1 parent c65dbe4 commit 279d0ec
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 80 deletions.
2 changes: 2 additions & 0 deletions pdf/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ if (enable_pdf) {
"pdfium/pdfium_print.h",
"pdfium/pdfium_range.cc",
"pdfium/pdfium_range.h",
"pdfium/pdfium_unsupported_features.cc",
"pdfium/pdfium_unsupported_features.h",
]

include_dirs += [ "//third_party/pdfium" ]
Expand Down
1 change: 1 addition & 0 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,7 @@ pp::Instance* OutOfProcessInstance::GetPluginInstance() {

void OutOfProcessInstance::DocumentHasUnsupportedFeature(
const std::string& feature) {
DCHECK(!feature.empty());
std::string metric("PDF_Unsupported_");
metric += feature;
if (!unsupported_features_reported_.count(metric)) {
Expand Down
67 changes: 3 additions & 64 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
#include "pdf/pdfium/pdfium_unsupported_features.h"
#include "pdf/url_loader_wrapper_impl.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/pdf.h"
Expand Down Expand Up @@ -419,19 +420,6 @@ void Release(FPDF_SYSFONTINFO* sysfontinfo) {
PDFiumEngine::CreateDocumentLoaderFunction
g_create_document_loader_for_testing = nullptr;

PDFiumEngine* g_engine_for_unsupported = nullptr;

void Unsupported_Handler(UNSUPPORT_INFO*, int type) {
if (!g_engine_for_unsupported) {
NOTREACHED();
return;
}

g_engine_for_unsupported->UnsupportedFeature(type);
}

UNSUPPORT_INFO g_unsupported_info = {1, Unsupported_Handler};

template <class S>
bool IsAboveOrDirectlyLeftOf(const S& lhs, const S& rhs) {
return lhs.y() < rhs.y() || (lhs.y() == rhs.y() && lhs.x() < rhs.x());
Expand Down Expand Up @@ -669,7 +657,7 @@ bool InitializeSDK() {
FPDF_SetSystemFontInfo(g_font_info);
#endif

FSDK_SetUnSpObjProcessHandler(&g_unsupported_info);
InitializeUnsupportedFeaturesHandler();

return true;
}
Expand Down Expand Up @@ -1066,47 +1054,7 @@ void PDFiumEngine::FinishLoadingDocument() {
}
}

void PDFiumEngine::UnsupportedFeature(int type) {
std::string feature;
switch (type) {
case FPDF_UNSP_DOC_XFAFORM:
feature = "XFA";
break;
case FPDF_UNSP_DOC_PORTABLECOLLECTION:
feature = "Portfolios_Packages";
break;
case FPDF_UNSP_DOC_ATTACHMENT:
case FPDF_UNSP_ANNOT_ATTACHMENT:
feature = "Attachment";
break;
case FPDF_UNSP_DOC_SECURITY:
feature = "Rights_Management";
break;
case FPDF_UNSP_DOC_SHAREDREVIEW:
feature = "Shared_Review";
break;
case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT:
case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM:
case FPDF_UNSP_DOC_SHAREDFORM_EMAIL:
feature = "Shared_Form";
break;
case FPDF_UNSP_ANNOT_3DANNOT:
feature = "3D";
break;
case FPDF_UNSP_ANNOT_MOVIE:
feature = "Movie";
break;
case FPDF_UNSP_ANNOT_SOUND:
feature = "Sound";
break;
case FPDF_UNSP_ANNOT_SCREEN_MEDIA:
case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA:
feature = "Screen";
break;
case FPDF_UNSP_ANNOT_SIG:
feature = "Digital_Signature";
break;
}
void PDFiumEngine::UnsupportedFeature(const std::string& feature) {
client_->DocumentHasUnsupportedFeature(feature);
}

Expand Down Expand Up @@ -3691,15 +3639,6 @@ void PDFiumEngine::ProgressivePaint::SetBitmapAndImageData(
image_data_ = std::move(image_data);
}

ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine)
: old_engine_(g_engine_for_unsupported) {
g_engine_for_unsupported = engine;
}

ScopedUnsupportedFeature::~ScopedUnsupportedFeature() {
g_engine_for_unsupported = old_engine_;
}

ScopedSubstFont::ScopedSubstFont(PDFiumEngine* engine)
: old_engine_(g_engine_for_fontmapper) {
g_engine_for_fontmapper = engine;
Expand Down
15 changes: 1 addition & 14 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class PDFiumEngine : public PDFEngine,
void CancelBrowserDownload() override;
void KillFormFocus() override;

void UnsupportedFeature(int type);
void UnsupportedFeature(const std::string& feature);
void FontSubstituted();

FPDF_AVAIL fpdf_availability() const { return fpdf_availability_.get(); }
Expand Down Expand Up @@ -710,19 +710,6 @@ class PDFiumEngine : public PDFEngine,
DISALLOW_COPY_AND_ASSIGN(PDFiumEngine);
};

// Create a local variable of this when calling PDFium functions which can call
// our global callback when an unsupported feature is reached.
class ScopedUnsupportedFeature {
public:
explicit ScopedUnsupportedFeature(PDFiumEngine* engine);
~ScopedUnsupportedFeature();

private:
PDFiumEngine* const old_engine_;

DISALLOW_COPY_AND_ASSIGN(ScopedUnsupportedFeature);
};

// Create a local variable of this when calling PDFium functions which can call
// our global callback when a substitute font is mapped.
class ScopedSubstFont {
Expand Down
11 changes: 9 additions & 2 deletions pdf/pdfium/pdfium_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_unsupported_features.h"
#include "printing/units.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_annot.h"
Expand Down Expand Up @@ -60,7 +61,10 @@ pp::FloatRect FloatPageRectToPixelRect(FPDF_PAGE page,
pp::FloatRect GetFloatCharRectInPixels(FPDF_PAGE page,
FPDF_TEXTPAGE text_page,
int index) {
double left, right, bottom, top;
double left;
double right;
double bottom;
double top;
FPDFText_GetCharBox(text_page, index, &left, &right, &bottom, &top);
if (right < left)
std::swap(left, right);
Expand Down Expand Up @@ -420,7 +424,10 @@ int PDFiumPage::GetLink(int char_index, LinkTarget* target) {

// Get the bounding box of the rect again, since it might have moved because
// of the tolerance above.
double left, right, bottom, top;
double left;
double right;
double bottom;
double top;
FPDFText_GetCharBox(GetTextPage(), char_index, &left, &right, &bottom, &top);

pp::Point origin(
Expand Down
84 changes: 84 additions & 0 deletions pdf/pdfium/pdfium_unsupported_features.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "pdf/pdfium/pdfium_unsupported_features.h"

#include "base/logging.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "third_party/pdfium/public/fpdf_ext.h"

namespace chrome_pdf {

namespace {

PDFiumEngine* g_engine_for_unsupported = nullptr;

void Unsupported_Handler(UNSUPPORT_INFO*, int type) {
if (!g_engine_for_unsupported) {
NOTREACHED();
return;
}

std::string feature;
switch (type) {
case FPDF_UNSP_DOC_XFAFORM:
feature = "XFA";
break;
case FPDF_UNSP_DOC_PORTABLECOLLECTION:
feature = "Portfolios_Packages";
break;
case FPDF_UNSP_DOC_ATTACHMENT:
case FPDF_UNSP_ANNOT_ATTACHMENT:
feature = "Attachment";
break;
case FPDF_UNSP_DOC_SECURITY:
feature = "Rights_Management";
break;
case FPDF_UNSP_DOC_SHAREDREVIEW:
feature = "Shared_Review";
break;
case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT:
case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM:
case FPDF_UNSP_DOC_SHAREDFORM_EMAIL:
feature = "Shared_Form";
break;
case FPDF_UNSP_ANNOT_3DANNOT:
feature = "3D";
break;
case FPDF_UNSP_ANNOT_MOVIE:
feature = "Movie";
break;
case FPDF_UNSP_ANNOT_SOUND:
feature = "Sound";
break;
case FPDF_UNSP_ANNOT_SCREEN_MEDIA:
case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA:
feature = "Screen";
break;
case FPDF_UNSP_ANNOT_SIG:
feature = "Digital_Signature";
break;
}

g_engine_for_unsupported->UnsupportedFeature(feature);
}

UNSUPPORT_INFO g_unsupported_info = {1, Unsupported_Handler};

} // namespace

void InitializeUnsupportedFeaturesHandler() {
FSDK_SetUnSpObjProcessHandler(&g_unsupported_info);
}

ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine)
: old_engine_(g_engine_for_unsupported) {
g_engine_for_unsupported = engine;
}

ScopedUnsupportedFeature::~ScopedUnsupportedFeature() {
g_engine_for_unsupported = old_engine_;
}

} // namespace chrome_pdf
31 changes: 31 additions & 0 deletions pdf/pdfium/pdfium_unsupported_features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PDF_PDFIUM_PDFIUM_UNSUPPORTED_FEATURES_H_
#define PDF_PDFIUM_PDFIUM_UNSUPPORTED_FEATURES_H_

#include "base/macros.h"

namespace chrome_pdf {

class PDFiumEngine;

void InitializeUnsupportedFeaturesHandler();

// Create a local variable of this when calling PDFium functions which can call
// our global callback when an unsupported feature is reached.
class ScopedUnsupportedFeature {
public:
explicit ScopedUnsupportedFeature(PDFiumEngine* engine);
~ScopedUnsupportedFeature();

private:
PDFiumEngine* const old_engine_;

DISALLOW_COPY_AND_ASSIGN(ScopedUnsupportedFeature);
};

} // namespace chrome_pdf

#endif // PDF_PDFIUM_PDFIUM_UNSUPPORTED_FEATURES_H_

0 comments on commit 279d0ec

Please sign in to comment.