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