| Index: chrome/browser/resources/print_preview/cloud_print_interface.js
|
| diff --git a/chrome/browser/resources/print_preview/cloud_print_interface.js b/chrome/browser/resources/print_preview/cloud_print_interface.js
|
| index e62257b767b897fe663d0de2e519ed849ebc95ff..ac7bf5700b79fa6db7d508d15bfed07e2f5eb36d 100644
|
| --- a/chrome/browser/resources/print_preview/cloud_print_interface.js
|
| +++ b/chrome/browser/resources/print_preview/cloud_print_interface.js
|
| @@ -94,8 +94,13 @@ cr.define('cloudprint', function() {
|
| * @enum {string}
|
| */
|
| CloudPrintInterface.EventType = {
|
| + INVITES_DONE: 'cloudprint.CloudPrintInterface.INVITES_DONE',
|
| + INVITES_FAILED: 'cloudprint.CloudPrintInterface.INVITES_FAILED',
|
| PRINTER_DONE: 'cloudprint.CloudPrintInterface.PRINTER_DONE',
|
| PRINTER_FAILED: 'cloudprint.CloudPrintInterface.PRINTER_FAILED',
|
| + PROCESS_INVITE_DONE: 'cloudprint.CloudPrintInterface.PROCESS_INVITE_DONE',
|
| + PROCESS_INVITE_FAILED:
|
| + 'cloudprint.CloudPrintInterface.PROCESS_INVITE_FAILED',
|
| SEARCH_DONE: 'cloudprint.CloudPrintInterface.SEARCH_DONE',
|
| SEARCH_FAILED: 'cloudprint.CloudPrintInterface.SEARCH_FAILED',
|
| SUBMIT_DONE: 'cloudprint.CloudPrintInterface.SUBMIT_DONE',
|
| @@ -234,6 +239,44 @@ cr.define('cloudprint', function() {
|
| },
|
|
|
| /**
|
| + * Sends Google Cloud Print printer sharing invitations API requests.
|
| + * @param {string} account Account the request is sent for.
|
| + */
|
| + invites: function(account) {
|
| + var params = [
|
| + new HttpParam('client', 'chrome'),
|
| + ];
|
| + this.sendOrQueueRequest_(this.buildRequest_(
|
| + 'GET',
|
| + 'invites',
|
| + params,
|
| + print_preview.Destination.Origin.COOKIES,
|
| + account,
|
| + this.onInvitesDone_.bind(this)));
|
| + },
|
| +
|
| + /**
|
| + * Accepts or rejects printer sharing invitation.
|
| + * @param {!print_preview.Invitation} invitation Invitation to process.
|
| + * @param {boolean} accept Whether to accept this invitation.
|
| + */
|
| + processInvite: function(invitation, accept) {
|
| + var params = [
|
| + new HttpParam('printerid', invitation.destination.id),
|
| + new HttpParam('email', invitation.scopeId),
|
| + new HttpParam('accept', accept),
|
| + new HttpParam('use_cdd', true),
|
| + ];
|
| + this.sendOrQueueRequest_(this.buildRequest_(
|
| + 'POST',
|
| + 'processinvite',
|
| + params,
|
| + invitation.destination.origin,
|
| + invitation.destination.account,
|
| + this.onProcessInviteDone_.bind(this, invitation, accept)));
|
| + },
|
| +
|
| + /**
|
| * Sends a Google Cloud Print submit API request.
|
| * @param {!print_preview.Destination} destination Cloud destination to
|
| * print to.
|
| @@ -575,6 +618,73 @@ cr.define('cloudprint', function() {
|
| },
|
|
|
| /**
|
| + * Called when invitations search request completes.
|
| + * @param {!CloudPrintRequest} request Request that has been completed.
|
| + * @private
|
| + */
|
| + onInvitesDone_: function(request) {
|
| + var event = null;
|
| + var activeUser =
|
| + (request.result &&
|
| + request.result['request'] &&
|
| + request.result['request']['user']) || '';
|
| + if (request.xhr.status == 200 && request.result['success']) {
|
| + // Extract invitations.
|
| + var invitationListJson = request.result['invites'] || [];
|
| + var invitationList = [];
|
| + invitationListJson.forEach(function(invitationJson) {
|
| + try {
|
| + invitationList.push(cloudprint.InvitationParser.parse(
|
| + invitationJson, activeUser));
|
| + } catch (e) {
|
| + console.error('Unable to parse invitation: ' + e);
|
| + }
|
| + });
|
| + // Dispatch INVITES_DONE event.
|
| + event = new Event(CloudPrintInterface.EventType.INVITES_DONE);
|
| + event.invitations = invitationList;
|
| + } else {
|
| + event = this.createErrorEvent_(
|
| + CloudPrintInterface.EventType.INVITES_FAILED, request);
|
| + }
|
| + event.user = activeUser;
|
| + this.dispatchEvent(event);
|
| + },
|
| +
|
| + /**
|
| + * Called when invitation processing request completes.
|
| + * @param {!print_preview.Invitation} invitation Processed invitation.
|
| + * @param {boolean} accept Whether this invitation was accepted or rejected.
|
| + * @param {!CloudPrintRequest} request Request that has been completed.
|
| + * @private
|
| + */
|
| + onProcessInviteDone_: function(invitation, accept, request) {
|
| + var event = null;
|
| + var activeUser =
|
| + (request.result &&
|
| + request.result['request'] &&
|
| + request.result['request']['user']) || '';
|
| + if (request.xhr.status == 200 && request.result['success']) {
|
| + event = new Event(CloudPrintInterface.EventType.PROCESS_INVITE_DONE);
|
| + if (accept) {
|
| + try {
|
| + event.printer = cloudprint.CloudDestinationParser.parse(
|
| + request.result['printer'], request.origin, activeUser);
|
| + } catch (e) {
|
| + console.error('Failed to parse cloud print destination: ' + e);
|
| + }
|
| + }
|
| + } else {
|
| + event = this.createErrorEvent_(
|
| + CloudPrintInterface.EventType.PROCESS_INVITE_FAILED, request);
|
| + }
|
| + event.invitation = invitation;
|
| + event.accept = accept;
|
| + event.user = activeUser;
|
| + this.dispatchEvent(event);
|
| + },
|
| +
|
| + /**
|
| * Called when the submit request completes.
|
| * @param {!CloudPrintRequest} request Request that has been completed.
|
| * @private
|
|
|