OLD | NEW |
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 Loading... |
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 |
88 // A dictionary of cloud printers that have been added to the printer | 92 // A dictionary of cloud printers that have been added to the printer |
89 // dropdown. | 93 // dropdown. |
90 var addedCloudPrinters = {}; | 94 var addedCloudPrinters = {}; |
91 | 95 |
92 // The maximum number of cloud printers to allow in the dropdown. | 96 // The maximum number of cloud printers to allow in the dropdown. |
93 const maxCloudPrinters = 10; | 97 const maxCloudPrinters = 10; |
94 | 98 |
95 const MIN_REQUEST_ID = 0; | 99 const MIN_REQUEST_ID = 0; |
96 const MAX_REQUEST_ID = 32000; | 100 const MAX_REQUEST_ID = 32000; |
97 | 101 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 * Gets the selected printer capabilities and updates the controls accordingly. | 216 * Gets the selected printer capabilities and updates the controls accordingly. |
213 */ | 217 */ |
214 function updateControlsWithSelectedPrinterCapabilities() { | 218 function updateControlsWithSelectedPrinterCapabilities() { |
215 var printerList = $('printer-list'); | 219 var printerList = $('printer-list'); |
216 var selectedIndex = printerList.selectedIndex; | 220 var selectedIndex = printerList.selectedIndex; |
217 if (selectedIndex < 0) | 221 if (selectedIndex < 0) |
218 return; | 222 return; |
219 var skip_refresh = false; | 223 var skip_refresh = false; |
220 var selectedValue = printerList.options[selectedIndex].value; | 224 var selectedValue = printerList.options[selectedIndex].value; |
221 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { | 225 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { |
222 cloudprint.updatePrinterCaps(printerList.options[selectedIndex], | 226 updateWithCloudPrinterCapabilities(); |
223 doUpdateCloudPrinterCapabilities); | 227 skip_refresh = true; |
| 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(); |
224 skip_refresh = true; | 232 skip_refresh = true; |
225 } else if (selectedValue == SIGN_IN || | 233 } else if (selectedValue == SIGN_IN || |
226 selectedValue == MANAGE_CLOUD_PRINTERS || | 234 selectedValue == MANAGE_CLOUD_PRINTERS || |
227 selectedValue == MANAGE_LOCAL_PRINTERS) { | 235 selectedValue == MANAGE_LOCAL_PRINTERS) { |
228 printerList.selectedIndex = lastSelectedPrinterIndex; | 236 printerList.selectedIndex = lastSelectedPrinterIndex; |
229 chrome.send(selectedValue); | 237 chrome.send(selectedValue); |
230 skip_refresh = true; | 238 skip_refresh = true; |
231 } else if (selectedValue == PRINT_TO_PDF || | 239 } else if (selectedValue == PRINT_TO_PDF) { |
232 selectedValue == PRINT_WITH_CLOUD_PRINT) { | |
233 updateWithPrinterCapabilities({ | 240 updateWithPrinterCapabilities({ |
234 'disableColorOption': true, | 241 'disableColorOption': true, |
235 'setColorAsDefault': true, | 242 'setColorAsDefault': true, |
236 'setDuplexAsDefault': false, | 243 'setDuplexAsDefault': false, |
237 'printerColorModelForColor': colorSettings.COLOR, | 244 'printerColorModelForColor': colorSettings.COLOR, |
238 'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE, | 245 'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE, |
239 'disableCopiesOption': true}); | 246 'disableCopiesOption': true}); |
240 } else { | 247 } else { |
241 // This message will call back to 'updateWithPrinterCapabilities' | 248 // This message will call back to 'updateWithPrinterCapabilities' |
242 // function. | 249 // function. |
243 chrome.send('getPrinterCapabilities', [selectedValue]); | 250 chrome.send('getPrinterCapabilities', [selectedValue]); |
244 } | 251 } |
245 if (!skip_refresh) { | 252 if (!skip_refresh) { |
246 lastSelectedPrinterIndex = selectedIndex; | 253 lastSelectedPrinterIndex = selectedIndex; |
247 | 254 |
248 // Regenerate the preview data based on selected printer settings. | 255 // Regenerate the preview data based on selected printer settings. |
249 setDefaultValuesAndRegeneratePreview(true); | 256 setDefaultValuesAndRegeneratePreview(true); |
250 } | 257 } |
251 } | 258 } |
252 | 259 |
253 /** | 260 /** |
| 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 /** |
254 * Helper function to do the actual work of updating cloud printer | 272 * Helper function to do the actual work of updating cloud printer |
255 * capabilities. | 273 * capabilities. |
256 * @param {Object} printer The printer object to set capabilities for. | 274 * @param {Object} printer The printer object to set capabilities for. |
257 */ | 275 */ |
258 function doUpdateCloudPrinterCapabilities(printer) { | 276 function doUpdateCloudPrinterCapabilities(printer) { |
259 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), | 277 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), |
260 'setColorAsDefault': cloudprint.colorIsDefault(printer), | 278 'setColorAsDefault': cloudprint.colorIsDefault(printer), |
261 'disableCopiesOption': true, | 279 'disableCopiesOption': true, |
262 'disableLandscapeOption': true}; | 280 'disableLandscapeOption': true}; |
263 updateWithPrinterCapabilities(settings); | 281 updateWithPrinterCapabilities(settings); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 function finishedCloudPrinting() { | 322 function finishedCloudPrinting() { |
305 window.location = cloudprint.getBaseURL(); | 323 window.location = cloudprint.getBaseURL(); |
306 } | 324 } |
307 | 325 |
308 /** | 326 /** |
309 * Checks whether the specified settings are valid. | 327 * Checks whether the specified settings are valid. |
310 * | 328 * |
311 * @return {boolean} true if settings are valid, false if not. | 329 * @return {boolean} true if settings are valid, false if not. |
312 */ | 330 */ |
313 function areSettingsValid() { | 331 function areSettingsValid() { |
314 var selectedPrinter = getSelectedPrinterName(); | |
315 return pageSettings.isPageSelectionValid() && | 332 return pageSettings.isPageSelectionValid() && |
316 (copiesSettings.isValid() || | 333 (copiesSettings.isValid() || |
317 selectedPrinter == PRINT_TO_PDF || | 334 getSelectedPrinterName() == PRINT_TO_PDF); |
318 selectedPrinter == PRINT_WITH_CLOUD_PRINT); | |
319 } | 335 } |
320 | 336 |
321 /** | 337 /** |
322 * Creates an object based on the values in the printer settings. | 338 * Creates an object based on the values in the printer settings. |
323 * | 339 * |
324 * @return {Object} Object containing print job settings. | 340 * @return {Object} Object containing print job settings. |
325 */ | 341 */ |
326 function getSettings() { | 342 function getSettings() { |
327 var deviceName = getSelectedPrinterName(); | 343 var deviceName = getSelectedPrinterName(); |
328 var printToPDF = deviceName == PRINT_TO_PDF; | 344 var printToPDF = (deviceName == PRINT_TO_PDF); |
329 var printWithCloudPrint = deviceName == PRINT_WITH_CLOUD_PRINT; | |
330 | 345 |
331 var settings = | 346 var settings = |
332 {'deviceName': deviceName, | 347 {'deviceName': deviceName, |
333 'pageRange': pageSettings.selectedPageRanges, | 348 'pageRange': pageSettings.selectedPageRanges, |
334 'duplex': copiesSettings.duplexMode, | 349 'duplex': copiesSettings.duplexMode, |
335 'copies': copiesSettings.numberOfCopies, | 350 'copies': copiesSettings.numberOfCopies, |
336 'collate': copiesSettings.isCollated(), | 351 'collate': copiesSettings.isCollated(), |
337 'landscape': layoutSettings.isLandscape(), | 352 'landscape': layoutSettings.isLandscape(), |
338 'color': colorSettings.colorMode, | 353 'color': colorSettings.colorMode, |
339 'printToPDF': printToPDF, | 354 'printToPDF': printToPDF, |
340 'printWithCloudPrint': printWithCloudPrint, | |
341 'isFirstRequest' : false, | 355 'isFirstRequest' : false, |
342 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(), | 356 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(), |
343 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(), | 357 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(), |
344 'margins': marginSettings.customMargins, | 358 'margins': marginSettings.customMargins, |
345 'requestID': -1, | 359 'requestID': -1, |
346 'generateDraftData': generateDraftData}; | 360 'generateDraftData': generateDraftData}; |
347 | 361 |
348 var printerList = $('printer-list'); | 362 var printerList = $('printer-list'); |
349 var selectedPrinter = printerList.selectedIndex; | 363 var selectedPrinter = printerList.selectedIndex; |
350 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { | 364 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 return printerList.options[selectedPrinter].value; | 428 return printerList.options[selectedPrinter].value; |
415 } | 429 } |
416 | 430 |
417 /** | 431 /** |
418 * Asks the browser to print the preview PDF based on current print | 432 * Asks the browser to print the preview PDF based on current print |
419 * settings. If the preview is still loading, printPendingFile() will get | 433 * settings. If the preview is still loading, printPendingFile() will get |
420 * called once the preview loads. | 434 * called once the preview loads. |
421 */ | 435 */ |
422 function requestToPrintDocument() { | 436 function requestToPrintDocument() { |
423 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; | 437 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; |
424 var selectedPrinterName = getSelectedPrinterName(); | 438 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; |
425 var printToPDF = selectedPrinterName == PRINT_TO_PDF; | 439 |
426 var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; | |
427 if (hasPendingPrintDocumentRequest) { | 440 if (hasPendingPrintDocumentRequest) { |
428 if (printToPDF) { | 441 if (printToPDF) { |
429 sendPrintDocumentRequest(); | 442 sendPrintDocumentRequest(); |
430 } else if (printWithCloudPrint) { | |
431 showCustomMessage(localStrings.getString('printWithCloudPrintWait')); | |
432 disableInputElementsInSidebar(); | |
433 } else { | 443 } else { |
434 isTabHidden = true; | 444 isTabHidden = true; |
435 chrome.send('hidePreview'); | 445 chrome.send('hidePreview'); |
436 } | 446 } |
437 return; | 447 return; |
438 } | 448 } |
439 | 449 |
440 if (printToPDF) { | 450 if (printToPDF) { |
441 sendPrintDocumentRequest(); | 451 sendPrintDocumentRequest(); |
442 } else { | 452 } else { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 * the default printer is a cloud printer. | 545 * the default printer is a cloud printer. |
536 */ | 546 */ |
537 function setDefaultPrinter(printer_name, cloudPrintData) { | 547 function setDefaultPrinter(printer_name, cloudPrintData) { |
538 // Add a placeholder value so the printer list looks valid. | 548 // Add a placeholder value so the printer list looks valid. |
539 addDestinationListOption('', '', true, true, true); | 549 addDestinationListOption('', '', true, true, true); |
540 if (printer_name) { | 550 if (printer_name) { |
541 defaultOrLastUsedPrinterName = printer_name; | 551 defaultOrLastUsedPrinterName = printer_name; |
542 if (cloudPrintData) { | 552 if (cloudPrintData) { |
543 cloudprint.setDefaultPrinter(printer_name, | 553 cloudprint.setDefaultPrinter(printer_name, |
544 cloudPrintData, | 554 cloudPrintData, |
545 addDestinationListOptionAtPosition, | 555 addCloudPrinters, |
546 doUpdateCloudPrinterCapabilities); | 556 doUpdateCloudPrinterCapabilities); |
547 } else { | 557 } else { |
548 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 558 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
549 updateControlsWithSelectedPrinterCapabilities(); | 559 updateControlsWithSelectedPrinterCapabilities(); |
550 } | 560 } |
551 } | 561 } |
552 chrome.send('getPrinters'); | 562 chrome.send('getPrinters'); |
553 } | 563 } |
554 | 564 |
555 /** | 565 /** |
(...skipping 25 matching lines...) Expand all Loading... |
581 if (useCloudPrint) { | 591 if (useCloudPrint) { |
582 addDestinationListOption(localStrings.getString('printWithCloudPrint'), | 592 addDestinationListOption(localStrings.getString('printWithCloudPrint'), |
583 PRINT_WITH_CLOUD_PRINT, | 593 PRINT_WITH_CLOUD_PRINT, |
584 false, | 594 false, |
585 false, | 595 false, |
586 false); | 596 false); |
587 addDestinationListOption('', '', false, true, true); | 597 addDestinationListOption('', '', false, true, true); |
588 } | 598 } |
589 // Add options to manage printers. | 599 // Add options to manage printers. |
590 if (!cr.isChromeOS) { | 600 if (!cr.isChromeOS) { |
591 addDestinationListOption(localStrings.getString('managePrinters'), | 601 addDestinationListOption(localStrings.getString('manageLocalPrinters'), |
592 MANAGE_LOCAL_PRINTERS, false, false, false); | 602 MANAGE_LOCAL_PRINTERS, false, false, false); |
593 } else if (useCloudPrint) { | 603 } else if (useCloudPrint) { |
594 // Fetch recent printers. | 604 // Fetch recent printers. |
595 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false); | 605 cloudprint.fetchPrinters(addCloudPrinters, false); |
596 // Fetch the full printer list. | 606 // Fetch the full printer list. |
597 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true); | 607 cloudprint.fetchPrinters(addCloudPrinters, true); |
598 addDestinationListOption(localStrings.getString('managePrinters'), | 608 addDestinationListOption(localStrings.getString('manageCloudPrinters'), |
599 MANAGE_CLOUD_PRINTERS, false, false, false); | 609 MANAGE_CLOUD_PRINTERS, false, false, false); |
600 } | 610 } |
601 | 611 |
602 printerList.disabled = false; | 612 printerList.disabled = false; |
603 | 613 |
604 if (!hasRequestedPreview()) | 614 if (!hasRequestedPreview()) |
605 updateControlsWithSelectedPrinterCapabilities(); | 615 updateControlsWithSelectedPrinterCapabilities(); |
606 } | 616 } |
607 | 617 |
608 /** | 618 /** |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 var option = createDestinationListOption(optionText, | 676 var option = createDestinationListOption(optionText, |
667 optionValue, | 677 optionValue, |
668 isDefault, | 678 isDefault, |
669 isDisabled, | 679 isDisabled, |
670 isSeparator); | 680 isSeparator); |
671 var printerList = $('printer-list'); | 681 var printerList = $('printer-list'); |
672 var before = printerList[position]; | 682 var before = printerList[position]; |
673 printerList.add(option, before); | 683 printerList.add(option, before); |
674 return option; | 684 return option; |
675 } | 685 } |
| 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 |
676 /** | 788 /** |
677 * Sets the color mode for the PDF plugin. | 789 * Sets the color mode for the PDF plugin. |
678 * Called from PrintPreviewHandler::ProcessColorSetting(). | 790 * Called from PrintPreviewHandler::ProcessColorSetting(). |
679 * @param {boolean} color is true if the PDF plugin should display in color. | 791 * @param {boolean} color is true if the PDF plugin should display in color. |
680 */ | 792 */ |
681 function setColor(color) { | 793 function setColor(color) { |
682 var pdfViewer = $('pdf-viewer'); | 794 var pdfViewer = $('pdf-viewer'); |
683 if (!pdfViewer) { | 795 if (!pdfViewer) { |
684 return; | 796 return; |
685 } | 797 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 // TODO(aayushkumar): Do something here! | 902 // TODO(aayushkumar): Do something here! |
791 } | 903 } |
792 | 904 |
793 /** | 905 /** |
794 * This function sends a request to hide the overlay layer only if there is no | 906 * This function sends a request to hide the overlay layer only if there is no |
795 * pending print document request and we are not waiting for the print ready | 907 * pending print document request and we are not waiting for the print ready |
796 * metafile. | 908 * metafile. |
797 */ | 909 */ |
798 function checkAndHideOverlayLayerIfValid() { | 910 function checkAndHideOverlayLayerIfValid() { |
799 var selectedPrinter = getSelectedPrinterName(); | 911 var selectedPrinter = getSelectedPrinterName(); |
800 var printToDialog = selectedPrinter == PRINT_TO_PDF || | 912 var printToPDF = selectedPrinter == PRINT_TO_PDF; |
801 selectedPrinter == PRINT_WITH_CLOUD_PRINT; | 913 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; |
802 if ((printToDialog || !previewModifiable) && | 914 if ((printToPDF || printWithCloudPrint || !previewModifiable) && |
803 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) { | 915 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) { |
804 return; | 916 return; |
805 } | 917 } |
806 hideOverlayLayer(); | 918 hideOverlayLayer(); |
807 } | 919 } |
808 | 920 |
809 /** | 921 /** |
810 * Called when no pipelining previewed pages. | 922 * Called when no pipelining previewed pages. |
811 * @param {string} previewUid Preview unique identifier. | 923 * @param {string} previewUid Preview unique identifier. |
812 * @param {number} previewResponseId The preview request id that resulted in | 924 * @param {number} previewResponseId The preview request id that resulted in |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 */ | 1009 */ |
898 function sendPrintDocumentRequestIfNeeded() { | 1010 function sendPrintDocumentRequestIfNeeded() { |
899 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) | 1011 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) |
900 return; | 1012 return; |
901 | 1013 |
902 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or | 1014 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or |
903 // the preview source is not modifiable, we need the print ready data for | 1015 // the preview source is not modifiable, we need the print ready data for |
904 // printing. If the preview source is modifiable, we need to wait till all | 1016 // printing. If the preview source is modifiable, we need to wait till all |
905 // the requested pages are loaded in the plugin for printing. | 1017 // the requested pages are loaded in the plugin for printing. |
906 var selectedPrinter = getSelectedPrinterName(); | 1018 var selectedPrinter = getSelectedPrinterName(); |
907 var printToDialog = selectedPrinter == PRINT_TO_PDF || | 1019 var printToPDF = selectedPrinter == PRINT_TO_PDF; |
908 selectedPrinter == PRINT_WITH_CLOUD_PRINT; | 1020 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; |
909 if (((printToDialog || !previewModifiable) && !isPrintReadyMetafileReady) || | 1021 if (((printToPDF || !previewModifiable || printWithCloudPrint) && |
| 1022 !isPrintReadyMetafileReady) || |
910 (previewModifiable && hasPendingPreviewRequest)) { | 1023 (previewModifiable && hasPendingPreviewRequest)) { |
911 return; | 1024 return; |
912 } | 1025 } |
913 | 1026 |
914 hasPendingPrintDocumentRequest = false; | 1027 hasPendingPrintDocumentRequest = false; |
| 1028 if (printWithCloudPrint) { |
| 1029 chrome.send('printWithCloudPrint'); |
| 1030 return; |
| 1031 } |
915 | 1032 |
916 if (!areSettingsValid()) { | 1033 if (!areSettingsValid()) { |
917 if (isTabHidden) | 1034 if (isTabHidden) |
918 cancelPendingPrintRequest(); | 1035 cancelPendingPrintRequest(); |
919 return; | 1036 return; |
920 } | 1037 } |
921 sendPrintDocumentRequest(); | 1038 sendPrintDocumentRequest(); |
922 } | 1039 } |
923 | 1040 |
924 /** | 1041 /** |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 * 'getInitiatorTabTitle' message. | 1134 * 'getInitiatorTabTitle' message. |
1018 * @param {string} initiatorTabTitle The title of the initiator tab. | 1135 * @param {string} initiatorTabTitle The title of the initiator tab. |
1019 */ | 1136 */ |
1020 function setInitiatorTabTitle(initiatorTabTitle) { | 1137 function setInitiatorTabTitle(initiatorTabTitle) { |
1021 if (initiatorTabTitle == '') | 1138 if (initiatorTabTitle == '') |
1022 return; | 1139 return; |
1023 document.title = localStrings.getStringF( | 1140 document.title = localStrings.getStringF( |
1024 'printPreviewTitleFormat', initiatorTabTitle); | 1141 'printPreviewTitleFormat', initiatorTabTitle); |
1025 } | 1142 } |
1026 | 1143 |
| 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 |
1027 /// Pull in all other scripts in a single shot. | 1159 /// Pull in all other scripts in a single shot. |
1028 <include src="print_preview_animations.js"/> | 1160 <include src="print_preview_animations.js"/> |
1029 <include src="print_preview_cloud.js"/> | 1161 <include src="print_preview_cloud.js"/> |
1030 <include src="print_preview_utils.js"/> | 1162 <include src="print_preview_utils.js"/> |
1031 <include src="print_header.js"/> | 1163 <include src="print_header.js"/> |
1032 <include src="page_settings.js"/> | 1164 <include src="page_settings.js"/> |
1033 <include src="copies_settings.js"/> | 1165 <include src="copies_settings.js"/> |
1034 <include src="header_footer_settings.js"/> | 1166 <include src="header_footer_settings.js"/> |
1035 <include src="layout_settings.js"/> | 1167 <include src="layout_settings.js"/> |
1036 <include src="color_settings.js"/> | 1168 <include src="color_settings.js"/> |
1037 <include src="margin_settings.js"/> | 1169 <include src="margin_settings.js"/> |
OLD | NEW |