Skip to content

Commit

Permalink
[unseasoned-pdf] Introduce PdfViewPluginBase::SendMessage()
Browse files Browse the repository at this point in the history
Also implement the pure virtual method for both derived classes of
PdfViewPluginBase.

The interface will allow for PostMessage()'ing from common
implementations of the plugins.

Bug: 1109796
Change-Id: I9377b550acecb1411a63e1e87604f67c7b0732e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2670884
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#851827}
  • Loading branch information
Daniel Hosseinian authored and Chromium LUCI CQ committed Feb 8, 2021
1 parent ea19ce4 commit 59c11b3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,10 @@ void OutOfProcessInstance::DidOpenPreview(std::unique_ptr<UrlLoader> loader,
}
}

void OutOfProcessInstance::SendMessage(base::Value message) {
PostMessage(VarFromValue(message));
}

void OutOfProcessInstance::InitImageData(const gfx::Size& size) {
pepper_image_data_ =
pp::ImageData(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, PPSizeFromSize(size),
Expand Down
1 change: 1 addition & 0 deletions pdf/out_of_process_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) override;
void SendMessage(base::Value message) override;
void InitImageData(const gfx::Size& size) override;
void OnGeometryChanged(double old_zoom, float old_device_scale) override;
Image GetPluginImageData() const override;
Expand Down
5 changes: 5 additions & 0 deletions pdf/pdf_view_plugin_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
// Handles `postMessage()` calls from the embedder.
void HandleMessage(const base::Value& message);

// Enqueues a "message" event carrying `message` to the embedder. Messages are
// guaranteed to be received in the order that they are sent. This method is
// non-blocking.
virtual void SendMessage(base::Value message) = 0;

// Initialize image buffer(s) according to the new context size.
virtual void InitImageData(const gfx::Size& size) = 0;

Expand Down
4 changes: 4 additions & 0 deletions pdf/pdf_view_web_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ void PdfViewWebPlugin::DidOpenPreview(std::unique_ptr<UrlLoader> loader,
NOTIMPLEMENTED();
}

void PdfViewWebPlugin::SendMessage(base::Value message) {
post_message_sender_.Post(std::move(message));
}

void PdfViewWebPlugin::InitImageData(const gfx::Size& size) {
mutable_image_data() = CreateN32PremulSkBitmap(gfx::SizeToSkISize(size));
}
Expand Down
1 change: 1 addition & 0 deletions pdf/pdf_view_web_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) override;
void SendMessage(base::Value message) override;
void InitImageData(const gfx::Size& size) override;
void OnGeometryChanged(double old_zoom, float old_device_scale) override;

Expand Down

0 comments on commit 59c11b3

Please sign in to comment.