| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 * Whether Print Preview is in App Kiosk mode, basically, use only printers | 45 * Whether Print Preview is in App Kiosk mode, basically, use only printers |
| 46 * available for the device. | 46 * available for the device. |
| 47 * @type {boolean} | 47 * @type {boolean} |
| 48 * @private | 48 * @private |
| 49 */ | 49 */ |
| 50 this.isInAppKioskMode_ = isInAppKioskMode; | 50 this.isInAppKioskMode_ = isInAppKioskMode; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Currently logged in users (identified by email) mapped to the Google | 53 * Currently logged in users (identified by email) mapped to the Google |
| 54 * session index. | 54 * session index. |
| 55 * @type {!Object.<string, number>} | 55 * @type {!Object<string, number>} |
| 56 * @private | 56 * @private |
| 57 */ | 57 */ |
| 58 this.userSessionIndex_ = {}; | 58 this.userSessionIndex_ = {}; |
| 59 | 59 |
| 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<!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<!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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 * Enumeration of JSON response fields from Google Cloud Print API. | 150 * Enumeration of JSON response fields from Google Cloud Print API. |
| 151 * @enum {string} | 151 * @enum {string} |
| 152 * @private | 152 * @private |
| 153 */ | 153 */ |
| 154 CloudPrintInterface.JsonFields_ = { | 154 CloudPrintInterface.JsonFields_ = { |
| 155 PRINTER: 'printer' | 155 PRINTER: 'printer' |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * Could Print origins used to search printers. | 159 * Could Print origins used to search printers. |
| 160 * @type {!Array.<!print_preview.Destination.Origin>} | 160 * @type {!Array<!print_preview.Destination.Origin>} |
| 161 * @const | 161 * @const |
| 162 * @private | 162 * @private |
| 163 */ | 163 */ |
| 164 CloudPrintInterface.CLOUD_ORIGINS_ = [ | 164 CloudPrintInterface.CLOUD_ORIGINS_ = [ |
| 165 print_preview.Destination.Origin.COOKIES, | 165 print_preview.Destination.Origin.COOKIES, |
| 166 print_preview.Destination.Origin.DEVICE | 166 print_preview.Destination.Origin.DEVICE |
| 167 // TODO(vitalybuka): Enable when implemented. | 167 // TODO(vitalybuka): Enable when implemented. |
| 168 // ready print_preview.Destination.Origin.PROFILE | 168 // ready print_preview.Destination.Origin.PROFILE |
| 169 ]; | 169 ]; |
| 170 | 170 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 this.search_(false, account, origins); | 205 this.search_(false, account, origins); |
| 206 }, | 206 }, |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * Sends Google Cloud Print search API requests. | 209 * Sends Google Cloud Print search API requests. |
| 210 * @param {boolean} isRecent Whether to search for only recently used | 210 * @param {boolean} isRecent Whether to search for only recently used |
| 211 * printers. | 211 * printers. |
| 212 * @param {string} account Account the search is sent for. It matters for | 212 * @param {string} account Account the search is sent for. It matters for |
| 213 * COOKIES origin only, and can be empty (sent on behalf of the primary | 213 * COOKIES origin only, and can be empty (sent on behalf of the primary |
| 214 * user in this case). | 214 * user in this case). |
| 215 * @param {!Array.<!print_preview.Destination.Origin>} origins Origins to | 215 * @param {!Array<!print_preview.Destination.Origin>} origins Origins to |
| 216 * search printers for. | 216 * search printers for. |
| 217 * @private | 217 * @private |
| 218 */ | 218 */ |
| 219 search_: function(isRecent, account, origins) { | 219 search_: function(isRecent, account, origins) { |
| 220 var params = [ | 220 var params = [ |
| 221 new HttpParam('connection_status', 'ALL'), | 221 new HttpParam('connection_status', 'ALL'), |
| 222 new HttpParam('client', 'chrome'), | 222 new HttpParam('client', 'chrome'), |
| 223 new HttpParam('use_cdd', 'true') | 223 new HttpParam('use_cdd', 'true') |
| 224 ]; | 224 ]; |
| 225 if (isRecent) { | 225 if (isRecent) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 this.tracker_.add( | 367 this.tracker_.add( |
| 368 this.nativeLayer_, | 368 this.nativeLayer_, |
| 369 print_preview.NativeLayer.EventType.ACCESS_TOKEN_READY, | 369 print_preview.NativeLayer.EventType.ACCESS_TOKEN_READY, |
| 370 this.onAccessTokenReady_.bind(this)); | 370 this.onAccessTokenReady_.bind(this)); |
| 371 }, | 371 }, |
| 372 | 372 |
| 373 /** | 373 /** |
| 374 * Builds request to the Google Cloud Print API. | 374 * Builds request to the Google Cloud Print API. |
| 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 {!CloudPrintRequest} Partially prepared request. |
| 386 * @private | 386 * @private |
| 387 */ | 387 */ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 this.userSessionIndex_ = {}; | 495 this.userSessionIndex_ = {}; |
| 496 for (var i = 0; i < users.length; i++) { | 496 for (var i = 0; i < users.length; i++) { |
| 497 this.userSessionIndex_[users[i]] = i; | 497 this.userSessionIndex_[users[i]] = i; |
| 498 } | 498 } |
| 499 this.userInfo_.setUsers(request.result['request']['user'], users); | 499 this.userInfo_.setUsers(request.result['request']['user'], users); |
| 500 } | 500 } |
| 501 }, | 501 }, |
| 502 | 502 |
| 503 /** | 503 /** |
| 504 * Terminates search requests for requested {@code origins}. | 504 * Terminates search requests for requested {@code origins}. |
| 505 * @param {!Array.<print_preview.Destination.Origin>} origins Origins | 505 * @param {!Array<print_preview.Destination.Origin>} origins Origins |
| 506 * to terminate search requests for. | 506 * to terminate search requests for. |
| 507 * @private | 507 * @private |
| 508 */ | 508 */ |
| 509 abortSearchRequests_: function(origins) { | 509 abortSearchRequests_: function(origins) { |
| 510 this.outstandingCloudSearchRequests_ = | 510 this.outstandingCloudSearchRequests_ = |
| 511 this.outstandingCloudSearchRequests_.filter(function(request) { | 511 this.outstandingCloudSearchRequests_.filter(function(request) { |
| 512 if (origins.indexOf(request.origin) >= 0) { | 512 if (origins.indexOf(request.origin) >= 0) { |
| 513 request.xhr.abort(); | 513 request.xhr.abort(); |
| 514 return false; | 514 return false; |
| 515 } | 515 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 * @type {string} | 844 * @type {string} |
| 845 */ | 845 */ |
| 846 this.value = value; | 846 this.value = value; |
| 847 }; | 847 }; |
| 848 | 848 |
| 849 // Export | 849 // Export |
| 850 return { | 850 return { |
| 851 CloudPrintInterface: CloudPrintInterface | 851 CloudPrintInterface: CloudPrintInterface |
| 852 }; | 852 }; |
| 853 }); | 853 }); |
| OLD | NEW |