0

Migrate PdfViewPluginBase::LoadUrl()

Migrates LoadUrl() from PdfViewPluginBase to PdfViewWebPlugin, removing
the last references to UrlLoader from PdfViewPluginBase.

Bug: 1322928
Change-Id: I501b6fb5abec2702607cd51fed5144e1ec1ee5be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3709988
Auto-Submit: K. Moon <kmoon@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1014983}
This commit is contained in:
K. Moon
2022-06-16 17:33:48 +00:00
committed by Chromium LUCI CQ
parent 71f1e69a0c
commit 4d6513f719
4 changed files with 31 additions and 31 deletions

@ -42,8 +42,6 @@
#include "pdf/pdf_features.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_form_filler.h"
#include "pdf/ppapi_migration/result_codes.h"
#include "pdf/ppapi_migration/url_loader.h"
#include "pdf/ui/file_name.h"
#include "pdf/ui/thumbnail.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
@ -850,18 +848,6 @@ void PdfViewPluginBase::LoadAccessibility() {
kAccessibilityPageDelay);
}
void PdfViewPluginBase::DidOpen(std::unique_ptr<UrlLoader> loader,
int32_t result) {
if (result == kSuccess) {
if (!engine()->HandleDocumentLoad(std::move(loader), GetURL())) {
document_load_state_ = DocumentLoadState::kLoading;
DocumentLoadFailed();
}
} else if (result != kErrorAborted) {
DocumentLoadFailed();
}
}
gfx::Point PdfViewPluginBase::FrameToPdfCoordinates(
const gfx::PointF& frame_coordinates) const {
// TODO(crbug.com/1288847): Use methods on `blink::WebPluginContainer`.

@ -42,7 +42,6 @@ namespace chrome_pdf {
class PDFiumEngine;
class PaintReadyRect;
class Thumbnail;
class UrlLoader;
struct AccessibilityActionData;
struct AccessibilityCharInfo;
struct AccessibilityDocInfo;
@ -128,12 +127,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
}
protected:
// Callback that runs after `LoadUrl()`. The `loader` is the loader used to
// load the URL, and `result` is the result code for the load.
using LoadUrlCallback =
base::OnceCallback<void(std::unique_ptr<UrlLoader> loader,
int32_t result)>;
struct BackgroundPart {
gfx::Rect location;
uint32_t color;
@ -150,9 +143,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
virtual const PDFiumEngine* engine() const = 0;
virtual PDFiumEngine* engine() = 0;
// Loads `url`, invoking `callback` on receiving the initial response.
virtual void LoadUrl(base::StringPiece url, LoadUrlCallback callback) = 0;
// Gets a weak pointer with a lifetime matching the derived class.
virtual base::WeakPtr<PdfViewPluginBase> GetWeakPtr() = 0;
@ -320,9 +310,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
return size > 0 && size <= kMaximumSavedFileSize;
}
// Handles `LoadUrl()` result.
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result);
// Converts a scroll offset (which is relative to a UI direction-dependent
// scroll origin) to a scroll position (which is always relative to the
// top-left corner).

@ -14,6 +14,7 @@
#include <vector>
#include "base/bind.h"
#include "base/callback.h"
#include "base/check_op.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/queue.h"
@ -336,8 +337,8 @@ bool PdfViewWebPlugin::InitializeCommon() {
return true;
set_last_progress_sent(0);
LoadUrl(params->src_url,
base::BindOnce(&PdfViewWebPlugin::DidOpen, GetWeakPtr()));
LoadUrl(params->src_url, base::BindOnce(&PdfViewWebPlugin::DidOpen,
weak_factory_.GetWeakPtr()));
url_ = params->original_url;
// Not all edits go through the PDF plugin's form filler. The plugin instance
@ -360,6 +361,18 @@ void PdfViewWebPlugin::SendSetSmoothScrolling() {
SendMessage(std::move(message));
}
void PdfViewWebPlugin::DidOpen(std::unique_ptr<UrlLoader> loader,
int32_t result) {
if (result == kSuccess) {
if (!engine_->HandleDocumentLoad(std::move(loader), url_)) {
set_document_load_state(DocumentLoadState::kLoading);
DocumentLoadFailed();
}
} else if (result != kErrorAborted) {
DocumentLoadFailed();
}
}
void PdfViewWebPlugin::Destroy() {
if (client_->PluginContainer()) {
// Explicitly destroy the PDFEngine during destruction as it may call back
@ -1632,7 +1645,8 @@ void PdfViewWebPlugin::HandleResetPrintPreviewModeMessage(
preview_document_load_state_ = DocumentLoadState::kComplete;
set_document_load_state(DocumentLoadState::kLoading);
set_last_progress_sent(0);
LoadUrl(url_, base::BindOnce(&PdfViewWebPlugin::DidOpen, GetWeakPtr()));
LoadUrl(url_, base::BindOnce(&PdfViewWebPlugin::DidOpen,
weak_factory_.GetWeakPtr()));
preview_engine_.reset();
// TODO(crbug.com/1237952): Figure out a more consistent way to preserve

@ -11,11 +11,13 @@
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/containers/flat_set.h"
#include "base/containers/queue.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_piece_forward.h"
#include "base/values.h"
#include "cc/paint/paint_image.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
@ -340,7 +342,6 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
PDFiumFormFiller::ScriptOption script_option) override;
const PDFiumEngine* engine() const override;
PDFiumEngine* engine() override;
void LoadUrl(base::StringPiece url, LoadUrlCallback callback) override;
base::WeakPtr<PdfViewPluginBase> GetWeakPtr() override;
void OnPrintPreviewLoaded() override;
void OnDocumentLoadComplete() override;
@ -372,6 +373,12 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void PrepareForFirstPaint(std::vector<PaintReadyRect>& ready) override;
private:
// Callback that runs after `LoadUrl()`. The `loader` is the loader used to
// load the URL, and `result` is the result code for the load.
using LoadUrlCallback =
base::OnceCallback<void(std::unique_ptr<UrlLoader> loader,
int32_t result)>;
// Metadata about an available preview page.
struct PreviewPageInfo {
// Data source URL.
@ -389,10 +396,16 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// Sends whether to do smooth scrolling.
void SendSetSmoothScrolling();
// Handles `LoadUrl()` result for the main document.
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result);
// Updates the scroll position, which is in CSS pixels relative to the
// top-left corner.
void UpdateScroll(const gfx::PointF& scroll_position);
// Loads `url`, invoking `callback` on receiving the initial response.
void LoadUrl(base::StringPiece url, LoadUrlCallback callback);
// Handles `Open()` result for `form_loader_`.
void DidFormOpen(int32_t result);