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 cr.define('cloudprint', function() { | 5 cr.define('cloudprint', function() { |
6 | 6 |
7 // The URL to use to access the cloud print servers. | 7 // The URL to use to access the cloud print servers. |
8 // Set by a call to setBaseURL. | 8 // Set by a call to setBaseURL. |
9 var cloudPrintBaseURL = ''; | 9 var cloudPrintBaseURL = ''; |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 callback.call(this, xhr); | 82 callback.call(this, xhr); |
83 } | 83 } |
84 }; | 84 }; |
85 } | 85 } |
86 var url = cloudPrintBaseURL + '/' + action; | 86 var url = cloudPrintBaseURL + '/' + action; |
87 if (params == null) { | 87 if (params == null) { |
88 params = new Array; | 88 params = new Array; |
89 } | 89 } |
90 if (lastXSRFToken.length != 0) { | 90 if (lastXSRFToken.length != 0) { |
91 params.push("xsrf=" + lastXSRFToken); | 91 params.push('xsrf=' + lastXSRFToken); |
92 } | 92 } |
93 if (params.length != 0) { | 93 if (params.length != 0) { |
94 url = url + "?"; | 94 url = url + '?'; |
95 for (param in params) { | 95 for (param in params) { |
96 url = url + params[param] + "&"; | 96 url = url + params[param] + '&'; |
97 } | 97 } |
98 } | 98 } |
99 xhr.open(method, url, true); | 99 xhr.open(method, url, true); |
100 xhr.withCredentials = true; | 100 xhr.withCredentials = true; |
101 if (headers) { | 101 if (headers) { |
102 for (var header in headers) { | 102 for (var header in headers) { |
103 if (headers.hasOwnProperty(header)) { | 103 if (headers.hasOwnProperty(header)) { |
104 xhr.setRequestHeader(header, headers[header]); | 104 xhr.setRequestHeader(header, headers[header]); |
105 } | 105 } |
106 } | 106 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 printer.cloudPrintOptions.colorIsDefault = false; | 208 printer.cloudPrintOptions.colorIsDefault = false; |
209 var detailedCapabilities = printResult.printers[0].capabilities; | 209 var detailedCapabilities = printResult.printers[0].capabilities; |
210 for (var capability in detailedCapabilities) { | 210 for (var capability in detailedCapabilities) { |
211 var cap = detailedCapabilities[capability]; | 211 var cap = detailedCapabilities[capability]; |
212 if (cap.name == 'ns1:Colors') { | 212 if (cap.name == 'ns1:Colors') { |
213 printer.cloudPrintOptions.colorOption = new Object; | 213 printer.cloudPrintOptions.colorOption = new Object; |
214 printer.cloudPrintOptions.colorOption.name = cap.name; | 214 printer.cloudPrintOptions.colorOption.name = cap.name; |
215 printer.cloudPrintOptions.colorOption.type = cap.type; | 215 printer.cloudPrintOptions.colorOption.type = cap.type; |
216 for (var option in cap.options) { | 216 for (var option in cap.options) { |
217 var opt = cap.options[option]; | 217 var opt = cap.options[option]; |
218 if (opt.name == "Color") { | 218 if (opt.name == 'Color') { |
219 printer.cloudPrintOptions.colorOnOption = opt; | 219 printer.cloudPrintOptions.colorOnOption = opt; |
220 } | 220 } |
221 if (opt.name == "Grey_K") { | 221 if (opt.name == 'Grey_K') { |
222 printer.cloudPrintOptions.colorOffOption = opt; | 222 printer.cloudPrintOptions.colorOffOption = opt; |
223 } | 223 } |
224 if (opt.default) { | 224 if (opt.default) { |
225 printer.cloudPrintOptions.colorOption.options = [opt]; | 225 printer.cloudPrintOptions.colorOption.options = [opt]; |
226 printer.cloudPrintOptions.colorIsDefault = | 226 printer.cloudPrintOptions.colorIsDefault = |
227 opt.name == printer.cloudPrintOptions.colorOnOption.name; | 227 opt.name == printer.cloudPrintOptions.colorOnOption.name; |
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 } | 231 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 * Returns the data necessary to serialize a cloud print printer. | 316 * Returns the data necessary to serialize a cloud print printer. |
317 * @param {Object} printer The printer object to get data for. | 317 * @param {Object} printer The printer object to get data for. |
318 * @return {string} A JSON string that can be used to recreate the | 318 * @return {string} A JSON string that can be used to recreate the |
319 * cloud print portion of the printer object, or and empty string if | 319 * cloud print portion of the printer object, or and empty string if |
320 * there is no data to save. | 320 * there is no data to save. |
321 */ | 321 */ |
322 function getData(printer) { | 322 function getData(printer) { |
323 if (isCloudPrint(printer)) { | 323 if (isCloudPrint(printer)) { |
324 return JSON.stringify(printer.cloudPrintOptions); | 324 return JSON.stringify(printer.cloudPrintOptions); |
325 } else { | 325 } else { |
326 return ""; | 326 return ''; |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 /** | 330 /** |
331 * Test if a printer is a cloud print printer. | 331 * Test if a printer is a cloud print printer. |
332 * @param {Object} printer The printer to test. | 332 * @param {Object} printer The printer to test. |
333 * @return {boolean} true iff the printer is a cloud print printer. | 333 * @return {boolean} true iff the printer is a cloud print printer. |
334 */ | 334 */ |
335 function isCloudPrint(printer) { | 335 function isCloudPrint(printer) { |
336 return printer && printer.cloudPrintOptions != null; | 336 return printer && printer.cloudPrintOptions != null; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 isCloudPrint: isCloudPrint, | 441 isCloudPrint: isCloudPrint, |
442 printToCloud: printToCloud, | 442 printToCloud: printToCloud, |
443 setBaseURL: setBaseURL, | 443 setBaseURL: setBaseURL, |
444 setCloudPrint: setCloudPrint, | 444 setCloudPrint: setCloudPrint, |
445 setColor: setColor, | 445 setColor: setColor, |
446 setDefaultPrinter: setDefaultPrinter, | 446 setDefaultPrinter: setDefaultPrinter, |
447 supportsColor: supportsColor, | 447 supportsColor: supportsColor, |
448 updatePrinterCaps: updatePrinterCaps | 448 updatePrinterCaps: updatePrinterCaps |
449 }; | 449 }; |
450 }); | 450 }); |
OLD | NEW |