Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
M52: PDF: Always call FPDFAvail_IsDocAvail() when loading.
Browse files Browse the repository at this point in the history
BUG=613704

Review-Url: https://codereview.chromium.org/2006793003
Cr-Commit-Position: refs/heads/master@{#400286}
(cherry picked from commit 0968faa)

Review URL: https://codereview.chromium.org/2080313003 .

Cr-Commit-Position: refs/branch-heads/2743@{#406}
Cr-Branched-From: 2b3ae3b-refs/heads/master@{#394939}
  • Loading branch information
leizleiz committed Jun 20, 2016
1 parent a5694a5 commit d7d4d71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
23 changes: 17 additions & 6 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ FPDF_SYSFONTINFO g_font_info = {
};
#endif // defined(OS_LINUX)

PDFiumEngine* g_engine_for_unsupported;
PDFiumEngine* g_engine_for_unsupported = nullptr;

void Unsupported_Handler(UNSUPPORT_INFO*, int type) {
if (!g_engine_for_unsupported) {
Expand Down Expand Up @@ -1049,6 +1049,7 @@ void PDFiumEngine::OnPartialDocumentLoaded() {

void PDFiumEngine::OnPendingRequestComplete() {
if (!doc_ || !form_) {
DCHECK(fpdf_availability_);
LoadDocument();
return;
}
Expand Down Expand Up @@ -2417,8 +2418,13 @@ bool PDFiumEngine::TryLoadingDoc(bool with_password,
const std::string& password,
bool* needs_password) {
*needs_password = false;
if (doc_)
if (doc_) {
// This is probably not necessary, because it should have already been
// called below in the |doc_| initialization path. However, the previous
// call may have failed, so call it again for good measure.
FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
return true;
}

const char* password_cstr = nullptr;
if (with_password) {
Expand All @@ -2431,11 +2437,16 @@ bool PDFiumEngine::TryLoadingDoc(bool with_password,
} else {
doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr);
}
if (!doc_) {
if (FPDF_GetLastError() == FPDF_ERR_PASSWORD)
*needs_password = true;
return false;
}

if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD)
*needs_password = true;

return !!doc_;
// Always call FPDFAvail_IsDocAvail() so PDFium initializes internal data
// structures.
FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
return true;
}

void PDFiumEngine::GetPasswordAndLoad() {
Expand Down
14 changes: 8 additions & 6 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class PDFiumEngine : public PDFEngine,
const std::string& password,
bool* needs_password);

// Ask the user for the document password and then continue loading the
// Asks the user for the document password and then continue loading the
// document.
void GetPasswordAndLoad();

Expand All @@ -225,17 +225,19 @@ class PDFiumEngine : public PDFEngine,
void ContinueLoadingDocument(bool has_password,
const std::string& password);

// Finish loading the document and notify the client that the document has
// been loaded. This should only be run after |doc_| has been loaded and the
// document is fully downloaded. If this has been run once, it will result in
// a no-op.
// Finishes loading the document. Recalculate the document size if there were
// pages that were not previously available.
// Also notifies the client that the document has been loaded.
// This should only be called after |doc_| has been loaded and the document is
// fully downloaded.
// If this has been run once, it will not notify the client again.
void FinishLoadingDocument();

// Loads information about the pages in the document and calculate the
// document size.
void LoadPageInfo(bool reload);

// Calculate which pages should be displayed right now.
// Calculates which pages should be displayed right now.
void CalculateVisiblePages();

// Returns true iff the given page index is visible. CalculateVisiblePages
Expand Down

0 comments on commit d7d4d71

Please sign in to comment.