blob: 0df76d8bdc1a946e45c0de455a4bcfaff8373dcc [file] [log] [blame]
// 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 <memory>
#include <string>
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_dataavail.h"
#include "third_party/pdfium/public/fpdfview.h"
namespace chrome_pdf {
class DocumentLoader;
class PDFiumDocument {
explicit PDFiumDocument(DocumentLoader* doc_loader);
PDFiumDocument(const PDFiumDocument&) = delete;
PDFiumDocument& operator=(const PDFiumDocument&) = delete;
FPDF_FILEACCESS& file_access() { return *file_access_; }
FX_FILEAVAIL& file_availability() { return *file_availability_; }
FX_DOWNLOADHINTS& download_hints() { return *download_hints_; }
FPDF_AVAIL fpdf_availability() const { return fpdf_availability_.get(); }
FPDF_DOCUMENT doc() const { return doc_handle_.get(); }
FPDF_FORMHANDLE form() const { return form_handle_.get(); }
int form_status() const { return form_status_; }
void CreateFPDFAvailability();
void ResetFPDFAvailability();
void LoadDocument(const std::string& password);
void SetFormStatus();
void InitializeForm(FPDF_FORMFILLINFO* form_info);
DocumentLoader* const doc_loader_;
// Interface structure to provide access to document stream.
std::unique_ptr<FPDF_FILEACCESS> file_access_;
// Interface structure to check data availability in the document stream.
std::unique_ptr<FX_FILEAVAIL> file_availability_;
// Interface structure to request data chunks from the document stream.
std::unique_ptr<FX_DOWNLOADHINTS> download_hints_;
// Pointer to the document availability interface.
ScopedFPDFAvail fpdf_availability_;
// The PDFium wrapper object for the document. Must come after
// |fpdf_availability_| to prevent outliving it.
ScopedFPDFDocument doc_handle_;
// The PDFium wrapper for form data. Used even if there are no form controls
// on the page. Must come after |doc_handle_| to prevent outliving it.
ScopedFPDFFormHandle form_handle_;
// Current form availability status.
int form_status_ = PDF_FORM_NOTAVAIL;
} // namespace chrome_pdf