OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 { | 79 { |
80 for (var connection of this._connections.values()) | 80 for (var connection of this._connections.values()) |
81 connection._close(); | 81 connection._close(); |
82 this._connections.clear(); | 82 this._connections.clear(); |
83 this._targetsByWorkerId.clear(); | 83 this._targetsByWorkerId.clear(); |
84 }, | 84 }, |
85 | 85 |
86 _onSuspendStateChanged: function() | 86 _onSuspendStateChanged: function() |
87 { | 87 { |
88 var suspended = WebInspector.targetManager.allTargetsSuspended(); | 88 var suspended = WebInspector.targetManager.allTargetsSuspended(); |
89 this.target().workerAgent().setWaitForDebuggerOnStart(!suspended); | 89 this.target().workerAgent().setAutoconnectToWorkers(!suspended); |
90 }, | 90 }, |
91 | 91 |
92 /** | 92 /** |
93 * @param {string} workerId | 93 * @param {string} workerId |
94 * @param {string} url | 94 * @param {string} url |
95 * @param {boolean} waitingForDebugger | 95 * @param {boolean} inspectorConnected |
96 */ | 96 */ |
97 _workerCreated: function(workerId, url, waitingForDebugger) | 97 _workerCreated: function(workerId, url, inspectorConnected) |
98 { | 98 { |
99 var connection = new WebInspector.WorkerConnection(this, workerId); | 99 var connection = new WebInspector.WorkerConnection(this, workerId, inspe
ctorConnected, onConnectionReady.bind(this)); |
100 this._connections.set(workerId, connection); | 100 this._connections.set(workerId, connection); |
101 | 101 |
102 var parsedURL = url.asParsedURL(); | 102 /** |
103 var workerName = parsedURL ? parsedURL.lastPathComponentWithFragment() :
"#" + (++this._lastAnonymousTargetId); | 103 * @param {!InspectorBackendClass.Connection} connection |
104 var target = WebInspector.targetManager.createTarget(workerName, WebInsp
ector.Target.Type.DedicatedWorker, connection, this.target()); | 104 * @this {WebInspector.WorkerManager} |
105 this._targetsByWorkerId.set(workerId, target); | 105 */ |
| 106 function onConnectionReady(connection) |
| 107 { |
| 108 var parsedURL = url.asParsedURL(); |
| 109 var workerName = parsedURL ? parsedURL.lastPathComponentWithFragment
() : "#" + (++this._lastAnonymousTargetId); |
| 110 var target = WebInspector.targetManager.createTarget(workerName, Web
Inspector.Target.Type.DedicatedWorker, connection, this.target()); |
| 111 this._targetsByWorkerId.set(workerId, target); |
106 | 112 |
107 // Only pause new worker if debugging SW - we are going through the | 113 if (inspectorConnected) |
108 // pause on start checkbox. | 114 target.runtimeAgent().isRunRequired(pauseInDebuggerAndRunIfRequi
red.bind(null, target)); |
109 var mainIsServiceWorker = WebInspector.targetManager.mainTarget().isServ
iceWorker(); | 115 } |
110 if (mainIsServiceWorker && waitingForDebugger) | 116 |
111 target.debuggerAgent().pause(); | 117 /** |
112 target.runtimeAgent().run(); | 118 * @param {!WebInspector.Target} target |
| 119 * @param {?Protocol.Error} error |
| 120 * @param {boolean} required |
| 121 */ |
| 122 function pauseInDebuggerAndRunIfRequired(target, error, required) |
| 123 { |
| 124 // Only pause new worker if debugging SW - we are going through the |
| 125 // pause on start checkbox. |
| 126 var mainIsServiceWorker = WebInspector.targetManager.mainTarget().is
ServiceWorker(); |
| 127 if (mainIsServiceWorker && required) |
| 128 target.debuggerAgent().pause(); |
| 129 target.runtimeAgent().run(); |
| 130 } |
113 }, | 131 }, |
114 | 132 |
115 /** | 133 /** |
116 * @param {string} workerId | 134 * @param {string} workerId |
117 */ | 135 */ |
118 _workerTerminated: function(workerId) | 136 _workerTerminated: function(workerId) |
119 { | 137 { |
120 var connection = this._connections.get(workerId); | 138 var connection = this._connections.get(workerId); |
121 if (connection) | 139 if (connection) |
122 connection._close(); | 140 connection._close(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 WebInspector.WorkerDispatcher = function(workerManager) | 180 WebInspector.WorkerDispatcher = function(workerManager) |
163 { | 181 { |
164 this._workerManager = workerManager; | 182 this._workerManager = workerManager; |
165 } | 183 } |
166 | 184 |
167 WebInspector.WorkerDispatcher.prototype = { | 185 WebInspector.WorkerDispatcher.prototype = { |
168 /** | 186 /** |
169 * @override | 187 * @override |
170 * @param {string} workerId | 188 * @param {string} workerId |
171 * @param {string} url | 189 * @param {string} url |
172 * @param {boolean} waitingForDebugger | 190 * @param {boolean} inspectorConnected |
173 */ | 191 */ |
174 workerCreated: function(workerId, url, waitingForDebugger) | 192 workerCreated: function(workerId, url, inspectorConnected) |
175 { | 193 { |
176 this._workerManager._workerCreated(workerId, url, waitingForDebugger); | 194 this._workerManager._workerCreated(workerId, url, inspectorConnected); |
177 }, | 195 }, |
178 | 196 |
179 /** | 197 /** |
180 * @override | 198 * @override |
181 * @param {string} workerId | 199 * @param {string} workerId |
182 */ | 200 */ |
183 workerTerminated: function(workerId) | 201 workerTerminated: function(workerId) |
184 { | 202 { |
185 this._workerManager._workerTerminated(workerId); | 203 this._workerManager._workerTerminated(workerId); |
186 }, | 204 }, |
187 | 205 |
188 /** | 206 /** |
189 * @override | 207 * @override |
190 * @param {string} workerId | 208 * @param {string} workerId |
191 * @param {string} message | 209 * @param {string} message |
192 */ | 210 */ |
193 dispatchMessageFromWorker: function(workerId, message) | 211 dispatchMessageFromWorker: function(workerId, message) |
194 { | 212 { |
195 this._workerManager._dispatchMessageFromWorker(workerId, message); | 213 this._workerManager._dispatchMessageFromWorker(workerId, message); |
196 } | 214 } |
197 } | 215 } |
198 | 216 |
199 /** | 217 /** |
200 * @constructor | 218 * @constructor |
201 * @extends {InspectorBackendClass.Connection} | 219 * @extends {InspectorBackendClass.Connection} |
202 * @param {!WebInspector.WorkerManager} workerManager | 220 * @param {!WebInspector.WorkerManager} workerManager |
203 * @param {string} workerId | 221 * @param {string} workerId |
| 222 * @param {boolean} inspectorConnected |
| 223 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady |
204 */ | 224 */ |
205 WebInspector.WorkerConnection = function(workerManager, workerId) | 225 WebInspector.WorkerConnection = function(workerManager, workerId, inspectorConne
cted, onConnectionReady) |
206 { | 226 { |
207 InspectorBackendClass.Connection.call(this); | 227 InspectorBackendClass.Connection.call(this); |
208 //FIXME: remove resourceTreeModel and others from worker targets | 228 //FIXME: remove resourceTreeModel and others from worker targets |
209 this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage",
"Database", "Network", "IndexedDB"]); | 229 this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage",
"Database", "Network", "IndexedDB"]); |
210 this._agent = workerManager.target().workerAgent(); | 230 this._agent = workerManager.target().workerAgent(); |
211 this._workerId = workerId; | 231 this._workerId = workerId; |
| 232 |
| 233 |
| 234 if (!inspectorConnected) |
| 235 this._agent.connectToWorker(workerId, onConnectionReady.bind(null, this)
); |
| 236 else |
| 237 onConnectionReady.call(null, this); |
212 } | 238 } |
213 | 239 |
214 WebInspector.WorkerConnection.prototype = { | 240 WebInspector.WorkerConnection.prototype = { |
215 /** | 241 /** |
216 * @override | 242 * @override |
217 * @param {!Object} messageObject | 243 * @param {!Object} messageObject |
218 */ | 244 */ |
219 sendMessage: function(messageObject) | 245 sendMessage: function(messageObject) |
220 { | 246 { |
221 this._agent.sendMessageToWorker(this._workerId, JSON.stringify(messageOb
ject)); | 247 this._agent.sendMessageToWorker(this._workerId, JSON.stringify(messageOb
ject)); |
222 }, | 248 }, |
223 | 249 |
224 _close: function() | 250 _close: function() |
225 { | 251 { |
226 this.connectionClosed("worker_terminated"); | 252 this.connectionClosed("worker_terminated"); |
227 }, | 253 }, |
228 | 254 |
229 __proto__: InspectorBackendClass.Connection.prototype | 255 __proto__: InspectorBackendClass.Connection.prototype |
230 } | 256 } |
OLD | NEW |