Commit 88c98070 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Enable thumbnail requests to the PDF plugin

Handle messages requesting thumbnails from the PDF plugin.
OutOfProcessInstance provides the callbacks for responding to the
requests when the thumbnails are ready and passes the request to the PDF
engine.

Bug: 652400
Change-Id: I2ed5acfa4fcfbb0167a38a6149017756f44c36d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2336312
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810854}
parent 5df0acca
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <algorithm> // for min/max() #include <algorithm> // for min/max()
#include <cmath> // for log() and pow() #include <cmath> // for log() and pow()
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
#include "pdf/ppapi_migration/input_event_conversions.h" #include "pdf/ppapi_migration/input_event_conversions.h"
#include "pdf/ppapi_migration/url_loader.h" #include "pdf/ppapi_migration/url_loader.h"
#include "pdf/ppapi_migration/value_conversions.h" #include "pdf/ppapi_migration/value_conversions.h"
#include "pdf/thumbnail.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_pdf.h"
...@@ -225,6 +227,15 @@ constexpr char kJSFieldFocus[] = "focused"; ...@@ -225,6 +227,15 @@ constexpr char kJSFieldFocus[] = "focused";
constexpr char kJSDocumentFocusChangedType[] = "documentFocusChanged"; constexpr char kJSDocumentFocusChangedType[] = "documentFocusChanged";
constexpr char kJSDocumentHasFocus[] = "hasFocus"; constexpr char kJSDocumentHasFocus[] = "hasFocus";
// Request the thumbnail image for a particular page (Page -> Plugin)
constexpr char kJSGetThumbnailType[] = "getThumbnail";
constexpr char kJSGetThumbnailPage[] = "page";
// Reply with the image data of the requested thumbnail (Plugin -> Page)
constexpr char kJSGetThumbnailReplyType[] = "getThumbnailReply";
constexpr char kJSGetThumbnailImageData[] = "imageData";
constexpr char kJSGetThumbnailWidth[] = "width";
constexpr char kJSGetThumbnailHeight[] = "height";
constexpr int kFindResultCooldownMs = 100; constexpr int kFindResultCooldownMs = 100;
// Do not save files with over 100 MB. This cap should be kept in sync with and // Do not save files with over 100 MB. This cap should be kept in sync with and
...@@ -618,6 +629,8 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) { ...@@ -618,6 +629,8 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
HandleGetSelectedTextMessage(dict); HandleGetSelectedTextMessage(dict);
} else if (type == kJSGetNamedDestinationType) { } else if (type == kJSGetNamedDestinationType) {
HandleGetNamedDestinationMessage(dict); HandleGetNamedDestinationMessage(dict);
} else if (type == kJSGetThumbnailType) {
HandleGetThumbnailMessage(dict);
} else { } else {
NOTREACHED(); NOTREACHED();
} }
...@@ -1669,6 +1682,22 @@ void OutOfProcessInstance::HandleGetSelectedTextMessage( ...@@ -1669,6 +1682,22 @@ void OutOfProcessInstance::HandleGetSelectedTextMessage(
PostMessage(reply); PostMessage(reply);
} }
void OutOfProcessInstance::HandleGetThumbnailMessage(
const pp::VarDictionary& dict) {
if (!dict.Get(pp::Var(kJSGetThumbnailPage)).is_number() ||
!dict.Get(pp::Var(kJSMessageId)).is_string()) {
NOTREACHED();
return;
}
const int page_index = dict.Get(pp::Var(kJSGetThumbnailPage)).AsInt();
engine()->RequestThumbnail(
page_index, device_scale_,
base::BindOnce(&OutOfProcessInstance::SendThumbnail,
weak_factory_.GetWeakPtr(),
dict.Get(pp::Var(kJSMessageId)).AsString()));
}
void OutOfProcessInstance::HandleLoadPreviewPageMessage( void OutOfProcessInstance::HandleLoadPreviewPageMessage(
const pp::VarDictionary& dict) { const pp::VarDictionary& dict) {
if (!(dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && if (!(dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() &&
...@@ -2232,6 +2261,25 @@ void OutOfProcessInstance::SendLoadingProgress(double percentage) { ...@@ -2232,6 +2261,25 @@ void OutOfProcessInstance::SendLoadingProgress(double percentage) {
PostMessage(progress_message); PostMessage(progress_message);
} }
void OutOfProcessInstance::SendThumbnail(const std::string& message_id,
Thumbnail thumbnail) {
pp::VarDictionary reply;
reply.Set(pp::Var(kType), pp::Var(kJSGetThumbnailReplyType));
reply.Set(pp::Var(kJSMessageId), message_id);
const SkBitmap& bitmap = thumbnail.bitmap();
const size_t buffer_size = bitmap.computeByteSize();
pp::VarArrayBuffer buffer(buffer_size);
memcpy(buffer.Map(), bitmap.getPixels(), buffer_size);
reply.Set(pp::Var(kJSGetThumbnailImageData), buffer);
buffer.Unmap();
reply.Set(pp::Var(kJSGetThumbnailWidth), bitmap.width());
reply.Set(pp::Var(kJSGetThumbnailHeight), bitmap.height());
PostMessage(reply);
}
void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) { void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) {
// TODO(raymes): Move this function to PPB_UMA_Private. // TODO(raymes): Move this function to PPB_UMA_Private.
pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
......
...@@ -43,6 +43,7 @@ namespace chrome_pdf { ...@@ -43,6 +43,7 @@ namespace chrome_pdf {
class Graphics; class Graphics;
class PaintReadyRect; class PaintReadyRect;
class PDFiumEngine; class PDFiumEngine;
class Thumbnail;
class UrlLoader; class UrlLoader;
class OutOfProcessInstance : public PdfViewPluginBase, class OutOfProcessInstance : public PdfViewPluginBase,
...@@ -188,6 +189,7 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -188,6 +189,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
void HandleGetNamedDestinationMessage(const pp::VarDictionary& dict); void HandleGetNamedDestinationMessage(const pp::VarDictionary& dict);
void HandleGetPasswordCompleteMessage(const pp::VarDictionary& dict); void HandleGetPasswordCompleteMessage(const pp::VarDictionary& dict);
void HandleGetSelectedTextMessage(const pp::VarDictionary& dict); void HandleGetSelectedTextMessage(const pp::VarDictionary& dict);
void HandleGetThumbnailMessage(const pp::VarDictionary& dict);
void HandleLoadPreviewPageMessage(const pp::VarDictionary& dict); void HandleLoadPreviewPageMessage(const pp::VarDictionary& dict);
void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict); void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict);
void HandleSaveAttachmentMessage(const pp::VarDictionary& dict); void HandleSaveAttachmentMessage(const pp::VarDictionary& dict);
...@@ -287,6 +289,9 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -287,6 +289,9 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// -1 for loading error. // -1 for loading error.
void SendLoadingProgress(double percentage); void SendLoadingProgress(double percentage);
// Sends the thumbnail image data.
void SendThumbnail(const std::string& message_id, Thumbnail thumbnail);
// Bound the given scroll offset to the document. // Bound the given scroll offset to the document.
pp::FloatPoint BoundScrollOffsetToDocument( pp::FloatPoint BoundScrollOffsetToDocument(
const pp::FloatPoint& scroll_offset); const pp::FloatPoint& scroll_offset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment