Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / print_preview / print_preview.js
index edf5c9f..ac3a0ab 100644 (file)
@@ -60,7 +60,7 @@ cr.define('print_preview', function() {
      * @private
      */
     this.destinationStore_ = new print_preview.DestinationStore(
-        this.nativeLayer_, this.appState_, this.metrics_);
+        this.nativeLayer_, this.userInfo_, this.appState_, this.metrics_);
 
     /**
      * Storage of the print ticket used to create the print job.
@@ -116,6 +116,15 @@ cr.define('print_preview', function() {
     this.addChild(this.copiesSettings_);
 
     /**
+     * Component that renders the media size settings.
+     * @type {!print_preview.MediaSizeSettings}
+     * @private
+     */
+    this.mediaSizeSettings_ =
+        new print_preview.MediaSizeSettings(this.printTicketStore_.mediaSize);
+    this.addChild(this.mediaSizeSettings_);
+
+    /**
      * Component that renders the layout settings.
      * @type {!print_preview.LayoutSettings}
      * @private
@@ -208,6 +217,7 @@ cr.define('print_preview', function() {
     INITIALIZING: 'initializing',
     READY: 'ready',
     OPENING_PDF_PREVIEW: 'opening-pdf-preview',
+    OPENING_CLOUD_PRINT_DIALOG: 'opening-cloud-print-dialog',
     OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
     PRINTING: 'printing',
     FILE_SELECTION: 'file-selection',
@@ -347,8 +357,12 @@ cr.define('print_preview', function() {
           this.onManageLocalDestinationsActivated_.bind(this));
       this.tracker.add(
           this.destinationSearch_,
+          print_preview.DestinationSearch.EventType.ADD_ACCOUNT,
+          this.onCloudPrintSignInActivated_.bind(this, true /*addAccount*/));
+      this.tracker.add(
+          this.destinationSearch_,
           print_preview.DestinationSearch.EventType.SIGN_IN,
-          this.onCloudPrintSignInActivated_.bind(this));
+          this.onCloudPrintSignInActivated_.bind(this, false /*addAccount*/));
       this.tracker.add(
           this.destinationSearch_,
           print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED,
@@ -377,6 +391,7 @@ cr.define('print_preview', function() {
       this.destinationSettings_.decorate($('destination-settings'));
       this.pageSettings_.decorate($('page-settings'));
       this.copiesSettings_.decorate($('copies-settings'));
+      this.mediaSizeSettings_.decorate($('media-size-settings'));
       this.layoutSettings_.decorate($('layout-settings'));
       this.colorSettings_.decorate($('color-settings'));
       this.marginSettings_.decorate($('margin-settings'));
@@ -400,6 +415,7 @@ cr.define('print_preview', function() {
       this.destinationSettings_.isEnabled = isEnabled;
       this.pageSettings_.isEnabled = isEnabled;
       this.copiesSettings_.isEnabled = isEnabled;
+      this.mediaSizeSettings_.isEnabled = isEnabled;
       this.layoutSettings_.isEnabled = isEnabled;
       this.colorSettings_.isEnabled = isEnabled;
       this.marginSettings_.isEnabled = isEnabled;
@@ -449,9 +465,10 @@ cr.define('print_preview', function() {
     printIfReady_: function() {
       var okToPrint =
           (this.uiState_ == PrintPreview.UiState_.PRINTING ||
-              this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW ||
-              this.uiState_ == PrintPreview.UiState_.FILE_SELECTION ||
-              this.isInKioskAutoPrintMode_) &&
+           this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW ||
+           this.uiState_ == PrintPreview.UiState_.FILE_SELECTION ||
+           this.uiState_ == PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG ||
+           this.isInKioskAutoPrintMode_) &&
           this.destinationStore_.selectedDestination &&
           this.destinationStore_.selectedDestination.capabilities;
       if (!okToPrint) {
@@ -462,12 +479,17 @@ cr.define('print_preview', function() {
       }
       assert(this.printTicketStore_.isTicketValid(),
           'Trying to print with invalid ticket');
-      this.nativeLayer_.startPrint(
-          this.destinationStore_.selectedDestination,
-          this.printTicketStore_,
-          this.cloudPrintInterface_,
-          this.documentInfo_,
-          this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW);
+      if (this.uiState_ == PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG) {
+        this.nativeLayer_.startShowCloudPrintDialog(
+            this.printTicketStore_.pageRange.getPageNumberSet().size);
+      } else {
+        this.nativeLayer_.startPrint(
+            this.destinationStore_.selectedDestination,
+            this.printTicketStore_,
+            this.cloudPrintInterface_,
+            this.documentInfo_,
+            this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW);
+      }
       return PrintPreview.PrintAttemptResult_.PRINTED;
     },
 
@@ -510,7 +532,9 @@ cr.define('print_preview', function() {
       this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode;
 
       // The following components must be initialized in this order.
-      this.appState_.init(settings.serializedAppStateStr);
+      this.appState_.init(
+          settings.serializedAppStateStr,
+          settings.systemDefaultDestinationId);
       this.documentInfo_.init(
           settings.isDocumentModifiable,
           settings.documentTitle,
@@ -520,7 +544,7 @@ cr.define('print_preview', function() {
           settings.decimalDelimeter,
           settings.unitType,
           settings.selectionOnly);
-      this.destinationStore_.init(settings.systemDefaultDestinationId);
+      this.destinationStore_.init();
       this.appState_.setInitialized();
 
       $('document-title').innerText = settings.documentTitle;
@@ -536,9 +560,10 @@ cr.define('print_preview', function() {
      * @private
      */
     onCloudPrintEnable_: function(event) {
-      this.cloudPrintInterface_ =
-          new cloudprint.CloudPrintInterface(event.baseCloudPrintUrl,
-                                             this.nativeLayer_);
+      this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface(
+          event.baseCloudPrintUrl,
+          this.nativeLayer_,
+          this.userInfo_);
       this.tracker.add(
           this.cloudPrintInterface_,
           cloudprint.CloudPrintInterface.EventType.SUBMIT_DONE,
@@ -561,7 +586,6 @@ cr.define('print_preview', function() {
               UPDATE_PRINTER_TOS_ACCEPTANCE_FAILED,
           this.onCloudPrintError_.bind(this));
 
-      this.userInfo_.setCloudPrintInterface(this.cloudPrintInterface_);
       this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_);
       if (this.destinationSearch_.getIsVisible()) {
         this.destinationStore_.startLoadCloudDestinations();
@@ -679,6 +703,9 @@ cr.define('print_preview', function() {
       this.printHeader_.isPrintButtonEnabled = false;
       if (this.uiState_ == PrintPreview.UiState_.PRINTING) {
         this.nativeLayer_.startCancelPendingPrint();
+      } else if (this.uiState_ ==
+            PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG) {
+        this.uiState_ = PrintPreview.UiState_.READY;
       }
     },
 
@@ -769,6 +796,7 @@ cr.define('print_preview', function() {
 
       if (e.keyCode == 13 /*enter*/ &&
           !this.destinationSearch_.getIsVisible() &&
+          this.destinationStore_.selectedDestination &&
           this.printTicketStore_.isTicketValid()) {
         assert(this.uiState_ == PrintPreview.UiState_.READY,
             'Trying to print when not in ready state: ' + this.uiState_);
@@ -831,10 +859,12 @@ cr.define('print_preview', function() {
     /**
      * Called when the user wants to sign in to Google Cloud Print. Calls the
      * corresponding native layer event.
+     * @param {boolean} addAccount Whether to open an 'add a new account' or
+     *     default sign in page.
      * @private
      */
-    onCloudPrintSignInActivated_: function() {
-      this.nativeLayer_.startCloudPrintSignIn();
+    onCloudPrintSignInActivated_: function(addAccount) {
+      this.nativeLayer_.startCloudPrintSignIn(addAccount);
     },
 
     /**
@@ -870,9 +900,8 @@ cr.define('print_preview', function() {
                  this.uiState_);
       setIsVisible($('cloud-print-dialog-throbber'), true);
       this.setIsEnabled_(false);
-      this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG;
-      this.nativeLayer_.startShowCloudPrintDialog(
-          this.printTicketStore_.pageRange.getPageNumberSet().size);
+      this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG;
+      this.printIfReady_();
     },
 
     /**
@@ -882,9 +911,10 @@ cr.define('print_preview', function() {
      */
     onDestinationSelect_: function() {
       var selectedDest = this.destinationStore_.selectedDestination;
-      setIsVisible($('cloud-print-dialog-link'),
-                   !cr.isChromeOS && !selectedDest.isLocal);
-      if (this.isInKioskAutoPrintMode_) {
+      setIsVisible(
+          $('cloud-print-dialog-link'),
+          selectedDest && !cr.isChromeOS && !selectedDest.isLocal);
+      if (selectedDest && this.isInKioskAutoPrintMode_) {
         this.onPrintButtonClick_();
       }
     },
@@ -898,7 +928,7 @@ cr.define('print_preview', function() {
     onDestinationSearchDone_: function() {
       var isPromoVisible = cr.isChromeOS &&
           this.cloudPrintInterface_ &&
-          this.userInfo_.getUserEmail() &&
+          this.userInfo_.activeUser &&
           !this.appState_.isGcpPromoDismissed &&
           !this.destinationStore_.isLocalDestinationsSearchInProgress &&
           !this.destinationStore_.isCloudDestinationsSearchInProgress &&
@@ -933,7 +963,7 @@ cr.define('print_preview', function() {
           print_preview.Metrics.GcpPromoBucket.CLICKED);
       this.appState_.persistIsGcpPromoDismissed(true);
       window.open(this.cloudPrintInterface_.baseUrl + '?user=' +
-                  this.userInfo_.getUserEmail() + '#printers');
+                  this.userInfo_.activeUser + '#printers');
       this.close_();
     }
   };
@@ -969,6 +999,7 @@ cr.define('print_preview', function() {
 <include src="data/ticket_items/copies.js"/>
 <include src="data/ticket_items/duplex.js"/>
 <include src="data/ticket_items/header_footer.js"/>
+<include src="data/ticket_items/media_size.js"/>
 <include src="data/ticket_items/landscape.js"/>
 <include src="data/ticket_items/margins_type.js"/>
 <include src="data/ticket_items/page_range.js"/>
@@ -985,6 +1016,7 @@ cr.define('print_preview', function() {
 
 <include src="settings/page_settings.js"/>
 <include src="settings/copies_settings.js"/>
+<include src="settings/media_size_settings.js"/>
 <include src="settings/layout_settings.js"/>
 <include src="settings/color_settings.js"/>
 <include src="settings/margin_settings.js"/>
@@ -993,6 +1025,7 @@ cr.define('print_preview', function() {
 
 <include src="previewarea/margin_control.js"/>
 <include src="previewarea/margin_control_container.js"/>
+<include src="../pdf/pdf_scripting_api.js" />
 <include src="previewarea/preview_area.js"/>
 <include src="preview_generator.js"/>