Skip to content

Commit

Permalink
#97: Store the request URL in the returned XMLDocument to workaround …
Browse files Browse the repository at this point in the history
…weird behavior with document.URL in IE

In IE document.URL always holds the same value as window.location.href, even if the document was loaded from an external source
with an HTTP request. Without explicitly storing the original request URL in the response we have no way of resolving relative
URIs inside the returned XMLDocument (ie. src="asset.xml#asset").
  • Loading branch information
csvurt committed Feb 20, 2015
1 parent 50529b2 commit e852f9c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/base/resourcemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ function setDocumentData(httpRequest, url, mimetype) {
response = JSON.parse(httpRequest.responseText);
} else if (cleanedMimetype.match(/xml/)) {
response = httpRequest.responseXML;
//Workaround for IE "bug" where external documents always report their document.URL as being identical to window.location.href
response._documentURL = url;
if (!response) {
XML3D.debug.logError("Invalid external XML document '" + httpRequest._url +
"': XML Syntax error");
Expand Down Expand Up @@ -460,7 +462,7 @@ ResourceManager.prototype.getAbsoluteURI = function(baseDocument, uri){

if (typeof uri == "string") uri = new XML3D.URI(uri);
if (baseDocument != document || !uri.isLocal()) {
uri = uri.getAbsoluteURI(baseDocument.URL);
uri = uri.getAbsoluteURI(baseDocument._documentURL || baseDocument.URL);
}
return uri;
};
Expand Down
2 changes: 1 addition & 1 deletion src/data/adapter/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Xflow.registerErrorCallback(function(message, xflowNode){
}
else if (userData.id) {
var uri = new XML3D.URI("#" + userData.id);
uri = uri.getAbsoluteURI(userData.ownerDocument.URL);
uri = uri.getAbsoluteURI(userData.ownerDocument._documentURL || userData.ownerDocument.URL);
XML3D.debug.logError(message, "External Node: " + uri);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/data/adapter/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var NodeAdapter = XML3D.base.NodeAdapter;
*/
ImgDataAdapter.prototype.createImageFromURL = function(url) {
var that = this;
var uri = new XML3D.URI(url).getAbsoluteURI(this.node.ownerDocument.URL);
var uri = new XML3D.URI(url).getAbsoluteURI(this.node.ownerDocument._documentURL || this.node.ownerDocument.URL);
var onload = function (e, image) {
if (that.textureEntry) {
that.textureEntry.setImage(image, true);
Expand Down Expand Up @@ -134,7 +134,7 @@ var NodeAdapter = XML3D.base.NodeAdapter;
*/
VideoDataAdapter.prototype.createVideoFromURL = function(url) {
var that = this;
var uri = new XML3D.URI(url).getAbsoluteURI(this.node.ownerDocument.URL);
var uri = new XML3D.URI(url).getAbsoluteURI(this.node.ownerDocument._documentURL || this.node.ownerDocument.URL);
this.video = XML3D.base.resourceManager.getVideo(uri, this.node.autoplay, this.node.loop,
{
canplay : function(event, video) {
Expand Down

0 comments on commit e852f9c

Please sign in to comment.