Move LoadUrl() to PdfViewPluginBase
Moves OutOfProcessInstance::LoadUrl() to PdfViewPluginBase, so the implementation may be shared between the Pepper and Pepper-free PDF plugins. The PdfViewWebPlugin implementation creates a BlinkUrlLoader instead of a PepperUrlLoader. Bug: 1099022 Change-Id: I2d3c97ba7adb8d3608f32760c942d7333a4e54db Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401507 Commit-Queue: K. Moon <kmoon@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#805998}
This commit is contained in:
@ -2084,20 +2084,8 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom,
|
||||
SendAccessibilityViewportInfo();
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::LoadUrl(const std::string& url,
|
||||
bool is_print_preview) {
|
||||
UrlRequest request;
|
||||
request.url = url;
|
||||
request.method = "GET";
|
||||
request.ignore_redirects = true;
|
||||
|
||||
std::unique_ptr<UrlLoader> loader = CreateUrlLoaderInternal();
|
||||
UrlLoader* raw_loader = loader.get();
|
||||
raw_loader->Open(
|
||||
request,
|
||||
base::BindOnce(is_print_preview ? &OutOfProcessInstance::DidOpenPreview
|
||||
: &OutOfProcessInstance::DidOpen,
|
||||
weak_factory_.GetWeakPtr(), std::move(loader)));
|
||||
base::WeakPtr<PdfViewPluginBase> OutOfProcessInstance::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
std::unique_ptr<UrlLoader> OutOfProcessInstance::CreateUrlLoaderInternal() {
|
||||
|
@ -57,26 +57,26 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
OutOfProcessInstance& operator=(const OutOfProcessInstance&) = delete;
|
||||
~OutOfProcessInstance() override;
|
||||
|
||||
// pp::Instance implementation.
|
||||
// pp::Instance:
|
||||
bool Init(uint32_t argc, const char* argn[], const char* argv[]) override;
|
||||
void HandleMessage(const pp::Var& message) override;
|
||||
bool HandleInputEvent(const pp::InputEvent& event) override;
|
||||
void DidChangeView(const pp::View& view) override;
|
||||
void DidChangeFocus(bool has_focus) override;
|
||||
|
||||
// pp::Find_Private implementation.
|
||||
// pp::Find_Private:
|
||||
bool StartFind(const std::string& text, bool case_sensitive) override;
|
||||
void SelectFindResult(bool forward) override;
|
||||
void StopFind() override;
|
||||
|
||||
// pp::PaintManager::Client implementation.
|
||||
// pp::PaintManager::Client:
|
||||
std::unique_ptr<Graphics> CreatePaintGraphics(const gfx::Size& size) override;
|
||||
bool BindPaintGraphics(Graphics& graphics) override;
|
||||
void OnPaint(const std::vector<gfx::Rect>& paint_rects,
|
||||
std::vector<PaintReadyRect>* ready,
|
||||
std::vector<gfx::Rect>* pending) override;
|
||||
|
||||
// pp::Printing_Dev implementation.
|
||||
// pp::Printing_Dev:
|
||||
uint32_t QuerySupportedPrintOutputFormats() override;
|
||||
int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) override;
|
||||
pp::Resource PrintPages(const PP_PrintPageNumberRange_Dev* page_ranges,
|
||||
@ -84,7 +84,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
void PrintEnd() override;
|
||||
bool IsPrintScalingDisabled() override;
|
||||
|
||||
// pp::Private implementation.
|
||||
// pp::Private:
|
||||
pp::Var GetLinkAtPosition(const pp::Point& point);
|
||||
void GetPrintPresetOptionsFromDocument(PP_PdfPrintPresetOptions_Dev* options);
|
||||
void EnableAccessibility();
|
||||
@ -105,10 +105,8 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
const PP_PdfPrintSettings_Dev* pdf_print_settings);
|
||||
|
||||
void FlushCallback(int32_t result);
|
||||
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result);
|
||||
void DidOpenPreview(std::unique_ptr<UrlLoader> loader, int32_t result);
|
||||
|
||||
// PdfViewPluginBase implementation.
|
||||
// PdfViewPluginBase:
|
||||
void ProposeDocumentLayout(const DocumentLayout& layout) override;
|
||||
void Invalidate(const gfx::Rect& rect) override;
|
||||
void DidScroll(const gfx::Vector2d& offset) override;
|
||||
@ -163,7 +161,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
float GetToolbarHeightInScreenCoords() override;
|
||||
void DocumentFocusChanged(bool document_has_focus) override;
|
||||
|
||||
// PreviewModeClient::Client implementation.
|
||||
// PreviewModeClient::Client:
|
||||
void PreviewDocumentLoadComplete() override;
|
||||
void PreviewDocumentLoadFailed() override;
|
||||
|
||||
@ -175,6 +173,14 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
// for testing.
|
||||
static std::string GetFileNameFromUrl(const std::string& url);
|
||||
|
||||
protected:
|
||||
// PdfViewPluginBase:
|
||||
base::WeakPtr<PdfViewPluginBase> GetWeakPtr() override;
|
||||
std::unique_ptr<UrlLoader> CreateUrlLoaderInternal() override;
|
||||
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
|
||||
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
|
||||
int32_t result) override;
|
||||
|
||||
private:
|
||||
// Message handlers.
|
||||
void HandleBackgroundColorChangedMessage(const pp::VarDictionary& dict);
|
||||
@ -219,12 +225,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
// Draws a rectangle with the specified dimensions and color in our buffer.
|
||||
void FillRect(const pp::Rect& rect, uint32_t color);
|
||||
|
||||
void LoadUrl(const std::string& url, bool is_print_preview);
|
||||
|
||||
// Creates a URL loader and allows it to access all urls, i.e. not just the
|
||||
// frame's origin.
|
||||
std::unique_ptr<UrlLoader> CreateUrlLoaderInternal();
|
||||
|
||||
bool CanSaveEdits() const;
|
||||
void SaveToFile(const std::string& token);
|
||||
void SaveToBuffer(const std::string& token);
|
||||
|
@ -5,8 +5,14 @@
|
||||
#include "pdf/pdf_view_plugin_base.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/ppapi_migration/url_loader.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -22,4 +28,19 @@ void PdfViewPluginBase::DestroyEngine() {
|
||||
engine_.reset();
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::LoadUrl(const std::string& url, bool is_print_preview) {
|
||||
UrlRequest request;
|
||||
request.url = url;
|
||||
request.method = "GET";
|
||||
request.ignore_redirects = true;
|
||||
|
||||
std::unique_ptr<UrlLoader> loader = CreateUrlLoaderInternal();
|
||||
UrlLoader* raw_loader = loader.get();
|
||||
raw_loader->Open(
|
||||
request,
|
||||
base::BindOnce(is_print_preview ? &PdfViewPluginBase::DidOpenPreview
|
||||
: &PdfViewPluginBase::DidOpen,
|
||||
GetWeakPtr(), std::move(loader)));
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -7,11 +7,17 @@
|
||||
|
||||
#include "pdf/pdf_engine.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
class PDFiumEngine;
|
||||
class UrlLoader;
|
||||
|
||||
// Common base to share code between the two plugin implementations,
|
||||
// `OutOfProcessInstance` (Pepper) and `PdfViewWebPlugin` (Blink).
|
||||
@ -36,6 +42,24 @@ class PdfViewPluginBase : public PDFEngine::Client {
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
std::unique_ptr<PDFiumEngine> engine_;
|
||||
};
|
||||
|
@ -6,10 +6,13 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/thread_annotations.h"
|
||||
#include "base/threading/thread_checker.h"
|
||||
#include "cc/paint/paint_canvas.h"
|
||||
@ -23,6 +26,10 @@
|
||||
#include "third_party/blink/public/platform/web_rect.h"
|
||||
#include "third_party/blink/public/platform/web_url_error.h"
|
||||
#include "third_party/blink/public/platform/web_url_response.h"
|
||||
#include "third_party/blink/public/web/web_associated_url_loader.h"
|
||||
#include "third_party/blink/public/web/web_associated_url_loader_options.h"
|
||||
#include "third_party/blink/public/web/web_document.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
#include "third_party/blink/public/web/web_plugin_container.h"
|
||||
#include "third_party/blink/public/web/web_plugin_params.h"
|
||||
#include "ui/base/cursor/cursor.h"
|
||||
@ -255,4 +262,39 @@ float PdfViewWebPlugin::GetToolbarHeightInScreenCoords() {
|
||||
|
||||
void PdfViewWebPlugin::DocumentFocusChanged(bool document_has_focus) {}
|
||||
|
||||
std::unique_ptr<blink::WebAssociatedURLLoader>
|
||||
PdfViewWebPlugin::CreateAssociatedURLLoader(
|
||||
const blink::WebAssociatedURLLoaderOptions& options) {
|
||||
if (!container_)
|
||||
return nullptr;
|
||||
|
||||
blink::WebLocalFrame* frame = container_->GetDocument().GetFrame();
|
||||
if (!frame)
|
||||
return nullptr;
|
||||
|
||||
// TODO(crbug.com/1127146): blink::WebLocalFrame::CreateAssociatedURLLoader()
|
||||
// really should return a std::unique_ptr instead.
|
||||
return base::WrapUnique(frame->CreateAssociatedURLLoader(options));
|
||||
}
|
||||
|
||||
base::WeakPtr<PdfViewPluginBase> PdfViewWebPlugin::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
std::unique_ptr<UrlLoader> PdfViewWebPlugin::CreateUrlLoaderInternal() {
|
||||
auto loader = std::make_unique<BlinkUrlLoader>(weak_factory_.GetWeakPtr());
|
||||
loader->GrantUniversalAccess();
|
||||
return loader;
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::DidOpen(std::unique_ptr<UrlLoader> loader,
|
||||
int32_t result) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::DidOpenPreview(std::unique_ptr<UrlLoader> loader,
|
||||
int32_t result) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -5,7 +5,9 @@
|
||||
#ifndef PDF_PDF_VIEW_WEB_PLUGIN_H_
|
||||
#define PDF_PDF_VIEW_WEB_PLUGIN_H_
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "pdf/pdf_view_plugin_base.h"
|
||||
#include "pdf/ppapi_migration/url_loader.h"
|
||||
#include "third_party/blink/public/web/web_plugin.h"
|
||||
|
||||
namespace blink {
|
||||
@ -17,7 +19,8 @@ namespace chrome_pdf {
|
||||
|
||||
// Skeleton for a `blink::WebPlugin` to replace `OutOfProcessInstance`.
|
||||
class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
public blink::WebPlugin {
|
||||
public blink::WebPlugin,
|
||||
public BlinkUrlLoader::Client {
|
||||
public:
|
||||
explicit PdfViewWebPlugin(const blink::WebPluginParams& params);
|
||||
PdfViewWebPlugin(const PdfViewWebPlugin& other) = delete;
|
||||
@ -98,11 +101,25 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
float GetToolbarHeightInScreenCoords() override;
|
||||
void DocumentFocusChanged(bool document_has_focus) override;
|
||||
|
||||
// BlinkUrlLoader::Client:
|
||||
std::unique_ptr<blink::WebAssociatedURLLoader> CreateAssociatedURLLoader(
|
||||
const blink::WebAssociatedURLLoaderOptions& options) override;
|
||||
|
||||
protected:
|
||||
// PdfViewPluginBase:
|
||||
base::WeakPtr<PdfViewPluginBase> GetWeakPtr() override;
|
||||
std::unique_ptr<UrlLoader> CreateUrlLoaderInternal() override;
|
||||
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
|
||||
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
|
||||
int32_t result) override;
|
||||
|
||||
private:
|
||||
// Call `Destroy()` instead.
|
||||
~PdfViewWebPlugin() override;
|
||||
|
||||
blink::WebPluginContainer* container_ = nullptr;
|
||||
|
||||
base::WeakPtrFactory<PdfViewWebPlugin> weak_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
Reference in New Issue
Block a user