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

Live Preview fixes #6889

Merged
merged 15 commits into from
Mar 7, 2014
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
3 changes: 3 additions & 0 deletions src/LiveDevelopment/Agents/ConsoleAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ define(function ConsoleAgent(require, exports, module) {
level = "warn";
}
var text = "ConsoleAgent: " + message.text;
if (message.url) {
text += " (url: " + message.url + ")";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 404 error message provides a url that is not added to error message. This case I saw ended up not being related to this code, but this is good info to display.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

if (message.stackTrace) {
var callFrame = message.stackTrace[0];
text += " in " + callFrame.functionName + ":" + callFrame.columnNumber;
Expand Down
8 changes: 6 additions & 2 deletions src/LiveDevelopment/Agents/NetworkAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ define(function NetworkAgent(require, exports, module) {
_logURL(res.request.url);
}

function _reset() {
_urlRequested = {};
}

// WebInspector Event: Page.frameNavigated
function _onFrameNavigated(event, res) {
// res = {frame}
_reset();
_logURL(res.frame.url);
}

Expand All @@ -86,8 +91,7 @@ define(function NetworkAgent(require, exports, module) {

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

_reset();
$(Inspector.Page).off(".NetworkAgent");
$(Inspector.Network).off(".NetworkAgent");
}
Expand Down
13 changes: 3 additions & 10 deletions src/LiveDevelopment/Agents/RemoteAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,11 @@ define(function RemoteAgent(require, exports, module) {
call("keepAlive");
}, 1000);
}

/**
* @private
* Cancel the keepAlive interval if the page reloads
*/
function _onFrameStartedLoading(event, res) {
_stopKeepAliveInterval();
}


// WebInspector Event: Page.frameNavigated
function _onFrameNavigated(event, res) {
// res = {timestamp}
_stopKeepAliveInterval();

// inject RemoteFunctions
var command = "window._LD=" + RemoteFunctions + "(" + LiveDevelopment.config.experimental + ");";
Expand All @@ -153,7 +146,7 @@ define(function RemoteAgent(require, exports, module) {
function load() {
_load = new $.Deferred();
$(Inspector.Page).on("frameNavigated.RemoteAgent", _onFrameNavigated);
$(Inspector.Page).on("frameStartedLoading.RemoteAgent", _onFrameStartedLoading);
$(Inspector.Page).on("frameStartedLoading.RemoteAgent", _stopKeepAliveInterval);
$(Inspector.DOM).on("attributeModified.RemoteAgent", _onAttributeModified);

return _load.promise();
Expand Down
22 changes: 20 additions & 2 deletions src/LiveDevelopment/Agents/ScriptAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,25 @@ define(function ScriptAgent(require, exports, module) {

}

/** Initialize the agent */
function load() {
function _reset() {
_urlToScript = {};
_idToScript = {};
}

/**
* @private
* WebInspector Event: Page.frameNavigated
* @param {jQuery.Event} event
* @param {frame: Frame} res
*/
function _onFrameNavigated(event, res) {
// Clear maps when navigating to a new page
_reset();
}

/** Initialize the agent */
function load() {
_reset();
_load = new $.Deferred();

var enableResult = new $.Deferred();
Expand All @@ -131,6 +146,7 @@ define(function ScriptAgent(require, exports, module) {
});
});

$(Inspector.Page).on("frameNavigated.ScriptAgent", _onFrameNavigated);
$(DOMAgent).on("getDocument.ScriptAgent", _onGetDocument);
$(Inspector.Debugger)
.on("scriptParsed.ScriptAgent", _onScriptParsed)
Expand All @@ -143,6 +159,8 @@ define(function ScriptAgent(require, exports, module) {

/** Clean up */
function unload() {
_reset();
$(Inspector.Page).off(".ScriptAgent");
$(DOMAgent).off(".ScriptAgent");
$(Inspector.Debugger).off(".ScriptAgent");
$(Inspector.DOM).off(".ScriptAgent");
Expand Down
25 changes: 17 additions & 8 deletions src/LiveDevelopment/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ define(function Inspector(require, exports, module) {
// jQuery exports object for events
var $exports = $(exports);

/**
* Map message IDs to the callback function and original JSON message
* @type {Object.<number, {callback: function, message: Object}}
*/
var _messageCallbacks = {};

var _messageId = 1; // id used for remote method calls, auto-incrementing
var _messageCallbacks = {}; // {id -> function} for remote method calls
var _socket; // remote debugger WebSocket
var _connectDeferred; // The deferred connect

Expand Down Expand Up @@ -125,7 +130,7 @@ define(function Inspector(require, exports, module) {
return (new $.Deferred()).reject().promise();
}

var id, callback, args, i, params = {}, promise;
var id, callback, args, i, params = {}, promise, msg;

// extract the parameters, the callback function, and the message id
args = Array.prototype.slice.call(arguments, 2);
Expand All @@ -144,7 +149,6 @@ define(function Inspector(require, exports, module) {
}

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

// verify the parameters against the method signature
// this also constructs the params object of type {name -> value}
Expand All @@ -156,7 +160,10 @@ define(function Inspector(require, exports, module) {
}
}

_socket.send(JSON.stringify({ method: method, id: id, params: params }));
// Store message callback and send message
msg = { method: method, id: id, params: params };
_messageCallbacks[id] = { callback: callback, message: msg };
_socket.send(JSON.stringify(msg));

return promise;
}
Expand Down Expand Up @@ -204,10 +211,12 @@ define(function Inspector(require, exports, module) {
* @param {object} message
*/
function _onMessage(message) {
var response = JSON.parse(message.data),
callback = _messageCallbacks[response.id];
var response = JSON.parse(message.data),
msgRecord = _messageCallbacks[response.id],
callback = msgRecord && msgRecord.callback,
msgText = (msgRecord && msgRecord.message) || "No message";

if (callback) {
if (msgRecord) {
// Messages with an ID are a response to a command, fire callback
callback(response.result, response.error);
delete _messageCallbacks[response.id];
Expand All @@ -224,7 +233,7 @@ define(function Inspector(require, exports, module) {
$exports.triggerHandler("message", [response]);

if (response.error) {
$exports.triggerHandler("error", [response.error]);
$exports.triggerHandler("error", [response.error, msgText]);
}
}

Expand Down
Loading