Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3438)

Unified Diff: chrome/browser/resources/print_preview/native_layer.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/native_layer.js
diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js
new file mode 100644
index 0000000000000000000000000000000000000000..9a017d93dc3ae057c0d4571bdc45289b9fdb67c5
--- /dev/null
+++ b/chrome/browser/resources/print_preview/native_layer.js
@@ -0,0 +1,653 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('print_preview', function() {
+ 'use strict';
+
+ /**
+ * An interface to the native Chromium printing system layer.
+ *
+ * @constructor
+ * @extends {cr.EventTarget}
+ */
+ function NativeLayer() {
+ cr.EventTarget.call(this);
+ };
+
+ /**
+ * Events dispatched from the Chromium native layer.
+ * @enum {string}
+ * @const
+ */
+ NativeLayer.Event = {
+ CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET',
+ CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE',
+ DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD',
+ FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL',
+ FILE_SELECTION_COMPLETE:
+ 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE',
+ INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET',
+ LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET',
+ PAGE_COUNT_CHANGE: 'print_preview.NativeLayer.PAGE_COUNT_CHANGE',
+ PAGE_LAYOUT_CHANGE: 'print_preview.NativeLayer.PAGE_LAYOUT_CHANGE',
+ PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY',
+ PREVIEW_GENERATION_DONE:
+ 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE',
+ PREVIEW_GENERATION_FAIL:
+ 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL',
+ PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD',
+ PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD',
+ SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID'
+ };
+
+ /**
+ * Constant values matching printing::DuplexMode enum.
+ * @enum {number}
+ */
+ NativeLayer.DuplexMode = {
+ SIMPLEX: 0,
+ LONG_EDGE: 1,
+ UNKNOWN_DUPLEX_MODE: -1
+ };
+
+ /**
+ * Enumeration of color modes used by Chromium.
+ * @enum {number}
+ * @private
+ */
+ NativeLayer.ColorMode_ = {
+ GRAY: 1,
+ COLOR: 2
+ };
+
+ /**
+ * Enumeration of the predefined types of page margins. Matches enum
+ * MarginType in printing/print_job_constants.h.
+ * @type {object.<print_preview.Margins.Type, number>}
+ * @private
+ */
+ NativeLayer.MarginsTypeMap_ = {};
+ NativeLayer.MarginsTypeMap_[print_preview.Margins.Type.DEFAULT] = 0;
dpapad 2012/04/24 01:24:56 This mapping was not needed when Margins.Type was
Robert Toscano 2012/04/24 22:29:56 I explain the benefit in my comment response in ma
+ NativeLayer.MarginsTypeMap_[print_preview.Margins.Type.NO_MARGINS] = 1;
+ NativeLayer.MarginsTypeMap_[print_preview.Margins.Type.MINIMUM] = 2;
+ NativeLayer.MarginsTypeMap_[print_preview.Margins.Type.CUSTOM] = 3;
+
+ NativeLayer.prototype = {
+ __proto__: cr.EventTarget.prototype,
+
+ // TODO Remove me
+ dispatchEvent: function(evt) {
+ log(evt.type);
+ cr.EventTarget.prototype.dispatchEvent.call(this, evt);
+ },
+
+ /** Gets the initial settings to initialize the print preview with. */
+ startGetInitialSettings: function() {
+ chrome.send('getInitialSettings');
+ },
+
+ /**
+ * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET
+ * event will be dispatched in response.
+ */
+ startGetLocalDestinations: function() {
+ chrome.send('getPrinters');
+ },
+
+ /**
+ * Requests the destination's printing capabilities. A CAPABILITIES_SET
+ * event will be dispatched in response.
+ * @param {string} destinationId ID of the destination.
+ */
+ startGetLocalDestinationCapabilities: function(destinationId) {
+ chrome.send('getPrinterCapabilities', [destinationId]);
+ },
+
+ /**
+ * Requests that a preview be generated. The following events may be
+ * dispatched in response:
+ * - PAGE_COUNT_CHANGE
+ * - PAGE_LAYOUT_CHANGE
+ * - PAGE_PREVIEW_READY
+ * - PREVIEW_GENERATION_DONE
+ * - PREVIEW_GENERATION_FAIL
+ * - PREVIEW_RELOAD
+ * @param {print_preview.Destination} destination Destination to print to.
+ * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
+ * state of the print ticket.
+ * @param {number} ID of the preview request.
+ */
+ startGetPreview: function(destination, printTicketStore, requestId) {
+ if (!printTicketStore.isTicketValid()) {
+ throw Error('Trying to generate preview when ticket is not valid');
+ }
+
+ var ticket = {
+ 'pageRange': [], // TODO this.ticket_.pageRangeSequence,
+ 'landscape': printTicketStore.isLandscapeEnabled(),
+ 'color': printTicketStore.isColorEnabled() ?
+ NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY,
+ 'headerFooterEnabled': printTicketStore.isHeaderFooterEnabled(),
+ 'marginsType': NativeLayer.MarginsTypeMap_[
+ printTicketStore.getMarginsType()],
+ 'isFirstRequest': requestId == 0,
+ 'requestID': requestId,
+ 'previewModifiable': printTicketStore.isDocumentModifiable,
+ 'printToPDF': destination != null && destination.isPrintToPdf,
+ 'printWithCloudPrint': destination != null && !destination.isLocal,
+ 'deviceName': destination == null ? 'foo' : destination.id,
+ 'cloudPrintID': destination == null ? 'foo' : destination.id,
+
+ // This field seems to issue a reloadPreviewPages call when true.
+ 'generateDraftData': true, // TODO What should this value be?
+
+ // NOTE: Even though the following fields don't directly relate to the
+ // preview, they still need to be included.
+ 'duplex': printTicketStore.isDuplexEnabled() ?
+ NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX,
+ 'copies': printTicketStore.getCopies(),
+ 'collate': printTicketStore.isCollateEnabled()
+ };
+
+ if (printTicketStore.getMarginsType() ==
+ print_preview.Margins.Type.CUSTOM) {
+ var customMargins = printTicketStore.getCustomMargins();
+ ticket['marginsCustom'] = {
+ 'marginTop': customMargins.top,
+ 'marginRight': customMargins.right,
+ 'marginBottom': customMargins.bottom,
+ 'marginLeft': customMargins.left
+ };
+ }
+
+ var pageCount = requestId == 0 ? -1 : printTicketStore.pageCount;
+ // TODO this.printTicketStore_.getPageNumberSet().size,
+ chrome.send(
+ 'getPreview',
+ [JSON.stringify(ticket),
+ pageCount,
+ printTicketStore.isDocumentModifiable]);
+ },
+
+ /**
+ * Persists the selected destination and print ticket for the next print
+ * session.
+ * @param {string} destinatId ID of the destination.
+ * @param {string} serializedTicket Serialized form of the print ticket.
+ */
+ startSaveDestinationAndTicket: function(destinationId, serializedTicket) {
+ chrome.send('saveLastPrinter', [destinationId, serializedTicket]);
+ },
+
+ /**
+ * Requests that the document be printed.
+ * @param {!print_preview.Destination} destination Destination to print to.
+ * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
+ * state of the print ticket.
+ * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface
+ * to Google Cloud Print.
+ */
+ startPrint: function(destination, printTicketStore, cloudPrintInterface) {
+ if (!printTicketStore.isTicketValid()) {
+ throw Error(
+ 'Requesting ticket for preview generator when ticket is not valid');
+ }
+
+ var ticket = {
+ 'pageRange': [], // TODO this.ticket_.pageRangeSequence,
+ 'landscape': printTicketStore.isLandscapeEnabled(),
+ 'color': printTicketStore.isColorEnabled() ?
+ NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY,
+ 'headerFooterEnabled': printTicketStore.isHeaderFooterEnabled(),
+ 'marginsType': NativeLayer.MarginsTypeMap_[
+ printTicketStore.getMarginsType()],
+ 'generateDraftData': true, // TODO What should this value be?
+ 'duplex': printTicketStore.isDuplexEnabled() ?
+ NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX,
+ 'copies': printTicketStore.getCopies(),
+ 'collate': printTicketStore.isCollateEnabled(),
+ 'previewModifiable': printTicketStore.isDocumentModifiable,
+ 'printToPDF': destination.isPrintToPdf,
+ 'printWithCloudPrint': !destination.isLocal,
+ 'deviceName': destination.id,
+ 'isFirstRequest': false,
+ 'requestID': -1
+ };
+
+ if (!destination.isLocal && !destination.isPrintWithCloudPrint) {
+ // We can't set cloudPrintID if the destination is "Print with Cloud
+ // Print" because the native system will try to print to Google Cloud
+ // Print with this ID instead of opening a Google Cloud Print dialog.
+ ticket['cloudPrintID'] = destination.id;
+ }
+
+ if (printTicketStore.getMarginsType() ==
+ print_preview.Margins.Type.CUSTOM) {
+ var customMargins = printTicketStore.getCustomMargins();
+ ticket['marginsCustom'] = {
+ 'marginTop': customMargins.top,
+ 'marginRight': customMargins.right,
+ 'marginBottom': customMargins.bottom,
+ 'marginLeft': customMargins.left
+ };
+ }
+
+ var cloudTicket = null;
+ if (!destination.isLocal) {
+ if (!cloudPrintInterface) {
+ throw Error(
+ 'Trying to print to a cloud destination but Google Cloud Print ' +
+ 'integration is disabled');
+ }
+ cloudTicket = cloudPrintInterface.createPrintTicket(
+ destination, printTicketStore);
+ cloudTicket = JSON.stringify(cloudTicket);
+ }
+
+ chrome.send('print', [JSON.stringify(ticket), cloudTicket]);
+ },
+
+ /** Requests that the current pending print request be cancelled. */
+ startCancelPendingPrint: function() {
+ chrome.send('cancelPendingPrintRequest');
+ },
+
+ /** Shows the system's native printing dialog. */
+ startShowSystemDialog: function() {
+ chrome.send('showSystemDialog');
+ },
+
+ /** Closes the print preview dialog. */
+ startCloseDialog: function() {
+ chrome.send('closePrintPreviewTab');
+ chrome.send('DialogClose');
+ },
+
+ /**
+ * Opens the Google Cloud Print sign-in dialog. The DESTINATIONS_RELOAD
+ * event will be dispatched in response.
+ */
+ startCloudPrintSignIn: function() {
+ chrome.send('signIn');
+ },
+
+ /** Navigates the user to the system printer settings interface. */
+ startManageLocalPrinters: function() {
+ chrome.send('manageLocalPrinters');
+ },
+
+ /** Navigates the user to the Google Cloud Print management page. */
+ startManageCloudPrinters: function() {
+ chrome.send('manageCloudPrinters');
+ }
+ };
+
+ /**
+ * Initial settings retrieved from the native layer.
+ *
+ * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be
+ * in auto-print mode.
+ * @param {!print_preview.MeasurementSystem} Measurement system of the print
+ * preview.
+ * @param {boolean} isDocumentModifiable Whether the document to print is
+ * modifiable.
+ * @param {print_preview.Margins.Type} marginsType Initial margins type.
+ * @param {print_preview.Margins} customMargins Initial custom margins.
+ * @param {boolean} isDuplexEnabled Whether duplexing is initially enabled.
+ * @param {boolean} isHeaderFooterEnabled Whether the header-footer is
+ * initially enabled.
+ * @param {?string} initialDestinationId ID of the destination to initially
+ * select.
+ * @constructor
+ */
+ function NativeInitialSettings(
+ isInKioskAutoPrintMode,
+ measurementSystem,
+ isDocumentModifiable,
+ marginsType,
+ customMargins,
+ isDuplexEnabled,
+ isHeaderFooterEnabled,
+ initialDestinationId) {
+
+ /**
+ * Whether the print preview should be in auto-print mode.
+ * @type {boolean}
+ * @private
+ */
+ this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode;
+
+ /**
+ * Measurement system of the print preview.
+ * @type {!print_preview.MeasurementSystem}
+ * @private
+ */
+ this.measurementSystem_ = measurementSystem;
+
+ /**
+ * Whether the document to print is modifiable.
+ * @type {boolean}
+ * @private
+ */
+ this.isDocumentModifiable_ = isDocumentModifiable;
+
+ /**
+ * Initial margins type.
+ * @type {print_preview.Margins.Type}
+ * @private
+ */
+ this.marginsType_ = marginsType == null ?
+ print_preview.Margins.Type.DEFAULT : marginsType;
+
+ /**
+ * Initial custom margins.
+ * @type {print_preview.Margins}
+ * @private
+ */
+ this.customMargins_ = customMargins;
+
+ /**
+ * Whether duplexing is initially enabled.
+ * @type {boolean}
+ * @private
+ */
+ this.isDuplexEnabled_ = isDuplexEnabled;
+
+ /**
+ * Whether the header-footer is initially enabled.
+ * @type {boolean}
+ * @private
+ */
+ this.isHeaderFooterEnabled_ = isHeaderFooterEnabled;
+
+ /**
+ * ID of the initially selected destination.
+ * @type {?string}
+ * @private
+ */
+ this.initialDestinationId_ = initialDestinationId;
+ };
+
+ NativeInitialSettings.prototype = {
+ /**
+ * @return {boolean} Whether the print preview should be in auto-print mode.
+ */
+ get isInKioskAutoPrintMode() {
+ return this.isInKioskAutoPrintMode_;
+ },
+
+ /**
+ * @return {!print_preview.MeasurementSystem} Measurement system of the
+ * print preview.
+ */
+ get measurementSystem() {
+ return this.measurementSystem_;
+ },
+
+ /** @return {boolean} Whether the document to print is modifiable. */
+ get isDocumentModifiable() {
+ return this.isDocumentModifiable_;
+ },
+
+ /** @return {print_preview.Margins.Type} Initial margins type. */
+ get marginsType() {
+ return this.marginsType_;
+ },
+
+ /** @return {print_preview.Margins} Initial custom margins. */
+ get customMargins() {
+ return this.customMargins_;
+ },
+
+ /** @return {boolean} Whether duplexing is initially enabled. */
+ get isDuplexEnabled() {
+ return this.isDuplexEnabled_;
+ },
+
+ /** @return {boolean} Whether the header-footer is initially enabled. */
+ get isHeaderFooterEnabled() {
+ this.isHeaderFooterEnabled_;
+ },
+
+ /** @return {?string} ID of the initially selected destination. */
+ get initialDestinationId() {
+ return this.initialDestinationId_;
+ }
+ };
+
+ return {
+ NativeInitialSettings: NativeInitialSettings,
+ NativeLayer: NativeLayer
+ };
+});
+
+var nativeLayer = new print_preview.NativeLayer();
dpapad 2012/04/24 01:24:56 Global var? Should all global vars be initialized
Robert Toscano 2012/04/24 22:29:56 Yea I'm not sure where I should put them. My goal
+
+/** @param {object} initialSettings Object containing all initial settings. */
+function setInitialSettings(initialSettings) {
+ // Not using initialSettings['initiatorTabTitle'] since the print preview
+ // no longer opens in a new tab. And because of this,
+ // localStrings.getStringF('printPreviewTitleFormat', initiatorTabTitle)
dpapad 2012/04/24 01:24:56 IIRC, we use the tab title to pre-populate the fil
Robert Toscano 2012/04/24 22:29:56 This must happen in the native layer then, because
+ // is also not used.
+ // TODO Remove those unused local strings.
+
+ // TODO Use initialSettings['cloudPrintData'] somehow. Btw,
+ // initialSettings['cloudPrintData'] is the JSON form of the cloud
+ // printer's capabilities.
+
+ var numberFormatSymbols = print_preview.MeasurementSystem.parseNumberFormat(
+ initialSettings['numberFormat']);
+ var measurementSystem = new print_preview.MeasurementSystem(
+ numberFormatSymbols[0],
+ numberFormatSymbols[1],
+ initialSettings['measurementSystem']);
+
+ var customMargins = null;
+ if (initialSettings.hasOwnProperty('marginTop') &&
+ initialSettings.hasOwnProperty('marginRight') &&
+ initialSettings.hasOwnProperty('marginBottom') &&
+ initialSettings.hasOwnProperty('marginLeft')) {
+ customMargins = new print_preview.Margins(
+ initialSettings['marginTop'] || 0,
+ initialSettings['marginRight'] || 0,
+ initialSettings['marginBottom'] || 0,
+ initialSettings['marginLeft'] || 0);
+ }
+
+ var marginsType;
dpapad 2012/04/24 01:24:56 This also got more complicated by converting Margi
Robert Toscano 2012/04/24 22:29:56 It could be, but then native semantics of these in
+ for (var mt in print_preview.NativeLayer.MarginsTypeMap_) {
+ if (print_preview.NativeLayer.MarginsTypeMap_[mt] ==
+ initialSettings['marginsType']) {
+ marginsType = mt;
+ break;
+ }
+ }
+
+ var nativeInitialSettings = new print_preview.NativeInitialSettings(
+ initialSettings['printAutomaticallyInKioskMode'] || false,
+ measurementSystem,
+ initialSettings['previewModifiable'] || false,
+ marginsType,
+ customMargins,
+ initialSettings['duplex'] || false,
+ initialSettings['headerFooterEnabled'] || false,
+ initialSettings['printerName'] || null);
+
+ var initialSettingsSetEvt =
dpapad 2012/04/24 01:24:56 Nit: An abbreviation for 2 saving characters not r
Robert Toscano 2012/04/24 22:29:56 Done.
+ new cr.Event(print_preview.NativeLayer.Event.INITIAL_SETTINGS_SET);
+ initialSettingsSetEvt.initialSettings = nativeInitialSettings;
+ nativeLayer.dispatchEvent(initialSettingsSetEvt);
+}
+
+/**
+ * Turn on the integration of Cloud Print.
+ * @param {string} cloudPrintURL The URL to use for cloud print servers.
+ */
+function setUseCloudPrint(cloudPrintURL) {
+ var cloudPrintEnableEvt = new cr.Event(
+ print_preview.NativeLayer.Event.CLOUD_PRINT_ENABLE);
+ cloudPrintEnableEvt.baseCloudPrintUrl = cloudPrintURL;
+ nativeLayer.dispatchEvent(cloudPrintEnableEvt);
+}
+
+/**
+ * Updates the print preview with local printers.
+ * Called from PrintPreviewHandler::SetupPrinterList().
+ * @param {Array} printers Array of printer info objects.
+ */
+function setPrinters(printers) {
+ var localDestsSetEvt = new cr.Event(
+ print_preview.NativeLayer.Event.LOCAL_DESTINATIONS_SET);
+ localDestsSetEvt.destinationInfos = printers;
+ nativeLayer.dispatchEvent(localDestsSetEvt);
+}
+
+/**
+ * Called when native layer gets settings information for a requested local
+ * destination.
+ * @param {Object} settingsInfo printer setting information.
+ */
+function updateWithPrinterCapabilities(settingsInfo) {
+ var capsSetEvt = new cr.Event(
+ print_preview.NativeLayer.Event.CAPABILITIES_SET);
+ capsSetEvt.settingsInfo = settingsInfo;
+ nativeLayer.dispatchEvent(capsSetEvt);
+}
+
+/** Reloads the printer list. */
+function reloadPrintersList() {
+ cr.dispatchSimpleEvent(
+ nativeLayer, print_preview.NativeLayer.Event.DESTINATIONS_RELOAD);
+}
+
+/**
+ * Called from the C++ layer.
+ * Take the PDF data handed to us and submit it to the cloud, closing the print
+ * preview tab once the upload is successful.
+ * @param {string} data Data to send as the print job.
+ */
+function printToCloud(data) {
+ var printToCloudEvt = new cr.Event(
+ print_preview.NativeLayer.Event.PRINT_TO_CLOUD);
+ printToCloudEvt.data = data;
+ nativeLayer.dispatchEvent(printToCloudEvt);
+}
+
+/**
+ * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
+ * preview tab regarding the file selection cancel event.
+ */
+function fileSelectionCancelled() {
+ cr.dispatchSimpleEvent(
+ nativeLayer, print_preview.NativeLayer.Event.FILE_SELECTION_CANCEL);
+}
+
+/**
+ * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print
+ * preview tab regarding the file selection completed event.
+ */
+function fileSelectionCompleted() {
+ // If the file selection is completed and the tab is not already closed it
+ // means that a pending print to pdf request exists.
+ cr.dispatchSimpleEvent(
+ nativeLayer, print_preview.NativeLayer.Event.FILE_SELECTION_COMPLETE);
+}
+
+/**
+ * Display an error message when print preview fails.
+ * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed().
+ */
+function printPreviewFailed() {
+ cr.dispatchSimpleEvent(
+ nativeLayer, print_preview.NativeLayer.Event.PREVIEW_GENERATION_FAIL);
+}
+
+/**
+ * Display an error message when encountered invalid printer settings.
+ * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings().
+ */
+function invalidPrinterSettings() {
+ cr.dispatchSimpleEvent(
+ nativeLayer, print_preview.NativeLayer.Event.SETTINGS_INVALID);
+}
+
+/**
+ * @param {{contentWidth: number, contentHeight: number, marginLeft: number,
+ * marginRight: number, marginTop: number, marginBottom: number,
+ * printableAreaX: number, printableAreaY: number,
+ * printableAreaWidth: number, printableAreaHeight: number}} pageLayout
+ * Specifies default page layout details in points.
+ * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed
+ * document has a custom page size style.
+ */
+function onDidGetDefaultPageLayout(pageLayout, hasCustomPageSizeStyle) {
+ var pageLayoutChangeEvt = new cr.Event(
+ print_preview.NativeLayer.Event.PAGE_LAYOUT_CHANGE);
+ pageLayoutChangeEvt.pageLayout = pageLayout;
+ pageLayoutChangeEvt.hasCustomPageSizeStyle = hasCustomPageSizeStyle;
+ nativeLayer.dispatchEvent(pageLayoutChangeEvt);
+}
+
+/**
+ * Update the page count and check the page range.
+ * Called from PrintPreviewUI::OnDidGetPreviewPageCount().
+ * @param {number} pageCount The number of pages.
+ * @param {number} previewResponseId The preview request id that resulted in
+ * this response.
+ */
+function onDidGetPreviewPageCount(pageCount, previewResponseId) {
+ var pageCountChangeEvt = new cr.Event(
+ print_preview.NativeLayer.Event.PAGE_COUNT_CHANGE);
+ pageCountChangeEvt.pageCount = pageCount;
+ pageCountChangeEvt.previewResponseId = previewResponseId;
+ nativeLayer.dispatchEvent(pageCountChangeEvt);
+}
+
+/**
+ * Called when no pipelining previewed pages.
+ * @param {string} previewUid Preview unique identifier.
+ * @param {number} previewResponseId The preview request id that resulted in
+ * this response.
+ */
+function reloadPreviewPages(previewUid, previewResponseId) {
+ var previewReloadEvt = new cr.Event(
+ print_preview.NativeLayer.Event.PREVIEW_RELOAD);
+ previewReloadEvt.previewUid = previewUid;
+ previewReloadEvt.previewResponseId = previewResponseId;
+ nativeLayer.dispatchEvent(previewReloadEvt);
+}
+
+/**
+ * Notification that a print preview page has been rendered.
+ * Check if the settings have changed and request a regeneration if needed.
+ * Called from PrintPreviewUI::OnDidPreviewPage().
+ * @param {number} pageNumber The page number, 0-based.
+ * @param {string} previewUid Preview unique identifier.
+ * @param {number} previewResponseId The preview request id that resulted in
+ * this response.
+ */
+function onDidPreviewPage(pageNumber, previewUid, previewResponseId) {
+ var pagePreviewGenEvt = new cr.Event(
+ print_preview.NativeLayer.Event.PAGE_PREVIEW_READY);
+ pagePreviewGenEvt.pageIndex = pageNumber;
+ pagePreviewGenEvt.previewUid = previewUid;
+ pagePreviewGenEvt.previewResponseId = previewResponseId;
+ nativeLayer.dispatchEvent(pagePreviewGenEvt);
+}
+
+/**
+ * Update the print preview when new preview data is available.
+ * Create the PDF plugin as needed.
+ * Called from PrintPreviewUI::PreviewDataIsAvailable().
+ * @param {string} previewUid Preview unique identifier.
+ * @param {number} previewResponseId The preview request id that resulted in
+ * this response.
+ */
+function updatePrintPreview(previewUid, previewResponseId) {
+ var previewGenDoneEvt = new cr.Event(
+ print_preview.NativeLayer.Event.PREVIEW_GENERATION_DONE);
+ previewGenDoneEvt.previewUid = previewUid;
+ previewGenDoneEvt.previewResponseId = previewResponseId;
+ nativeLayer.dispatchEvent(previewGenDoneEvt);
+}

Powered by Google App Engine
This is Rietveld 408576698