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

Fix live development connection in Chrome 27 beta #3442

Merged
merged 5 commits into from
Apr 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/LiveDevelopment/Agents/CSSAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ define(function CSSAgent(require, exports, module) {
function _onLoadEventFired(event, res) {
// res = {timestamp}
_urlToStyle = {};
Inspector.CSS.getAllStyleSheets(function onGetAllStyleSheets(res) {
var i, header;
for (i in res.headers) {
header = res.headers[i];
_urlToStyle[_canonicalize(header.sourceURL)] = header;
}
_load.resolve();
Inspector.CSS.enable().done(function () {
Inspector.CSS.getAllStyleSheets(function onGetAllStyleSheets(res) {
var i, header;
for (i in res.headers) {
header = res.headers[i];
_urlToStyle[_canonicalize(header.sourceURL)] = header;
}
_load.resolve();
});
});
}

Expand Down
11 changes: 6 additions & 5 deletions src/LiveDevelopment/Agents/ConsoleAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ define(function ConsoleAgent(require, exports, module) {

/** Initialize the agent */
function load() {
Inspector.Console.enable();
$(Inspector.Console)
.on("messageAdded.ConsoleAgent", _onMessageAdded)
.on("messageRepeatCountUpdated.ConsoleAgent", _onMessageRepeatCountUpdated)
.on("messagesCleared.ConsoleAgent", _onMessagesCleared);
return Inspector.Console.enable().done(function () {
$(Inspector.Console)
.on("messageAdded.ConsoleAgent", _onMessageAdded)
.on("messageRepeatCountUpdated.ConsoleAgent", _onMessageRepeatCountUpdated)
.on("messagesCleared.ConsoleAgent", _onMessagesCleared);
});
}

/** Clean up */
Expand Down
1 change: 0 additions & 1 deletion src/LiveDevelopment/Agents/DOMAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ define(function DOMAgent(require, exports, module) {
.on("childNodeCountUpdated.DOMAgent", _onChildNodeCountUpdated)
.on("childNodeInserted.DOMAgent", _onChildNodeInserted)
.on("childNodeRemoved.DOMAgent", _onChildNodeRemoved);
Inspector.Page.enable();
return _load.promise();
}

Expand Down
5 changes: 3 additions & 2 deletions src/LiveDevelopment/Agents/NetworkAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ define(function NetworkAgent(require, exports, module) {
/** Initialize the agent */
function load() {
_urlRequested = {};
Inspector.Network.enable();
$(Inspector.Network).on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
return Inspector.Network.enable().done(function () {
$(Inspector.Network).on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
});
}

/** Unload the agent */
Expand Down
24 changes: 12 additions & 12 deletions src/LiveDevelopment/Agents/RemoteAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ define(function RemoteAgent(require, exports, module) {

var $exports = $(exports);

var LiveDevelopment = require("LiveDevelopment/LiveDevelopment");
var Inspector = require("LiveDevelopment/Inspector/Inspector");
var LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
Inspector = require("LiveDevelopment/Inspector/Inspector"),
RemoteFunctions = require("text!LiveDevelopment/Agents/RemoteFunctions.js");

var _load; // deferred load
var _objectId; // the object id of the remote object
Expand All @@ -47,17 +48,16 @@ define(function RemoteAgent(require, exports, module) {
// WebInspector Event: Page.loadEventFired
function _onLoadEventFired(event, res) {
// res = {timestamp}
var request = new XMLHttpRequest();
request.open("GET", "LiveDevelopment/Agents/RemoteFunctions.js");
request.onload = function onLoad() {
var run = "window._LD=" + request.response + "(" + LiveDevelopment.config.experimental + ")";
Inspector.Runtime.evaluate(run, function onEvaluate(res) {
console.assert(!res.wasThrown, res.result.description);
_objectId = res.result.objectId;
var command = "window._LD=" + RemoteFunctions + "(" + LiveDevelopment.config.experimental + ")";

Inspector.Runtime.evaluate(command, function onEvaluate(response) {
if (response.error || response.wasThrown) {
_load.reject(null, response.error);
} else {
_objectId = response.result.objectId;
_load.resolve();
});
};
request.send(null);
}
});
}

// WebInspector Event: DOM.attributeModified
Expand Down
2 changes: 1 addition & 1 deletion src/LiveDevelopment/Agents/RemoteFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*jslint vars: true, plusplus: true, browser: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*global define, $, window, document, navigator */

/**
Expand Down
14 changes: 11 additions & 3 deletions src/LiveDevelopment/Agents/ScriptAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,23 @@ define(function ScriptAgent(require, exports, module) {
_urlToScript = {};
_idToScript = {};
_load = new $.Deferred();
Inspector.Debugger.enable();
Inspector.Debugger.setPauseOnExceptions("uncaught");

var enableResult = new $.Deferred();

Inspector.Debugger.enable().done(function () {
Inspector.Debugger.setPauseOnExceptions("uncaught").done(function () {
enableResult.resolve();
});
});

$(DOMAgent).on("getDocument.ScriptAgent", _onGetDocument);
$(Inspector.Debugger)
.on("scriptParsed.ScriptAgent", _onScriptParsed)
.on("scriptFailedToParse.ScriptAgent", _onScriptFailedToParse)
.on("paused.ScriptAgent", _onPaused);
$(Inspector.DOM).on("childNodeInserted.ScriptAgent", _onChildNodeInserted);
return _load;

return $.when(_load.promise(), enableResult.promise());
}

/** Clean up */
Expand Down
19 changes: 15 additions & 4 deletions src/LiveDevelopment/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,23 @@ define(function Inspector(require, exports, module) {
}

console.assert(_socket, "You must connect to the WebSocket before sending messages.");
var id, callback, args, i, params = {};
var id, callback, args, i, params = {}, promise;

// extract the parameters, the callback function, and the message id
args = Array.prototype.slice.call(arguments, 2);
if (typeof args[args.length - 1] === "function") {
id = _messageId++;
_messageCallbacks[id] = args.pop();
callback = args.pop();
} else {
id = 0;
var deferred = new $.Deferred();
promise = deferred.promise();
callback = function (result) {
deferred.resolve(result);
};
}

id = _messageId++;
_messageCallbacks[id] = callback;

// verify the parameters against the method signature
// this also constructs the params object of type {name -> value}
for (i in signature) {
Expand All @@ -141,6 +147,8 @@ define(function Inspector(require, exports, module) {
}
}
_socket.send(JSON.stringify({ method: method, id: id, params: params }));

return promise;
}

/** WebSocket did close */
Expand Down Expand Up @@ -182,6 +190,7 @@ define(function Inspector(require, exports, module) {
} else if (response.result) {
if (_messageCallbacks[response.id]) {
_messageCallbacks[response.id](response.result);
delete _messageCallbacks[response.id];
}
} else {
var domainAndMethod = response.method.split(".");
Expand Down Expand Up @@ -215,7 +224,9 @@ define(function Inspector(require, exports, module) {
request.onerror = function onError() {
def.reject(request.response);
};

request.send(null);

return def.promise();
}

Expand Down
46 changes: 27 additions & 19 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ define(function LiveDevelopment(require, exports, module) {
_liveDocument = _createDocument(doc, editor);

// Enable instrumentation
if (_liveDocument.setInstrumentationEnabled) {
if (_liveDocument && _liveDocument.setInstrumentationEnabled) {
var enableInstrumentation = false;

if (_serverProvider && _serverProvider.setRequestFilterPaths) {
Expand Down Expand Up @@ -403,8 +403,8 @@ define(function LiveDevelopment(require, exports, module) {

/** Load the agents */
function loadAgents() {
var name, promises = [];
var agentsToLoad;
var name, promises = [], agentsToLoad, promise;

if (exports.config.experimental) {
// load all agents
agentsToLoad = agents;
Expand All @@ -414,7 +414,12 @@ define(function LiveDevelopment(require, exports, module) {
}
for (name in agentsToLoad) {
if (agentsToLoad.hasOwnProperty(name) && agents[name] && agents[name].load) {
promises.push(agents[name].load());
promise = agents[name].load();

if (promise) {
promises.push(promise);
}

_loadedAgentNames.push(name);
}
}
Expand Down Expand Up @@ -542,8 +547,8 @@ define(function LiveDevelopment(require, exports, module) {

/** Triggered by Inspector.disconnect */
function _onDisconnect(event) {
$(Inspector.Inspector).off("detached", _onDetached);
$(Inspector.Page).off("frameNavigated.DOMAgent", _onFrameNavigated);
$(Inspector.Inspector).off("detached.livedev");
$(Inspector.Page).off("frameNavigated.livedev");

unloadAgents();
_closeDocument();
Expand Down Expand Up @@ -814,22 +819,25 @@ define(function LiveDevelopment(require, exports, module) {
* interstitial page has finished loading.
*/
function onInterstitialPageLoad() {
// Page domain must be enabled first before loading other agents
Inspector.Page.enable().done(function () {
// Load the right document (some agents are waiting for the page's load event)
var doc = _getCurrentDocument();
if (doc) {
Inspector.Page.navigate(doc.root.url);
} else {
close();
}
});

// Load agents
_setStatus(STATUS_LOADING_AGENTS);
var promises = loadAgents();
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);

// Load the right document (some agents are waiting for the page's load event)
var doc = _getCurrentDocument();
if (doc) {
Inspector.Page.navigate(doc.root.url);
} else {
close();
}
}

$(Inspector.Inspector).on("detached", _onDetached);
$(Inspector.Page).on("frameNavigated.DOMAgent", _onFrameNavigated);
$(Inspector.Inspector).on("detached.livedev", _onDetached);
$(Inspector.Page).on("frameNavigated.livedev", _onFrameNavigated);

waitForInterstitialPageLoad()
.fail(function () {
Expand Down Expand Up @@ -882,11 +890,11 @@ define(function LiveDevelopment(require, exports, module) {
function _onDocumentSaved(event, doc) {
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument &&
agents.network && agents.network.wasURLRequested(doc.url)) {
// Unload and reload agents before reloading the page
reconnect();

// Reload HTML page
Inspector.Page.reload();

// Reload unsaved changes
reconnect();
}
}

Expand Down