Commit d3af33f9 authored by Hui Yingst's avatar Hui Yingst Committed by Commit Bot

Send the PDF's attachment information to the front end.

This CL adds an array of |Attachment| in MetadataMessageData so that the
back end can send the pp::VarArray of attachment information with the
rest of the metadata to the front end, and then stores it.

Bug: 177188
Change-Id: I676c8ecf86321eb0cbd2d95f328d76ed5eec0e4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335032
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804344}
parent 1b31f942
......@@ -2,6 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @typedef {{
* name: string,
* size: number,
* readable: boolean,
* }}
*/
export let Attachment;
/** @enum {string} */
export const DisplayAnnotationsAction = {
DISPLAY_ANNOTATIONS: 'display-annotations',
......
......@@ -23,7 +23,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.
import {Bookmark} from './bookmark_type.js';
import {BrowserApi} from './browser_api.js';
import {FittingType, Point, SaveRequestType} from './constants.js';
import {Attachment, FittingType, Point, SaveRequestType} from './constants.js';
import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js';
// <if expr="chromeos">
import {InkController} from './ink_controller.js';
......@@ -51,6 +51,7 @@ let NavigateMessageData;
* @typedef {{
* type: string,
* title: string,
* attachments: !Array<!Attachment>,
* bookmarks: !Array<!Bookmark>,
* canSerializeDocument: boolean,
* }}
......@@ -112,6 +113,8 @@ export class PDFViewerElement extends PDFViewerBaseElement {
value: false,
},
attachments_: Array,
bookmarks_: Array,
documentHasFocus_: {
......@@ -164,6 +167,9 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/** @private {boolean} */
this.annotationMode_ = false;
/** @private {!Array<!Attachment>} */
this.attachments_ = [];
/** @private {!Array<!Bookmark>} */
this.bookmarks_ = [];
......@@ -812,6 +818,7 @@ export class PDFViewerElement extends PDFViewerBaseElement {
setDocumentMetadata_(metadata) {
this.title_ = metadata.title || getFilenameFromURL(this.originalUrl);
document.title = this.title_;
this.attachments_ = metadata.attachments;
this.bookmarks_ = metadata.bookmarks;
this.canSerializeDocument_ = metadata.canSerializeDocument;
}
......
......@@ -119,6 +119,7 @@ constexpr char kJSProgressPercentage[] = "progress";
constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded";
// Metadata
constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSAttachments[] = "attachments";
constexpr char kJSBookmarks[] = "bookmarks";
constexpr char kJSTitle[] = "title";
constexpr char kJSCanSerializeDocument[] = "canSerializeDocument";
......@@ -2215,6 +2216,8 @@ void OutOfProcessInstance::SendDocumentMetadata() {
if (!base::TrimWhitespace(base::UTF8ToUTF16(title), base::TRIM_ALL).empty())
metadata_message.Set(pp::Var(kJSTitle), pp::Var(title));
metadata_message.Set(pp::Var(kJSAttachments), GetDocumentAttachments());
pp::VarArray bookmarks = engine()->GetBookmarks();
metadata_message.Set(pp::Var(kJSBookmarks), bookmarks);
......
......@@ -281,7 +281,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Send a notification that the print preview has loaded.
void SendPrintPreviewLoadedNotification();
// Send document metadata. (e.g. PDF title and bookmarks.)
// Send document metadata. (e.g. PDF title, attachments and bookmarks.)
void SendDocumentMetadata();
// Send the loading progress, where |percentage| represents the progress, or
......
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