Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 2969383003: Print Preview: Finish removing global Javascript functions. (Closed)
Patch Set: Move listener addition Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 print_preview.DestinationOrigin.LOCAL; 170 print_preview.DestinationOrigin.LOCAL;
171 171
172 /** 172 /**
173 * Whether to default to the system default printer instead of the most 173 * Whether to default to the system default printer instead of the most
174 * recent destination. 174 * recent destination.
175 * @private {boolean} 175 * @private {boolean}
176 */ 176 */
177 this.useSystemDefaultAsDefault_ = 177 this.useSystemDefaultAsDefault_ =
178 loadTimeData.getBoolean('useSystemDefaultPrinter'); 178 loadTimeData.getBoolean('useSystemDefaultPrinter');
179 179
180 this.addEventListeners_();
181 this.reset_(); 180 this.reset_();
182 } 181 }
183 182
184 /** 183 /**
185 * Event types dispatched by the data store. 184 * Event types dispatched by the data store.
186 * @enum {string} 185 * @enum {string}
187 */ 186 */
188 DestinationStore.EventType = { 187 DestinationStore.EventType = {
189 DESTINATION_SEARCH_DONE: 188 DESTINATION_SEARCH_DONE:
190 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', 189 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE',
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 538
540 /** 539 /**
541 * @return {boolean} Whether a search for cloud destinations is in progress. 540 * @return {boolean} Whether a search for cloud destinations is in progress.
542 */ 541 */
543 get isCloudDestinationSearchInProgress() { 542 get isCloudDestinationSearchInProgress() {
544 return !!this.cloudPrintInterface_ && 543 return !!this.cloudPrintInterface_ &&
545 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; 544 this.cloudPrintInterface_.isCloudDestinationSearchInProgress;
546 }, 545 },
547 546
548 /** 547 /**
548 * Registers the destination store for the WebUI events it responds to and
dpapad 2017/07/07 21:12:41 Nit: Slightly confused by the syntax in this comme
rbpotter 2017/07/07 23:58:39 Done.
549 * adds the listeners to |listenerTracker| so that they can be
550 * automatically removed by this tracker later.
551 * @param {!WebUIListenerTracker} listenerTracker The tracker to add the
552 * listeners to.
553 */
554 addWebUIEventListeners: function(listenerTracker) {
555 listenerTracker.add(
556 'privet-printer-added', this.onPrivetPrinterAdded_.bind(this));
557 listenerTracker.add(
558 'extension-printers-added',
559 this.onExtensionPrintersAdded_.bind(this));
560 listenerTracker.add(
561 'reload-printer-list', this.onDestinationsReload.bind(this));
562 },
563
564 /**
549 * Initializes the destination store. Sets the initially selected 565 * Initializes the destination store. Sets the initially selected
550 * destination. If any inserted destinations match this ID, that destination 566 * destination. If any inserted destinations match this ID, that destination
551 * will be automatically selected. This method must be called after the 567 * will be automatically selected. This method must be called after the
552 * print_preview.AppState has been initialized. 568 * print_preview.AppState has been initialized.
553 * @param {boolean} isInAppKioskMode Whether the print preview is in App 569 * @param {boolean} isInAppKioskMode Whether the print preview is in App
554 * Kiosk mode. 570 * Kiosk mode.
555 * @param {?string} systemDefaultDestinationId ID of the system default 571 * @param {?string} systemDefaultDestinationId ID of the system default
556 * destination. 572 * destination.
557 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 573 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
558 * default destination selection rules. 574 * default destination selection rules.
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 }, 1188 },
1173 1189
1174 /** 1190 /**
1175 * Dispatches the PROVISIONAL_DESTINATION_RESOLVED event for id 1191 * Dispatches the PROVISIONAL_DESTINATION_RESOLVED event for id
1176 * |provisionalId| and destination |destination|. 1192 * |provisionalId| and destination |destination|.
1177 * @param {string} provisionalId The ID of the destination that was 1193 * @param {string} provisionalId The ID of the destination that was
1178 * resolved. 1194 * resolved.
1179 * @param {?print_preview.Destination} destination Information about the 1195 * @param {?print_preview.Destination} destination Information about the
1180 * destination if it was resolved successfully. 1196 * destination if it was resolved successfully.
1181 */ 1197 */
1182 dispatchProvisionalDestinationResolvedEvent_: function(provisionalId, 1198 dispatchProvisionalDestinationResolvedEvent_: function(
1183 destination) { 1199 provisionalId, destination) {
1184 var event = new Event( 1200 var event = new Event(
1185 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); 1201 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED);
1186 event.provisionalId = provisionalId; 1202 event.provisionalId = provisionalId;
1187 event.destination = destination; 1203 event.destination = destination;
1188 this.dispatchEvent(event); 1204 this.dispatchEvent(event);
1189 }, 1205 },
1190 1206
1191 /** 1207 /**
1192 * Inserts {@code destination} to the data store and dispatches a 1208 * Inserts {@code destination} to the data store and dispatches a
1193 * DESTINATIONS_INSERTED event. 1209 * DESTINATIONS_INSERTED event.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 destination.connectionStatus != 1342 destination.connectionStatus !=
1327 print_preview.DestinationConnectionStatus.UNKNOWN) { 1343 print_preview.DestinationConnectionStatus.UNKNOWN) {
1328 existingDestination.connectionStatus = destination.connectionStatus; 1344 existingDestination.connectionStatus = destination.connectionStatus;
1329 return true; 1345 return true;
1330 } else { 1346 } else {
1331 return false; 1347 return false;
1332 } 1348 }
1333 }, 1349 },
1334 1350
1335 /** 1351 /**
1336 * Binds handlers to events.
1337 * @private
1338 */
1339 addEventListeners_: function() {
1340 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget();
1341 this.tracker_.add(
1342 nativeLayerEventTarget,
1343 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD,
1344 this.onDestinationsReload_.bind(this));
1345 },
1346
1347 /**
1348 * Creates a local PDF print destination. 1352 * Creates a local PDF print destination.
1349 * @private 1353 * @private
1350 */ 1354 */
1351 createLocalPdfPrintDestination_: function() { 1355 createLocalPdfPrintDestination_: function() {
1352 // TODO(alekseys): Create PDF printer in the native code and send its 1356 // TODO(alekseys): Create PDF printer in the native code and send its
1353 // capabilities back with other local printers. 1357 // capabilities back with other local printers.
1354 if (this.pdfPrinterEnabled_) { 1358 if (this.pdfPrinterEnabled_) {
1355 this.insertDestination_(new print_preview.Destination( 1359 this.insertDestination_(new print_preview.Destination(
1356 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, 1360 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
1357 print_preview.DestinationType.LOCAL, 1361 print_preview.DestinationType.LOCAL,
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 * name: string, 1546 * name: string,
1543 * hasLocalPrinting: boolean, 1547 * hasLocalPrinting: boolean,
1544 * isUnregistered: boolean, 1548 * isUnregistered: boolean,
1545 * cloudID: string}} printer Information about the added printer. 1549 * cloudID: string}} printer Information about the added printer.
1546 * @private 1550 * @private
1547 */ 1551 */
1548 onPrivetPrinterAdded_: function(printer) { 1552 onPrivetPrinterAdded_: function(printer) {
1549 if (printer.serviceName == this.waitForRegisterDestination_ && 1553 if (printer.serviceName == this.waitForRegisterDestination_ &&
1550 !printer.isUnregistered) { 1554 !printer.isUnregistered) {
1551 this.waitForRegisterDestination_ = null; 1555 this.waitForRegisterDestination_ = null;
1552 this.onDestinationsReload_(); 1556 this.onDestinationsReload();
1553 } else { 1557 } else {
1554 this.insertDestinations_( 1558 this.insertDestinations_(
1555 print_preview.PrivetDestinationParser.parse(printer)); 1559 print_preview.PrivetDestinationParser.parse(printer));
1556 } 1560 }
1557 }, 1561 },
1558 1562
1559 /** 1563 /**
1560 * Called when capabilities for a privet printer are set. 1564 * Called when capabilities for a privet printer are set.
1561 * @param {!print_preview.PrivetPrinterCapabilitiesResponse} printerInfo 1565 * @param {!print_preview.PrivetPrinterCapabilitiesResponse} printerInfo
1562 * Contains the privet printer's description and capabilities. 1566 * Contains the privet printer's description and capabilities.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 print_preview.DestinationOrigin.EXTENSION, printerId, 1614 print_preview.DestinationOrigin.EXTENSION, printerId,
1611 '' /* account */); 1615 '' /* account */);
1612 var destination = this.destinationMap_[destinationKey]; 1616 var destination = this.destinationMap_[destinationKey];
1613 if (!destination) 1617 if (!destination)
1614 return; 1618 return;
1615 destination.capabilities = capabilities; 1619 destination.capabilities = capabilities;
1616 this.updateDestination_(destination); 1620 this.updateDestination_(destination);
1617 }, 1621 },
1618 1622
1619 /** 1623 /**
1620 * Called from native layer after the user was requested to sign in, and did 1624 * Called from print preview after the user was requested to sign in, and
1621 * so successfully. 1625 * did so successfully.
1622 * @private
1623 */ 1626 */
1624 onDestinationsReload_: function() { 1627 onDestinationsReload: function() {
1625 this.reset_(); 1628 this.reset_();
1626 this.autoSelectMatchingDestination_ = 1629 this.autoSelectMatchingDestination_ =
1627 this.convertPreselectedToDestinationMatch_(); 1630 this.convertPreselectedToDestinationMatch_();
1628 this.createLocalPdfPrintDestination_(); 1631 this.createLocalPdfPrintDestination_();
1629 this.startLoadAllDestinations(); 1632 this.startLoadAllDestinations();
1630 }, 1633 },
1631 1634
1632 // TODO(vitalybuka): Remove three next functions replacing Destination.id 1635 // TODO(vitalybuka): Remove three next functions replacing Destination.id
1633 // and Destination.origin by complex ID. 1636 // and Destination.origin by complex ID.
1634 /** 1637 /**
(...skipping 15 matching lines...) Expand all
1650 */ 1653 */
1651 getKey_: function(destination) { 1654 getKey_: function(destination) {
1652 return this.getDestinationKey_( 1655 return this.getDestinationKey_(
1653 destination.origin, destination.id, destination.account); 1656 destination.origin, destination.id, destination.account);
1654 } 1657 }
1655 }; 1658 };
1656 1659
1657 // Export 1660 // Export
1658 return {DestinationStore: DestinationStore}; 1661 return {DestinationStore: DestinationStore};
1659 }); 1662 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698