| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * API to the Google Cloud Print service. | 9 * API to the Google Cloud Print service. |
| 10 * @param {string} baseUrl Base part of the Google Cloud Print service URL | 10 * @param {string} baseUrl Base part of the Google Cloud Print service URL |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 printer: function(printerId) { | 96 printer: function(printerId) { |
| 97 var params = {'printerid': printerId}; | 97 var params = {'printerid': printerId}; |
| 98 this.sendRequest_('GET', 'printer', params, null, this.onPrinterDone_); | 98 this.sendRequest_('GET', 'printer', params, null, this.onPrinterDone_); |
| 99 }, | 99 }, |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * Creates an object that represents a Google Cloud Print print ticket. | 102 * Creates an object that represents a Google Cloud Print print ticket. |
| 103 * @param {!print_preview.Destination} destination Destination to print to. | 103 * @param {!print_preview.Destination} destination Destination to print to. |
| 104 * @param {!print_preview.PrintTicketStore} printTicketStore Used to create | 104 * @param {!print_preview.PrintTicketStore} printTicketStore Used to create |
| 105 * the state of the print ticket. | 105 * the state of the print ticket. |
| 106 * @return {object} Google Cloud Print print ticket. | 106 * @return {!Object} Google Cloud Print print ticket. |
| 107 */ | 107 */ |
| 108 createPrintTicket: function(destination, printTicketStore) { | 108 createPrintTicket: function(destination, printTicketStore) { |
| 109 assert(!destination.isLocal, | 109 assert(!destination.isLocal, |
| 110 'Trying to create a Google Cloud Print print ticket for a local ' + | 110 'Trying to create a Google Cloud Print print ticket for a local ' + |
| 111 'destination'); | 111 'destination'); |
| 112 assert(destination.capabilities, | 112 assert(destination.capabilities, |
| 113 'Trying to create a Google Cloud Print print ticket for a ' + | 113 'Trying to create a Google Cloud Print print ticket for a ' + |
| 114 'destination with no print capabilities'); | 114 'destination with no print capabilities'); |
| 115 | 115 |
| 116 var ticketItems = []; | 116 var ticketItems = []; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 }, | 240 }, |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * Called when the search request completes successfully. | 243 * Called when the search request completes successfully. |
| 244 * @param {Object} result JSON response. | 244 * @param {Object} result JSON response. |
| 245 * @private | 245 * @private |
| 246 */ | 246 */ |
| 247 onSearchDone_: function(result) { | 247 onSearchDone_: function(result) { |
| 248 var printerListJson = result['printers'] || []; | 248 var printerListJson = result['printers'] || []; |
| 249 var printerList = []; | 249 var printerList = []; |
| 250 for (var printerJson, i = 0; printerJson = printerListJson[i]; i++) { | 250 printerListJson.forEach(function(printerJson) { |
| 251 try { | 251 try { |
| 252 printerList.push( | 252 printerList.push( |
| 253 cloudprint.CloudDestinationParser.parse(printerJson)); | 253 cloudprint.CloudDestinationParser.parse(printerJson)); |
| 254 } catch (err) { | 254 } catch (err) { |
| 255 console.error('Unable to parse cloud print destination: ' + err); | 255 console.error('Unable to parse cloud print destination: ' + err); |
| 256 } | 256 } |
| 257 } | 257 }); |
| 258 var isRecent = result['request']['params']['q'] == '^recent'; | 258 var isRecent = result['request']['params']['q'] == '^recent'; |
| 259 var searchDoneEvent = | 259 var searchDoneEvent = |
| 260 new cr.Event(CloudPrintInterface.EventType.SEARCH_DONE); | 260 new cr.Event(CloudPrintInterface.EventType.SEARCH_DONE); |
| 261 searchDoneEvent.printers = printerList; | 261 searchDoneEvent.printers = printerList; |
| 262 searchDoneEvent.isRecent = isRecent; | 262 searchDoneEvent.isRecent = isRecent; |
| 263 searchDoneEvent.email = result['request']['user']; | 263 searchDoneEvent.email = result['request']['user']; |
| 264 this.dispatchEvent(searchDoneEvent); | 264 this.dispatchEvent(searchDoneEvent); |
| 265 }, | 265 }, |
| 266 | 266 |
| 267 /** | 267 /** |
| (...skipping 27 matching lines...) Expand all Loading... |
| 295 printerDoneEvent.printer = printer; | 295 printerDoneEvent.printer = printer; |
| 296 this.dispatchEvent(printerDoneEvent); | 296 this.dispatchEvent(printerDoneEvent); |
| 297 } | 297 } |
| 298 }; | 298 }; |
| 299 | 299 |
| 300 // Export | 300 // Export |
| 301 return { | 301 return { |
| 302 CloudPrintInterface: CloudPrintInterface | 302 CloudPrintInterface: CloudPrintInterface |
| 303 }; | 303 }; |
| 304 }); | 304 }); |
| OLD | NEW |