Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[XhrIo] Expose the responseBody property of the XHR object, which is …

…defined in IE. IE 9 can only access binary data from an XHR via this property.

R=brenneman
DELTA=53 (44 added, 3 deleted, 6 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6083


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2417 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
commit 8559beeaa01689a8f46b7beb1591cc90d2f27f87 1 parent a8a7f25
peyman@google.com authored
View
4 closure/goog/deps.js
@@ -451,7 +451,7 @@ goog.addDependency('net/testdata/jsloader_test4.js', ['goog.net.testdata.jsloade
goog.addDependency('net/tmpnetwork.js', ['goog.net.tmpnetwork'], ['goog.Uri', 'goog.net.ChannelDebug']);
goog.addDependency('net/websocket.js', ['goog.net.WebSocket', 'goog.net.WebSocket.ErrorEvent', 'goog.net.WebSocket.EventType', 'goog.net.WebSocket.MessageEvent'], ['goog.Timer', 'goog.asserts', 'goog.debug.Logger', 'goog.debug.entryPointRegistry', 'goog.events', 'goog.events.Event', 'goog.events.EventTarget']);
goog.addDependency('net/wrapperxmlhttpfactory.js', ['goog.net.WrapperXmlHttpFactory'], ['goog.net.XmlHttpFactory']);
-goog.addDependency('net/xhrio.js', ['goog.net.XhrIo', 'goog.net.XhrIo.ResponseType'], ['goog.Timer', 'goog.debug.Logger', 'goog.debug.entryPointRegistry', 'goog.debug.errorHandlerWeakDep', 'goog.events.EventTarget', 'goog.json', 'goog.net.ErrorCode', 'goog.net.EventType', 'goog.net.HttpStatus', 'goog.net.XmlHttp', 'goog.object', 'goog.structs', 'goog.structs.Map', 'goog.uri.utils']);
+goog.addDependency('net/xhrio.js', ['goog.net.XhrIo', 'goog.net.XhrIo.ResponseType'], ['goog.Timer', 'goog.array', 'goog.debug.Logger', 'goog.debug.entryPointRegistry', 'goog.events', 'goog.events.EventTarget', 'goog.json', 'goog.net.ErrorCode', 'goog.net.EventType', 'goog.net.HttpStatus', 'goog.net.XmlHttp', 'goog.object', 'goog.structs', 'goog.structs.Map', 'goog.uri.utils']);
goog.addDependency('net/xhriopool.js', ['goog.net.XhrIoPool'], ['goog.net.XhrIo', 'goog.structs', 'goog.structs.PriorityPool']);
goog.addDependency('net/xhrlite.js', ['goog.net.XhrLite'], ['goog.net.XhrIo']);
goog.addDependency('net/xhrlitepool.js', ['goog.net.XhrLitePool'], ['goog.net.XhrIoPool']);
@@ -602,7 +602,7 @@ goog.addDependency('testing/mockrange.js', ['goog.testing.MockRange'], ['goog.do
goog.addDependency('testing/mockstorage.js', ['goog.testing.MockStorage'], ['goog.structs.Map']);
goog.addDependency('testing/mockuseragent.js', ['goog.testing.MockUserAgent'], ['goog.Disposable', 'goog.userAgent']);
goog.addDependency('testing/multitestrunner.js', ['goog.testing.MultiTestRunner', 'goog.testing.MultiTestRunner.TestFrame'], ['goog.Timer', 'goog.array', 'goog.dom', 'goog.dom.classes', 'goog.events.EventHandler', 'goog.functions', 'goog.string', 'goog.ui.Component', 'goog.ui.ServerChart', 'goog.ui.ServerChart.ChartType', 'goog.ui.TableSorter']);
-goog.addDependency('testing/net/xhrio.js', ['goog.testing.net.XhrIo'], ['goog.array', 'goog.dom.xml', 'goog.events', 'goog.events.EventTarget', 'goog.json', 'goog.net.ErrorCode', 'goog.net.EventType', 'goog.net.HttpStatus', 'goog.net.XhrIo.ResponseType', 'goog.net.XmlHttp', 'goog.object', 'goog.structs.Map', 'goog.uri.utils']);
+goog.addDependency('testing/net/xhrio.js', ['goog.testing.net.XhrIo'], ['goog.array', 'goog.dom.xml', 'goog.events', 'goog.events.EventTarget', 'goog.json', 'goog.net.ErrorCode', 'goog.net.EventType', 'goog.net.HttpStatus', 'goog.net.XhrIo', 'goog.net.XmlHttp', 'goog.object', 'goog.structs.Map']);
goog.addDependency('testing/net/xhriopool.js', ['goog.testing.net.XhrIoPool'], ['goog.net.XhrIoPool', 'goog.testing.net.XhrIo']);
goog.addDependency('testing/objectpropertystring.js', ['goog.testing.ObjectPropertyString'], []);
goog.addDependency('testing/performancetable.js', ['goog.testing.PerformanceTable'], ['goog.dom', 'goog.testing.PerformanceTimer']);
View
38 closure/goog/net/xhrio.js
@@ -42,9 +42,10 @@ goog.provide('goog.net.XhrIo');
goog.provide('goog.net.XhrIo.ResponseType');
goog.require('goog.Timer');
+goog.require('goog.array');
goog.require('goog.debug.Logger');
goog.require('goog.debug.entryPointRegistry');
-goog.require('goog.debug.errorHandlerWeakDep');
+goog.require('goog.events');
goog.require('goog.events.EventTarget');
goog.require('goog.json');
goog.require('goog.net.ErrorCode');
@@ -925,8 +926,8 @@ goog.net.XhrIo.prototype.getResponseText = function() {
// http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute
// states that responseText should return '' (and responseXML null)
// when the state is not LOADING or DONE. Instead, IE and Gears can
- // throw unexpected exceptions, eg, when a request is aborted or no
- // data is available yet.
+ // throw unexpected exceptions, for example when a request is aborted
+ // or no data is available yet.
this.logger_.fine('Can not get responseText: ' + e.message);
return '';
}
@@ -934,6 +935,37 @@ goog.net.XhrIo.prototype.getResponseText = function() {
/**
+ * Get the response body from the Xhr object. This property is only available
+ * in IE since version 7 according to MSDN:
+ * http://msdn.microsoft.com/en-us/library/ie/ms534368(v=vs.85).aspx
+ * Will only return correct result when called from the context of a callback.
+ *
+ * One option is to construct a VBArray from the returned object and convert
+ * it to a JavaScript array using the toArray method:
+ * {@code (new window['VBArray'](xhrIo.getResponseBody())).toArray()}
+ * This will result in an array of numbers in the range of [0..255]
+ *
+ * Another option is to use the VBScript CStr method to convert it into a
+ * string as outlined in http://stackoverflow.com/questions/1919972
+ *
+ * @return {Object} Binary result from the server or null if not available.
+ */
+goog.net.XhrIo.prototype.getResponseBody = function() {
+ /** @preserveTry */
+ try {
+ if (this.xhr_ && 'responseBody' in this.xhr_) {
+ return this.xhr_['responseBody'];
+ }
+ } catch (e) {
+ // IE can throw unexpected exceptions, for example when a request is aborted
+ // or no data is yet available.
+ this.logger_.fine('Can not get responseBody: ' + e.message);
+ }
+ return null;
+};
+
+
+/**
* Get the response XML from the Xhr object
* Will only return correct result when called from the context of a callback.
* @return {Document} The DOM Document representing the XML file, or null
View
13 closure/goog/testing/net/xhrio.js
@@ -26,11 +26,10 @@ goog.require('goog.json');
goog.require('goog.net.ErrorCode');
goog.require('goog.net.EventType');
goog.require('goog.net.HttpStatus');
-goog.require('goog.net.XhrIo.ResponseType');
+goog.require('goog.net.XhrIo');
goog.require('goog.net.XmlHttp');
goog.require('goog.object');
goog.require('goog.structs.Map');
-goog.require('goog.uri.utils');
@@ -627,6 +626,16 @@ goog.testing.net.XhrIo.prototype.getResponseText = function() {
/**
+ * Gets the response body from the Xhr object. Will only return correct result
+ * when called from the context of a callback.
+ * @return {Object} Binary result from the server or null.
+ */
+goog.testing.net.XhrIo.prototype.getResponseBody = function() {
+ return null;
+};
+
+
+/**
* Gets the response and evaluates it as JSON from the Xhr object. Will only
* return correct result when called from the context of a callback.
* @param {string=} opt_xssiPrefix Optional XSSI prefix string to use for
Please sign in to comment.
Something went wrong with that request. Please try again.