Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 7313035: Print Preview: Associating preview requests and responses using an identifier (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 26
27 // State of the print preview settings. 27 // State of the print preview settings.
28 var printSettings = new PrintSettings(); 28 var printSettings = new PrintSettings();
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.
37 var lastPreviewRequestID = -1;
38
36 // True when a pending print file request exists. 39 // True when a pending print file request exists.
37 var hasPendingPrintFileRequest = false; 40 var hasPendingPrintFileRequest = false;
38 41
39 // True when preview tab is hidden. 42 // True when preview tab is hidden.
40 var isTabHidden = false; 43 var isTabHidden = false;
41 44
42 // Object holding all the pages related settings. 45 // Object holding all the pages related settings.
43 var pageSettings; 46 var pageSettings;
44 47
45 // Object holding all the copies related settings. 48 // Object holding all the copies related settings.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 * @return {number} duplex mode. 337 * @return {number} duplex mode.
335 */ 338 */
336 function getDuplexMode() { 339 function getDuplexMode() {
337 // Constants values matches printing::DuplexMode enum. 340 // Constants values matches printing::DuplexMode enum.
338 const SIMPLEX = 0; 341 const SIMPLEX = 0;
339 const LONG_EDGE = 1; 342 const LONG_EDGE = 1;
340 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE; 343 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE;
341 } 344 }
342 345
343 /** 346 /**
344 * Creates a JSON string based on the values in the printer settings. 347 * Creates an object based on the values in the printer settings.
345 * 348 *
346 * @return {string} JSON string with print job settings. 349 * @return {Object} Object containing print job settings.
347 */ 350 */
348 function getSettingsJSON() { 351 function getSettings() {
349 var deviceName = getSelectedPrinterName(); 352 var deviceName = getSelectedPrinterName();
350 var printToPDF = (deviceName == PRINT_TO_PDF); 353 var printToPDF = (deviceName == PRINT_TO_PDF);
351 354
352 var settings = {'deviceName': deviceName, 355 var settings =
353 'pageRange': pageSettings.selectedPageRanges, 356 {'deviceName': deviceName,
354 'printAll': pageSettings.allPagesRadioButton.checked, 357 'pageRange': pageSettings.selectedPageRanges,
355 'duplex': getDuplexMode(), 358 'printAll': pageSettings.allPagesRadioButton.checked,
356 'copies': copiesSettings.numberOfCopies, 359 'duplex': getDuplexMode(),
357 'collate': isCollated(), 360 'copies': copiesSettings.numberOfCopies,
358 'landscape': isLandscape(), 361 'collate': isCollated(),
359 'color': isColor(), 362 'landscape': isLandscape(),
360 'printToPDF': printToPDF}; 363 'color': isColor(),
364 'printToPDF': printToPDF,
365 'requestID': 0};
366
361 var printerList = $('printer-list'); 367 var printerList = $('printer-list');
362 var selectedPrinter = printerList.selectedIndex; 368 var selectedPrinter = printerList.selectedIndex;
363 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { 369 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) {
364 settings['cloudPrintID'] = 370 settings['cloudPrintID'] =
365 printerList.options[selectedPrinter].value; 371 printerList.options[selectedPrinter].value;
366 } 372 }
367 373 return settings;
368 return JSON.stringify(settings);
369 } 374 }
370 375
371 /** 376 /**
377 * @return {number} The next unused preview request id.
378 */
379 function generatePreviewRequestID() {
380 return ++lastPreviewRequestID;
381 }
382
383 /**
372 * Returns the name of the selected printer or the empty string if no 384 * Returns the name of the selected printer or the empty string if no
373 * printer is selected. 385 * printer is selected.
374 * @return {string} The name of the currently selected printer. 386 * @return {string} The name of the currently selected printer.
375 */ 387 */
376 function getSelectedPrinterName() { 388 function getSelectedPrinterName() {
377 var printerList = $('printer-list') 389 var printerList = $('printer-list')
378 var selectedPrinter = printerList.selectedIndex; 390 var selectedPrinter = printerList.selectedIndex;
379 if (selectedPrinter < 0) 391 if (selectedPrinter < 0)
380 return ''; 392 return '';
381 return printerList.options[selectedPrinter].value; 393 return printerList.options[selectedPrinter].value;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 446 }
435 447
436 /** 448 /**
437 * Sends a message to initiate print workflow. 449 * Sends a message to initiate print workflow.
438 */ 450 */
439 function sendPrintFileRequest() { 451 function sendPrintFileRequest() {
440 var printerList = $('printer-list'); 452 var printerList = $('printer-list');
441 var printer = printerList[printerList.selectedIndex]; 453 var printer = printerList[printerList.selectedIndex];
442 chrome.send('saveLastPrinter', [printer.textContent, 454 chrome.send('saveLastPrinter', [printer.textContent,
443 cloudprint.getData(printer)]); 455 cloudprint.getData(printer)]);
444 chrome.send('print', [getSettingsJSON(), 456 chrome.send('print', [JSON.stringify(getSettings()),
445 cloudprint.getPrintTicketJSON(printer)]); 457 cloudprint.getPrintTicketJSON(printer)]);
446 } 458 }
447 459
448 /** 460 /**
449 * Asks the browser to generate a preview PDF based on current print settings. 461 * Asks the browser to generate a preview PDF based on current print settings.
450 */ 462 */
451 function requestPrintPreview() { 463 function requestPrintPreview() {
452 hasPendingPreviewRequest = true; 464 hasPendingPreviewRequest = true;
453 removeEventListeners(); 465 removeEventListeners();
454 printSettings.save(); 466 printSettings.save();
455 if (!isTabHidden) 467 if (!isTabHidden)
456 showLoadingAnimation(); 468 showLoadingAnimation();
457 469
458 chrome.send('getPreview', [getSettingsJSON()]); 470 var settings = getSettings();
471 settings.requestID = generatePreviewRequestID();
472 chrome.send('getPreview', [JSON.stringify(settings)]);
459 } 473 }
460 474
461 /** 475 /**
462 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print 476 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
463 * preview tab regarding the file selection cancel event. 477 * preview tab regarding the file selection cancel event.
464 */ 478 */
465 function fileSelectionCancelled() { 479 function fileSelectionCancelled() {
466 // TODO(thestig) re-enable controls here. 480 // TODO(thestig) re-enable controls here.
467 } 481 }
468 482
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 // TODO(thestig) Make use of |pageNumber| for pipelined preview generation. 807 // TODO(thestig) Make use of |pageNumber| for pipelined preview generation.
794 } 808 }
795 809
796 /** 810 /**
797 * Update the print preview when new preview data is available. 811 * Update the print preview when new preview data is available.
798 * Create the PDF plugin as needed. 812 * Create the PDF plugin as needed.
799 * Called from PrintPreviewUI::PreviewDataIsAvailable(). 813 * Called from PrintPreviewUI::PreviewDataIsAvailable().
800 * @param {string} jobTitle The print job title. 814 * @param {string} jobTitle The print job title.
801 * @param {boolean} modifiable If the preview is modifiable. 815 * @param {boolean} modifiable If the preview is modifiable.
802 * @param {string} previewUid Preview unique identifier. 816 * @param {string} previewUid Preview unique identifier.
817 * @param {number} previewRequestId The preview request id that resulted in this
818 * response.
803 */ 819 */
804 function updatePrintPreview(jobTitle, modifiable, previewUid) { 820 function updatePrintPreview(jobTitle,
821 modifiable,
822 previewUid,
823 previewRequestId) {
824 if (lastPreviewRequestID != previewRequestId)
825 return;
805 hasPendingPreviewRequest = false; 826 hasPendingPreviewRequest = false;
806 827
807 if (checkIfSettingsChangedAndRegeneratePreview()) 828 if (checkIfSettingsChangedAndRegeneratePreview())
808 return; 829 return;
809 830
810 previewModifiable = modifiable; 831 previewModifiable = modifiable;
811 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); 832 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle);
812 833
813 createPDFPlugin(previewUid); 834 createPDFPlugin(previewUid);
814 updatePrintSummary(); 835 updatePrintSummary();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 } 1004 }
984 1005
985 /** 1006 /**
986 * Takes a snapshot of the print settings. 1007 * Takes a snapshot of the print settings.
987 */ 1008 */
988 PrintSettings.prototype.save = function() { 1009 PrintSettings.prototype.save = function() {
989 this.deviceName = getSelectedPrinterName(); 1010 this.deviceName = getSelectedPrinterName();
990 this.isLandscape = isLandscape(); 1011 this.isLandscape = isLandscape();
991 } 1012 }
992 1013
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.cc ('k') | chrome/browser/ui/webui/print_preview_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698