Index: chrome/browser/resources/cryptotoken/textfetcher.js |
diff --git a/chrome/browser/resources/cryptotoken/textfetcher.js b/chrome/browser/resources/cryptotoken/textfetcher.js |
index e63a8413a88edb5eb7689977fe2d8c476d5b68d7..4135b0e12cb81599fbaa254f1ae7d648328784ef 100644 |
--- a/chrome/browser/resources/cryptotoken/textfetcher.js |
+++ b/chrome/browser/resources/cryptotoken/textfetcher.js |
@@ -17,10 +17,12 @@ function TextFetcher() {} |
/** |
* @param {string} url The URL to fetch. |
+ * @param {string?} opt_method The HTTP method to use (default GET) |
+ * @param {string?} opt_body The request body |
* @return {!Promise.<string>} A promise for the fetched text. In case of an |
* error, this promise is rejected with an HTTP status code. |
*/ |
-TextFetcher.prototype.fetch = function(url) {}; |
+TextFetcher.prototype.fetch = function(url, opt_method, opt_body) {}; |
/** |
* @constructor |
@@ -31,13 +33,16 @@ function XhrTextFetcher() { |
/** |
* @param {string} url The URL to fetch. |
+ * @param {string?} opt_method The HTTP method to use (default GET) |
+ * @param {string?} opt_body The request body |
* @return {!Promise.<string>} A promise for the fetched text. In case of an |
* error, this promise is rejected with an HTTP status code. |
*/ |
-XhrTextFetcher.prototype.fetch = function(url) { |
+XhrTextFetcher.prototype.fetch = function(url, opt_method, opt_body) { |
return new Promise(function(resolve, reject) { |
var xhr = new XMLHttpRequest(); |
- xhr.open('GET', url, true); |
+ var method = opt_method || 'GET'; |
+ xhr.open(method, url, true); |
xhr.onloadend = function() { |
if (xhr.status != 200) { |
reject(xhr.status); |
@@ -45,6 +50,13 @@ XhrTextFetcher.prototype.fetch = function(url) { |
} |
resolve(xhr.responseText); |
}; |
- xhr.send(); |
+ xhr.onerror = function() { |
+ // Treat any network-level errors as though the page didn't exist. |
+ reject(404); |
+ }; |
+ if (opt_body) |
+ xhr.send(opt_body); |
+ else |
+ xhr.send(); |
}); |
}; |