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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 cloudprint.CloudPrintInterface.EventType.SEARCH_FAILED, | 357 cloudprint.CloudPrintInterface.EventType.SEARCH_FAILED, |
358 this.onCloudPrintSearchDone_.bind(this)); | 358 this.onCloudPrintSearchDone_.bind(this)); |
359 this.tracker_.add( | 359 this.tracker_.add( |
360 this.cloudPrintInterface_, | 360 this.cloudPrintInterface_, |
361 cloudprint.CloudPrintInterface.EventType.PRINTER_DONE, | 361 cloudprint.CloudPrintInterface.EventType.PRINTER_DONE, |
362 this.onCloudPrintPrinterDone_.bind(this)); | 362 this.onCloudPrintPrinterDone_.bind(this)); |
363 this.tracker_.add( | 363 this.tracker_.add( |
364 this.cloudPrintInterface_, | 364 this.cloudPrintInterface_, |
365 cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, | 365 cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, |
366 this.onCloudPrintPrinterFailed_.bind(this)); | 366 this.onCloudPrintPrinterFailed_.bind(this)); |
367 this.tracker_.add( | |
368 this.cloudPrintInterface_, | |
369 cloudprint.CloudPrintInterface.EventType.PROCESS_INVITE_DONE, | |
370 this.onCloudPrintProcessInviteDone_.bind(this)); | |
367 }, | 371 }, |
368 | 372 |
369 /** | 373 /** |
370 * @return {boolean} Whether only default cloud destinations have been | 374 * @return {boolean} Whether only default cloud destinations have been |
371 * loaded. | 375 * loaded. |
372 */ | 376 */ |
373 hasOnlyDefaultCloudDestinations: function() { | 377 hasOnlyDefaultCloudDestinations: function() { |
374 // TODO: Move the logic to print_preview. | 378 // TODO: Move the logic to print_preview. |
375 return this.destinations_.every(function(dest) { | 379 return this.destinations_.every(function(dest) { |
376 return dest.isLocal || | 380 return dest.isLocal || |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 var origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || []; | 508 var origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || []; |
505 if (origins.indexOf(print_preview.Destination.Origin.COOKIES) >= 0) { | 509 if (origins.indexOf(print_preview.Destination.Origin.COOKIES) >= 0) { |
506 cr.dispatchSimpleEvent( | 510 cr.dispatchSimpleEvent( |
507 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); | 511 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); |
508 } else { | 512 } else { |
509 this.startLoadCloudDestinations( | 513 this.startLoadCloudDestinations( |
510 print_preview.Destination.Origin.COOKIES); | 514 print_preview.Destination.Origin.COOKIES); |
511 } | 515 } |
512 }, | 516 }, |
513 | 517 |
518 /** Initiates loading of all known destination types. */ | |
519 startLoadAllDestinations: function() { | |
520 this.startLoadCloudDestinations(); | |
521 this.startLoadLocalDestinations(); | |
522 this.startLoadPrivetDestinations(); | |
523 }, | |
524 | |
514 /** | 525 /** |
515 * Wait for a privet device to be registered. | 526 * Wait for a privet device to be registered. |
516 */ | 527 */ |
517 waitForRegister: function(id) { | 528 waitForRegister: function(id) { |
518 this.nativeLayer_.startGetPrivetDestinations(); | 529 this.nativeLayer_.startGetPrivetDestinations(); |
519 this.waitForRegisterDestination_ = id; | 530 this.waitForRegisterDestination_ = id; |
520 }, | 531 }, |
521 | 532 |
522 /** | 533 /** |
523 * Inserts {@code destination} to the data store and dispatches a | 534 * Inserts {@code destination} to the data store and dispatches a |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 if (this.isInAutoSelectMode_ && | 840 if (this.isInAutoSelectMode_ && |
830 this.sameAsPersistedDestination_(event.destinationId, | 841 this.sameAsPersistedDestination_(event.destinationId, |
831 event.destinationOrigin)) { | 842 event.destinationOrigin)) { |
832 console.error( | 843 console.error( |
833 'Failed to fetch last used printer caps: ' + event.destinationId); | 844 'Failed to fetch last used printer caps: ' + event.destinationId); |
834 this.selectDefaultDestination_(); | 845 this.selectDefaultDestination_(); |
835 } | 846 } |
836 }, | 847 }, |
837 | 848 |
838 /** | 849 /** |
850 * Called when printer sharing invitation was processed successfully. | |
851 * @param {Event} event Contains detailed information about the invite and | |
852 * newly accepted destination (if known). | |
853 * @private | |
854 */ | |
855 onCloudPrintProcessInviteDone_: function(event) { | |
856 if (event.accept && event.printer) { | |
857 // Hint the destination list to promote this new destination. | |
858 event.printer.isRecent = true; | |
Vitaly Buka (NO REVIEWS)
2014/09/22 01:25:15
Please add metricts somewhere to count accepts and
| |
859 this.insertDestination_(event.printer); | |
860 } | |
861 }, | |
862 | |
863 /** | |
839 * Called when a Privet printer is added to the local network. | 864 * Called when a Privet printer is added to the local network. |
840 * @param {object} event Contains information about the added printer. | 865 * @param {object} event Contains information about the added printer. |
841 * @private | 866 * @private |
842 */ | 867 */ |
843 onPrivetPrinterAdded_: function(event) { | 868 onPrivetPrinterAdded_: function(event) { |
844 if (event.printer.serviceName == this.waitForRegisterDestination_ && | 869 if (event.printer.serviceName == this.waitForRegisterDestination_ && |
845 !event.printer.isUnregistered) { | 870 !event.printer.isUnregistered) { |
846 this.waitForRegisterDestination_ = null; | 871 this.waitForRegisterDestination_ = null; |
847 this.onDestinationsReload_(); | 872 this.onDestinationsReload_(); |
848 } else { | 873 } else { |
(...skipping 19 matching lines...) Expand all Loading... | |
868 | 893 |
869 /** | 894 /** |
870 * Called from native layer after the user was requested to sign in, and did | 895 * Called from native layer after the user was requested to sign in, and did |
871 * so successfully. | 896 * so successfully. |
872 * @private | 897 * @private |
873 */ | 898 */ |
874 onDestinationsReload_: function() { | 899 onDestinationsReload_: function() { |
875 this.reset_(); | 900 this.reset_(); |
876 this.isInAutoSelectMode_ = true; | 901 this.isInAutoSelectMode_ = true; |
877 this.createLocalPdfPrintDestination_(); | 902 this.createLocalPdfPrintDestination_(); |
878 this.startLoadLocalDestinations(); | 903 this.startLoadAllDestinations(); |
879 this.startLoadCloudDestinations(); | |
880 this.startLoadPrivetDestinations(); | |
881 }, | 904 }, |
882 | 905 |
883 // TODO(vitalybuka): Remove three next functions replacing Destination.id | 906 // TODO(vitalybuka): Remove three next functions replacing Destination.id |
884 // and Destination.origin by complex ID. | 907 // and Destination.origin by complex ID. |
885 /** | 908 /** |
886 * Returns key to be used with {@code destinationMap_}. | 909 * Returns key to be used with {@code destinationMap_}. |
887 * @param {!print_preview.Destination.Origin} origin Destination origin. | 910 * @param {!print_preview.Destination.Origin} origin Destination origin. |
888 * @return {string} id Destination id. | 911 * @return {string} id Destination id. |
889 * @return {string} account User account destination is registered for. | 912 * @return {string} account User account destination is registered for. |
890 * @private | 913 * @private |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
926 return id == this.appState_.selectedDestinationId && | 949 return id == this.appState_.selectedDestinationId && |
927 origin == this.appState_.selectedDestinationOrigin; | 950 origin == this.appState_.selectedDestinationOrigin; |
928 } | 951 } |
929 }; | 952 }; |
930 | 953 |
931 // Export | 954 // Export |
932 return { | 955 return { |
933 DestinationStore: DestinationStore | 956 DestinationStore: DestinationStore |
934 }; | 957 }; |
935 }); | 958 }); |
OLD | NEW |