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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 updateCopiesButtonsState(); | 497 updateCopiesButtonsState(); |
498 } | 498 } |
499 | 499 |
500 /** | 500 /** |
501 * Update the print preview when new preview data is available. | 501 * Update the print preview when new preview data is available. |
502 * Create the PDF plugin as needed. | 502 * Create the PDF plugin as needed. |
503 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 503 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
504 * @param {number} pageCount The expected total pages count. | 504 * @param {number} pageCount The expected total pages count. |
505 * @param {string} jobTitle The print job title. | 505 * @param {string} jobTitle The print job title. |
506 * @param {boolean} modifiable If the preview is modifiable. | 506 * @param {boolean} modifiable If the preview is modifiable. |
507 * | 507 * @param {string} previewUid Preview unique identifier. |
508 */ | 508 */ |
509 function updatePrintPreview(pageCount, jobTitle, modifiable) { | 509 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { |
510 var tempPrintSettings = new PrintSettings(); | 510 var tempPrintSettings = new PrintSettings(); |
511 tempPrintSettings.save(); | 511 tempPrintSettings.save(); |
512 | 512 |
513 previewModifiable = modifiable; | 513 previewModifiable = modifiable; |
514 | 514 |
515 if (totalPageCount == -1) | 515 if (totalPageCount == -1) |
516 totalPageCount = pageCount; | 516 totalPageCount = pageCount; |
517 | 517 |
518 if (previouslySelectedPages.length == 0) | 518 if (previouslySelectedPages.length == 0) |
519 for (var i = 0; i < totalPageCount; i++) | 519 for (var i = 0; i < totalPageCount; i++) |
(...skipping 13 matching lines...) Expand all Loading... |
533 return; | 533 return; |
534 } | 534 } |
535 } | 535 } |
536 | 536 |
537 if (getSelectedPagesValidityLevel() != 1) | 537 if (getSelectedPagesValidityLevel() != 1) |
538 pageRangesFieldChanged(); | 538 pageRangesFieldChanged(); |
539 | 539 |
540 // Update the current tab title. | 540 // Update the current tab title. |
541 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 541 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
542 | 542 |
543 createPDFPlugin(); | 543 createPDFPlugin(previewUid); |
544 updatePrintSummary(); | 544 updatePrintSummary(); |
545 updatePrintButtonState(); | 545 updatePrintButtonState(); |
546 addEventListeners(); | 546 addEventListeners(); |
547 } | 547 } |
548 | 548 |
549 /** | 549 /** |
550 * Create the PDF plugin or reload the existing one. | 550 * Create the PDF plugin or reload the existing one. |
| 551 * @param {string} previewUid Preview unique identifier. |
551 */ | 552 */ |
552 function createPDFPlugin() { | 553 function createPDFPlugin(previewUid) { |
553 // Enable the print button. | 554 // Enable the print button. |
554 if (!$('printer-list').disabled) { | 555 if (!$('printer-list').disabled) { |
555 $('print-button').disabled = false; | 556 $('print-button').disabled = false; |
556 } | 557 } |
557 | 558 |
558 var pdfViewer = $('pdf-viewer'); | 559 var pdfViewer = $('pdf-viewer'); |
559 if (pdfViewer) { | 560 if (pdfViewer) { |
560 // Older version of the PDF plugin may not have this method. | 561 // Older version of the PDF plugin may not have this method. |
561 // TODO(thestig) Eventually remove this check. | 562 // TODO(thestig) Eventually remove this check. |
562 if (pdfViewer.goToPage) { | 563 if (pdfViewer.goToPage) { |
563 // Need to call this before the reload(), where the plugin resets its | 564 // Need to call this before the reload(), where the plugin resets its |
564 // internal page count. | 565 // internal page count. |
565 pdfViewer.goToPage('0'); | 566 pdfViewer.goToPage('0'); |
566 } | 567 } |
567 pdfViewer.reload(); | 568 pdfViewer.reload(); |
568 pdfViewer.grayscale(!isColor()); | 569 pdfViewer.grayscale(!isColor()); |
569 return; | 570 return; |
570 } | 571 } |
571 | 572 |
572 var pdfPlugin = document.createElement('embed'); | 573 var pdfPlugin = document.createElement('embed'); |
573 pdfPlugin.setAttribute('id', 'pdf-viewer'); | 574 pdfPlugin.setAttribute('id', 'pdf-viewer'); |
574 pdfPlugin.setAttribute('type', 'application/pdf'); | 575 pdfPlugin.setAttribute('type', 'application/pdf'); |
575 pdfPlugin.setAttribute('src', 'chrome://print/print.pdf'); | 576 pdfPlugin.setAttribute('src', 'chrome://print/' + previewUid + '/print.pdf'); |
576 var mainView = $('mainview'); | 577 var mainView = $('mainview'); |
577 mainView.appendChild(pdfPlugin); | 578 mainView.appendChild(pdfPlugin); |
578 pdfPlugin.onload('onPDFLoad()'); | 579 pdfPlugin.onload('onPDFLoad()'); |
579 | 580 |
580 // Older version of the PDF plugin may not have this method. | 581 // Older version of the PDF plugin may not have this method. |
581 // TODO(thestig) Eventually remove this check. | 582 // TODO(thestig) Eventually remove this check. |
582 if (pdfPlugin.removePrintButton) { | 583 if (pdfPlugin.removePrintButton) { |
583 pdfPlugin.removePrintButton(); | 584 pdfPlugin.removePrintButton(); |
584 } | 585 } |
585 | 586 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 this.isLandscape = ''; | 979 this.isLandscape = ''; |
979 } | 980 } |
980 | 981 |
981 /** | 982 /** |
982 * Takes a snapshot of the print settings. | 983 * Takes a snapshot of the print settings. |
983 */ | 984 */ |
984 PrintSettings.prototype.save = function() { | 985 PrintSettings.prototype.save = function() { |
985 this.deviceName = getSelectedPrinterName(); | 986 this.deviceName = getSelectedPrinterName(); |
986 this.isLandscape = isLandscape(); | 987 this.isLandscape = isLandscape(); |
987 } | 988 } |
OLD | NEW |