Change PDFiumDocument::LoadDocument() to take a std::string.
already known. Change to const char* right before interacting with the PDFium C API. std: :string is slightly better than const char* since its length is Change-Id: I429f6c05a5b517e73622909b7ac5583b27af6ea3 Reviewed-on: https://chromium-review.googlesource.com/c/1407923 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#622611}
This commit is contained in:
@ -94,13 +94,15 @@ void PDFiumDocument::ResetFPDFAvailability() {
|
||||
fpdf_availability_.reset();
|
||||
}
|
||||
|
||||
void PDFiumDocument::LoadDocument(const char* password) {
|
||||
void PDFiumDocument::LoadDocument(const std::string& password) {
|
||||
const char* password_cstr = password.empty() ? nullptr : password.c_str();
|
||||
if (doc_loader_->IsDocumentComplete() &&
|
||||
!FPDFAvail_IsLinearized(fpdf_availability_.get())) {
|
||||
doc_handle_.reset(FPDF_LoadCustomDocument(file_access_.get(), password));
|
||||
doc_handle_.reset(
|
||||
FPDF_LoadCustomDocument(file_access_.get(), password_cstr));
|
||||
} else {
|
||||
doc_handle_.reset(
|
||||
FPDFAvail_GetDocument(fpdf_availability_.get(), password));
|
||||
FPDFAvail_GetDocument(fpdf_availability_.get(), password_cstr));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
#ifndef PDF_PDFIUM_PDFIUM_DOCUMENT_H_
|
||||
#define PDF_PDFIUM_PDFIUM_DOCUMENT_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
#include "third_party/pdfium/public/fpdf_dataavail.h"
|
||||
@ -32,7 +35,7 @@ class PDFiumDocument {
|
||||
void CreateFPDFAvailability();
|
||||
void ResetFPDFAvailability();
|
||||
|
||||
void LoadDocument(const char* password);
|
||||
void LoadDocument(const std::string& password);
|
||||
|
||||
void SetFormStatus();
|
||||
void InitializeForm(FPDF_FORMFILLINFO* form_info);
|
||||
|
@ -2645,12 +2645,9 @@ bool PDFiumEngine::TryLoadingDoc(const std::string& password,
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* password_cstr = nullptr;
|
||||
if (!password.empty()) {
|
||||
password_cstr = password.c_str();
|
||||
if (!password.empty())
|
||||
password_tries_remaining_--;
|
||||
}
|
||||
document_->LoadDocument(password_cstr);
|
||||
document_->LoadDocument(password);
|
||||
if (!doc()) {
|
||||
if (FPDF_GetLastError() == FPDF_ERR_PASSWORD)
|
||||
*needs_password = true;
|
||||
|
Reference in New Issue
Block a user