0

[unseasoned-pdf] Migrate edit_mode_.

Migrate `edit_mode_` to PdfViewPluginBase and provide an accessor and
a mutator for it, so that it can be shared by both PdfViewWebPlugin
and OutOfProcessInstance.

Bug: 1140629
Change-Id: I8a153df524d07dd4d097389a9b0fcf977ed8d904
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2737529
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#860077}
This commit is contained in:
Hui Yingst
2021-03-05 01:55:25 +00:00
committed by Chromium LUCI CQ
parent 19fd12b30c
commit b9299fe4c3
3 changed files with 11 additions and 7 deletions

@ -655,9 +655,9 @@ bool OutOfProcessInstance::Init(uint32_t argc,
// Not all edits go through the PDF plugin's form filler. The plugin instance
// can be restarted by exiting annotation mode on ChromeOS, which can set the
// document to an edited state.
edit_mode_ = has_edits;
set_edit_mode(has_edits);
#if !BUILDFLAG(IS_CHROMEOS_ASH)
DCHECK(!edit_mode_);
DCHECK(!edit_mode());
#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
pp::PDF::SetCrashData(GetPluginInstance(), original_url, top_level_url);
@ -1046,7 +1046,7 @@ void OutOfProcessInstance::SaveToBuffer(const std::string& token) {
// This will be overwritten if the save is successful.
message.Set(kJSDataToSave, pp::Var(pp::Var::Null()));
if (edit_mode_) {
if (edit_mode()) {
std::vector<uint8_t> data = engine()->GetSaveData();
if (IsSaveDataSizeValid(data.size())) {
pp::VarArrayBuffer buffer(data.size());
@ -1369,7 +1369,7 @@ void OutOfProcessInstance::HandleSaveMessage(const pp::VarDictionary& dict) {
case SaveRequestType::kOriginal:
pp::PDF::SetPluginCanSave(this, false);
SaveToFile(dict.Get(pp::Var(kJSToken)).AsString());
pp::PDF::SetPluginCanSave(this, edit_mode_);
pp::PDF::SetPluginCanSave(this, edit_mode());
break;
case SaveRequestType::kEdited:
SaveToBuffer(dict.Get(pp::Var(kJSToken)).AsString());
@ -1558,7 +1558,7 @@ bool OutOfProcessInstance::IsPrintPreview() {
}
void OutOfProcessInstance::EnteredEditMode() {
edit_mode_ = true;
set_edit_mode(true);
pp::PDF::SetPluginCanSave(this, true);
pp::VarDictionary message;

@ -343,8 +343,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// document finishes loading.
bool did_call_start_loading_ = false;
bool edit_mode_ = false;
base::WeakPtrFactory<OutOfProcessInstance> weak_factory_{this};
};

@ -269,6 +269,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
AccessibilityState accessibility_state() { return accessibility_state_; }
bool edit_mode() const { return edit_mode_; }
void set_edit_mode(bool edit_mode) { edit_mode_ = edit_mode; }
private:
// Message handlers.
void HandleDisplayAnnotationsMessage(const base::Value& message);
@ -381,6 +384,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
// The next accessibility page index, used to track interprocess calls when
// reconstructing the tree for new document layouts.
int32_t next_accessibility_page_index_ = 0;
// Whether the document is in edit mode.
bool edit_mode_ = false;
};
} // namespace chrome_pdf