0

Migrate PdfViewPluginBase::SubmitForm()

Migrates SubmitForm() from PdfViewPluginBase to PdfViewWebPlugin.

Bug: 1322928
Change-Id: I113f3c4f8e610ce27f1c80b1346c4e14bc053b27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3646512
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1003583}
This commit is contained in:
K. Moon
2022-05-15 22:55:06 +00:00
committed by Chromium LUCI CQ
parent ea000fcadb
commit d74a56d2d0
4 changed files with 35 additions and 35 deletions

@ -25,7 +25,6 @@
#include "base/feature_list.h"
#include "base/i18n/rtl.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
@ -347,25 +346,6 @@ void PdfViewPluginBase::Print() {
InvokePrintDialog();
}
void PdfViewPluginBase::SubmitForm(const std::string& url,
const void* data,
int length) {
// `url` might be a relative URL. Resolve it against the document's URL.
// TODO(crbug.com/1322928): Probably redundant with `Client::CompleteURL()`.
GURL resolved_url = GURL(GetURL()).Resolve(url);
if (!resolved_url.is_valid())
return;
UrlRequest request;
request.url = resolved_url.spec();
request.method = "POST";
request.body.assign(static_cast<const char*>(data), length);
form_loader_ = CreateUrlLoaderInternal();
form_loader_->Open(
request, base::BindOnce(&PdfViewPluginBase::DidFormOpen, GetWeakPtr()));
}
std::unique_ptr<UrlLoader> PdfViewPluginBase::CreateUrlLoader() {
if (full_frame_) {
DidStartLoading();
@ -1544,12 +1524,6 @@ void PdfViewPluginBase::DidOpenPreview(std::unique_ptr<UrlLoader> loader,
preview_engine_->HandleDocumentLoad(std::move(loader), GetURL());
}
void PdfViewPluginBase::DidFormOpen(int32_t result) {
// TODO(crbug.com/719344): Process response.
LOG_IF(ERROR, result != kSuccess) << "DidFormOpen failed: " << result;
form_loader_.reset();
}
void PdfViewPluginBase::OnPrintPreviewLoaded() {
// Scroll location is retained across document loads in print preview mode, so
// there's no need to override the scroll position by scrolling again.

@ -118,9 +118,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
const std::string& subject,
const std::string& body) override;
void Print() override;
void SubmitForm(const std::string& url,
const void* data,
int length) override;
std::unique_ptr<UrlLoader> CreateUrlLoader() override;
void DocumentLoadComplete() override;
void DocumentLoadFailed() override;
@ -461,9 +458,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
// Handles `LoadUrl()` result for print preview.
void DidOpenPreview(std::unique_ptr<UrlLoader> loader, int32_t result);
// Handles `Open()` result for `form_loader_`.
void DidFormOpen(int32_t result);
// Performs tasks necessary when the document is loaded in print preview mode.
void OnPrintPreviewLoaded();
@ -595,9 +589,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
// Whether the document is in edit mode.
bool edit_mode_ = false;
// Used for submitting forms.
std::unique_ptr<UrlLoader> form_loader_;
// Assigned a value only between `PrintBegin()` and `PrintEnd()` calls.
absl::optional<blink::WebPrintParams> print_params_;

@ -17,6 +17,7 @@
#include "base/i18n/char_iterator.h"
#include "base/i18n/string_search.h"
#include "base/i18n/time_formatting.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
@ -636,6 +637,31 @@ std::string PdfViewWebPlugin::Prompt(const std::string& question,
.Utf8();
}
void PdfViewWebPlugin::SubmitForm(const std::string& url,
const void* data,
int length) {
// `url` might be a relative URL. Resolve it against the document's URL.
// TODO(crbug.com/1322928): Probably redundant with `Client::CompleteURL()`.
GURL resolved_url = GURL(GetURL()).Resolve(url);
if (!resolved_url.is_valid())
return;
UrlRequest request;
request.url = resolved_url.spec();
request.method = "POST";
request.body.assign(static_cast<const char*>(data), length);
form_loader_ = CreateUrlLoaderInternal();
form_loader_->Open(request, base::BindOnce(&PdfViewWebPlugin::DidFormOpen,
weak_factory_.GetWeakPtr()));
}
void PdfViewWebPlugin::DidFormOpen(int32_t result) {
// TODO(crbug.com/719344): Process response.
LOG_IF(ERROR, result != kSuccess) << "DidFormOpen failed: " << result;
form_loader_.reset();
}
std::vector<PDFEngine::Client::SearchStringResult>
PdfViewWebPlugin::SearchString(const char16_t* string,
const char16_t* term,

@ -252,6 +252,9 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
bool Confirm(const std::string& message) override;
std::string Prompt(const std::string& question,
const std::string& default_answer) override;
void SubmitForm(const std::string& url,
const void* data,
int length) override;
std::vector<SearchStringResult> SearchString(const char16_t* string,
const char16_t* term,
bool case_sensitive) override;
@ -335,6 +338,9 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// Sends whether to do smooth scrolling.
void SendSetSmoothScrolling();
// Handles `Open()` result for `form_loader_`.
void DidFormOpen(int32_t result);
// Recalculates values that depend on scale factors.
void UpdateScaledValues();
@ -441,6 +447,9 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// The plugin rect in CSS pixels.
gfx::Rect css_plugin_rect_;
// Used for submitting forms.
std::unique_ptr<UrlLoader> form_loader_;
// May be null in unit tests.
std::unique_ptr<PdfAccessibilityDataHandler> const
pdf_accessibility_data_handler_;