Skip to content

Commit

Permalink
Remove nohost/StaticServer (dead code), always rewrite CSS files, fix…
Browse files Browse the repository at this point in the history
… remote script injection
  • Loading branch information
humphd committed Mar 30, 2017
1 parent 085b5e2 commit e457f54
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 64 deletions.
8 changes: 3 additions & 5 deletions src/extensions/default/bramble/lib/PostMessageTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,12 @@ define(function (require, exports, module) {
/**
* Returns the script that should be injected into the browser to handle the other end of the transport.
* Includes a base tag to handle external protocol-less, linked files.
* @param {string} path (Optional) a path being served, or the current LiveDoc's path if missing.
* @return {string}
*/
function getRemoteScript() {
function getRemoteScript(path) {
var currentDoc = LiveDevMultiBrowser._getCurrentLiveDoc();
var currentPath;
if(currentDoc) {
currentPath = currentDoc.doc.file.fullPath;
}
var currentPath = path || (currentDoc && currentDoc.doc.file.fullPath);

return '<base href="' + window.location.href + '">\n' +
"<script>\n" + PostMessageTransportRemote + "</script>\n" +
Expand Down
16 changes: 11 additions & 5 deletions src/extensions/default/bramble/nohost/HTMLServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define(function (require, exports, module) {

var Compatibility = require("lib/compatibility"),
MouseManager = require("lib/MouseManager"),
PostMessageTransport = require("lib/PostMessageTransport"),
LinkManager = require("lib/LinkManager");

var fs = Filer.fs(),
Expand All @@ -39,9 +40,14 @@ define(function (require, exports, module) {
HTMLServer.prototype.pathToUrl = function(path) {
return BlobUtils.getUrl(path);
};
//Returns a path based on blob url
//Returns a path based on blob url or filepath. Returns null for any other URL.
HTMLServer.prototype.urlToPath = function(url) {
return BlobUtils.getFilename(url);
if(Content.isBlobURL(url) || Content.isRelativeURL(url)) {
return BlobUtils.getFilename(url);
}

// Any other URL (http://...) so skip it, since we don't serve it.
return null;
};

HTMLServer.prototype.readyToServe = function () {
Expand Down Expand Up @@ -158,9 +164,9 @@ define(function (require, exports, module) {
}

if (_isHTML(path)) {
// Since we're not instrumenting this doc fully for some reason,
// at least inject the scroll manager so we can track scroll position.
var scripts = MouseManager.getRemoteScript(path) + LinkManager.getRemoteScript();
// Since we don't have a LiveDoc (yet) and aren't instrumenting fully,
// at least inject the necessary remote scripts so preview APIs work.
var scripts = PostMessageTransport.getRemoteScript(path);
var scriptsWithEndTag = scripts + "$&";
var headRegex = new RegExp(/<\/\s*head>/);
var htmlRegex = new RegExp(/<\/\s*html>/);
Expand Down
36 changes: 0 additions & 36 deletions src/extensions/default/bramble/nohost/StaticServer.js

This file was deleted.

19 changes: 2 additions & 17 deletions src/extensions/default/bramble/nohost/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ define(function (require, exports, module) {
"use strict";

var LiveDevServerManager = brackets.getModule("LiveDevelopment/LiveDevServerManager");
var ProjectManager = brackets.getModule("project/ProjectManager");
var ProjectManager = brackets.getModule("project/ProjectManager");
var HTMLServer = require("nohost/HTMLServer").HTMLServer;
var StaticServer = require("nohost/StaticServer").StaticServer;

var _HTMLServer;
var _StaticServer;

// Server for HTML files only
function getHTMLServer() {
if (!_HTMLServer) {
_HTMLServer = new HTMLServer({
Expand All @@ -24,20 +21,8 @@ define(function (require, exports, module) {
return _HTMLServer;
}

// Server for non-HTML files only
function _getStaticServer() {
if (!_StaticServer) {
_StaticServer = new StaticServer({
pathResolver : ProjectManager.makeProjectRelativeIfPossible,
root : ProjectManager.getProjectRoot()
});
}
return _StaticServer;
}

function init() {
LiveDevServerManager.registerServer({ create: _getStaticServer }, 9000);
LiveDevServerManager.registerServer({ create: getHTMLServer }, 9001);
LiveDevServerManager.registerServer({ create: getHTMLServer }, 9001);
}

exports.init = init;
Expand Down
9 changes: 8 additions & 1 deletion src/filesystem/impls/filer/FileSystemCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ define(function (require, exports, module) {
var decodePath = require("filesystem/impls/filer/FilerUtils").decodePath;

// Walk the project root dir and make sure we have Blob URLs generated for
// all file paths.
// all file paths. Skip CSS and HTML files, since we need to rewrite them
// before they are useful (e.g., for linked files within them).
exports.refresh = function(callback) {
var fs = BracketsFiler.fs();

function _getUrlAsync(filename, callback) {
var decodedFilename = decodePath(filename);
var cachedUrl = BlobUtils.getUrl(filename);

// Skip HTML and CSS files, since we need to run a rewriter over them
// before we can serve a Blob URL.
if(Content.needsRewriting(Path.extname(decodedFilename))) {
return callback(null);
}

// If we get a Blob URL (i.e., not the filename back) and get it
// synchronously, run the callback and yield to main thread.
if(cachedUrl !== filename) {
Expand Down
13 changes: 13 additions & 0 deletions src/filesystem/impls/filer/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ define(function (require, exports, module) {
return id === "css";
},

needsRewriting: function(ext) {
return this.isHTML(ext) || this.isCSS(ext);
},

isMarkdown: function(ext) {
var id = _getLanguageId(ext);
return id === "markdown";
Expand Down Expand Up @@ -124,6 +128,15 @@ define(function (require, exports, module) {
}

return !(/\:?\/\//.test(url) || /\s*data\:/.test(url));
},

// Test for a Blob URL, eg: blob:http://localhost:8000/bf64f1e0-044d-4673-ba7d-156251db09f8
isBlobURL: function(url) {
if(!url) {
return false;
}

return /^blob\:/.test(url);
}
};
});

0 comments on commit e457f54

Please sign in to comment.