| 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. |
| 11 * @param {!print_preview.NativeLayer} nativeLayer Used to fetch local print | 11 * @param {!print_preview.NativeLayer} nativeLayer Used to fetch local print |
| 12 * destinations. | 12 * destinations. |
| 13 * @param {!print_preview.UserInfo} userInfo User information repository. | 13 * @param {!print_preview.UserInfo} userInfo User information repository. |
| 14 * @param {!print_preview.AppState} appState Application state. | 14 * @param {!print_preview.AppState} appState Application state. |
| 15 * @param {!WebUIListenerTracker} listenerTracker Tracker for WebUI listeners |
| 16 * added in DestinationStore constructor. |
| 15 * @constructor | 17 * @constructor |
| 16 * @extends {cr.EventTarget} | 18 * @extends {cr.EventTarget} |
| 17 */ | 19 */ |
| 18 function DestinationStore(nativeLayer, userInfo, appState) { | 20 function DestinationStore(nativeLayer, userInfo, appState, listenerTracker) { |
| 19 cr.EventTarget.call(this); | 21 cr.EventTarget.call(this); |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * Used to fetch local print destinations. | 24 * Used to fetch local print destinations. |
| 23 * @private {!print_preview.NativeLayer} | 25 * @private {!print_preview.NativeLayer} |
| 24 */ | 26 */ |
| 25 this.nativeLayer_ = nativeLayer; | 27 this.nativeLayer_ = nativeLayer; |
| 26 | 28 |
| 27 /** | 29 /** |
| 28 * User information repository. | 30 * User information repository. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 173 |
| 172 /** | 174 /** |
| 173 * Whether to default to the system default printer instead of the most | 175 * Whether to default to the system default printer instead of the most |
| 174 * recent destination. | 176 * recent destination. |
| 175 * @private {boolean} | 177 * @private {boolean} |
| 176 */ | 178 */ |
| 177 this.useSystemDefaultAsDefault_ = | 179 this.useSystemDefaultAsDefault_ = |
| 178 loadTimeData.getBoolean('useSystemDefaultPrinter'); | 180 loadTimeData.getBoolean('useSystemDefaultPrinter'); |
| 179 | 181 |
| 180 this.reset_(); | 182 this.reset_(); |
| 183 |
| 184 this.addWebUIEventListeners_(listenerTracker); |
| 181 } | 185 } |
| 182 | 186 |
| 183 /** | 187 /** |
| 184 * Event types dispatched by the data store. | 188 * Event types dispatched by the data store. |
| 185 * @enum {string} | 189 * @enum {string} |
| 186 */ | 190 */ |
| 187 DestinationStore.EventType = { | 191 DestinationStore.EventType = { |
| 188 DESTINATION_SEARCH_DONE: | 192 DESTINATION_SEARCH_DONE: |
| 189 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', | 193 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', |
| 190 DESTINATION_SEARCH_STARTED: | 194 DESTINATION_SEARCH_STARTED: |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 get isCloudDestinationSearchInProgress() { | 546 get isCloudDestinationSearchInProgress() { |
| 543 return !!this.cloudPrintInterface_ && | 547 return !!this.cloudPrintInterface_ && |
| 544 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; | 548 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; |
| 545 }, | 549 }, |
| 546 | 550 |
| 547 /** | 551 /** |
| 548 * Starts listening for relevant WebUI events and adds the listeners to | 552 * Starts listening for relevant WebUI events and adds the listeners to |
| 549 * |listenerTracker|. |listenerTracker| is responsible for removing the | 553 * |listenerTracker|. |listenerTracker| is responsible for removing the |
| 550 * listeners when necessary. | 554 * listeners when necessary. |
| 551 * @param {!WebUIListenerTracker} listenerTracker | 555 * @param {!WebUIListenerTracker} listenerTracker |
| 556 * @private |
| 552 */ | 557 */ |
| 553 addWebUIEventListeners: function(listenerTracker) { | 558 addWebUIEventListeners_: function(listenerTracker) { |
| 554 listenerTracker.add( | 559 listenerTracker.add( |
| 555 'privet-printer-added', this.onPrivetPrinterAdded_.bind(this)); | 560 'privet-printer-added', this.onPrivetPrinterAdded_.bind(this)); |
| 556 listenerTracker.add( | 561 listenerTracker.add( |
| 557 'extension-printers-added', | 562 'extension-printers-added', |
| 558 this.onExtensionPrintersAdded_.bind(this)); | 563 this.onExtensionPrintersAdded_.bind(this)); |
| 559 listenerTracker.add( | 564 listenerTracker.add( |
| 560 'reload-printer-list', this.onDestinationsReload.bind(this)); | 565 'reload-printer-list', this.onDestinationsReload.bind(this)); |
| 561 }, | 566 }, |
| 562 | 567 |
| 563 /** | 568 /** |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'), | 877 new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'), |
| 873 null /*displayNameRegExp*/, false /*skipVirtualDestinations*/); | 878 null /*displayNameRegExp*/, false /*skipVirtualDestinations*/); |
| 874 }, | 879 }, |
| 875 | 880 |
| 876 /** | 881 /** |
| 877 * Sets the destination store's Google Cloud Print interface. | 882 * Sets the destination store's Google Cloud Print interface. |
| 878 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface | 883 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
| 879 * to set. | 884 * to set. |
| 880 */ | 885 */ |
| 881 setCloudPrintInterface: function(cloudPrintInterface) { | 886 setCloudPrintInterface: function(cloudPrintInterface) { |
| 887 assert(this.cloudPrintInterface_ == null); |
| 882 this.cloudPrintInterface_ = cloudPrintInterface; | 888 this.cloudPrintInterface_ = cloudPrintInterface; |
| 883 this.tracker_.add( | 889 this.tracker_.add( |
| 884 this.cloudPrintInterface_, | 890 this.cloudPrintInterface_, |
| 885 cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE, | 891 cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE, |
| 886 this.onCloudPrintSearchDone_.bind(this)); | 892 this.onCloudPrintSearchDone_.bind(this)); |
| 887 this.tracker_.add( | 893 this.tracker_.add( |
| 888 this.cloudPrintInterface_, | 894 this.cloudPrintInterface_, |
| 889 cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, | 895 cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, |
| 890 this.onCloudPrintSearchDone_.bind(this)); | 896 this.onCloudPrintSearchDone_.bind(this)); |
| 891 this.tracker_.add( | 897 this.tracker_.add( |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 */ | 1658 */ |
| 1653 getKey_: function(destination) { | 1659 getKey_: function(destination) { |
| 1654 return this.getDestinationKey_( | 1660 return this.getDestinationKey_( |
| 1655 destination.origin, destination.id, destination.account); | 1661 destination.origin, destination.id, destination.account); |
| 1656 } | 1662 } |
| 1657 }; | 1663 }; |
| 1658 | 1664 |
| 1659 // Export | 1665 // Export |
| 1660 return {DestinationStore: DestinationStore}; | 1666 return {DestinationStore: DestinationStore}; |
| 1661 }); | 1667 }); |
| OLD | NEW |