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

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 7976017: Simplified print preview printer selection to be more consistent with Chrome (Closed)
Patch Set: Fixed typo in comment Created 9 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // require: cr/ui/print_preview_cloud.js 5 // require: cr/ui/print_preview_cloud.js
6 6
7 var localStrings = new LocalStrings(); 7 var localStrings = new LocalStrings();
8 8
9 // If useCloudPrint is true we attempt to connect to cloud print 9 // If useCloudPrint is true we attempt to connect to cloud print
10 // and populate the list of printers with cloud print printers. 10 // and populate the list of printers with cloud print printers.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // The range of options in the printer dropdown controlled by cloud print. 78 // The range of options in the printer dropdown controlled by cloud print.
79 var firstCloudPrintOptionPos = 0; 79 var firstCloudPrintOptionPos = 0;
80 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; 80 var lastCloudPrintOptionPos = firstCloudPrintOptionPos;
81 81
82 // Store the current previewUid. 82 // Store the current previewUid.
83 var currentPreviewUid = ''; 83 var currentPreviewUid = '';
84 84
85 // True if we need to generate draft preview data. 85 // True if we need to generate draft preview data.
86 var generateDraftData = true; 86 var generateDraftData = true;
87 87
88 // TODO(abodenha@chromium.org) A lot of cloud print specific logic has
89 // made its way into this file. Refactor to create a cleaner boundary
90 // between print preview and GCP code. Reference bug 88098 when fixing.
91
92 // A dictionary of cloud printers that have been added to the printer 88 // A dictionary of cloud printers that have been added to the printer
93 // dropdown. 89 // dropdown.
94 var addedCloudPrinters = {}; 90 var addedCloudPrinters = {};
95 91
96 // The maximum number of cloud printers to allow in the dropdown. 92 // The maximum number of cloud printers to allow in the dropdown.
97 const maxCloudPrinters = 10; 93 const maxCloudPrinters = 10;
98 94
99 const MIN_REQUEST_ID = 0; 95 const MIN_REQUEST_ID = 0;
100 const MAX_REQUEST_ID = 32000; 96 const MAX_REQUEST_ID = 32000;
101 97
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 * Gets the selected printer capabilities and updates the controls accordingly. 212 * Gets the selected printer capabilities and updates the controls accordingly.
217 */ 213 */
218 function updateControlsWithSelectedPrinterCapabilities() { 214 function updateControlsWithSelectedPrinterCapabilities() {
219 var printerList = $('printer-list'); 215 var printerList = $('printer-list');
220 var selectedIndex = printerList.selectedIndex; 216 var selectedIndex = printerList.selectedIndex;
221 if (selectedIndex < 0) 217 if (selectedIndex < 0)
222 return; 218 return;
223 var skip_refresh = false; 219 var skip_refresh = false;
224 var selectedValue = printerList.options[selectedIndex].value; 220 var selectedValue = printerList.options[selectedIndex].value;
225 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { 221 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) {
226 updateWithCloudPrinterCapabilities(); 222 cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
227 skip_refresh = true; 223 doUpdateCloudPrinterCapabilities);
228 } else if (selectedValue == PRINT_WITH_CLOUD_PRINT) {
229 // If a preview is pending this will just disable controls.
230 // Once the preview completes we'll try again.
231 printWithCloudPrintDialog();
232 skip_refresh = true; 224 skip_refresh = true;
233 } else if (selectedValue == SIGN_IN || 225 } else if (selectedValue == SIGN_IN ||
234 selectedValue == MANAGE_CLOUD_PRINTERS || 226 selectedValue == MANAGE_CLOUD_PRINTERS ||
235 selectedValue == MANAGE_LOCAL_PRINTERS) { 227 selectedValue == MANAGE_LOCAL_PRINTERS) {
236 printerList.selectedIndex = lastSelectedPrinterIndex; 228 printerList.selectedIndex = lastSelectedPrinterIndex;
237 chrome.send(selectedValue); 229 chrome.send(selectedValue);
238 skip_refresh = true; 230 skip_refresh = true;
239 } else if (selectedValue == PRINT_TO_PDF) { 231 } else if (selectedValue == PRINT_TO_PDF ||
232 selectedValue == PRINT_WITH_CLOUD_PRINT) {
240 updateWithPrinterCapabilities({ 233 updateWithPrinterCapabilities({
241 'disableColorOption': true, 234 'disableColorOption': true,
242 'setColorAsDefault': true, 235 'setColorAsDefault': true,
243 'setDuplexAsDefault': false, 236 'setDuplexAsDefault': false,
244 'printerColorModelForColor': colorSettings.COLOR, 237 'printerColorModelForColor': colorSettings.COLOR,
245 'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE, 238 'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE,
246 'disableCopiesOption': true}); 239 'disableCopiesOption': true});
247 } else { 240 } else {
248 // This message will call back to 'updateWithPrinterCapabilities' 241 // This message will call back to 'updateWithPrinterCapabilities'
249 // function. 242 // function.
250 chrome.send('getPrinterCapabilities', [selectedValue]); 243 chrome.send('getPrinterCapabilities', [selectedValue]);
251 } 244 }
252 if (!skip_refresh) { 245 if (!skip_refresh) {
253 lastSelectedPrinterIndex = selectedIndex; 246 lastSelectedPrinterIndex = selectedIndex;
254 247
255 // Regenerate the preview data based on selected printer settings. 248 // Regenerate the preview data based on selected printer settings.
256 setDefaultValuesAndRegeneratePreview(true); 249 setDefaultValuesAndRegeneratePreview(true);
257 } 250 }
258 } 251 }
259 252
260 /** 253 /**
261 * Updates the printer capabilities for the currently selected
262 * cloud print printer.
263 */
264 function updateWithCloudPrinterCapabilities() {
265 var printerList = $('printer-list');
266 var selectedIndex = printerList.selectedIndex;
267 cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
268 doUpdateCloudPrinterCapabilities);
269 }
270
271 /**
272 * Helper function to do the actual work of updating cloud printer 254 * Helper function to do the actual work of updating cloud printer
273 * capabilities. 255 * capabilities.
274 * @param {Object} printer The printer object to set capabilities for. 256 * @param {Object} printer The printer object to set capabilities for.
275 */ 257 */
276 function doUpdateCloudPrinterCapabilities(printer) { 258 function doUpdateCloudPrinterCapabilities(printer) {
277 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), 259 var settings = {'disableColorOption': !cloudprint.supportsColor(printer),
278 'setColorAsDefault': cloudprint.colorIsDefault(printer), 260 'setColorAsDefault': cloudprint.colorIsDefault(printer),
279 'disableCopiesOption': true, 261 'disableCopiesOption': true,
280 'disableLandscapeOption': true}; 262 'disableLandscapeOption': true};
281 updateWithPrinterCapabilities(settings); 263 updateWithPrinterCapabilities(settings);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 function finishedCloudPrinting() { 304 function finishedCloudPrinting() {
323 window.location = cloudprint.getBaseURL(); 305 window.location = cloudprint.getBaseURL();
324 } 306 }
325 307
326 /** 308 /**
327 * Checks whether the specified settings are valid. 309 * Checks whether the specified settings are valid.
328 * 310 *
329 * @return {boolean} true if settings are valid, false if not. 311 * @return {boolean} true if settings are valid, false if not.
330 */ 312 */
331 function areSettingsValid() { 313 function areSettingsValid() {
314 var selectedPrinter = getSelectedPrinterName();
332 return pageSettings.isPageSelectionValid() && 315 return pageSettings.isPageSelectionValid() &&
333 (copiesSettings.isValid() || 316 (copiesSettings.isValid() ||
334 getSelectedPrinterName() == PRINT_TO_PDF); 317 selectedPrinter() == PRINT_TO_PDF ||
kmadhusu 2011/09/23 20:30:07 selectedPrinter() => selectedPrinter
Albert Bodenhamer 2011/09/23 22:10:56 Done.
318 selectedPrinter() == PRINT_WITH_CLOUD_PRINT);
335 } 319 }
336 320
337 /** 321 /**
338 * Creates an object based on the values in the printer settings. 322 * Creates an object based on the values in the printer settings.
339 * 323 *
340 * @return {Object} Object containing print job settings. 324 * @return {Object} Object containing print job settings.
341 */ 325 */
342 function getSettings() { 326 function getSettings() {
343 var deviceName = getSelectedPrinterName(); 327 var deviceName = getSelectedPrinterName();
344 var printToPDF = (deviceName == PRINT_TO_PDF); 328 var printToPDF = deviceName == PRINT_TO_PDF;
329 var printWithCloudPrint = deviceName == PRINT_WITH_CLOUD_PRINT;
345 330
346 var settings = 331 var settings =
347 {'deviceName': deviceName, 332 {'deviceName': deviceName,
348 'pageRange': pageSettings.selectedPageRanges, 333 'pageRange': pageSettings.selectedPageRanges,
349 'duplex': copiesSettings.duplexMode, 334 'duplex': copiesSettings.duplexMode,
350 'copies': copiesSettings.numberOfCopies, 335 'copies': copiesSettings.numberOfCopies,
351 'collate': copiesSettings.isCollated(), 336 'collate': copiesSettings.isCollated(),
352 'landscape': layoutSettings.isLandscape(), 337 'landscape': layoutSettings.isLandscape(),
353 'color': colorSettings.colorMode, 338 'color': colorSettings.colorMode,
354 'printToPDF': printToPDF, 339 'printToPDF': printToPDF,
340 'printWithCloudPrint': printWithCloudPrint,
355 'isFirstRequest' : false, 341 'isFirstRequest' : false,
356 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(), 342 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(),
357 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(), 343 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(),
358 'margins': marginSettings.customMargins, 344 'margins': marginSettings.customMargins,
359 'requestID': -1, 345 'requestID': -1,
360 'generateDraftData': generateDraftData}; 346 'generateDraftData': generateDraftData};
361 347
362 var printerList = $('printer-list'); 348 var printerList = $('printer-list');
363 var selectedPrinter = printerList.selectedIndex; 349 var selectedPrinter = printerList.selectedIndex;
364 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { 350 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 return printerList.options[selectedPrinter].value; 414 return printerList.options[selectedPrinter].value;
429 } 415 }
430 416
431 /** 417 /**
432 * Asks the browser to print the preview PDF based on current print 418 * Asks the browser to print the preview PDF based on current print
433 * settings. If the preview is still loading, printPendingFile() will get 419 * settings. If the preview is still loading, printPendingFile() will get
434 * called once the preview loads. 420 * called once the preview loads.
435 */ 421 */
436 function requestToPrintDocument() { 422 function requestToPrintDocument() {
437 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; 423 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady;
438 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; 424 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF;
dpapad 2011/09/23 19:57:18 Nit: No need to invoke getSelectedPrinterName() tw
Albert Bodenhamer 2011/09/23 22:10:56 Done.
439 425 var printWithCloudPrint = getSelectedPrinterName() == PRINT_WITH_CLOUD_PRINT;
kmadhusu 2011/09/23 20:30:07 nit: var deviceName = getSelectedPrinterName(); v
Albert Bodenhamer 2011/09/23 22:10:56 Done.
440 if (hasPendingPrintDocumentRequest) { 426 if (hasPendingPrintDocumentRequest) {
441 if (printToPDF) { 427 if (printToPDF) {
442 sendPrintDocumentRequest(); 428 sendPrintDocumentRequest();
429 } else if (printWithCloudPrint) {
430 showCustomMessage(localStrings.getString('printWithCloudPrintWait'));
431 disableInputElementsInSidebar();
443 } else { 432 } else {
444 isTabHidden = true; 433 isTabHidden = true;
445 chrome.send('hidePreview'); 434 chrome.send('hidePreview');
446 } 435 }
447 return; 436 return;
448 } 437 }
449 438
450 if (printToPDF) { 439 if (printToPDF) {
451 sendPrintDocumentRequest(); 440 sendPrintDocumentRequest();
452 } else { 441 } else {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 * the default printer is a cloud printer. 534 * the default printer is a cloud printer.
546 */ 535 */
547 function setDefaultPrinter(printer_name, cloudPrintData) { 536 function setDefaultPrinter(printer_name, cloudPrintData) {
548 // Add a placeholder value so the printer list looks valid. 537 // Add a placeholder value so the printer list looks valid.
549 addDestinationListOption('', '', true, true, true); 538 addDestinationListOption('', '', true, true, true);
550 if (printer_name) { 539 if (printer_name) {
551 defaultOrLastUsedPrinterName = printer_name; 540 defaultOrLastUsedPrinterName = printer_name;
552 if (cloudPrintData) { 541 if (cloudPrintData) {
553 cloudprint.setDefaultPrinter(printer_name, 542 cloudprint.setDefaultPrinter(printer_name,
554 cloudPrintData, 543 cloudPrintData,
555 addCloudPrinters, 544 addDestinationListOptionAtPosition,
556 doUpdateCloudPrinterCapabilities); 545 doUpdateCloudPrinterCapabilities);
557 } else { 546 } else {
558 $('printer-list')[0].value = defaultOrLastUsedPrinterName; 547 $('printer-list')[0].value = defaultOrLastUsedPrinterName;
559 updateControlsWithSelectedPrinterCapabilities(); 548 updateControlsWithSelectedPrinterCapabilities();
560 } 549 }
561 } 550 }
562 chrome.send('getPrinters'); 551 chrome.send('getPrinters');
563 } 552 }
564 553
565 /** 554 /**
(...skipping 25 matching lines...) Expand all
591 if (useCloudPrint) { 580 if (useCloudPrint) {
592 addDestinationListOption(localStrings.getString('printWithCloudPrint'), 581 addDestinationListOption(localStrings.getString('printWithCloudPrint'),
593 PRINT_WITH_CLOUD_PRINT, 582 PRINT_WITH_CLOUD_PRINT,
594 false, 583 false,
595 false, 584 false,
596 false); 585 false);
597 addDestinationListOption('', '', false, true, true); 586 addDestinationListOption('', '', false, true, true);
598 } 587 }
599 // Add options to manage printers. 588 // Add options to manage printers.
600 if (!cr.isChromeOS) { 589 if (!cr.isChromeOS) {
601 addDestinationListOption(localStrings.getString('manageLocalPrinters'), 590 addDestinationListOption(localStrings.getString('managePrinters'),
602 MANAGE_LOCAL_PRINTERS, false, false, false); 591 MANAGE_LOCAL_PRINTERS, false, false, false);
603 } else if (useCloudPrint) { 592 } else if (useCloudPrint) {
604 // Fetch recent printers. 593 // Fetch recent printers.
605 cloudprint.fetchPrinters(addCloudPrinters, false); 594 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false);
606 // Fetch the full printer list. 595 // Fetch the full printer list.
607 cloudprint.fetchPrinters(addCloudPrinters, true); 596 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true);
608 addDestinationListOption(localStrings.getString('manageCloudPrinters'), 597 addDestinationListOption(localStrings.getString('managePrinters'),
609 MANAGE_CLOUD_PRINTERS, false, false, false); 598 MANAGE_CLOUD_PRINTERS, false, false, false);
610 } 599 }
611 600
612 printerList.disabled = false; 601 printerList.disabled = false;
613 602
614 if (!hasRequestedPreview()) 603 if (!hasRequestedPreview())
615 updateControlsWithSelectedPrinterCapabilities(); 604 updateControlsWithSelectedPrinterCapabilities();
616 } 605 }
617 606
618 /** 607 /**
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 var option = createDestinationListOption(optionText, 665 var option = createDestinationListOption(optionText,
677 optionValue, 666 optionValue,
678 isDefault, 667 isDefault,
679 isDisabled, 668 isDisabled,
680 isSeparator); 669 isSeparator);
681 var printerList = $('printer-list'); 670 var printerList = $('printer-list');
682 var before = printerList[position]; 671 var before = printerList[position];
683 printerList.add(option, before); 672 printerList.add(option, before);
684 return option; 673 return option;
685 } 674 }
686
687 /**
688 * Test if a particular cloud printer has already been added to the
689 * printer dropdown.
690 * @param {string} id A unique value to track this printer.
691 * @return {boolean} True if this id has previously been passed to
692 * trackCloudPrinterAdded.
693 */
694 function cloudPrinterAlreadyAdded(id) {
695 return (addedCloudPrinters[id]);
696 }
697
698 /**
699 * Record that a cloud printer will added to the printer dropdown.
700 * @param {string} id A unique value to track this printer.
701 * @return {boolean} False if adding this printer would exceed
702 * |maxCloudPrinters|.
703 */
704 function trackCloudPrinterAdded(id) {
705 if (Object.keys(addedCloudPrinters).length < maxCloudPrinters) {
706 addedCloudPrinters[id] = true;
707 return true;
708 } else {
709 return false;
710 }
711 }
712
713
714 /**
715 * Add cloud printers to the list drop down.
716 * Called from the cloudprint object on receipt of printer information from the
717 * cloud print server.
718 * @param {Array} printers Array of printer info objects.
719 * @return {Object} The currently selected printer.
720 */
721 function addCloudPrinters(printers) {
722 var isFirstPass = false;
723 var printerList = $('printer-list');
724
725 if (firstCloudPrintOptionPos == lastCloudPrintOptionPos) {
726 isFirstPass = true;
727 // Remove empty entry added by setDefaultPrinter.
728 if (printerList[0] && printerList[0].textContent == '')
729 printerList.remove(0);
730 var option = addDestinationListOptionAtPosition(
731 lastCloudPrintOptionPos++,
732 localStrings.getString('cloudPrinters'),
733 'Label',
734 false,
735 true,
736 false);
737 cloudprint.setCloudPrint(option, null, null);
738 }
739 if (printers != null) {
740 for (var i = 0; i < printers.length; i++) {
741 if (!cloudPrinterAlreadyAdded(printers[i]['id'])) {
742 if (!trackCloudPrinterAdded(printers[i]['id'])) {
743 break;
744 }
745 var option = addDestinationListOptionAtPosition(
746 lastCloudPrintOptionPos++,
747 printers[i]['name'],
748 printers[i]['id'],
749 printers[i]['name'] == defaultOrLastUsedPrinterName,
750 false,
751 false);
752 cloudprint.setCloudPrint(option,
753 printers[i]['name'],
754 printers[i]['id']);
755 }
756 }
757 } else {
758 if (!cloudPrinterAlreadyAdded(SIGN_IN)) {
759 addDestinationListOptionAtPosition(lastCloudPrintOptionPos++,
760 localStrings.getString('signIn'),
761 SIGN_IN,
762 false,
763 false,
764 false);
765 trackCloudPrinterAdded(SIGN_IN);
766 }
767 }
768 if (isFirstPass) {
769 addDestinationListOptionAtPosition(lastCloudPrintOptionPos,
770 '',
771 '',
772 false,
773 true,
774 true);
775 addDestinationListOptionAtPosition(lastCloudPrintOptionPos + 1,
776 localStrings.getString('localPrinters'),
777 '',
778 false,
779 true,
780 false);
781 }
782 var selectedPrinter = printerList.selectedIndex;
783 if (selectedPrinter < 0)
784 return null;
785 return printerList.options[selectedPrinter];
786 }
787
788 /** 675 /**
789 * Sets the color mode for the PDF plugin. 676 * Sets the color mode for the PDF plugin.
790 * Called from PrintPreviewHandler::ProcessColorSetting(). 677 * Called from PrintPreviewHandler::ProcessColorSetting().
791 * @param {boolean} color is true if the PDF plugin should display in color. 678 * @param {boolean} color is true if the PDF plugin should display in color.
792 */ 679 */
793 function setColor(color) { 680 function setColor(color) {
794 var pdfViewer = $('pdf-viewer'); 681 var pdfViewer = $('pdf-viewer');
795 if (!pdfViewer) { 682 if (!pdfViewer) {
796 return; 683 return;
797 } 684 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 // TODO(aayushkumar): Do something here! 789 // TODO(aayushkumar): Do something here!
903 } 790 }
904 791
905 /** 792 /**
906 * This function sends a request to hide the overlay layer only if there is no 793 * This function sends a request to hide the overlay layer only if there is no
907 * pending print document request and we are not waiting for the print ready 794 * pending print document request and we are not waiting for the print ready
908 * metafile. 795 * metafile.
909 */ 796 */
910 function checkAndHideOverlayLayerIfValid() { 797 function checkAndHideOverlayLayerIfValid() {
911 var selectedPrinter = getSelectedPrinterName(); 798 var selectedPrinter = getSelectedPrinterName();
912 var printToPDF = selectedPrinter == PRINT_TO_PDF; 799 var printToDialog = selectedPrinter == PRINT_TO_PDF ||
913 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; 800 selectedPrinter == PRINT_WITH_CLOUD_PRINT;
914 if ((printToPDF || printWithCloudPrint || !previewModifiable) && 801 if ((printToDialog || !previewModifiable) &&
915 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) { 802 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) {
916 return; 803 return;
917 } 804 }
918 hideOverlayLayer(); 805 hideOverlayLayer();
919 } 806 }
920 807
921 /** 808 /**
922 * Called when no pipelining previewed pages. 809 * Called when no pipelining previewed pages.
923 * @param {string} previewUid Preview unique identifier. 810 * @param {string} previewUid Preview unique identifier.
924 * @param {number} previewResponseId The preview request id that resulted in 811 * @param {number} previewResponseId The preview request id that resulted in
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 */ 896 */
1010 function sendPrintDocumentRequestIfNeeded() { 897 function sendPrintDocumentRequestIfNeeded() {
1011 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) 898 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded)
1012 return; 899 return;
1013 900
1014 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or 901 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or
1015 // the preview source is not modifiable, we need the print ready data for 902 // the preview source is not modifiable, we need the print ready data for
1016 // printing. If the preview source is modifiable, we need to wait till all 903 // printing. If the preview source is modifiable, we need to wait till all
1017 // the requested pages are loaded in the plugin for printing. 904 // the requested pages are loaded in the plugin for printing.
1018 var selectedPrinter = getSelectedPrinterName(); 905 var selectedPrinter = getSelectedPrinterName();
1019 var printToPDF = selectedPrinter == PRINT_TO_PDF; 906 var printToDialog = selectedPrinter == PRINT_TO_PDF ||
1020 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; 907 selectedPrinter == PRINT_WITH_CLOUD_PRINT;
1021 if (((printToPDF || !previewModifiable || printWithCloudPrint) && 908 if (((printToDialog || !previewModifiable) && !isPrintReadyMetafileReady) ||
1022 !isPrintReadyMetafileReady) ||
1023 (previewModifiable && hasPendingPreviewRequest)) { 909 (previewModifiable && hasPendingPreviewRequest)) {
1024 return; 910 return;
1025 } 911 }
1026 912
1027 hasPendingPrintDocumentRequest = false; 913 hasPendingPrintDocumentRequest = false;
1028 if (printWithCloudPrint) {
1029 chrome.send('printWithCloudPrint');
1030 return;
1031 }
1032 914
1033 if (!areSettingsValid()) { 915 if (!areSettingsValid()) {
1034 if (isTabHidden) 916 if (isTabHidden)
1035 cancelPendingPrintRequest(); 917 cancelPendingPrintRequest();
1036 return; 918 return;
1037 } 919 }
1038 sendPrintDocumentRequest(); 920 sendPrintDocumentRequest();
1039 } 921 }
1040 922
1041 /** 923 /**
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 * 'getInitiatorTabTitle' message. 1016 * 'getInitiatorTabTitle' message.
1135 * @param {string} initiatorTabTitle The title of the initiator tab. 1017 * @param {string} initiatorTabTitle The title of the initiator tab.
1136 */ 1018 */
1137 function setInitiatorTabTitle(initiatorTabTitle) { 1019 function setInitiatorTabTitle(initiatorTabTitle) {
1138 if (initiatorTabTitle == '') 1020 if (initiatorTabTitle == '')
1139 return; 1021 return;
1140 document.title = localStrings.getStringF( 1022 document.title = localStrings.getStringF(
1141 'printPreviewTitleFormat', initiatorTabTitle); 1023 'printPreviewTitleFormat', initiatorTabTitle);
1142 } 1024 }
1143 1025
1144 /**
1145 * Attempt to hide the preview tab and display the Cloud Print
1146 * dialog instead. Just disables controls if we're waiting on a new preview
1147 * to be generated.
1148 */
1149 function printWithCloudPrintDialog() {
1150 if (isPrintReadyMetafileReady) {
1151 chrome.send('printWithCloudPrint');
1152 } else {
1153 showCustomMessage(localStrings.getString('printWithCloudPrintWait'));
1154 disableInputElementsInSidebar();
1155 hasPendingPrintDocumentRequest = true;
1156 }
1157 }
1158
1159 /// Pull in all other scripts in a single shot. 1026 /// Pull in all other scripts in a single shot.
1160 <include src="print_preview_animations.js"/> 1027 <include src="print_preview_animations.js"/>
1161 <include src="print_preview_cloud.js"/> 1028 <include src="print_preview_cloud.js"/>
1162 <include src="print_preview_utils.js"/> 1029 <include src="print_preview_utils.js"/>
1163 <include src="print_header.js"/> 1030 <include src="print_header.js"/>
1164 <include src="page_settings.js"/> 1031 <include src="page_settings.js"/>
1165 <include src="copies_settings.js"/> 1032 <include src="copies_settings.js"/>
1166 <include src="header_footer_settings.js"/> 1033 <include src="header_footer_settings.js"/>
1167 <include src="layout_settings.js"/> 1034 <include src="layout_settings.js"/>
1168 <include src="color_settings.js"/> 1035 <include src="color_settings.js"/>
1169 <include src="margin_settings.js"/> 1036 <include src="margin_settings.js"/>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698