blob: 6e73f78f1903cb044707fa46e7c19dd0d1c5709c [file] [log] [blame]
<import src="/mojo/public/sky/connection.sky" as="connection" />
<import src="/mojo/public/sky/core.sky" as="core" />
<import src="/mojo/public/sky/support.sky" as="support" />
<import src="/sky/services/inspector/inspector.mojom.sky" as="inspector" />
<import src="console-agent.sky" as="ConsoleAgent" />
<import src="dom-agent.sky" as="DOMAgent" />
<import src="page-agent.sky" as="PageAgent" />
<import src="worker-agent.sky" as="WorkerAgent" />
<import src="runtime-agent.sky" as="RuntimeAgent" />
<import src="indexeddb-agent.sky" as="IndexedDBAgent" />
<import src="css-agent.sky" as="CSSAgent" />
<script>
function InspectorBackend(frontend) {
this.frontend = frontend;
var domAgent = new DOMAgent(this);
this.agents = {
Console: new ConsoleAgent(),
DOM: domAgent,
Page: new PageAgent(),
Worker: new WorkerAgent(),
Runtime: new RuntimeAgent(this),
CSS: new CSSAgent(domAgent),
IndexedDB: new IndexedDBAgent(),
};
this.missingNames_ = {};
}
InspectorBackend.prototype = Object.create(
inspector.InspectorBackend.stubClass.prototype);
InspectorBackend.prototype.onConnect = function() {
};
InspectorBackend.prototype.onDisconnect = function() {
};
InspectorBackend.prototype.logMissing_ = function(name) {
if (name in this.missingNames_)
return;
this.missingNames_[name] = true;
console.log("InspectorBackend missing " + name);
}
InspectorBackend.prototype.dispatch_ = function(descriptor, params) {
var parsed = descriptor.split('.');
var agentName = parsed[0];
var methodName = parsed[1];
if (!(agentName in this.agents)) {
this.logMissing_(agentName);
return {};
}
var agent = this.agents[agentName];
if (!(methodName in agent)) {
this.logMissing_(agentName + "." + methodName);
return {};
}
try {
return agent[methodName](params);
} catch(ex) {
console.log(descriptor + ": " + ex);
}
};
InspectorBackend.prototype.onMessage = function(data) {
var message = JSON.parse(data);
var result = this.dispatch_(message.method, message.params);
var response = {
id: message.id,
};
if (typeof result !== "undefined")
response.result = result;
this.frontend.sendMessage(JSON.stringify(response));
};
InspectorBackend.prototype.sendMessage = function(method, params) {
var message = JSON.stringify({
method: method,
params: params,
});
this.frontend.sendMessage(message);
};
var frontendHandle = internals.connectToService(
"mojo:sky_inspector_server", inspector.InspectorFrontend.name);
window.frontendConnection = new connection.Connection(
frontendHandle,
InspectorBackend,
inspector.InspectorFrontend.proxyClass);
window.frontend = frontendConnection.remote;
</script>