Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 // The name of the default or last used printer. | 30 // The name of the default or last used printer. |
| 31 var defaultOrLastUsedPrinterName = ''; | 31 var defaultOrLastUsedPrinterName = ''; |
| 32 | 32 |
| 33 // True when a pending print preview request exists. | 33 // True when a pending print preview request exists. |
| 34 var hasPendingPreviewRequest = false; | 34 var hasPendingPreviewRequest = false; |
| 35 | 35 |
| 36 // The ID of the last preview request. | 36 // The ID of the last preview request. |
| 37 var lastPreviewRequestID = -1; | 37 var lastPreviewRequestID = -1; |
| 38 | 38 |
| 39 // The ID of the initial preview request. | |
| 40 var initialPreviewRequestID = -1; | |
| 41 | |
| 39 // True when a pending print file request exists. | 42 // True when a pending print file request exists. |
| 40 var hasPendingPrintDocumentRequest = false; | 43 var hasPendingPrintDocumentRequest = false; |
| 41 | 44 |
| 42 // True when preview tab is hidden. | 45 // True when preview tab is hidden. |
| 43 var isTabHidden = false; | 46 var isTabHidden = false; |
| 44 | 47 |
| 45 // Object holding all the pages related settings. | 48 // Object holding all the pages related settings. |
| 46 var pageSettings; | 49 var pageSettings; |
| 47 | 50 |
| 48 // Object holding all the copies related settings. | 51 // Object holding all the copies related settings. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 67 // made its way into this file. Refactor to create a cleaner boundary | 70 // made its way into this file. Refactor to create a cleaner boundary |
| 68 // between print preview and GCP code. Reference bug 88098 when fixing. | 71 // between print preview and GCP code. Reference bug 88098 when fixing. |
| 69 | 72 |
| 70 // A dictionary of cloud printers that have been added to the printer | 73 // A dictionary of cloud printers that have been added to the printer |
| 71 // dropdown. | 74 // dropdown. |
| 72 var addedCloudPrinters = {}; | 75 var addedCloudPrinters = {}; |
| 73 | 76 |
| 74 // The maximum number of cloud printers to allow in the dropdown. | 77 // The maximum number of cloud printers to allow in the dropdown. |
| 75 const maxCloudPrinters = 10; | 78 const maxCloudPrinters = 10; |
| 76 | 79 |
| 80 const MIN_REQUEST_ID = 0; | |
| 81 const MAX_REQUEST_ID = 32000; | |
| 82 | |
| 77 /** | 83 /** |
| 78 * Window onload handler, sets up the page and starts print preview by getting | 84 * Window onload handler, sets up the page and starts print preview by getting |
| 79 * the printer list. | 85 * the printer list. |
| 80 */ | 86 */ |
| 81 function onLoad() { | 87 function onLoad() { |
| 82 cr.enablePlatformSpecificCSSRules(); | 88 cr.enablePlatformSpecificCSSRules(); |
| 89 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); | |
| 90 lastPreviewRequestID = initialPreviewRequestID; | |
| 83 | 91 |
| 84 if (!checkCompatiblePluginExists()) { | 92 if (!checkCompatiblePluginExists()) { |
| 85 disableInputElementsInSidebar(); | 93 disableInputElementsInSidebar(); |
| 86 displayErrorMessageWithButton(localStrings.getString('noPlugin'), | 94 displayErrorMessageWithButton(localStrings.getString('noPlugin'), |
| 87 localStrings.getString('launchNativeDialog'), | 95 localStrings.getString('launchNativeDialog'), |
| 88 launchNativePrintDialog); | 96 launchNativePrintDialog); |
| 89 $('mainview').parentElement.removeChild($('dummy-viewer')); | 97 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 90 return; | 98 return; |
| 91 } | 99 } |
| 92 | 100 |
| 93 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); | 101 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); |
| 94 $('mainview').parentElement.removeChild($('dummy-viewer')); | 102 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 95 | 103 |
| 96 $('printer-list').disabled = true; | 104 $('printer-list').disabled = true; |
| 97 | 105 |
| 98 printHeader = print_preview.PrintHeader.getInstance(); | 106 printHeader = print_preview.PrintHeader.getInstance(); |
| 99 pageSettings = print_preview.PageSettings.getInstance(); | 107 pageSettings = print_preview.PageSettings.getInstance(); |
| 100 copiesSettings = print_preview.CopiesSettings.getInstance(); | 108 copiesSettings = print_preview.CopiesSettings.getInstance(); |
| 101 layoutSettings = print_preview.LayoutSettings.getInstance(); | 109 layoutSettings = print_preview.LayoutSettings.getInstance(); |
| 102 colorSettings = print_preview.ColorSettings.getInstance(); | 110 colorSettings = print_preview.ColorSettings.getInstance(); |
| 103 printHeader.addEventListeners(); | 111 printHeader.addEventListeners(); |
| 104 pageSettings.addEventListeners(); | 112 pageSettings.addEventListeners(); |
| 105 copiesSettings.addEventListeners(); | 113 copiesSettings.addEventListeners(); |
| 106 layoutSettings.addEventListeners(); | 114 layoutSettings.addEventListeners(); |
| 107 colorSettings.addEventListeners(); | 115 colorSettings.addEventListeners(); |
| 116 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | |
| 108 | 117 |
| 109 showLoadingAnimation(); | 118 showLoadingAnimation(); |
| 110 chrome.send('getDefaultPrinter'); | 119 chrome.send('getDefaultPrinter'); |
| 111 } | 120 } |
| 112 | 121 |
| 113 /** | 122 /** |
| 114 * Adds event listeners to the settings controls. | |
| 115 */ | |
| 116 function addEventListeners() { | |
| 117 // Controls that require preview rendering. | |
| 118 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | |
| 119 } | |
| 120 | |
| 121 /** | |
| 122 * Removes event listeners from the settings controls. | |
| 123 */ | |
| 124 function removeEventListeners() { | |
| 125 if (pageSettings) | |
| 126 clearTimeout(pageSettings.timerId_); | |
| 127 | |
| 128 // Controls that require preview rendering | |
| 129 $('printer-list').onchange = null; | |
| 130 } | |
| 131 | |
| 132 /** | |
| 133 * Disables the input elements in the sidebar. | 123 * Disables the input elements in the sidebar. |
| 134 */ | 124 */ |
| 135 function disableInputElementsInSidebar() { | 125 function disableInputElementsInSidebar() { |
| 136 var els = $('sidebar').querySelectorAll('input, button, select'); | 126 var els = $('sidebar').querySelectorAll('input, button, select'); |
| 137 for (var i = 0; i < els.length; i++) | 127 for (var i = 0; i < els.length; i++) |
| 138 els[i].disabled = true; | 128 els[i].disabled = true; |
| 139 } | 129 } |
| 140 | 130 |
| 141 /** | 131 /** |
| 142 * Disables the controls in the sidebar, shows the throbber and instructs the | 132 * Disables the controls in the sidebar, shows the throbber and instructs the |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 * @return {boolean} true if settings are valid, false if not. | 277 * @return {boolean} true if settings are valid, false if not. |
| 288 */ | 278 */ |
| 289 function areSettingsValid() { | 279 function areSettingsValid() { |
| 290 return pageSettings.isPageSelectionValid() && | 280 return pageSettings.isPageSelectionValid() && |
| 291 (copiesSettings.isValid() || | 281 (copiesSettings.isValid() || |
| 292 getSelectedPrinterName() == PRINT_TO_PDF); | 282 getSelectedPrinterName() == PRINT_TO_PDF); |
| 293 } | 283 } |
| 294 | 284 |
| 295 /** | 285 /** |
| 296 * Creates an object based on the values in the printer settings. | 286 * Creates an object based on the values in the printer settings. |
| 287 * Note: |lastPreviewRequestID| is being modified every time this function is | |
|
kmadhusu
2011/08/10 17:12:40
How |lastPreviewRequestID| change when you call ge
dpapad
2011/08/10 17:21:40
Obviously that is an obsolete comment belonging to
| |
| 288 * called. | |
| 297 * | 289 * |
| 298 * @return {Object} Object containing print job settings. | 290 * @return {Object} Object containing print job settings. |
| 299 */ | 291 */ |
| 300 function getSettings() { | 292 function getSettings() { |
| 301 var deviceName = getSelectedPrinterName(); | 293 var deviceName = getSelectedPrinterName(); |
| 302 var printToPDF = (deviceName == PRINT_TO_PDF); | 294 var printToPDF = (deviceName == PRINT_TO_PDF); |
| 303 | 295 |
| 304 var settings = | 296 var settings = |
| 305 {'deviceName': deviceName, | 297 {'deviceName': deviceName, |
| 306 'pageRange': pageSettings.selectedPageRanges, | 298 'pageRange': pageSettings.selectedPageRanges, |
| 307 'printAll': pageSettings.allPagesRadioButton.checked, | |
| 308 'duplex': copiesSettings.duplexMode, | 299 'duplex': copiesSettings.duplexMode, |
| 309 'copies': copiesSettings.numberOfCopies, | 300 'copies': copiesSettings.numberOfCopies, |
| 310 'collate': copiesSettings.isCollated(), | 301 'collate': copiesSettings.isCollated(), |
| 311 'landscape': layoutSettings.isLandscape(), | 302 'landscape': layoutSettings.isLandscape(), |
| 312 'color': colorSettings.isColor(), | 303 'color': colorSettings.isColor(), |
| 313 'printToPDF': printToPDF, | 304 'printToPDF': printToPDF, |
| 305 'isFirstRequest' : false, | |
| 314 'requestID': 0}; | 306 'requestID': 0}; |
| 315 | 307 |
| 316 var printerList = $('printer-list'); | 308 var printerList = $('printer-list'); |
| 317 var selectedPrinter = printerList.selectedIndex; | 309 var selectedPrinter = printerList.selectedIndex; |
| 318 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { | 310 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { |
| 319 settings['cloudPrintID'] = | 311 settings['cloudPrintID'] = |
| 320 printerList.options[selectedPrinter].value; | 312 printerList.options[selectedPrinter].value; |
| 321 } | 313 } |
| 322 return settings; | 314 return settings; |
| 323 } | 315 } |
| 324 | 316 |
| 325 /** | 317 /** |
| 318 * Creates an object based on the values in the printer settings. | |
| 319 * Note: |lastPreviewRequestID| is being modified every time this function is | |
| 320 * called. Only call this function when a preview request is actually sent, | |
| 321 * otherwise (for example when debugging) call getSettings(). | |
| 322 * | |
| 323 * @return {Object} Object containing print job settings. | |
| 324 */ | |
| 325 function getSettingsWithRequestID() { | |
| 326 var settings = getSettings(); | |
| 327 settings.requestID = generatePreviewRequestID(); | |
| 328 settings.isFirstRequest = isFirstPreviewRequest(); | |
| 329 return settings; | |
| 330 } | |
| 331 | |
| 332 /** | |
| 326 * @return {number} The next unused preview request id. | 333 * @return {number} The next unused preview request id. |
| 327 */ | 334 */ |
| 328 function generatePreviewRequestID() { | 335 function generatePreviewRequestID() { |
| 329 return ++lastPreviewRequestID; | 336 return ++lastPreviewRequestID; |
| 330 } | 337 } |
| 331 | 338 |
| 332 /** | 339 /** |
| 333 * @return {boolean} True iff a preview has been requested. | 340 * @return {boolean} True iff a preview has been requested. |
| 334 */ | 341 */ |
| 335 function hasRequestedPreview() { | 342 function hasRequestedPreview() { |
| 336 return lastPreviewRequestID > -1; | 343 return lastPreviewRequestID != initialPreviewRequestID; |
| 337 } | 344 } |
| 338 | 345 |
| 339 /** | 346 /** |
| 347 * @return {boolean} True if |lastPreviewRequestID| corresponds to the initial | |
| 348 * preview request. | |
| 349 */ | |
| 350 function isFirstPreviewRequest() { | |
| 351 return lastPreviewRequestID == initialPreviewRequestID + 1; | |
| 352 } | |
| 353 | |
| 354 /** | |
| 340 * Checks if |previewResponseId| matches |lastPreviewRequestId|. Used to ignore | 355 * Checks if |previewResponseId| matches |lastPreviewRequestId|. Used to ignore |
| 341 * obsolete preview data responses. | 356 * obsolete preview data responses. |
| 342 * @param {number} previewResponseId The id to check. | 357 * @param {number} previewResponseId The id to check. |
| 343 * @return {boolean} True if previewResponseId reffers to the expected response. | 358 * @return {boolean} True if previewResponseId reffers to the expected response. |
| 344 */ | 359 */ |
| 345 function isExpectedPreviewResponse(previewResponseId) { | 360 function isExpectedPreviewResponse(previewResponseId) { |
| 346 return lastPreviewRequestID == previewResponseId; | 361 return lastPreviewRequestID == previewResponseId; |
| 347 } | 362 } |
| 348 | 363 |
| 349 /** | 364 /** |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 374 } else { | 389 } else { |
| 375 isTabHidden = true; | 390 isTabHidden = true; |
| 376 chrome.send('hidePreview'); | 391 chrome.send('hidePreview'); |
| 377 } | 392 } |
| 378 return; | 393 return; |
| 379 } | 394 } |
| 380 | 395 |
| 381 if (printToPDF) { | 396 if (printToPDF) { |
| 382 sendPrintDocumentRequest(); | 397 sendPrintDocumentRequest(); |
| 383 } else { | 398 } else { |
| 384 removeEventListeners(); | |
| 385 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); | 399 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); |
| 386 } | 400 } |
| 387 } | 401 } |
| 388 | 402 |
| 389 /** | 403 /** |
| 390 * Asks the browser to print the pending preview PDF that just finished | 404 * Asks the browser to print the pending preview PDF that just finished |
| 391 * loading. | 405 * loading. |
| 392 */ | 406 */ |
| 393 function requestToPrintPendingDocument() { | 407 function requestToPrintPendingDocument() { |
| 394 hasPendingPrintDocumentRequest = false; | 408 hasPendingPrintDocumentRequest = false; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 418 cloudprint.getData(printer)]); | 432 cloudprint.getData(printer)]); |
| 419 chrome.send('print', [JSON.stringify(getSettings()), | 433 chrome.send('print', [JSON.stringify(getSettings()), |
| 420 cloudprint.getPrintTicketJSON(printer)]); | 434 cloudprint.getPrintTicketJSON(printer)]); |
| 421 } | 435 } |
| 422 | 436 |
| 423 /** | 437 /** |
| 424 * Asks the browser to generate a preview PDF based on current print settings. | 438 * Asks the browser to generate a preview PDF based on current print settings. |
| 425 */ | 439 */ |
| 426 function requestPrintPreview() { | 440 function requestPrintPreview() { |
| 427 hasPendingPreviewRequest = true; | 441 hasPendingPreviewRequest = true; |
| 428 removeEventListeners(); | |
| 429 printSettings.save(); | 442 printSettings.save(); |
| 430 if (!isTabHidden) | 443 if (!isTabHidden) |
| 431 showLoadingAnimation(); | 444 showLoadingAnimation(); |
| 432 | 445 |
| 433 var settings = getSettings(); | 446 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID())]); |
| 434 settings.requestID = generatePreviewRequestID(); | |
| 435 chrome.send('getPreview', [JSON.stringify(settings)]); | |
| 436 } | 447 } |
| 437 | 448 |
| 438 /** | 449 /** |
| 439 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print | 450 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print |
| 440 * preview tab regarding the file selection cancel event. | 451 * preview tab regarding the file selection cancel event. |
| 441 */ | 452 */ |
| 442 function fileSelectionCancelled() { | 453 function fileSelectionCancelled() { |
| 443 // TODO(thestig) re-enable controls here. | 454 // TODO(thestig) re-enable controls here. |
| 444 } | 455 } |
| 445 | 456 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 /** | 735 /** |
| 725 * Display an error message in the center of the preview area. | 736 * Display an error message in the center of the preview area. |
| 726 * @param {string} errorMessage The error message to be displayed. | 737 * @param {string} errorMessage The error message to be displayed. |
| 727 */ | 738 */ |
| 728 function displayErrorMessage(errorMessage) { | 739 function displayErrorMessage(errorMessage) { |
| 729 $('print-button').disabled = true; | 740 $('print-button').disabled = true; |
| 730 $('overlay-layer').classList.remove('invisible'); | 741 $('overlay-layer').classList.remove('invisible'); |
| 731 $('dancing-dots-text').classList.add('hidden'); | 742 $('dancing-dots-text').classList.add('hidden'); |
| 732 $('error-text').innerHTML = errorMessage; | 743 $('error-text').innerHTML = errorMessage; |
| 733 $('error-text').classList.remove('hidden'); | 744 $('error-text').classList.remove('hidden'); |
| 734 removeEventListeners(); | |
| 735 var pdfViewer = $('pdf-viewer'); | 745 var pdfViewer = $('pdf-viewer'); |
| 736 if (pdfViewer) | 746 if (pdfViewer) |
| 737 $('mainview').removeChild(pdfViewer); | 747 $('mainview').removeChild(pdfViewer); |
| 738 | 748 |
| 739 if (isTabHidden) | 749 if (isTabHidden) |
| 740 cancelPendingPrintRequest(); | 750 cancelPendingPrintRequest(); |
| 741 } | 751 } |
| 742 | 752 |
| 743 /** | 753 /** |
| 744 * Display an error message in the center of the preview area followed by a | 754 * Display an error message in the center of the preview area followed by a |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 767 function printPreviewFailed() { | 777 function printPreviewFailed() { |
| 768 displayErrorMessage(localStrings.getString('previewFailed')); | 778 displayErrorMessage(localStrings.getString('previewFailed')); |
| 769 } | 779 } |
| 770 | 780 |
| 771 /** | 781 /** |
| 772 * Called when the PDF plugin loads its document. | 782 * Called when the PDF plugin loads its document. |
| 773 */ | 783 */ |
| 774 function onPDFLoad() { | 784 function onPDFLoad() { |
| 775 if (previewModifiable) { | 785 if (previewModifiable) { |
| 776 setPluginPreviewPageCount(); | 786 setPluginPreviewPageCount(); |
| 777 cr.dispatchSimpleEvent(document, 'updateSummary'); | |
| 778 } | 787 } |
| 779 $('pdf-viewer').fitToHeight(); | 788 $('pdf-viewer').fitToHeight(); |
| 780 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 789 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
| 781 hideLoadingAnimation(); | 790 hideLoadingAnimation(); |
| 782 } | 791 } |
| 783 | 792 |
| 784 function setPluginPreviewPageCount() { | 793 function setPluginPreviewPageCount() { |
| 785 $('pdf-viewer').printPreviewPageCount( | 794 $('pdf-viewer').printPreviewPageCount( |
| 786 pageSettings.previouslySelectedPages.length); | 795 pageSettings.previouslySelectedPages.length); |
| 787 } | 796 } |
| 788 | 797 |
| 789 /** | 798 /** |
| 790 * Update the page count and check the page range. | 799 * Update the page count and check the page range. |
| 791 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 800 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| 792 * @param {number} pageCount The number of pages. | 801 * @param {number} pageCount The number of pages. |
| 793 * @param {boolean} isModifiable Indicates whether the previewed document can be | 802 * @param {boolean} isModifiable Indicates whether the previewed document can be |
| 794 * modified. | 803 * modified. |
| 804 * @param {number} previewResponseId The preview request id that resulted in | |
| 805 * this response. | |
| 795 */ | 806 */ |
| 796 function onDidGetPreviewPageCount(pageCount, isModifiable) { | 807 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { |
| 808 if (!isExpectedPreviewResponse(previewResponseId)) | |
| 809 return; | |
| 797 pageSettings.updateState(pageCount); | 810 pageSettings.updateState(pageCount); |
| 798 previewModifiable = isModifiable; | 811 previewModifiable = isModifiable; |
| 812 cr.dispatchSimpleEvent(document, 'updateSummary'); | |
| 799 } | 813 } |
| 800 | 814 |
| 801 /** | 815 /** |
| 802 * Called when no pipelining previewed pages. | 816 * Called when no pipelining previewed pages. |
| 817 * @param {string} previewUid Preview unique identifier. | |
| 818 * @param {number} previewResponseId The preview request id that resulted in | |
| 819 * this response. | |
| 803 */ | 820 */ |
| 804 function reloadPreviewPages(previewUid, previewResponseId) { | 821 function reloadPreviewPages(previewUid, previewResponseId) { |
| 805 if (!isExpectedPreviewResponse(previewResponseId)) | 822 if (!isExpectedPreviewResponse(previewResponseId)) |
| 806 return; | 823 return; |
| 807 hasPendingPreviewRequest = false; | 824 hasPendingPreviewRequest = false; |
| 808 | 825 |
| 809 if (checkIfSettingsChangedAndRegeneratePreview()) | 826 if (checkIfSettingsChangedAndRegeneratePreview()) |
| 810 return; | 827 return; |
| 811 cr.dispatchSimpleEvent(document, 'updateSummary'); | |
| 812 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 828 cr.dispatchSimpleEvent(document, 'updatePrintButton'); |
| 813 addEventListeners(); | |
| 814 hideLoadingAnimation(); | 829 hideLoadingAnimation(); |
| 815 var pageSet = pageSettings.previouslySelectedPages; | 830 var pageSet = pageSettings.previouslySelectedPages; |
| 816 for (var i = 0; i < pageSet.length; i++) | 831 for (var i = 0; i < pageSet.length; i++) |
| 817 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); | 832 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); |
| 818 // TODO(dpapad): handle pending print file requests. | 833 // TODO(dpapad): handle pending print file requests. |
| 819 } | 834 } |
| 820 | 835 |
| 821 /** | 836 /** |
| 822 * Notification that a print preview page has been rendered. | 837 * Notification that a print preview page has been rendered. |
| 823 * Check if the settings have changed and request a regeneration if needed. | 838 * Check if the settings have changed and request a regeneration if needed. |
| 824 * Called from PrintPreviewUI::OnDidPreviewPage(). | 839 * Called from PrintPreviewUI::OnDidPreviewPage(). |
| 825 * @param {number} pageNumber The page number, 0-based. | 840 * @param {number} pageNumber The page number, 0-based. |
| 841 * @param {string} previewUid Preview unique identifier. | |
| 842 * @param {number} previewResponseId The preview request id that resulted in | |
| 843 * this response. | |
| 826 */ | 844 */ |
| 827 function onDidPreviewPage(pageNumber, previewUid) { | 845 function onDidPreviewPage(pageNumber, previewUid, previewResponseId) { |
| 846 if (!isExpectedPreviewResponse(previewResponseId)) | |
| 847 return; | |
| 848 | |
| 828 // Refactor | 849 // Refactor |
| 829 if (!previewModifiable) | 850 if (!previewModifiable) |
| 830 return; | 851 return; |
| 831 | 852 |
| 832 var pageIndex = pageSettings.previouslySelectedPages.indexOf(pageNumber + 1); | 853 var pageIndex = pageSettings.previouslySelectedPages.indexOf(pageNumber + 1); |
| 833 | 854 |
| 834 if (checkIfSettingsChangedAndRegeneratePreview()) | 855 if (checkIfSettingsChangedAndRegeneratePreview()) |
| 835 return; | 856 return; |
| 836 if (pageIndex == 0) | 857 if (pageIndex == 0) |
| 837 createPDFPlugin(previewUid); | 858 createPDFPlugin(previewUid); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 860 if (checkIfSettingsChangedAndRegeneratePreview()) | 881 if (checkIfSettingsChangedAndRegeneratePreview()) |
| 861 return; | 882 return; |
| 862 | 883 |
| 863 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 884 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
| 864 | 885 |
| 865 if (!previewModifiable) { | 886 if (!previewModifiable) { |
| 866 // If the preview is not modifiable the plugin has not been created yet. | 887 // If the preview is not modifiable the plugin has not been created yet. |
| 867 createPDFPlugin(previewUid); | 888 createPDFPlugin(previewUid); |
| 868 } | 889 } |
| 869 | 890 |
| 870 cr.dispatchSimpleEvent(document, 'updateSummary'); | |
| 871 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 891 cr.dispatchSimpleEvent(document, 'updatePrintButton'); |
| 872 addEventListeners(); | |
| 873 | 892 |
| 874 if (hasPendingPrintDocumentRequest) | 893 if (hasPendingPrintDocumentRequest) |
| 875 requestToPrintPendingDocument(); | 894 requestToPrintPendingDocument(); |
| 876 } | 895 } |
| 877 | 896 |
| 878 /** | 897 /** |
| 879 * Check if any print settings changed and regenerate the preview if needed. | 898 * Check if any print settings changed and regenerate the preview if needed. |
| 880 * @return {boolean} true if a new preview is required. | 899 * @return {boolean} true if a new preview is required. |
| 881 */ | 900 */ |
| 882 function checkIfSettingsChangedAndRegeneratePreview() { | 901 function checkIfSettingsChangedAndRegeneratePreview() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 | 987 |
| 969 /// Pull in all other scripts in a single shot. | 988 /// Pull in all other scripts in a single shot. |
| 970 <include src="print_preview_animations.js"/> | 989 <include src="print_preview_animations.js"/> |
| 971 <include src="print_preview_cloud.js"/> | 990 <include src="print_preview_cloud.js"/> |
| 972 <include src="print_preview_utils.js"/> | 991 <include src="print_preview_utils.js"/> |
| 973 <include src="print_header.js"/> | 992 <include src="print_header.js"/> |
| 974 <include src="page_settings.js"/> | 993 <include src="page_settings.js"/> |
| 975 <include src="copies_settings.js"/> | 994 <include src="copies_settings.js"/> |
| 976 <include src="layout_settings.js"/> | 995 <include src="layout_settings.js"/> |
| 977 <include src="color_settings.js"/> | 996 <include src="color_settings.js"/> |
| OLD | NEW |