| 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() |
| 11 { | 11 { |
| 12 WebInspector.VBox.call(this, true); | 12 WebInspector.VBox.call(this, true); |
| 13 | 13 |
| 14 this._reportView = new WebInspector.ReportView(WebInspector.UIString("Servic
e Workers")); | 14 this._reportView = new WebInspector.ReportView(WebInspector.UIString("Servic
e Workers")); |
| 15 this._reportView.show(this.contentElement); | 15 this._reportView.show(this.contentElement); |
| 16 | 16 |
| 17 this._toolbar = this._reportView.createToolbar(); | 17 this._toolbar = this._reportView.createToolbar(); |
| 18 | 18 |
| 19 /** @type {!Map<!WebInspector.ServiceWorkerRegistration, !WebInspector.Servi
ceWorkersView.Section>} */ | 19 /** @type {!Map<!WebInspector.ServiceWorkerRegistration, !WebInspector.Servi
ceWorkersView.Section>} */ |
| 20 this._sections = new Map(); | 20 this._sections = new Map(); |
| 21 | 21 |
| 22 this._toolbar.appendToolbarItem(WebInspector.NetworkConditionsSelector.creat
eOfflineToolbarCheckbox()); |
| 23 var forceUpdate = new WebInspector.ToolbarCheckbox(WebInspector.UIString("Up
date on reload"), WebInspector.UIString("Force update Service Worker on page rel
oad"), WebInspector.settings.createSetting("serviceWorkerUpdateOnReload", false)
); |
| 24 this._toolbar.appendToolbarItem(forceUpdate); |
| 25 var fallbackToNetwork = new WebInspector.ToolbarCheckbox(WebInspector.UIStri
ng("Bypass for network"), WebInspector.UIString("Bypass Service Worker and load
resources from the network"), WebInspector.settings.createSetting("bypassService
Worker", false)); |
| 26 this._toolbar.appendToolbarItem(fallbackToNetwork); |
| 27 this._toolbar.appendSpacer(); |
| 28 this._showAllCheckbox = new WebInspector.ToolbarCheckbox(WebInspector.UIStri
ng("Show all"), WebInspector.UIString("Show all Service Workers regardless of th
e origin")); |
| 29 this._showAllCheckbox.inputElement.addEventListener("change", this._updateSe
ctionVisibility.bind(this), false); |
| 30 this._toolbar.appendToolbarItem(this._showAllCheckbox); |
| 31 |
| 32 /** @type {!Map<!WebInspector.Target, !Array<!WebInspector.EventTarget.Event
Descriptor>>}*/ |
| 33 this._eventListeners = new Map(); |
| 22 WebInspector.targetManager.observeTargets(this); | 34 WebInspector.targetManager.observeTargets(this); |
| 23 } | 35 } |
| 24 | 36 |
| 25 WebInspector.ServiceWorkersView.prototype = { | 37 WebInspector.ServiceWorkersView.prototype = { |
| 26 /** | 38 /** |
| 27 * @override | 39 * @override |
| 28 * @param {!WebInspector.Target} target | 40 * @param {!WebInspector.Target} target |
| 29 */ | 41 */ |
| 30 targetAdded: function(target) | 42 targetAdded: function(target) |
| 31 { | 43 { |
| 32 var securityOriginManager = WebInspector.SecurityOriginManager.fromTarge
t(target); | 44 if (this._manager || !target.serviceWorkerManager) |
| 33 if (this._manager || !target.serviceWorkerManager || !securityOriginMana
ger) | |
| 34 return; | 45 return; |
| 35 this._manager = target.serviceWorkerManager; | 46 this._manager = target.serviceWorkerManager; |
| 36 this._subTargetsManager = target.subTargetsManager; | 47 this._subTargetsManager = target.subTargetsManager; |
| 37 this._securityOriginManager = securityOriginManager; | 48 this._securityOriginManager = WebInspector.SecurityOriginManager.fromTar
get(target); |
| 38 | |
| 39 this._toolbar.appendToolbarItem(WebInspector.NetworkConditionsSelector.c
reateOfflineToolbarCheckbox()); | |
| 40 var forceUpdate = new WebInspector.ToolbarCheckbox(WebInspector.UIString
("Update on reload"), WebInspector.UIString("Force update Service Worker on page
reload"), this._manager.forceUpdateOnReloadSetting()); | |
| 41 this._toolbar.appendToolbarItem(forceUpdate); | |
| 42 var networkManager = target && WebInspector.NetworkManager.fromTarget(ta
rget); | |
| 43 if (networkManager) { | |
| 44 var fallbackToNetwork = new WebInspector.ToolbarCheckbox(WebInspecto
r.UIString("Bypass for network"), WebInspector.UIString("Bypass Service Worker a
nd load resources from the network"), networkManager.bypassServiceWorkerSetting(
)); | |
| 45 this._toolbar.appendToolbarItem(fallbackToNetwork); | |
| 46 this._toolbar.appendSpacer(); | |
| 47 } | |
| 48 this._showAllCheckbox = new WebInspector.ToolbarCheckbox(WebInspector.UI
String("Show all"), WebInspector.UIString("Show all Service Workers regardless o
f the origin")); | |
| 49 this._showAllCheckbox.inputElement.addEventListener("change", this._upda
teSectionVisibility.bind(this), false); | |
| 50 this._toolbar.appendToolbarItem(this._showAllCheckbox); | |
| 51 | 49 |
| 52 for (var registration of this._manager.registrations().values()) | 50 for (var registration of this._manager.registrations().values()) |
| 53 this._updateRegistration(registration); | 51 this._updateRegistration(registration); |
| 54 | 52 |
| 55 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events.
RegistrationUpdated, this._registrationUpdated, this); | 53 this._eventListeners.set(target, [ |
| 56 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events.
RegistrationDeleted, this._registrationDeleted, this); | 54 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Eve
nts.RegistrationUpdated, this._registrationUpdated, this), |
| 57 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events.
RegistrationErrorAdded, this._registrationErrorAdded, this); | 55 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Eve
nts.RegistrationDeleted, this._registrationDeleted, this), |
| 58 securityOriginManager.addEventListener(WebInspector.SecurityOriginManage
r.Events.SecurityOriginAdded, this._updateSectionVisibility, this); | 56 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Eve
nts.RegistrationErrorAdded, this._registrationErrorAdded, this), |
| 59 securityOriginManager.addEventListener(WebInspector.SecurityOriginManage
r.Events.SecurityOriginRemoved, this._updateSectionVisibility, this); | 57 this._securityOriginManager.addEventListener(WebInspector.SecurityOr
iginManager.Events.SecurityOriginAdded, this._updateSectionVisibility, this), |
| 58 this._securityOriginManager.addEventListener(WebInspector.SecurityOr
iginManager.Events.SecurityOriginRemoved, this._updateSectionVisibility, this), |
| 59 ]); |
| 60 }, | 60 }, |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * @override | 63 * @override |
| 64 * @param {!WebInspector.Target} target | 64 * @param {!WebInspector.Target} target |
| 65 */ | 65 */ |
| 66 targetRemoved: function(target) | 66 targetRemoved: function(target) |
| 67 { | 67 { |
| 68 if (this._manager !== target.serviceWorkerManager) | 68 if (!this._manager || this._manager !== target.serviceWorkerManager) |
| 69 return; | 69 return; |
| 70 |
| 71 WebInspector.EventTarget.removeEventListeners(this._eventListeners.get(t
arget)); |
| 72 this._eventListeners.delete(target); |
| 70 this._manager = null; | 73 this._manager = null; |
| 74 this._subTargetsManager = null; |
| 71 this._securityOriginManager = null; | 75 this._securityOriginManager = null; |
| 72 }, | 76 }, |
| 73 | 77 |
| 74 _updateSectionVisibility: function() | 78 _updateSectionVisibility: function() |
| 75 { | 79 { |
| 76 var securityOrigins = new Set(this._securityOriginManager.securityOrigin
s()); | 80 var securityOrigins = new Set(this._securityOriginManager.securityOrigin
s()); |
| 77 for (var section of this._sections.values()) { | 81 for (var section of this._sections.values()) { |
| 78 var visible = this._showAllCheckbox.checked() || securityOrigins.has
(section._registration.securityOrigin); | 82 var visible = this._showAllCheckbox.checked() || securityOrigins.has
(section._registration.securityOrigin); |
| 79 section._section.element.classList.toggle("hidden", !visible); | 83 section._section.element.classList.toggle("hidden", !visible); |
| 80 } | 84 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 return contentElement; | 427 return contentElement; |
| 424 }, | 428 }, |
| 425 | 429 |
| 426 _dispose: function() | 430 _dispose: function() |
| 427 { | 431 { |
| 428 this._linkifier.dispose(); | 432 this._linkifier.dispose(); |
| 429 if (this._pendingUpdate) | 433 if (this._pendingUpdate) |
| 430 clearTimeout(this._pendingUpdate); | 434 clearTimeout(this._pendingUpdate); |
| 431 } | 435 } |
| 432 } | 436 } |
| OLD | NEW |