Chromium Code Reviews| 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 // TODO(rltoscano): Move data/* into print_preview.data namespace | 5 // TODO(rltoscano): Move data/* into print_preview.data namespace |
| 6 | 6 |
| 7 // <include src="component.js"> | 7 // <include src="component.js"> |
| 8 // <include src="print_preview_focus_manager.js"> | 8 // <include src="print_preview_focus_manager.js"> |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 | 324 |
| 325 PrintPreview.prototype = { | 325 PrintPreview.prototype = { |
| 326 __proto__: print_preview.Component.prototype, | 326 __proto__: print_preview.Component.prototype, |
| 327 | 327 |
| 328 /** Sets up the page and print preview by getting the printer list. */ | 328 /** Sets up the page and print preview by getting the printer list. */ |
| 329 initialize: function() { | 329 initialize: function() { |
| 330 this.decorate($('print-preview')); | 330 this.decorate($('print-preview')); |
| 331 if (!this.previewArea_.hasCompatiblePlugin) { | 331 if (!this.previewArea_.hasCompatiblePlugin) { |
| 332 this.setIsEnabled_(false); | 332 this.setIsEnabled_(false); |
| 333 } | 333 } |
| 334 this.nativeLayer_.startGetInitialSettings(); | 334 this.nativeLayer_.getInitialSettings().then( |
| 335 /** | |
| 336 * @param {!print_preview.NativeInitialSettings} settings | |
| 337 * The print preview initial settings. | |
| 338 */ | |
| 339 function(settings) { | |
| 340 assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, | |
| 341 'Updating initial settings when not in initializing ' + | |
| 342 'state: ' + this.uiState_); | |
| 343 this.uiState_ = PrintPreviewUiState_.READY; | |
| 344 this.onInitialSettingsSet_(settings); | |
| 345 }.bind(this), | |
| 346 /** | |
| 347 * Initial settings failed | |
| 348 */ | |
| 349 function() { | |
|
dpapad
2017/05/17 23:59:12
getInitialSettings() should never fail (see commen
rbpotter
2017/05/18 17:56:30
Done.
| |
| 350 console.warn('Failed to set initial settings for print preview'); | |
| 351 }.bind(this)); | |
| 335 print_preview.PrintPreviewFocusManager.getInstance().initialize(); | 352 print_preview.PrintPreviewFocusManager.getInstance().initialize(); |
| 336 cr.ui.FocusOutlineManager.forDocument(document); | 353 cr.ui.FocusOutlineManager.forDocument(document); |
| 337 }, | 354 }, |
| 338 | 355 |
| 339 /** @override */ | 356 /** @override */ |
| 340 enterDocument: function() { | 357 enterDocument: function() { |
| 341 // Native layer events. | 358 // Native layer events. |
| 359 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); | |
| 342 this.tracker.add( | 360 this.tracker.add( |
| 343 this.nativeLayer_, | 361 nativeLayerEventTarget, |
| 344 print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET, | |
| 345 this.onInitialSettingsSet_.bind(this)); | |
| 346 this.tracker.add( | |
| 347 this.nativeLayer_, | |
| 348 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, | 362 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, |
| 349 this.onCloudPrintEnable_.bind(this)); | 363 this.onCloudPrintEnable_.bind(this)); |
| 350 this.tracker.add( | 364 this.tracker.add( |
| 351 this.nativeLayer_, | 365 nativeLayerEventTarget, |
| 352 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, | 366 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, |
| 353 this.onPrintToCloud_.bind(this)); | 367 this.onPrintToCloud_.bind(this)); |
| 354 this.tracker.add( | 368 this.tracker.add( |
| 355 this.nativeLayer_, | 369 nativeLayerEventTarget, |
| 356 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, | 370 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, |
| 357 this.onFileSelectionCancel_.bind(this)); | 371 this.onFileSelectionCancel_.bind(this)); |
| 358 this.tracker.add( | 372 this.tracker.add( |
| 359 this.nativeLayer_, | 373 nativeLayerEventTarget, |
| 360 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, | 374 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, |
| 361 this.onFileSelectionComplete_.bind(this)); | 375 this.onFileSelectionComplete_.bind(this)); |
| 362 this.tracker.add( | 376 this.tracker.add( |
| 363 this.nativeLayer_, | 377 nativeLayerEventTarget, |
| 364 print_preview.NativeLayer.EventType.SETTINGS_INVALID, | 378 print_preview.NativeLayer.EventType.SETTINGS_INVALID, |
| 365 this.onSettingsInvalid_.bind(this)); | 379 this.onSettingsInvalid_.bind(this)); |
| 366 this.tracker.add( | 380 this.tracker.add( |
| 367 this.nativeLayer_, | 381 nativeLayerEventTarget, |
| 368 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, | 382 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, |
| 369 this.onPrintPresetOptionsFromDocument_.bind(this)); | 383 this.onPrintPresetOptionsFromDocument_.bind(this)); |
| 370 this.tracker.add( | 384 this.tracker.add( |
| 371 this.nativeLayer_, | 385 nativeLayerEventTarget, |
| 372 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, | 386 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, |
| 373 this.onPageCountReady_.bind(this)); | 387 this.onPageCountReady_.bind(this)); |
| 374 this.tracker.add( | 388 this.tracker.add( |
| 375 this.nativeLayer_, | 389 nativeLayerEventTarget, |
| 376 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, | 390 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, |
| 377 this.onPrivetPrintFailed_.bind(this)); | 391 this.onPrivetPrintFailed_.bind(this)); |
| 378 this.tracker.add( | 392 this.tracker.add( |
| 379 this.nativeLayer_, | 393 nativeLayerEventTarget, |
| 380 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, | 394 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, |
| 381 this.onManipulateSettingsForTest_.bind(this)); | 395 this.onManipulateSettingsForTest_.bind(this)); |
| 382 | 396 |
| 383 if ($('system-dialog-link')) { | 397 if ($('system-dialog-link')) { |
| 384 this.tracker.add( | 398 this.tracker.add( |
| 385 getRequiredElement('system-dialog-link'), | 399 getRequiredElement('system-dialog-link'), |
| 386 'click', | 400 'click', |
| 387 this.openSystemPrintDialog_.bind(this)); | 401 this.openSystemPrintDialog_.bind(this)); |
| 388 } | 402 } |
| 389 if ($('open-pdf-in-preview-link')) { | 403 if ($('open-pdf-in-preview-link')) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 setIsVisible(getRequiredElement('system-dialog-throbber'), true); | 645 setIsVisible(getRequiredElement('system-dialog-throbber'), true); |
| 632 this.setIsEnabled_(false); | 646 this.setIsEnabled_(false); |
| 633 this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG; | 647 this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG; |
| 634 this.nativeLayer_.startShowSystemDialog(); | 648 this.nativeLayer_.startShowSystemDialog(); |
| 635 }, | 649 }, |
| 636 | 650 |
| 637 /** | 651 /** |
| 638 * Called when the native layer has initial settings to set. Sets the | 652 * Called when the native layer has initial settings to set. Sets the |
| 639 * initial settings of the print preview and begins fetching print | 653 * initial settings of the print preview and begins fetching print |
| 640 * destinations. | 654 * destinations. |
| 641 * @param {Event} event Contains the initial print preview settings | 655 * @param {!print_preview.NativeInitialSettings} settings The initial print |
| 642 * persisted through the session. | 656 * preview settings persisted through the session. |
| 643 * @private | 657 * @private |
| 644 */ | 658 */ |
| 645 onInitialSettingsSet_: function(event) { | 659 onInitialSettingsSet_: function(settings) { |
| 646 assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, | |
| 647 'Updating initial settings when not in initializing state: ' + | |
| 648 this.uiState_); | |
| 649 this.uiState_ = PrintPreviewUiState_.READY; | |
| 650 | |
| 651 var settings = event.initialSettings; | |
| 652 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; | 660 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; |
| 653 this.isInAppKioskMode_ = settings.isInAppKioskMode; | 661 this.isInAppKioskMode_ = settings.isInAppKioskMode; |
| 654 | 662 |
| 655 // The following components must be initialized in this order. | 663 // The following components must be initialized in this order. |
| 656 this.appState_.init(settings.serializedAppStateStr); | 664 this.appState_.init(settings.serializedAppStateStr); |
| 657 this.documentInfo_.init( | 665 this.documentInfo_.init( |
| 658 settings.isDocumentModifiable, | 666 settings.isDocumentModifiable, |
| 659 settings.documentTitle, | 667 settings.documentTitle, |
| 660 settings.documentHasSelection); | 668 settings.documentHasSelection); |
| 661 this.printTicketStore_.init( | 669 this.printTicketStore_.init( |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1344 // <include src="previewarea/preview_area.js"> | 1352 // <include src="previewarea/preview_area.js"> |
| 1345 // <include src="preview_generator.js"> | 1353 // <include src="preview_generator.js"> |
| 1346 | 1354 |
| 1347 // <include src="search/destination_list.js"> | 1355 // <include src="search/destination_list.js"> |
| 1348 // <include src="search/cloud_destination_list.js"> | 1356 // <include src="search/cloud_destination_list.js"> |
| 1349 // <include src="search/recent_destination_list.js"> | 1357 // <include src="search/recent_destination_list.js"> |
| 1350 // <include src="search/destination_list_item.js"> | 1358 // <include src="search/destination_list_item.js"> |
| 1351 // <include src="search/destination_search.js"> | 1359 // <include src="search/destination_search.js"> |
| 1352 // <include src="search/provisional_destination_resolver.js"> | 1360 // <include src="search/provisional_destination_resolver.js"> |
| 1353 | 1361 |
| 1354 /** | |
| 1355 * Global instance of PrintPreview, used by browser tests. | |
| 1356 * @type {print_preview.PrintPreview} | |
| 1357 */ | |
| 1358 var printPreview; | |
| 1359 window.addEventListener('DOMContentLoaded', function() { | 1362 window.addEventListener('DOMContentLoaded', function() { |
| 1360 printPreview = new print_preview.PrintPreview(); | 1363 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
| 1361 printPreview.initialize(); | 1364 if (!previewWindow.isTest) { |
| 1365 var printPreview = new print_preview.PrintPreview(); | |
| 1366 printPreview.initialize(); | |
| 1367 } | |
| 1362 }); | 1368 }); |
| OLD | NEW |