buildRequest_(method, action, params, origin, account, callback) {
      let url = this.baseUrl_ + '/' + action + '?xsrf=';
      if (origin == print_preview.DestinationOrigin.COOKIES) {
        const xsrfToken = this.xsrfTokens_[account];
        if (!xsrfToken) {
          // TODO(rltoscano): Should throw an error if not a read-only action or
          // issue an xsrf token request.
        } else {
          url = url + xsrfToken;
        }
        if (account) {
          const index = this.userSessionIndex_[account] || 0;
          if (index > 0) {
            url += '&authuser=' + index;
          }
        }
      }
      let body = null;
      if (params) {
        if (method == 'GET') {
          url = params.reduce(function(partialUrl, param) {
            return partialUrl + '&' + param.name + '=' +
                encodeURIComponent(param.value);
          }, url);
        } else if (method == 'POST') {
          body = params.reduce(function(partialBody, param) {
            return partialBody + 'Content-Disposition: form-data; name=\"' +
                param.name + '\"\r\n\r\n' + param.value + '\r\n--' +
                MULTIPART_BOUNDARY_ + '\r\n';
          }, '--' + MULTIPART_BOUNDARY_ + '\r\n');
        }
      }

      const headers = {};
      headers['X-CloudPrint-Proxy'] = 'ChromePrintPreview';
      if (method == 'GET') {
        headers['Content-Type'] = URL_ENCODED_CONTENT_TYPE_;
      } else if (method == 'POST') {
        headers['Content-Type'] = MULTIPART_CONTENT_TYPE_;
      }

      const xhr = new XMLHttpRequest();
      xhr.open(method, url, true);
      xhr.withCredentials = (origin == print_preview.DestinationOrigin.COOKIES);
      for (const header in headers) {
        xhr.setRequestHeader(header, headers[header]);
      }

      return new cloudprint.CloudPrintRequest(
          xhr, body, origin, account, callback);
    }
/**
     * Builds request to the Google Cloud Print API.
     * @param {string} method HTTP method of the request.
     * @param {string} action Google Cloud Print action to perform.
     * @param {Array<!HttpParam>} params HTTP parameters to include in the
     *     request.
     * @param {!print_preview.DestinationOrigin} origin Origin for destination.
     * @param {?string} account Account the request is sent for. Can be
     *     {@code null} or empty string if the request is not cookie bound or
     *     is sent on behalf of the primary user.
     * @param {function(!cloudprint.CloudPrintRequest)} callback Callback to
     *     invoke when request completes.
     * @return {!cloudprint.CloudPrintRequest} Partially prepared request.
     * @private
     */
Builds request to the Google Cloud Print API.
@param {string} method HTTP method of the request.
@param {string} action Google Cloud Print action to perform.
@param {Array} params HTTP parameters to include in the
request.
Builds request to the Google Cloud Print API . @param { string } method HTTP method of the request . @param { string } action Google Cloud Print action to perform . @param { Array } params HTTP parameters to include in the request .
buildRequest_(method, action, params, origin, account, callback) {
      let url = this.baseUrl_ + '/' + action + '?xsrf=';
      if (origin == print_preview.DestinationOrigin.COOKIES) {
        const xsrfToken = this.xsrfTokens_[account];
        if (!xsrfToken) {
        } else {
          url = url + xsrfToken;
        }
        if (account) {
          const index = this.userSessionIndex_[account] || 0;
          if (index > 0) {
            url += '&authuser=' + index;
          }
        }
      }
      let body = null;
      if (params) {
        if (method == 'GET') {
          url = params.reduce(function(partialUrl, param) {
            return partialUrl + '&' + param.name + '=' +
                encodeURIComponent(param.value);
          }, url);
        } else if (method == 'POST') {
          body = params.reduce(function(partialBody, param) {
            return partialBody + 'Content-Disposition: form-data; name=\"' +
                param.name + '\"\r\n\r\n' + param.value + '\r\n--' +
                MULTIPART_BOUNDARY_ + '\r\n';
          }, '--' + MULTIPART_BOUNDARY_ + '\r\n');
        }
      }
      const headers = {};
      headers['X-CloudPrint-Proxy'] = 'ChromePrintPreview';
      if (method == 'GET') {
        headers['Content-Type'] = URL_ENCODED_CONTENT_TYPE_;
      } else if (method == 'POST') {
        headers['Content-Type'] = MULTIPART_CONTENT_TYPE_;
      }
      const xhr = new XMLHttpRequest();
      xhr.open(method, url, true);
      xhr.withCredentials = (origin == print_preview.DestinationOrigin.COOKIES);
      for (const header in headers) {
        xhr.setRequestHeader(header, headers[header]);
      }
      return new cloudprint.CloudPrintRequest(
          xhr, body, origin, account, callback);
    }
buildRequest_ ( method , action , params , origin , account , callback ) { let url = this . baseUrl_ + '/' + action + '?xsrf=' ; if ( origin == print_preview . DestinationOrigin . COOKIES ) { const xsrfToken = this . xsrfTokens_ [ account ] ; if ( ! xsrfToken ) { } else { url = url + xsrfToken ; } if ( account ) { const index = this . userSessionIndex_ [ account ] || 0 ; if ( index > 0 ) { url += '&authuser=' + index ; } } } let body = null ; if ( params ) { if ( method == 'GET' ) { url = params . reduce ( function ( partialUrl , param ) { return partialUrl + '&' + param . name + '=' + encodeURIComponent ( param . value ) ; } , url ) ; } else if ( method == 'POST' ) { body = params . reduce ( function ( partialBody , param ) { return partialBody + 'Content-Disposition: form-data; name=\"' + param . name + '\"\r\n\r\n' + param . value + '\r\n--' + MULTIPART_BOUNDARY_ + '\r\n' ; } , '--' + MULTIPART_BOUNDARY_ + '\r\n' ) ; } } const headers = { } ; headers [ 'X-CloudPrint-Proxy' ] = 'ChromePrintPreview' ; if ( method == 'GET' ) { headers [ 'Content-Type' ] = URL_ENCODED_CONTENT_TYPE_ ; } else if ( method == 'POST' ) { headers [ 'Content-Type' ] = MULTIPART_CONTENT_TYPE_ ; } const xhr = new XMLHttpRequest ( ) ; xhr . open ( method , url , true ) ; xhr . withCredentials = ( origin == print_preview . DestinationOrigin . COOKIES ) ; for ( const header in headers ) { xhr . setRequestHeader ( header , headers [ header ] ) ; } return new cloudprint . CloudPrintRequest ( xhr , body , origin , account , callback ) ; }
Builds request to the Google Cloud Print API.
Builds request to the Google Cloud Print API .
// TODO(rltoscano): Should throw an error if not a read-only action or // issue an xsrf token request.