| OLD | NEW |
| 1 <import src="/mojo/public/sky/connection.sky" as="connection" /> | 1 <import src="/mojo/public/sky/connection.sky" as="connection" /> |
| 2 <import src="/mojo/public/sky/core.sky" as="core" /> | 2 <import src="/mojo/public/sky/core.sky" as="core" /> |
| 3 <import src="/mojo/public/sky/support.sky" as="support" /> | 3 <import src="/mojo/public/sky/support.sky" as="support" /> |
| 4 <import src="/mojo/services/public/sky/application.sky" as="application" /> | 4 <import src="/mojo/services/public/sky/application.sky" as="application" /> |
| 5 <import src="/sky/services/inspector/inspector.mojom.sky" as="inspector" /> | 5 <import src="/sky/services/inspector/inspector.mojom.sky" as="inspector" /> |
| 6 <import src="console-agent.sky" as="ConsoleAgent" /> | 6 <import src="console-agent.sky" as="ConsoleAgent" /> |
| 7 <import src="dom-agent.sky" as="DOMAgent" /> | 7 <import src="dom-agent.sky" as="DOMAgent" /> |
| 8 <import src="page-agent.sky" as="PageAgent" /> | 8 <import src="page-agent.sky" as="PageAgent" /> |
| 9 <import src="worker-agent.sky" as="WorkerAgent" /> | 9 <import src="worker-agent.sky" as="WorkerAgent" /> |
| 10 <import src="runtime-agent.sky" as="RuntimeAgent" /> | 10 <import src="runtime-agent.sky" as="RuntimeAgent" /> |
| 11 <import src="indexeddb-agent.sky" as="IndexedDBAgent" /> | 11 <import src="indexeddb-agent.sky" as="IndexedDBAgent" /> |
| 12 <import src="css-agent.sky" as="CSSAgent" /> | 12 <import src="css-agent.sky" as="CSSAgent" /> |
| 13 <script> | 13 <script> |
| 14 function InspectorBackend(frontend) { | 14 class InspectorBackend extends inspector.InspectorBackend.stubClass { |
| 15 var domAgent = new DOMAgent(this); | 15 constructor(frontend) { |
| 16 this.agents = { | 16 var domAgent = new DOMAgent(this); |
| 17 Console: new ConsoleAgent(), | 17 this.agents = { |
| 18 DOM: domAgent, | 18 Console: new ConsoleAgent(), |
| 19 Page: new PageAgent(this), | 19 DOM: domAgent, |
| 20 Worker: new WorkerAgent(), | 20 Page: new PageAgent(this), |
| 21 Runtime: new RuntimeAgent(this), | 21 Worker: new WorkerAgent(), |
| 22 CSS: new CSSAgent(domAgent), | 22 Runtime: new RuntimeAgent(this), |
| 23 IndexedDB: new IndexedDBAgent(), | 23 CSS: new CSSAgent(domAgent), |
| 24 }; | 24 IndexedDB: new IndexedDBAgent(), |
| 25 this.missingNames_ = {}; | 25 }; |
| 26 this.unansweredMessages_ = []; | 26 this.missingNames_ = {}; |
| 27 } | 27 this.unansweredMessages_ = []; |
| 28 | 28 |
| 29 InspectorBackend.prototype = Object.create( | 29 this.IMPLEMENTED_IN_CPP = "IMPLEMENTED_IN_CPP"; |
| 30 inspector.InspectorBackend.stubClass.prototype); | 30 this.ASYNC_RESPONSE = "ASYNC_RESPONSE"; |
| 31 this.MESSAGE_TIMEOUT_MS = 30000; |
| 31 | 32 |
| 32 InspectorBackend.prototype.IMPLEMENTED_IN_CPP = "IMPLEMENTED_IN_CPP"; | 33 Object.preventExtensions(this); |
| 33 InspectorBackend.prototype.ASYNC_RESPONSE = "ASYNC_RESPONSE"; | |
| 34 InspectorBackend.prototype.MESSAGE_TIMEOUT_MS = 30000; | |
| 35 | |
| 36 InspectorBackend.prototype.onConnect = function() { | |
| 37 }; | |
| 38 | |
| 39 InspectorBackend.prototype.onDisconnect = function() { | |
| 40 }; | |
| 41 | |
| 42 InspectorBackend.prototype.logMissing_ = function(name) { | |
| 43 if (name in this.missingNames_) | |
| 44 return; | |
| 45 this.missingNames_[name] = true; | |
| 46 console.log("InspectorBackend missing " + name); | |
| 47 } | |
| 48 | |
| 49 InspectorBackend.prototype.dispatch_ = function(descriptor, params, message_id)
{ | |
| 50 var parsed = descriptor.split('.'); | |
| 51 | |
| 52 var agentName = parsed[0]; | |
| 53 var methodName = parsed[1]; | |
| 54 | |
| 55 // Debugger is implemented in c++. | |
| 56 if (agentName == "Debugger") | |
| 57 return this.IMPLEMENTED_IN_CPP; | |
| 58 | |
| 59 if (!(agentName in this.agents)) { | |
| 60 this.logMissing_(agentName); | |
| 61 return {}; | |
| 62 } | 34 } |
| 63 | 35 |
| 64 var agent = this.agents[agentName]; | 36 onConnect() { |
| 65 | |
| 66 if (!(methodName in agent)) { | |
| 67 this.logMissing_(descriptor); | |
| 68 return {}; | |
| 69 } | 37 } |
| 70 | 38 |
| 71 try { | 39 onDisconnect() { |
| 72 return agent[methodName](params, message_id); | |
| 73 } catch(ex) { | |
| 74 console.log(descriptor + ": " + ex); | |
| 75 } | 40 } |
| 76 }; | |
| 77 | 41 |
| 78 InspectorBackend.prototype.onMessage = function(data) { | 42 logMissing_(name) { |
| 79 var message = JSON.parse(data); | 43 if (name in this.missingNames_) |
| 80 var result = this.dispatch_(message.method, message.params, message.id); | |
| 81 if (result === this.IMPLEMENTED_IN_CPP) | |
| 82 return; | 44 return; |
| 83 this.unansweredMessages_.push(message.id); | 45 this.missingNames_[name] = true; |
| 84 // FIXME: This magic return value is kinda hacky. | 46 console.log("InspectorBackend missing " + name); |
| 85 if (result !== this.ASYNC_RESPONSE) | |
| 86 this.sendResponse(message.id, result); | |
| 87 else { | |
| 88 window.setTimeout(function() { | |
| 89 if (this.unansweredMessages_.indexOf(message.id) == -1) | |
| 90 return; | |
| 91 console.log("Error, failed to reply to message id " + message.id); | |
| 92 }.bind(this), this.MESSAGE_TIMEOUT_MS); | |
| 93 } | 47 } |
| 94 }; | |
| 95 | 48 |
| 96 InspectorBackend.prototype.sendResponse = function(message_id, result) { | 49 dispatch_(descriptor, params, message_id) { |
| 97 var messageIndex = this.unansweredMessages_.indexOf(message_id); | 50 var parsed = descriptor.split('.'); |
| 98 if (messageIndex != -1) | 51 |
| 99 this.unansweredMessages_.splice(messageIndex, 1); | 52 var agentName = parsed[0]; |
| 100 else | 53 var methodName = parsed[1]; |
| 101 console.log("Error, responding to unknown message id " + message_id); | 54 |
| 102 var response = { | 55 // Debugger is implemented in c++. |
| 103 id: message_id, | 56 if (agentName == "Debugger") |
| 104 }; | 57 return this.IMPLEMENTED_IN_CPP; |
| 105 if (typeof result !== "undefined") | 58 |
| 106 response.result = result; | 59 if (!(agentName in this.agents)) { |
| 107 window.frontend.sendMessage(JSON.stringify(response)); | 60 this.logMissing_(agentName); |
| 61 return {}; |
| 62 } |
| 63 |
| 64 var agent = this.agents[agentName]; |
| 65 |
| 66 if (!(methodName in agent)) { |
| 67 this.logMissing_(descriptor); |
| 68 return {}; |
| 69 } |
| 70 |
| 71 try { |
| 72 return agent[methodName](params, message_id); |
| 73 } catch(ex) { |
| 74 console.log(descriptor + ": " + ex); |
| 75 } |
| 76 } |
| 77 |
| 78 onMessage(data) { |
| 79 var message = JSON.parse(data); |
| 80 var result = this.dispatch_(message.method, message.params, message.id); |
| 81 if (result === this.IMPLEMENTED_IN_CPP) |
| 82 return; |
| 83 this.unansweredMessages_.push(message.id); |
| 84 // FIXME: This magic return value is kinda hacky. |
| 85 if (result !== this.ASYNC_RESPONSE) |
| 86 this.sendResponse(message.id, result); |
| 87 else { |
| 88 window.setTimeout(function() { |
| 89 if (this.unansweredMessages_.indexOf(message.id) == -1) |
| 90 return; |
| 91 console.log("Error, failed to reply to message id " + message.id); |
| 92 }.bind(this), this.MESSAGE_TIMEOUT_MS); |
| 93 } |
| 94 } |
| 95 |
| 96 sendResponse(message_id, result) { |
| 97 var messageIndex = this.unansweredMessages_.indexOf(message_id); |
| 98 if (messageIndex != -1) |
| 99 this.unansweredMessages_.splice(messageIndex, 1); |
| 100 else |
| 101 console.log("Error, responding to unknown message id " + message_id); |
| 102 var response = { |
| 103 id: message_id, |
| 104 }; |
| 105 if (typeof result !== "undefined") |
| 106 response.result = result; |
| 107 window.frontend.sendMessage(JSON.stringify(response)); |
| 108 } |
| 109 |
| 110 sendMessage(method, params) { |
| 111 var message = JSON.stringify({ |
| 112 method: method, |
| 113 params: params, |
| 114 }); |
| 115 window.frontend.sendMessage(message); |
| 116 } |
| 108 } | 117 } |
| 109 | 118 |
| 110 InspectorBackend.prototype.sendMessage = function(method, params) { | |
| 111 var message = JSON.stringify({ | |
| 112 method: method, | |
| 113 params: params, | |
| 114 }); | |
| 115 window.frontend.sendMessage(message); | |
| 116 }; | |
| 117 | |
| 118 (function() { | 119 (function() { |
| 119 var app = new application.Application(internals.passShellProxyHandle()); | 120 var app = new application.Application(internals.passShellProxyHandle()); |
| 120 var tracingApp = app.shell.connectToApplication("mojo:sky_inspector_server"); | 121 var tracingApp = app.shell.connectToApplication("mojo:sky_inspector_server"); |
| 121 tracingApp.provideService(inspector.InspectorBackend, InspectorBackend); | 122 tracingApp.provideService(inspector.InspectorBackend, InspectorBackend); |
| 122 | 123 |
| 123 window.frontend = tracingApp.requestService(inspector.InspectorFrontend); | 124 window.frontend = tracingApp.requestService(inspector.InspectorFrontend); |
| 124 })(); | 125 })(); |
| 125 | |
| 126 | |
| 127 </script> | 126 </script> |
| OLD | NEW |