This commit is contained in:
deepak1556 2023-11-14 02:13:53 +09:00
Родитель e13b8ec9fa
Коммит 88ae9b43ea
1 изменённых файлов: 17 добавлений и 601 удалений

Просмотреть файл

@ -13,639 +13,55 @@ This patch can be removed should we choose to support chrome.fileSystem
or support it enough to fix the crash.
diff --git a/chrome/browser/resources/pdf/pdf_viewer.ts b/chrome/browser/resources/pdf/pdf_viewer.ts
index 63e6e4ea24cd7e1df3963096b54573b4acfccedf..26caec6fbc95d4ba0f9d18b9ae141cd27566d757 100644
index 63e6e4ea24cd7e1df3963096b54573b4acfccedf..2f006d4b12f21035d5f9e712ccb2dc87bf635322 100644
--- a/chrome/browser/resources/pdf/pdf_viewer.ts
+++ b/chrome/browser/resources/pdf/pdf_viewer.ts
@@ -15,32 +15,32 @@ import './pdf_viewer_shared_style.css.js';
import 'chrome://resources/cr_elements/cr_hidden_style.css.js';
import 'chrome://resources/cr_elements/cr_shared_vars.css.js';
-import {assert, assertNotReached} from 'chrome://resources/js/assert.js';
-import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
-import {listenOnce} from 'chrome://resources/js/util.js';
-
-import {Bookmark} from './bookmark_type.js';
-import {BrowserApi} from './browser_api.js';
-import {Attachment, DocumentMetadata, ExtendedKeyEvent, FittingType, Point, SaveRequestType} from './constants.js';
-import {MessageData, PluginController} from './controller.js';
+import { assert, assertNotReached } from 'chrome://resources/js/assert.js';
+import { loadTimeData } from 'chrome://resources/js/load_time_data.js';
+import { listenOnce } from 'chrome://resources/js/util.js';
+
+import { Bookmark } from './bookmark_type.js';
+import { BrowserApi } from './browser_api.js';
+import { Attachment, DocumentMetadata, ExtendedKeyEvent, FittingType, Point, SaveRequestType } from './constants.js';
+import { MessageData, PluginController } from './controller.js';
// <if expr="enable_ink">
-import {ContentController} from './controller.js';
+import { ContentController } from './controller.js';
// </if>
-import {ChangePageAndXyDetail, ChangePageDetail, ChangePageOrigin, NavigateDetail} from './elements/viewer-bookmark.js';
-import {ViewerErrorDialogElement} from './elements/viewer-error-dialog.js';
-import {ViewerPasswordDialogElement} from './elements/viewer-password-dialog.js';
-import {ViewerPdfSidenavElement} from './elements/viewer-pdf-sidenav.js';
-import {ViewerToolbarElement} from './elements/viewer-toolbar.js';
+import { ChangePageAndXyDetail, ChangePageDetail, ChangePageOrigin, NavigateDetail } from './elements/viewer-bookmark.js';
+import { ViewerErrorDialogElement } from './elements/viewer-error-dialog.js';
+import { ViewerPasswordDialogElement } from './elements/viewer-password-dialog.js';
+import { ViewerPdfSidenavElement } from './elements/viewer-pdf-sidenav.js';
+import { ViewerToolbarElement } from './elements/viewer-toolbar.js';
// <if expr="enable_ink">
-import {InkController, InkControllerEventType} from './ink_controller.js';
+import { InkController, InkControllerEventType } from './ink_controller.js';
//</if>
-import {LocalStorageProxyImpl} from './local_storage_proxy.js';
-import {record, UserAction} from './metrics.js';
-import {NavigatorDelegateImpl, PdfNavigator, WindowOpenDisposition} from './navigator.js';
-import {deserializeKeyEvent, LoadState} from './pdf_scripting_api.js';
-import {getTemplate} from './pdf_viewer.html.js';
-import {KeyEventData, PdfViewerBaseElement} from './pdf_viewer_base.js';
-import {DestinationMessageData, DocumentDimensionsMessageData, hasCtrlModifier, hasCtrlModifierOnly, shouldIgnoreKeyEvents} from './pdf_viewer_utils.js';
+import { LocalStorageProxyImpl } from './local_storage_proxy.js';
+import { record, UserAction } from './metrics.js';
+import { NavigatorDelegateImpl, PdfNavigator, WindowOpenDisposition } from './navigator.js';
+import { deserializeKeyEvent, LoadState } from './pdf_scripting_api.js';
+import { getTemplate } from './pdf_viewer.html.js';
+import { KeyEventData, PdfViewerBaseElement } from './pdf_viewer_base.js';
+import { DestinationMessageData, DocumentDimensionsMessageData, hasCtrlModifier, hasCtrlModifierOnly, shouldIgnoreKeyEvents } from './pdf_viewer_utils.js';
interface EmailMessageData {
type: string;
@@ -83,7 +83,7 @@ export function getFilenameFromURL(url: string): string {
function eventToPromise(event: string, target: HTMLElement): Promise<void> {
return new Promise(
- resolve => listenOnce(target, event, (_e: Event) => resolve()));
+ resolve => listenOnce(target, event, (_e: Event) => resolve()));
}
const LOCAL_STORAGE_SIDENAV_COLLAPSED_KEY: string = 'sidenavCollapsed';
@@ -118,8 +118,8 @@ export class PdfViewerElement extends PdfViewerBaseElement {
annotationAvailable_: {
type: Boolean,
computed: 'computeAnnotationAvailable_(' +
- 'hadPassword_, clockwiseRotations_, canSerializeDocument_,' +
- 'twoUpViewEnabled_)',
+ 'hadPassword_, clockwiseRotations_, canSerializeDocument_,' +
+ 'twoUpViewEnabled_)',
},
annotationMode_: {
@@ -157,7 +157,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
documentMetadata_: {
type: Object,
- value: () => {},
+ value: () => { },
},
fileName_: String,
@@ -234,7 +234,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
zoomBounds_: {
type: Object,
- value: () => ({min: 0, max: 0}),
+ value: () => ({ min: 0, max: 0 }),
},
};
}
@@ -256,13 +256,13 @@ export class PdfViewerElement extends PdfViewerBaseElement {
private hasEnteredAnnotationMode_: boolean;
private isFormFieldFocused_: boolean;
private loadProgress_: number;
- private navigator_: PdfNavigator|null = null;
+ private navigator_: PdfNavigator | null = null;
private pageNo_: number;
private pdfAnnotationsEnabled_: boolean;
// <if expr="enable_screen_ai_service">
private pdfOcrEnabled_: boolean;
// </if>
- private pluginController_: PluginController|null = null;
+ private pluginController_: PluginController | null = null;
private printingEnabled_: boolean;
private showPasswordDialog_: boolean;
private showPropertiesDialog_: boolean;
@@ -281,7 +281,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
private zoomBounds_: ZoomBounds;
// <if expr="enable_ink">
- private inkController_: InkController|null = null;
+ private inkController_: InkController | null = null;
// </if>
constructor() {
@@ -289,9 +289,9 @@ export class PdfViewerElement extends PdfViewerBaseElement {
// TODO(dpapad): Add tests after crbug.com/1111459 is fixed.
this.sidenavCollapsed_ = Boolean(Number.parseInt(
- LocalStorageProxyImpl.getInstance().getItem(
- LOCAL_STORAGE_SIDENAV_COLLAPSED_KEY)!,
- 10));
+ LocalStorageProxyImpl.getInstance().getItem(
+ LOCAL_STORAGE_SIDENAV_COLLAPSED_KEY)!,
+ 10));
}
getBackgroundColor(): number {
@@ -304,7 +304,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
init(browserApi: BrowserApi) {
this.initInternal(
- browserApi, this.$.scroller, this.$.sizer, this.$.content);
+ browserApi, this.$.scroller, this.$.sizer, this.$.content);
this.pluginController_ = PluginController.getInstance();
@@ -312,14 +312,14 @@ export class PdfViewerElement extends PdfViewerBaseElement {
this.inkController_ = InkController.getInstance();
this.inkController_.init(this.viewport);
this.tracker.add(
- this.inkController_.getEventTarget(),
- InkControllerEventType.HAS_UNSAVED_CHANGES, () => {
- // TODO(crbug.com/1445746): Write an equivalent API call for
- // chrome.pdfViewerPrivate.
- if (!this.pdfOopifEnabled) {
- chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(true);
- }
- });
+ this.inkController_.getEventTarget(),
+ InkControllerEventType.HAS_UNSAVED_CHANGES, () => {
+ // TODO(crbug.com/1445746): Write an equivalent API call for
+ // chrome.pdfViewerPrivate.
+ if (!this.pdfOopifEnabled) {
+ chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(true);
+ }
+ });
// </if>
this.fileName_ = getFilenameFromURL(this.originalUrl);
@@ -327,17 +327,17 @@ export class PdfViewerElement extends PdfViewerBaseElement {
assert(this.paramsParser);
this.toolbarEnabled_ =
- this.paramsParser.shouldShowToolbar(this.originalUrl);
+ this.paramsParser.shouldShowToolbar(this.originalUrl);
if (this.toolbarEnabled_) {
this.$.toolbar.hidden = false;
}
const showSidenav = this.paramsParser.shouldShowSidenav(
- this.originalUrl, this.sidenavCollapsed_);
+ this.originalUrl, this.sidenavCollapsed_);
this.sidenavCollapsed_ = !showSidenav;
this.navigator_ = new PdfNavigator(
- this.originalUrl, this.viewport, this.paramsParser,
- new NavigatorDelegateImpl(browserApi));
+ this.originalUrl, this.viewport, this.paramsParser,
+ new NavigatorDelegateImpl(browserApi));
// Listen for save commands from the browser.
if (chrome.mimeHandlerPrivate && chrome.mimeHandlerPrivate.onSave) {
@@ -361,7 +361,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
// Disable zoom shortcuts in Presentation mode.
// Handle '+' and '-' buttons (both in the numpad and elsewhere).
if (hasCtrlModifier(e) &&
- (e.key === '=' || e.key === '-' || e.key === '+')) {
+ (e.key === '=' || e.key === '-' || e.key === '+')) {
e.preventDefault();
}
@@ -440,9 +440,9 @@ export class PdfViewerElement extends PdfViewerBaseElement {
/** @return Resolves when the sidenav animation is complete. */
private waitForSidenavTransition_(): Promise<void> {
return eventToPromise(
- 'transitionend',
- this.shadowRoot!.querySelector<ViewerPdfSidenavElement>(
- '#sidenav-container')!);
+ 'transitionend',
+ this.shadowRoot!.querySelector<ViewerPdfSidenavElement>(
+ '#sidenav-container')!);
}
/**
@@ -452,7 +452,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
private restoreSidenav_(): Promise<void> {
this.sidenavCollapsed_ = this.sidenavRestoreState_;
return this.sidenavCollapsed_ ? Promise.resolve() :
- this.waitForSidenavTransition_();
+ this.waitForSidenavTransition_();
}
/** Handles the annotation mode being toggled on or off. */
@@ -474,7 +474,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
// TODO(dstockwell): handle save failure
const result =
- await this.pluginController_!.save(SaveRequestType.ANNOTATION);
+ await this.pluginController_!.save(SaveRequestType.ANNOTATION);
// Data always exists when save is called with requestType = ANNOTATION.
assert(result);
@@ -503,7 +503,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
});
// TODO(dstockwell): handle save failure
const result =
- await this.inkController_!.save(SaveRequestType.ANNOTATION);
+ await this.inkController_!.save(SaveRequestType.ANNOTATION);
// Data always exists when save is called with requestType = ANNOTATION.
await this.restoreSidenav_();
this.currentController = this.pluginController_!;
@@ -594,8 +594,8 @@ export class PdfViewerElement extends PdfViewerBaseElement {
assert(this.currentController);
this.currentController.setTwoUpView(twoUpViewEnabled);
record(
- twoUpViewEnabled ? UserAction.TWO_UP_VIEW_ENABLE :
- UserAction.TWO_UP_VIEW_DISABLE);
+ twoUpViewEnabled ? UserAction.TWO_UP_VIEW_ENABLE :
+ UserAction.TWO_UP_VIEW_DISABLE);
}
/**
@@ -607,7 +607,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
* navigate to in screen coordinates.
*/
private goToPageAndXy_(
- origin: ChangePageOrigin, page: number, message: Point) {
+ origin: ChangePageOrigin, page: number, message: Point) {
this.viewport.goToPageAndXy(page, message.x, message.y);
if (origin === ChangePageOrigin.BOOKMARK) {
record(UserAction.FOLLOW_BOOKMARK);
@@ -640,8 +640,8 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
const errorDialog =
- this.shadowRoot!.querySelector<ViewerErrorDialogElement>(
- '#error-dialog')!;
+ this.shadowRoot!.querySelector<ViewerErrorDialogElement>(
+ '#error-dialog')!;
errorDialog.reloadFn = () => {
chrome.tabs.reload(this.browserApi!.getStreamInfo().tabId);
};
@@ -649,8 +649,8 @@ export class PdfViewerElement extends PdfViewerBaseElement {
private closePasswordDialog_() {
const passwordDialog =
- this.shadowRoot!.querySelector<ViewerPasswordDialogElement>(
- '#password-dialog')!;
+ this.shadowRoot!.querySelector<ViewerPasswordDialogElement>(
+ '#password-dialog')!;
if (passwordDialog) {
passwordDialog.close();
}
@@ -665,7 +665,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
* when an event is entered into the password dialog.
* @param event A password-submitted event.
*/
- private onPasswordSubmitted_(event: CustomEvent<{password: string}>) {
+ private onPasswordSubmitted_(event: CustomEvent<{ password: string }>) {
this.pluginController_!.getPasswordComplete(event.detail.password);
}
@@ -679,11 +679,11 @@ export class PdfViewerElement extends PdfViewerBaseElement {
this.currentController.viewportChanged();
}
- override handleStrings(strings: {[key: string]: string}) {
+ override handleStrings(strings: { [key: string]: string }) {
super.handleStrings(strings);
this.pdfAnnotationsEnabled_ =
- loadTimeData.getBoolean('pdfAnnotationsEnabled');
+ loadTimeData.getBoolean('pdfAnnotationsEnabled');
// <if expr="enable_screen_ai_service">
this.pdfOcrEnabled_ = loadTimeData.getBoolean('pdfOcrEnabled');
// </if>
@@ -691,7 +691,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
const presetZoomFactors = this.viewport.presetZoomFactors;
this.zoomBounds_.min = Math.round(presetZoomFactors[0] * 100);
this.zoomBounds_.max =
- Math.round(presetZoomFactors[presetZoomFactors.length - 1] * 100);
+ Math.round(presetZoomFactors[presetZoomFactors.length - 1] * 100);
}
override handleScriptingMessage(message: MessageEvent<any>) {
@@ -706,7 +706,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
switch (message.data.type.toString()) {
case 'getSelectedText':
this.pluginController_!.getSelectedText().then(
- this.handleSelectedTextReply.bind(this));
+ this.handleSelectedTextReply.bind(this));
break;
case 'print':
this.pluginController_!.print();
@@ -725,32 +725,32 @@ export class PdfViewerElement extends PdfViewerBaseElement {
switch (data.type.toString()) {
case 'attachments':
const attachmentsData =
- data as unknown as {attachmentsData: Attachment[]};
+ data as unknown as { attachmentsData: Attachment[] };
this.setAttachments_(attachmentsData.attachmentsData);
return;
case 'beep':
this.handleBeep_();
return;
case 'bookmarks':
- const bookmarksData = data as unknown as {bookmarksData: Bookmark[]};
+ const bookmarksData = data as unknown as { bookmarksData: Bookmark[] };
this.setBookmarks_(bookmarksData.bookmarksData);
return;
case 'documentDimensions':
this.setDocumentDimensions(
- data as unknown as DocumentDimensionsMessageData);
+ data as unknown as DocumentDimensionsMessageData);
return;
case 'email':
const emailData = data as unknown as EmailMessageData;
const href = 'mailto:' + emailData.to + '?cc=' + emailData.cc +
- '&bcc=' + emailData.bcc + '&subject=' + emailData.subject +
- '&body=' + emailData.body;
+ '&bcc=' + emailData.bcc + '&subject=' + emailData.subject +
+ '&body=' + emailData.body;
this.handleNavigate_(href, WindowOpenDisposition.CURRENT_TAB);
return;
case 'getPassword':
this.handlePasswordRequest_();
return;
case 'loadProgress':
- const progressData = data as unknown as {progress: number};
+ const progressData = data as unknown as { progress: number };
this.updateProgress(progressData.progress);
return;
case 'navigate':
@@ -760,12 +760,12 @@ export class PdfViewerElement extends PdfViewerBaseElement {
case 'navigateToDestination':
const destinationData = data as unknown as DestinationMessageData;
this.viewport.handleNavigateToDestination(
- destinationData.page, destinationData.x, destinationData.y,
- destinationData.zoom);
+ destinationData.page, destinationData.x, destinationData.y,
+ destinationData.zoom);
return;
case 'metadata':
const metadataData =
- data as unknown as {metadataData: DocumentMetadata};
+ data as unknown as { metadataData: DocumentMetadata };
this.setDocumentMetadata_(metadataData.metadataData);
return;
case 'setIsEditing':
@@ -773,15 +773,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
this.hasEdits_ = true;
return;
case 'setIsSelecting':
- const selectingData = data as unknown as {isSelecting: boolean};
+ const selectingData = data as unknown as { isSelecting: boolean };
this.viewportScroller!.setEnableScrolling(selectingData.isSelecting);
return;
case 'setSmoothScrolling':
this.viewport.setSmoothScrolling(
- (data as unknown as {smoothScrolling: boolean}).smoothScrolling);
+ (data as unknown as { smoothScrolling: boolean }).smoothScrolling);
return;
case 'formFocusChange':
- const focusedData = data as unknown as {focused: boolean};
+ const focusedData = data as unknown as { focused: boolean };
this.isFormFieldFocused_ = focusedData.focused;
return;
case 'touchSelectionOccurred':
@@ -790,13 +790,13 @@ export class PdfViewerElement extends PdfViewerBaseElement {
});
return;
case 'documentFocusChanged':
- const hasFocusData = data as unknown as {hasFocus: boolean};
+ const hasFocusData = data as unknown as { hasFocus: boolean };
this.documentHasFocus_ = hasFocusData.hasFocus;
return;
case 'sendKeyEvent':
const keyEventData = data as unknown as KeyEventData;
const keyEvent =
- deserializeKeyEvent(keyEventData.keyEvent) as ExtendedKeyEvent;
+ deserializeKeyEvent(keyEventData.keyEvent) as ExtendedKeyEvent;
keyEvent.fromPlugin = true;
this.handleKeyEvent(keyEvent);
return;
@@ -813,7 +813,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
override setDocumentDimensions(documentDimensions:
- DocumentDimensionsMessageData): void {
+ DocumentDimensionsMessageData): void {
super.setDocumentDimensions(documentDimensions);
// If the document dimensions are received, the password was correct and the
@@ -837,11 +837,11 @@ export class PdfViewerElement extends PdfViewerBaseElement {
// to an incorrect password.
if (!this.showPasswordDialog_) {
this.showPasswordDialog_ = true;
- this.sendScriptingMessage({type: 'passwordPrompted'});
+ this.sendScriptingMessage({ type: 'passwordPrompted' });
} else {
const passwordDialog =
- this.shadowRoot!.querySelector<ViewerPasswordDialogElement>(
- '#password-dialog')!;
+ this.shadowRoot!.querySelector<ViewerPasswordDialogElement>(
+ '#password-dialog')!;
assert(passwordDialog);
passwordDialog.deny();
}
@@ -849,7 +849,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
/** Handles a navigation request from the current controller. */
private handleNavigate_(url: string, disposition: WindowOpenDisposition):
- void {
+ void {
this.navigator_!.navigate(url, disposition);
}
@@ -895,40 +895,46 @@ export class PdfViewerElement extends PdfViewerBaseElement {
const MAX_FILE_SIZE = 100 * 1000 * 1000;
const bufView = new Uint8Array(result.dataToSave);
assert(
- bufView.length <= MAX_FILE_SIZE,
- `File too large to be saved: ${bufView.length} bytes.`);
+ bufView.length <= MAX_FILE_SIZE,
+ `File too large to be saved: ${bufView.length} bytes.`);
assert(
- bufView.length === size,
- `Received attachment size does not match its expected value: ${
- size} bytes.`);
+ bufView.length === size,
+ `Received attachment size does not match its expected value: ${size} bytes.`);
@@ -905,7 +905,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
dataArray = [result.dataToSave];
}
+ const a = document.createElement('a');
+ a.download = this.attachments_[index].name;
const blob = new Blob(dataArray);
+ // <if expr="not _google_chrome">
+ a.href = URL.createObjectURL(blob);
+ a.click();
+ URL.revokeObjectURL(a.href);
+ // </if>
+ // <if expr="_google_chrome">
const fileName = this.attachments_[index].name;
chrome.fileSystem.chooseEntry(
- {type: 'saveFile', suggestedName: fileName},
- (entry?: FileSystemFileEntry) => {
- if (chrome.runtime.lastError) {
- if (chrome.runtime.lastError.message !== 'User cancelled') {
- console.error(
- 'chrome.fileSystem.chooseEntry failed: ' +
- chrome.runtime.lastError.message);
- }
- return;
+ { type: 'saveFile', suggestedName: fileName },
+ (entry?: FileSystemFileEntry) => {
+ if (chrome.runtime.lastError) {
+ if (chrome.runtime.lastError.message !== 'User cancelled') {
+ console.error(
+ 'chrome.fileSystem.chooseEntry failed: ' +
+ chrome.runtime.lastError.message);
+ }
+ return;
+ }
+ entry!.createWriter((writer: FileWriter) => {
+ writer.write(blob);
+ // Unblock closing the window now that the user has saved
+ // successfully.
+ // TODO(crbug.com/1445746): Write an equivalent API call for
+ // chrome.pdfViewerPrivate.
+ if (!this.pdfOopifEnabled) {
+ chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false);
}
- entry!.createWriter((writer: FileWriter) => {
- writer.write(blob);
- // Unblock closing the window now that the user has saved
- // successfully.
- // TODO(crbug.com/1445746): Write an equivalent API call for
- // chrome.pdfViewerPrivate.
- if (!this.pdfOopifEnabled) {
- chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false);
- }
- });
{type: 'saveFile', suggestedName: fileName},
@@ -929,6 +937,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
});
});
+ });
+ // </if>
}
/**
@@ -975,8 +981,8 @@ export class PdfViewerElement extends PdfViewerBaseElement {
private onNavigate_(e: CustomEvent<NavigateDetail>) {
const disposition = e.detail.newtab ?
- WindowOpenDisposition.NEW_BACKGROUND_TAB :
- WindowOpenDisposition.CURRENT_TAB;
+ WindowOpenDisposition.NEW_BACKGROUND_TAB :
+ WindowOpenDisposition.CURRENT_TAB;
this.navigator_!.navigate(e.detail.uri, disposition);
}
@@ -990,12 +996,12 @@ export class PdfViewerElement extends PdfViewerBaseElement {
container.classList.add('floating');
container.addEventListener('transitionend', () => {
container.classList.remove('floating');
- }, {once: true});
+ }, { once: true });
}
LocalStorageProxyImpl.getInstance().setItem(
- LOCAL_STORAGE_SIDENAV_COLLAPSED_KEY,
- (this.sidenavCollapsed_ ? 1 : 0).toString());
+ LOCAL_STORAGE_SIDENAV_COLLAPSED_KEY,
+ (this.sidenavCollapsed_ ? 1 : 0).toString());
}
/**
@@ -1012,7 +1018,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
// Always send requests of type ORIGINAL to the plugin controller, not the
// ink controller. The ink controller always saves the edited document.
// TODO(dstockwell): Report an error to user if this fails.
- let result: {fileName: string, dataToSave: ArrayBuffer}|null = null;
+ let result: { fileName: string, dataToSave: ArrayBuffer } | null = null;
assert(this.currentController);
if (requestType !== SaveRequestType.ORIGINAL || !this.annotationMode_) {
result = await this.currentController.save(requestType);
@@ -1036,34 +1042,40 @@ export class PdfViewerElement extends PdfViewerBaseElement {
@@ -1036,8 +1045,15 @@ export class PdfViewerElement extends PdfViewerBaseElement {
fileName = fileName + '.pdf';
}
- // Create blob before callback to avoid race condition.
- const blob = new Blob([result.dataToSave], {type: 'application/pdf'});
+ const a = document.createElement('a');
+ a.download = fileName;
+ const blob = new Blob([result.dataToSave], { type: 'application/pdf' });
const blob = new Blob([result.dataToSave], {type: 'application/pdf'});
+ // <if expr="not _google_chrome">
+ a.href = URL.createObjectURL(blob);
+ a.click();
+ URL.revokeObjectURL(a.href);
+ // </if>
+ // <if expr="_google_chrome">
chrome.fileSystem.chooseEntry(
- {
- type: 'saveFile',
- accepts: [{description: '*.pdf', extensions: ['pdf']}],
- suggestedName: fileName,
- },
- (entry?: FileSystemFileEntry) => {
- if (chrome.runtime.lastError) {
- if (chrome.runtime.lastError.message !== 'User cancelled') {
- console.error(
- 'chrome.fileSystem.chooseEntry failed: ' +
- chrome.runtime.lastError.message);
- }
- return;
+ {
+ type: 'saveFile',
+ accepts: [{ description: '*.pdf', extensions: ['pdf'] }],
+ suggestedName: fileName,
+ },
+ (entry?: FileSystemFileEntry) => {
+ if (chrome.runtime.lastError) {
+ if (chrome.runtime.lastError.message !== 'User cancelled') {
+ console.error(
+ 'chrome.fileSystem.chooseEntry failed: ' +
+ chrome.runtime.lastError.message);
+ }
+ return;
+ }
+ entry!.createWriter((writer: FileWriter) => {
+ writer.write(blob);
+ // Unblock closing the window now that the user has saved
+ // successfully.
+ // TODO(crbug.com/1445746): Write an equivalent API call for
+ // chrome.pdfViewerPrivate.
+ if (!this.pdfOopifEnabled) {
+ chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false);
}
- entry!.createWriter((writer: FileWriter) => {
- writer.write(blob);
- // Unblock closing the window now that the user has saved
- // successfully.
- // TODO(crbug.com/1445746): Write an equivalent API call for
- // chrome.pdfViewerPrivate.
- if (!this.pdfOopifEnabled) {
- chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false);
- }
- });
{
type: 'saveFile',
@@ -1064,6 +1080,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
});
});
+ });
+ // </if>
// <if expr="enable_ink">
// Saving in Annotation mode is destructive: crbug.com/919364
@@ -1082,8 +1094,8 @@ export class PdfViewerElement extends PdfViewerBaseElement {
break;
case SaveRequestType.ORIGINAL:
record(
- this.hasEdits_ ? UserAction.SAVE_ORIGINAL :
- UserAction.SAVE_ORIGINAL_ONLY);
+ this.hasEdits_ ? UserAction.SAVE_ORIGINAL :
+ UserAction.SAVE_ORIGINAL_ONLY);
break;
case SaveRequestType.EDITED:
record(UserAction.SAVE_EDITED);
@@ -1115,7 +1127,7 @@ export class PdfViewerElement extends PdfViewerBaseElement {
}
// <if expr="enable_ink">
- getCurrentControllerForTesting(): ContentController|null {
+ getCurrentControllerForTesting(): ContentController | null {
return this.currentController;
}
// </if>