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

Unified Diff: chrome/browser/resources/print_preview/cloud_print_interface.js

Issue 10827463: Fixes cloud-printer being treated as local-printer problem. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes JSDoc comment. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/print_preview/data/destination_store.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a0c875855bed41dca33f331f69cedb3f74f08c3d..8d9649fa40f159ef1b973d95e83927eb57dbd9fb 100644
--- a/chrome/browser/resources/print_preview/cloud_print_interface.js
+++ b/chrome/browser/resources/print_preview/cloud_print_interface.js
@@ -36,6 +36,7 @@ cr.define('cloudprint', function() {
CloudPrintInterface.EventType = {
ERROR: 'cloudprint.CloudPrintInterface.ERROR',
PRINTER_DONE: 'cloudprint.CloudPrintInterface.PRINTER_DONE',
+ PRINTER_FAILED: 'cloudprint.CloudPrintInterface.PRINTER_FAILED',
SEARCH_DONE: 'cloudprint.CloudPrintInterface.SEARCH_DONE',
SUBMIT_DONE: 'cloudprint.CloudPrintInterface.SUBMIT_DONE'
};
@@ -80,7 +81,8 @@ cr.define('cloudprint', function() {
}
params['connection_status'] = 'ALL';
params['client'] = 'chrome';
- this.sendRequest_('GET', 'search', params, null, this.onSearchDone_);
+ this.sendRequest_(
+ 'GET', 'search', params, null, this.onSearchDone_.bind(this));
},
/**
@@ -88,7 +90,8 @@ cr.define('cloudprint', function() {
* @param {string} body Body of the HTTP post request to send.
*/
submit: function(body) {
- this.sendRequest_('POST', 'submit', null, body, this.onSubmitDone_);
+ this.sendRequest_(
+ 'POST', 'submit', null, body, this.onSubmitDone_.bind(this));
},
/**
@@ -97,7 +100,10 @@ cr.define('cloudprint', function() {
*/
printer: function(printerId) {
var params = {'printerid': printerId};
- this.sendRequest_('GET', 'printer', params, null, this.onPrinterDone_);
+ this.sendRequest_(
+ 'GET', 'printer', params, null,
+ this.onPrinterDone_.bind(this),
+ this.onPrinterFailed_.bind(this, printerId));
},
/**
@@ -190,8 +196,11 @@ cr.define('cloudprint', function() {
* @param {string} body HTTP multi-part encoded body.
* @param {function(Object)} successCallback Callback to invoke when request
* completes successfully.
+ * @param {function(Object)=} opt_failureCallback Callback to call if the
+ * request failed.
*/
- sendRequest_: function(method, action, params, body, successCallback) {
+ sendRequest_: function(method, action, params, body, successCallback,
+ opt_failureCallback) {
if (!this.xsrfToken_) {
// TODO(rltoscano): Should throw an error if not a read-only action or
// issue an xsrf token request.
@@ -214,7 +223,7 @@ cr.define('cloudprint', function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = this.onReadyStateChange_.bind(
- this, xhr, successCallback.bind(this));
+ this, xhr, successCallback, opt_failureCallback);
xhr.open(method, url, true);
xhr.withCredentials = true;
for (var header in headers) {
@@ -240,15 +249,19 @@ cr.define('cloudprint', function() {
* @param {XMLHttpRequest} xhr XML http request that changed.
* @param {function(Object)} successCallback Callback to call if the request
* was successful.
+ * @param {function(Object)=} opt_failureCallback Callback to call if the
+ * request failed.
* @private
*/
- onReadyStateChange_: function(xhr, successCallback) {
+ onReadyStateChange_: function(xhr, successCallback, opt_failureCallback) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var result = JSON.parse(xhr.responseText);
if (result['success']) {
this.xsrfToken_ = result['xsrf_token'];
successCallback(result);
+ } else if (opt_failureCallback) {
+ opt_failureCallback(result);
} else {
this.dispatchErrorEvent_(result['message']);
}
@@ -318,6 +331,20 @@ cr.define('cloudprint', function() {
},
/**
+ * Called when the printer request fails.
+ * @param {string} ID of the destination that failed to be looked up.
+ * @param {object} Contains the JSON response.
+ * @private
+ */
+ onPrinterFailed_: function(destinationId, result) {
+ var printerFailedEvent = new cr.Event(
+ CloudPrintInterface.EventType.PRINTER_FAILED);
+ printerFailedEvent.destinationId = destinationId;
+ printerFailedEvent.errorCode = result['errorCode'];
+ this.dispatchEvent(printerFailedEvent);
+ },
+
+ /**
* Called when the update printer TOS acceptance request completes
* successfully.
* @param {Object} result JSON response.
« no previous file with comments | « no previous file | chrome/browser/resources/print_preview/data/destination_store.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698