Commit 7e04bf85 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Chromium LUCI CQ

Send bookmarks and attachments separately from PDF metadata

With the addition of more document metadata (i.e. properties), split
the sending of bookmarks and attachments so they don't get mixed up with
what will now be the actual metadata.

Additionally, don't send bookmarks or attachments if the document
doesn't have any.

Bug: 93619
Change-Id: I4c327c508cf55f207c5ef36239097e7d20a1571e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2608499
Commit-Queue: Stephen Martinis <martiniss@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840922}
parent d9f4fd7c
...@@ -66,8 +66,6 @@ let NavigateMessageData; ...@@ -66,8 +66,6 @@ let NavigateMessageData;
* @typedef {{ * @typedef {{
* type: string, * type: string,
* title: string, * title: string,
* attachments: !Array<!Attachment>,
* bookmarks: !Array<!Bookmark>,
* canSerializeDocument: boolean, * canSerializeDocument: boolean,
* }} * }}
*/ */
...@@ -900,9 +898,19 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -900,9 +898,19 @@ export class PDFViewerElement extends PDFViewerBaseElement {
handlePluginMessage(e) { handlePluginMessage(e) {
const data = e.detail; const data = e.detail;
switch (data.type.toString()) { switch (data.type.toString()) {
case 'attachments':
this.setAttachments_(
/** @type {{ attachmentsData: !Array<!Attachment> }} */ (data)
.attachmentsData);
return;
case 'beep': case 'beep':
this.handleBeep_(); this.handleBeep_();
return; return;
case 'bookmarks':
this.setBookmarks_(
/** @type {{ bookmarksData: !Array<!Bookmark> }} */ (data)
.bookmarksData);
return;
case 'documentDimensions': case 'documentDimensions':
this.setDocumentDimensions( this.setDocumentDimensions(
/** @type {!DocumentDimensionsMessageData} */ (data)); /** @type {!DocumentDimensionsMessageData} */ (data));
...@@ -1028,6 +1036,24 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1028,6 +1036,24 @@ export class PDFViewerElement extends PDFViewerBaseElement {
this.navigator_.navigate(url, disposition); this.navigator_.navigate(url, disposition);
} }
/**
* Sets the document attachment data.
* @param {!Array<!Attachment>} attachments
* @private
*/
setAttachments_(attachments) {
this.attachments_ = attachments;
}
/**
* Sets the document bookmarks data.
* @param {!Array<!Bookmark>} bookmarks
* @private
*/
setBookmarks_(bookmarks) {
this.bookmarks_ = bookmarks;
}
/** /**
* Sets document metadata from the current controller. * Sets document metadata from the current controller.
* @param {!MetadataMessageData} metadata * @param {!MetadataMessageData} metadata
...@@ -1036,8 +1062,6 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1036,8 +1062,6 @@ export class PDFViewerElement extends PDFViewerBaseElement {
setDocumentMetadata_(metadata) { setDocumentMetadata_(metadata) {
this.title_ = metadata.title || getFilenameFromURL(this.originalUrl); this.title_ = metadata.title || getFilenameFromURL(this.originalUrl);
document.title = this.title_; document.title = this.title_;
this.attachments_ = metadata.attachments;
this.bookmarks_ = metadata.bookmarks;
this.canSerializeDocument_ = metadata.canSerializeDocument; this.canSerializeDocument_ = metadata.canSerializeDocument;
} }
......
...@@ -121,10 +121,14 @@ constexpr char kJSLoadProgressType[] = "loadProgress"; ...@@ -121,10 +121,14 @@ constexpr char kJSLoadProgressType[] = "loadProgress";
constexpr char kJSProgressPercentage[] = "progress"; constexpr char kJSProgressPercentage[] = "progress";
// Document print preview loaded (Plugin -> Page) // Document print preview loaded (Plugin -> Page)
constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded"; constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded";
// Metadata // Attachments (Plugin -> Page)
constexpr char kJSAttachmentsType[] = "attachments";
constexpr char kJSAttachmentsData[] = "attachmentsData";
// Bookmarks (Plugin -> Page)
constexpr char kJSBookmarksType[] = "bookmarks";
constexpr char kJSBookmarksData[] = "bookmarksData";
// Metadata (Plugin -> Page)
constexpr char kJSMetadataType[] = "metadata"; constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSAttachments[] = "attachments";
constexpr char kJSBookmarks[] = "bookmarks";
constexpr char kJSTitle[] = "title"; constexpr char kJSTitle[] = "title";
constexpr char kJSCanSerializeDocument[] = "canSerializeDocument"; constexpr char kJSCanSerializeDocument[] = "canSerializeDocument";
// Get password (Plugin -> Page) // Get password (Plugin -> Page)
...@@ -1615,7 +1619,9 @@ void OutOfProcessInstance::DocumentLoadComplete( ...@@ -1615,7 +1619,9 @@ void OutOfProcessInstance::DocumentLoadComplete(
OnGeometryChanged(0, 0); OnGeometryChanged(0, 0);
} }
SendDocumentMetadata(); SendAttachments();
SendBookmarks();
SendMetadata();
SendLoadingProgress(/*percentage=*/100); SendLoadingProgress(/*percentage=*/100);
if (accessibility_state_ == ACCESSIBILITY_STATE_PENDING) if (accessibility_state_ == ACCESSIBILITY_STATE_PENDING)
...@@ -2339,7 +2345,32 @@ void OutOfProcessInstance::SendPrintPreviewLoadedNotification() { ...@@ -2339,7 +2345,32 @@ void OutOfProcessInstance::SendPrintPreviewLoadedNotification() {
PostMessage(loaded_message); PostMessage(loaded_message);
} }
void OutOfProcessInstance::SendDocumentMetadata() { void OutOfProcessInstance::SendAttachments() {
pp::VarArray attachments = GetDocumentAttachments();
if (attachments.GetLength() == 0)
return;
pp::VarDictionary attachments_message;
attachments_message.Set(pp::Var(kType), pp::Var(kJSAttachmentsType));
attachments_message.Set(pp::Var(kJSAttachmentsData), attachments);
PostMessage(attachments_message);
}
void OutOfProcessInstance::SendBookmarks() {
base::Value bookmarks = engine()->GetBookmarks();
DCHECK(bookmarks.is_list());
if (bookmarks.GetList().empty())
return;
pp::VarDictionary bookmarks_message;
bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType));
bookmarks_message.Set(pp::Var(kJSBookmarksData), VarFromValue(bookmarks));
PostMessage(bookmarks_message);
}
void OutOfProcessInstance::SendMetadata() {
pp::VarDictionary metadata_message; pp::VarDictionary metadata_message;
metadata_message.Set(pp::Var(kType), pp::Var(kJSMetadataType)); metadata_message.Set(pp::Var(kType), pp::Var(kJSMetadataType));
...@@ -2347,12 +2378,6 @@ void OutOfProcessInstance::SendDocumentMetadata() { ...@@ -2347,12 +2378,6 @@ void OutOfProcessInstance::SendDocumentMetadata() {
if (!base::TrimWhitespace(base::UTF8ToUTF16(title), base::TRIM_ALL).empty()) if (!base::TrimWhitespace(base::UTF8ToUTF16(title), base::TRIM_ALL).empty())
metadata_message.Set(pp::Var(kJSTitle), pp::Var(title)); metadata_message.Set(pp::Var(kJSTitle), pp::Var(title));
metadata_message.Set(pp::Var(kJSAttachments), GetDocumentAttachments());
base::Value bookmarks = engine()->GetBookmarks();
DCHECK(bookmarks.is_list());
metadata_message.Set(pp::Var(kJSBookmarks), VarFromValue(bookmarks));
metadata_message.Set( metadata_message.Set(
pp::Var(kJSCanSerializeDocument), pp::Var(kJSCanSerializeDocument),
pp::Var(IsSaveDataSizeValid(engine()->GetLoadedByteSize()))); pp::Var(IsSaveDataSizeValid(engine()->GetLoadedByteSize())));
......
...@@ -278,8 +278,14 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -278,8 +278,14 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Send a notification that the print preview has loaded. // Send a notification that the print preview has loaded.
void SendPrintPreviewLoadedNotification(); void SendPrintPreviewLoadedNotification();
// Send document metadata. (e.g. PDF title, attachments and bookmarks.) // Send attachments.
void SendDocumentMetadata(); void SendAttachments();
// Send bookmarks.
void SendBookmarks();
// Send document metadata.
void SendMetadata();
// Send the loading progress, where |percentage| represents the progress, or // Send the loading progress, where |percentage| represents the progress, or
// -1 for loading error. // -1 for loading error.
......
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