| Index: chrome/browser/resources/print_preview.js
|
| diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js
|
| index 7118615fcf1abd994fc2ab2ca60befd4356448ce..3e93e3642a96a3749837675bd27343255803bf85 100644
|
| --- a/chrome/browser/resources/print_preview.js
|
| +++ b/chrome/browser/resources/print_preview.js
|
| @@ -2,8 +2,13 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +// require: cr/ui/print_preview_cloud.js
|
| +
|
| var localStrings = new LocalStrings();
|
|
|
| +var useCloudPrint = false;
|
| +var maxCloudPrinters = 10;
|
| +
|
| // The total page count of the previewed document regardless of which pages the
|
| // user has selected.
|
| var totalPageCount = -1;
|
| @@ -24,8 +29,12 @@ var lastSelectedPrinterIndex = 0;
|
| var previewModifiable = false;
|
|
|
| // Destination list special value constants.
|
| +const ADD_PRINTER = 'addPrinter';
|
| +const MANAGE_CLOUD_PRINTERS = 'manageCloudPrinters';
|
| +const MANAGE_LOCAL_PRINTERS = 'manageLocalPrinters';
|
| +const MORE_PRINTERS = 'morePrinters';
|
| +const SIGN_IN = 'signIn';
|
| const PRINT_TO_PDF = 'Print To PDF';
|
| -const MANAGE_PRINTERS = 'Manage Printers';
|
|
|
| // State of the print preview settings.
|
| var printSettings = new PrintSettings();
|
| @@ -154,14 +163,20 @@ function updateControlsWithSelectedPrinterCapabilities() {
|
| return;
|
|
|
| var selectedValue = printerList.options[selectedIndex].value;
|
| - if (selectedValue == PRINT_TO_PDF) {
|
| - updateWithPrinterCapabilities({'disableColorOption': true,
|
| - 'setColorAsDefault': true,
|
| - 'disableCopiesOption': true});
|
| - } else if (selectedValue == MANAGE_PRINTERS) {
|
| + if (printerList.options[selectedIndex].isCloudPrint) {
|
| + updateWithCloudPrinterCapabilities();
|
| + return;
|
| + } else if (selectedValue == SIGN_IN ||
|
| + selectedValue == MANAGE_CLOUD_PRINTERS ||
|
| + selectedValue == MANAGE_LOCAL_PRINTERS) {
|
| printerList.selectedIndex = lastSelectedPrinterIndex;
|
| - chrome.send('managePrinters');
|
| + chrome.send(selectedValue);
|
| return;
|
| + } else if (selectedValue == PRINT_TO_PDF) {
|
| + updateWithPrinterCapabilities({'disableColorOption': true,
|
| + 'setColorAsDefault': true,
|
| + 'disableCopiesOption': true,
|
| + 'disableLandscapeOption': false});
|
| } else {
|
| // This message will call back to 'updateWithPrinterCapabilities'
|
| // function.
|
| @@ -174,6 +189,33 @@ function updateControlsWithSelectedPrinterCapabilities() {
|
| setDefaultValuesAndRegeneratePreview();
|
| }
|
|
|
| +function updateWithCloudPrinterCapabilities() {
|
| + var printerList = $('printer-list');
|
| + var selectedIndex = printerList.selectedIndex;
|
| + if (printerList.options[selectedIndex].capabilities) {
|
| + doUpdateCloudPrinterCapabilities(
|
| + printerList.options[selectedIndex],
|
| + printerList.options[selectedIndex].capabilities);
|
| + } else {
|
| + cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
|
| + doUpdateCloudPrinterCapabilities);
|
| + }
|
| +}
|
| +
|
| +function doUpdateCloudPrinterCapabilities(printer) {
|
| + var settings = {'disableColorOption': !cloudprint.supportsColor(printer),
|
| + 'setColorAsDefault': cloudprint.colorIsDefault(printer),
|
| + 'disableCopiesOption': true,
|
| + 'disableLandscapeOption': true};
|
| + updateWithPrinterCapabilities(settings);
|
| + var printerList = $('printer-list');
|
| + var selectedIndex = printerList.selectedIndex;
|
| + lastSelectedPrinterIndex = selectedIndex;
|
| +
|
| + // Regenerate the preview data based on selected printer settings.
|
| + setDefaultValuesAndRegeneratePreview();
|
| +}
|
| +
|
| /**
|
| * Updates the controls with printer capabilities information.
|
| * @param {Object} settingInfo printer setting information.
|
| @@ -182,6 +224,7 @@ function updateWithPrinterCapabilities(settingInfo) {
|
| var disableColorOption = settingInfo.disableColorOption;
|
| var disableCopiesOption = settingInfo.disableCopiesOption;
|
| var setColorAsDefault = settingInfo.setColorAsDefault;
|
| + var disableLandscapeOption = settingInfo.disableLandscapeOption;
|
| var colorOption = $('color');
|
| var bwOption = $('bw');
|
|
|
| @@ -193,6 +236,12 @@ function updateWithPrinterCapabilities(settingInfo) {
|
| $('hr-before-copies').classList.add('invisible');
|
| }
|
|
|
| + if (disableLandscapeOption) {
|
| + fadeOutElement($('landscape-option'));
|
| + } else {
|
| + fadeInElement($('landscape-option'));
|
| + }
|
| +
|
| disableColorOption ? fadeOutElement($('color-options')) :
|
| fadeInElement($('color-options'));
|
|
|
| @@ -204,6 +253,44 @@ function updateWithPrinterCapabilities(settingInfo) {
|
| }
|
|
|
| /**
|
| + * Turn on the integration of Cloud Print.
|
| + * @param {enable} true if cloud print should be used.
|
| + */
|
| +function setUseCloudPrint(enable, cloudPrintURL) {
|
| + useCloudPrint = enable;
|
| + cloudprint.setBaseURL(cloudPrintURL);
|
| +}
|
| +
|
| +/**
|
| + * Take the PDF data handed to us and submit it to the cloud, closing the print
|
| + * preview tab once the upload is successful.
|
| + * @param {pdfData} data to send as the print job.
|
| + */
|
| +function printToCloud(data) {
|
| + cloudprint.printToCloud(data, finishedCloudPrinting);
|
| +}
|
| +
|
| +/**
|
| + * Cloud print upload of the PDF file is finished, time to close the dialog.
|
| + */
|
| +function finishedCloudPrinting() {
|
| + window.location = cloudprint.getBaseURL();
|
| +}
|
| +
|
| +/**
|
| + * Disables or enables all controls in the options pane except for the cancel
|
| + * button.
|
| + */
|
| +function setControlsDisabled(disabled) {
|
| + var elementList = $('controls').elements;
|
| + for (var i = 0; i < elementList.length; ++i) {
|
| + if (elementList[i] == $('cancel-button'))
|
| + continue;
|
| + elementList[i].disabled = disabled;
|
| + }
|
| +}
|
| +
|
| +/**
|
| * Validates the copies text field value.
|
| * NOTE: An empty copies field text is considered valid because the blur event
|
| * listener of this field will set it back to a default value.
|
| @@ -294,19 +381,27 @@ function getDuplexMode() {
|
| * @return {string} JSON string with print job settings.
|
| */
|
| function getSettingsJSON() {
|
| + var printerList = $('printer-list');
|
| + var selectedPrinter = printerList.selectedIndex;
|
| var printAll = $('all-pages').checked;
|
| var deviceName = getSelectedPrinterName();
|
| var printToPDF = (deviceName == PRINT_TO_PDF);
|
|
|
| - return JSON.stringify({'deviceName': deviceName,
|
| - 'pageRange': getSelectedPageRanges(),
|
| - 'printAll': printAll,
|
| - 'duplex': getDuplexMode(),
|
| - 'copies': getCopies(),
|
| - 'collate': isCollated(),
|
| - 'landscape': isLandscape(),
|
| - 'color': isColor(),
|
| - 'printToPDF': printToPDF});
|
| + var settings = {'deviceName': deviceName,
|
| + 'pageRange': getSelectedPageRanges(),
|
| + 'printAll': printAll,
|
| + 'duplex': getDuplexMode(),
|
| + 'copies': getCopies(),
|
| + 'collate': isCollated(),
|
| + 'landscape': isLandscape(),
|
| + 'color': isColor(),
|
| + 'printToPDF': printToPDF};
|
| + if (printerList.options[selectedPrinter].isCloudPrint) {
|
| + settings['cloudPrintID'] =
|
| + printerList.options[selectedPrinter].value;
|
| + }
|
| +
|
| + return JSON.stringify(settings);
|
| }
|
|
|
| /**
|
| @@ -331,10 +426,12 @@ function printFile() {
|
| $('cancel-button').classList.add('loading');
|
| $('print-summary').innerHTML = localStrings.getString('printing');
|
| removeEventListeners();
|
| - window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); },
|
| - 1000);
|
| + var printerList = $('printer-list')
|
| + var printer = printerList[printerList.selectedIndex];
|
| + window.setTimeout(function() { chrome.send('print',
|
| + [getSettingsJSON(), cloudprint.getPrintTicketJSON(printer)]); }, 1000);
|
| } else
|
| - chrome.send('print', [getSettingsJSON()]);
|
| + chrome.send('print', [getSettingsJSON(), null]);
|
| }
|
|
|
| /**
|
| @@ -369,6 +466,16 @@ function setDefaultPrinter(printer) {
|
| */
|
| function setPrinters(printers, defaultPrinterIndex) {
|
| var printerList = $('printer-list');
|
| + if (useCloudPrint) {
|
| + cloudprint.fetchPrinters(addCloudPrinters);
|
| + if (printers.length > 0) {
|
| + option = addDestinationListOption('', '', false, true);
|
| + option = addDestinationListOption(localStrings.getString('localPrinters'),
|
| + '',
|
| + false,
|
| + true);
|
| + }
|
| + }
|
| // If there exists a dummy printer value, then setDefaultPrinter() already
|
| // requested a preview, so no need to do it again.
|
| var needPreview = (printerList[0].value == '');
|
| @@ -395,9 +502,15 @@ function setPrinters(printers, defaultPrinterIndex) {
|
| PRINT_TO_PDF, false, false);
|
| addDestinationListOption('', '', false, true);
|
|
|
| - // Add an option to manage printers.
|
| - addDestinationListOption(localStrings.getString('managePrinters'),
|
| - MANAGE_PRINTERS, false, false);
|
| + // Add options to manage printers.
|
| + if (!cr.isChromeOS) {
|
| + addDestinationListOption(localStrings.getString('manageLocalPrinters'),
|
| + MANAGE_LOCAL_PRINTERS, false, false);
|
| + }
|
| + if (useCloudPrint) {
|
| + addDestinationListOption(localStrings.getString('manageCloudPrinters'),
|
| + MANAGE_CLOUD_PRINTERS, false, false);
|
| + }
|
|
|
| printerList.disabled = false;
|
|
|
| @@ -420,6 +533,44 @@ function addDestinationListOption(optionText, optionValue, isDefault,
|
| $('printer-list').add(option);
|
| option.selected = isDefault;
|
| option.disabled = isDisabled;
|
| + return option;
|
| +}
|
| +
|
| +/**
|
| + * Add cloud printers to the list drop down.
|
| + * Called from the cloudprint object on receipt of printer information from the
|
| + * cloud print server.
|
| + */
|
| +function addCloudPrinters(printers) {
|
| + addDestinationListOption(localStrings.getString('cloudPrinters'),
|
| + '',
|
| + false,
|
| + true);
|
| + if (printers != null) {
|
| + var l = printers.length;
|
| + if (l > maxCloudPrinters) {
|
| + l = maxCloudPrinters;
|
| + }
|
| + for (var i = 0; i < l; i++) {
|
| + var option = addDestinationListOption(printers[i]['name'],
|
| + printers[i]['id'],
|
| + i == 0,
|
| + false);
|
| + option.isCloudPrint = true;
|
| + }
|
| + if (printers.length == 0) {
|
| + addDestinationListOption(localStrings.getString('addCloudPrinter'),
|
| + ADD_PRINTER, false, false);
|
| + }
|
| + if (l < printers.length) {
|
| + var option = addDestinationListOption('', '', false, true);
|
| + addDestinationListOption(localStrings.getString('morePrinters'),
|
| + MORE_PRINTERS, false, false);
|
| + }
|
| + } else {
|
| + addDestinationListOption(localStrings.getString('signIn'),
|
| + SIGN_IN, false, false);
|
| + }
|
| }
|
|
|
| /**
|
| @@ -433,6 +584,8 @@ function setColor(color) {
|
| return;
|
| }
|
| pdfViewer.grayscale(!color);
|
| + var printerList = $('printer-list')
|
| + cloudprint.setColor(printerList[printerList.selectedIndex], color);
|
| }
|
|
|
| /**
|
| @@ -972,3 +1125,4 @@ PrintSettings.prototype.save = function() {
|
| this.deviceName = getSelectedPrinterName();
|
| this.isLandscape = isLandscape();
|
| }
|
| +
|
|
|