[unseasoned-pdf] Migrate EnteredEditMode() to PdfViewPluginBase.
Hide the Pepper-only implementation pp::PDF::SetPluginCanSave() behind PdfViewPluginBase::SetPluginCanSave(), so that EnteredEditMode() can be migrated to PdfViewPluginBase. Bug: 1140629 Change-Id: I33174a24e87dc36178e970dba6b2ac27ba8af935 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2909507 Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Commit-Queue: Hui Yingst <nigi@chromium.org> Cr-Commit-Position: refs/heads/master@{#885639}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
74745fa888
commit
6b1a5438d8
@ -102,9 +102,6 @@ constexpr char kJSLoadPreviewPageType[] = "loadPreviewPage";
|
||||
constexpr char kJSPreviewPageUrl[] = "url";
|
||||
constexpr char kJSPreviewPageIndex[] = "index";
|
||||
|
||||
// Editing forms in document (Plugin -> Page)
|
||||
constexpr char kJSSetIsEditingType[] = "setIsEditing";
|
||||
|
||||
constexpr base::TimeDelta kFindResultCooldown =
|
||||
base::TimeDelta::FromMilliseconds(100);
|
||||
|
||||
@ -1100,13 +1097,13 @@ void OutOfProcessInstance::HandleSaveMessage(const pp::VarDictionary& dict) {
|
||||
case SaveRequestType::kAnnotation:
|
||||
// In annotation mode, assume the user will make edits and prefer saving
|
||||
// using the plugin data.
|
||||
pp::PDF::SetPluginCanSave(this, true);
|
||||
SetPluginCanSave(true);
|
||||
SaveToBuffer(dict.Get(pp::Var(kJSToken)).AsString());
|
||||
break;
|
||||
case SaveRequestType::kOriginal:
|
||||
pp::PDF::SetPluginCanSave(this, false);
|
||||
SetPluginCanSave(false);
|
||||
SaveToFile(dict.Get(pp::Var(kJSToken)).AsString());
|
||||
pp::PDF::SetPluginCanSave(this, edit_mode());
|
||||
SetPluginCanSave(edit_mode());
|
||||
break;
|
||||
case SaveRequestType::kEdited:
|
||||
SaveToBuffer(dict.Get(pp::Var(kJSToken)).AsString());
|
||||
@ -1222,6 +1219,10 @@ void OutOfProcessInstance::SetAccessibilityViewportInfo(
|
||||
pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &pp_viewport_info);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SetPluginCanSave(bool can_save) {
|
||||
pp::PDF::SetPluginCanSave(this, can_save);
|
||||
}
|
||||
|
||||
base::WeakPtr<PdfViewPluginBase> OutOfProcessInstance::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
@ -1241,15 +1242,6 @@ bool OutOfProcessInstance::IsPrintPreview() {
|
||||
return is_print_preview_;
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::EnteredEditMode() {
|
||||
set_edit_mode(true);
|
||||
pp::PDF::SetPluginCanSave(this, true);
|
||||
|
||||
pp::VarDictionary message;
|
||||
message.Set(kType, kJSSetIsEditingType);
|
||||
PostMessage(message);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SetSelectedText(const std::string& selected_text) {
|
||||
pp::PDF::SetSelectedText(this, selected_text.c_str());
|
||||
}
|
||||
|
@ -114,7 +114,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
void DocumentHasUnsupportedFeature(const std::string& feature) override;
|
||||
bool IsPrintPreview() override;
|
||||
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
|
||||
void EnteredEditMode() override;
|
||||
void SetSelectedText(const std::string& selected_text) override;
|
||||
void SetLinkUnderCursor(const std::string& link_under_cursor) override;
|
||||
bool IsValidLink(const std::string& url) override;
|
||||
@ -152,6 +151,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
void SetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info) override;
|
||||
void SetContentRestrictions(int content_restrictions) override;
|
||||
void SetPluginCanSave(bool can_save) override;
|
||||
void DidStartLoading() override;
|
||||
void DidStopLoading() override;
|
||||
void OnPrintPreviewLoaded() override;
|
||||
|
@ -361,6 +361,15 @@ void PdfViewPluginBase::SetIsSelecting(bool is_selecting) {
|
||||
SendMessage(std::move(message));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::EnteredEditMode() {
|
||||
edit_mode_ = true;
|
||||
SetPluginCanSave(true);
|
||||
|
||||
base::Value message(base::Value::Type::DICTIONARY);
|
||||
message.SetStringKey("type", "setIsEditing");
|
||||
SendMessage(std::move(message));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::DocumentFocusChanged(bool document_has_focus) {
|
||||
base::Value message(base::Value::Type::DICTIONARY);
|
||||
message.SetStringKey("type", "documentFocusChanged");
|
||||
|
@ -86,6 +86,7 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
void FormTextFieldFocusChange(bool in_focus) override;
|
||||
SkColor GetBackgroundColor() override;
|
||||
void SetIsSelecting(bool is_selecting) override;
|
||||
void EnteredEditMode() override;
|
||||
void DocumentFocusChanged(bool document_has_focus) override;
|
||||
|
||||
// PaintManager::Client
|
||||
@ -251,6 +252,10 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
// set by `chrome_pdf::ContentRestriction` enum values.
|
||||
virtual void SetContentRestrictions(int content_restrictions) = 0;
|
||||
|
||||
// Informs the embedder whether the plugin can handle save commands
|
||||
// internally.
|
||||
virtual void SetPluginCanSave(bool can_save) = 0;
|
||||
|
||||
// Sends start/stop loading notifications to the plugin's render frame.
|
||||
// TODO(crbug.com/702993): Evaluate whether these methods are needed when the
|
||||
// plugin is moved into a renderer process.
|
||||
|
@ -34,6 +34,7 @@ class FakePdfViewPluginBase : public PdfViewPluginBase {
|
||||
public:
|
||||
// Public for testing.
|
||||
using PdfViewPluginBase::ConsumeSaveToken;
|
||||
using PdfViewPluginBase::edit_mode;
|
||||
using PdfViewPluginBase::HandleMessage;
|
||||
|
||||
MOCK_METHOD(bool, Confirm, (const std::string&), (override));
|
||||
@ -114,6 +115,8 @@ class FakePdfViewPluginBase : public PdfViewPluginBase {
|
||||
|
||||
MOCK_METHOD(void, SetContentRestrictions, (int), (override));
|
||||
|
||||
MOCK_METHOD(void, SetPluginCanSave, (bool), (override));
|
||||
|
||||
MOCK_METHOD(void, DidStartLoading, (), (override));
|
||||
|
||||
MOCK_METHOD(void, DidStopLoading, (), (override));
|
||||
@ -135,6 +138,16 @@ class PdfViewPluginBaseTest : public testing::Test {
|
||||
FakePdfViewPluginBase fake_plugin_;
|
||||
};
|
||||
|
||||
TEST_F(PdfViewPluginBaseTest, EnteredEditMode) {
|
||||
fake_plugin_.EnteredEditMode();
|
||||
|
||||
base::Value expected_message(base::Value::Type::DICTIONARY);
|
||||
expected_message.SetStringKey("type", "setIsEditing");
|
||||
|
||||
EXPECT_TRUE(fake_plugin_.edit_mode());
|
||||
EXPECT_EQ(expected_message, fake_plugin_.sent_message());
|
||||
}
|
||||
|
||||
TEST_F(PdfViewPluginBaseTest, ConsumeSaveToken) {
|
||||
const std::string kTokenString("12345678901234567890");
|
||||
fake_plugin_.ConsumeSaveToken(kTokenString);
|
||||
|
@ -417,8 +417,6 @@ bool PdfViewWebPlugin::IsPrintPreview() {
|
||||
void PdfViewWebPlugin::SelectionChanged(const gfx::Rect& left,
|
||||
const gfx::Rect& right) {}
|
||||
|
||||
void PdfViewWebPlugin::EnteredEditMode() {}
|
||||
|
||||
void PdfViewWebPlugin::SetSelectedText(const std::string& selected_text) {
|
||||
selected_text_ = blink::WebString::FromUTF8(selected_text);
|
||||
container_wrapper_->TextSelectionChanged(
|
||||
@ -566,6 +564,10 @@ void PdfViewWebPlugin::SetContentRestrictions(int content_restrictions) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::SetPluginCanSave(bool can_save) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::DidStartLoading() {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
@ -133,7 +133,6 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
void DocumentHasUnsupportedFeature(const std::string& feature) override;
|
||||
bool IsPrintPreview() override;
|
||||
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
|
||||
void EnteredEditMode() override;
|
||||
void SetSelectedText(const std::string& selected_text) override;
|
||||
void SetLinkUnderCursor(const std::string& link_under_cursor) override;
|
||||
bool IsValidLink(const std::string& url) override;
|
||||
@ -183,6 +182,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
void SetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info) override;
|
||||
void SetContentRestrictions(int content_restrictions) override;
|
||||
void SetPluginCanSave(bool can_save) override;
|
||||
void DidStartLoading() override;
|
||||
void DidStopLoading() override;
|
||||
void OnPrintPreviewLoaded() override;
|
||||
|
Reference in New Issue
Block a user