| 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 var localStrings = new LocalStrings(); | 5 var localStrings = new LocalStrings(); |
| 6 | 6 |
| 7 // The total page count of the previewed document regardless of which pages the | 7 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 8 // user has selected. |
| 9 var totalPageCount = -1; | 9 var totalPageCount = -1; |
| 10 | 10 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 updateCopiesButtonsState(); | 463 updateCopiesButtonsState(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 /** | 466 /** |
| 467 * Update the print preview when new preview data is available. | 467 * Update the print preview when new preview data is available. |
| 468 * Create the PDF plugin as needed. | 468 * Create the PDF plugin as needed. |
| 469 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 469 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
| 470 * @param {number} pageCount The expected total pages count. | 470 * @param {number} pageCount The expected total pages count. |
| 471 * @param {string} jobTitle The print job title. | 471 * @param {string} jobTitle The print job title. |
| 472 * @param {boolean} modifiable If the preview is modifiable. | 472 * @param {boolean} modifiable If the preview is modifiable. |
| 473 * | 473 * @param {string} previewUid Preview unique identifier. |
| 474 */ | 474 */ |
| 475 function updatePrintPreview(pageCount, jobTitle, modifiable) { | 475 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { |
| 476 var tempPrintSettings = new PrintSettings(); | 476 var tempPrintSettings = new PrintSettings(); |
| 477 tempPrintSettings.save(); | 477 tempPrintSettings.save(); |
| 478 | 478 |
| 479 previewModifiable = modifiable; | 479 previewModifiable = modifiable; |
| 480 | 480 |
| 481 if (totalPageCount == -1) | 481 if (totalPageCount == -1) |
| 482 totalPageCount = pageCount; | 482 totalPageCount = pageCount; |
| 483 | 483 |
| 484 if (previouslySelectedPages.length == 0) | 484 if (previouslySelectedPages.length == 0) |
| 485 for (var i = 0; i < totalPageCount; i++) | 485 for (var i = 0; i < totalPageCount; i++) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 499 return; | 499 return; |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 if (getSelectedPagesValidityLevel() != 1) | 503 if (getSelectedPagesValidityLevel() != 1) |
| 504 pageRangesFieldChanged(); | 504 pageRangesFieldChanged(); |
| 505 | 505 |
| 506 // Update the current tab title. | 506 // Update the current tab title. |
| 507 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 507 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
| 508 | 508 |
| 509 createPDFPlugin(); | 509 createPDFPlugin(previewUid); |
| 510 updatePrintSummary(); | 510 updatePrintSummary(); |
| 511 updatePrintButtonState(); | 511 updatePrintButtonState(); |
| 512 addEventListeners(); | 512 addEventListeners(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 /** | 515 /** |
| 516 * Create the PDF plugin or reload the existing one. | 516 * Create the PDF plugin or reload the existing one. |
| 517 * @param {string} previewUid Preview unique identifier. |
| 517 */ | 518 */ |
| 518 function createPDFPlugin() { | 519 function createPDFPlugin(previewUid) { |
| 519 // Enable the print button. | 520 // Enable the print button. |
| 520 if (!$('printer-list').disabled) { | 521 if (!$('printer-list').disabled) { |
| 521 $('print-button').disabled = false; | 522 $('print-button').disabled = false; |
| 522 } | 523 } |
| 523 | 524 |
| 524 var pdfViewer = $('pdf-viewer'); | 525 var pdfViewer = $('pdf-viewer'); |
| 525 if (pdfViewer) { | 526 if (pdfViewer) { |
| 526 // Older version of the PDF plugin may not have this method. | 527 // Older version of the PDF plugin may not have this method. |
| 527 // TODO(thestig) Eventually remove this check. | 528 // TODO(thestig) Eventually remove this check. |
| 528 if (pdfViewer.goToPage) { | 529 if (pdfViewer.goToPage) { |
| 529 // Need to call this before the reload(), where the plugin resets its | 530 // Need to call this before the reload(), where the plugin resets its |
| 530 // internal page count. | 531 // internal page count. |
| 531 pdfViewer.goToPage('0'); | 532 pdfViewer.goToPage('0'); |
| 532 } | 533 } |
| 533 pdfViewer.reload(); | 534 pdfViewer.reload(); |
| 534 pdfViewer.grayscale(!isColor()); | 535 pdfViewer.grayscale(!isColor()); |
| 535 return; | 536 return; |
| 536 } | 537 } |
| 537 | 538 |
| 538 var pdfPlugin = document.createElement('embed'); | 539 var pdfPlugin = document.createElement('embed'); |
| 539 pdfPlugin.setAttribute('id', 'pdf-viewer'); | 540 pdfPlugin.setAttribute('id', 'pdf-viewer'); |
| 540 pdfPlugin.setAttribute('type', 'application/pdf'); | 541 pdfPlugin.setAttribute('type', 'application/pdf'); |
| 541 pdfPlugin.setAttribute('src', 'chrome://print/print.pdf'); | 542 pdfPlugin.setAttribute('src', 'chrome://print/' + previewUid + '/print.pdf'); |
| 542 var mainView = $('mainview'); | 543 var mainView = $('mainview'); |
| 543 mainView.appendChild(pdfPlugin); | 544 mainView.appendChild(pdfPlugin); |
| 544 pdfPlugin.onload('onPDFLoad()'); | 545 pdfPlugin.onload('onPDFLoad()'); |
| 545 | 546 |
| 546 // Older version of the PDF plugin may not have this method. | 547 // Older version of the PDF plugin may not have this method. |
| 547 // TODO(thestig) Eventually remove this check. | 548 // TODO(thestig) Eventually remove this check. |
| 548 if (pdfPlugin.removePrintButton) { | 549 if (pdfPlugin.removePrintButton) { |
| 549 pdfPlugin.removePrintButton(); | 550 pdfPlugin.removePrintButton(); |
| 550 } | 551 } |
| 551 | 552 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 this.isLandscape = ''; | 940 this.isLandscape = ''; |
| 940 } | 941 } |
| 941 | 942 |
| 942 /** | 943 /** |
| 943 * Takes a snapshot of the print settings. | 944 * Takes a snapshot of the print settings. |
| 944 */ | 945 */ |
| 945 PrintSettings.prototype.save = function() { | 946 PrintSettings.prototype.save = function() { |
| 946 this.deviceName = getSelectedPrinterName(); | 947 this.deviceName = getSelectedPrinterName(); |
| 947 this.isLandscape = isLandscape(); | 948 this.isLandscape = isLandscape(); |
| 948 } | 949 } |
| OLD | NEW |