blob: 566ca4f471e293233c8c05a41a49cf6ddc1dee96 [file] [log] [blame]
// Copyright 2020 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/pdf_engine.h"
#include <stdint.h>
#include <memory>
#include <string>
#include "base/memory/weak_ptr.h"
#include "pdf/pdfium/pdfium_form_filler.h"
namespace chrome_pdf {
class PDFiumEngine;
class UrlLoader;
// Common base to share code between the two plugin implementations,
// `OutOfProcessInstance` (Pepper) and `PdfViewWebPlugin` (Blink).
class PdfViewPluginBase : public PDFEngine::Client {
PdfViewPluginBase(const PdfViewPluginBase& other) = delete;
PdfViewPluginBase& operator=(const PdfViewPluginBase& other) = delete;
~PdfViewPluginBase() override;
// Initializes the main `PDFiumEngine`. Any existing engine will be replaced.
void InitializeEngine(PDFiumFormFiller::ScriptOption script_option);
// Destroys the main `PDFiumEngine`. Subclasses should call this method in
// their destructor to ensure the engine is destroyed first.
void DestroyEngine();
PDFiumEngine* engine() { return engine_.get(); }
// Starts loading `url`. If `is_print_preview` is `true`, load for print
// preview instead of normal PDF viewing.
void LoadUrl(const std::string& url, bool is_print_preview);
// Gets a weak pointer with a lifetime matching the derived class.
virtual base::WeakPtr<PdfViewPluginBase> GetWeakPtr() = 0;
// Creates a URL loader and allows it to access all urls, i.e. not just the
// frame's origin.
virtual std::unique_ptr<UrlLoader> CreateUrlLoaderInternal() = 0;
// Handles `LoadUrl()` result.
virtual void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) = 0;
// Handles `LoadUrl()` result for print preview.
virtual void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) = 0;
std::unique_ptr<PDFiumEngine> engine_;
} // namespace chrome_pdf