[unseasoned-pdf] Migrate SaveToBuffer().
Migrate from a Pepper OutOfProcessInstance implementation to a common PdfViewPluginBase one. Bug: 1109796 Change-Id: Id5dadd38bb98ed706ba9778f05beea2f053a0c9a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2740717 Commit-Queue: Hui Yingst <nigi@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Cr-Commit-Position: refs/heads/master@{#861253}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
69fc2acf31
commit
65fb894089
@ -45,7 +45,6 @@
|
||||
#include "pdf/ppapi_migration/url_loader.h"
|
||||
#include "pdf/ppapi_migration/value_conversions.h"
|
||||
#include "pdf/thumbnail.h"
|
||||
#include "pdf/ui/file_name.h"
|
||||
#include "pdf/ui/format_page_size.h"
|
||||
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
@ -118,10 +117,6 @@ constexpr char kJSAttachmentDataToSave[] = "dataToSave";
|
||||
constexpr char kJSSaveType[] = "save";
|
||||
constexpr char kJSToken[] = "token";
|
||||
constexpr char kJSSaveRequestType[] = "saveRequestType";
|
||||
// Save data (Plugin -> Page)
|
||||
constexpr char kJSSaveDataType[] = "saveData";
|
||||
constexpr char kJSFileName[] = "fileName";
|
||||
constexpr char kJSDataToSave[] = "dataToSave";
|
||||
// Reset print preview mode (Page -> Plugin)
|
||||
constexpr char kJSResetPrintPreviewModeType[] = "resetPrintPreviewMode";
|
||||
constexpr char kJSPrintPreviewUrl[] = "url";
|
||||
@ -1035,41 +1030,6 @@ void OutOfProcessInstance::NotifySelectedFindResultChanged(
|
||||
SelectedFindResultChanged(current_find_index);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SaveToBuffer(const std::string& token) {
|
||||
engine()->KillFormFocus();
|
||||
|
||||
pp::VarDictionary message;
|
||||
message.Set(kType, kJSSaveDataType);
|
||||
message.Set(kJSToken, pp::Var(token));
|
||||
message.Set(kJSFileName, pp::Var(GetFileNameForSaveFromUrl(GetURL())));
|
||||
// This will be overwritten if the save is successful.
|
||||
message.Set(kJSDataToSave, pp::Var(pp::Var::Null()));
|
||||
|
||||
if (edit_mode()) {
|
||||
std::vector<uint8_t> data = engine()->GetSaveData();
|
||||
if (IsSaveDataSizeValid(data.size())) {
|
||||
pp::VarArrayBuffer buffer(data.size());
|
||||
std::copy(data.begin(), data.end(),
|
||||
reinterpret_cast<char*>(buffer.Map()));
|
||||
message.Set(kJSDataToSave, buffer);
|
||||
}
|
||||
} else {
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
uint32_t length = engine()->GetLoadedByteSize();
|
||||
if (IsSaveDataSizeValid(length)) {
|
||||
pp::VarArrayBuffer buffer(length);
|
||||
if (engine()->ReadLoadedBytes(length, buffer.Map())) {
|
||||
message.Set(kJSDataToSave, buffer);
|
||||
}
|
||||
}
|
||||
#else
|
||||
NOTREACHED();
|
||||
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
}
|
||||
|
||||
PostMessage(message);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SaveToFile(const std::string& token) {
|
||||
engine()->KillFormFocus();
|
||||
ConsumeSaveToken(token);
|
||||
|
@ -172,7 +172,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
|
||||
bool CanSaveEdits() const;
|
||||
void SaveToFile(const std::string& token);
|
||||
void SaveToBuffer(const std::string& token);
|
||||
|
||||
void FormDidOpen(int32_t result);
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/values.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "net/base/escape.h"
|
||||
#include "pdf/accessibility.h"
|
||||
#include "pdf/accessibility_structs.h"
|
||||
@ -36,6 +37,7 @@
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/ppapi_migration/image.h"
|
||||
#include "pdf/ppapi_migration/url_loader.h"
|
||||
#include "pdf/ui/file_name.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
@ -286,6 +288,36 @@ void PdfViewPluginBase::HandleMessage(const base::Value& message) {
|
||||
(this->*handler)(message);
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::SaveToBuffer(const std::string& token) {
|
||||
engine()->KillFormFocus();
|
||||
|
||||
base::Value message(base::Value::Type::DICTIONARY);
|
||||
message.SetStringKey("type", "saveData");
|
||||
message.SetStringKey("token", token);
|
||||
message.SetStringKey("fileName", GetFileNameForSaveFromUrl(url_));
|
||||
|
||||
base::Value data_to_save;
|
||||
if (edit_mode_) {
|
||||
base::Value::BlobStorage data = engine()->GetSaveData();
|
||||
if (IsSaveDataSizeValid(data.size()))
|
||||
data_to_save = base::Value(std::move(data));
|
||||
} else {
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
uint32_t length = engine()->GetLoadedByteSize();
|
||||
if (IsSaveDataSizeValid(length)) {
|
||||
base::Value::BlobStorage data(length);
|
||||
if (engine()->ReadLoadedBytes(length, data.data()))
|
||||
data_to_save = base::Value(std::move(data));
|
||||
}
|
||||
#else
|
||||
NOTREACHED();
|
||||
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
}
|
||||
|
||||
message.SetKey("dataToSave", std::move(data_to_save));
|
||||
SendMessage(std::move(message));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::ConsumeSaveToken(const std::string& token) {
|
||||
base::Value message(base::Value::Type::DICTIONARY);
|
||||
message.SetStringKey("type", "consumeSaveToken");
|
||||
|
@ -149,6 +149,8 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
// non-blocking.
|
||||
virtual void SendMessage(base::Value message) = 0;
|
||||
|
||||
void SaveToBuffer(const std::string& token);
|
||||
|
||||
// Consumes a token for saving the document.
|
||||
void ConsumeSaveToken(const std::string& token);
|
||||
|
||||
|
Reference in New Issue
Block a user