Chromium Code Reviews| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 /** | 112 /** |
| 113 * Parse the response from the fetchPrinters call. | 113 * Parse the response from the fetchPrinters call. |
| 114 * @param {function} callback Function to be called to process response. | 114 * @param {function} callback Function to be called to process response. |
| 115 * @param {XMLHttpRequest} xhr The object used to make the request. | 115 * @param {XMLHttpRequest} xhr The object used to make the request. |
| 116 */ | 116 */ |
| 117 function fetchPrintersResponse(callback, xhr) { | 117 function fetchPrintersResponse(callback, xhr) { |
| 118 if (xhr.status == 200) { | 118 if (xhr.status == 200) { |
| 119 var searchResult = JSON.parse(xhr.responseText); | 119 var searchResult = JSON.parse(xhr.responseText); |
| 120 if (searchResult['success']) { | 120 if (searchResult['success']) { |
| 121 var printerList = searchResult['printers']; | 121 var printerList = searchResult['printers']; |
| 122 callback.call(this, printerList, false); | 122 callback.call(this, printerList); |
| 123 } else { | 123 } else { |
| 124 callback.call(this, null, false); | 124 callback.call(this, null); |
| 125 } | 125 } |
| 126 } else { | 126 } else { |
| 127 callback.call(this, null, false); | 127 callback.call(this, null); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * Retrieve the list of printers available via cloud print. | 132 * Retrieve the list of printers available via cloud print. |
| 133 * @param {function} callback Function to be called to process response. | 133 * @param {function} callback Function to be called to process response. |
| 134 */ | 134 */ |
| 135 function fetchPrinters(callback, all) { | 135 function fetchPrinters(callback, all) { |
| 136 var query = 'q=^recent'; | 136 var query = 'q=^recent'; |
| 137 if (all) { | 137 if (all) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 * @param {Object} cloud_print_data Data to be stored in cloudPrintOptions. | 298 * @param {Object} cloud_print_data Data to be stored in cloudPrintOptions. |
| 299 * @param {function} add_callback The callback to be called to add the new | 299 * @param {function} add_callback The callback to be called to add the new |
| 300 * printer to the print preview UI. | 300 * printer to the print preview UI. |
| 301 * @param {function} update_caps_callback The callback to be called to update | 301 * @param {function} update_caps_callback The callback to be called to update |
| 302 * capabilities on the new printer. | 302 * capabilities on the new printer. |
| 303 */ | 303 */ |
| 304 function setDefaultPrinter(printer_name, | 304 function setDefaultPrinter(printer_name, |
| 305 cloud_print_data, | 305 cloud_print_data, |
| 306 add_callback, | 306 add_callback, |
| 307 update_caps_callback) { | 307 update_caps_callback) { |
| 308 var printer = add_callback([JSON.parse(cloud_print_data)], false); | 308 var printer = add_callback([JSON.parse(cloud_print_data)]); |
| 309 if (printer) | 309 if (printer) |
| 310 update_caps_callback(printer); | 310 update_caps_callback(printer); |
| 311 } | 311 } |
| 312 | 312 |
| 313 /** Returns the data necessary to serialize a cloud print printer. | 313 /** Returns the data necessary to serialize a cloud print printer. |
|
dpapad
2011/07/19 22:22:58
Please use the following format, here and elsewher
Albert Bodenhamer
2011/07/19 22:43:48
Done.
| |
| 314 * @param {Object} printer The printer object to get data for. | 314 * @param {Object} printer The printer object to get data for. |
| 315 * @return {string} A JSON string that can be used to recreate the | 315 * @return {string} A JSON string that can be used to recreate the |
| 316 * cloud print portion of the printer object, or | 316 * cloud print portion of the printer object, or |
|
dpapad
2011/07/19 22:22:58
Nit: More can fit in this line.
Albert Bodenhamer
2011/07/19 22:43:48
Done.
| |
| 317 * an empty string if there is no data to save. | 317 * an empty string if there is no data to save. |
| 318 */ | 318 */ |
| 319 function getData(printer) { | 319 function getData(printer) { |
| 320 if (isCloudPrint(printer)) { | 320 if (isCloudPrint(printer)) { |
| 321 return JSON.stringify(printer.cloudPrintOptions); | 321 return JSON.stringify(printer.cloudPrintOptions); |
| 322 } else { | 322 } else { |
| 323 return ""; | 323 return ""; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 /** Test if a printer is a cloud print printer. | 327 /** Test if a printer is a cloud print printer. |
| 328 * @param {Object} printer The printer to test. | 328 * @param {Object} printer The printer to test. |
| 329 * @return {boolean} true iff the printer is a cloud print printer. | 329 * @return {boolean} true iff the printer is a cloud print printer. |
| 330 */ | 330 */ |
| 331 function isCloudPrint(printer) { | 331 function isCloudPrint(printer) { |
| 332 return printer && printer.cloudPrintOptions != null; | 332 return printer && printer.cloudPrintOptions != null; |
| 333 } | 333 } |
| 334 | 334 |
| 335 /** Mark a printer as a cloud print printer and record its name and id. | 335 /** Mark a printer as a cloud print printer and record its name and id. |
| 336 * @param {Object} printer The printer to mark. | 336 * @param {Object} printer The printer to mark. |
| 337 * @param {string} name The user visible name of the printer. | 337 * @param {string} name The user visible name of the printer. |
| 338 * @param {string} id The id of the printer used by cloud print to | 338 * @param {string} id The id of the printer used by cloud print to |
| 339 * identify it. | 339 * identify it. |
| 340 */ | 340 */ |
| 341 function setCloudPrint(printer, name, id) { | 341 function setCloudPrint(printer, name, id) { |
| 342 if (!printer.cloudPrintOptions) { | 342 if (!printer.cloudPrintOptions) { |
| 343 printer.cloudPrintOptions = new Object; | 343 printer.cloudPrintOptions = new Object; |
| 344 } | 344 } |
| 345 printer.cloudPrintOptions.name = name; | 345 printer.cloudPrintOptions.name = name; |
| 346 printer.cloudPrintOptions.id = id; | 346 printer.cloudPrintOptions.id = id; |
| 347 } | 347 } |
| 348 | 348 |
| 349 return { | 349 return { |
| 350 colorIsDefault: colorIsDefault, | 350 colorIsDefault: colorIsDefault, |
| 351 fetchPrinters: fetchPrinters, | 351 fetchPrinters: fetchPrinters, |
| 352 getBaseURL: getBaseURL, | 352 getBaseURL: getBaseURL, |
| 353 getData: getData, | 353 getData: getData, |
| 354 getPrintTicketJSON: getPrintTicketJSON, | 354 getPrintTicketJSON: getPrintTicketJSON, |
| 355 isCloudPrint: isCloudPrint, | 355 isCloudPrint: isCloudPrint, |
| 356 printToCloud: printToCloud, | 356 printToCloud: printToCloud, |
| 357 setBaseURL: setBaseURL, | 357 setBaseURL: setBaseURL, |
| 358 setCloudPrint: setCloudPrint, | 358 setCloudPrint: setCloudPrint, |
| 359 setColor: setColor, | 359 setColor: setColor, |
| 360 setDefaultPrinter: setDefaultPrinter, | 360 setDefaultPrinter: setDefaultPrinter, |
| 361 supportsColor: supportsColor, | 361 supportsColor: supportsColor, |
| 362 updatePrinterCaps: updatePrinterCaps | 362 updatePrinterCaps: updatePrinterCaps |
| 363 }; | 363 }; |
| 364 }); | 364 }); |
| OLD | NEW |