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

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

Issue 606213002: Compile print_preview, part 6: reduce down to 48 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@J_print_preview_5
Patch Set: vitalybuka@'s review Created 6 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/resources/print_preview/data/app_state.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('cloudprint', function() { 5 cr.define('cloudprint', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * API to the Google Cloud Print service. 9 * API to the Google Cloud Print service.
10 * @param {string} baseUrl Base part of the Google Cloud Print service URL 10 * @param {string} baseUrl Base part of the Google Cloud Print service URL
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 /** 179 /**
180 * @return {boolean} Whether a search for cloud destinations is in progress. 180 * @return {boolean} Whether a search for cloud destinations is in progress.
181 */ 181 */
182 get isCloudDestinationSearchInProgress() { 182 get isCloudDestinationSearchInProgress() {
183 return this.outstandingCloudSearchRequests_.length > 0; 183 return this.outstandingCloudSearchRequests_.length > 0;
184 }, 184 },
185 185
186 /** 186 /**
187 * Sends Google Cloud Print search API request. 187 * Sends Google Cloud Print search API request.
188 * @param {string=} opt_account Account the search is sent for. When 188 * @param {?string=} opt_account Account the search is sent for. When
189 * omitted, the search is done on behalf of the primary user. 189 * omitted or null, the search is done on behalf of the primary user.
190 * @param {print_preview.Destination.Origin=} opt_origin When specified, 190 * @param {print_preview.Destination.Origin=} opt_origin When specified,
191 * searches destinations for {@code opt_origin} only, otherwise starts 191 * searches destinations for {@code opt_origin} only, otherwise starts
192 * searches for all origins. 192 * searches for all origins.
193 */ 193 */
194 search: function(opt_account, opt_origin) { 194 search: function(opt_account, opt_origin) {
195 var account = opt_account || ''; 195 var account = opt_account || '';
196 var origins = 196 var origins =
197 opt_origin && [opt_origin] || CloudPrintInterface.CLOUD_ORIGINS_; 197 opt_origin && [opt_origin] || CloudPrintInterface.CLOUD_ORIGINS_;
198 if (this.isInAppKioskMode_) { 198 if (this.isInAppKioskMode_) {
199 origins = origins.filter(function(origin) { 199 origins = origins.filter(function(origin) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 /** 373 /**
374 * Builds request to the Google Cloud Print API. 374 * Builds request to the Google Cloud Print API.
375 * @param {string} method HTTP method of the request. 375 * @param {string} method HTTP method of the request.
376 * @param {string} action Google Cloud Print action to perform. 376 * @param {string} action Google Cloud Print action to perform.
377 * @param {Array.<!HttpParam>} params HTTP parameters to include in the 377 * @param {Array.<!HttpParam>} params HTTP parameters to include in the
378 * request. 378 * request.
379 * @param {!print_preview.Destination.Origin} origin Origin for destination. 379 * @param {!print_preview.Destination.Origin} origin Origin for destination.
380 * @param {?string} account Account the request is sent for. Can be 380 * @param {?string} account Account the request is sent for. Can be
381 * {@code null} or empty string if the request is not cookie bound or 381 * {@code null} or empty string if the request is not cookie bound or
382 * is sent on behalf of the primary user. 382 * is sent on behalf of the primary user.
383 * @param {function(number, Object, !print_preview.Destination.Origin)} 383 * @param {function(!cloudprint.CloudPrintRequest)}
384 * callback Callback to invoke when request completes. 384 * callback Callback to invoke when request completes.
385 * @return {!cloudprint.CloudPrintRequest} Partially prepared request. 385 * @return {!cloudprint.CloudPrintRequest} Partially prepared request.
386 * @private 386 * @private
387 */ 387 */
388 buildRequest_: function(method, action, params, origin, account, callback) { 388 buildRequest_: function(method, action, params, origin, account, callback) {
389 var url = this.baseUrl_ + '/' + action + '?xsrf='; 389 var url = this.baseUrl_ + '/' + action + '?xsrf=';
390 if (origin == print_preview.Destination.Origin.COOKIES) { 390 if (origin == print_preview.Destination.Origin.COOKIES) {
391 var xsrfToken = account ? this.xsrfTokens_[account] : undefined; 391 var xsrfToken = account ? this.xsrfTokens_[account] : undefined;
392 if (!xsrfToken) { 392 if (!xsrfToken) {
393 // TODO(rltoscano): Should throw an error if not a read-only action or 393 // TODO(rltoscano): Should throw an error if not a read-only action or
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 for (var header in headers) { 433 for (var header in headers) {
434 xhr.setRequestHeader(header, headers[header]); 434 xhr.setRequestHeader(header, headers[header]);
435 } 435 }
436 436
437 return new CloudPrintRequest(xhr, body, origin, account, callback); 437 return new CloudPrintRequest(xhr, body, origin, account, callback);
438 }, 438 },
439 439
440 /** 440 /**
441 * Sends a request to the Google Cloud Print API or queues if it needs to 441 * Sends a request to the Google Cloud Print API or queues if it needs to
442 * wait OAuth2 access token. 442 * wait OAuth2 access token.
443 * @param {!CloudPrintRequest} request Request to send or queue. 443 * @param {!cloudprint.CloudPrintRequest} request Request to send or queue.
444 * @private 444 * @private
445 */ 445 */
446 sendOrQueueRequest_: function(request) { 446 sendOrQueueRequest_: function(request) {
447 if (request.origin == print_preview.Destination.Origin.COOKIES) { 447 if (request.origin == print_preview.Destination.Origin.COOKIES) {
448 return this.sendRequest_(request); 448 return this.sendRequest_(request);
449 } else { 449 } else {
450 this.requestQueue_.push(request); 450 this.requestQueue_.push(request);
451 this.nativeLayer_.startGetAccessToken(request.origin); 451 this.nativeLayer_.startGetAccessToken(request.origin);
452 } 452 }
453 }, 453 },
454 454
455 /** 455 /**
456 * Sends a request to the Google Cloud Print API. 456 * Sends a request to the Google Cloud Print API.
457 * @param {!CloudPrintRequest} request Request to send. 457 * @param {!cloudprint.CloudPrintRequest} request Request to send.
458 * @private 458 * @private
459 */ 459 */
460 sendRequest_: function(request) { 460 sendRequest_: function(request) {
461 request.xhr.onreadystatechange = 461 request.xhr.onreadystatechange =
462 this.onReadyStateChange_.bind(this, request); 462 this.onReadyStateChange_.bind(this, request);
463 request.xhr.send(request.body); 463 request.xhr.send(request.body);
464 }, 464 },
465 465
466 /** 466 /**
467 * Creates a Google Cloud Print interface error that is ready to dispatch. 467 * Creates a Google Cloud Print interface error that is ready to dispatch.
468 * @param {!CloudPrintInterface.EventType} type Type of the error. 468 * @param {!cloudprint.CloudPrintInterface.EventType} type Type of the
469 * @param {!CloudPrintRequest} request Request that has been completed. 469 * error.
470 * @param {!cloudprint.CloudPrintRequest} request Request that has been
471 * completed.
470 * @return {!Event} Google Cloud Print interface error event. 472 * @return {!Event} Google Cloud Print interface error event.
471 * @private 473 * @private
472 */ 474 */
473 createErrorEvent_: function(type, request) { 475 createErrorEvent_: function(type, request) {
474 var errorEvent = new Event(type); 476 var errorEvent = new Event(type);
475 errorEvent.status = request.xhr.status; 477 errorEvent.status = request.xhr.status;
476 if (request.xhr.status == 200) { 478 if (request.xhr.status == 200) {
477 errorEvent.errorCode = request.result['errorCode']; 479 errorEvent.errorCode = request.result['errorCode'];
478 errorEvent.message = request.result['message']; 480 errorEvent.message = request.result['message'];
479 } else { 481 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 request.xhr.abort(); 541 request.xhr.abort();
540 request.callback(request); 542 request.callback(request);
541 } 543 }
542 return false; 544 return false;
543 }, this); 545 }, this);
544 }, 546 },
545 547
546 /** 548 /**
547 * Called when the ready-state of a XML http request changes. 549 * Called when the ready-state of a XML http request changes.
548 * Calls the successCallback with the result or dispatches an ERROR event. 550 * Calls the successCallback with the result or dispatches an ERROR event.
549 * @param {!CloudPrintRequest} request Request that was changed. 551 * @param {!cloudprint.CloudPrintRequest} request Request that was changed.
550 * @private 552 * @private
551 */ 553 */
552 onReadyStateChange_: function(request) { 554 onReadyStateChange_: function(request) {
553 if (request.xhr.readyState == 4) { 555 if (request.xhr.readyState == 4) {
554 if (request.xhr.status == 200) { 556 if (request.xhr.status == 200) {
555 request.result = JSON.parse(request.xhr.responseText); 557 request.result = JSON.parse(request.xhr.responseText);
556 if (request.origin == print_preview.Destination.Origin.COOKIES && 558 if (request.origin == print_preview.Destination.Origin.COOKIES &&
557 request.result['success']) { 559 request.result['success']) {
558 this.xsrfTokens_[request.result['request']['user']] = 560 this.xsrfTokens_[request.result['request']['user']] =
559 request.result['xsrf_token']; 561 request.result['xsrf_token'];
560 } 562 }
561 } 563 }
562 request.status = request.xhr.status; 564 request.status = request.xhr.status;
563 request.callback(request); 565 request.callback(request);
564 } 566 }
565 }, 567 },
566 568
567 /** 569 /**
568 * Called when the search request completes. 570 * Called when the search request completes.
569 * @param {boolean} isRecent Whether the search request was for recent 571 * @param {boolean} isRecent Whether the search request was for recent
570 * destinations. 572 * destinations.
571 * @param {!CloudPrintRequest} request Request that has been completed. 573 * @param {!cloudprint.CloudPrintRequest} request Request that has been
574 * completed.
572 * @private 575 * @private
573 */ 576 */
574 onSearchDone_: function(isRecent, request) { 577 onSearchDone_: function(isRecent, request) {
575 var lastRequestForThisOrigin = true; 578 var lastRequestForThisOrigin = true;
576 this.outstandingCloudSearchRequests_ = 579 this.outstandingCloudSearchRequests_ =
577 this.outstandingCloudSearchRequests_.filter(function(item) { 580 this.outstandingCloudSearchRequests_.filter(function(item) {
578 if (item != request && item.origin == request.origin) { 581 if (item != request && item.origin == request.origin) {
579 lastRequestForThisOrigin = false; 582 lastRequestForThisOrigin = false;
580 } 583 }
581 return item != request; 584 return item != request;
(...skipping 30 matching lines...) Expand all
612 CloudPrintInterface.EventType.SEARCH_FAILED, 615 CloudPrintInterface.EventType.SEARCH_FAILED,
613 request); 616 request);
614 } 617 }
615 event.user = activeUser; 618 event.user = activeUser;
616 event.searchDone = lastRequestForThisOrigin; 619 event.searchDone = lastRequestForThisOrigin;
617 this.dispatchEvent(event); 620 this.dispatchEvent(event);
618 }, 621 },
619 622
620 /** 623 /**
621 * Called when invitations search request completes. 624 * Called when invitations search request completes.
622 * @param {!CloudPrintRequest} request Request that has been completed. 625 * @param {!cloudprint.CloudPrintRequest} request Request that has been
626 * completed.
623 * @private 627 * @private
624 */ 628 */
625 onInvitesDone_: function(request) { 629 onInvitesDone_: function(request) {
626 var event = null; 630 var event = null;
627 var activeUser = 631 var activeUser =
628 (request.result && 632 (request.result &&
629 request.result['request'] && 633 request.result['request'] &&
630 request.result['request']['user']) || ''; 634 request.result['request']['user']) || '';
631 if (request.xhr.status == 200 && request.result['success']) { 635 if (request.xhr.status == 200 && request.result['success']) {
632 // Extract invitations. 636 // Extract invitations.
(...skipping 15 matching lines...) Expand all
648 CloudPrintInterface.EventType.INVITES_FAILED, request); 652 CloudPrintInterface.EventType.INVITES_FAILED, request);
649 } 653 }
650 event.user = activeUser; 654 event.user = activeUser;
651 this.dispatchEvent(event); 655 this.dispatchEvent(event);
652 }, 656 },
653 657
654 /** 658 /**
655 * Called when invitation processing request completes. 659 * Called when invitation processing request completes.
656 * @param {!print_preview.Invitation} invitation Processed invitation. 660 * @param {!print_preview.Invitation} invitation Processed invitation.
657 * @param {boolean} accept Whether this invitation was accepted or rejected. 661 * @param {boolean} accept Whether this invitation was accepted or rejected.
658 * @param {!CloudPrintRequest} request Request that has been completed. 662 * @param {!cloudprint.CloudPrintRequest} request Request that has been
663 * completed.
659 * @private 664 * @private
660 */ 665 */
661 onProcessInviteDone_: function(invitation, accept, request) { 666 onProcessInviteDone_: function(invitation, accept, request) {
662 var event = null; 667 var event = null;
663 var activeUser = 668 var activeUser =
664 (request.result && 669 (request.result &&
665 request.result['request'] && 670 request.result['request'] &&
666 request.result['request']['user']) || ''; 671 request.result['request']['user']) || '';
667 if (request.xhr.status == 200 && request.result['success']) { 672 if (request.xhr.status == 200 && request.result['success']) {
668 event = new Event(CloudPrintInterface.EventType.PROCESS_INVITE_DONE); 673 event = new Event(CloudPrintInterface.EventType.PROCESS_INVITE_DONE);
(...skipping 10 matching lines...) Expand all
679 CloudPrintInterface.EventType.PROCESS_INVITE_FAILED, request); 684 CloudPrintInterface.EventType.PROCESS_INVITE_FAILED, request);
680 } 685 }
681 event.invitation = invitation; 686 event.invitation = invitation;
682 event.accept = accept; 687 event.accept = accept;
683 event.user = activeUser; 688 event.user = activeUser;
684 this.dispatchEvent(event); 689 this.dispatchEvent(event);
685 }, 690 },
686 691
687 /** 692 /**
688 * Called when the submit request completes. 693 * Called when the submit request completes.
689 * @param {!CloudPrintRequest} request Request that has been completed. 694 * @param {!cloudprint.CloudPrintRequest} request Request that has been
695 * completed.
690 * @private 696 * @private
691 */ 697 */
692 onSubmitDone_: function(request) { 698 onSubmitDone_: function(request) {
693 if (request.xhr.status == 200 && request.result['success']) { 699 if (request.xhr.status == 200 && request.result['success']) {
694 var submitDoneEvent = new Event( 700 var submitDoneEvent = new Event(
695 CloudPrintInterface.EventType.SUBMIT_DONE); 701 CloudPrintInterface.EventType.SUBMIT_DONE);
696 submitDoneEvent.jobId = request.result['job']['id']; 702 submitDoneEvent.jobId = request.result['job']['id'];
697 this.dispatchEvent(submitDoneEvent); 703 this.dispatchEvent(submitDoneEvent);
698 } else { 704 } else {
699 var errorEvent = this.createErrorEvent_( 705 var errorEvent = this.createErrorEvent_(
700 CloudPrintInterface.EventType.SUBMIT_FAILED, request); 706 CloudPrintInterface.EventType.SUBMIT_FAILED, request);
701 this.dispatchEvent(errorEvent); 707 this.dispatchEvent(errorEvent);
702 } 708 }
703 }, 709 },
704 710
705 /** 711 /**
706 * Called when the printer request completes. 712 * Called when the printer request completes.
707 * @param {string} destinationId ID of the destination that was looked up. 713 * @param {string} destinationId ID of the destination that was looked up.
708 * @param {!CloudPrintRequest} request Request that has been completed. 714 * @param {!cloudprint.CloudPrintRequest} request Request that has been
715 * completed.
709 * @private 716 * @private
710 */ 717 */
711 onPrinterDone_: function(destinationId, request) { 718 onPrinterDone_: function(destinationId, request) {
712 // Special handling of the first printer request. It does not matter at 719 // Special handling of the first printer request. It does not matter at
713 // this point, whether printer was found or not. 720 // this point, whether printer was found or not.
714 if (request.origin == print_preview.Destination.Origin.COOKIES && 721 if (request.origin == print_preview.Destination.Origin.COOKIES &&
715 request.result && 722 request.result &&
716 request.account && 723 request.account &&
717 request.result['request']['user'] && 724 request.result['request']['user'] &&
718 request.result['request']['users'] && 725 request.result['request']['users'] &&
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 var errorEvent = this.createErrorEvent_( 762 var errorEvent = this.createErrorEvent_(
756 CloudPrintInterface.EventType.PRINTER_FAILED, request); 763 CloudPrintInterface.EventType.PRINTER_FAILED, request);
757 errorEvent.destinationId = destinationId; 764 errorEvent.destinationId = destinationId;
758 errorEvent.destinationOrigin = request.origin; 765 errorEvent.destinationOrigin = request.origin;
759 this.dispatchEvent(errorEvent); 766 this.dispatchEvent(errorEvent);
760 } 767 }
761 }, 768 },
762 769
763 /** 770 /**
764 * Called when the update printer TOS acceptance request completes. 771 * Called when the update printer TOS acceptance request completes.
765 * @param {!CloudPrintRequest} request Request that has been completed. 772 * @param {!cloudprint.CloudPrintRequest} request Request that has been
773 * completed.
766 * @private 774 * @private
767 */ 775 */
768 onUpdatePrinterTosAcceptanceDone_: function(request) { 776 onUpdatePrinterTosAcceptanceDone_: function(request) {
769 if (request.xhr.status == 200 && request.result['success']) { 777 if (request.xhr.status == 200 && request.result['success']) {
770 // Do nothing. 778 // Do nothing.
771 } else { 779 } else {
772 var errorEvent = this.createErrorEvent_( 780 var errorEvent = this.createErrorEvent_(
773 CloudPrintInterface.EventType.SUBMIT_FAILED, request); 781 CloudPrintInterface.EventType.SUBMIT_FAILED, request);
774 this.dispatchEvent(errorEvent); 782 this.dispatchEvent(errorEvent);
775 } 783 }
776 } 784 }
777 }; 785 };
778 786
779 /** 787 /**
780 * Data structure that holds data for Cloud Print requests. 788 * Data structure that holds data for Cloud Print requests.
781 * @param {!XMLHttpRequest} xhr Partially prepared http request. 789 * @param {!XMLHttpRequest} xhr Partially prepared http request.
782 * @param {string} body Data to send with POST requests. 790 * @param {string} body Data to send with POST requests.
783 * @param {!print_preview.Destination.Origin} origin Origin for destination. 791 * @param {!print_preview.Destination.Origin} origin Origin for destination.
784 * @param {?string} account Account the request is sent for. Can be 792 * @param {?string} account Account the request is sent for. Can be
785 * {@code null} or empty string if the request is not cookie bound or 793 * {@code null} or empty string if the request is not cookie bound or
786 * is sent on behalf of the primary user. 794 * is sent on behalf of the primary user.
787 * @param {function(!CloudPrintRequest)} callback Callback to invoke when 795 * @param {function(!cloudprint.CloudPrintRequest)} callback Callback to
788 * request completes. 796 * invoke when request completes.
789 * @constructor 797 * @constructor
790 */ 798 */
791 function CloudPrintRequest(xhr, body, origin, account, callback) { 799 function CloudPrintRequest(xhr, body, origin, account, callback) {
792 /** 800 /**
793 * Partially prepared http request. 801 * Partially prepared http request.
794 * @type {!XMLHttpRequest} 802 * @type {!XMLHttpRequest}
795 */ 803 */
796 this.xhr = xhr; 804 this.xhr = xhr;
797 805
798 /** 806 /**
(...skipping 23 matching lines...) Expand all
822 /** 830 /**
823 * Result for requests. 831 * Result for requests.
824 * @type {Object} JSON response. 832 * @type {Object} JSON response.
825 */ 833 */
826 this.result = null; 834 this.result = null;
827 }; 835 };
828 836
829 /** 837 /**
830 * Data structure that represents an HTTP parameter. 838 * Data structure that represents an HTTP parameter.
831 * @param {string} name Name of the parameter. 839 * @param {string} name Name of the parameter.
832 * @param {print_preview.ValueType} value Value of the parameter. 840 * @param {?} value Value of the parameter.
833 * @constructor 841 * @constructor
834 */ 842 */
835 function HttpParam(name, value) { 843 function HttpParam(name, value) {
836 /** 844 /**
837 * Name of the parameter. 845 * Name of the parameter.
838 * @type {string} 846 * @type {string}
839 */ 847 */
840 this.name = name; 848 this.name = name;
841 849
842 /** 850 /**
843 * Name of the value. 851 * Name of the value.
844 * @type {print_preview.ValueType} 852 * @type {?}
845 */ 853 */
846 this.value = value; 854 this.value = value;
847 }; 855 };
848 856
849 // Export 857 // Export
850 return { 858 return {
851 CloudPrintInterface: CloudPrintInterface, 859 CloudPrintInterface: CloudPrintInterface,
852 860
853 // CloudPrintRequest is exported to be used in type definitions inside this 861 // CloudPrintRequest is exported to be used in type definitions inside this
854 // file. It isn't actually exported to be used from other files. 862 // file. It isn't actually exported to be used from other files.
855 CloudPrintRequest: CloudPrintRequest 863 CloudPrintRequest: CloudPrintRequest
856 }; 864 };
857 }); 865 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/print_preview/data/app_state.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698