From 46da3132a2a63a8947a411134e99e87926230fbf Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Mon, 17 Mar 2014 23:10:24 +0100 Subject: [PATCH] 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. --- lib/ace/lib/net.js | 10 ++++++++++ lib/ace/worker/worker_client.js | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ace/lib/net.js b/lib/ace/lib/net.js index 3869da45..bba76df8 100644 --- a/lib/ace/lib/net.js +++ b/lib/ace/lib/net.js @@ -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; +} + }); diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 4aebe641..409b7202 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -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