Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js

Issue 2354973003: [DevTools] Move subtargets functionality from ServiceWorker to Target domain. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.SDKObject} 33 * @extends {WebInspector.SDKObject}
34 * @param {!WebInspector.Target} target 34 * @param {!WebInspector.Target} target
35 * @param {!WebInspector.SubTargetsManager} subTargetsManager
35 */ 36 */
36 WebInspector.ServiceWorkerManager = function(target) 37 WebInspector.ServiceWorkerManager = function(target, subTargetsManager)
37 { 38 {
38 WebInspector.SDKObject.call(this, target); 39 WebInspector.SDKObject.call(this, target);
39 target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatc her(this)); 40 target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatc her(this));
40 this._lastAnonymousTargetId = 0; 41 this._lastAnonymousTargetId = 0;
42 this._subTargetsManager = subTargetsManager;
43 this._subTargetsManager.addEventListener(WebInspector.SubTargetsManager.Even ts.SubTargetsUpdated, this._updateAllContextLabels, this);
41 this._agent = target.serviceWorkerAgent(); 44 this._agent = target.serviceWorkerAgent();
42 /** @type {!Map.<string, !WebInspector.ServiceWorker>} */
43 this._workers = new Map();
44 /** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */ 45 /** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */
45 this._registrations = new Map(); 46 this._registrations = new Map();
46 this.enable(); 47 this.enable();
47 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke rUpdateOnReload", false); 48 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke rUpdateOnReload", false);
48 if (this._forceUpdateSetting.get()) 49 if (this._forceUpdateSetting.get())
49 this._forceUpdateSettingChanged(); 50 this._forceUpdateSettingChanged();
50 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged, this); 51 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged, this);
51 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat ed, this); 52 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat ed, this);
52 } 53 }
53 54
54 /** @enum {symbol} */ 55 /** @enum {symbol} */
55 WebInspector.ServiceWorkerManager.Events = { 56 WebInspector.ServiceWorkerManager.Events = {
56 WorkersUpdated: Symbol("WorkersUpdated"),
57 RegistrationUpdated: Symbol("RegistrationUpdated"), 57 RegistrationUpdated: Symbol("RegistrationUpdated"),
58 RegistrationErrorAdded: Symbol("RegistrationErrorAdded"), 58 RegistrationErrorAdded: Symbol("RegistrationErrorAdded"),
59 RegistrationDeleted: Symbol("RegistrationDeleted") 59 RegistrationDeleted: Symbol("RegistrationDeleted")
60 } 60 }
61 61
62 WebInspector.ServiceWorkerManager._VersionIdSymbol = Symbol("VersionId");
63
62 WebInspector.ServiceWorkerManager.prototype = { 64 WebInspector.ServiceWorkerManager.prototype = {
63 enable: function() 65 enable: function()
64 { 66 {
65 if (this._enabled) 67 if (this._enabled)
66 return; 68 return;
67 this._enabled = true; 69 this._enabled = true;
68
69 this._agent.enable(); 70 this._agent.enable();
70 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.MainFrameNavigated, this._mainFrameNavigated, this);
71 }, 71 },
72 72
73 disable: function() 73 disable: function()
74 { 74 {
75 if (!this._enabled) 75 if (!this._enabled)
76 return; 76 return;
77 this._enabled = false; 77 this._enabled = false;
78
79 for (var worker of this._workers.values())
80 worker._connection.close();
81 this._workers.clear();
82 this._registrations.clear(); 78 this._registrations.clear();
83 this._agent.disable(); 79 this._agent.disable();
84 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage r.Events.MainFrameNavigated, this._mainFrameNavigated, this);
85 }, 80 },
86 81
87 /** 82 /**
88 * @return {!Iterable.<!WebInspector.ServiceWorker>}
89 */
90 workers: function()
91 {
92 return this._workers.values();
93 },
94
95 /**
96 * @param {string} versionId 83 * @param {string} versionId
97 * @return {?WebInspector.Target} 84 * @return {?WebInspector.Target}
98 */ 85 */
99 targetForVersionId: function(versionId) 86 targetForVersionId: function(versionId)
100 { 87 {
101 for (var pair of this._workers) { 88 var version = this.findVersion(versionId);
102 if (pair[1]._versionId === versionId) 89 if (!version || !version.targetId)
103 return pair[1]._target; 90 return null;
104 } 91 return this._subTargetsManager.targetForId(version.targetId);
105 return null;
106 }, 92 },
107 93
108 /** 94 /**
109 * @return {boolean} 95 * @param {!WebInspector.Target} target
96 * @return {?string}
110 */ 97 */
111 hasWorkers: function() 98 _versionIdForTarget: function(target)
112 { 99 {
113 return !!this._workers.size; 100 return target[WebInspector.ServiceWorkerManager._VersionIdSymbol] || nul l;
114 }, 101 },
115 102
116 /** 103 /**
117 * @return {!Map.<string, !WebInspector.ServiceWorkerRegistration>} 104 * @return {!Map.<string, !WebInspector.ServiceWorkerRegistration>}
118 */ 105 */
119 registrations: function() 106 registrations: function()
120 { 107 {
121 return this._registrations; 108 return this._registrations;
122 }, 109 },
123 110
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 dispatchSyncEvent: function(registrationId, tag, lastChance) 173 dispatchSyncEvent: function(registrationId, tag, lastChance)
187 { 174 {
188 var registration = this._registrations.get(registrationId); 175 var registration = this._registrations.get(registrationId);
189 if (!registration) 176 if (!registration)
190 return; 177 return;
191 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL) ; 178 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL) ;
192 this._agent.dispatchSyncEvent(origin, registrationId, tag, lastChance); 179 this._agent.dispatchSyncEvent(origin, registrationId, tag, lastChance);
193 }, 180 },
194 181
195 /** 182 /**
196 * @param {!ServiceWorkerAgent.TargetID} targetId
197 */
198 activateTarget: function(targetId)
199 {
200 this._agent.activateTarget(targetId);
201 },
202
203 /**
204 * @param {string} scope 183 * @param {string} scope
205 */ 184 */
206 _unregister: function(scope) 185 _unregister: function(scope)
207 { 186 {
208 this._agent.unregister(scope); 187 this._agent.unregister(scope);
209 }, 188 },
210 189
211 /** 190 /**
212 * @param {string} scope 191 * @param {string} scope
213 */ 192 */
(...skipping 20 matching lines...) Expand all
234 213
235 /** 214 /**
236 * @param {string} versionId 215 * @param {string} versionId
237 */ 216 */
238 inspectWorker: function(versionId) 217 inspectWorker: function(versionId)
239 { 218 {
240 this._agent.inspectWorker(versionId); 219 this._agent.inspectWorker(versionId);
241 }, 220 },
242 221
243 /** 222 /**
244 * @param {!ServiceWorkerAgent.TargetID} targetId
245 * @param {function(?WebInspector.TargetInfo)=} callback
246 */
247 getTargetInfo: function(targetId, callback)
248 {
249 /**
250 * @param {?Protocol.Error} error
251 * @param {?ServiceWorkerAgent.TargetInfo} targetInfo
252 */
253 function innerCallback(error, targetInfo)
254 {
255 if (error) {
256 console.error(error);
257 callback(null);
258 return;
259 }
260 if (targetInfo)
261 callback(new WebInspector.TargetInfo(targetInfo));
262 else
263 callback(null)
264 }
265 this._agent.getTargetInfo(targetId, innerCallback);
266 },
267
268 /**
269 * @param {string} workerId
270 * @param {string} url
271 * @param {string} versionId
272 */
273 _workerCreated: function(workerId, url, versionId)
274 {
275 new WebInspector.ServiceWorker(this, workerId, url, versionId);
276 this._updateWorkerStatuses();
277 },
278
279 /**
280 * @param {string} workerId
281 */
282 _workerTerminated: function(workerId)
283 {
284 var worker = this._workers.get(workerId);
285 if (!worker)
286 return;
287
288 worker._closeConnection();
289 this._workers.delete(workerId);
290
291 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.W orkersUpdated);
292 },
293
294 /**
295 * @param {string} workerId
296 * @param {string} message
297 */
298 _dispatchMessage: function(workerId, message)
299 {
300 var worker = this._workers.get(workerId);
301 if (worker)
302 worker._connection.dispatch(message);
303 },
304
305 /**
306 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat ions 223 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat ions
307 */ 224 */
308 _workerRegistrationUpdated: function(registrations) 225 _workerRegistrationUpdated: function(registrations)
309 { 226 {
310 for (var payload of registrations) { 227 for (var payload of registrations) {
311 var registration = this._registrations.get(payload.registrationId); 228 var registration = this._registrations.get(payload.registrationId);
312 if (!registration) { 229 if (!registration) {
313 registration = new WebInspector.ServiceWorkerRegistration(payloa d); 230 registration = new WebInspector.ServiceWorkerRegistration(payloa d);
314 this._registrations.set(payload.registrationId, registration); 231 this._registrations.set(payload.registrationId, registration);
315 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration); 232 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration);
(...skipping 14 matching lines...) Expand all
330 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions 247 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions
331 */ 248 */
332 _workerVersionUpdated: function(versions) 249 _workerVersionUpdated: function(versions)
333 { 250 {
334 /** @type {!Set.<!WebInspector.ServiceWorkerRegistration>} */ 251 /** @type {!Set.<!WebInspector.ServiceWorkerRegistration>} */
335 var registrations = new Set(); 252 var registrations = new Set();
336 for (var payload of versions) { 253 for (var payload of versions) {
337 var registration = this._registrations.get(payload.registrationId); 254 var registration = this._registrations.get(payload.registrationId);
338 if (!registration) 255 if (!registration)
339 continue; 256 continue;
340 registration._updateVersion(payload); 257 var version = registration._updateVersion(payload);
258 var target = version.targetId ? this._subTargetsManager.targetForId( version.targetId) : null;
259 if (target)
260 target[WebInspector.ServiceWorkerManager._VersionIdSymbol] = ver sion.id;
341 registrations.add(registration); 261 registrations.add(registration);
342 } 262 }
343 for (var registration of registrations) { 263 for (var registration of registrations) {
344 if (registration._shouldBeRemoved()) { 264 if (registration._shouldBeRemoved()) {
345 this._registrations.delete(registration.id); 265 this._registrations.delete(registration.id);
346 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationDeleted, registration); 266 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationDeleted, registration);
347 } else { 267 } else {
348 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration); 268 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration);
349 } 269 }
350 } 270 }
351 this._updateWorkerStatuses(); 271 this._updateAllContextLabels();
352 },
353
354 _updateWorkerStatuses: function()
355 {
356 /** @type {!Map<string, string>} */
357 var versionById = new Map();
358 for (var registration of this._registrations.valuesArray()) {
359 for (var version of registration.versions.valuesArray())
360 versionById.set(version.id, version.status);
361 }
362 for (var worker of this._workers.valuesArray()) {
363 var status = versionById.get(worker.versionId());
364 if (status)
365 worker.setStatus(status);
366 }
367 }, 272 },
368 273
369 /** 274 /**
370 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload 275 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
371 */ 276 */
372 _workerErrorReported: function(payload) 277 _workerErrorReported: function(payload)
373 { 278 {
374 var registration = this._registrations.get(payload.registrationId); 279 var registration = this._registrations.get(payload.registrationId);
375 if (!registration) 280 if (!registration)
376 return; 281 return;
377 registration.errors.push(payload); 282 registration.errors.push(payload);
378 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationErrorAdded, { registration: registration, error: payload }); 283 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationErrorAdded, { registration: registration, error: payload });
379 }, 284 },
380 285
381 /** 286 /**
382 * @param {!WebInspector.Event} event
383 */
384 _mainFrameNavigated: function(event)
385 {
386 // Attach to the new worker set.
387 },
388
389 /**
390 * @return {!WebInspector.Setting} 287 * @return {!WebInspector.Setting}
391 */ 288 */
392 forceUpdateOnReloadSetting: function() 289 forceUpdateOnReloadSetting: function()
393 { 290 {
394 return this._forceUpdateSetting; 291 return this._forceUpdateSetting;
395 }, 292 },
396 293
397 _forceUpdateSettingChanged: function() 294 _forceUpdateSettingChanged: function()
398 { 295 {
399 this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get()); 296 this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get());
400 }, 297 },
401 298
299 _updateAllContextLabels: function()
300 {
301 /** @type {!Map<string, string>} */
302 var statusByVersionId = new Map();
303 for (var registration of this._registrations.valuesArray()) {
304 for (var version of registration.versions.valuesArray()) {
305 var target = version.targetId ? this._subTargetsManager.targetFo rId(version.targetId) : null;
306 if (target)
307 target[WebInspector.ServiceWorkerManager._VersionIdSymbol] = version.id;
308 statusByVersionId.set(version.id, version.status);
309 }
310 }
311
312 for (var target of WebInspector.targetManager.targets()) {
313 var versionId = this._versionForWorkerOfServiceWorkerTarget(target);
314 if (!versionId)
315 return;
316 var status = statusByVersionId.get(versionId) || "";
317 for (var context of target.runtimeModel.executionContexts())
318 this._updateContextLabel(context, versionId, status);
319 }
320 },
321
322 /**
323 * @param {!WebInspector.Target} target
324 * @return {?string}
325 */
326 _versionForWorkerOfServiceWorkerTarget: function(target)
327 {
328 var parent = target.parentTarget();
329 if (!parent || parent.parentTarget() !== this.target())
330 return null;
331 if (this._subTargetsManager.targetType(parent) !== TargetAgent.TargetTyp e.Service_worker)
332 return null;
333 return this._versionIdForTarget(parent);
334 },
335
402 /** 336 /**
403 * @param {!WebInspector.Event} event 337 * @param {!WebInspector.Event} event
404 */ 338 */
405 _executionContextCreated: function(event) 339 _executionContextCreated: function(event)
406 { 340 {
407 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev ent.data); 341 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev ent.data);
408 var target = executionContext.target(); 342 var versionId = this._versionForWorkerOfServiceWorkerTarget(executionCon text.target());
409 if (!target.parentTarget()) 343 if (!versionId)
410 return; 344 return;
411 var worker = target.parentTarget()[WebInspector.ServiceWorker.Symbol]; 345 this._updateContextLabel(executionContext, versionId, this.findVersion(v ersionId).status);
412 if (worker) 346 },
413 worker._setContextLabelFor(executionContext); 347
348 /**
349 * @param {!WebInspector.ExecutionContext} context
350 * @param {string} versionId
351 * @param {string} status
352 */
353 _updateContextLabel: function(context, versionId, status)
354 {
355 var parsedUrl = context.origin.asParsedURL();
356 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : cont ext.name;
357 if (status)
358 context.setLabel(label + " #" + versionId + " (" + status + ")");
359 else
360 context.setLabel(label);
414 }, 361 },
415 362
416 __proto__: WebInspector.SDKObject.prototype 363 __proto__: WebInspector.SDKObject.prototype
417 } 364 }
418 365
419 /** 366 /**
420 * @constructor
421 * @param {!WebInspector.ServiceWorkerManager} manager
422 * @param {string} workerId
423 * @param {string} url
424 * @param {string} versionId
425 */
426 WebInspector.ServiceWorker = function(manager, workerId, url, versionId)
427 {
428 this._manager = manager;
429 this._agent = manager.target().serviceWorkerAgent();
430 this._workerId = workerId;
431 this._connection = new WebInspector.ServiceWorkerConnection(this._agent, wor kerId);
432 this._url = url;
433 this._versionId = versionId;
434 var parsedURL = url.asParsedURL();
435 this._name = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++WebInspector.ServiceWorker._lastAnonymousTargetId);
436 this._scope = parsedURL ? parsedURL.host + parsedURL.folderPathComponents : "";
437
438 this._manager._workers.set(workerId, this);
439 var capabilities =
440 WebInspector.Target.Capability.Log | WebInspector.Target.Capability.Netw ork |
441 WebInspector.Target.Capability.Worker;
442 this._target = WebInspector.targetManager.createTarget(this._name, capabilit ies, this._connection, manager.target());
443 this._target[WebInspector.ServiceWorker.Symbol] = this;
444 this._manager.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Eve nts.WorkersUpdated);
445 this._target.runtimeAgent().runIfWaitingForDebugger();
446 }
447
448 WebInspector.ServiceWorker.Symbol = Symbol("serviceWorker");
449
450 WebInspector.ServiceWorker._lastAnonymousTargetId = 0;
451
452 WebInspector.ServiceWorker.prototype = {
453 /**
454 * @return {string}
455 */
456 name: function()
457 {
458 return this._name;
459 },
460
461 /**
462 * @return {string}
463 */
464 url: function()
465 {
466 return this._url;
467 },
468
469 /**
470 * @return {string}
471 */
472 versionId: function()
473 {
474 return this._versionId;
475 },
476
477 /**
478 * @return {string}
479 */
480 scope: function()
481 {
482 return this._scope;
483 },
484
485 stop: function()
486 {
487 this._agent.stop(this._workerId);
488 },
489
490 /** @param {string} status */
491 setStatus: function(status)
492 {
493 if (this._status === status)
494 return;
495 this._status = status;
496
497 for (var target of WebInspector.targetManager.targets()) {
498 if (target.parentTarget() !== this._target)
499 continue;
500 for (var context of target.runtimeModel.executionContexts())
501 this._setContextLabelFor(context);
502 }
503 },
504
505 /**
506 * @param {!WebInspector.ExecutionContext} context
507 */
508 _setContextLabelFor: function(context)
509 {
510 var parsedUrl = context.origin.asParsedURL();
511 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : cont ext.name;
512 if (this._status)
513 context.setLabel(label + " #" + this._versionId + " (" + this._statu s + ")");
514 else
515 context.setLabel(label);
516 },
517
518 _closeConnection: function()
519 {
520 this._connection._close();
521 delete this._connection;
522 }
523 }
524
525 /**
526 * @constructor 367 * @constructor
527 * @implements {ServiceWorkerAgent.Dispatcher} 368 * @implements {ServiceWorkerAgent.Dispatcher}
528 * @param {!WebInspector.ServiceWorkerManager} manager 369 * @param {!WebInspector.ServiceWorkerManager} manager
529 */ 370 */
530 WebInspector.ServiceWorkerDispatcher = function(manager) 371 WebInspector.ServiceWorkerDispatcher = function(manager)
531 { 372 {
532 this._manager = manager; 373 this._manager = manager;
533 } 374 }
534 375
535 WebInspector.ServiceWorkerDispatcher.prototype = { 376 WebInspector.ServiceWorkerDispatcher.prototype = {
536 /** 377 /**
537 * @override 378 * @override
538 * @param {string} workerId
539 * @param {string} url
540 * @param {string} versionId
541 */
542 workerCreated: function(workerId, url, versionId)
543 {
544 this._manager._workerCreated(workerId, url, versionId);
545 },
546
547 /**
548 * @override
549 * @param {string} workerId
550 */
551 workerTerminated: function(workerId)
552 {
553 this._manager._workerTerminated(workerId);
554 },
555
556 /**
557 * @override
558 * @param {string} workerId
559 * @param {string} message
560 */
561 dispatchMessage: function(workerId, message)
562 {
563 this._manager._dispatchMessage(workerId, message);
564 },
565
566 /**
567 * @override
568 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat ions 379 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat ions
569 */ 380 */
570 workerRegistrationUpdated: function(registrations) 381 workerRegistrationUpdated: function(registrations)
571 { 382 {
572 this._manager._workerRegistrationUpdated(registrations); 383 this._manager._workerRegistrationUpdated(registrations);
573 }, 384 },
574 385
575 /** 386 /**
576 * @override 387 * @override
577 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions 388 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions
578 */ 389 */
579 workerVersionUpdated: function(versions) 390 workerVersionUpdated: function(versions)
580 { 391 {
581 this._manager._workerVersionUpdated(versions); 392 this._manager._workerVersionUpdated(versions);
582 }, 393 },
583 394
584 /** 395 /**
585 * @override 396 * @override
586 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} errorMessage 397 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} errorMessage
587 */ 398 */
588 workerErrorReported: function(errorMessage) 399 workerErrorReported: function(errorMessage)
589 { 400 {
590 this._manager._workerErrorReported(errorMessage); 401 this._manager._workerErrorReported(errorMessage);
591 } 402 }
592 } 403 }
593 404
594 /** 405 /**
595 * @constructor 406 * @constructor
596 * @extends {InspectorBackendClass.Connection}
597 * @param {!Protocol.ServiceWorkerAgent} agent
598 * @param {string} workerId
599 */
600 WebInspector.ServiceWorkerConnection = function(agent, workerId)
601 {
602 InspectorBackendClass.Connection.call(this);
603 // FIXME: remove resourceTreeModel and others from worker targets
604 this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]);
605 this._agent = agent;
606 this._workerId = workerId;
607 }
608
609 WebInspector.ServiceWorkerConnection.prototype = {
610 /**
611 * @override
612 * @param {!Object} messageObject
613 */
614 sendMessage: function(messageObject)
615 {
616 this._agent.sendMessage(this._workerId, JSON.stringify(messageObject));
617 },
618
619 _close: function()
620 {
621 this.connectionClosed("worker_terminated");
622 },
623
624 __proto__: InspectorBackendClass.Connection.prototype
625 }
626
627 /**
628 * @constructor
629 * @param {!ServiceWorkerAgent.TargetInfo} payload
630 */
631 WebInspector.TargetInfo = function(payload)
632 {
633 this.id = payload.id;
634 this.type = payload.type;
635 this.title = payload.title;
636 this.url = payload.url;
637 }
638
639 WebInspector.TargetInfo.prototype = {
640 /**
641 * @return {boolean}
642 */
643 isWebContents: function()
644 {
645 return this.type === "page";
646 },
647 /**
648 * @return {boolean}
649 */
650 isFrame: function()
651 {
652 return this.type === "frame";
653 },
654 }
655
656 /**
657 * @constructor
658 * @param {!WebInspector.ServiceWorkerRegistration} registration 407 * @param {!WebInspector.ServiceWorkerRegistration} registration
659 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 408 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
660 */ 409 */
661 WebInspector.ServiceWorkerVersion = function(registration, payload) 410 WebInspector.ServiceWorkerVersion = function(registration, payload)
662 { 411 {
663 this.registration = registration; 412 this.registration = registration;
664 this._update(payload); 413 this._update(payload);
665 } 414 }
666 415
667 /** 416 /**
(...skipping 16 matching lines...) Expand all
684 this.scriptURL = payload.scriptURL; 433 this.scriptURL = payload.scriptURL;
685 var parsedURL = new WebInspector.ParsedURL(payload.scriptURL); 434 var parsedURL = new WebInspector.ParsedURL(payload.scriptURL);
686 this.securityOrigin = parsedURL.securityOrigin(); 435 this.securityOrigin = parsedURL.securityOrigin();
687 this.runningStatus = payload.runningStatus; 436 this.runningStatus = payload.runningStatus;
688 this.status = payload.status; 437 this.status = payload.status;
689 this.scriptLastModified = payload.scriptLastModified; 438 this.scriptLastModified = payload.scriptLastModified;
690 this.scriptResponseTime = payload.scriptResponseTime; 439 this.scriptResponseTime = payload.scriptResponseTime;
691 this.controlledClients = []; 440 this.controlledClients = [];
692 for (var i = 0; i < payload.controlledClients.length; ++i) 441 for (var i = 0; i < payload.controlledClients.length; ++i)
693 this.controlledClients.push(payload.controlledClients[i]); 442 this.controlledClients.push(payload.controlledClients[i]);
443 this.targetId = payload.targetId || null;
694 }, 444 },
695 445
696 /** 446 /**
697 * @return {boolean} 447 * @return {boolean}
698 */ 448 */
699 isStartable: function() 449 isStartable: function()
700 { 450 {
701 return !this.registration.isDeleted && this.isActivated() && this.isStop ped(); 451 return !this.registration.isDeleted && this.isActivated() && this.isStop ped();
702 }, 452 },
703 453
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 { 639 {
890 return this._isRedundant() && (!this.errors.length || this._deleting); 640 return this._isRedundant() && (!this.errors.length || this._deleting);
891 }, 641 },
892 642
893 clearErrors: function() 643 clearErrors: function()
894 { 644 {
895 this._fingerprint = Symbol("fingerprint"); 645 this._fingerprint = Symbol("fingerprint");
896 this.errors = []; 646 this.errors = [];
897 } 647 }
898 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698