OLD | NEW |
(Empty) | |
| 1 <link rel="import" href="/mojo/public/html/connection.html" as="connection" /> |
| 2 <link rel="import" href="/mojo/public/html/core.html" as="core" /> |
| 3 <link rel="import" href="/mojo/public/html/support.html" as="support" /> |
| 4 <link rel="import" href="/sky/framework/inspector/server/inspector.mojom.html" a
s="inspector" /> |
| 5 <link rel="import" href="console-agent.sky" as="ConsoleAgent" /> |
| 6 <link rel="import" href="dom-agent.sky" as="DOMAgent" /> |
| 7 <link rel="import" href="page-agent.sky" as="PageAgent" /> |
| 8 <link rel="import" href="worker-agent.sky" as="WorkerAgent" /> |
| 9 <script> |
| 10 function InspectorBackend(frontend) { |
| 11 this.frontend = frontend; |
| 12 this.agents = { |
| 13 Console: new ConsoleAgent(), |
| 14 DOM: new DOMAgent(this), |
| 15 Page: new PageAgent(), |
| 16 Worker: new WorkerAgent(), |
| 17 }; |
| 18 } |
| 19 |
| 20 InspectorBackend.prototype = Object.create( |
| 21 inspector.InspectorBackend.stubClass.prototype); |
| 22 |
| 23 InspectorBackend.prototype.onConnect = function() { |
| 24 }; |
| 25 |
| 26 InspectorBackend.prototype.onDisconnect = function() { |
| 27 }; |
| 28 |
| 29 InspectorBackend.prototype.dispatch_ = function(descriptor, params) { |
| 30 var parsed = descriptor.split('.'); |
| 31 |
| 32 var agentName = parsed[0]; |
| 33 var methodName = parsed[1]; |
| 34 |
| 35 if (!(agentName in this.agents)) { |
| 36 console.log("InspectorBackend cannot find agent " + agentName); |
| 37 return {}; |
| 38 } |
| 39 |
| 40 var agent = this.agents[agentName]; |
| 41 |
| 42 if (!(methodName in agent)) { |
| 43 console.log("InspectorBackend cannot find method " + |
| 44 methodName + " on agent " + agentName); |
| 45 return {}; |
| 46 } |
| 47 |
| 48 try { |
| 49 return agent[methodName](params); |
| 50 } catch(ex) { |
| 51 console.log(descriptor + ": " + ex); |
| 52 } |
| 53 }; |
| 54 |
| 55 InspectorBackend.prototype.onMessage = function(data) { |
| 56 var message = JSON.parse(data); |
| 57 var result = this.dispatch_(message.method, message.params); |
| 58 var response = { |
| 59 id: message.id, |
| 60 }; |
| 61 if (typeof result !== "undefined") |
| 62 response.result = result; |
| 63 this.frontend.sendMessage(JSON.stringify(response)); |
| 64 }; |
| 65 |
| 66 InspectorBackend.prototype.sendMessage = function(method, params) { |
| 67 var message = JSON.stringify({ |
| 68 method: method, |
| 69 params: params, |
| 70 }); |
| 71 this.frontend.sendMessage(message); |
| 72 }; |
| 73 |
| 74 var frontendHandle = internals.connectToService( |
| 75 "mojo:sky_inspector_server", inspector.InspectorFrontend.name); |
| 76 window.frontendConnection = new connection.Connection( |
| 77 frontendHandle, |
| 78 InspectorBackend, |
| 79 inspector.InspectorFrontend.proxyClass); |
| 80 |
| 81 window.frontend = frontendConnection.remote; |
| 82 frontend.listen(9898); |
| 83 </script> |
OLD | NEW |