onPrinterDone_(destinationId, request) {
      // Special handling of the first printer request. It does not matter at
      // this point, whether printer was found or not.
      if (request.origin == print_preview.DestinationOrigin.COOKIES &&
          request.result && request.account &&
          request.result['request']['user'] &&
          request.result['request']['users'] &&
          request.account != request.result['request']['user']) {
        this.setUsers_(request);
        // In case the user account is known, but not the primary one,
        // activate it.
        if (this.userSessionIndex_[request.account] > 0) {
          this.userInfo_.activeUser = request.account;
          // Repeat the request for the newly activated account.
          this.printer(
              request.result['request']['params']['printerid'], request.origin,
              request.account);
          // Stop processing this request, wait for the new response.
          return;
        }
      }
      // Process response.
      if (request.xhr.status == 200 && request.result['success']) {
        let activeUser = '';
        if (request.origin == print_preview.DestinationOrigin.COOKIES) {
          activeUser = request.result['request']['user'];
        }
        const printerJson = request.result['printers'][0];
        let printer;
        try {
          printer = cloudprint.parseCloudDestination(
              printerJson, request.origin, activeUser);
        } catch (err) {
          console.error(
              'Failed to parse cloud print destination: ' +
              JSON.stringify(printerJson));
          return;
        }
        const printerDoneEvent =
            new Event(CloudPrintInterfaceEventType.PRINTER_DONE);
        printerDoneEvent.printer = printer;
        this.dispatchEvent(printerDoneEvent);
      } else {
        const errorEvent = this.createErrorEvent_(
            CloudPrintInterfaceEventType.PRINTER_FAILED, request);
        errorEvent.destinationId = destinationId;
        errorEvent.destinationOrigin = request.origin;
        this.dispatchEvent(errorEvent);
      }
    }
/**
     * Called when the printer request completes.
     * @param {string} destinationId ID of the destination that was looked up.
     * @param {!cloudprint.CloudPrintRequest} request Request that has been
     *     completed.
     * @private
     */
Called when the printer request completes.
@param {string} destinationId ID of the destination that was looked up.
@param {!cloudprint.CloudPrintRequest} request Request that has been
completed.
@private
Called when the printer request completes . @param { string } destinationId ID of the destination that was looked up . @param { !cloudprint . CloudPrintRequest } request Request that has been completed . @private
onPrinterDone_(destinationId, request) {
      if (request.origin == print_preview.DestinationOrigin.COOKIES &&
          request.result && request.account &&
          request.result['request']['user'] &&
          request.result['request']['users'] &&
          request.account != request.result['request']['user']) {
        this.setUsers_(request);
        if (this.userSessionIndex_[request.account] > 0) {
          this.userInfo_.activeUser = request.account;
          this.printer(
              request.result['request']['params']['printerid'], request.origin,
              request.account);
          return;
        }
      }
      if (request.xhr.status == 200 && request.result['success']) {
        let activeUser = '';
        if (request.origin == print_preview.DestinationOrigin.COOKIES) {
          activeUser = request.result['request']['user'];
        }
        const printerJson = request.result['printers'][0];
        let printer;
        try {
          printer = cloudprint.parseCloudDestination(
              printerJson, request.origin, activeUser);
        } catch (err) {
          console.error(
              'Failed to parse cloud print destination: ' +
              JSON.stringify(printerJson));
          return;
        }
        const printerDoneEvent =
            new Event(CloudPrintInterfaceEventType.PRINTER_DONE);
        printerDoneEvent.printer = printer;
        this.dispatchEvent(printerDoneEvent);
      } else {
        const errorEvent = this.createErrorEvent_(
            CloudPrintInterfaceEventType.PRINTER_FAILED, request);
        errorEvent.destinationId = destinationId;
        errorEvent.destinationOrigin = request.origin;
        this.dispatchEvent(errorEvent);
      }
    }
onPrinterDone_ ( destinationId , request ) { if ( request . origin == print_preview . DestinationOrigin . COOKIES && request . result && request . account && request . result [ 'request' ] [ 'user' ] && request . result [ 'request' ] [ 'users' ] && request . account != request . result [ 'request' ] [ 'user' ] ) { this . setUsers_ ( request ) ; if ( this . userSessionIndex_ [ request . account ] > 0 ) { this . userInfo_ . activeUser = request . account ; this . printer ( request . result [ 'request' ] [ 'params' ] [ 'printerid' ] , request . origin , request . account ) ; return ; } } if ( request . xhr . status == 200 && request . result [ 'success' ] ) { let activeUser = '' ; if ( request . origin == print_preview . DestinationOrigin . COOKIES ) { activeUser = request . result [ 'request' ] [ 'user' ] ; } const printerJson = request . result [ 'printers' ] [ 0 ] ; let printer ; try { printer = cloudprint . parseCloudDestination ( printerJson , request . origin , activeUser ) ; } catch ( err ) { console . error ( 'Failed to parse cloud print destination: ' + JSON . stringify ( printerJson ) ) ; return ; } const printerDoneEvent = new Event ( CloudPrintInterfaceEventType . PRINTER_DONE ) ; printerDoneEvent . printer = printer ; this . dispatchEvent ( printerDoneEvent ) ; } else { const errorEvent = this . createErrorEvent_ ( CloudPrintInterfaceEventType . PRINTER_FAILED , request ) ; errorEvent . destinationId = destinationId ; errorEvent . destinationOrigin = request . origin ; this . dispatchEvent ( errorEvent ) ; } }
Called when the printer request completes.
Called when the printer request completes .
// Special handling of the first printer request. It does not matter at // this point, whether printer was found or not. // In case the user account is known, but not the primary one, // activate it. // Repeat the request for the newly activated account. // Stop processing this request, wait for the new response. // Process response.