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

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

Issue 6533006: Print Preview: Hook up the print button to initiate printing without displaying a print dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 var hasPDFPlugin = true; 6 var hasPDFPlugin = true;
7 7
8 /** 8 /**
9 * Window onload handler, sets up the page. 9 * Window onload handler, sets up the page.
10 */ 10 */
11 function load() { 11 function load() {
12 $('print-button').addEventListener('click', printFile);
13
12 $('cancel-button').addEventListener('click', function(e) { 14 $('cancel-button').addEventListener('click', function(e) {
13 window.close(); 15 window.close();
14 }); 16 });
15 17
16 chrome.send('getPrinters'); 18 chrome.send('getPrinters');
17 }; 19 };
18 20
19 /** 21 /**
22 * Parse page range text.
23 * Eg: If page range is specified as "1-3,7-9,8". Create an array with three
24 * elements. Each array element contains the range information.
25 * [{from:1, to:3}, {from:7, to:9}, {from:8, to:8}]
26 * TODO (kmadhusu): Check for invalid characters.
27 */
28 function pageRange() {
29 var pageRangeParams;
30 var pageRangesInfo = new Array();
31 var pageRangeText = $('pages').value;
32 var pageRangeList = pageRangeText.split(",");
arv (Not doing code reviews) 2011/02/16 23:54:41 Use single quotes
kmadhusu 2011/02/17 19:20:31 Done.
33 for (var i = 0; i < pageRangeList.length; i++) {
34 var temp_range = pageRangeList[i].split("-");
James Hawkins 2011/02/16 22:58:21 What if the page range text is malformed?
arv (Not doing code reviews) 2011/02/16 23:54:41 no underscores in js
kmadhusu 2011/02/17 19:20:31 Done.
kmadhusu 2011/02/17 19:20:31 Added isValidPageRange() function to validate the
35 if (temp_range.length > 1) {
36 pageRangeParams = JSON.stringify({"from" : parseInt(temp_range[0]),
arv (Not doing code reviews) 2011/02/16 23:54:41 parseInt(n, 10) please
kmadhusu 2011/02/17 19:20:31 Done.
37 "to" : parseInt(temp_range[1])});
38 } else {
39 pageRangeParams = JSON.stringify({"from" : parseInt(temp_range[0]),
arv (Not doing code reviews) 2011/02/16 23:54:41 It seems like you can do the from to assignment ou
kmadhusu 2011/02/17 19:20:31 Done.
40 "to" : parseInt(temp_range[0])});
41 }
42 pageRangesInfo.push(pageRangeParams);
arv (Not doing code reviews) 2011/02/16 23:54:41 Why are we using strings in here?
kmadhusu 2011/02/17 19:20:31 Rather than creating json strings, I modified the
43 }
44 return pageRangesInfo;
45 }
46
47 function printFile() {
48 var selected_printer = $('printer-list').selectedIndex;
49 var printer_name = $('printer-list').options[selected_printer].textContent;
50 var page_range = pageRange();
51 var print_all = $('all-pages').checked;
52 var two_sided = $('two-sided').checked;
53 var copies = $('copies').value;
54 var collate = $('collate').checked;
55 var layout = $('layout').options[$('layout').selectedIndex].value;
56 var color = $('color').options[$('color').selectedIndex].value;
57
58 var job_settings = JSON.stringify({"printerName" : printer_name,
arv (Not doing code reviews) 2011/02/16 23:54:41 no ws before :
kmadhusu 2011/02/17 19:20:31 Done.
59 "pageRange" : page_range,
arv (Not doing code reviews) 2011/02/16 23:54:41 Won't this lead to double json encoding?
kmadhusu 2011/02/17 19:20:31 Fixed. |pageRange| is now an array of objects. JSO
60 "printAll" : print_all,
61 "twoSided" : two_sided,
62 "copies" : copies,
63 "collate" : collate,
64 "layout" : layout,
65 "color" : color});
66 chrome.send('print', [job_settings]);
67 }
68
69 /**
20 * Fill the printer list drop down. 70 * Fill the printer list drop down.
21 */ 71 */
22 function setPrinters(printers) { 72 function setPrinters(printers) {
23 if (printers.length > 0) { 73 if (printers.length > 0) {
24 for (var i = 0; i < printers.length; ++i) { 74 for (var i = 0; i < printers.length; ++i) {
25 var option = document.createElement('option'); 75 var option = document.createElement('option');
26 option.textContent = printers[i]; 76 option.textContent = printers[i];
27 $('printer-list').add(option); 77 $('printer-list').add(option);
28 } 78 }
29 } else { 79 } else {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 if (!pdfPlugin.onload) { 114 if (!pdfPlugin.onload) {
65 hasPDFPlugin = false; 115 hasPDFPlugin = false;
66 mainView.removeChild(pdfPlugin); 116 mainView.removeChild(pdfPlugin);
67 $('no-plugin').classList.remove('hidden'); 117 $('no-plugin').classList.remove('hidden');
68 return; 118 return;
69 } 119 }
70 pdfPlugin.onload('onPDFLoad()'); 120 pdfPlugin.onload('onPDFLoad()');
71 } 121 }
72 122
73 window.addEventListener('DOMContentLoaded', load); 123 window.addEventListener('DOMContentLoaded', load);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698