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

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

Issue 7408004: Printer dropdown cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More review feedback 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 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
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (color) { 286 if (color) {
287 printer.cloudPrintOptions.colorOption.options = 287 printer.cloudPrintOptions.colorOption.options =
288 [printer.cloudPrintOptions.colorOnOption]; 288 [printer.cloudPrintOptions.colorOnOption];
289 } else { 289 } else {
290 printer.cloudPrintOptions.colorOption.options = 290 printer.cloudPrintOptions.colorOption.options =
291 [printer.cloudPrintOptions.colorOffOption]; 291 [printer.cloudPrintOptions.colorOffOption];
292 } 292 }
293 } 293 }
294 } 294 }
295 295
296 /** Creates a cloud print printer and sets it as the default printer. 296 /**
297 * Creates a cloud print printer and sets it as the default printer.
297 * @param {string} printer_name The name of the printer to create. 298 * @param {string} printer_name The name of the printer to create.
298 * @param {Object} cloud_print_data Data to be stored in cloudPrintOptions. 299 * @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 300 * @param {function} add_callback The callback to be called to add the new
300 * printer to the print preview UI. 301 * printer to the print preview UI.
301 * @param {function} update_caps_callback The callback to be called to update 302 * @param {function} update_caps_callback The callback to be called to update
302 * capabilities on the new printer. 303 * capabilities on the new printer.
303 */ 304 */
304 function setDefaultPrinter(printer_name, 305 function setDefaultPrinter(printer_name,
305 cloud_print_data, 306 cloud_print_data,
306 add_callback, 307 add_callback,
307 update_caps_callback) { 308 update_caps_callback) {
308 var printer = add_callback([JSON.parse(cloud_print_data)], false); 309 var printer = add_callback([JSON.parse(cloud_print_data)]);
309 if (printer) 310 if (printer)
310 update_caps_callback(printer); 311 update_caps_callback(printer);
311 } 312 }
312 313
313 /** Returns the data necessary to serialize a cloud print printer. 314 /**
315 * Returns the data necessary to serialize a cloud print printer.
314 * @param {Object} printer The printer object to get data for. 316 * @param {Object} printer The printer object to get data for.
315 * @return {string} A JSON string that can be used to recreate the 317 * @return {string} A JSON string that can be used to recreate the
316 * cloud print portion of the printer object, or 318 * cloud print portion of the printer object, or and empty string if
317 * an empty string if there is no data to save. 319 * there is no data to save.
318 */ 320 */
319 function getData(printer) { 321 function getData(printer) {
320 if (isCloudPrint(printer)) { 322 if (isCloudPrint(printer)) {
321 return JSON.stringify(printer.cloudPrintOptions); 323 return JSON.stringify(printer.cloudPrintOptions);
322 } else { 324 } else {
323 return ""; 325 return "";
324 } 326 }
325 } 327 }
326 328
327 /** Test if a printer is a cloud print printer. 329 /**
330 * Test if a printer is a cloud print printer.
328 * @param {Object} printer The printer to test. 331 * @param {Object} printer The printer to test.
329 * @return {boolean} true iff the printer is a cloud print printer. 332 * @return {boolean} true iff the printer is a cloud print printer.
330 */ 333 */
331 function isCloudPrint(printer) { 334 function isCloudPrint(printer) {
332 return printer && printer.cloudPrintOptions != null; 335 return printer && printer.cloudPrintOptions != null;
333 } 336 }
334 337
335 /** Mark a printer as a cloud print printer and record its name and id. 338 /**
339 * Mark a printer as a cloud print printer and record its name and id.
336 * @param {Object} printer The printer to mark. 340 * @param {Object} printer The printer to mark.
337 * @param {string} name The user visible name of the printer. 341 * @param {string} name The user visible name of the printer.
338 * @param {string} id The id of the printer used by cloud print to 342 * @param {string} id The id of the printer used by cloud print to
339 * identify it. 343 * identify it.
340 */ 344 */
341 function setCloudPrint(printer, name, id) { 345 function setCloudPrint(printer, name, id) {
342 if (!printer.cloudPrintOptions) { 346 if (!printer.cloudPrintOptions) {
343 printer.cloudPrintOptions = new Object; 347 printer.cloudPrintOptions = new Object;
344 } 348 }
345 printer.cloudPrintOptions.name = name; 349 printer.cloudPrintOptions.name = name;
346 printer.cloudPrintOptions.id = id; 350 printer.cloudPrintOptions.id = id;
347 } 351 }
348 352
349 return { 353 return {
350 colorIsDefault: colorIsDefault, 354 colorIsDefault: colorIsDefault,
351 fetchPrinters: fetchPrinters, 355 fetchPrinters: fetchPrinters,
352 getBaseURL: getBaseURL, 356 getBaseURL: getBaseURL,
353 getData: getData, 357 getData: getData,
354 getPrintTicketJSON: getPrintTicketJSON, 358 getPrintTicketJSON: getPrintTicketJSON,
355 isCloudPrint: isCloudPrint, 359 isCloudPrint: isCloudPrint,
356 printToCloud: printToCloud, 360 printToCloud: printToCloud,
357 setBaseURL: setBaseURL, 361 setBaseURL: setBaseURL,
358 setCloudPrint: setCloudPrint, 362 setCloudPrint: setCloudPrint,
359 setColor: setColor, 363 setColor: setColor,
360 setDefaultPrinter: setDefaultPrinter, 364 setDefaultPrinter: setDefaultPrinter,
361 supportsColor: supportsColor, 365 supportsColor: supportsColor,
362 updatePrinterCaps: updatePrinterCaps 366 updatePrinterCaps: updatePrinterCaps
363 }; 367 };
364 }); 368 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698