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

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

Issue 10827463: Fixes cloud-printer being treated as local-printer problem. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes JSDoc comment. Created 8 years, 4 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 * An interface to the native Chromium printing system layer. 9 * An interface to the native Chromium printing system layer.
10 * @constructor 10 * @constructor
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 * @const 47 * @const
48 */ 48 */
49 NativeLayer.EventType = { 49 NativeLayer.EventType = {
50 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', 50 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET',
51 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', 51 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE',
52 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', 52 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD',
53 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', 53 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING',
54 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', 54 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL',
55 FILE_SELECTION_COMPLETE: 55 FILE_SELECTION_COMPLETE:
56 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', 56 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE',
57 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL',
57 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', 58 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET',
58 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', 59 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET',
59 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', 60 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY',
60 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', 61 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY',
61 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', 62 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY',
62 PREVIEW_GENERATION_DONE: 63 PREVIEW_GENERATION_DONE:
63 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', 64 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE',
64 PREVIEW_GENERATION_FAIL: 65 PREVIEW_GENERATION_FAIL:
65 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', 66 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL',
66 PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD', 67 PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD',
(...skipping 14 matching lines...) Expand all
81 /** 82 /**
82 * Enumeration of color modes used by Chromium. 83 * Enumeration of color modes used by Chromium.
83 * @enum {number} 84 * @enum {number}
84 * @private 85 * @private
85 */ 86 */
86 NativeLayer.ColorMode_ = { 87 NativeLayer.ColorMode_ = {
87 GRAY: 1, 88 GRAY: 1,
88 COLOR: 2 89 COLOR: 2
89 }; 90 };
90 91
92 /**
93 * Version of the serialized state of the print preview.
94 * @type {number}
95 * @const
96 * @private
97 */
98 NativeLayer.SERIALIZED_STATE_VERSION_ = 1;
99
91 NativeLayer.prototype = { 100 NativeLayer.prototype = {
92 __proto__: cr.EventTarget.prototype, 101 __proto__: cr.EventTarget.prototype,
93 102
94 /** Gets the initial settings to initialize the print preview with. */ 103 /** Gets the initial settings to initialize the print preview with. */
95 startGetInitialSettings: function() { 104 startGetInitialSettings: function() {
96 chrome.send('getInitialSettings'); 105 chrome.send('getInitialSettings');
97 }, 106 },
98 107
99 /** 108 /**
100 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET 109 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 }, 198 },
190 199
191 /** 200 /**
192 * Persists the selected destination and print ticket for the next print 201 * Persists the selected destination and print ticket for the next print
193 * session. 202 * session.
194 * @param {!print_preview.Destination} destination Destination to save. 203 * @param {!print_preview.Destination} destination Destination to save.
195 * @param {!print_preview.PrintTicketStore} printTicketStore Used for 204 * @param {!print_preview.PrintTicketStore} printTicketStore Used for
196 * generating the serialized print ticket to persist. 205 * generating the serialized print ticket to persist.
197 */ 206 */
198 startSaveDestinationAndTicket: function(destination, printTicketStore) { 207 startSaveDestinationAndTicket: function(destination, printTicketStore) {
199 chrome.send('saveLastPrinter', [destination.id, '' /*TODO(rltoscano)*/]); 208 // TODO(rltoscano): Implement a comprehensive serialization process.
209 var printPreviewSerializedState = {
210 'version': print_preview.NativeLayer.SERIALIZED_STATE_VERSION_,
211 'isLocalDestination':
212 destination.type == print_preview.Destination.Type.LOCAL
213 };
214 chrome.send(
215 'saveLastPrinter',
216 [destination.id, JSON.stringify(printPreviewSerializedState)]);
200 }, 217 },
201 218
202 /** 219 /**
203 * Requests that the document be printed. 220 * Requests that the document be printed.
204 * @param {!print_preview.Destination} destination Destination to print to. 221 * @param {!print_preview.Destination} destination Destination to print to.
205 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the 222 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
206 * state of the print ticket. 223 * state of the print ticket.
207 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface 224 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface
208 * to Google Cloud Print. 225 * to Google Cloud Print.
209 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the 226 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 initialSettings['marginRight'] || 0, 364 initialSettings['marginRight'] || 0,
348 initialSettings['marginBottom'] || 0, 365 initialSettings['marginBottom'] || 0,
349 initialSettings['marginLeft'] || 0); 366 initialSettings['marginLeft'] || 0);
350 } 367 }
351 368
352 var marginsType = null; 369 var marginsType = null;
353 if (initialSettings.hasOwnProperty('marginsType')) { 370 if (initialSettings.hasOwnProperty('marginsType')) {
354 marginsType = initialSettings['marginsType']; 371 marginsType = initialSettings['marginsType'];
355 } 372 }
356 373
374 // TODO(rltoscano): Replace this loading of serialized state with a
375 // comprehensive version.
376 var serializedPrintPreviewState =
377 JSON.parse(initialSettings['cloudPrintData'] || '{}');
378 var isLocalDestination = true;
379 if (serializedPrintPreviewState &&
380 serializedPrintPreviewState.version == 1) {
381 isLocalDestination = serializedPrintPreviewState.isLocalDestination;
382 }
383
357 var nativeInitialSettings = new print_preview.NativeInitialSettings( 384 var nativeInitialSettings = new print_preview.NativeInitialSettings(
358 initialSettings['printAutomaticallyInKioskMode'] || false, 385 initialSettings['printAutomaticallyInKioskMode'] || false,
359 numberFormatSymbols[0] || ',', 386 numberFormatSymbols[0] || ',',
360 numberFormatSymbols[1] || '.', 387 numberFormatSymbols[1] || '.',
361 unitType, 388 unitType,
362 initialSettings['previewModifiable'] || false, 389 initialSettings['previewModifiable'] || false,
363 initialSettings['initiatorTabTitle'] || '', 390 initialSettings['initiatorTabTitle'] || '',
364 marginsType, 391 marginsType,
365 customMargins, 392 customMargins,
366 initialSettings['duplex'] || false, 393 initialSettings['duplex'] || false,
367 initialSettings['headerFooterEnabled'] || false, 394 initialSettings['headerFooterEnabled'] || false,
368 initialSettings['printerName'] || null); 395 initialSettings['printerName'] || null,
396 isLocalDestination);
369 397
370 var initialSettingsSetEvent = new cr.Event( 398 var initialSettingsSetEvent = new cr.Event(
371 NativeLayer.EventType.INITIAL_SETTINGS_SET); 399 NativeLayer.EventType.INITIAL_SETTINGS_SET);
372 initialSettingsSetEvent.initialSettings = nativeInitialSettings; 400 initialSettingsSetEvent.initialSettings = nativeInitialSettings;
373 this.dispatchEvent(initialSettingsSetEvent); 401 this.dispatchEvent(initialSettingsSetEvent);
374 }, 402 },
375 403
376 /** 404 /**
377 * Turn on the integration of Cloud Print. 405 * Turn on the integration of Cloud Print.
378 * @param {string} cloudPrintURL The URL to use for cloud print servers. 406 * @param {string} cloudPrintURL The URL to use for cloud print servers.
(...skipping 27 matching lines...) Expand all
406 */ 434 */
407 onUpdateWithPrinterCapabilities_: function(settingsInfo) { 435 onUpdateWithPrinterCapabilities_: function(settingsInfo) {
408 var capsSetEvent = new cr.Event(NativeLayer.EventType.CAPABILITIES_SET); 436 var capsSetEvent = new cr.Event(NativeLayer.EventType.CAPABILITIES_SET);
409 capsSetEvent.settingsInfo = settingsInfo; 437 capsSetEvent.settingsInfo = settingsInfo;
410 this.dispatchEvent(capsSetEvent); 438 this.dispatchEvent(capsSetEvent);
411 }, 439 },
412 440
413 /** 441 /**
414 * Called when native layer gets settings information for a requested local 442 * Called when native layer gets settings information for a requested local
415 * destination. 443 * destination.
416 * @param {Object} printer_name printer affected by error. 444 * @param {string} printerId printer affected by error.
417 * @private 445 * @private
418 */ 446 */
419 onFailedToGetPrinterCapabilities_: function(printer_name) { 447 onFailedToGetPrinterCapabilities_: function(destinationId) {
420 // TODO(rltoscano): Switch to the next printer. 448 var getCapsFailEvent = new cr.Event(
421 console.log('onFailedToGetPrinterCapabilities: ' + printer_name); 449 NativeLayer.EventType.GET_CAPABILITIES_FAIL);
450 getCapsFailEvent.destinationId = destinationId;
451 this.dispatchEvent(getCapsFailEvent);
422 }, 452 },
423 453
424 /** Reloads the printer list. */ 454 /** Reloads the printer list. */
425 onReloadPrintersList_: function() { 455 onReloadPrintersList_: function() {
426 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD); 456 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD);
427 }, 457 },
428 458
429 /** 459 /**
430 * Called from the C++ layer. 460 * Called from the C++ layer.
431 * Take the PDF data handed to us and submit it to the cloud, closing the 461 * Take the PDF data handed to us and submit it to the cloud, closing the
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 * modifiable. 620 * modifiable.
591 * @param {string} documentTitle Title of the document. 621 * @param {string} documentTitle Title of the document.
592 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Initial 622 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Initial
593 * margins type. 623 * margins type.
594 * @param {print_preview.Margins} customMargins Initial custom margins. 624 * @param {print_preview.Margins} customMargins Initial custom margins.
595 * @param {boolean} isDuplexEnabled Whether duplexing is initially enabled. 625 * @param {boolean} isDuplexEnabled Whether duplexing is initially enabled.
596 * @param {boolean} isHeaderFooterEnabled Whether the header-footer is 626 * @param {boolean} isHeaderFooterEnabled Whether the header-footer is
597 * initially enabled. 627 * initially enabled.
598 * @param {?string} initialDestinationId ID of the destination to initially 628 * @param {?string} initialDestinationId ID of the destination to initially
599 * select. 629 * select.
630 * @param {boolean} isLocalDestination Whether the initial destination is
631 * local.
600 * @constructor 632 * @constructor
601 */ 633 */
602 function NativeInitialSettings( 634 function NativeInitialSettings(
603 isInKioskAutoPrintMode, 635 isInKioskAutoPrintMode,
604 thousandsDelimeter, 636 thousandsDelimeter,
605 decimalDelimeter, 637 decimalDelimeter,
606 unitType, 638 unitType,
607 isDocumentModifiable, 639 isDocumentModifiable,
608 documentTitle, 640 documentTitle,
609 marginsType, 641 marginsType,
610 customMargins, 642 customMargins,
611 isDuplexEnabled, 643 isDuplexEnabled,
612 isHeaderFooterEnabled, 644 isHeaderFooterEnabled,
613 initialDestinationId) { 645 initialDestinationId,
646 isLocalDestination) {
614 647
615 /** 648 /**
616 * Whether the print preview should be in auto-print mode. 649 * Whether the print preview should be in auto-print mode.
617 * @type {boolean} 650 * @type {boolean}
618 * @private 651 * @private
619 */ 652 */
620 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode; 653 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode;
621 654
622 /** 655 /**
623 * Character delimeter of thousands digits. 656 * Character delimeter of thousands digits.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 * @private 714 * @private
682 */ 715 */
683 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; 716 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled;
684 717
685 /** 718 /**
686 * ID of the initially selected destination. 719 * ID of the initially selected destination.
687 * @type {?string} 720 * @type {?string}
688 * @private 721 * @private
689 */ 722 */
690 this.initialDestinationId_ = initialDestinationId; 723 this.initialDestinationId_ = initialDestinationId;
724
725 /**
726 * Whether the initial destination is local.
727 * @type {boolean}
728 * @private
729 */
730 this.isLocalDestination_ = isLocalDestination;
691 }; 731 };
692 732
693 NativeInitialSettings.prototype = { 733 NativeInitialSettings.prototype = {
694 /** 734 /**
695 * @return {boolean} Whether the print preview should be in auto-print mode. 735 * @return {boolean} Whether the print preview should be in auto-print mode.
696 */ 736 */
697 get isInKioskAutoPrintMode() { 737 get isInKioskAutoPrintMode() {
698 return this.isInKioskAutoPrintMode_; 738 return this.isInKioskAutoPrintMode_;
699 }, 739 },
700 740
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 }, 785 },
746 786
747 /** @return {boolean} Whether the header-footer is initially enabled. */ 787 /** @return {boolean} Whether the header-footer is initially enabled. */
748 get isHeaderFooterEnabled() { 788 get isHeaderFooterEnabled() {
749 return this.isHeaderFooterEnabled_; 789 return this.isHeaderFooterEnabled_;
750 }, 790 },
751 791
752 /** @return {?string} ID of the initially selected destination. */ 792 /** @return {?string} ID of the initially selected destination. */
753 get initialDestinationId() { 793 get initialDestinationId() {
754 return this.initialDestinationId_; 794 return this.initialDestinationId_;
795 },
796
797 /** @return {boolean} Whether the initial destination is local. */
798 get isLocalDestination() {
799 return this.isLocalDestination_;
755 } 800 }
756 }; 801 };
757 802
758 // Export 803 // Export
759 return { 804 return {
760 NativeInitialSettings: NativeInitialSettings, 805 NativeInitialSettings: NativeInitialSettings,
761 NativeLayer: NativeLayer 806 NativeLayer: NativeLayer
762 }; 807 };
763 }); 808 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698