| 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 14 matching lines...) Expand all Loading... |
| 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; |
| 41 this._agent = target.serviceWorkerAgent(); | 42 this._agent = target.serviceWorkerAgent(); |
| 42 /** @type {!Map.<string, !WebInspector.ServiceWorker>} */ | |
| 43 this._workers = new Map(); | |
| 44 /** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */ | 43 /** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */ |
| 45 this._registrations = new Map(); | 44 this._registrations = new Map(); |
| 46 this.enable(); | 45 this.enable(); |
| 47 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke
rUpdateOnReload", false); | 46 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke
rUpdateOnReload", false); |
| 48 if (this._forceUpdateSetting.get()) | 47 if (this._forceUpdateSetting.get()) |
| 49 this._forceUpdateSettingChanged(); | 48 this._forceUpdateSettingChanged(); |
| 50 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged,
this); | 49 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged,
this); |
| 51 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat
ed, this); | 50 new WebInspector.ServiceWorkerContextNamer(target, this, subTargetsManager); |
| 52 } | 51 } |
| 53 | 52 |
| 54 /** @enum {symbol} */ | 53 /** @enum {symbol} */ |
| 55 WebInspector.ServiceWorkerManager.Events = { | 54 WebInspector.ServiceWorkerManager.Events = { |
| 56 WorkersUpdated: Symbol("WorkersUpdated"), | |
| 57 RegistrationUpdated: Symbol("RegistrationUpdated"), | 55 RegistrationUpdated: Symbol("RegistrationUpdated"), |
| 58 RegistrationErrorAdded: Symbol("RegistrationErrorAdded"), | 56 RegistrationErrorAdded: Symbol("RegistrationErrorAdded"), |
| 59 RegistrationDeleted: Symbol("RegistrationDeleted") | 57 RegistrationDeleted: Symbol("RegistrationDeleted") |
| 60 } | 58 } |
| 61 | 59 |
| 62 WebInspector.ServiceWorkerManager.prototype = { | 60 WebInspector.ServiceWorkerManager.prototype = { |
| 63 enable: function() | 61 enable: function() |
| 64 { | 62 { |
| 65 if (this._enabled) | 63 if (this._enabled) |
| 66 return; | 64 return; |
| 67 this._enabled = true; | 65 this._enabled = true; |
| 68 | |
| 69 this._agent.enable(); | 66 this._agent.enable(); |
| 70 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E
vents.MainFrameNavigated, this._mainFrameNavigated, this); | |
| 71 }, | 67 }, |
| 72 | 68 |
| 73 disable: function() | 69 disable: function() |
| 74 { | 70 { |
| 75 if (!this._enabled) | 71 if (!this._enabled) |
| 76 return; | 72 return; |
| 77 this._enabled = false; | 73 this._enabled = false; |
| 78 | |
| 79 for (var worker of this._workers.values()) | |
| 80 worker._connection.close(); | |
| 81 this._workers.clear(); | |
| 82 this._registrations.clear(); | 74 this._registrations.clear(); |
| 83 this._agent.disable(); | 75 this._agent.disable(); |
| 84 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage
r.Events.MainFrameNavigated, this._mainFrameNavigated, this); | |
| 85 }, | 76 }, |
| 86 | 77 |
| 87 /** | 78 /** |
| 88 * @return {!Iterable.<!WebInspector.ServiceWorker>} | |
| 89 */ | |
| 90 workers: function() | |
| 91 { | |
| 92 return this._workers.values(); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @param {string} versionId | |
| 97 * @return {?WebInspector.Target} | |
| 98 */ | |
| 99 targetForVersionId: function(versionId) | |
| 100 { | |
| 101 for (var pair of this._workers) { | |
| 102 if (pair[1]._versionId === versionId) | |
| 103 return pair[1]._target; | |
| 104 } | |
| 105 return null; | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * @return {boolean} | |
| 110 */ | |
| 111 hasWorkers: function() | |
| 112 { | |
| 113 return !!this._workers.size; | |
| 114 }, | |
| 115 | |
| 116 /** | |
| 117 * @return {!Map.<string, !WebInspector.ServiceWorkerRegistration>} | 79 * @return {!Map.<string, !WebInspector.ServiceWorkerRegistration>} |
| 118 */ | 80 */ |
| 119 registrations: function() | 81 registrations: function() |
| 120 { | 82 { |
| 121 return this._registrations; | 83 return this._registrations; |
| 122 }, | 84 }, |
| 123 | 85 |
| 124 /** | 86 /** |
| 125 * @param {string} versionId | 87 * @param {string} versionId |
| 126 * @return {?WebInspector.ServiceWorkerVersion} | 88 * @return {?WebInspector.ServiceWorkerVersion} |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 dispatchSyncEvent: function(registrationId, tag, lastChance) | 148 dispatchSyncEvent: function(registrationId, tag, lastChance) |
| 187 { | 149 { |
| 188 var registration = this._registrations.get(registrationId); | 150 var registration = this._registrations.get(registrationId); |
| 189 if (!registration) | 151 if (!registration) |
| 190 return; | 152 return; |
| 191 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL)
; | 153 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL)
; |
| 192 this._agent.dispatchSyncEvent(origin, registrationId, tag, lastChance); | 154 this._agent.dispatchSyncEvent(origin, registrationId, tag, lastChance); |
| 193 }, | 155 }, |
| 194 | 156 |
| 195 /** | 157 /** |
| 196 * @param {!ServiceWorkerAgent.TargetID} targetId | |
| 197 */ | |
| 198 activateTarget: function(targetId) | |
| 199 { | |
| 200 this._agent.activateTarget(targetId); | |
| 201 }, | |
| 202 | |
| 203 /** | |
| 204 * @param {string} scope | 158 * @param {string} scope |
| 205 */ | 159 */ |
| 206 _unregister: function(scope) | 160 _unregister: function(scope) |
| 207 { | 161 { |
| 208 this._agent.unregister(scope); | 162 this._agent.unregister(scope); |
| 209 }, | 163 }, |
| 210 | 164 |
| 211 /** | 165 /** |
| 212 * @param {string} scope | 166 * @param {string} scope |
| 213 */ | 167 */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 234 | 188 |
| 235 /** | 189 /** |
| 236 * @param {string} versionId | 190 * @param {string} versionId |
| 237 */ | 191 */ |
| 238 inspectWorker: function(versionId) | 192 inspectWorker: function(versionId) |
| 239 { | 193 { |
| 240 this._agent.inspectWorker(versionId); | 194 this._agent.inspectWorker(versionId); |
| 241 }, | 195 }, |
| 242 | 196 |
| 243 /** | 197 /** |
| 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 | 198 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat
ions |
| 307 */ | 199 */ |
| 308 _workerRegistrationUpdated: function(registrations) | 200 _workerRegistrationUpdated: function(registrations) |
| 309 { | 201 { |
| 310 for (var payload of registrations) { | 202 for (var payload of registrations) { |
| 311 var registration = this._registrations.get(payload.registrationId); | 203 var registration = this._registrations.get(payload.registrationId); |
| 312 if (!registration) { | 204 if (!registration) { |
| 313 registration = new WebInspector.ServiceWorkerRegistration(payloa
d); | 205 registration = new WebInspector.ServiceWorkerRegistration(payloa
d); |
| 314 this._registrations.set(payload.registrationId, registration); | 206 this._registrations.set(payload.registrationId, registration); |
| 315 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.
Events.RegistrationUpdated, registration); | 207 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.
Events.RegistrationUpdated, registration); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 341 registrations.add(registration); | 233 registrations.add(registration); |
| 342 } | 234 } |
| 343 for (var registration of registrations) { | 235 for (var registration of registrations) { |
| 344 if (registration._shouldBeRemoved()) { | 236 if (registration._shouldBeRemoved()) { |
| 345 this._registrations.delete(registration.id); | 237 this._registrations.delete(registration.id); |
| 346 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.
Events.RegistrationDeleted, registration); | 238 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.
Events.RegistrationDeleted, registration); |
| 347 } else { | 239 } else { |
| 348 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.
Events.RegistrationUpdated, registration); | 240 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.
Events.RegistrationUpdated, registration); |
| 349 } | 241 } |
| 350 } | 242 } |
| 351 this._updateWorkerStatuses(); | |
| 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 }, | 243 }, |
| 368 | 244 |
| 369 /** | 245 /** |
| 370 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload | 246 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload |
| 371 */ | 247 */ |
| 372 _workerErrorReported: function(payload) | 248 _workerErrorReported: function(payload) |
| 373 { | 249 { |
| 374 var registration = this._registrations.get(payload.registrationId); | 250 var registration = this._registrations.get(payload.registrationId); |
| 375 if (!registration) | 251 if (!registration) |
| 376 return; | 252 return; |
| 377 registration.errors.push(payload); | 253 registration.errors.push(payload); |
| 378 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R
egistrationErrorAdded, { registration: registration, error: payload }); | 254 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R
egistrationErrorAdded, { registration: registration, error: payload }); |
| 379 }, | 255 }, |
| 380 | 256 |
| 381 /** | 257 /** |
| 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} | 258 * @return {!WebInspector.Setting} |
| 391 */ | 259 */ |
| 392 forceUpdateOnReloadSetting: function() | 260 forceUpdateOnReloadSetting: function() |
| 393 { | 261 { |
| 394 return this._forceUpdateSetting; | 262 return this._forceUpdateSetting; |
| 395 }, | 263 }, |
| 396 | 264 |
| 397 _forceUpdateSettingChanged: function() | 265 _forceUpdateSettingChanged: function() |
| 398 { | 266 { |
| 399 this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get()); | 267 this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get()); |
| 400 }, | 268 }, |
| 401 | 269 |
| 402 /** | |
| 403 * @param {!WebInspector.Event} event | |
| 404 */ | |
| 405 _executionContextCreated: function(event) | |
| 406 { | |
| 407 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); | |
| 408 var target = executionContext.target(); | |
| 409 if (!target.parentTarget()) | |
| 410 return; | |
| 411 var worker = target.parentTarget()[WebInspector.ServiceWorker.Symbol]; | |
| 412 if (worker) | |
| 413 worker._setContextLabelFor(executionContext); | |
| 414 }, | |
| 415 | |
| 416 __proto__: WebInspector.SDKObject.prototype | 270 __proto__: WebInspector.SDKObject.prototype |
| 417 } | 271 } |
| 418 | 272 |
| 419 /** | 273 /** |
| 420 * @constructor | 274 * @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 | |
| 527 * @implements {ServiceWorkerAgent.Dispatcher} | 275 * @implements {ServiceWorkerAgent.Dispatcher} |
| 528 * @param {!WebInspector.ServiceWorkerManager} manager | 276 * @param {!WebInspector.ServiceWorkerManager} manager |
| 529 */ | 277 */ |
| 530 WebInspector.ServiceWorkerDispatcher = function(manager) | 278 WebInspector.ServiceWorkerDispatcher = function(manager) |
| 531 { | 279 { |
| 532 this._manager = manager; | 280 this._manager = manager; |
| 533 } | 281 } |
| 534 | 282 |
| 535 WebInspector.ServiceWorkerDispatcher.prototype = { | 283 WebInspector.ServiceWorkerDispatcher.prototype = { |
| 536 /** | 284 /** |
| 537 * @override | 285 * @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 | 286 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat
ions |
| 569 */ | 287 */ |
| 570 workerRegistrationUpdated: function(registrations) | 288 workerRegistrationUpdated: function(registrations) |
| 571 { | 289 { |
| 572 this._manager._workerRegistrationUpdated(registrations); | 290 this._manager._workerRegistrationUpdated(registrations); |
| 573 }, | 291 }, |
| 574 | 292 |
| 575 /** | 293 /** |
| 576 * @override | 294 * @override |
| 577 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions | 295 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions |
| 578 */ | 296 */ |
| 579 workerVersionUpdated: function(versions) | 297 workerVersionUpdated: function(versions) |
| 580 { | 298 { |
| 581 this._manager._workerVersionUpdated(versions); | 299 this._manager._workerVersionUpdated(versions); |
| 582 }, | 300 }, |
| 583 | 301 |
| 584 /** | 302 /** |
| 585 * @override | 303 * @override |
| 586 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} errorMessage | 304 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} errorMessage |
| 587 */ | 305 */ |
| 588 workerErrorReported: function(errorMessage) | 306 workerErrorReported: function(errorMessage) |
| 589 { | 307 { |
| 590 this._manager._workerErrorReported(errorMessage); | 308 this._manager._workerErrorReported(errorMessage); |
| 591 } | 309 } |
| 592 } | 310 } |
| 593 | 311 |
| 594 /** | 312 /** |
| 595 * @constructor | 313 * @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 | 314 * @param {!WebInspector.ServiceWorkerRegistration} registration |
| 659 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload | 315 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload |
| 660 */ | 316 */ |
| 661 WebInspector.ServiceWorkerVersion = function(registration, payload) | 317 WebInspector.ServiceWorkerVersion = function(registration, payload) |
| 662 { | 318 { |
| 663 this.registration = registration; | 319 this.registration = registration; |
| 664 this._update(payload); | 320 this._update(payload); |
| 665 } | 321 } |
| 666 | 322 |
| 667 /** | 323 /** |
| (...skipping 16 matching lines...) Expand all Loading... |
| 684 this.scriptURL = payload.scriptURL; | 340 this.scriptURL = payload.scriptURL; |
| 685 var parsedURL = new WebInspector.ParsedURL(payload.scriptURL); | 341 var parsedURL = new WebInspector.ParsedURL(payload.scriptURL); |
| 686 this.securityOrigin = parsedURL.securityOrigin(); | 342 this.securityOrigin = parsedURL.securityOrigin(); |
| 687 this.runningStatus = payload.runningStatus; | 343 this.runningStatus = payload.runningStatus; |
| 688 this.status = payload.status; | 344 this.status = payload.status; |
| 689 this.scriptLastModified = payload.scriptLastModified; | 345 this.scriptLastModified = payload.scriptLastModified; |
| 690 this.scriptResponseTime = payload.scriptResponseTime; | 346 this.scriptResponseTime = payload.scriptResponseTime; |
| 691 this.controlledClients = []; | 347 this.controlledClients = []; |
| 692 for (var i = 0; i < payload.controlledClients.length; ++i) | 348 for (var i = 0; i < payload.controlledClients.length; ++i) |
| 693 this.controlledClients.push(payload.controlledClients[i]); | 349 this.controlledClients.push(payload.controlledClients[i]); |
| 350 this.targetId = payload.targetId || null; |
| 694 }, | 351 }, |
| 695 | 352 |
| 696 /** | 353 /** |
| 697 * @return {boolean} | 354 * @return {boolean} |
| 698 */ | 355 */ |
| 699 isStartable: function() | 356 isStartable: function() |
| 700 { | 357 { |
| 701 return !this.registration.isDeleted && this.isActivated() && this.isStop
ped(); | 358 return !this.registration.isDeleted && this.isActivated() && this.isStop
ped(); |
| 702 }, | 359 }, |
| 703 | 360 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 { | 546 { |
| 890 return this._isRedundant() && (!this.errors.length || this._deleting); | 547 return this._isRedundant() && (!this.errors.length || this._deleting); |
| 891 }, | 548 }, |
| 892 | 549 |
| 893 clearErrors: function() | 550 clearErrors: function() |
| 894 { | 551 { |
| 895 this._fingerprint = Symbol("fingerprint"); | 552 this._fingerprint = Symbol("fingerprint"); |
| 896 this.errors = []; | 553 this.errors = []; |
| 897 } | 554 } |
| 898 } | 555 } |
| 556 |
| 557 /** |
| 558 * @constructor |
| 559 * @param {!WebInspector.Target} target |
| 560 * @param {!WebInspector.ServiceWorkerManager} serviceWorkerManager |
| 561 * @param {!WebInspector.SubTargetsManager} subTargetsManager |
| 562 */ |
| 563 WebInspector.ServiceWorkerContextNamer = function(target, serviceWorkerManager,
subTargetsManager) |
| 564 { |
| 565 this._target = target; |
| 566 this._serviceWorkerManager = serviceWorkerManager; |
| 567 this._subTargetsManager = subTargetsManager; |
| 568 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */ |
| 569 this._versionByTargetId = new Map(); |
| 570 serviceWorkerManager.addEventListener(WebInspector.ServiceWorkerManager.Even
ts.RegistrationUpdated, this._registrationsUpdated, this); |
| 571 serviceWorkerManager.addEventListener(WebInspector.ServiceWorkerManager.Even
ts.RegistrationDeleted, this._registrationsUpdated, this); |
| 572 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn
spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat
ed, this); |
| 573 } |
| 574 |
| 575 WebInspector.ServiceWorkerContextNamer.prototype = { |
| 576 /** |
| 577 * @param {!WebInspector.Event} event |
| 578 */ |
| 579 _registrationsUpdated: function(event) |
| 580 { |
| 581 this._versionByTargetId.clear(); |
| 582 var registrations = this._serviceWorkerManager.registrations().valuesArr
ay(); |
| 583 for (var registration of registrations) { |
| 584 var versions = registration.versions.valuesArray(); |
| 585 for (var version of versions) { |
| 586 if (version.targetId) |
| 587 this._versionByTargetId.set(version.targetId, version); |
| 588 } |
| 589 } |
| 590 this._updateAllContextLabels(); |
| 591 }, |
| 592 |
| 593 /** |
| 594 * @param {!WebInspector.Event} event |
| 595 */ |
| 596 _executionContextCreated: function(event) |
| 597 { |
| 598 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev
ent.data); |
| 599 var serviceWorkerTargetId = this._serviceWorkerTargetIdForWorker(executi
onContext.target()); |
| 600 if (!serviceWorkerTargetId) |
| 601 return; |
| 602 this._updateContextLabel(executionContext, this._versionByTargetId.get(s
erviceWorkerTargetId) || null); |
| 603 }, |
| 604 |
| 605 /** |
| 606 * @param {!WebInspector.Target} target |
| 607 * @return {?string} |
| 608 */ |
| 609 _serviceWorkerTargetIdForWorker: function(target) |
| 610 { |
| 611 var parent = target.parentTarget(); |
| 612 if (!parent || parent.parentTarget() !== this._target) |
| 613 return null; |
| 614 if (this._subTargetsManager.targetType(parent) !== "service_worker") |
| 615 return null; |
| 616 return this._subTargetsManager.targetId(parent); |
| 617 }, |
| 618 |
| 619 _updateAllContextLabels: function() |
| 620 { |
| 621 for (var target of WebInspector.targetManager.targets()) { |
| 622 var serviceWorkerTargetId = this._serviceWorkerTargetIdForWorker(tar
get); |
| 623 if (!serviceWorkerTargetId) |
| 624 continue; |
| 625 var version = this._versionByTargetId.get(serviceWorkerTargetId) ||
null; |
| 626 for (var context of target.runtimeModel.executionContexts()) |
| 627 this._updateContextLabel(context, version); |
| 628 } |
| 629 }, |
| 630 |
| 631 /** |
| 632 * @param {!WebInspector.ExecutionContext} context |
| 633 * @param {?WebInspector.ServiceWorkerVersion} version |
| 634 */ |
| 635 _updateContextLabel: function(context, version) |
| 636 { |
| 637 var parsedUrl = context.origin.asParsedURL(); |
| 638 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : cont
ext.name; |
| 639 if (version) |
| 640 context.setLabel(label + " #" + version.id + " (" + version.status +
")"); |
| 641 else |
| 642 context.setLabel(label); |
| 643 }, |
| 644 } |
| OLD | NEW |