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

Side by Side Diff: chrome/browser/resources/print_preview/native_layer.js

Issue 2881213003: Print Preview: Use cr.sendWithPromise for getInitialSettings (Closed)
Patch Set: Revert extra change from rebase Created 3 years, 7 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.exportPath('print_preview'); 5 cr.exportPath('print_preview');
6 6
7 /** 7 /**
8 * @typedef {{selectSaveAsPdfDestination: boolean, 8 * @typedef {{selectSaveAsPdfDestination: boolean,
9 * layoutSettings.portrait: boolean, 9 * layoutSettings.portrait: boolean,
10 * pageRange: string, 10 * pageRange: string,
(...skipping 12 matching lines...) Expand all
23 * }} 23 * }}
24 */ 24 */
25 print_preview.PrinterSetupResponse; 25 print_preview.PrinterSetupResponse;
26 26
27 cr.define('print_preview', function() { 27 cr.define('print_preview', function() {
28 'use strict'; 28 'use strict';
29 29
30 /** 30 /**
31 * An interface to the native Chromium printing system layer. 31 * An interface to the native Chromium printing system layer.
32 * @constructor 32 * @constructor
33 * @extends {cr.EventTarget}
34 */ 33 */
35 function NativeLayer() { 34 function NativeLayer() {
36 cr.EventTarget.call(this);
37
38 // Bind global handlers 35 // Bind global handlers
39 global.setInitialSettings = this.onSetInitialSettings_.bind(this);
40 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); 36 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this);
41 global.setPrinters = this.onSetPrinters_.bind(this); 37 global.setPrinters = this.onSetPrinters_.bind(this);
42 global.updateWithPrinterCapabilities = 38 global.updateWithPrinterCapabilities =
43 this.onUpdateWithPrinterCapabilities_.bind(this); 39 this.onUpdateWithPrinterCapabilities_.bind(this);
44 global.failedToGetPrinterCapabilities = 40 global.failedToGetPrinterCapabilities =
45 this.onFailedToGetPrinterCapabilities_.bind(this); 41 this.onFailedToGetPrinterCapabilities_.bind(this);
46 global.failedToGetPrivetPrinterCapabilities = 42 global.failedToGetPrivetPrinterCapabilities =
47 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); 43 this.onFailedToGetPrivetPrinterCapabilities_.bind(this);
48 global.failedToGetExtensionPrinterCapabilities = 44 global.failedToGetExtensionPrinterCapabilities =
49 this.onFailedToGetExtensionPrinterCapabilities_.bind(this); 45 this.onFailedToGetExtensionPrinterCapabilities_.bind(this);
(...skipping 22 matching lines...) Expand all
72 global.onExtensionCapabilitiesSet = 68 global.onExtensionCapabilitiesSet =
73 this.onExtensionCapabilitiesSet_.bind(this); 69 this.onExtensionCapabilitiesSet_.bind(this);
74 global.onEnableManipulateSettingsForTest = 70 global.onEnableManipulateSettingsForTest =
75 this.onEnableManipulateSettingsForTest_.bind(this); 71 this.onEnableManipulateSettingsForTest_.bind(this);
76 global.printPresetOptionsFromDocument = 72 global.printPresetOptionsFromDocument =
77 this.onPrintPresetOptionsFromDocument_.bind(this); 73 this.onPrintPresetOptionsFromDocument_.bind(this);
78 global.onProvisionalPrinterResolved = 74 global.onProvisionalPrinterResolved =
79 this.onProvisionalDestinationResolved_.bind(this); 75 this.onProvisionalDestinationResolved_.bind(this);
80 global.failedToResolveProvisionalPrinter = 76 global.failedToResolveProvisionalPrinter =
81 this.failedToResolveProvisionalDestination_.bind(this); 77 this.failedToResolveProvisionalDestination_.bind(this);
78
79 /** @private {!cr.EventTarget} */
80 this.eventTarget_ = new cr.EventTarget();
82 } 81 }
83 82
84 /** 83 /**
85 * Event types dispatched from the Chromium native layer. 84 * Event types dispatched from the Chromium native layer.
86 * @enum {string} 85 * @enum {string}
87 * @const 86 * @const
88 */ 87 */
89 NativeLayer.EventType = { 88 NativeLayer.EventType = {
90 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', 89 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY',
91 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', 90 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET',
92 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', 91 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE',
93 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', 92 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD',
94 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', 93 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING',
95 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', 94 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL',
96 FILE_SELECTION_COMPLETE: 95 FILE_SELECTION_COMPLETE:
97 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', 96 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE',
98 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', 97 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL',
99 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET',
100 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', 98 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET',
101 MANIPULATE_SETTINGS_FOR_TEST: 99 MANIPULATE_SETTINGS_FOR_TEST:
102 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', 100 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST',
103 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', 101 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY',
104 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', 102 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY',
105 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', 103 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY',
106 PREVIEW_GENERATION_DONE: 104 PREVIEW_GENERATION_DONE:
107 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', 105 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE',
108 PREVIEW_GENERATION_FAIL: 106 PREVIEW_GENERATION_FAIL:
109 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', 107 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL',
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 142
145 /** 143 /**
146 * Version of the serialized state of the print preview. 144 * Version of the serialized state of the print preview.
147 * @type {number} 145 * @type {number}
148 * @const 146 * @const
149 * @private 147 * @private
150 */ 148 */
151 NativeLayer.SERIALIZED_STATE_VERSION_ = 1; 149 NativeLayer.SERIALIZED_STATE_VERSION_ = 1;
152 150
153 NativeLayer.prototype = { 151 NativeLayer.prototype = {
154 __proto__: cr.EventTarget.prototype, 152 /** @return {!cr.EventTarget} The event target for the native layer.*/
153 getEventTarget: function() {
154 return this.eventTarget_;
155 },
155 156
156 /** 157 /**
157 * Requests access token for cloud print requests. 158 * Requests access token for cloud print requests.
158 * @param {string} authType type of access token. 159 * @param {string} authType type of access token.
159 */ 160 */
160 startGetAccessToken: function(authType) { 161 startGetAccessToken: function(authType) {
161 chrome.send('getAccessToken', [authType]); 162 chrome.send('getAccessToken', [authType]);
162 }, 163 },
163 164
164 /** Gets the initial settings to initialize the print preview with. */ 165 /**
165 startGetInitialSettings: function() { 166 * Gets the initial settings to initialize the print preview with.
166 chrome.send('getInitialSettings'); 167 * @return {!Promise<!print_preview.NativeInitialSettings>}
168 */
169 getInitialSettings: function() {
170 return cr.sendWithPromise('getInitialSettings').then(
171 /**
172 * @param {!Object} initialSettings Object containing the raw
173 * Print Preview settings.
174 */
175 function(initialSettings) {
176 var numberFormatSymbols =
177 print_preview.MeasurementSystem.parseNumberFormat(
178 initialSettings['numberFormat']);
179 var unitType = print_preview.MeasurementSystemUnitType.IMPERIAL;
180 if (initialSettings['measurementSystem'] != null) {
181 unitType = initialSettings['measurementSystem'];
182 }
183 return new print_preview.NativeInitialSettings(
184 initialSettings['printAutomaticallyInKioskMode'] || false,
185 initialSettings['appKioskMode'] || false,
186 numberFormatSymbols[0] || ',',
187 numberFormatSymbols[1] || '.',
188 unitType,
189 initialSettings['previewModifiable'] || false,
190 initialSettings['initiatorTitle'] || '',
191 initialSettings['documentHasSelection'] || false,
192 initialSettings['shouldPrintSelectionOnly'] || false,
193 initialSettings['printerName'] || null,
194 initialSettings['appState'] || null,
195 initialSettings['defaultDestinationSelectionRules'] || null);
196 });
167 }, 197 },
168 198
169 /** 199 /**
170 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET 200 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET
171 * event will be dispatched in response. 201 * event will be dispatched in response.
172 */ 202 */
173 startGetLocalDestinations: function() { 203 startGetLocalDestinations: function() {
174 chrome.send('getPrinters'); 204 chrome.send('getPrinters');
175 }, 205 },
176 206
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 startManageCloudDestinations: function(user) { 508 startManageCloudDestinations: function(user) {
479 chrome.send('manageCloudPrinters', [user || '']); 509 chrome.send('manageCloudPrinters', [user || '']);
480 }, 510 },
481 511
482 /** Forces browser to open a new tab with the given URL address. */ 512 /** Forces browser to open a new tab with the given URL address. */
483 startForceOpenNewTab: function(url) { 513 startForceOpenNewTab: function(url) {
484 chrome.send('forceOpenNewTab', [url]); 514 chrome.send('forceOpenNewTab', [url]);
485 }, 515 },
486 516
487 /** 517 /**
488 * @param {!Object} initialSettings Object containing all initial settings.
489 */
490 onSetInitialSettings_: function(initialSettings) {
491 var numberFormatSymbols =
492 print_preview.MeasurementSystem.parseNumberFormat(
493 initialSettings['numberFormat']);
494 var unitType = print_preview.MeasurementSystemUnitType.IMPERIAL;
495 if (initialSettings['measurementSystem'] != null) {
496 unitType = initialSettings['measurementSystem'];
497 }
498
499 var nativeInitialSettings = new print_preview.NativeInitialSettings(
500 initialSettings['printAutomaticallyInKioskMode'] || false,
501 initialSettings['appKioskMode'] || false,
502 numberFormatSymbols[0] || ',',
503 numberFormatSymbols[1] || '.',
504 unitType,
505 initialSettings['previewModifiable'] || false,
506 initialSettings['initiatorTitle'] || '',
507 initialSettings['documentHasSelection'] || false,
508 initialSettings['shouldPrintSelectionOnly'] || false,
509 initialSettings['printerName'] || null,
510 initialSettings['appState'] || null,
511 initialSettings['defaultDestinationSelectionRules'] || null);
512
513 var initialSettingsSetEvent = new Event(
514 NativeLayer.EventType.INITIAL_SETTINGS_SET);
515 initialSettingsSetEvent.initialSettings = nativeInitialSettings;
516 this.dispatchEvent(initialSettingsSetEvent);
517 },
518
519 /**
520 * Turn on the integration of Cloud Print. 518 * Turn on the integration of Cloud Print.
521 * @param {{cloudPrintURL: string, appKioskMode: string}} settings 519 * @param {{cloudPrintURL: string, appKioskMode: string}} settings
522 * cloudPrintUrl: The URL to use for cloud print servers. 520 * cloudPrintUrl: The URL to use for cloud print servers.
523 * @private 521 * @private
524 */ 522 */
525 onSetUseCloudPrint_: function(settings) { 523 onSetUseCloudPrint_: function(settings) {
526 var cloudPrintEnableEvent = new Event( 524 var cloudPrintEnableEvent = new Event(
527 NativeLayer.EventType.CLOUD_PRINT_ENABLE); 525 NativeLayer.EventType.CLOUD_PRINT_ENABLE);
528 cloudPrintEnableEvent.baseCloudPrintUrl = settings['cloudPrintUrl'] || ''; 526 cloudPrintEnableEvent.baseCloudPrintUrl = settings['cloudPrintUrl'] || '';
529 cloudPrintEnableEvent.appKioskMode = settings['appKioskMode'] || false; 527 cloudPrintEnableEvent.appKioskMode = settings['appKioskMode'] || false;
530 this.dispatchEvent(cloudPrintEnableEvent); 528 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent);
531 }, 529 },
532 530
533 /** 531 /**
534 * Updates the print preview with local printers. 532 * Updates the print preview with local printers.
535 * Called from PrintPreviewHandler::SetupPrinterList(). 533 * Called from PrintPreviewHandler::SetupPrinterList().
536 * @param {Array} printers Array of printer info objects. 534 * @param {Array} printers Array of printer info objects.
537 * @private 535 * @private
538 */ 536 */
539 onSetPrinters_: function(printers) { 537 onSetPrinters_: function(printers) {
540 var localDestsSetEvent = new Event( 538 var localDestsSetEvent = new Event(
541 NativeLayer.EventType.LOCAL_DESTINATIONS_SET); 539 NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
542 localDestsSetEvent.destinationInfos = printers; 540 localDestsSetEvent.destinationInfos = printers;
543 this.dispatchEvent(localDestsSetEvent); 541 this.eventTarget_.dispatchEvent(localDestsSetEvent);
544 }, 542 },
545 543
546 /** 544 /**
547 * Called when native layer gets settings information for a requested local 545 * Called when native layer gets settings information for a requested local
548 * destination. 546 * destination.
549 * @param {Object} settingsInfo printer setting information. 547 * @param {Object} settingsInfo printer setting information.
550 * @private 548 * @private
551 */ 549 */
552 onUpdateWithPrinterCapabilities_: function(settingsInfo) { 550 onUpdateWithPrinterCapabilities_: function(settingsInfo) {
553 assert(settingsInfo.capabilities, 551 assert(settingsInfo.capabilities,
554 'Capabilities update without capabilites'); 552 'Capabilities update without capabilites');
555 var capsSetEvent = new Event(NativeLayer.EventType.CAPABILITIES_SET); 553 var capsSetEvent = new Event(NativeLayer.EventType.CAPABILITIES_SET);
556 capsSetEvent.settingsInfo = settingsInfo; 554 capsSetEvent.settingsInfo = settingsInfo;
557 this.dispatchEvent(capsSetEvent); 555 this.eventTarget_.dispatchEvent(capsSetEvent);
558 }, 556 },
559 557
560 /** 558 /**
561 * Called when native layer gets settings information for a requested local 559 * Called when native layer gets settings information for a requested local
562 * destination. 560 * destination.
563 * @param {string} destinationId Printer affected by error. 561 * @param {string} destinationId Printer affected by error.
564 * @private 562 * @private
565 */ 563 */
566 onFailedToGetPrinterCapabilities_: function(destinationId) { 564 onFailedToGetPrinterCapabilities_: function(destinationId) {
567 var getCapsFailEvent = new Event( 565 var getCapsFailEvent = new Event(
568 NativeLayer.EventType.GET_CAPABILITIES_FAIL); 566 NativeLayer.EventType.GET_CAPABILITIES_FAIL);
569 getCapsFailEvent.destinationId = destinationId; 567 getCapsFailEvent.destinationId = destinationId;
570 getCapsFailEvent.destinationOrigin = 568 getCapsFailEvent.destinationOrigin =
571 print_preview.DestinationOrigin.LOCAL; 569 print_preview.DestinationOrigin.LOCAL;
572 this.dispatchEvent(getCapsFailEvent); 570 this.eventTarget_.dispatchEvent(getCapsFailEvent);
573 }, 571 },
574 572
575 /** 573 /**
576 * Called when native layer gets settings information for a requested privet 574 * Called when native layer gets settings information for a requested privet
577 * destination. 575 * destination.
578 * @param {string} destinationId Printer affected by error. 576 * @param {string} destinationId Printer affected by error.
579 * @private 577 * @private
580 */ 578 */
581 onFailedToGetPrivetPrinterCapabilities_: function(destinationId) { 579 onFailedToGetPrivetPrinterCapabilities_: function(destinationId) {
582 var getCapsFailEvent = new Event( 580 var getCapsFailEvent = new Event(
583 NativeLayer.EventType.GET_CAPABILITIES_FAIL); 581 NativeLayer.EventType.GET_CAPABILITIES_FAIL);
584 getCapsFailEvent.destinationId = destinationId; 582 getCapsFailEvent.destinationId = destinationId;
585 getCapsFailEvent.destinationOrigin = 583 getCapsFailEvent.destinationOrigin =
586 print_preview.DestinationOrigin.PRIVET; 584 print_preview.DestinationOrigin.PRIVET;
587 this.dispatchEvent(getCapsFailEvent); 585 this.eventTarget_.dispatchEvent(getCapsFailEvent);
588 }, 586 },
589 587
590 /** 588 /**
591 * Called when native layer fails to get settings information for a 589 * Called when native layer fails to get settings information for a
592 * requested extension destination. 590 * requested extension destination.
593 * @param {string} destinationId Printer affected by error. 591 * @param {string} destinationId Printer affected by error.
594 * @private 592 * @private
595 */ 593 */
596 onFailedToGetExtensionPrinterCapabilities_: function(destinationId) { 594 onFailedToGetExtensionPrinterCapabilities_: function(destinationId) {
597 var getCapsFailEvent = new Event( 595 var getCapsFailEvent = new Event(
598 NativeLayer.EventType.GET_CAPABILITIES_FAIL); 596 NativeLayer.EventType.GET_CAPABILITIES_FAIL);
599 getCapsFailEvent.destinationId = destinationId; 597 getCapsFailEvent.destinationId = destinationId;
600 getCapsFailEvent.destinationOrigin = 598 getCapsFailEvent.destinationOrigin =
601 print_preview.DestinationOrigin.EXTENSION; 599 print_preview.DestinationOrigin.EXTENSION;
602 this.dispatchEvent(getCapsFailEvent); 600 this.eventTarget_.dispatchEvent(getCapsFailEvent);
603 }, 601 },
604 602
605 /** Reloads the printer list. */ 603 /** Reloads the printer list. */
606 onReloadPrintersList_: function() { 604 onReloadPrintersList_: function() {
607 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD); 605 cr.dispatchSimpleEvent(this.eventTarget_,
606 NativeLayer.EventType.DESTINATIONS_RELOAD);
608 }, 607 },
609 608
610 /** 609 /**
611 * Called from the C++ layer. 610 * Called from the C++ layer.
612 * Take the PDF data handed to us and submit it to the cloud, closing the 611 * Take the PDF data handed to us and submit it to the cloud, closing the
613 * print preview dialog once the upload is successful. 612 * print preview dialog once the upload is successful.
614 * @param {string} data Data to send as the print job. 613 * @param {string} data Data to send as the print job.
615 * @private 614 * @private
616 */ 615 */
617 onPrintToCloud_: function(data) { 616 onPrintToCloud_: function(data) {
618 var printToCloudEvent = new Event( 617 var printToCloudEvent = new Event(
619 NativeLayer.EventType.PRINT_TO_CLOUD); 618 NativeLayer.EventType.PRINT_TO_CLOUD);
620 printToCloudEvent.data = data; 619 printToCloudEvent.data = data;
621 this.dispatchEvent(printToCloudEvent); 620 this.eventTarget_.dispatchEvent(printToCloudEvent);
622 }, 621 },
623 622
624 /** 623 /**
625 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print 624 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
626 * preview dialog regarding the file selection cancel event. 625 * preview dialog regarding the file selection cancel event.
627 * @private 626 * @private
628 */ 627 */
629 onFileSelectionCancelled_: function() { 628 onFileSelectionCancelled_: function() {
630 cr.dispatchSimpleEvent(this, NativeLayer.EventType.FILE_SELECTION_CANCEL); 629 cr.dispatchSimpleEvent(
630 this.eventTarget_, NativeLayer.EventType.FILE_SELECTION_CANCEL);
631 }, 631 },
632 632
633 /** 633 /**
634 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print 634 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print
635 * preview dialog regarding the file selection completed event. 635 * preview dialog regarding the file selection completed event.
636 * @private 636 * @private
637 */ 637 */
638 onFileSelectionCompleted_: function() { 638 onFileSelectionCompleted_: function() {
639 // If the file selection is completed and the dialog is not already closed 639 // If the file selection is completed and the dialog is not already closed
640 // it means that a pending print to pdf request exists. 640 // it means that a pending print to pdf request exists.
641 cr.dispatchSimpleEvent( 641 cr.dispatchSimpleEvent(
642 this, NativeLayer.EventType.FILE_SELECTION_COMPLETE); 642 this.eventTarget_, NativeLayer.EventType.FILE_SELECTION_COMPLETE);
643 }, 643 },
644 644
645 /** 645 /**
646 * Display an error message when print preview fails. 646 * Display an error message when print preview fails.
647 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). 647 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed().
648 * @private 648 * @private
649 */ 649 */
650 onPrintPreviewFailed_: function() { 650 onPrintPreviewFailed_: function() {
651 cr.dispatchSimpleEvent( 651 cr.dispatchSimpleEvent(
652 this, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); 652 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL);
653 }, 653 },
654 654
655 /** 655 /**
656 * Display an error message when encountered invalid printer settings. 656 * Display an error message when encountered invalid printer settings.
657 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). 657 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings().
658 * @private 658 * @private
659 */ 659 */
660 onInvalidPrinterSettings_: function() { 660 onInvalidPrinterSettings_: function() {
661 cr.dispatchSimpleEvent(this, NativeLayer.EventType.SETTINGS_INVALID); 661 cr.dispatchSimpleEvent(this.eventTarget_,
662 NativeLayer.EventType.SETTINGS_INVALID);
662 }, 663 },
663 664
664 /** 665 /**
665 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, 666 * @param {{contentWidth: number, contentHeight: number, marginLeft: number,
666 * marginRight: number, marginTop: number, marginBottom: number, 667 * marginRight: number, marginTop: number, marginBottom: number,
667 * printableAreaX: number, printableAreaY: number, 668 * printableAreaX: number, printableAreaY: number,
668 * printableAreaWidth: number, printableAreaHeight: number}} 669 * printableAreaWidth: number, printableAreaHeight: number}}
669 * pageLayout Specifies default page layout details in points. 670 * pageLayout Specifies default page layout details in points.
670 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed 671 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed
671 * document has a custom page size style. 672 * document has a custom page size style.
672 * @private 673 * @private
673 */ 674 */
674 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { 675 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) {
675 var pageLayoutChangeEvent = new Event( 676 var pageLayoutChangeEvent = new Event(
676 NativeLayer.EventType.PAGE_LAYOUT_READY); 677 NativeLayer.EventType.PAGE_LAYOUT_READY);
677 pageLayoutChangeEvent.pageLayout = pageLayout; 678 pageLayoutChangeEvent.pageLayout = pageLayout;
678 pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle; 679 pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle;
679 this.dispatchEvent(pageLayoutChangeEvent); 680 this.eventTarget_.dispatchEvent(pageLayoutChangeEvent);
680 }, 681 },
681 682
682 /** 683 /**
683 * Update the page count and check the page range. 684 * Update the page count and check the page range.
684 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). 685 * Called from PrintPreviewUI::OnDidGetPreviewPageCount().
685 * @param {number} pageCount The number of pages. 686 * @param {number} pageCount The number of pages.
686 * @param {number} previewResponseId The preview request id that resulted in 687 * @param {number} previewResponseId The preview request id that resulted in
687 * this response. 688 * this response.
688 * @param {number} fitToPageScaling The scaling percentage required to fit 689 * @param {number} fitToPageScaling The scaling percentage required to fit
689 * the document to page, rounded to the nearest integer. 690 * the document to page, rounded to the nearest integer.
690 * @private 691 * @private
691 */ 692 */
692 onDidGetPreviewPageCount_: function(pageCount, previewResponseId, 693 onDidGetPreviewPageCount_: function(pageCount, previewResponseId,
693 fitToPageScaling) { 694 fitToPageScaling) {
694 var pageCountChangeEvent = new Event( 695 var pageCountChangeEvent = new Event(
695 NativeLayer.EventType.PAGE_COUNT_READY); 696 NativeLayer.EventType.PAGE_COUNT_READY);
696 pageCountChangeEvent.pageCount = pageCount; 697 pageCountChangeEvent.pageCount = pageCount;
697 pageCountChangeEvent.previewResponseId = previewResponseId; 698 pageCountChangeEvent.previewResponseId = previewResponseId;
698 pageCountChangeEvent.fitToPageScaling = fitToPageScaling; 699 pageCountChangeEvent.fitToPageScaling = fitToPageScaling;
699 this.dispatchEvent(pageCountChangeEvent); 700 this.eventTarget_.dispatchEvent(pageCountChangeEvent);
700 }, 701 },
701 702
702 /** 703 /**
703 * Notification that a print preview page has been rendered. 704 * Notification that a print preview page has been rendered.
704 * Check if the settings have changed and request a regeneration if needed. 705 * Check if the settings have changed and request a regeneration if needed.
705 * Called from PrintPreviewUI::OnDidPreviewPage(). 706 * Called from PrintPreviewUI::OnDidPreviewPage().
706 * @param {number} pageNumber The page number, 0-based. 707 * @param {number} pageNumber The page number, 0-based.
707 * @param {number} previewUid Preview unique identifier. 708 * @param {number} previewUid Preview unique identifier.
708 * @param {number} previewResponseId The preview request id that resulted in 709 * @param {number} previewResponseId The preview request id that resulted in
709 * this response. 710 * this response.
710 * @private 711 * @private
711 */ 712 */
712 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { 713 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) {
713 var pagePreviewGenEvent = new Event( 714 var pagePreviewGenEvent = new Event(
714 NativeLayer.EventType.PAGE_PREVIEW_READY); 715 NativeLayer.EventType.PAGE_PREVIEW_READY);
715 pagePreviewGenEvent.pageIndex = pageNumber; 716 pagePreviewGenEvent.pageIndex = pageNumber;
716 pagePreviewGenEvent.previewUid = previewUid; 717 pagePreviewGenEvent.previewUid = previewUid;
717 pagePreviewGenEvent.previewResponseId = previewResponseId; 718 pagePreviewGenEvent.previewResponseId = previewResponseId;
718 this.dispatchEvent(pagePreviewGenEvent); 719 this.eventTarget_.dispatchEvent(pagePreviewGenEvent);
719 }, 720 },
720 721
721 /** 722 /**
722 * Notification that access token is ready. 723 * Notification that access token is ready.
723 * @param {string} authType Type of access token. 724 * @param {string} authType Type of access token.
724 * @param {string} accessToken Access token. 725 * @param {string} accessToken Access token.
725 * @private 726 * @private
726 */ 727 */
727 onDidGetAccessToken_: function(authType, accessToken) { 728 onDidGetAccessToken_: function(authType, accessToken) {
728 var getAccessTokenEvent = new Event( 729 var getAccessTokenEvent = new Event(
729 NativeLayer.EventType.ACCESS_TOKEN_READY); 730 NativeLayer.EventType.ACCESS_TOKEN_READY);
730 getAccessTokenEvent.authType = authType; 731 getAccessTokenEvent.authType = authType;
731 getAccessTokenEvent.accessToken = accessToken; 732 getAccessTokenEvent.accessToken = accessToken;
732 this.dispatchEvent(getAccessTokenEvent); 733 this.eventTarget_.dispatchEvent(getAccessTokenEvent);
733 }, 734 },
734 735
735 /** 736 /**
736 * Update the print preview when new preview data is available. 737 * Update the print preview when new preview data is available.
737 * Create the PDF plugin as needed. 738 * Create the PDF plugin as needed.
738 * Called from PrintPreviewUI::PreviewDataIsAvailable(). 739 * Called from PrintPreviewUI::PreviewDataIsAvailable().
739 * @param {number} previewUid Preview unique identifier. 740 * @param {number} previewUid Preview unique identifier.
740 * @param {number} previewResponseId The preview request id that resulted in 741 * @param {number} previewResponseId The preview request id that resulted in
741 * this response. 742 * this response.
742 * @private 743 * @private
743 */ 744 */
744 onUpdatePrintPreview_: function(previewUid, previewResponseId) { 745 onUpdatePrintPreview_: function(previewUid, previewResponseId) {
745 var previewGenDoneEvent = new Event( 746 var previewGenDoneEvent = new Event(
746 NativeLayer.EventType.PREVIEW_GENERATION_DONE); 747 NativeLayer.EventType.PREVIEW_GENERATION_DONE);
747 previewGenDoneEvent.previewUid = previewUid; 748 previewGenDoneEvent.previewUid = previewUid;
748 previewGenDoneEvent.previewResponseId = previewResponseId; 749 previewGenDoneEvent.previewResponseId = previewResponseId;
749 this.dispatchEvent(previewGenDoneEvent); 750 this.eventTarget_.dispatchEvent(previewGenDoneEvent);
750 }, 751 },
751 752
752 /** 753 /**
753 * Updates print preset options from source PDF document. 754 * Updates print preset options from source PDF document.
754 * Called from PrintPreviewUI::OnSetOptionsFromDocument(). 755 * Called from PrintPreviewUI::OnSetOptionsFromDocument().
755 * @param {{disableScaling: boolean, copies: number, 756 * @param {{disableScaling: boolean, copies: number,
756 * duplex: number}} options Specifies 757 * duplex: number}} options Specifies
757 * printing options according to source document presets. 758 * printing options according to source document presets.
758 * @private 759 * @private
759 */ 760 */
760 onPrintPresetOptionsFromDocument_: function(options) { 761 onPrintPresetOptionsFromDocument_: function(options) {
761 var printPresetOptionsEvent = new Event( 762 var printPresetOptionsEvent = new Event(
762 NativeLayer.EventType.PRINT_PRESET_OPTIONS); 763 NativeLayer.EventType.PRINT_PRESET_OPTIONS);
763 printPresetOptionsEvent.optionsFromDocument = options; 764 printPresetOptionsEvent.optionsFromDocument = options;
764 this.dispatchEvent(printPresetOptionsEvent); 765 this.eventTarget_.dispatchEvent(printPresetOptionsEvent);
765 }, 766 },
766 767
767 /** 768 /**
768 * @param {{serviceName: string, name: string}} printer Specifies 769 * @param {{serviceName: string, name: string}} printer Specifies
769 * information about the printer that was added. 770 * information about the printer that was added.
770 * @private 771 * @private
771 */ 772 */
772 onPrivetPrinterChanged_: function(printer) { 773 onPrivetPrinterChanged_: function(printer) {
773 var privetPrinterChangedEvent = 774 var privetPrinterChangedEvent =
774 new Event(NativeLayer.EventType.PRIVET_PRINTER_CHANGED); 775 new Event(NativeLayer.EventType.PRIVET_PRINTER_CHANGED);
775 privetPrinterChangedEvent.printer = printer; 776 privetPrinterChangedEvent.printer = printer;
776 this.dispatchEvent(privetPrinterChangedEvent); 777 this.eventTarget_.dispatchEvent(privetPrinterChangedEvent);
777 }, 778 },
778 779
779 /** 780 /**
780 * @param {Object} printer Specifies information about the printer that was 781 * @param {Object} printer Specifies information about the printer that was
781 * added. 782 * added.
782 * @private 783 * @private
783 */ 784 */
784 onPrivetCapabilitiesSet_: function(printer, capabilities) { 785 onPrivetCapabilitiesSet_: function(printer, capabilities) {
785 var privetCapabilitiesSetEvent = 786 var privetCapabilitiesSetEvent =
786 new Event(NativeLayer.EventType.PRIVET_CAPABILITIES_SET); 787 new Event(NativeLayer.EventType.PRIVET_CAPABILITIES_SET);
787 privetCapabilitiesSetEvent.printer = printer; 788 privetCapabilitiesSetEvent.printer = printer;
788 privetCapabilitiesSetEvent.capabilities = capabilities; 789 privetCapabilitiesSetEvent.capabilities = capabilities;
789 this.dispatchEvent(privetCapabilitiesSetEvent); 790 this.eventTarget_.dispatchEvent(privetCapabilitiesSetEvent);
790 }, 791 },
791 792
792 /** 793 /**
793 * @param {string} http_error The HTTP response code or -1 if not an HTTP 794 * @param {string} http_error The HTTP response code or -1 if not an HTTP
794 * error. 795 * error.
795 * @private 796 * @private
796 */ 797 */
797 onPrivetPrintFailed_: function(http_error) { 798 onPrivetPrintFailed_: function(http_error) {
798 var privetPrintFailedEvent = 799 var privetPrintFailedEvent =
799 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); 800 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED);
800 privetPrintFailedEvent.httpError = http_error; 801 privetPrintFailedEvent.httpError = http_error;
801 this.dispatchEvent(privetPrintFailedEvent); 802 this.eventTarget_.dispatchEvent(privetPrintFailedEvent);
802 }, 803 },
803 804
804 /** 805 /**
805 * @param {Array<!{extensionId: string, 806 * @param {Array<!{extensionId: string,
806 * extensionName: string, 807 * extensionName: string,
807 * id: string, 808 * id: string,
808 * name: string, 809 * name: string,
809 * description: (string|undefined), 810 * description: (string|undefined),
810 * provisional: (boolean|undefined)}>} printers The list 811 * provisional: (boolean|undefined)}>} printers The list
811 * containing information about printers added by an extension. 812 * containing information about printers added by an extension.
812 * @param {boolean} done Whether this is the final list of extension 813 * @param {boolean} done Whether this is the final list of extension
813 * managed printers. 814 * managed printers.
814 */ 815 */
815 onExtensionPrintersAdded_: function(printers, done) { 816 onExtensionPrintersAdded_: function(printers, done) {
816 var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED); 817 var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED);
817 event.printers = printers; 818 event.printers = printers;
818 event.done = done; 819 event.done = done;
819 this.dispatchEvent(event); 820 this.eventTarget_.dispatchEvent(event);
820 }, 821 },
821 822
822 /** 823 /**
823 * Called when an extension responds to a request for an extension printer 824 * Called when an extension responds to a request for an extension printer
824 * capabilities. 825 * capabilities.
825 * @param {string} printerId The printer's ID. 826 * @param {string} printerId The printer's ID.
826 * @param {!Object} capabilities The reported printer capabilities. 827 * @param {!Object} capabilities The reported printer capabilities.
827 */ 828 */
828 onExtensionCapabilitiesSet_: function(printerId, 829 onExtensionCapabilitiesSet_: function(printerId,
829 capabilities) { 830 capabilities) {
830 var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET); 831 var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET);
831 event.printerId = printerId; 832 event.printerId = printerId;
832 event.capabilities = capabilities; 833 event.capabilities = capabilities;
833 this.dispatchEvent(event); 834 this.eventTarget_.dispatchEvent(event);
834 }, 835 },
835 836
836 /** 837 /**
837 * Called when Chrome reports that attempt to resolve a provisional 838 * Called when Chrome reports that attempt to resolve a provisional
838 * destination failed. 839 * destination failed.
839 * @param {string} destinationId The provisional destination ID. 840 * @param {string} destinationId The provisional destination ID.
840 * @private 841 * @private
841 */ 842 */
842 failedToResolveProvisionalDestination_: function(destinationId) { 843 failedToResolveProvisionalDestination_: function(destinationId) {
843 var evt = new Event( 844 var evt = new Event(
844 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); 845 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED);
845 evt.provisionalId = destinationId; 846 evt.provisionalId = destinationId;
846 evt.destination = null; 847 evt.destination = null;
847 this.dispatchEvent(evt); 848 this.eventTarget_.dispatchEvent(evt);
848 }, 849 },
849 850
850 /** 851 /**
851 * Called when Chrome reports that a provisional destination has been 852 * Called when Chrome reports that a provisional destination has been
852 * successfully resolved. 853 * successfully resolved.
853 * Currently used only for extension provided destinations. 854 * Currently used only for extension provided destinations.
854 * @param {string} provisionalDestinationId The provisional destination id. 855 * @param {string} provisionalDestinationId The provisional destination id.
855 * @param {!{extensionId: string, 856 * @param {!{extensionId: string,
856 * extensionName: string, 857 * extensionName: string,
857 * id: string, 858 * id: string,
858 * name: string, 859 * name: string,
859 * description: (string|undefined)}} destinationInfo The resolved 860 * description: (string|undefined)}} destinationInfo The resolved
860 * destination info. 861 * destination info.
861 * @private 862 * @private
862 */ 863 */
863 onProvisionalDestinationResolved_: function(provisionalDestinationId, 864 onProvisionalDestinationResolved_: function(provisionalDestinationId,
864 destinationInfo) { 865 destinationInfo) {
865 var evt = new Event( 866 var evt = new Event(
866 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); 867 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED);
867 evt.provisionalId = provisionalDestinationId; 868 evt.provisionalId = provisionalDestinationId;
868 evt.destination = destinationInfo; 869 evt.destination = destinationInfo;
869 this.dispatchEvent(evt); 870 this.eventTarget_.dispatchEvent(evt);
870 }, 871 },
871 872
872 /** 873 /**
873 * Allows for onManipulateSettings to be called 874 * Allows for onManipulateSettings to be called
874 * from the native layer. 875 * from the native layer.
875 * @private 876 * @private
876 */ 877 */
877 onEnableManipulateSettingsForTest_: function() { 878 onEnableManipulateSettingsForTest_: function() {
878 global.onManipulateSettingsForTest = 879 global.onManipulateSettingsForTest =
879 this.onManipulateSettingsForTest_.bind(this); 880 this.onManipulateSettingsForTest_.bind(this);
880 }, 881 },
881 882
882 /** 883 /**
883 * Dispatches an event to print_preview.js to change 884 * Dispatches an event to print_preview.js to change
884 * a particular setting for print preview. 885 * a particular setting for print preview.
885 * @param {!print_preview.PreviewSettings} settings Object containing the 886 * @param {!print_preview.PreviewSettings} settings Object containing the
886 * value to be changed and that value should be set to. 887 * value to be changed and that value should be set to.
887 * @private 888 * @private
888 */ 889 */
889 onManipulateSettingsForTest_: function(settings) { 890 onManipulateSettingsForTest_: function(settings) {
890 var manipulateSettingsEvent = 891 var manipulateSettingsEvent =
891 new Event(NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST); 892 new Event(NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST);
892 manipulateSettingsEvent.settings = settings; 893 manipulateSettingsEvent.settings = settings;
893 this.dispatchEvent(manipulateSettingsEvent); 894 this.eventTarget_.dispatchEvent(manipulateSettingsEvent);
894 }, 895 },
895 896
896 /** 897 /**
897 * Sends a message to the test, letting it know that an 898 * Sends a message to the test, letting it know that an
898 * option has been set to a particular value and that the change has 899 * option has been set to a particular value and that the change has
899 * finished modifying the preview area. 900 * finished modifying the preview area.
900 */ 901 */
901 previewReadyForTest: function() { 902 previewReadyForTest: function() {
902 if (global.onManipulateSettingsForTest) 903 if (global.onManipulateSettingsForTest)
903 chrome.send('UILoadedForTest'); 904 chrome.send('UILoadedForTest');
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 return this.serializedDefaultDestinationSelectionRulesStr_; 1095 return this.serializedDefaultDestinationSelectionRulesStr_;
1095 } 1096 }
1096 }; 1097 };
1097 1098
1098 // Export 1099 // Export
1099 return { 1100 return {
1100 NativeInitialSettings: NativeInitialSettings, 1101 NativeInitialSettings: NativeInitialSettings,
1101 NativeLayer: NativeLayer 1102 NativeLayer: NativeLayer
1102 }; 1103 };
1103 }); 1104 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698