| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.ServiceWorkersView = function() | 10 WebInspector.ServiceWorkersView = function() |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration | 78 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration |
| 79 */ | 79 */ |
| 80 _updateRegistration: function(registration) | 80 _updateRegistration: function(registration) |
| 81 { | 81 { |
| 82 var parsedURL = registration.scopeURL.asParsedURL(); | 82 var parsedURL = registration.scopeURL.asParsedURL(); |
| 83 if (!parsedURL) | 83 if (!parsedURL) |
| 84 return; | 84 return; |
| 85 var originHost = parsedURL.host; | 85 var originHost = parsedURL.host; |
| 86 var originElement = this._originHostToOriginElementMap.get(originHost); | 86 var originElement = this._originHostToOriginElementMap.get(originHost); |
| 87 if (!originElement) { | 87 if (!originElement) { |
| 88 originElement = new WebInspector.ServiceWorkerOriginElement(originHo
st); | 88 originElement = new WebInspector.ServiceWorkerOriginElement(this._ma
nager, originHost); |
| 89 if (this._securityOriginHosts.has(originHost)) | 89 if (this._securityOriginHosts.has(originHost)) |
| 90 this._appendOriginNode(originElement); | 90 this._appendOriginNode(originElement); |
| 91 this._originHostToOriginElementMap.set(originHost, originElement); | 91 this._originHostToOriginElementMap.set(originHost, originElement); |
| 92 } | 92 } |
| 93 this._registrationIdToOriginElementMap.set(registration.registrationId,
originElement); | 93 this._registrationIdToOriginElementMap.set(registration.registrationId,
originElement); |
| 94 originElement._updateRegistration(registration); | 94 originElement._updateRegistration(registration); |
| 95 }, | 95 }, |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * @param {!WebInspector.Event} event | 98 * @param {!WebInspector.Event} event |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 _removeOriginNode: function(originElement) | 200 _removeOriginNode: function(originElement) |
| 201 { | 201 { |
| 202 this.root.removeChild(originElement.element); | 202 this.root.removeChild(originElement.element); |
| 203 }, | 203 }, |
| 204 | 204 |
| 205 __proto__: WebInspector.VBox.prototype | 205 __proto__: WebInspector.VBox.prototype |
| 206 } | 206 } |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * @constructor | 209 * @constructor |
| 210 * @param {!WebInspector.ServiceWorkerManager} manager |
| 210 * @param {string} originHost | 211 * @param {string} originHost |
| 211 */ | 212 */ |
| 212 WebInspector.ServiceWorkerOriginElement = function(originHost) | 213 WebInspector.ServiceWorkerOriginElement = function(manager, originHost) |
| 213 { | 214 { |
| 215 this._manager = manager; |
| 214 /** @type {!Map.<string, !WebInspector.SWRegistrationElement>} */ | 216 /** @type {!Map.<string, !WebInspector.SWRegistrationElement>} */ |
| 215 this._registrationElements = new Map(); | 217 this._registrationElements = new Map(); |
| 216 this.originHost = originHost; | 218 this.originHost = originHost; |
| 217 this.element = createElementWithClass("div", "service-workers-origin"); | 219 this.element = createElementWithClass("div", "service-workers-origin"); |
| 218 this._listItemNode = this.element.createChild("li", "service-workers-origin-
title"); | 220 this._listItemNode = this.element.createChild("li", "service-workers-origin-
title"); |
| 219 this._listItemNode.createChild("div").createTextChild(originHost); | 221 this._listItemNode.createChild("div").createTextChild(originHost); |
| 220 this._childrenListNode = this.element.createChild("ol"); | 222 this._childrenListNode = this.element.createChild("ol"); |
| 221 } | 223 } |
| 222 | 224 |
| 223 WebInspector.ServiceWorkerOriginElement.prototype = { | 225 WebInspector.ServiceWorkerOriginElement.prototype = { |
| 224 /** | 226 /** |
| 225 * @return {boolean} | 227 * @return {boolean} |
| 226 */ | 228 */ |
| 227 _hasRegistration: function() | 229 _hasRegistration: function() |
| 228 { | 230 { |
| 229 return this._registrationElements.size != 0; | 231 return this._registrationElements.size != 0; |
| 230 }, | 232 }, |
| 231 | 233 |
| 232 /** | 234 /** |
| 233 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration | 235 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration |
| 234 */ | 236 */ |
| 235 _updateRegistration: function(registration) | 237 _updateRegistration: function(registration) |
| 236 { | 238 { |
| 237 var swRegistrationElement = this._registrationElements.get(registration.
registrationId); | 239 var swRegistrationElement = this._registrationElements.get(registration.
registrationId); |
| 238 if (swRegistrationElement) { | 240 if (swRegistrationElement) { |
| 239 swRegistrationElement._updateRegistration(registration); | 241 swRegistrationElement._updateRegistration(registration); |
| 240 return; | 242 return; |
| 241 } | 243 } |
| 242 swRegistrationElement = new WebInspector.SWRegistrationElement(registrat
ion); | 244 swRegistrationElement = new WebInspector.SWRegistrationElement(this._man
ager, registration); |
| 243 this._registrationElements.set(registration.registrationId, swRegistrati
onElement); | 245 this._registrationElements.set(registration.registrationId, swRegistrati
onElement); |
| 244 this._childrenListNode.appendChild(swRegistrationElement.element); | 246 this._childrenListNode.appendChild(swRegistrationElement.element); |
| 245 }, | 247 }, |
| 246 | 248 |
| 247 /** | 249 /** |
| 248 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration | 250 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration |
| 249 */ | 251 */ |
| 250 _deleteRegistration: function(registration) | 252 _deleteRegistration: function(registration) |
| 251 { | 253 { |
| 252 var swRegistrationElement = this._registrationElements.get(registration.
registrationId); | 254 var swRegistrationElement = this._registrationElements.get(registration.
registrationId); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 274 { | 276 { |
| 275 var swRegistrationElement = this._registrationElements.get(version.regis
trationId); | 277 var swRegistrationElement = this._registrationElements.get(version.regis
trationId); |
| 276 if (!swRegistrationElement) | 278 if (!swRegistrationElement) |
| 277 return; | 279 return; |
| 278 swRegistrationElement._deleteVersion(version); | 280 swRegistrationElement._deleteVersion(version); |
| 279 } | 281 } |
| 280 } | 282 } |
| 281 | 283 |
| 282 /** | 284 /** |
| 283 * @constructor | 285 * @constructor |
| 286 * @param {!WebInspector.ServiceWorkerManager} manager |
| 284 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration | 287 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration |
| 285 */ | 288 */ |
| 286 WebInspector.SWRegistrationElement = function(registration) | 289 WebInspector.SWRegistrationElement = function(manager, registration) |
| 287 { | 290 { |
| 291 this._manager = manager; |
| 288 /** @type {!ServiceWorkerAgent.ServiceWorkerRegistration} */ | 292 /** @type {!ServiceWorkerAgent.ServiceWorkerRegistration} */ |
| 289 this._registration = registration; | 293 this._registration = registration; |
| 290 /** @type {!Map.<string, !ServiceWorkerAgent.ServiceWorkerVersion>} */ | 294 /** @type {!Map.<string, !ServiceWorkerAgent.ServiceWorkerVersion>} */ |
| 291 this._versions = new Map(); | 295 this._versions = new Map(); |
| 292 this.element = createElementWithClass("div", "service-workers-registration")
; | 296 this.element = createElementWithClass("div", "service-workers-registration")
; |
| 293 this._titleNode = this.element.createChild("li").createChild("div", "service
-workers-registration-title"); | 297 var headerNode = this.element.createChild("li").createChild("div", "service-
workers-registration-header"); |
| 298 this._titleNode = headerNode.createChild("div", "service-workers-registratio
n-title"); |
| 299 this._unregisterButton = headerNode.createChild("button", "service-workers-b
utton service-workers-unregister-button"); |
| 300 this._unregisterButton.addEventListener("click", this._unregisterButtonClick
ed.bind(this), false); |
| 301 this._unregisterButton.title = WebInspector.UIString("Unregister"); |
| 294 this._childrenListNode = this.element.createChild("ol"); | 302 this._childrenListNode = this.element.createChild("ol"); |
| 295 this._updateRegistration(registration); | 303 this._updateRegistration(registration); |
| 296 } | 304 } |
| 297 | 305 |
| 298 /** @enum {string} */ | 306 /** @enum {string} */ |
| 299 WebInspector.SWRegistrationElement.VersionMode = { | 307 WebInspector.SWRegistrationElement.VersionMode = { |
| 300 Installing: "installing", | 308 Installing: "installing", |
| 301 Waiting: "waiting", | 309 Waiting: "waiting", |
| 302 Active: "active", | 310 Active: "active", |
| 303 Redundant: "redundant", | 311 Redundant: "redundant", |
| 304 } | 312 } |
| 305 | 313 |
| 306 /** @type {!Map.<string, string>} */ | 314 /** @type {!Map.<string, string>} */ |
| 307 WebInspector.SWRegistrationElement.VersionStausToModeMap = new Map([ | 315 WebInspector.SWRegistrationElement.VersionStausToModeMap = new Map([ |
| 308 [ServiceWorkerAgent.ServiceWorkerVersionStatus.New, WebInspector.SWRegistrat
ionElement.VersionMode.Installing], | 316 [ServiceWorkerAgent.ServiceWorkerVersionStatus.New, WebInspector.SWRegistrat
ionElement.VersionMode.Installing], |
| 309 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installing, WebInspector.SWRe
gistrationElement.VersionMode.Installing], | 317 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installing, WebInspector.SWRe
gistrationElement.VersionMode.Installing], |
| 310 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installed, WebInspector.SWReg
istrationElement.VersionMode.Waiting], | 318 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installed, WebInspector.SWReg
istrationElement.VersionMode.Waiting], |
| 311 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activating, WebInspector.SWRe
gistrationElement.VersionMode.Active], | 319 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activating, WebInspector.SWRe
gistrationElement.VersionMode.Active], |
| 312 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activated, WebInspector.SWReg
istrationElement.VersionMode.Active], | 320 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activated, WebInspector.SWReg
istrationElement.VersionMode.Active], |
| 313 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Redundant, WebInspector.SWReg
istrationElement.VersionMode.Redundant]]); | 321 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Redundant, WebInspector.SWReg
istrationElement.VersionMode.Redundant]]); |
| 314 | 322 |
| 315 WebInspector.SWRegistrationElement.prototype = { | 323 WebInspector.SWRegistrationElement.prototype = { |
| 316 /** | 324 /** |
| 317 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration | 325 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration |
| 318 */ | 326 */ |
| 319 _updateRegistration: function(registration) | 327 _updateRegistration: function(registration) |
| 320 { | 328 { |
| 321 this._registration = registration; | 329 this._registration = registration; |
| 322 var text = WebInspector.UIString("Scope: ") + registration.scopeURL.asPa
rsedURL().path; | 330 this._titleNode.textContent = WebInspector.UIString(registration.isDelet
ed ? "Scope: %s - deleted" : "Scope: %s", registration.scopeURL.asParsedURL().pa
th); |
| 323 if (registration.isDeleted) | 331 this._unregisterButton.style.display = registration.isDeleted? "none" :
"block"; |
| 324 text += " - deleted"; | 332 this._updateVersionList(); |
| 325 this._titleNode.textContent = text; | |
| 326 }, | 333 }, |
| 327 | 334 |
| 328 /** | 335 /** |
| 329 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} version | 336 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} version |
| 330 */ | 337 */ |
| 331 _updateVersion: function(version) | 338 _updateVersion: function(version) |
| 332 { | 339 { |
| 333 this._versions.set(version.versionId, version); | 340 this._versions.set(version.versionId, version); |
| 334 this._updateVersionList(); | 341 this._updateVersionList(); |
| 335 }, | 342 }, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 WebInspector.SWRegistrationElement.VersionMode.Redundant)); | 378 WebInspector.SWRegistrationElement.VersionMode.Redundant)); |
| 372 fragment.appendChild(tableElement); | 379 fragment.appendChild(tableElement); |
| 373 this._childrenListNode.removeChildren(); | 380 this._childrenListNode.removeChildren(); |
| 374 this._childrenListNode.appendChild(fragment); | 381 this._childrenListNode.appendChild(fragment); |
| 375 }, | 382 }, |
| 376 | 383 |
| 377 /** | 384 /** |
| 378 * @param {!Map.<string, !Array.<!ServiceWorkerAgent.ServiceWorkerVersion>>}
modeVersionArrayMap | 385 * @param {!Map.<string, !Array.<!ServiceWorkerAgent.ServiceWorkerVersion>>}
modeVersionArrayMap |
| 379 * @param {string} mode | 386 * @param {string} mode |
| 380 */ | 387 */ |
| 381 _createVersionModeRow: function(modeVersionArrayMap, mode) { | 388 _createVersionModeRow: function(modeVersionArrayMap, mode) |
| 389 { |
| 382 var versionList = /** @type {!Array.<!ServiceWorkerAgent.ServiceWorkerVe
rsion>} */(modeVersionArrayMap.get(mode)); | 390 var versionList = /** @type {!Array.<!ServiceWorkerAgent.ServiceWorkerVe
rsion>} */(modeVersionArrayMap.get(mode)); |
| 383 var modeRowElement = createElementWithClass("div", "service-workers-vers
ion-mode-row service-workers-version-mode-row-" + mode); | 391 var modeRowElement = createElementWithClass("div", "service-workers-vers
ion-mode-row service-workers-version-mode-row-" + mode); |
| 384 modeRowElement.createChild("div", "service-workers-version-mode").create
TextChild(mode); | 392 modeRowElement.createChild("div", "service-workers-version-mode").create
Child("div", "service-workers-version-mode-text").createTextChild(mode); |
| 385 var versionsElement = modeRowElement.createChild("div", "service-workers
-versions" + mode); | 393 var versionsElement = modeRowElement.createChild("div", "service-workers
-versions"); |
| 386 for (var version of versionList) { | 394 for (var version of versionList) { |
| 387 var stateRowElement = versionsElement.createChild("div", "service-wo
rkers-version-row"); | 395 var stateRowElement = versionsElement.createChild("div", "service-wo
rkers-version-row"); |
| 388 stateRowElement.createChild("div", "service-workers-version-status")
.createTextChild(version.status); | 396 var statusDiv = stateRowElement.createChild("div", "service-workers-
version-status"); |
| 389 stateRowElement.createChild("div", "service-workers-version-running-
status").createTextChild(version.runningStatus); | 397 statusDiv.createChild("div", "service-workers-version-status-text").
createTextChild(version.status); |
| 390 stateRowElement.createChild("div", "service-workers-version-script-u
rl").createTextChild(version.scriptURL.asParsedURL().path); | 398 var runningStatusDiv = stateRowElement.createChild("div", "service-w
orkers-version-running-status"); |
| 399 if (version.runningStatus == ServiceWorkerAgent.ServiceWorkerVersion
RunningStatus.Running || version.runningStatus == ServiceWorkerAgent.ServiceWork
erVersionRunningStatus.Starting) { |
| 400 var stopButton = runningStatusDiv.createChild("button", "service
-workers-button service-workers-stop-button service-workers-version-running-stat
us-button"); |
| 401 stopButton.addEventListener("click", this._stopButtonClicked.bin
d(this, version.versionId), false); |
| 402 stopButton.title = WebInspector.UIString("Stop"); |
| 403 } else if (version.runningStatus == ServiceWorkerAgent.ServiceWorker
VersionRunningStatus.Stopped && !this._registration.isDeleted) { |
| 404 var startButton = runningStatusDiv.createChild("button", "servic
e-workers-button service-workers-start-button service-workers-version-running-st
atus-button"); |
| 405 startButton.addEventListener("click", this._startButtonClicked.b
ind(this), false); |
| 406 startButton.title = WebInspector.UIString("Start"); |
| 407 } |
| 408 runningStatusDiv.createChild("div", "service-workers-version-running
-status-text").createTextChild(version.runningStatus); |
| 409 var scriptURLDiv = stateRowElement.createChild("div", "service-worke
rs-version-script-url"); |
| 410 scriptURLDiv.createChild("div", "service-workers-version-script-url-
text").createTextChild(version.scriptURL.asParsedURL().path); |
| 411 if (version.runningStatus == ServiceWorkerAgent.ServiceWorkerVersion
RunningStatus.Running || version.runningStatus == ServiceWorkerAgent.ServiceWork
erVersionRunningStatus.Starting) { |
| 412 var inspectButton = scriptURLDiv.createChild("span", "service-wo
rkers-version-inspect"); |
| 413 inspectButton.createTextChild(WebInspector.UIString("inspect")); |
| 414 inspectButton.addEventListener("click", this._inspectButtonClick
ed.bind(this, version.versionId), false); |
| 415 } |
| 391 } | 416 } |
| 392 if (versionList.length == 0) { | 417 if (versionList.length == 0) { |
| 393 var stateRowElement = versionsElement.createChild("div", "service-wo
rkers-version-row"); | 418 var stateRowElement = versionsElement.createChild("div", "service-wo
rkers-version-row"); |
| 394 stateRowElement.createChild("div", "service-workers-version-status")
; | 419 stateRowElement.createChild("div", "service-workers-version-status")
; |
| 395 stateRowElement.createChild("div", "service-workers-version-running-
status"); | 420 stateRowElement.createChild("div", "service-workers-version-running-
status"); |
| 396 stateRowElement.createChild("div", "service-workers-version-script-u
rl"); | 421 stateRowElement.createChild("div", "service-workers-version-script-u
rl"); |
| 397 } | 422 } |
| 398 return modeRowElement; | 423 return modeRowElement; |
| 424 }, |
| 425 |
| 426 /** |
| 427 * @param {!Event} event |
| 428 */ |
| 429 _unregisterButtonClicked: function(event) |
| 430 { |
| 431 this._manager.unregister(this._registration.scopeURL); |
| 432 }, |
| 433 |
| 434 /** |
| 435 * @param {!Event} event |
| 436 */ |
| 437 _startButtonClicked: function(event) |
| 438 { |
| 439 this._manager.startWorker(this._registration.scopeURL); |
| 440 }, |
| 441 |
| 442 /** |
| 443 * @param {string} versionId |
| 444 * @param {!Event} event |
| 445 */ |
| 446 _stopButtonClicked: function(versionId, event) |
| 447 { |
| 448 this._manager.stopWorker(versionId); |
| 449 }, |
| 450 |
| 451 /** |
| 452 * @param {string} versionId |
| 453 * @param {!Event} event |
| 454 */ |
| 455 _inspectButtonClicked: function(versionId, event) |
| 456 { |
| 457 this._manager.inspectWorker(versionId); |
| 399 } | 458 } |
| 400 } | 459 } |
| OLD | NEW |