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() |
| 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)); | |
|
dgozman
2016/10/14 18:33:34
Should we remove networkManager.bypassServiceWorke
pfeldman
2016/10/14 20:03:22
Done.
| |
| 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 | |
| 22 WebInspector.targetManager.observeTargets(this); | 32 WebInspector.targetManager.observeTargets(this); |
| 23 } | 33 } |
| 24 | 34 |
| 25 WebInspector.ServiceWorkersView.prototype = { | 35 WebInspector.ServiceWorkersView.prototype = { |
| 26 /** | 36 /** |
| 27 * @override | 37 * @override |
| 28 * @param {!WebInspector.Target} target | 38 * @param {!WebInspector.Target} target |
| 29 */ | 39 */ |
| 30 targetAdded: function(target) | 40 targetAdded: function(target) |
| 31 { | 41 { |
| 32 var securityOriginManager = WebInspector.SecurityOriginManager.fromTarge t(target); | 42 if (this._manager || !target.serviceWorkerManager) |
| 33 if (this._manager || !target.serviceWorkerManager || !securityOriginMana ger) | |
| 34 return; | 43 return; |
| 35 this._manager = target.serviceWorkerManager; | 44 this._manager = target.serviceWorkerManager; |
| 36 this._subTargetsManager = target.subTargetsManager; | 45 this._subTargetsManager = target.subTargetsManager; |
| 37 this._securityOriginManager = securityOriginManager; | 46 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 | 47 |
| 52 for (var registration of this._manager.registrations().values()) | 48 for (var registration of this._manager.registrations().values()) |
| 53 this._updateRegistration(registration); | 49 this._updateRegistration(registration); |
| 54 | 50 |
| 55 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationUpdated, this._registrationUpdated, this); | 51 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationUpdated, this._registrationUpdated, this); |
| 56 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationDeleted, this._registrationDeleted, this); | 52 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationDeleted, this._registrationDeleted, this); |
| 57 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationErrorAdded, this._registrationErrorAdded, this); | 53 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationErrorAdded, this._registrationErrorAdded, this); |
| 58 securityOriginManager.addEventListener(WebInspector.SecurityOriginManage r.Events.SecurityOriginAdded, this._updateSectionVisibility, this); | 54 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin Manager.Events.SecurityOriginAdded, this._updateSectionVisibility, this); |
| 59 securityOriginManager.addEventListener(WebInspector.SecurityOriginManage r.Events.SecurityOriginRemoved, this._updateSectionVisibility, this); | 55 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin Manager.Events.SecurityOriginRemoved, this._updateSectionVisibility, this); |
| 60 }, | 56 }, |
| 61 | 57 |
| 62 /** | 58 /** |
| 63 * @override | 59 * @override |
| 64 * @param {!WebInspector.Target} target | 60 * @param {!WebInspector.Target} target |
| 65 */ | 61 */ |
| 66 targetRemoved: function(target) | 62 targetRemoved: function(target) |
| 67 { | 63 { |
| 68 if (this._manager !== target.serviceWorkerManager) | 64 if (!this._manager && this._manager !== target.serviceWorkerManager) |
|
dgozman
2016/10/14 18:33:34
&& -> ||
pfeldman
2016/10/14 20:03:22
Oops :(
| |
| 69 return; | 65 return; |
| 66 | |
| 67 this._manager.removeEventListener(WebInspector.ServiceWorkerManager.Even ts.RegistrationUpdated, this._registrationUpdated, this); | |
|
dgozman
2016/10/14 18:33:34
Use WebInspector.EventTarget.removeEventListeners.
pfeldman
2016/10/14 20:03:22
Done.
| |
| 68 this._manager.removeEventListener(WebInspector.ServiceWorkerManager.Even ts.RegistrationDeleted, this._registrationDeleted, this); | |
| 69 this._manager.removeEventListener(WebInspector.ServiceWorkerManager.Even ts.RegistrationErrorAdded, this._registrationErrorAdded, this); | |
| 70 this._securityOriginManager.removeEventListener(WebInspector.SecurityOri ginManager.Events.SecurityOriginAdded, this._updateSectionVisibility, this); | |
| 71 this._securityOriginManager.removeEventListener(WebInspector.SecurityOri ginManager.Events.SecurityOriginRemoved, this._updateSectionVisibility, this); | |
| 72 | |
| 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 |