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 | |
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 Loading... |
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 Loading... |
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 || |
| 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 Loading... |
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 selectedPrinterName = getSelectedPrinterName(); |
439 | 425 var printToPDF = selectedPrinterName == PRINT_TO_PDF; |
| 426 var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; |
440 if (hasPendingPrintDocumentRequest) { | 427 if (hasPendingPrintDocumentRequest) { |
441 if (printToPDF) { | 428 if (printToPDF) { |
442 sendPrintDocumentRequest(); | 429 sendPrintDocumentRequest(); |
| 430 } else if (printWithCloudPrint) { |
| 431 showCustomMessage(localStrings.getString('printWithCloudPrintWait')); |
| 432 disableInputElementsInSidebar(); |
443 } else { | 433 } else { |
444 isTabHidden = true; | 434 isTabHidden = true; |
445 chrome.send('hidePreview'); | 435 chrome.send('hidePreview'); |
446 } | 436 } |
447 return; | 437 return; |
448 } | 438 } |
449 | 439 |
450 if (printToPDF) { | 440 if (printToPDF) { |
451 sendPrintDocumentRequest(); | 441 sendPrintDocumentRequest(); |
452 } else { | 442 } else { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 * the default printer is a cloud printer. | 535 * the default printer is a cloud printer. |
546 */ | 536 */ |
547 function setDefaultPrinter(printer_name, cloudPrintData) { | 537 function setDefaultPrinter(printer_name, cloudPrintData) { |
548 // Add a placeholder value so the printer list looks valid. | 538 // Add a placeholder value so the printer list looks valid. |
549 addDestinationListOption('', '', true, true, true); | 539 addDestinationListOption('', '', true, true, true); |
550 if (printer_name) { | 540 if (printer_name) { |
551 defaultOrLastUsedPrinterName = printer_name; | 541 defaultOrLastUsedPrinterName = printer_name; |
552 if (cloudPrintData) { | 542 if (cloudPrintData) { |
553 cloudprint.setDefaultPrinter(printer_name, | 543 cloudprint.setDefaultPrinter(printer_name, |
554 cloudPrintData, | 544 cloudPrintData, |
555 addCloudPrinters, | 545 addDestinationListOptionAtPosition, |
556 doUpdateCloudPrinterCapabilities); | 546 doUpdateCloudPrinterCapabilities); |
557 } else { | 547 } else { |
558 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 548 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
559 updateControlsWithSelectedPrinterCapabilities(); | 549 updateControlsWithSelectedPrinterCapabilities(); |
560 } | 550 } |
561 } | 551 } |
562 chrome.send('getPrinters'); | 552 chrome.send('getPrinters'); |
563 } | 553 } |
564 | 554 |
565 /** | 555 /** |
(...skipping 25 matching lines...) Expand all Loading... |
591 if (useCloudPrint) { | 581 if (useCloudPrint) { |
592 addDestinationListOption(localStrings.getString('printWithCloudPrint'), | 582 addDestinationListOption(localStrings.getString('printWithCloudPrint'), |
593 PRINT_WITH_CLOUD_PRINT, | 583 PRINT_WITH_CLOUD_PRINT, |
594 false, | 584 false, |
595 false, | 585 false, |
596 false); | 586 false); |
597 addDestinationListOption('', '', false, true, true); | 587 addDestinationListOption('', '', false, true, true); |
598 } | 588 } |
599 // Add options to manage printers. | 589 // Add options to manage printers. |
600 if (!cr.isChromeOS) { | 590 if (!cr.isChromeOS) { |
601 addDestinationListOption(localStrings.getString('manageLocalPrinters'), | 591 addDestinationListOption(localStrings.getString('managePrinters'), |
602 MANAGE_LOCAL_PRINTERS, false, false, false); | 592 MANAGE_LOCAL_PRINTERS, false, false, false); |
603 } else if (useCloudPrint) { | 593 } else if (useCloudPrint) { |
604 // Fetch recent printers. | 594 // Fetch recent printers. |
605 cloudprint.fetchPrinters(addCloudPrinters, false); | 595 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false); |
606 // Fetch the full printer list. | 596 // Fetch the full printer list. |
607 cloudprint.fetchPrinters(addCloudPrinters, true); | 597 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true); |
608 addDestinationListOption(localStrings.getString('manageCloudPrinters'), | 598 addDestinationListOption(localStrings.getString('managePrinters'), |
609 MANAGE_CLOUD_PRINTERS, false, false, false); | 599 MANAGE_CLOUD_PRINTERS, false, false, false); |
610 } | 600 } |
611 | 601 |
612 printerList.disabled = false; | 602 printerList.disabled = false; |
613 | 603 |
614 if (!hasRequestedPreview()) | 604 if (!hasRequestedPreview()) |
615 updateControlsWithSelectedPrinterCapabilities(); | 605 updateControlsWithSelectedPrinterCapabilities(); |
616 } | 606 } |
617 | 607 |
618 /** | 608 /** |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 var option = createDestinationListOption(optionText, | 666 var option = createDestinationListOption(optionText, |
677 optionValue, | 667 optionValue, |
678 isDefault, | 668 isDefault, |
679 isDisabled, | 669 isDisabled, |
680 isSeparator); | 670 isSeparator); |
681 var printerList = $('printer-list'); | 671 var printerList = $('printer-list'); |
682 var before = printerList[position]; | 672 var before = printerList[position]; |
683 printerList.add(option, before); | 673 printerList.add(option, before); |
684 return option; | 674 return option; |
685 } | 675 } |
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 /** | 676 /** |
789 * Sets the color mode for the PDF plugin. | 677 * Sets the color mode for the PDF plugin. |
790 * Called from PrintPreviewHandler::ProcessColorSetting(). | 678 * Called from PrintPreviewHandler::ProcessColorSetting(). |
791 * @param {boolean} color is true if the PDF plugin should display in color. | 679 * @param {boolean} color is true if the PDF plugin should display in color. |
792 */ | 680 */ |
793 function setColor(color) { | 681 function setColor(color) { |
794 var pdfViewer = $('pdf-viewer'); | 682 var pdfViewer = $('pdf-viewer'); |
795 if (!pdfViewer) { | 683 if (!pdfViewer) { |
796 return; | 684 return; |
797 } | 685 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 // TODO(aayushkumar): Do something here! | 790 // TODO(aayushkumar): Do something here! |
903 } | 791 } |
904 | 792 |
905 /** | 793 /** |
906 * This function sends a request to hide the overlay layer only if there is no | 794 * 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 | 795 * pending print document request and we are not waiting for the print ready |
908 * metafile. | 796 * metafile. |
909 */ | 797 */ |
910 function checkAndHideOverlayLayerIfValid() { | 798 function checkAndHideOverlayLayerIfValid() { |
911 var selectedPrinter = getSelectedPrinterName(); | 799 var selectedPrinter = getSelectedPrinterName(); |
912 var printToPDF = selectedPrinter == PRINT_TO_PDF; | 800 var printToDialog = selectedPrinter == PRINT_TO_PDF || |
913 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; | 801 selectedPrinter == PRINT_WITH_CLOUD_PRINT; |
914 if ((printToPDF || printWithCloudPrint || !previewModifiable) && | 802 if ((printToDialog || !previewModifiable) && |
915 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) { | 803 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) { |
916 return; | 804 return; |
917 } | 805 } |
918 hideOverlayLayer(); | 806 hideOverlayLayer(); |
919 } | 807 } |
920 | 808 |
921 /** | 809 /** |
922 * Called when no pipelining previewed pages. | 810 * Called when no pipelining previewed pages. |
923 * @param {string} previewUid Preview unique identifier. | 811 * @param {string} previewUid Preview unique identifier. |
924 * @param {number} previewResponseId The preview request id that resulted in | 812 * @param {number} previewResponseId The preview request id that resulted in |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 */ | 897 */ |
1010 function sendPrintDocumentRequestIfNeeded() { | 898 function sendPrintDocumentRequestIfNeeded() { |
1011 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) | 899 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) |
1012 return; | 900 return; |
1013 | 901 |
1014 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or | 902 // 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 | 903 // 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 | 904 // printing. If the preview source is modifiable, we need to wait till all |
1017 // the requested pages are loaded in the plugin for printing. | 905 // the requested pages are loaded in the plugin for printing. |
1018 var selectedPrinter = getSelectedPrinterName(); | 906 var selectedPrinter = getSelectedPrinterName(); |
1019 var printToPDF = selectedPrinter == PRINT_TO_PDF; | 907 var printToDialog = selectedPrinter == PRINT_TO_PDF || |
1020 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; | 908 selectedPrinter == PRINT_WITH_CLOUD_PRINT; |
1021 if (((printToPDF || !previewModifiable || printWithCloudPrint) && | 909 if (((printToDialog || !previewModifiable) && !isPrintReadyMetafileReady) || |
1022 !isPrintReadyMetafileReady) || | |
1023 (previewModifiable && hasPendingPreviewRequest)) { | 910 (previewModifiable && hasPendingPreviewRequest)) { |
1024 return; | 911 return; |
1025 } | 912 } |
1026 | 913 |
1027 hasPendingPrintDocumentRequest = false; | 914 hasPendingPrintDocumentRequest = false; |
1028 if (printWithCloudPrint) { | |
1029 chrome.send('printWithCloudPrint'); | |
1030 return; | |
1031 } | |
1032 | 915 |
1033 if (!areSettingsValid()) { | 916 if (!areSettingsValid()) { |
1034 if (isTabHidden) | 917 if (isTabHidden) |
1035 cancelPendingPrintRequest(); | 918 cancelPendingPrintRequest(); |
1036 return; | 919 return; |
1037 } | 920 } |
1038 sendPrintDocumentRequest(); | 921 sendPrintDocumentRequest(); |
1039 } | 922 } |
1040 | 923 |
1041 /** | 924 /** |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 * 'getInitiatorTabTitle' message. | 1017 * 'getInitiatorTabTitle' message. |
1135 * @param {string} initiatorTabTitle The title of the initiator tab. | 1018 * @param {string} initiatorTabTitle The title of the initiator tab. |
1136 */ | 1019 */ |
1137 function setInitiatorTabTitle(initiatorTabTitle) { | 1020 function setInitiatorTabTitle(initiatorTabTitle) { |
1138 if (initiatorTabTitle == '') | 1021 if (initiatorTabTitle == '') |
1139 return; | 1022 return; |
1140 document.title = localStrings.getStringF( | 1023 document.title = localStrings.getStringF( |
1141 'printPreviewTitleFormat', initiatorTabTitle); | 1024 'printPreviewTitleFormat', initiatorTabTitle); |
1142 } | 1025 } |
1143 | 1026 |
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. | 1027 /// Pull in all other scripts in a single shot. |
1160 <include src="print_preview_animations.js"/> | 1028 <include src="print_preview_animations.js"/> |
1161 <include src="print_preview_cloud.js"/> | 1029 <include src="print_preview_cloud.js"/> |
1162 <include src="print_preview_utils.js"/> | 1030 <include src="print_preview_utils.js"/> |
1163 <include src="print_header.js"/> | 1031 <include src="print_header.js"/> |
1164 <include src="page_settings.js"/> | 1032 <include src="page_settings.js"/> |
1165 <include src="copies_settings.js"/> | 1033 <include src="copies_settings.js"/> |
1166 <include src="header_footer_settings.js"/> | 1034 <include src="header_footer_settings.js"/> |
1167 <include src="layout_settings.js"/> | 1035 <include src="layout_settings.js"/> |
1168 <include src="color_settings.js"/> | 1036 <include src="color_settings.js"/> |
1169 <include src="margin_settings.js"/> | 1037 <include src="margin_settings.js"/> |
OLD | NEW |