Commit 087f2421 authored by sergeyv@chromium.org's avatar sergeyv@chromium.org

DevTools: Show worker context in consoleView

BUG=

Review URL: https://codereview.chromium.org/196133031

git-svn-id: svn://svn.chromium.org/blink/trunk@169855 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 67333eb2
...@@ -43,6 +43,7 @@ WebInspector.ConsoleModel = function(target) ...@@ -43,6 +43,7 @@ WebInspector.ConsoleModel = function(target)
this._target = target; this._target = target;
this._consoleAgent = target.consoleAgent(); this._consoleAgent = target.consoleAgent();
target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this));
this._enableAgent();
} }
WebInspector.ConsoleModel.Events = { WebInspector.ConsoleModel.Events = {
...@@ -53,7 +54,7 @@ WebInspector.ConsoleModel.Events = { ...@@ -53,7 +54,7 @@ WebInspector.ConsoleModel.Events = {
} }
WebInspector.ConsoleModel.prototype = { WebInspector.ConsoleModel.prototype = {
enableAgent: function() _enableAgent: function()
{ {
if (WebInspector.settings.monitoringXHREnabled.get()) if (WebInspector.settings.monitoringXHREnabled.get())
this._consoleAgent.setMonitoringXHREnabled(true); this._consoleAgent.setMonitoringXHREnabled(true);
......
...@@ -97,11 +97,6 @@ WebInspector.ConsoleView = function(hideContextSelector) ...@@ -97,11 +97,6 @@ WebInspector.ConsoleView = function(hideContextSelector)
WebInspector.settings.monitoringXHREnabled.addChangeListener(this._monitoringXHREnabledSettingChanged.bind(this)); WebInspector.settings.monitoringXHREnabled.addChangeListener(this._monitoringXHREnabledSettingChanged.bind(this));
WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdded, this);
WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.RepeatCountUpdated, this._repeatCountUpdated, this);
WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this);
this._linkifier = new WebInspector.Linkifier(); this._linkifier = new WebInspector.Linkifier();
/** @type {!Map.<!WebInspector.ConsoleMessage, !WebInspector.ConsoleViewMessage>} */ /** @type {!Map.<!WebInspector.ConsoleMessage, !WebInspector.ConsoleViewMessage>} */
...@@ -109,25 +104,15 @@ WebInspector.ConsoleView = function(hideContextSelector) ...@@ -109,25 +104,15 @@ WebInspector.ConsoleView = function(hideContextSelector)
/** @type {!Array.<!WebInspector.ConsoleMessage>} */ /** @type {!Array.<!WebInspector.ConsoleMessage>} */
this._consoleMessages = []; this._consoleMessages = [];
this.prompt = new WebInspector.TextPromptWithHistory(WebInspector.runtimeModel.completionsForTextPrompt.bind(WebInspector.runtimeModel)); this.prompt = new WebInspector.TextPromptWithHistory(this._completionsForTextPrompt.bind(this));
this.prompt.setSuggestBoxEnabled("generic-suggest"); this.prompt.setSuggestBoxEnabled("generic-suggest");
this.prompt.renderAsBlock(); this.prompt.renderAsBlock();
this.prompt.attach(this.promptElement); this.prompt.attach(this.promptElement);
this.prompt.proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false); this.prompt.proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false);
this.prompt.setHistoryData(WebInspector.settings.consoleHistory.get()); this.prompt.setHistoryData(WebInspector.settings.consoleHistory.get());
/** WebInspector.targetManager.targets().forEach(this._targetAdded, this);
* @param {!WebInspector.ExecutionContextList} contextList WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Events.TargetAdded, this._onTargetAdded, this);
* @this {WebInspector.ConsoleView}
*/
function loadContextList(contextList)
{
this._addExecutionContextList(contextList);
this._contextListChanged(contextList);
}
WebInspector.runtimeModel.contextLists().forEach(loadContextList, this);
WebInspector.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextListAdded, this._executionContextListAdded, this);
WebInspector.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextListRemoved, this._executionContextListRemoved, this);
this._filterStatusMessageElement = document.createElement("div"); this._filterStatusMessageElement = document.createElement("div");
this._filterStatusMessageElement.classList.add("console-message"); this._filterStatusMessageElement.classList.add("console-message");
...@@ -140,13 +125,43 @@ WebInspector.ConsoleView = function(hideContextSelector) ...@@ -140,13 +125,43 @@ WebInspector.ConsoleView = function(hideContextSelector)
this.messagesElement.insertBefore(this._filterStatusMessageElement, this.topGroup.element); this.messagesElement.insertBefore(this._filterStatusMessageElement, this.topGroup.element);
this._updateFilterStatus(); this._updateFilterStatus();
WebInspector.console.messages.forEach(function(message) {
this._consoleMessageAdded(message);
}.bind(this));
} }
WebInspector.ConsoleView.prototype = { WebInspector.ConsoleView.prototype = {
/**
* @param {!WebInspector.Event} event
*/
_onTargetAdded: function(event)
{
this._targetAdded(/**@type {!WebInspector.Target} */(event.data));
},
/**
* @param {!WebInspector.Target} target
*/
_targetAdded: function(target)
{
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdded.bind(this, target), this);
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.RepeatCountUpdated, this._repeatCountUpdated, this);
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this);
target.consoleModel.messages.forEach(this._consoleMessageAdded.bind(this, target));
/**
* @param {!WebInspector.ExecutionContextList} contextList
* @this {WebInspector.ConsoleView}
*/
function loadContextList(contextList)
{
this._addExecutionContextList(target, contextList);
this._contextListChanged(target, contextList);
}
target.runtimeModel.contextLists().forEach(loadContextList, this);
target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextListAdded, this._executionContextListAdded.bind(this, target));
target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextListRemoved, this._executionContextListRemoved, this);
},
/** /**
* @return {!Element} * @return {!Element}
*/ */
...@@ -164,25 +179,26 @@ WebInspector.ConsoleView.prototype = { ...@@ -164,25 +179,26 @@ WebInspector.ConsoleView.prototype = {
/** /**
* @param {!WebInspector.Event} event * @param {!WebInspector.Event} event
*/ */
_executionContextListAdded: function(event) _executionContextListAdded: function(target, event)
{ {
var contextList = /** @type {!WebInspector.ExecutionContextList} */ (event.data); var contextList = /** @type {!WebInspector.ExecutionContextList} */ (event.data);
this._addExecutionContextList(contextList); this._addExecutionContextList(target, contextList);
}, },
/** /**
* @param {!WebInspector.ExecutionContextList} contextList * @param {!WebInspector.ExecutionContextList} contextList
*/ */
_addExecutionContextList: function(contextList) _addExecutionContextList: function(target, contextList)
{ {
var maxLength = 50; var maxLength = 50;
var topLevelOption = this._executionContextSelector.createOption(contextList.displayName().trimMiddle(maxLength), contextList.url()); var topLevelOption = this._executionContextSelector.createOption(contextList.displayName().trimMiddle(maxLength), contextList.url());
topLevelOption._executionContext = null; topLevelOption._executionContext = null;
topLevelOption._target = target;
this._topLevelOptionByContextListId[contextList.id()] = topLevelOption; this._topLevelOptionByContextListId[contextList.id()] = topLevelOption;
this._subOptionsByContextListId[contextList.id()] = []; this._subOptionsByContextListId[contextList.id()] = [];
contextList.addEventListener(WebInspector.ExecutionContextList.EventTypes.Reset, this._contextListReset, this); contextList.addEventListener(WebInspector.ExecutionContextList.EventTypes.Reset, this._contextListReset, this);
contextList.addEventListener(WebInspector.ExecutionContextList.EventTypes.ContextAdded, this._contextListChanged.bind(this, contextList), this); contextList.addEventListener(WebInspector.ExecutionContextList.EventTypes.ContextAdded, this._contextListChanged.bind(this, target, contextList));
}, },
/** /**
...@@ -218,9 +234,12 @@ WebInspector.ConsoleView.prototype = { ...@@ -218,9 +234,12 @@ WebInspector.ConsoleView.prototype = {
_executionContextChanged: function() _executionContextChanged: function()
{ {
var runtimeContext = WebInspector.runtimeModel.currentExecutionContext(); var runtimeModel = this._currentTarget().runtimeModel;
var runtimeContext = runtimeModel.currentExecutionContext();
if (this._currentExecutionContext() !== runtimeContext) if (this._currentExecutionContext() !== runtimeContext)
WebInspector.runtimeModel.setCurrentExecutionContext(this._currentExecutionContext()); runtimeModel.setCurrentExecutionContext(this._currentExecutionContext());
this.prompt.clearAutoComplete(true);
}, },
/** /**
...@@ -232,6 +251,26 @@ WebInspector.ConsoleView.prototype = { ...@@ -232,6 +251,26 @@ WebInspector.ConsoleView.prototype = {
return option ? option._executionContext : null; return option ? option._executionContext : null;
}, },
/**
* @return {!WebInspector.Target}
*/
_currentTarget: function()
{
var option = this._executionContextSelector.selectedOption();
return option ? option._target : WebInspector.targetManager.mainTarget();
},
/**
* @param {!Element} proxyElement
* @param {!Range} wordRange
* @param {boolean} force
* @param {function(!Array.<string>, number=)} completionsReadyCallback
*/
_completionsForTextPrompt: function(proxyElement, wordRange, force, completionsReadyCallback)
{
this._currentTarget().runtimeModel.completionsForTextPrompt(proxyElement, wordRange, force, completionsReadyCallback);
},
/** /**
* @param {!WebInspector.Event} event * @param {!WebInspector.Event} event
*/ */
...@@ -254,7 +293,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -254,7 +293,7 @@ WebInspector.ConsoleView.prototype = {
/** /**
* @param {!WebInspector.ExecutionContextList} contextList * @param {!WebInspector.ExecutionContextList} contextList
*/ */
_contextListChanged: function(contextList) _contextListChanged: function(target, contextList)
{ {
var currentExecutionContext = this._currentExecutionContext(); var currentExecutionContext = this._currentExecutionContext();
var shouldSelectOption = this._removeSubOptions(contextList.id()); var shouldSelectOption = this._removeSubOptions(contextList.id());
...@@ -271,6 +310,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -271,6 +310,7 @@ WebInspector.ConsoleView.prototype = {
var subOption = document.createElement("option"); var subOption = document.createElement("option");
subOption.text = "\u00a0\u00a0\u00a0\u00a0" + executionContexts[i].name; subOption.text = "\u00a0\u00a0\u00a0\u00a0" + executionContexts[i].name;
subOption._executionContext = executionContexts[i]; subOption._executionContext = executionContexts[i];
subOption._target = target;
this._executionContextSelector.selectElement().insertBefore(subOption, nextTopLevelOption); this._executionContextSelector.selectElement().insertBefore(subOption, nextTopLevelOption);
subOptions.push(subOption); subOptions.push(subOption);
...@@ -374,10 +414,10 @@ WebInspector.ConsoleView.prototype = { ...@@ -374,10 +414,10 @@ WebInspector.ConsoleView.prototype = {
/** /**
* @param {!WebInspector.ConsoleMessage} message * @param {!WebInspector.ConsoleMessage} message
*/ */
_consoleMessageAdded: function(message) _consoleMessageAdded: function(target, message)
{ {
this._consoleMessages.push(message); this._consoleMessages.push(message);
var viewMessage = this._createViewMessage(message); var viewMessage = this._createViewMessage(target, message);
if (this._urlToMessageCount[message.url]) if (this._urlToMessageCount[message.url])
this._urlToMessageCount[message.url]++; this._urlToMessageCount[message.url]++;
else else
...@@ -392,10 +432,10 @@ WebInspector.ConsoleView.prototype = { ...@@ -392,10 +432,10 @@ WebInspector.ConsoleView.prototype = {
/** /**
* @param {!WebInspector.Event} event * @param {!WebInspector.Event} event
*/ */
_onConsoleMessageAdded: function(event) _onConsoleMessageAdded: function(target, event)
{ {
var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data); var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data);
this._consoleMessageAdded(message); this._consoleMessageAdded(target, message);
}, },
/** /**
...@@ -436,15 +476,15 @@ WebInspector.ConsoleView.prototype = { ...@@ -436,15 +476,15 @@ WebInspector.ConsoleView.prototype = {
* @param {!WebInspector.ConsoleMessage} message * @param {!WebInspector.ConsoleMessage} message
* @return {!WebInspector.ConsoleViewMessage} * @return {!WebInspector.ConsoleViewMessage}
*/ */
_createViewMessage: function(message) _createViewMessage: function(target, message)
{ {
var viewMessage = this._messageToViewMessage.get(message); var viewMessage = this._messageToViewMessage.get(message);
if (viewMessage) if (viewMessage)
return viewMessage; return viewMessage;
if (message.type === WebInspector.ConsoleMessage.MessageType.Command) if (message.type === WebInspector.ConsoleMessage.MessageType.Command)
viewMessage = new WebInspector.ConsoleCommand(message); viewMessage = new WebInspector.ConsoleCommand(target, message);
else else
viewMessage = new WebInspector.ConsoleViewMessage(message, this._linkifier); viewMessage = new WebInspector.ConsoleViewMessage(target, message, this._linkifier);
this._messageToViewMessage.put(message, viewMessage); this._messageToViewMessage.put(message, viewMessage);
return viewMessage; return viewMessage;
}, },
...@@ -683,6 +723,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -683,6 +723,7 @@ WebInspector.ConsoleView.prototype = {
if (!result) if (!result)
return; return;
var target = result.target();
/** /**
* @param {string=} url * @param {string=} url
* @param {number=} lineNumber * @param {number=} lineNumber
...@@ -693,7 +734,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -693,7 +734,7 @@ WebInspector.ConsoleView.prototype = {
{ {
var resultMessage = new WebInspector.ConsoleCommandResult(/** @type {!WebInspector.RemoteObject} */ (result), wasThrown, originatingCommand, this._linkifier, url, lineNumber, columnNumber); var resultMessage = new WebInspector.ConsoleCommandResult(/** @type {!WebInspector.RemoteObject} */ (result), wasThrown, originatingCommand, this._linkifier, url, lineNumber, columnNumber);
this._messageToViewMessage.put(resultMessage.consoleMessage(), resultMessage); this._messageToViewMessage.put(resultMessage.consoleMessage(), resultMessage);
WebInspector.console.addMessage(resultMessage.consoleMessage()); target.consoleModel.addMessage(resultMessage.consoleMessage());
} }
if (result.type !== "function") { if (result.type !== "function") {
...@@ -701,7 +742,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -701,7 +742,7 @@ WebInspector.ConsoleView.prototype = {
return; return;
} }
DebuggerAgent.getFunctionDetails(result.objectId, didGetDetails.bind(this)); target.debuggerAgent().getFunctionDetails(result.objectId, didGetDetails.bind(this));
/** /**
* @param {?Protocol.Error} error * @param {?Protocol.Error} error
...@@ -736,7 +777,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -736,7 +777,7 @@ WebInspector.ConsoleView.prototype = {
_appendCommand: function(text, useCommandLineAPI) _appendCommand: function(text, useCommandLineAPI)
{ {
this.prompt.text = ""; this.prompt.text = "";
WebInspector.console.evaluateCommand(text, useCommandLineAPI); this._currentTarget().consoleModel.evaluateCommand(text, useCommandLineAPI);
}, },
/** /**
...@@ -945,9 +986,9 @@ WebInspector.ConsoleViewFilter.prototype = { ...@@ -945,9 +986,9 @@ WebInspector.ConsoleViewFilter.prototype = {
* @extends {WebInspector.ConsoleViewMessage} * @extends {WebInspector.ConsoleViewMessage}
* @param {!WebInspector.ConsoleMessage} message * @param {!WebInspector.ConsoleMessage} message
*/ */
WebInspector.ConsoleCommand = function(message) WebInspector.ConsoleCommand = function(target, message)
{ {
WebInspector.ConsoleViewMessage.call(this, message, null); WebInspector.ConsoleViewMessage.call(this, target, message, null);
} }
WebInspector.ConsoleCommand.prototype = { WebInspector.ConsoleCommand.prototype = {
...@@ -1035,7 +1076,7 @@ WebInspector.ConsoleCommandResult = function(result, wasThrown, originatingComma ...@@ -1035,7 +1076,7 @@ WebInspector.ConsoleCommandResult = function(result, wasThrown, originatingComma
this.originatingCommand = originatingCommand; this.originatingCommand = originatingCommand;
var level = wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log; var level = wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log;
var message = new WebInspector.ConsoleMessage(WebInspector.ConsoleMessage.MessageSource.JS, level, "", WebInspector.ConsoleMessage.MessageType.Result, url, lineNumber, columnNumber, undefined, undefined, [result]); var message = new WebInspector.ConsoleMessage(WebInspector.ConsoleMessage.MessageSource.JS, level, "", WebInspector.ConsoleMessage.MessageType.Result, url, lineNumber, columnNumber, undefined, undefined, [result]);
WebInspector.ConsoleViewMessage.call(this, message, linkifier); WebInspector.ConsoleViewMessage.call(this, result.target(), message, linkifier);
} }
WebInspector.ConsoleCommandResult.prototype = { WebInspector.ConsoleCommandResult.prototype = {
......
...@@ -34,10 +34,11 @@ ...@@ -34,10 +34,11 @@
* @param {!WebInspector.ConsoleMessage} consoleMessage * @param {!WebInspector.ConsoleMessage} consoleMessage
* @param {?WebInspector.Linkifier} linkifier * @param {?WebInspector.Linkifier} linkifier
*/ */
WebInspector.ConsoleViewMessage = function(consoleMessage, linkifier) WebInspector.ConsoleViewMessage = function(target, consoleMessage, linkifier)
{ {
this._message = consoleMessage; this._message = consoleMessage;
this._linkifier = linkifier; this._linkifier = linkifier;
this._target = target;
/** @type {!Array.<!WebInspector.DataGrid>} */ /** @type {!Array.<!WebInspector.DataGrid>} */
this._dataGrids = []; this._dataGrids = [];
...@@ -268,9 +269,9 @@ WebInspector.ConsoleViewMessage.prototype = { ...@@ -268,9 +269,9 @@ WebInspector.ConsoleViewMessage.prototype = {
continue; continue;
if (typeof parameters[i] === "object") if (typeof parameters[i] === "object")
parameters[i] = WebInspector.RemoteObject.fromPayload(parameters[i]); parameters[i] = WebInspector.RemoteObject.fromPayload(parameters[i], this._target);
else else
parameters[i] = WebInspector.RemoteObject.fromPrimitiveValue(parameters[i]); parameters[i] = WebInspector.RemoteObject.fromPrimitiveValue(parameters[i], this._target);
} }
// There can be string log and string eval result. We distinguish between them based on message type. // There can be string log and string eval result. We distinguish between them based on message type.
......
...@@ -368,8 +368,6 @@ WebInspector.Main.prototype = { ...@@ -368,8 +368,6 @@ WebInspector.Main.prototype = {
WebInspector.extensionServerProxy.setFrontendReady(); WebInspector.extensionServerProxy.setFrontendReady();
WebInspector.console.enableAgent();
WebInspector.databaseModel = new WebInspector.DatabaseModel(); WebInspector.databaseModel = new WebInspector.DatabaseModel();
WebInspector.domStorageModel = new WebInspector.DOMStorageModel(); WebInspector.domStorageModel = new WebInspector.DOMStorageModel();
WebInspector.cpuProfilerModel = new WebInspector.CPUProfilerModel(); WebInspector.cpuProfilerModel = new WebInspector.CPUProfilerModel();
......
...@@ -101,6 +101,11 @@ WebInspector.RemoteObject.prototype = { ...@@ -101,6 +101,11 @@ WebInspector.RemoteObject.prototype = {
* @param {function(*)} callback * @param {function(*)} callback
*/ */
callFunctionJSON: function(functionDeclaration, args, callback) callFunctionJSON: function(functionDeclaration, args, callback)
{
throw "Not implemented";
},
target: function()
{ {
throw "Not implemented"; throw "Not implemented";
} }
...@@ -114,6 +119,10 @@ WebInspector.RemoteObject.prototype = { ...@@ -114,6 +119,10 @@ WebInspector.RemoteObject.prototype = {
*/ */
WebInspector.RemoteObject.fromPrimitiveValue = function(value, target) WebInspector.RemoteObject.fromPrimitiveValue = function(value, target)
{ {
//FIXME: we should always pass non-undefined target
if (!target)
target = WebInspector.targetManager.mainTarget();
return new WebInspector.RemoteObjectImpl(target, undefined, typeof value, undefined, value); return new WebInspector.RemoteObjectImpl(target, undefined, typeof value, undefined, value);
} }
...@@ -157,6 +166,10 @@ WebInspector.RemoteObject.resolveNode = function(node, objectGroup, callback) ...@@ -157,6 +166,10 @@ WebInspector.RemoteObject.resolveNode = function(node, objectGroup, callback)
*/ */
WebInspector.RemoteObject.fromPayload = function(payload, target) WebInspector.RemoteObject.fromPayload = function(payload, target)
{ {
//FIXME: we should always pass non-undefined target
if (!target)
target = WebInspector.targetManager.mainTarget();
console.assert(typeof payload === "object", "Remote object payload should only be an object"); console.assert(typeof payload === "object", "Remote object payload should only be an object");
return new WebInspector.RemoteObjectImpl(target, payload.objectId, payload.type, payload.subtype, payload.value, payload.description, payload.preview); return new WebInspector.RemoteObjectImpl(target, payload.objectId, payload.type, payload.subtype, payload.value, payload.description, payload.preview);
...@@ -209,7 +222,7 @@ WebInspector.RemoteObject.toCallArgument = function(remoteObject) ...@@ -209,7 +222,7 @@ WebInspector.RemoteObject.toCallArgument = function(remoteObject)
/** /**
* @constructor * @constructor
* @extends {WebInspector.RemoteObject} * @extends {WebInspector.RemoteObject}
* @param {!WebInspector.Target|undefined} target * @param {!WebInspector.Target} target
* @param {string|undefined} objectId * @param {string|undefined} objectId
* @param {string} type * @param {string} type
* @param {string|undefined} subtype * @param {string|undefined} subtype
...@@ -220,14 +233,9 @@ WebInspector.RemoteObject.toCallArgument = function(remoteObject) ...@@ -220,14 +233,9 @@ WebInspector.RemoteObject.toCallArgument = function(remoteObject)
WebInspector.RemoteObjectImpl = function(target, objectId, type, subtype, value, description, preview) WebInspector.RemoteObjectImpl = function(target, objectId, type, subtype, value, description, preview)
{ {
WebInspector.RemoteObject.call(this); WebInspector.RemoteObject.call(this);
if (target) { this._target = target;
this._runtimeAgent = target.runtimeAgent(); this._runtimeAgent = target.runtimeAgent();
this._domAgent = target.domModel; this._domAgent = target.domModel;
} else {
//FIXME: remove this logic once every RemoteObjectImpl constructor call has non-undefined target
this._runtimeAgent = RuntimeAgent;
this._domAgent = WebInspector.domAgent;
}
this._type = type; this._type = type;
this._subtype = subtype; this._subtype = subtype;
...@@ -523,6 +531,14 @@ WebInspector.RemoteObjectImpl.prototype = { ...@@ -523,6 +531,14 @@ WebInspector.RemoteObjectImpl.prototype = {
return parseInt(matches[1], 10); return parseInt(matches[1], 10);
}, },
/**
* @return {!WebInspector.Target}
*/
target: function()
{
return this._target;
},
__proto__: WebInspector.RemoteObject.prototype __proto__: WebInspector.RemoteObject.prototype
}; };
...@@ -598,7 +614,7 @@ WebInspector.RemoteObject.loadFromObjectPerProto = function(object, callback) ...@@ -598,7 +614,7 @@ WebInspector.RemoteObject.loadFromObjectPerProto = function(object, callback)
/** /**
* @constructor * @constructor
* @extends {WebInspector.RemoteObjectImpl} * @extends {WebInspector.RemoteObjectImpl}
* @param {!WebInspector.Target|undefined} target * @param {!WebInspector.Target} target
* @param {string|undefined} objectId * @param {string|undefined} objectId
* @param {!WebInspector.ScopeRef} scopeRef * @param {!WebInspector.ScopeRef} scopeRef
* @param {string} type * @param {string} type
...@@ -612,8 +628,7 @@ WebInspector.ScopeRemoteObject = function(target, objectId, scopeRef, type, subt ...@@ -612,8 +628,7 @@ WebInspector.ScopeRemoteObject = function(target, objectId, scopeRef, type, subt
WebInspector.RemoteObjectImpl.call(this, target, objectId, type, subtype, value, description, preview); WebInspector.RemoteObjectImpl.call(this, target, objectId, type, subtype, value, description, preview);
this._scopeRef = scopeRef; this._scopeRef = scopeRef;
this._savedScopeProperties = undefined; this._savedScopeProperties = undefined;
//FIXME: remove this logic once every RemoteObjectImpl constructor call has non-undefined target this._debuggerAgent = target.debuggerAgent();
this._debuggerAgent = target ? target.debuggerAgent() : DebuggerAgent;
}; };
/** /**
...@@ -624,6 +639,10 @@ WebInspector.ScopeRemoteObject = function(target, objectId, scopeRef, type, subt ...@@ -624,6 +639,10 @@ WebInspector.ScopeRemoteObject = function(target, objectId, scopeRef, type, subt
*/ */
WebInspector.ScopeRemoteObject.fromPayload = function(payload, scopeRef, target) WebInspector.ScopeRemoteObject.fromPayload = function(payload, scopeRef, target)
{ {
//FIXME: we should always pass non-undefined target
if (!target)
target = WebInspector.targetManager.mainTarget();
if (scopeRef) if (scopeRef)
return new WebInspector.ScopeRemoteObject(target, payload.objectId, scopeRef, payload.type, payload.subtype, payload.value, payload.description, payload.preview); return new WebInspector.ScopeRemoteObject(target, payload.objectId, scopeRef, payload.type, payload.subtype, payload.value, payload.description, payload.preview);
else else
......
...@@ -62,7 +62,7 @@ WebInspector.Target.prototype = { ...@@ -62,7 +62,7 @@ WebInspector.Target.prototype = {
if (!WebInspector.domAgent) if (!WebInspector.domAgent)
WebInspector.domAgent = this.domModel; WebInspector.domAgent = this.domModel;
this.workerManager = new WebInspector.WorkerManager(this.isMainFrontend); this.workerManager = new WebInspector.WorkerManager(this, this.isMainFrontend);
if (!WebInspector.workerManager) if (!WebInspector.workerManager)
WebInspector.workerManager = this.workerManager; WebInspector.workerManager = this.workerManager;
...@@ -93,13 +93,19 @@ WebInspector.Target.prototype = { ...@@ -93,13 +93,19 @@ WebInspector.Target.prototype = {
/** /**
* @constructor * @constructor
* @extends {WebInspector.Object}
*/ */
WebInspector.TargetManager = function() WebInspector.TargetManager = function()
{ {
WebInspector.Object.call(this);
/** @type {!Array.<!WebInspector.Target>} */ /** @type {!Array.<!WebInspector.Target>} */
this._targets = []; this._targets = [];
} }
WebInspector.TargetManager.Events = {
TargetAdded: "TargetAdded",
}
WebInspector.TargetManager.prototype = { WebInspector.TargetManager.prototype = {
/** /**
...@@ -108,8 +114,43 @@ WebInspector.TargetManager.prototype = { ...@@ -108,8 +114,43 @@ WebInspector.TargetManager.prototype = {
*/ */
createTarget: function(connection, callback) createTarget: function(connection, callback)
{ {
var newTarget = new WebInspector.Target(connection, callback); var target = new WebInspector.Target(connection, callbackWrapper.bind(this));
this._targets.push(newTarget);
} /**
* @this {WebInspector.TargetManager}
* @param newTarget
*/
function callbackWrapper(newTarget)
{
if (callback)
callback(newTarget);
this._targets.push(newTarget);
this.dispatchEventToListeners(WebInspector.TargetManager.Events.TargetAdded, newTarget);
}
},
/**
* @return {!Array.<!WebInspector.Target>}
*/
targets: function()
{
return this._targets;
},
/**
* @return {!WebInspector.Target}
*/
mainTarget: function()
{
return this._targets[0];
},
__proto__: WebInspector.Object.prototype
} }
/**
* @type {!WebInspector.TargetManager}
*/
WebInspector.targetManager;
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
* @extends {WebInspector.Object} * @extends {WebInspector.Object}
* @param {boolean} isMainFrontend * @param {boolean} isMainFrontend
*/ */
WebInspector.WorkerManager = function(isMainFrontend) WebInspector.WorkerManager = function(target, isMainFrontend)
{ {
this._reset(); this._reset();
InspectorBackend.registerWorkerDispatcher(new WebInspector.WorkerDispatcher(this)); target.registerWorkerDispatcher(new WebInspector.WorkerDispatcher(this));
if (isMainFrontend) { if (isMainFrontend) {
WorkerAgent.enable(); WorkerAgent.enable();
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this); WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment