Chromium Code Reviews| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 /** | 231 /** |
| 232 * @param {!WebInspector.ServiceWorkerRegistration} registration | 232 * @param {!WebInspector.ServiceWorkerRegistration} registration |
| 233 */ | 233 */ |
| 234 _updateRegistration: function(registration) | 234 _updateRegistration: function(registration) |
| 235 { | 235 { |
| 236 var swRegistrationElement = this._registrationElements.get(registration. id); | 236 var swRegistrationElement = this._registrationElements.get(registration. id); |
| 237 if (swRegistrationElement) { | 237 if (swRegistrationElement) { |
| 238 swRegistrationElement._updateRegistration(registration); | 238 swRegistrationElement._updateRegistration(registration); |
| 239 return; | 239 return; |
| 240 } | 240 } |
| 241 swRegistrationElement = new WebInspector.SWRegistrationElement(this._man ager, registration); | 241 swRegistrationElement = new WebInspector.SWRegistrationElement(this._man ager, this, registration); |
| 242 this._registrationElements.set(registration.id, swRegistrationElement); | 242 this._registrationElements.set(registration.id, swRegistrationElement); |
| 243 this._childrenListNode.appendChild(swRegistrationElement._element); | 243 this._childrenListNode.appendChild(swRegistrationElement._element); |
| 244 }, | 244 }, |
| 245 | 245 |
| 246 /** | 246 /** |
| 247 * @param {string} registrationId | 247 * @param {string} registrationId |
| 248 */ | 248 */ |
| 249 _deleteRegistration: function(registrationId) | 249 _deleteRegistration: function(registrationId) |
| 250 { | 250 { |
| 251 var swRegistrationElement = this._registrationElements.get(registrationI d); | 251 var swRegistrationElement = this._registrationElements.get(registrationI d); |
| 252 if (!swRegistrationElement) | 252 if (!swRegistrationElement) |
| 253 return; | 253 return; |
| 254 this._registrationElements.delete(registrationId); | 254 this._registrationElements.delete(registrationId); |
| 255 this._childrenListNode.removeChild(swRegistrationElement._element); | 255 this._childrenListNode.removeChild(swRegistrationElement._element); |
| 256 } | 256 }, |
| 257 | |
| 258 /** | |
| 259 * @return {boolean} | |
| 260 */ | |
| 261 _visible: function() | |
| 262 { | |
| 263 return !!this._element.parentElement; | |
| 264 }, | |
| 257 } | 265 } |
| 258 | 266 |
| 259 /** | 267 /** |
| 260 * @constructor | 268 * @constructor |
| 261 * @param {!WebInspector.ServiceWorkerManager} manager | 269 * @param {!WebInspector.ServiceWorkerManager} manager |
| 270 * @param {!WebInspector.ServiceWorkerOriginElement} originElement | |
| 262 * @param {!WebInspector.ServiceWorkerRegistration} registration | 271 * @param {!WebInspector.ServiceWorkerRegistration} registration |
| 263 */ | 272 */ |
| 264 WebInspector.SWRegistrationElement = function(manager, registration) | 273 WebInspector.SWRegistrationElement = function(manager, originElement, registrati on) |
| 265 { | 274 { |
| 266 this._manager = manager; | 275 this._manager = manager; |
| 276 this._originElement = originElement; | |
| 267 this._registration = registration; | 277 this._registration = registration; |
| 268 this._element = createElementWithClass("div", "service-workers-registration" ); | 278 this._element = createElementWithClass("div", "service-workers-registration" ); |
| 269 var headerNode = this._element.createChild("li").createChild("div", "service -workers-registration-header"); | 279 var headerNode = this._element.createChild("li").createChild("div", "service -workers-registration-header"); |
| 270 this._titleNode = headerNode.createChild("div", "service-workers-registratio n-title"); | 280 this._titleNode = headerNode.createChild("div", "service-workers-registratio n-title"); |
| 271 this._deleteButton = headerNode.createChild("button", "service-workers-butto n service-workers-delete-button"); | 281 this._deleteButton = headerNode.createChild("button", "service-workers-butto n service-workers-delete-button"); |
| 272 this._deleteButton.addEventListener("click", this._deleteButtonClicked.bind( this), false); | 282 this._deleteButton.addEventListener("click", this._deleteButtonClicked.bind( this), false); |
| 273 this._deleteButton.title = WebInspector.UIString("Delete"); | 283 this._deleteButton.title = WebInspector.UIString("Delete"); |
| 274 this._updateButton = headerNode.createChild("button", "service-workers-butto n service-workers-update-button"); | 284 this._updateButton = headerNode.createChild("button", "service-workers-butto n service-workers-update-button"); |
| 275 this._updateButton.addEventListener("click", this._updateButtonClicked.bind( this), false); | 285 this._updateButton.addEventListener("click", this._updateButtonClicked.bind( this), false); |
| 276 this._updateButton.title = WebInspector.UIString("Update"); | 286 this._updateButton.title = WebInspector.UIString("Update"); |
| 277 this._updateButton.disabled = true | 287 this._updateButton.disabled = true |
| 278 this._pushButton = headerNode.createChild("button", "service-workers-button service-workers-push-button"); | 288 this._pushButton = headerNode.createChild("button", "service-workers-button service-workers-push-button"); |
| 279 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this ), false); | 289 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this ), false); |
| 280 this._pushButton.title = WebInspector.UIString("Emulate push event"); | 290 this._pushButton.title = WebInspector.UIString("Emulate push event"); |
| 281 this._pushButton.disabled = true | 291 this._pushButton.disabled = true |
| 282 this._childrenListNode = this._element.createChild("ol"); | 292 this._childrenListNode = this._element.createChild("ol"); |
| 293 | |
| 294 this._skipWaitingCheckboxLabel = createCheckboxLabel(WebInspector.UIString(" Skip waiting")); | |
| 295 this._skipWaitingCheckboxLabel.title = WebInspector.UIString("Simulate skipW aiting()"); | |
| 296 this._skipWaitingCheckboxLabel.classList.add("service-workers-skip-waiting-c heckbox-label"); | |
| 297 this._skipWaitingCheckbox = this._skipWaitingCheckboxLabel.checkboxElement; | |
| 298 this._skipWaitingCheckbox.checked = true; | |
| 299 this._skipWaitingCheckbox.classList.add("service-workers-skip-waiting-checkb ox"); | |
| 300 this._skipWaitingCheckbox.addEventListener("change", this._skipWaitingCheckb oxChanged.bind(this), false); | |
| 301 | |
| 283 this._updateRegistration(registration); | 302 this._updateRegistration(registration); |
| 284 } | 303 } |
| 285 | 304 |
| 286 WebInspector.SWRegistrationElement.prototype = { | 305 WebInspector.SWRegistrationElement.prototype = { |
| 287 /** | 306 /** |
| 288 * @param {!WebInspector.ServiceWorkerRegistration} registration | 307 * @param {!WebInspector.ServiceWorkerRegistration} registration |
| 289 */ | 308 */ |
| 290 _updateRegistration: function(registration) | 309 _updateRegistration: function(registration) |
| 291 { | 310 { |
| 292 this._registration = registration; | 311 this._registration = registration; |
| 293 this._titleNode.textContent = WebInspector.UIString(registration.isDelet ed ? "Scope: %s - deleted" : "Scope: %s", registration.scopeURL.asParsedURL().pa th); | 312 this._titleNode.textContent = WebInspector.UIString(registration.isDelet ed ? "Scope: %s - deleted" : "Scope: %s", registration.scopeURL.asParsedURL().pa th); |
| 294 this._updateButton.disabled = !!registration.isDeleted; | 313 this._updateButton.disabled = !!registration.isDeleted; |
| 295 this._deleteButton.disabled = !!registration.isDeleted; | 314 this._deleteButton.disabled = !!registration.isDeleted; |
| 315 this._skipWaitingCheckboxLabel.remove(); | |
| 296 this._updateVersionList(); | 316 this._updateVersionList(); |
| 317 if (this._visible() && this._skipWaitingCheckbox.checked) { | |
| 318 this._registration.versions.valuesArray().map((function(version) { | |
|
pfeldman
2015/04/27 16:47:30
This should be an annotated named function.
horo
2015/04/28 02:18:44
Done.
| |
| 319 if (version.isInstalled()) | |
| 320 this._manager.skipWaiting(version.id); | |
| 321 }).bind(this)); | |
| 322 } | |
| 297 }, | 323 }, |
| 298 | 324 |
| 299 _updateVersionList: function() | 325 _updateVersionList: function() |
| 300 { | 326 { |
| 301 var fragment = createDocumentFragment(); | 327 var fragment = createDocumentFragment(); |
| 302 var tableElement = createElementWithClass("div", "service-workers-versio ns-table"); | 328 var tableElement = createElementWithClass("div", "service-workers-versio ns-table"); |
| 303 var versions = this._registration.versions.valuesArray(); | 329 var versions = this._registration.versions.valuesArray(); |
| 304 versions = versions.filter(function(version) { | 330 versions = versions.filter(function(version) { |
| 305 return !version.isStoppedAndRedundant() || version.errorMessages.len gth; | 331 return !version.isStoppedAndRedundant() || version.errorMessages.len gth; |
| 306 }); | 332 }); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 329 }, | 355 }, |
| 330 | 356 |
| 331 /** | 357 /** |
| 332 * @param {!Array.<!WebInspector.ServiceWorkerVersion>} versions | 358 * @param {!Array.<!WebInspector.ServiceWorkerVersion>} versions |
| 333 * @param {string} modeClass | 359 * @param {string} modeClass |
| 334 * @param {string} modeTitle | 360 * @param {string} modeTitle |
| 335 */ | 361 */ |
| 336 _createVersionModeRow: function(versions, modeClass, modeTitle) | 362 _createVersionModeRow: function(versions, modeClass, modeTitle) |
| 337 { | 363 { |
| 338 var modeRowElement = createElementWithClass("div", "service-workers-vers ion-mode-row service-workers-version-mode-row-" + modeClass); | 364 var modeRowElement = createElementWithClass("div", "service-workers-vers ion-mode-row service-workers-version-mode-row-" + modeClass); |
| 339 modeRowElement.createChild("div", "service-workers-version-mode").create Child("div", "service-workers-version-mode-text").createTextChild(modeTitle); | 365 var modeTitleDiv = modeRowElement.createChild("div", "service-workers-ve rsion-mode"); |
| 366 modeTitleDiv.createChild("div", "service-workers-version-mode-text").cre ateTextChild(modeTitle); | |
| 367 if (modeClass == "waiting") { | |
| 368 modeTitleDiv.appendChild(this._skipWaitingCheckboxLabel); | |
| 369 } | |
| 340 var versionsElement = modeRowElement.createChild("div", "service-workers -versions"); | 370 var versionsElement = modeRowElement.createChild("div", "service-workers -versions"); |
| 341 for (var version of versions) { | 371 for (var version of versions) { |
| 342 var stateRowElement = versionsElement.createChild("div", "service-wo rkers-version-row"); | 372 var stateRowElement = versionsElement.createChild("div", "service-wo rkers-version-row"); |
| 343 var statusDiv = stateRowElement.createChild("div", "service-workers- version-status"); | 373 var statusDiv = stateRowElement.createChild("div", "service-workers- version-status"); |
| 344 var icon = statusDiv.createChild("div", "service-workers-version-sta tus-icon service-workers-color-" + (version.id % 10)); | 374 var icon = statusDiv.createChild("div", "service-workers-version-sta tus-icon service-workers-color-" + (version.id % 10)); |
| 345 icon.title = WebInspector.UIString("ID: %s", version.id); | 375 icon.title = WebInspector.UIString("ID: %s", version.id); |
| 346 statusDiv.createChild("div", "service-workers-version-status-text"). createTextChild(version.status); | 376 statusDiv.createChild("div", "service-workers-version-status-text"). createTextChild(version.status); |
| 347 var runningStatusDiv = stateRowElement.createChild("div", "service-w orkers-version-running-status"); | 377 var runningStatusDiv = stateRowElement.createChild("div", "service-w orkers-version-running-status"); |
| 348 if (version.isRunning() || version.isStarting()) { | 378 if (version.isRunning() || version.isStarting()) { |
| 349 var stopButton = runningStatusDiv.createChild("button", "service -workers-button service-workers-stop-button service-workers-version-running-stat us-button"); | 379 var stopButton = runningStatusDiv.createChild("button", "service -workers-button service-workers-stop-button service-workers-version-running-stat us-button"); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 this._manager.stopWorker(versionId); | 471 this._manager.stopWorker(versionId); |
| 442 }, | 472 }, |
| 443 | 473 |
| 444 /** | 474 /** |
| 445 * @param {string} versionId | 475 * @param {string} versionId |
| 446 * @param {!Event} event | 476 * @param {!Event} event |
| 447 */ | 477 */ |
| 448 _inspectButtonClicked: function(versionId, event) | 478 _inspectButtonClicked: function(versionId, event) |
| 449 { | 479 { |
| 450 this._manager.inspectWorker(versionId); | 480 this._manager.inspectWorker(versionId); |
| 451 } | 481 }, |
| 482 | |
| 483 _skipWaitingCheckboxChanged: function() | |
| 484 { | |
| 485 if (!this._skipWaitingCheckbox.checked) | |
| 486 return; | |
| 487 this._registration.versions.valuesArray().map((function(version) { | |
|
pfeldman
2015/04/27 16:47:30
ditto
horo
2015/04/28 02:18:44
Done.
| |
| 488 if (version.isInstalled()) | |
| 489 this._manager.skipWaiting(version.id); | |
| 490 }).bind(this)); | |
| 491 }, | |
| 492 | |
| 493 /** | |
| 494 * @return {boolean} | |
| 495 */ | |
| 496 _visible: function() | |
| 497 { | |
| 498 return this._originElement._visible(); | |
| 499 }, | |
| 452 } | 500 } |
| OLD | NEW |