Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
begin refactoring of request filters to ServerRequestManager
Browse files Browse the repository at this point in the history
fix bugs and disconnect handling

add jsdoc. remove unnecessary close/reopen of live dev connection.

fix for #4786 add CSSDocument to ServerRequestManager to rewrite HTTP responses on refresh

Refactor ServerRequestManager and all live dev server providers into BaseServer, FileServer, UserServer and StaticServer.

fix jshint errors

code review comments

code review comments from TomMalbran

more jsdoc comments from @TomMalbran

revert move of LiveDevServerManager to keep compatibility with theseus

Adapt older servers (theseus) to work with new API

break compatibility with older servers, including older versions of theseus

fix typo
  • Loading branch information
jasonsanjose committed Aug 23, 2013
1 parent ca551ba commit 1f6b5aa
Show file tree
Hide file tree
Showing 11 changed files with 939 additions and 665 deletions.
6 changes: 3 additions & 3 deletions src/LiveDevelopment/Agents/NetworkAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define(function NetworkAgent(require, exports, module) {

var Inspector = require("LiveDevelopment/Inspector/Inspector");

var _urlRequested; // url -> request info
var _urlRequested = {}; // url -> request info

/** Return the URL without the query string
* @param {string} URL
Expand Down Expand Up @@ -80,14 +80,14 @@ define(function NetworkAgent(require, exports, module) {

/** Initialize the agent */
function load() {
_urlRequested = {};

$(Inspector.Page).on("frameNavigated.NetworkAgent", _onFrameNavigated);
$(Inspector.Network).on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
}

/** Unload the agent */
function unload() {
_urlRequested = {};

$(Inspector.Page).off(".NetworkAgent");
$(Inspector.Network).off(".NetworkAgent");
}
Expand Down
41 changes: 33 additions & 8 deletions src/LiveDevelopment/Documents/CSSDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ define(function CSSDocumentModule(require, exports, module) {
this.onDeleted = this.onDeleted.bind(this);
$(this.doc).on("change", this.onChange);
$(this.doc).on("deleted", this.onDeleted);

// get the style sheet
this.styleSheet = CSSAgent.styleForURL(this.doc.url);

// If the CSS document is dirty, push the changes into the browser now
if (doc.isDirty) {
CSSAgent.reloadCSSForDocument(this.doc);
}

this.onActiveEditorChange = this.onActiveEditorChange.bind(this);
$(EditorManager).on("activeEditorChange", this.onActiveEditorChange);
Expand Down Expand Up @@ -126,6 +118,19 @@ define(function CSSDocumentModule(require, exports, module) {
this.doc.releaseRef();
this.detachFromEditor();
};

/**
* Force the browser to update if the file is dirty
*/
CSSDocument.prototype._updateBrowser = function () {
// get the style sheet
this.styleSheet = CSSAgent.styleForURL(this.doc.url);

// If the CSS document is dirty, push the changes into the browser now
if (this.doc.isDirty) {
CSSAgent.reloadCSSForDocument(this.doc);
}
};

CSSDocument.prototype.attachToEditor = function (editor) {
this.editor = editor;
Expand Down Expand Up @@ -158,6 +163,25 @@ define(function CSSDocumentModule(require, exports, module) {
}
}
};

/**
* Enable instrumented CSS
* @param enabled {boolean}
*/
CSSDocument.prototype.setInstrumentationEnabled = function setInstrumentationEnabled(enabled) {
// no-op
// "Instrumentation" is always enabled for CSS, we make no modifications
};

/**
* Returns a JSON object with HTTP response overrides
* @returns {{body: string}}
*/
CSSDocument.prototype.getResponseData = function getResponseData(enabled) {
return {
body: this.doc.getText()
};
};

/** Event Handlers *******************************************************/

Expand All @@ -174,6 +198,7 @@ define(function CSSDocumentModule(require, exports, module) {
HighlightAgent.redraw();
}
};

/** Triggered if the Document's file is deleted */
CSSDocument.prototype.onDeleted = function onDeleted(event, editor, change) {
// clear the CSS
Expand Down
123 changes: 44 additions & 79 deletions src/LiveDevelopment/LiveDevServerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,74 +21,28 @@
*
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define */

/*
* LiveDevServerManager Overview:
*
* The LiveDevServerManager allows extensions to register to be Live Development
* server providers. Providers are queried for their ability to serve a page in
* servers. Servers are queried for their ability to serve a page in
* order of descending priority by way their canServe methods.
*
* NOTE: This API is currently experimental and intented to be internal-only.
* It is very likely that it will be changed in the near future and/or
* removed entirely.
*
* # LiveDevServerManager.getProvider(localPath)
*
* Returns highest priority provider that can serve the local file.
*
* @param {String} url
* A url to file being served.
*
* @return {LiveDevServerProvider}
* Provider or null.
*
*
* LiveDevServerProvider Overview:
*
* A Live Development server provider must implement the following three functions:
*
* LiveDevServerProvider.canServe(localPath)
* LiveDevServerProvider.getBaseUrl()
* LiveDevServerProvider.readyToServe()
*
* The behavior of these three functions is described in detail below.
*
* # LiveDevServerProvider.canServe(localPath)
*
* The method by which a provider indicates intent to serve a local file.
* The manager calls this method when querying providers
*
* param {String} url
* A url for the page to be served.
*
* return {Boolean}
* Determines whether the current provider is able to serve the url.
*
*
* # LiveDevServerProvider.getBaseUrl()
* # LiveDevServerManager.getServer(localPath)
*
* The method by which a provider provides the base url for the current
* Brackets project.
*
* return {String}
*
*
* # LiveDevServerProvider.readyToServe()
*
* This method is called when Live Development is starting to check if the
* provider that has been selected is ready to serve. The provider returns a
* jQuery promise. The Live Development launch process waits until the promise
* resolves/rejects. If the promise rejects, an error window is shown
* and Live Development does not start.
*
* return {jQuery.Promise}
* Returns highest priority server (BaseServer) that can serve the local file.
*
* A Live Development server must implement the BaseServer API. See
* LiveDevelopment/Servers/BaseServer base class.
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define */

define(function (require, exports, module) {
"use strict";

Expand All @@ -98,7 +52,10 @@ define(function (require, exports, module) {
var _serverProviders = [];

/**
* @private
* Comparator to sort providers based on their priority
* @param {number} a
* @param {number} b
*/
function _providerSort(a, b) {
return b.priority - a.priority;
Expand All @@ -107,47 +64,55 @@ define(function (require, exports, module) {
/**
* Determines which provider can serve a file with a local path.
*
* @param {String} localPath
* A local path to file being served.
*
* @return {LiveDevServerProvider}
* true for yes, otherwise false.
* @param {string} localPath A local path to file being served.
* @return {?BaseServer} A server no null if no servers can serve the file
*/
function getProvider(localPath) {

var provider, i;
function getServer(localPath) {
var provider, server, i;

for (i = 0; i < _serverProviders.length; i++) {
provider = _serverProviders[i].provider;
if (provider.canServe(localPath)) {
return provider;
provider = _serverProviders[i];
server = provider.create();

if (server.canServe(localPath)) {
return server;
}
}

return null;
}

/**
* The method by which a LiveDevServerProvider registers itself.
* The method by which a server registers itself.
*
* @param {LiveDevServerProvider} provider
* The provider to be registered, described below.
*
* @param {Integer} priority
* A non-negative number used to break ties among providers for a
* particular url. Providers that register with a higher priority will
* have the opportunity to provide a given url before those with a
* lower priority. The higher the number, the higher the priority.
* @param {BaseServer|{create: function():BaseServer}} provider
* The provider to be registered, described below.
* @param {number} priority
* A non-negative number used to break ties among providers for a
* particular url. Providers that register with a higher priority will
* have the opportunity to provide a given url before those with a
* lower priority. The higher the number, the higher the priority.
*/
function registerProvider(provider, priority) {
var providerObj = { provider: provider,
priority: priority || 0 };
function registerServer(provider, priority) {
if (!provider.create) {
console.error("Incompatible live development server provider");
return;
}

var providerObj = {};

providerObj.create = provider.create;
providerObj.priority = priority || 0;

_serverProviders.push(providerObj);
_serverProviders.sort(_providerSort);
}

// Backwards compatibility
exports.getProvider = getServer;
exports.registerProvider = registerServer;

// Define public API
exports.getProvider = getProvider;
exports.registerProvider = registerProvider;
exports.getServer = getServer;
exports.registerServer = registerServer;
});
Loading

0 comments on commit 1f6b5aa

Please sign in to comment.