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 @@ ...@@ -2,6 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/**
* @typedef {{
* name: string,
* size: number,
* readable: boolean,
* }}
*/
export let Attachment;
/** @enum {string} */ /** @enum {string} */
export const DisplayAnnotationsAction = { export const DisplayAnnotationsAction = {
DISPLAY_ANNOTATIONS: 'display-annotations', DISPLAY_ANNOTATIONS: 'display-annotations',
......
...@@ -23,7 +23,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min. ...@@ -23,7 +23,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.
import {Bookmark} from './bookmark_type.js'; import {Bookmark} from './bookmark_type.js';
import {BrowserApi} from './browser_api.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'; import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js';
// <if expr="chromeos"> // <if expr="chromeos">
import {InkController} from './ink_controller.js'; import {InkController} from './ink_controller.js';
...@@ -51,6 +51,7 @@ let NavigateMessageData; ...@@ -51,6 +51,7 @@ let NavigateMessageData;
* @typedef {{ * @typedef {{
* type: string, * type: string,
* title: string, * title: string,
* attachments: !Array<!Attachment>,
* bookmarks: !Array<!Bookmark>, * bookmarks: !Array<!Bookmark>,
* canSerializeDocument: boolean, * canSerializeDocument: boolean,
* }} * }}
...@@ -112,6 +113,8 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -112,6 +113,8 @@ export class PDFViewerElement extends PDFViewerBaseElement {
value: false, value: false,
}, },
attachments_: Array,
bookmarks_: Array, bookmarks_: Array,
documentHasFocus_: { documentHasFocus_: {
...@@ -164,6 +167,9 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -164,6 +167,9 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/** @private {boolean} */ /** @private {boolean} */
this.annotationMode_ = false; this.annotationMode_ = false;
/** @private {!Array<!Attachment>} */
this.attachments_ = [];
/** @private {!Array<!Bookmark>} */ /** @private {!Array<!Bookmark>} */
this.bookmarks_ = []; this.bookmarks_ = [];
...@@ -812,6 +818,7 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -812,6 +818,7 @@ 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.bookmarks_ = metadata.bookmarks;
this.canSerializeDocument_ = metadata.canSerializeDocument; this.canSerializeDocument_ = metadata.canSerializeDocument;
} }
......
...@@ -119,6 +119,7 @@ constexpr char kJSProgressPercentage[] = "progress"; ...@@ -119,6 +119,7 @@ constexpr char kJSProgressPercentage[] = "progress";
constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded"; constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded";
// Metadata // Metadata
constexpr char kJSMetadataType[] = "metadata"; constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSAttachments[] = "attachments";
constexpr char kJSBookmarks[] = "bookmarks"; constexpr char kJSBookmarks[] = "bookmarks";
constexpr char kJSTitle[] = "title"; constexpr char kJSTitle[] = "title";
constexpr char kJSCanSerializeDocument[] = "canSerializeDocument"; constexpr char kJSCanSerializeDocument[] = "canSerializeDocument";
...@@ -2215,6 +2216,8 @@ void OutOfProcessInstance::SendDocumentMetadata() { ...@@ -2215,6 +2216,8 @@ 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());
pp::VarArray bookmarks = engine()->GetBookmarks(); pp::VarArray bookmarks = engine()->GetBookmarks();
metadata_message.Set(pp::Var(kJSBookmarks), bookmarks); metadata_message.Set(pp::Var(kJSBookmarks), bookmarks);
......
...@@ -281,7 +281,7 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -281,7 +281,7 @@ 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 and bookmarks.) // Send document metadata. (e.g. PDF title, attachments and bookmarks.)
void SendDocumentMetadata(); void SendDocumentMetadata();
// Send the loading progress, where |percentage| represents the progress, or // 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