From 5d0d130cd54257b4150649f0523c652fca082a92 Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Tue, 27 Aug 2013 13:35:29 -0700 Subject: [PATCH 1/7] For currentDocumentChange, check if the server can display the new document before starting a new live dev session. fix server cleanup remove extraneous runs() block --- src/LiveDevelopment/LiveDevelopment.js | 57 +++++++++++++++----------- test/spec/LiveDevelopment-test.js | 7 +--- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 5e26333a307..a1384ab560b 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -238,7 +238,9 @@ define(function LiveDevelopment(require, exports, module) { } // Clear all documents from request filtering - _server.clear(); + if (_server) { + _server.clear(); + } } /** @@ -543,8 +545,6 @@ define(function LiveDevelopment(require, exports, module) { // No longer in site, so terminate live dev, but don't close browser window Inspector.disconnect(); _closeReason = "navigated_away"; - _setStatus(STATUS_INACTIVE); - _server = null; } } @@ -555,12 +555,17 @@ define(function LiveDevelopment(require, exports, module) { unloadAgents(); - // Stop listening for requests when disconnected - _server.stop(); - // Close live documents _closeDocuments(); + if (_server) { + // Stop listening for requests when disconnected + _server.stop(); + + // Dispose server + _server = null; + } + _setStatus(STATUS_INACTIVE); } @@ -603,11 +608,15 @@ define(function LiveDevelopment(require, exports, module) { } if (Inspector.connected()) { - var timer = window.setTimeout(cleanup, 5000); // 5 seconds - Inspector.Runtime.evaluate("window.open('', '_self').close();", function (response) { - Inspector.disconnect(); - window.clearTimeout(timer); - cleanup(); + // Close the browser tab/window + var closePromise = Inspector.Runtime.evaluate("window.open('', '_self').close();"); + + // Add a timeout to force cleanup if Inspector does not respond + closePromise = Async.withTimeout(closePromise, 5000); + + // Disconnect the Inspector after closing the tab/winow + closePromise.always(function () { + Inspector.disconnect().always(cleanup); }); } else { cleanup(); @@ -932,23 +941,21 @@ define(function LiveDevelopment(require, exports, module) { function _onDocumentChange() { var doc = _getCurrentDocument(); - if (!doc) { + if (!doc || !Inspector.connected()) { return; } - if (Inspector.connected()) { - hideHighlight(); - - // close the current session and begin a new session if the current - // document changes to an HTML document that was not loaded yet - var wasRequested = agents.network && agents.network.wasURLRequested(doc.url), - isHTML = exports.config.experimental || _isHtmlFileExt(doc.extension); - - if (!wasRequested && isHTML) { - // TODO (jasonsanjose): optimize this by reusing the same connection - // no need to fully teardown. - close().done(open); - } + hideHighlight(); + + // close the current session and begin a new session if the current + // document changes to an HTML document that was not loaded yet + var wasRequested = agents.network && agents.network.wasURLRequested(doc.url), + isViewable = exports.config.experimental || _server.canServe(doc.file.fullPath); + + if (!wasRequested && isViewable) { + // TODO (jasonsanjose): optimize this by reusing the same connection + // no need to fully teardown. + close().done(open); } } diff --git a/test/spec/LiveDevelopment-test.js b/test/spec/LiveDevelopment-test.js index add1f785e23..99e087b17a3 100644 --- a/test/spec/LiveDevelopment-test.js +++ b/test/spec/LiveDevelopment-test.js @@ -511,10 +511,7 @@ define(function (require, exports, module) { afterEach(function () { waitsForDone(LiveDevelopment.close(), "Waiting for browser to become inactive", 10000); - - runs(function () { - testWindow.closeAllFiles(); - }); + testWindow.closeAllFiles(); }); it("should establish a browser connection for an opened html file", function () { @@ -690,7 +687,7 @@ define(function (require, exports, module) { // Verify that we still have modified text expect(updatedNode.value).toBe("Live Preview in Brackets is awesome!"); }); - + // Save original content back to the file after this test passes/fails runs(function () { htmlDoc.setText(origHtmlText); From 62295da3176ba668545c154d14dcdd92b9745a0c Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Tue, 27 Aug 2013 19:34:07 -0700 Subject: [PATCH 2/7] consolidate live dev connection closing. fix regression for live dev base url prompt #4972. --- src/LiveDevelopment/Documents/CSSDocument.js | 19 ++- src/LiveDevelopment/LiveDevelopment.js | 168 +++++++++++-------- test/spec/LiveDevelopment-test.js | 4 +- 3 files changed, 109 insertions(+), 82 deletions(-) diff --git a/src/LiveDevelopment/Documents/CSSDocument.js b/src/LiveDevelopment/Documents/CSSDocument.js index bf9786777a6..5883a92a8b9 100644 --- a/src/LiveDevelopment/Documents/CSSDocument.js +++ b/src/LiveDevelopment/Documents/CSSDocument.js @@ -69,11 +69,11 @@ define(function CSSDocumentModule(require, exports, module) { this.doc.addRef(); this.onChange = this.onChange.bind(this); this.onDeleted = this.onDeleted.bind(this); - $(this.doc).on("change", this.onChange); - $(this.doc).on("deleted", this.onDeleted); + $(this.doc).on("change.CSSDocument", this.onChange); + $(this.doc).on("deleted.CSSDocument", this.onDeleted); this.onActiveEditorChange = this.onActiveEditorChange.bind(this); - $(EditorManager).on("activeEditorChange", this.onActiveEditorChange); + $(EditorManager).on("activeEditorChange.CSSDocument", this.onActiveEditorChange); if (editor) { // Attach now @@ -113,8 +113,9 @@ define(function CSSDocumentModule(require, exports, module) { /** Close the document */ CSSDocument.prototype.close = function close() { - $(this.doc).off("change", this.onChange); - $(this.doc).off("deleted", this.onDeleted); + $(this.doc).off("change.CSSDocument"); + $(this.doc).off("deleted.CSSDocument"); + $(EditorManager).off("activeEditorChange.CSSDocument"); this.doc.releaseRef(); this.detachFromEditor(); }; @@ -136,8 +137,8 @@ define(function CSSDocumentModule(require, exports, module) { this.editor = editor; if (this.editor) { - $(HighlightAgent).on("highlight", this.onHighlight); - $(this.editor).on("cursorActivity", this.onCursorActivity); + $(HighlightAgent).on("highlight.CSSDocument", this.onHighlight); + $(this.editor).on("cursorActivity.CSSDocument", this.onCursorActivity); this.updateHighlight(); } }; @@ -145,8 +146,8 @@ define(function CSSDocumentModule(require, exports, module) { CSSDocument.prototype.detachFromEditor = function () { if (this.editor) { HighlightAgent.hide(); - $(HighlightAgent).off("highlight", this.onHighlight); - $(this.editor).off("cursorActivity", this.onCursorActivity); + $(HighlightAgent).off("highlight.CSSDocument"); + $(this.editor).off("cursorActivity.CSSDocument"); this.onHighlight(); this.editor = null; } diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index a1384ab560b..da9cc14ac49 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -144,7 +144,6 @@ define(function LiveDevelopment(require, exports, module) { var _liveDocument; // the document open for live editing. var _relatedDocuments; // CSS and JS documents that are used by the live HTML document var _server; // current live dev server - var _closeReason; // reason why live preview was closed var _openDeferred; // promise returned for each call to open() function _isHtmlFileExt(ext) { @@ -330,17 +329,21 @@ define(function LiveDevelopment(require, exports, module) { } } - /** Update the status - * @param {integer} new status + /** + * Update the status. Triggers a statusChange event. + * @param {number} status new status + * @param {?string} closeReason Optional string key suffix to display to + * user when closing the live development connection (see LIVE_DEV_* keys) */ - function _setStatus(status) { + function _setStatus(status, closeReason) { // Don't send a notification when the status didn't actually change if (status === exports.status) { return; } exports.status = status; - var reason = status === STATUS_INACTIVE ? _closeReason : null; + + var reason = status === STATUS_INACTIVE ? closeReason : null; $(exports).triggerHandler("statusChange", [status, reason]); } @@ -516,6 +519,48 @@ define(function LiveDevelopment(require, exports, module) { return result.promise(); } + /** + * @private + * While still connected to the Inspector, do cleanup for agents, + * documents and server. + * @return {jQuery.Promise} A promise that is always resolved + */ + function _doInspectorDisconnect(doCloseWindow) { + var closePromise, + deferred = new $.Deferred(); + + $(Inspector.Inspector).off("detached.livedev"); + $(Inspector.Page).off("frameNavigated.livedev"); + + unloadAgents(); + + // Close live documents + _closeDocuments(); + + if (_server) { + // Stop listening for requests when disconnected + _server.stop(); + + // Dispose server + _server = null; + } + + if (doCloseWindow) { + closePromise = Inspector.Runtime.evaluate("window.open('', '_self').close();"); + + // Add a timeout to continue cleanup if Inspector does not respond + closePromise = Async.withTimeout(closePromise, 5000); + } else { + closePromise = new $.Deferred().resolve(); + } + + closePromise.done(function () { + Inspector.disconnect().always(deferred.resolve); + }); + + return deferred.promise(); + } + // WebInspector Event: Page.frameNavigated function _onFrameNavigated(event, res) { // res = {frame} @@ -543,41 +588,22 @@ define(function LiveDevelopment(require, exports, module) { baseUrlRegExp = new RegExp("^" + StringUtils.regexEscape(baseUrl), "i"); if (!url.match(baseUrlRegExp)) { // No longer in site, so terminate live dev, but don't close browser window - Inspector.disconnect(); - _closeReason = "navigated_away"; + _close(false, "navigated_away"); } } - /** Triggered by Inspector.disconnect */ - function _onDisconnect(event) { - $(Inspector.Inspector).off("detached.livedev"); - $(Inspector.Page).off("frameNavigated.livedev"); - - unloadAgents(); - - // Close live documents - _closeDocuments(); - - if (_server) { - // Stop listening for requests when disconnected - _server.stop(); - - // Dispose server - _server = null; - } - - _setStatus(STATUS_INACTIVE); - } - function _onDetached(event, res) { - // If there already is a reason for closing the session, do not overwrite it - if (!_closeReason && res && res.reason) { + var closeReason; + + if (res && res.reason) { // Get the explanation from res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user" // Examples taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004 // However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API // Prefix with "detached_" to create a quasi-namespace for Chrome's reasons - _closeReason = "detached_" + res.reason; + closeReason = "detached_" + res.reason; } + + _close(false, closeReason); } /** @@ -589,13 +615,13 @@ define(function LiveDevelopment(require, exports, module) { } /** + * @private * Close the connection and the associated window asynchronously - * + * @param {boolean} doCloseWindow Use true to close the window/tab in the browser + * @param {?string} reason Optional string key suffix to display to user (see LIVE_DEV_* keys) * @return {jQuery.Promise} Resolves once the connection is closed */ - function close() { - _closeReason = "explicit_close"; - + function _close(doCloseWindow, reason) { var deferred = $.Deferred(); /* @@ -603,21 +629,12 @@ define(function LiveDevelopment(require, exports, module) { * the status accordingly. */ function cleanup() { - _setStatus(STATUS_INACTIVE); + _setStatus(STATUS_INACTIVE, reason || "explicit_close"); deferred.resolve(); } if (Inspector.connected()) { - // Close the browser tab/window - var closePromise = Inspector.Runtime.evaluate("window.open('', '_self').close();"); - - // Add a timeout to force cleanup if Inspector does not respond - closePromise = Async.withTimeout(closePromise, 5000); - - // Disconnect the Inspector after closing the tab/winow - closePromise.always(function () { - Inspector.disconnect().always(cleanup); - }); + _doInspectorDisconnect(doCloseWindow).done(cleanup); } else { cleanup(); } @@ -628,6 +645,14 @@ define(function LiveDevelopment(require, exports, module) { return deferred.promise(); } + + /** + * Close the connection and the associated window asynchronously + * @return {jQuery.Promise} Resolves once the connection is closed + */ + function close() { + return _close(true); + } /** * @private @@ -855,29 +880,29 @@ define(function LiveDevelopment(require, exports, module) { } function _prepareServer(doc) { - var deferred = new $.Deferred(); + var deferred = new $.Deferred(), + showBaseUrlPrompt = false; _server = LiveDevServerManager.getServer(doc.file.fullPath); - - if (!exports.config.experimental && !_server) { - if (FileUtils.isServerHtmlFileExt(doc.extension)) { - PreferencesDialogs.showProjectPreferencesDialog("", Strings.LIVE_DEV_NEED_BASEURL_MESSAGE) - .done(function (id) { - if (id === Dialogs.DIALOG_BTN_OK && ProjectManager.getBaseUrl()) { - // If base url is specifed, then re-invoke _prepareServer() to continue - _prepareServer(doc).then(deferred.resolve, deferred.reject); - } else { - deferred.reject(); - } - }); - } else if (!FileUtils.isStaticHtmlFileExt(doc.extension)) { - _showWrongDocError(); - deferred.reject(); - } else { - // fall-back to file:// - deferred.resolve(); - } - } else { + + // Optionally prompt for a base URL if no server was found but the + // file is a known server file extension + showBaseUrlPrompt = !exports.config.experimental && !_server && + FileUtils.isServerHtmlFileExt(doc.file.fullPath); + + if (showBaseUrlPrompt) { + // Prompt for a base URL + PreferencesDialogs.showProjectPreferencesDialog("", Strings.LIVE_DEV_NEED_BASEURL_MESSAGE) + .done(function (id) { + if (id === Dialogs.DIALOG_BTN_OK && ProjectManager.getBaseUrl()) { + // If base url is specifed, then re-invoke _prepareServer() to continue + _prepareServer(doc).then(deferred.resolve, deferred.reject); + } else { + deferred.reject(); + } + }); + } else if (_server) { + // Startup the server var readyPromise = _server.readyToServe(); if (!readyPromise) { _showLiveDevServerNotReadyError(); @@ -888,6 +913,9 @@ define(function LiveDevelopment(require, exports, module) { deferred.reject(); }); } + } else { + // No server found + deferred.reject(); } return deferred.promise(); @@ -895,11 +923,10 @@ define(function LiveDevelopment(require, exports, module) { /** Open the Connection and go live */ function open() { - _closeReason = null; _openDeferred = new $.Deferred(); var doc = _getCurrentDocument(), - prepareServerPromise = _prepareServer(doc); + prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject(); // wait for server (StaticServer, Base URL or file:) prepareServerPromise.done(_doLaunchAfterServerReady); @@ -999,8 +1026,7 @@ define(function LiveDevelopment(require, exports, module) { /** Initialize the LiveDevelopment Session */ function init(theConfig) { exports.config = theConfig; - $(Inspector).on("disconnect", _onDisconnect) - .on("error", _onError); + $(Inspector).on("error", _onError); $(Inspector.Inspector).on("detached", _onDetached); $(DocumentManager).on("currentDocumentChange", _onDocumentChange) .on("documentSaved", _onDocumentSaved) diff --git a/test/spec/LiveDevelopment-test.js b/test/spec/LiveDevelopment-test.js index 99e087b17a3..ff5feb13e3d 100644 --- a/test/spec/LiveDevelopment-test.js +++ b/test/spec/LiveDevelopment-test.js @@ -641,7 +641,7 @@ define(function (require, exports, module) { // Verify that we get the modified text in memory and not the original text on disk. var originalNode; runs(function () { - originalNode = DOMAgent.nodeAtLocation(388); + originalNode = DOMAgent.nodeAtLocation(396); expect(originalNode.value).toBe("Live Preview in Brackets is awesome!"); }); @@ -671,7 +671,7 @@ define(function (require, exports, module) { runs(function () { testWindow.$(LiveDevelopment).off("statusChange", statusChangeHandler); - updatedNode = DOMAgent.nodeAtLocation(388); + updatedNode = DOMAgent.nodeAtLocation(396); var liveDoc = LiveDevelopment.getLiveDocForPath(testPath + "/simple1.css"); liveDoc.getSourceFromBrowser().done(function (text) { From 3d605acce96690ca8b391a3f9e3bfefac620e7a5 Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Tue, 27 Aug 2013 19:38:47 -0700 Subject: [PATCH 3/7] fix JSLint function order error --- src/LiveDevelopment/LiveDevelopment.js | 64 +++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index da9cc14ac49..58bd4a74e83 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -561,6 +561,38 @@ define(function LiveDevelopment(require, exports, module) { return deferred.promise(); } + /** + * @private + * Close the connection and the associated window asynchronously + * @param {boolean} doCloseWindow Use true to close the window/tab in the browser + * @param {?string} reason Optional string key suffix to display to user (see LIVE_DEV_* keys) + * @return {jQuery.Promise} Resolves once the connection is closed + */ + function _close(doCloseWindow, reason) { + var deferred = $.Deferred(); + + /* + * Finish closing the live development connection, including setting + * the status accordingly. + */ + function cleanup() { + _setStatus(STATUS_INACTIVE, reason || "explicit_close"); + deferred.resolve(); + } + + if (Inspector.connected()) { + _doInspectorDisconnect(doCloseWindow).done(cleanup); + } else { + cleanup(); + } + + if (_openDeferred && _openDeferred.state() === "pending") { + _openDeferred.reject(); + } + + return deferred.promise(); + } + // WebInspector Event: Page.frameNavigated function _onFrameNavigated(event, res) { // res = {frame} @@ -614,38 +646,6 @@ define(function LiveDevelopment(require, exports, module) { loadAgents(); } - /** - * @private - * Close the connection and the associated window asynchronously - * @param {boolean} doCloseWindow Use true to close the window/tab in the browser - * @param {?string} reason Optional string key suffix to display to user (see LIVE_DEV_* keys) - * @return {jQuery.Promise} Resolves once the connection is closed - */ - function _close(doCloseWindow, reason) { - var deferred = $.Deferred(); - - /* - * Finish closing the live development connection, including setting - * the status accordingly. - */ - function cleanup() { - _setStatus(STATUS_INACTIVE, reason || "explicit_close"); - deferred.resolve(); - } - - if (Inspector.connected()) { - _doInspectorDisconnect(doCloseWindow).done(cleanup); - } else { - cleanup(); - } - - if (_openDeferred && _openDeferred.state() === "pending") { - _openDeferred.reject(); - } - - return deferred.promise(); - } - /** * Close the connection and the associated window asynchronously * @return {jQuery.Promise} Resolves once the connection is closed From 1d6064acdf8c0cddc2515930ccd51339a969547e Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Tue, 27 Aug 2013 20:23:43 -0700 Subject: [PATCH 4/7] Restore Inspector disconnect event handler for unexpected disconnects --- src/LiveDevelopment/LiveDevelopment.js | 43 +++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 58bd4a74e83..6f071009634 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -523,14 +523,16 @@ define(function LiveDevelopment(require, exports, module) { * @private * While still connected to the Inspector, do cleanup for agents, * documents and server. + * @param {boolean} doCloseWindow Use true to close the window/tab in the browser * @return {jQuery.Promise} A promise that is always resolved */ function _doInspectorDisconnect(doCloseWindow) { var closePromise, - deferred = new $.Deferred(); + deferred = new $.Deferred(), + connected = Inspector.connected(); - $(Inspector.Inspector).off("detached.livedev"); $(Inspector.Page).off("frameNavigated.livedev"); + $(Inspector).off("disconnect.livedev") unloadAgents(); @@ -545,7 +547,7 @@ define(function LiveDevelopment(require, exports, module) { _server = null; } - if (doCloseWindow) { + if (doCloseWindow && connected) { closePromise = Inspector.Runtime.evaluate("window.open('', '_self').close();"); // Add a timeout to continue cleanup if Inspector does not respond @@ -555,7 +557,11 @@ define(function LiveDevelopment(require, exports, module) { } closePromise.done(function () { - Inspector.disconnect().always(deferred.resolve); + if (Inspector.connected()) { + Inspector.disconnect().always(deferred.resolve); + } else { + deferred.resolve(); + } }); return deferred.promise(); @@ -570,7 +576,7 @@ define(function LiveDevelopment(require, exports, module) { */ function _close(doCloseWindow, reason) { var deferred = $.Deferred(); - + /* * Finish closing the live development connection, including setting * the status accordingly. @@ -579,16 +585,19 @@ define(function LiveDevelopment(require, exports, module) { _setStatus(STATUS_INACTIVE, reason || "explicit_close"); deferred.resolve(); } - - if (Inspector.connected()) { + + if (_openDeferred) { _doInspectorDisconnect(doCloseWindow).done(cleanup); + + if (_openDeferred.state() === "pending") { + _openDeferred.reject(); + } } else { + // Deferred may not be created yet + // We always close attempt to close the live dev connection on + // ProjectManager beforeProjectClose and beforeAppClose events cleanup(); } - - if (_openDeferred && _openDeferred.state() === "pending") { - _openDeferred.reject(); - } return deferred.promise(); } @@ -624,6 +633,14 @@ define(function LiveDevelopment(require, exports, module) { } } + /** + * @private + * Triggered by unexpected Inspector disconnect event + */ + function _onDisconnect(event) { + _close(false, "closed_unknown_reason"); + } + function _onDetached(event, res) { var closeReason; @@ -726,7 +743,11 @@ define(function LiveDevelopment(require, exports, module) { /** Triggered by Inspector.connect */ function _onConnect(event) { + // When the browser navigates away from the primary live document $(Inspector.Page).on("frameNavigated.livedev", _onFrameNavigated); + + // When the Inspector WebSocket disconnects unexpectedely + $(Inspector).on("disconnect.livedev", _onDisconnect); _waitForInterstitialPageLoad() .fail(function () { From eed9aac0901aca607028407ff2def3e0225d8949 Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Tue, 27 Aug 2013 20:28:20 -0700 Subject: [PATCH 5/7] fix jshint error --- src/LiveDevelopment/LiveDevelopment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 6f071009634..e84f2a1ee9f 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -532,7 +532,7 @@ define(function LiveDevelopment(require, exports, module) { connected = Inspector.connected(); $(Inspector.Page).off("frameNavigated.livedev"); - $(Inspector).off("disconnect.livedev") + $(Inspector).off("disconnect.livedev"); unloadAgents(); From d706cf2b23ba966bbaa55a63d6f84a5a221c7fe0 Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Wed, 28 Aug 2013 11:16:36 -0700 Subject: [PATCH 6/7] code review comments --- src/LiveDevelopment/Documents/CSSDocument.js | 13 ++++++------- src/LiveDevelopment/LiveDevelopment.js | 9 ++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/LiveDevelopment/Documents/CSSDocument.js b/src/LiveDevelopment/Documents/CSSDocument.js index 5883a92a8b9..723de1c6b4d 100644 --- a/src/LiveDevelopment/Documents/CSSDocument.js +++ b/src/LiveDevelopment/Documents/CSSDocument.js @@ -73,7 +73,7 @@ define(function CSSDocumentModule(require, exports, module) { $(this.doc).on("deleted.CSSDocument", this.onDeleted); this.onActiveEditorChange = this.onActiveEditorChange.bind(this); - $(EditorManager).on("activeEditorChange.CSSDocument", this.onActiveEditorChange); + $(EditorManager).on("activeEditorChange", this.onActiveEditorChange); if (editor) { // Attach now @@ -113,9 +113,8 @@ define(function CSSDocumentModule(require, exports, module) { /** Close the document */ CSSDocument.prototype.close = function close() { - $(this.doc).off("change.CSSDocument"); - $(this.doc).off("deleted.CSSDocument"); - $(EditorManager).off("activeEditorChange.CSSDocument"); + $(this.doc).off(".CSSDocument"); + $(EditorManager).off("activeEditorChange", this.onActiveEditorChange); this.doc.releaseRef(); this.detachFromEditor(); }; @@ -137,7 +136,7 @@ define(function CSSDocumentModule(require, exports, module) { this.editor = editor; if (this.editor) { - $(HighlightAgent).on("highlight.CSSDocument", this.onHighlight); + $(HighlightAgent).on("highlight", this.onHighlight); $(this.editor).on("cursorActivity.CSSDocument", this.onCursorActivity); this.updateHighlight(); } @@ -146,8 +145,8 @@ define(function CSSDocumentModule(require, exports, module) { CSSDocument.prototype.detachFromEditor = function () { if (this.editor) { HighlightAgent.hide(); - $(HighlightAgent).off("highlight.CSSDocument"); - $(this.editor).off("cursorActivity.CSSDocument"); + $(HighlightAgent).off("highlight", this.onHighlight); + $(this.editor).off(".CSSDocument"); this.onHighlight(); this.editor = null; } diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index e84f2a1ee9f..c49d1161e19 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -213,7 +213,10 @@ define(function LiveDevelopment(require, exports, module) { if (index !== -1) { _relatedDocuments.splice(index, 1); - _server.remove(liveDoc); + + if (_server) { + _server.remove(liveDoc); + } } } @@ -266,7 +269,7 @@ define(function LiveDevelopment(require, exports, module) { function createLiveStylesheet(url) { var stylesheetDeferred = $.Deferred(), promise = stylesheetDeferred.promise(), - path = _server.urlToPath(url); + path = _server && _server.urlToPath(url); // path may be null if loading an external stylesheet if (path) { @@ -998,7 +1001,7 @@ define(function LiveDevelopment(require, exports, module) { // close the current session and begin a new session if the current // document changes to an HTML document that was not loaded yet var wasRequested = agents.network && agents.network.wasURLRequested(doc.url), - isViewable = exports.config.experimental || _server.canServe(doc.file.fullPath); + isViewable = exports.config.experimental || (_server && _server.canServe(doc.file.fullPath)); if (!wasRequested && isViewable) { // TODO (jasonsanjose): optimize this by reusing the same connection From 373497ace89802eac1194fd04688df3d9e8ae39d Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Wed, 28 Aug 2013 11:24:40 -0700 Subject: [PATCH 7/7] minor event handler namespace cleanup --- src/LiveDevelopment/LiveDevelopment.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index c49d1161e19..b62d5f013e4 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -233,7 +233,7 @@ define(function LiveDevelopment(require, exports, module) { if (_relatedDocuments) { _relatedDocuments.forEach(function (liveDoc) { liveDoc.close(); - $(liveDoc).off("deleted", _handleRelatedDocumentDeleted); + $(liveDoc).off(".livedev"); }); _relatedDocuments = undefined; @@ -289,7 +289,7 @@ define(function LiveDevelopment(require, exports, module) { _relatedDocuments.push(liveDoc); _server.add(liveDoc); - $(liveDoc).on("deleted", _handleRelatedDocumentDeleted); + $(liveDoc).on("deleted.livedev", _handleRelatedDocumentDeleted); } } stylesheetDeferred.resolve(); @@ -534,8 +534,8 @@ define(function LiveDevelopment(require, exports, module) { deferred = new $.Deferred(), connected = Inspector.connected(); - $(Inspector.Page).off("frameNavigated.livedev"); - $(Inspector).off("disconnect.livedev"); + $(Inspector.Page).off(".livedev"); + $(Inspector).off(".livedev"); unloadAgents();