Index: Source/devtools/front_end/Runtime.js |
diff --git a/Source/devtools/front_end/Runtime.js b/Source/devtools/front_end/Runtime.js |
index 708667b5d3287b835fbb4178d076147c1cc931d2..4003c80a197dfad1c9155805dc35fa332a769c4e 100644 |
--- a/Source/devtools/front_end/Runtime.js |
+++ b/Source/devtools/front_end/Runtime.js |
@@ -35,24 +35,6 @@ var _loadedScripts = {}; |
/** |
* @param {string} url |
- * @return {string} |
- */ |
-function loadResource(url) |
-{ |
- var xhr = new XMLHttpRequest(); |
- xhr.open("GET", url, false); |
- try { |
- xhr.send(null); |
- } catch (e) { |
- console.error(url + " -> " + new Error().stack); |
- throw e; |
- } |
- // xhr.status === 0 if loading from bundle. |
- return xhr.status < 400 ? xhr.responseText : ""; |
-} |
- |
-/** |
- * @param {string} url |
* @return {!Promise.<string>} |
*/ |
function loadResourcePromise(url) |
@@ -232,74 +214,6 @@ Runtime.isReleaseMode = function() |
} |
/** |
- * @param {string} moduleName |
- * @param {string} workerName |
- * @return {!SharedWorker} |
- */ |
-Runtime.startSharedWorker = function(moduleName, workerName) |
-{ |
- if (Runtime.isReleaseMode()) |
- return new SharedWorker(moduleName + "_module.js", workerName); |
- |
- var content = loadResource(moduleName + "/module.json"); |
- if (!content) |
- throw new Error("Worker is not defined: " + moduleName + " " + new Error().stack); |
- var scripts = JSON.parse(content)["scripts"]; |
- if (scripts.length !== 1) |
- throw Error("Runtime.startSharedWorker supports modules with only one script!"); |
- return new SharedWorker(moduleName + "/" + scripts[0], workerName); |
-} |
- |
-/** |
- * @param {string} moduleName |
- * @return {!Worker} |
- */ |
-Runtime.startWorker = function(moduleName) |
-{ |
- if (Runtime.isReleaseMode()) |
- return new Worker(moduleName + "_module.js"); |
- |
- var content = loadResource(moduleName + "/module.json"); |
- if (!content) |
- throw new Error("Worker is not defined: " + moduleName + " " + new Error().stack); |
- var message = []; |
- var scripts = JSON.parse(content)["scripts"]; |
- for (var i = 0; i < scripts.length; ++i) { |
- var url = self._importScriptPathPrefix + moduleName + "/" + scripts[i]; |
- var parts = url.split("://"); |
- url = parts.length === 1 ? url : parts[0] + "://" + normalizePath(parts[1]); |
- message.push({ |
- source: loadResource(moduleName + "/" + scripts[i]), |
- url: url |
- }); |
- } |
- |
- /** |
- * @suppress {checkTypes} |
- */ |
- var loader = function() { |
- self.onmessage = function(event) { |
- self.onmessage = null; |
- var scripts = event.data; |
- for (var i = 0; i < scripts.length; ++i) { |
- var source = scripts[i]["source"]; |
- self.eval(source + "\n//# sourceURL=" + scripts[i]["url"]); |
- } |
- }; |
- }; |
- |
- var blob = new Blob(["(" + loader.toString() + ")()\n//# sourceURL=" + moduleName], { type: "text/javascript" }); |
- var workerURL = window.URL.createObjectURL(blob); |
- try { |
- var worker = new Worker(workerURL); |
- worker.postMessage(message); |
- return worker; |
- } finally { |
- window.URL.revokeObjectURL(workerURL); |
- } |
-} |
- |
-/** |
* @param {string} appName |
*/ |
Runtime.startApplication = function(appName) |
@@ -725,6 +639,7 @@ Runtime.Module.prototype = { |
dependencyPromises.push(this._manager._modulesMap[dependencies[i]]._loadPromise()); |
this._pendingLoadPromise = Promise.all(dependencyPromises) |
+ .then(this._loadStylesheets.bind(this)) |
.then(this._loadScripts.bind(this)) |
.then(markAsLoaded.bind(this)); |
@@ -742,25 +657,54 @@ Runtime.Module.prototype = { |
/** |
* @return {!Promise.<undefined>} |
+ * @this {Runtime.Module} |
+ */ |
+ _loadStylesheets: function() |
+ { |
+ var stylesheets = this._descriptor["stylesheets"]; |
+ if (!stylesheets) |
+ return Promise.resolve(); |
+ var promises = []; |
+ for (var i = 0; i < stylesheets.length; ++i) { |
+ var url = this._modularizeURL(stylesheets[i]); |
+ promises.push(loadResourcePromise(url).then(cacheStylesheet.bind(this, url), cacheStylesheet.bind(this, url, undefined))); |
+ } |
+ return Promise.all(promises).then(undefined); |
+ |
+ /** |
+ * @param {string} path |
+ * @param {string=} content |
+ */ |
+ function cacheStylesheet(path, content) |
+ { |
+ if (!content) { |
+ console.error("Failed to load stylesheet: " + path); |
+ return; |
+ } |
+ Runtime.cachedResources[path] = content; |
+ } |
+ }, |
+ |
+ /** |
+ * @return {!Promise.<undefined>} |
*/ |
_loadScripts: function() |
{ |
if (!this._descriptor.scripts) |
- return Promise.resolve(undefined); |
+ return Promise.resolve(); |
if (Runtime.isReleaseMode()) |
return loadScriptsPromise([this._name + "_module.js"]); |
- return loadScriptsPromise(this._descriptor.scripts.map(modularizeURL, this)).catch(Runtime._reportError); |
+ return loadScriptsPromise(this._descriptor.scripts.map(this._modularizeURL, this)).catch(Runtime._reportError); |
+ }, |
- /** |
- * @param {string} scriptName |
- * @this {Runtime.Module} |
- */ |
- function modularizeURL(scriptName) |
- { |
- return this._name + "/" + scriptName; |
- } |
+ /** |
+ * @param {string} resourceName |
+ */ |
+ _modularizeURL: function(resourceName) |
+ { |
+ return normalizePath(this._name + "/" + resourceName); |
}, |
/** |