Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 /** | 60 /** |
| 61 * Stores last received XSRF tokens for each user account. Sent as | 61 * Stores last received XSRF tokens for each user account. Sent as |
| 62 * a parameter with every request. | 62 * a parameter with every request. |
| 63 * @type {!Object.<string, string>} | 63 * @type {!Object.<string, string>} |
| 64 * @private | 64 * @private |
| 65 */ | 65 */ |
| 66 this.xsrfTokens_ = {}; | 66 this.xsrfTokens_ = {}; |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Pending requests delayed until we get access token. | 69 * Pending requests delayed until we get access token. |
| 70 * @type {!Array.<!CloudPrintRequest>} | 70 * @type {!Array.<!cloudprint.CloudPrintRequest>} |
| 71 * @private | 71 * @private |
| 72 */ | 72 */ |
| 73 this.requestQueue_ = []; | 73 this.requestQueue_ = []; |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Outstanding cloud destination search requests. | 76 * Outstanding cloud destination search requests. |
| 77 * @type {!Array.<!CloudPrintRequest>} | 77 * @type {!Array.<!cloudprint.CloudPrintRequest>} |
| 78 * @private | 78 * @private |
| 79 */ | 79 */ |
| 80 this.outstandingCloudSearchRequests_ = []; | 80 this.outstandingCloudSearchRequests_ = []; |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Event tracker used to keep track of native layer events. | 83 * Event tracker used to keep track of native layer events. |
| 84 * @type {!EventTracker} | 84 * @type {!EventTracker} |
| 85 * @private | 85 * @private |
| 86 */ | 86 */ |
| 87 this.tracker_ = new EventTracker(); | 87 this.tracker_ = new EventTracker(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 destination.origin, | 310 destination.origin, |
| 311 destination.account, | 311 destination.account, |
| 312 this.onSubmitDone_.bind(this)); | 312 this.onSubmitDone_.bind(this)); |
| 313 this.sendOrQueueRequest_(cpRequest); | 313 this.sendOrQueueRequest_(cpRequest); |
| 314 }, | 314 }, |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * Sends a Google Cloud Print printer API request. | 317 * Sends a Google Cloud Print printer API request. |
| 318 * @param {string} printerId ID of the printer to lookup. | 318 * @param {string} printerId ID of the printer to lookup. |
| 319 * @param {!print_preview.Destination.Origin} origin Origin of the printer. | 319 * @param {!print_preview.Destination.Origin} origin Origin of the printer. |
| 320 * @param {string=} account Account this printer is registered for. When | 320 * @param {?string} account Account this printer is registered for. When |
| 321 * provided for COOKIES {@code origin}, and users sessions are still not | 321 * provided for COOKIES {@code origin}, and users sessions are still not |
| 322 * known, will be checked against the response (both success and failure | 322 * known, will be checked against the response (both success and failure |
| 323 * to get printer) and, if the active user account is not the one | 323 * to get printer) and, if the active user account is not the one |
| 324 * requested, {@code account} is activated and printer request reissued. | 324 * requested, {@code account} is activated and printer request reissued. |
| 325 */ | 325 */ |
| 326 printer: function(printerId, origin, account) { | 326 printer: function(printerId, origin, account) { |
| 327 var params = [ | 327 var params = [ |
| 328 new HttpParam('printerid', printerId), | 328 new HttpParam('printerid', printerId), |
| 329 new HttpParam('use_cdd', 'true'), | 329 new HttpParam('use_cdd', 'true'), |
| 330 new HttpParam('printer_connection_status', 'true') | 330 new HttpParam('printer_connection_status', 'true') |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 * @param {string} method HTTP method of the request. | 375 * @param {string} method HTTP method of the request. |
| 376 * @param {string} action Google Cloud Print action to perform. | 376 * @param {string} action Google Cloud Print action to perform. |
| 377 * @param {Array.<!HttpParam>} params HTTP parameters to include in the | 377 * @param {Array.<!HttpParam>} params HTTP parameters to include in the |
| 378 * request. | 378 * request. |
| 379 * @param {!print_preview.Destination.Origin} origin Origin for destination. | 379 * @param {!print_preview.Destination.Origin} origin Origin for destination. |
| 380 * @param {?string} account Account the request is sent for. Can be | 380 * @param {?string} account Account the request is sent for. Can be |
| 381 * {@code null} or empty string if the request is not cookie bound or | 381 * {@code null} or empty string if the request is not cookie bound or |
| 382 * is sent on behalf of the primary user. | 382 * is sent on behalf of the primary user. |
| 383 * @param {function(number, Object, !print_preview.Destination.Origin)} | 383 * @param {function(number, Object, !print_preview.Destination.Origin)} |
| 384 * callback Callback to invoke when request completes. | 384 * callback Callback to invoke when request completes. |
| 385 * @return {!CloudPrintRequest} Partially prepared request. | 385 * @return {!cloudprint.CloudPrintRequest} Partially prepared request. |
| 386 * @private | 386 * @private |
| 387 */ | 387 */ |
| 388 buildRequest_: function(method, action, params, origin, account, callback) { | 388 buildRequest_: function(method, action, params, origin, account, callback) { |
| 389 var url = this.baseUrl_ + '/' + action + '?xsrf='; | 389 var url = this.baseUrl_ + '/' + action + '?xsrf='; |
| 390 if (origin == print_preview.Destination.Origin.COOKIES) { | 390 if (origin == print_preview.Destination.Origin.COOKIES) { |
| 391 account = assert(account); | |
| 391 var xsrfToken = this.xsrfTokens_[account]; | 392 var xsrfToken = this.xsrfTokens_[account]; |
| 392 if (!xsrfToken) { | 393 if (!xsrfToken) { |
| 393 // TODO(rltoscano): Should throw an error if not a read-only action or | 394 // TODO(rltoscano): Should throw an error if not a read-only action or |
| 394 // issue an xsrf token request. | 395 // issue an xsrf token request. |
| 395 } else { | 396 } else { |
| 396 url = url + xsrfToken; | 397 url = url + xsrfToken; |
| 397 } | 398 } |
| 398 if (account) { | 399 if (account) { |
| 399 var index = this.userSessionIndex_[account] || 0; | 400 var index = this.userSessionIndex_[account] || 0; |
| 400 if (index > 0) { | 401 if (index > 0) { |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 /** | 823 /** |
| 823 * Result for requests. | 824 * Result for requests. |
| 824 * @type {Object} JSON response. | 825 * @type {Object} JSON response. |
| 825 */ | 826 */ |
| 826 this.result = null; | 827 this.result = null; |
| 827 }; | 828 }; |
| 828 | 829 |
| 829 /** | 830 /** |
| 830 * Data structure that represents an HTTP parameter. | 831 * Data structure that represents an HTTP parameter. |
| 831 * @param {string} name Name of the parameter. | 832 * @param {string} name Name of the parameter. |
| 832 * @param {string} value Value of the parameter. | 833 * @param {print_preview.ValueType} value Value of the parameter. |
| 833 * @constructor | 834 * @constructor |
| 834 */ | 835 */ |
| 835 function HttpParam(name, value) { | 836 function HttpParam(name, value) { |
| 836 /** | 837 /** |
| 837 * Name of the parameter. | 838 * Name of the parameter. |
| 838 * @type {string} | 839 * @type {string} |
| 839 */ | 840 */ |
| 840 this.name = name; | 841 this.name = name; |
| 841 | 842 |
| 842 /** | 843 /** |
| 843 * Name of the value. | 844 * Name of the value. |
| 844 * @type {string} | 845 * @type {string} |
| 845 */ | 846 */ |
| 846 this.value = value; | 847 this.value = value; |
| 847 }; | 848 }; |
| 848 | 849 |
| 849 // Export | 850 // Export |
| 850 return { | 851 return { |
| 851 CloudPrintInterface: CloudPrintInterface | 852 CloudPrintInterface: CloudPrintInterface, |
| 853 CloudPrintRequest: CloudPrintRequest | |
|
Aleksey Shlyapnikov
2014/09/24 17:54:43
Why are you exporting it? It's not used anywhere o
Vitaly Pavlenko
2014/09/24 20:39:49
Right now that's the only way to use the type clou
Aleksey Shlyapnikov
2014/09/24 21:13:17
If we have no workaround, then yes. Let's add a co
Vitaly Pavlenko
2014/09/24 22:37:57
Done.
| |
| 852 }; | 854 }; |
| 853 }); | 855 }); |
| OLD | NEW |