Make sure the CORS blobworker loads absolute URLs

The only situation where this is really needed, is if the workerURL is
protocol relative, since we only end up in this situation if workerurl
is on a different server to begin with.
This commit is contained in:
Derk-Jan Hartman 2014-03-17 23:10:24 +01:00
commit 46da3132a2
2 changed files with 14 additions and 1 deletions

View file

@ -38,4 +38,14 @@ exports.loadScript = function(path, callback) {
};
};
/*
* Convert a url into a fully qualified absolute URL
* This function does not work in IE6
*/
exports.qualifyURL = function(url) {
var a = document.createElement('a');
a.href = url;
return a.href;
}
});

View file

@ -32,6 +32,7 @@ define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var net = require("../lib/net");
var EventEmitter = require("../lib/event_emitter").EventEmitter;
var config = require("../config");
@ -179,7 +180,9 @@ var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl) {
};
this.$workerBlob = function(workerUrl) {
var script = "importScripts('" + workerUrl + "');";
// workerUrl can be protocol relative
// importScripts only takes fully qualified urls
var script = "importScripts('" + net.qualifyURL( workerUrl ) + "');";
try {
return new Blob([script], {"type": "application/javascript"});
} catch (e) { // Backwards-compatibility