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('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * A data store that stores destinations and dispatches events when the data | 9 * A data store that stores destinations and dispatches events when the data |
10 * store changes. | 10 * store changes. |
(...skipping 21 matching lines...) Expand all Loading... |
32 this.appState_ = appState; | 32 this.appState_ = appState; |
33 | 33 |
34 /** | 34 /** |
35 * Internal backing store for the data store. | 35 * Internal backing store for the data store. |
36 * @type {!Array.<!print_preview.Destination>} | 36 * @type {!Array.<!print_preview.Destination>} |
37 * @private | 37 * @private |
38 */ | 38 */ |
39 this.destinations_ = []; | 39 this.destinations_ = []; |
40 | 40 |
41 /** | 41 /** |
42 * Cache used for constant lookup of destinations by ID. | 42 * Cache used for constant lookup of destinations by origin and id. |
43 * @type {object.<string, !print_preview.Destination>} | 43 * @type {object.<string, !print_preview.Destination>} |
44 * @private | 44 * @private |
45 */ | 45 */ |
46 this.destinationMap_ = {}; | 46 this.destinationMap_ = {}; |
47 | 47 |
48 /** | 48 /** |
49 * Currently selected destination. | 49 * Currently selected destination. |
50 * @type {print_preview.Destination} | 50 * @type {print_preview.Destination} |
51 * @private | 51 * @private |
52 */ | 52 */ |
53 this.selectedDestination_ = null; | 53 this.selectedDestination_ = null; |
54 | 54 |
55 /** | 55 /** |
56 * Initial destination ID used to auto-select the first inserted destination | 56 * Initial destination ID used to auto-select the first inserted destination |
57 * that matches. If {@code null}, the first destination inserted into the | 57 * that matches. If {@code null}, the first destination inserted into the |
58 * store will be selected. | 58 * store will be selected. |
59 * @type {?string} | 59 * @type {?string} |
60 * @private | 60 * @private |
61 */ | 61 */ |
62 this.initialDestinationId_ = null; | 62 this.initialDestinationId_ = null; |
63 | 63 |
64 /** | 64 /** |
65 * Whether the initial destination is a local one or not. | 65 * Initial origin used to auto-select destination. |
66 * @type {boolean} | 66 * @type {print_preview.Destination.Origin} |
67 * @private | 67 * @private |
68 */ | 68 */ |
69 this.isInitialDestinationLocal_ = true; | 69 this.initialDestinationOrigin_ = print_preview.Destination.Origin.LOCAL; |
70 | 70 |
71 /** | 71 /** |
72 * Whether the destination store will auto select the destination that | 72 * Whether the destination store will auto select the destination that |
73 * matches the initial destination. | 73 * matches the initial destination. |
74 * @type {boolean} | 74 * @type {boolean} |
75 * @private | 75 * @private |
76 */ | 76 */ |
77 this.isInAutoSelectMode_ = false; | 77 this.isInAutoSelectMode_ = false; |
78 | 78 |
79 /** | 79 /** |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 /** | 148 /** |
149 * Creates a local PDF print destination. | 149 * Creates a local PDF print destination. |
150 * @return {!print_preview.Destination} Created print destination. | 150 * @return {!print_preview.Destination} Created print destination. |
151 * @private | 151 * @private |
152 */ | 152 */ |
153 DestinationStore.createLocalPdfPrintDestination_ = function() { | 153 DestinationStore.createLocalPdfPrintDestination_ = function() { |
154 var dest = new print_preview.Destination( | 154 var dest = new print_preview.Destination( |
155 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 155 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
156 print_preview.Destination.Type.LOCAL, | 156 print_preview.Destination.Type.LOCAL, |
157 print_preview.Destination.AuthType.LOCAL, | 157 print_preview.Destination.Origin.LOCAL, |
158 localStrings.getString('printToPDF'), | 158 localStrings.getString('printToPDF'), |
159 false /*isRecent*/, | 159 false /*isRecent*/, |
160 print_preview.Destination.ConnectionStatus.ONLINE); | 160 print_preview.Destination.ConnectionStatus.ONLINE); |
161 dest.capabilities = { | 161 dest.capabilities = { |
162 version: '1.0', | 162 version: '1.0', |
163 printer: { | 163 printer: { |
164 page_orientation: { | 164 page_orientation: { |
165 option: [ | 165 option: [ |
166 {type: 'AUTO', is_default: true}, | 166 {type: 'AUTO', is_default: true}, |
167 {type: 'PORTRAIT'}, | 167 {type: 'PORTRAIT'}, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 /** | 211 /** |
212 * Initializes the destination store. Sets the initially selected | 212 * Initializes the destination store. Sets the initially selected |
213 * destination. If any inserted destinations match this ID, that destination | 213 * destination. If any inserted destinations match this ID, that destination |
214 * will be automatically selected. This method must be called after the | 214 * will be automatically selected. This method must be called after the |
215 * print_preview.AppState has been initialized. | 215 * print_preview.AppState has been initialized. |
216 * @param {?string} systemDefaultDestinationId ID of the system default | 216 * @param {?string} systemDefaultDestinationId ID of the system default |
217 * destination. | 217 * destination. |
218 * @private | 218 * @private |
219 */ | 219 */ |
220 init: function(systemDefaultDestinationId) { | 220 init: function(systemDefaultDestinationId) { |
221 if (this.appState_.selectedDestinationId) { | 221 if (this.appState_.selectedDestinationId && |
| 222 this.appState_.selectedDestinationOrigin) { |
222 this.initialDestinationId_ = this.appState_.selectedDestinationId; | 223 this.initialDestinationId_ = this.appState_.selectedDestinationId; |
223 this.isInitialDestinationLocal_ = | 224 this.initialDestinationOrigin_ = |
224 this.appState_.isSelectedDestinationLocal; | 225 this.appState_.selectedDestinationOrigin_; |
225 } else { | 226 } else { |
226 this.initialDestinationId_ = systemDefaultDestinationId; | 227 this.initialDestinationId_ = systemDefaultDestinationId; |
227 this.isInitialDestinationLocal_ = true; | 228 this.initialDestinationOrigin_ = |
| 229 print_preview.Destination.Origin.LOCAL; |
228 } | 230 } |
229 | |
230 this.isInAutoSelectMode_ = true; | 231 this.isInAutoSelectMode_ = true; |
231 if (this.initialDestinationId_ == null) { | 232 if (this.initialDestinationId_ == null || |
| 233 this.initialDestinationOrigin_ == null) { |
232 assert(this.destinations_.length > 0, | 234 assert(this.destinations_.length > 0, |
233 'No destinations available to select'); | 235 'No destinations available to select'); |
234 this.selectDestination(this.destinations_[0]); | 236 this.selectDestination(this.destinations_[0]); |
235 } else { | 237 } else { |
236 var candidate = this.destinationMap_[this.initialDestinationId_]; | 238 var key = this.getDestinationKey_(this.initialDestinationOrigin_, |
| 239 this.initialDestinationId_); |
| 240 var candidate = this.destinationMap_[key]; |
237 if (candidate != null) { | 241 if (candidate != null) { |
238 this.selectDestination(candidate); | 242 this.selectDestination(candidate); |
239 } else if (!cr.isChromeOS && this.isInitialDestinationLocal_) { | 243 } else if (!cr.isChromeOS && |
| 244 this.initialDestinationOrigin_ == |
| 245 print_preview.Destination.Origin.LOCAL) { |
240 this.nativeLayer_.startGetLocalDestinationCapabilities( | 246 this.nativeLayer_.startGetLocalDestinationCapabilities( |
241 this.initialDestinationId_); | 247 this.initialDestinationId_); |
242 } | 248 } |
243 } | 249 } |
244 }, | 250 }, |
245 | 251 |
246 /** | 252 /** |
247 * Sets the destination store's Google Cloud Print interface. | 253 * Sets the destination store's Google Cloud Print interface. |
248 * @param {!print_preview.CloudPrintInterface} cloudPrintInterface Interface | 254 * @param {!print_preview.CloudPrintInterface} cloudPrintInterface Interface |
249 * to set. | 255 * to set. |
(...skipping 10 matching lines...) Expand all Loading... |
260 this.onCloudPrintSearchFailed_.bind(this)); | 266 this.onCloudPrintSearchFailed_.bind(this)); |
261 this.tracker_.add( | 267 this.tracker_.add( |
262 this.cloudPrintInterface_, | 268 this.cloudPrintInterface_, |
263 cloudprint.CloudPrintInterface.EventType.PRINTER_DONE, | 269 cloudprint.CloudPrintInterface.EventType.PRINTER_DONE, |
264 this.onCloudPrintPrinterDone_.bind(this)); | 270 this.onCloudPrintPrinterDone_.bind(this)); |
265 this.tracker_.add( | 271 this.tracker_.add( |
266 this.cloudPrintInterface_, | 272 this.cloudPrintInterface_, |
267 cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, | 273 cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, |
268 this.onCloudPrintPrinterFailed_.bind(this)); | 274 this.onCloudPrintPrinterFailed_.bind(this)); |
269 // Fetch initial destination if its a cloud destination. | 275 // Fetch initial destination if its a cloud destination. |
270 if (this.isInAutoSelectMode_ && !this.isInitialDestinationLocal_) { | 276 var origin = this.initialDestinationOrigin_; |
271 this.cloudPrintInterface_.printer(this.initialDestinationId_); | 277 if (this.isInAutoSelectMode_ && |
| 278 origin != print_preview.Destination.Origin.LOCAL) { |
| 279 this.cloudPrintInterface_.printer(this.initialDestinationId_, origin); |
272 } | 280 } |
273 }, | 281 }, |
274 | 282 |
275 /** | 283 /** |
276 * @return {boolean} Whether only default cloud destinations have been | 284 * @return {boolean} Whether only default cloud destinations have been |
277 * loaded. | 285 * loaded. |
278 */ | 286 */ |
279 hasOnlyDefaultCloudDestinations: function() { | 287 hasOnlyDefaultCloudDestinations: function() { |
280 return this.destinations_.every(function(dest) { | 288 return this.destinations_.every(function(dest) { |
281 return dest.isLocal || | 289 return dest.isLocal || |
(...skipping 24 matching lines...) Expand all Loading... |
306 cr.dispatchSimpleEvent( | 314 cr.dispatchSimpleEvent( |
307 this, DestinationStore.EventType.DESTINATION_SELECT); | 315 this, DestinationStore.EventType.DESTINATION_SELECT); |
308 if (destination.capabilities == null) { | 316 if (destination.capabilities == null) { |
309 if (destination.isLocal) { | 317 if (destination.isLocal) { |
310 this.nativeLayer_.startGetLocalDestinationCapabilities( | 318 this.nativeLayer_.startGetLocalDestinationCapabilities( |
311 destination.id); | 319 destination.id); |
312 } else { | 320 } else { |
313 assert(this.cloudPrintInterface_ != null, | 321 assert(this.cloudPrintInterface_ != null, |
314 'Selected destination is a cloud destination, but Google ' + | 322 'Selected destination is a cloud destination, but Google ' + |
315 'Cloud Print is not enabled'); | 323 'Cloud Print is not enabled'); |
316 this.cloudPrintInterface_.printer(destination.id); | 324 this.cloudPrintInterface_.printer(destination.id, |
| 325 destination.origin); |
317 } | 326 } |
318 } else { | 327 } else { |
319 cr.dispatchSimpleEvent( | 328 cr.dispatchSimpleEvent( |
320 this, | 329 this, |
321 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); | 330 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); |
322 } | 331 } |
323 }, | 332 }, |
324 | 333 |
325 /** | 334 /** |
326 * Inserts a print destination to the data store and dispatches a | 335 * Inserts a print destination to the data store and dispatches a |
327 * DESTINATIONS_INSERTED event. If the destination matches the initial | 336 * DESTINATIONS_INSERTED event. If the destination matches the initial |
328 * destination ID, then the destination will be automatically selected. | 337 * destination ID, then the destination will be automatically selected. |
329 * @param {!print_preview.Destination} destination Print destination to | 338 * @param {!print_preview.Destination} destination Print destination to |
330 * insert. | 339 * insert. |
331 */ | 340 */ |
332 insertDestination: function(destination) { | 341 insertDestination: function(destination) { |
333 if (this.insertDestination_(destination)) { | 342 if (this.insertDestination_(destination)) { |
334 cr.dispatchSimpleEvent( | 343 cr.dispatchSimpleEvent( |
335 this, DestinationStore.EventType.DESTINATIONS_INSERTED); | 344 this, DestinationStore.EventType.DESTINATIONS_INSERTED); |
336 if (this.isInAutoSelectMode_ && | 345 if (this.isInAutoSelectMode_ && |
337 (this.initialDestinationId_ == null || | 346 this.matchInitialDestination_(destination.id, destination.origin)) { |
338 destination.id == this.initialDestinationId_)) { | |
339 this.selectDestination(destination); | 347 this.selectDestination(destination); |
340 } | 348 } |
341 } | 349 } |
342 }, | 350 }, |
343 | 351 |
344 /** | 352 /** |
345 * Inserts multiple print destinations to the data store and dispatches one | 353 * Inserts multiple print destinations to the data store and dispatches one |
346 * DESTINATIONS_INSERTED event. If any of the destinations match the initial | 354 * DESTINATIONS_INSERTED event. If any of the destinations match the initial |
347 * destination ID, then that destination will be automatically selected. | 355 * destination ID, then that destination will be automatically selected. |
348 * @param {!Array.<print_preview.Destination>} destinations Print | 356 * @param {!Array.<print_preview.Destination>} destinations Print |
349 * destinations to insert. | 357 * destinations to insert. |
350 */ | 358 */ |
351 insertDestinations: function(destinations) { | 359 insertDestinations: function(destinations) { |
352 var insertedDestination = false; | 360 var insertedDestination = false; |
353 var destinationToAutoSelect = null; | 361 var destinationToAutoSelect = null; |
354 destinations.forEach(function(dest) { | 362 destinations.forEach(function(dest) { |
355 if (this.insertDestination_(dest)) { | 363 if (this.insertDestination_(dest)) { |
356 insertedDestination = true; | 364 insertedDestination = true; |
357 if (this.isInAutoSelectMode_ && | 365 if (this.isInAutoSelectMode_ && |
358 destinationToAutoSelect == null && | 366 destinationToAutoSelect == null && |
359 (this.initialDestinationId_ == null || | 367 this.matchInitialDestination_(dest.id, dest.origin)) { |
360 dest.id == this.initialDestinationId_)) { | |
361 destinationToAutoSelect = dest; | 368 destinationToAutoSelect = dest; |
362 } | 369 } |
363 } | 370 } |
364 }, this); | 371 }, this); |
365 if (insertedDestination) { | 372 if (insertedDestination) { |
366 cr.dispatchSimpleEvent( | 373 cr.dispatchSimpleEvent( |
367 this, DestinationStore.EventType.DESTINATIONS_INSERTED); | 374 this, DestinationStore.EventType.DESTINATIONS_INSERTED); |
368 } | 375 } |
369 if (destinationToAutoSelect != null) { | 376 if (destinationToAutoSelect != null) { |
370 this.selectDestination(destinationToAutoSelect); | 377 this.selectDestination(destinationToAutoSelect); |
371 } | 378 } |
372 }, | 379 }, |
373 | 380 |
374 /** | 381 /** |
375 * Updates an existing print destination with capabilities information. If | 382 * Updates an existing print destination with capabilities information. If |
376 * the destination doesn't already exist, it will be added. | 383 * the destination doesn't already exist, it will be added. |
377 * @param {!print_preview.Destination} destination Destination to update. | 384 * @param {!print_preview.Destination} destination Destination to update. |
378 * @return {!print_preview.Destination} The existing destination that was | 385 * @return {!print_preview.Destination} The existing destination that was |
379 * updated. | 386 * updated or {@code null} if it was the new destination. |
380 */ | 387 */ |
381 updateDestination: function(destination) { | 388 updateDestination: function(destination) { |
382 var existingDestination = this.destinationMap_[destination.id]; | 389 var key = this.getDestinationKey_(destination.origin, destination.id); |
| 390 var existingDestination = this.destinationMap_[key]; |
383 if (existingDestination != null) { | 391 if (existingDestination != null) { |
384 existingDestination.capabilities = destination.capabilities; | 392 existingDestination.capabilities = destination.capabilities; |
385 return existingDestination; | 393 return existingDestination; |
386 } else { | 394 } else { |
387 this.insertDestination(destination); | 395 this.insertDestination(destination); |
| 396 return null; |
388 } | 397 } |
389 }, | 398 }, |
390 | 399 |
391 /** Initiates loading of local print destinations. */ | 400 /** Initiates loading of local print destinations. */ |
392 startLoadLocalDestinations: function() { | 401 startLoadLocalDestinations: function() { |
393 this.nativeLayer_.startGetLocalDestinations(); | 402 this.nativeLayer_.startGetLocalDestinations(); |
394 this.isLocalDestinationSearchInProgress_ = true; | 403 this.isLocalDestinationSearchInProgress_ = true; |
395 cr.dispatchSimpleEvent( | 404 cr.dispatchSimpleEvent( |
396 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 405 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
397 }, | 406 }, |
(...skipping 13 matching lines...) Expand all Loading... |
411 } | 420 } |
412 }, | 421 }, |
413 | 422 |
414 /** | 423 /** |
415 * Inserts a destination into the store without dispatching any events. | 424 * Inserts a destination into the store without dispatching any events. |
416 * @return {boolean} Whether the inserted destination was not already in the | 425 * @return {boolean} Whether the inserted destination was not already in the |
417 * store. | 426 * store. |
418 * @private | 427 * @private |
419 */ | 428 */ |
420 insertDestination_: function(destination) { | 429 insertDestination_: function(destination) { |
421 var existingDestination = this.destinationMap_[destination.id]; | 430 var key = this.getDestinationKey_(destination.origin, destination.id); |
| 431 var existingDestination = this.destinationMap_[key]; |
422 if (existingDestination == null) { | 432 if (existingDestination == null) { |
423 this.destinations_.push(destination); | 433 this.destinations_.push(destination); |
424 this.destinationMap_[destination.id] = destination; | 434 this.destinationMap_[key] = destination; |
425 return true; | 435 return true; |
426 } else if (existingDestination.connectionStatus == | 436 } else if (existingDestination.connectionStatus == |
427 print_preview.Destination.ConnectionStatus.UNKNOWN && | 437 print_preview.Destination.ConnectionStatus.UNKNOWN && |
428 destination.connectionStatus != | 438 destination.connectionStatus != |
429 print_preview.Destination.ConnectionStatus.UNKNOWN) { | 439 print_preview.Destination.ConnectionStatus.UNKNOWN) { |
430 existingDestination.connectionStatus = destination.connectionStatus; | 440 existingDestination.connectionStatus = destination.connectionStatus; |
431 return true; | 441 return true; |
432 } else { | 442 } else { |
433 return false; | 443 return false; |
434 } | 444 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 * Called when the native layer retrieves the capabilities for the selected | 502 * Called when the native layer retrieves the capabilities for the selected |
493 * local destination. Updates the destination with new capabilities if the | 503 * local destination. Updates the destination with new capabilities if the |
494 * destination already exists, otherwise it creates a new destination and | 504 * destination already exists, otherwise it creates a new destination and |
495 * then updates its capabilities. | 505 * then updates its capabilities. |
496 * @param {cr.Event} event Contains the capabilities of the local print | 506 * @param {cr.Event} event Contains the capabilities of the local print |
497 * destination. | 507 * destination. |
498 * @private | 508 * @private |
499 */ | 509 */ |
500 onLocalDestinationCapabilitiesSet_: function(event) { | 510 onLocalDestinationCapabilitiesSet_: function(event) { |
501 var destinationId = event.settingsInfo['printerId']; | 511 var destinationId = event.settingsInfo['printerId']; |
502 var destination = this.destinationMap_[destinationId]; | 512 var key = |
| 513 this.getDestinationKey_(print_preview.Destination.Origin.LOCAL, |
| 514 destinationId); |
| 515 var destination = this.destinationMap_[key]; |
503 var capabilities = print_preview.LocalCapabilitiesParser.parse( | 516 var capabilities = print_preview.LocalCapabilitiesParser.parse( |
504 event.settingsInfo); | 517 event.settingsInfo); |
505 if (destination) { | 518 if (destination) { |
506 // In case there were multiple capabilities request for this local | 519 // In case there were multiple capabilities request for this local |
507 // destination, just ignore the later ones. | 520 // destination, just ignore the later ones. |
508 if (destination.capabilities != null) { | 521 if (destination.capabilities != null) { |
509 return; | 522 return; |
510 } | 523 } |
511 destination.capabilities = capabilities; | 524 destination.capabilities = capabilities; |
512 } else { | 525 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
530 * Called when a request to get a local destination's print capabilities | 543 * Called when a request to get a local destination's print capabilities |
531 * fails. If the destination is the initial destination, auto-select another | 544 * fails. If the destination is the initial destination, auto-select another |
532 * destination instead. | 545 * destination instead. |
533 * @param {cr.Event} event Contains the destination ID that failed. | 546 * @param {cr.Event} event Contains the destination ID that failed. |
534 * @private | 547 * @private |
535 */ | 548 */ |
536 onGetCapabilitiesFail_: function(event) { | 549 onGetCapabilitiesFail_: function(event) { |
537 console.error('Failed to get print capabilities for printer ' + | 550 console.error('Failed to get print capabilities for printer ' + |
538 event.destinationId); | 551 event.destinationId); |
539 if (this.isInAutoSelectMode_ && | 552 if (this.isInAutoSelectMode_ && |
540 this.initialDestinationId_ == event.destinationId) { | 553 this.matchInitialDestinationStrict_(event.destinationId, |
| 554 event.destinationOrigin)) { |
541 assert(this.destinations_.length > 0, | 555 assert(this.destinations_.length > 0, |
542 'No destinations were loaded when failed to get initial ' + | 556 'No destinations were loaded when failed to get initial ' + |
543 'destination'); | 557 'destination'); |
544 this.selectDestination(this.destinations_[0]); | 558 this.selectDestination(this.destinations_[0]); |
545 } | 559 } |
546 }, | 560 }, |
547 | 561 |
548 /** | 562 /** |
549 * Called when the /search call completes. Adds the fetched destinations to | 563 * Called when the /search call completes. Adds the fetched destinations to |
550 * the destination store. | 564 * the destination store. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 /** | 600 /** |
587 * Called when the Google Cloud Print interface fails to lookup a | 601 * Called when the Google Cloud Print interface fails to lookup a |
588 * destination. Selects another destination if the failed destination was | 602 * destination. Selects another destination if the failed destination was |
589 * the initial destination. | 603 * the initial destination. |
590 * @param {object} event Contains the ID of the destination that was failed | 604 * @param {object} event Contains the ID of the destination that was failed |
591 * to be looked up. | 605 * to be looked up. |
592 * @private | 606 * @private |
593 */ | 607 */ |
594 onCloudPrintPrinterFailed_: function(event) { | 608 onCloudPrintPrinterFailed_: function(event) { |
595 if (this.isInAutoSelectMode_ && | 609 if (this.isInAutoSelectMode_ && |
596 this.initialDestinationId_ == event.destinationId) { | 610 this.matchInitialDestinationStrict_(event.destinationId, |
| 611 event.destinationOrigin)) { |
597 console.error('Could not find initial printer: ' + event.destinationId); | 612 console.error('Could not find initial printer: ' + event.destinationId); |
598 assert(this.destinations_.length > 0, | 613 assert(this.destinations_.length > 0, |
599 'No destinations were loaded when failed to get initial ' + | 614 'No destinations were loaded when failed to get initial ' + |
600 'destination'); | 615 'destination'); |
601 this.selectDestination(this.destinations_[0]); | 616 this.selectDestination(this.destinations_[0]); |
602 } | 617 } |
603 }, | 618 }, |
604 | 619 |
605 /** | 620 /** |
606 * Called from native layer after the user was requested to sign in, and did | 621 * Called from native layer after the user was requested to sign in, and did |
(...skipping 11 matching lines...) Expand all Loading... |
618 /** | 633 /** |
619 * Called when no destination was auto-selected after some timeout. Selects | 634 * Called when no destination was auto-selected after some timeout. Selects |
620 * the first destination in store. | 635 * the first destination in store. |
621 * @private | 636 * @private |
622 */ | 637 */ |
623 onAutoSelectTimeoutExpired_: function() { | 638 onAutoSelectTimeoutExpired_: function() { |
624 this.autoSelectTimeout_ = null; | 639 this.autoSelectTimeout_ = null; |
625 assert(this.destinations_.length > 0, | 640 assert(this.destinations_.length > 0, |
626 'No destinations were loaded before auto-select timeout expired'); | 641 'No destinations were loaded before auto-select timeout expired'); |
627 this.selectDestination(this.destinations_[0]); | 642 this.selectDestination(this.destinations_[0]); |
| 643 }, |
| 644 |
| 645 // TODO(vitalybuka): Remove three next functions replacing Destination.id |
| 646 // and Destination.origin by complex ID. |
| 647 /** |
| 648 * Returns key to be used with {@code destinationMap_}. |
| 649 * @param {!print_preview.Destination.Origin} origin Destination origin. |
| 650 * @return {!string} id Destination id. |
| 651 * @private |
| 652 */ |
| 653 getDestinationKey_: function(origin, id) { |
| 654 return origin + '/' + id; |
| 655 }, |
| 656 |
| 657 /** |
| 658 * @param {?string} id Id of the destination. |
| 659 * @param {?string} origin Oring of the destination. |
| 660 * @return {boolean} Whether a initial destination matches provided. |
| 661 * @private |
| 662 */ |
| 663 matchInitialDestination_: function(id, origin) { |
| 664 return this.initialDestinationId_ == null || |
| 665 this.initialDestinationOrigin_ == null || |
| 666 this.matchInitialDestinationStrict_(id, origin); |
| 667 }, |
| 668 |
| 669 /** |
| 670 * @param {?string} id Id of the destination. |
| 671 * @param {?string} origin Oring of the destination. |
| 672 * @return {boolean} Whether destination is the same as initial. |
| 673 * @private |
| 674 */ |
| 675 matchInitialDestinationStrict_: function(id, origin) { |
| 676 return id == this.initialDestinationId_ && |
| 677 origin == this.initialDestinationOrigin_; |
628 } | 678 } |
629 }; | 679 }; |
630 | 680 |
631 // Export | 681 // Export |
632 return { | 682 return { |
633 DestinationStore: DestinationStore | 683 DestinationStore: DestinationStore |
634 }; | 684 }; |
635 }); | 685 }); |
OLD | NEW |