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().setAutoconnectToWorkers(!suspended); | 89 this.target().workerAgent().setPauseWorkersOnStart(!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} inspectorConnected | 95 * @param {boolean} pausedOnStart |
96 */ | 96 */ |
97 _workerCreated: function(workerId, url, inspectorConnected) | 97 _workerCreated: function(workerId, url, pausedOnStart) |
98 { | 98 { |
99 var connection = new WebInspector.WorkerConnection(this, workerId, inspe ctorConnected, onConnectionReady.bind(this)); | 99 var connection = new WebInspector.WorkerConnection(this, workerId); |
100 this._connections.set(workerId, connection); | 100 this._connections.set(workerId, connection); |
101 | 101 |
102 /** | 102 var parsedURL = url.asParsedURL(); |
103 * @param {!InspectorBackendClass.Connection} connection | 103 var workerName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId); |
104 * @this {WebInspector.WorkerManager} | 104 var target = WebInspector.targetManager.createTarget(workerName, WebInsp ector.Target.Type.DedicatedWorker, connection, this.target()); |
105 */ | 105 this._targetsByWorkerId.set(workerId, target); |
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); | |
112 | 106 |
113 if (inspectorConnected) | 107 // Only pause new worker if debugging SW - we are going through the |
114 target.runtimeAgent().isRunRequired(pauseInDebuggerAndRunIfRequi red.bind(null, target)); | 108 // pause on start checkbox. |
115 } | 109 var mainIsServiceWorker = WebInspector.targetManager.mainTarget().isServ iceWorker(); |
116 | 110 if (mainIsServiceWorker && pausedOnStart) |
pfeldman
2016/02/09 22:42:56
So it is not pausedOnStart - it is not yet running
| |
117 /** | 111 target.debuggerAgent().pause(); |
118 * @param {!WebInspector.Target} target | 112 target.runtimeAgent().run(); |
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 } | |
131 }, | 113 }, |
132 | 114 |
133 /** | 115 /** |
134 * @param {string} workerId | 116 * @param {string} workerId |
135 */ | 117 */ |
136 _workerTerminated: function(workerId) | 118 _workerTerminated: function(workerId) |
137 { | 119 { |
138 var connection = this._connections.get(workerId); | 120 var connection = this._connections.get(workerId); |
139 if (connection) | 121 if (connection) |
140 connection._close(); | 122 connection._close(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 WebInspector.WorkerDispatcher = function(workerManager) | 162 WebInspector.WorkerDispatcher = function(workerManager) |
181 { | 163 { |
182 this._workerManager = workerManager; | 164 this._workerManager = workerManager; |
183 } | 165 } |
184 | 166 |
185 WebInspector.WorkerDispatcher.prototype = { | 167 WebInspector.WorkerDispatcher.prototype = { |
186 /** | 168 /** |
187 * @override | 169 * @override |
188 * @param {string} workerId | 170 * @param {string} workerId |
189 * @param {string} url | 171 * @param {string} url |
190 * @param {boolean} inspectorConnected | 172 * @param {boolean} pausedOnStart |
191 */ | 173 */ |
192 workerCreated: function(workerId, url, inspectorConnected) | 174 workerCreated: function(workerId, url, pausedOnStart) |
193 { | 175 { |
194 this._workerManager._workerCreated(workerId, url, inspectorConnected); | 176 this._workerManager._workerCreated(workerId, url, pausedOnStart); |
195 }, | 177 }, |
196 | 178 |
197 /** | 179 /** |
198 * @override | 180 * @override |
199 * @param {string} workerId | 181 * @param {string} workerId |
200 */ | 182 */ |
201 workerTerminated: function(workerId) | 183 workerTerminated: function(workerId) |
202 { | 184 { |
203 this._workerManager._workerTerminated(workerId); | 185 this._workerManager._workerTerminated(workerId); |
204 }, | 186 }, |
205 | 187 |
206 /** | 188 /** |
207 * @override | 189 * @override |
208 * @param {string} workerId | 190 * @param {string} workerId |
209 * @param {string} message | 191 * @param {string} message |
210 */ | 192 */ |
211 dispatchMessageFromWorker: function(workerId, message) | 193 dispatchMessageFromWorker: function(workerId, message) |
212 { | 194 { |
213 this._workerManager._dispatchMessageFromWorker(workerId, message); | 195 this._workerManager._dispatchMessageFromWorker(workerId, message); |
214 } | 196 } |
215 } | 197 } |
216 | 198 |
217 /** | 199 /** |
218 * @constructor | 200 * @constructor |
219 * @extends {InspectorBackendClass.Connection} | 201 * @extends {InspectorBackendClass.Connection} |
220 * @param {!WebInspector.WorkerManager} workerManager | 202 * @param {!WebInspector.WorkerManager} workerManager |
221 * @param {string} workerId | 203 * @param {string} workerId |
222 * @param {boolean} inspectorConnected | |
223 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady | |
224 */ | 204 */ |
225 WebInspector.WorkerConnection = function(workerManager, workerId, inspectorConne cted, onConnectionReady) | 205 WebInspector.WorkerConnection = function(workerManager, workerId) |
226 { | 206 { |
227 InspectorBackendClass.Connection.call(this); | 207 InspectorBackendClass.Connection.call(this); |
228 //FIXME: remove resourceTreeModel and others from worker targets | 208 //FIXME: remove resourceTreeModel and others from worker targets |
229 this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]); | 209 this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]); |
230 this._agent = workerManager.target().workerAgent(); | 210 this._agent = workerManager.target().workerAgent(); |
231 this._workerId = workerId; | 211 this._workerId = workerId; |
232 | |
233 | |
234 if (!inspectorConnected) | |
235 this._agent.connectToWorker(workerId, onConnectionReady.bind(null, this) ); | |
236 else | |
237 onConnectionReady.call(null, this); | |
238 } | 212 } |
239 | 213 |
240 WebInspector.WorkerConnection.prototype = { | 214 WebInspector.WorkerConnection.prototype = { |
241 /** | 215 /** |
242 * @override | 216 * @override |
243 * @param {!Object} messageObject | 217 * @param {!Object} messageObject |
244 */ | 218 */ |
245 sendMessage: function(messageObject) | 219 sendMessage: function(messageObject) |
246 { | 220 { |
247 this._agent.sendMessageToWorker(this._workerId, JSON.stringify(messageOb ject)); | 221 this._agent.sendMessageToWorker(this._workerId, JSON.stringify(messageOb ject)); |
248 }, | 222 }, |
249 | 223 |
250 _close: function() | 224 _close: function() |
251 { | 225 { |
252 this.connectionClosed("worker_terminated"); | 226 this.connectionClosed("worker_terminated"); |
253 }, | 227 }, |
254 | 228 |
255 __proto__: InspectorBackendClass.Connection.prototype | 229 __proto__: InspectorBackendClass.Connection.prototype |
256 } | 230 } |
OLD | NEW |