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 this.registerRequiredCSS("resources/serviceWorkersView.css"); | |
| 14 this.contentElement.classList.add("service-workers-view"); | |
| 15 | 13 |
| 14 this._reportView = new WebInspector.ReportView(WebInspector.UIString("Servic e Workers")); | |
| 15 this._reportView.show(this.contentElement); | |
| 16 | 16 |
| 17 /** @type {boolean} */ | 17 this._toolbar = this._reportView.createToolbar(); |
| 18 this._showAll = false; | |
| 19 /** @type {!Set.<string>} */ | |
| 20 this._securityOriginHosts = new Set(); | |
| 21 /** @type {!Map.<string, !WebInspector.ServiceWorkerOriginWidget>} */ | |
| 22 this._originHostToOriginWidgetMap = new Map(); | |
| 23 /** @type {!Map.<string, !WebInspector.ServiceWorkerOriginWidget>} */ | |
| 24 this._registrationIdToOriginWidgetMap = new Map(); | |
| 25 | 18 |
| 26 this._toolbar = new WebInspector.Toolbar("", this.contentElement); | 19 /** @type {!Map<!WebInspector.ServiceWorkerRegistration, !WebInspector.Servi ceWorkersView.Section>} */ |
| 27 | 20 this._sections = new Map(); |
| 28 this._root = this.contentElement.createChild("div"); | |
| 29 this._root.classList.add("service-workers-root"); | |
| 30 | 21 |
| 31 WebInspector.targetManager.observeTargets(this); | 22 WebInspector.targetManager.observeTargets(this); |
| 32 } | 23 } |
| 33 | 24 |
| 34 WebInspector.ServiceWorkersView.prototype = { | 25 WebInspector.ServiceWorkersView.prototype = { |
| 35 /** | 26 /** |
| 36 * @override | 27 * @override |
| 37 * @param {!WebInspector.Target} target | 28 * @param {!WebInspector.Target} target |
| 38 */ | 29 */ |
| 39 targetAdded: function(target) | 30 targetAdded: function(target) |
| 40 { | 31 { |
| 41 if (this._target) | 32 if (this._target) |
| 42 return; | 33 return; |
| 43 this._target = target; | 34 this._target = target; |
| 44 this._manager = this._target.serviceWorkerManager; | 35 this._manager = this._target.serviceWorkerManager; |
| 45 | 36 |
| 46 var forceUpdate = new WebInspector.ToolbarCheckbox(WebInspector.UIString ("Update worker on reload"), WebInspector.UIString("Update Service Worker on pag e reload"), this._manager.forceUpdateOnReloadSetting()); | 37 var forceUpdate = new WebInspector.ToolbarCheckbox(WebInspector.UIString ("Force update on reload"), WebInspector.UIString("Force update Service Worker o n page reload"), this._manager.forceUpdateOnReloadSetting()); |
| 47 this._toolbar.appendToolbarItem(forceUpdate); | 38 this._toolbar.appendToolbarItem(forceUpdate); |
| 48 var fallbackToNetwork = new WebInspector.ToolbarCheckbox(WebInspector.UI String("Bypass worker for network"), WebInspector.UIString("Bypass Service Worke r and load resources from the network"), target.networkManager.bypassServiceWork erSetting()); | 39 var fallbackToNetwork = new WebInspector.ToolbarCheckbox(WebInspector.UI String("Bypass worker for network"), WebInspector.UIString("Bypass Service Worke r and load resources from the network"), target.networkManager.bypassServiceWork erSetting()); |
| 49 this._toolbar.appendToolbarItem(fallbackToNetwork); | 40 this._toolbar.appendToolbarItem(fallbackToNetwork); |
| 50 this._toolbar.appendSpacer(); | 41 this._toolbar.appendSpacer(); |
| 51 this._showAllCheckbox = new WebInspector.ToolbarCheckbox(WebInspector.UI String("Show all"), WebInspector.UIString("Show all Service Workers regardless o f the scope")); | 42 this._showAllCheckbox = new WebInspector.ToolbarCheckbox(WebInspector.UI String("Show all"), WebInspector.UIString("Show all Service Workers regardless o f the origin")); |
| 52 this._showAllCheckbox.inputElement.addEventListener("change", this._onSh owAllCheckboxChanged.bind(this), false); | 43 this._showAllCheckbox.inputElement.addEventListener("change", this._upda teSectionVisibility.bind(this), false); |
| 53 this._toolbar.appendToolbarItem(this._showAllCheckbox); | 44 this._toolbar.appendToolbarItem(this._showAllCheckbox); |
| 54 | 45 |
| 55 for (var registration of this._manager.registrations().values()) | 46 for (var registration of this._manager.registrations().values()) |
| 56 this._updateRegistration(registration); | 47 this._updateRegistration(registration); |
| 57 | 48 |
| 58 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationUpdated, this._registrationUpdated, this); | 49 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationUpdated, this._registrationUpdated, this); |
| 59 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationDeleted, this._registrationDeleted, this); | 50 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationDeleted, this._registrationDeleted, this); |
| 60 this._target.resourceTreeModel.addEventListener(WebInspector.ResourceTre eModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 51 this._manager.addEventListener(WebInspector.ServiceWorkerManager.Events. RegistrationErrorAdded, this._registrationErrorAdded, this); |
| 61 this._target.resourceTreeModel.addEventListener(WebInspector.ResourceTre eModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this); | 52 this._target.resourceTreeModel.addEventListener(WebInspector.ResourceTre eModel.EventTypes.SecurityOriginAdded, this._updateSectionVisibility, this); |
| 62 var securityOrigins = this._target.resourceTreeModel.securityOrigins(); | 53 this._target.resourceTreeModel.addEventListener(WebInspector.ResourceTre eModel.EventTypes.SecurityOriginRemoved, this._updateSectionVisibility, this); |
| 63 for (var i = 0; i < securityOrigins.length; ++i) | |
| 64 this._addOrigin(securityOrigins[i]); | |
| 65 }, | 54 }, |
| 66 | 55 |
| 67 /** | 56 /** |
| 68 * @override | 57 * @override |
| 69 * @param {!WebInspector.Target} target | 58 * @param {!WebInspector.Target} target |
| 70 */ | 59 */ |
| 71 targetRemoved: function(target) | 60 targetRemoved: function(target) |
| 72 { | 61 { |
| 73 if (target !== this._target) | 62 if (target !== this._target) |
| 74 return; | 63 return; |
| 75 delete this._target; | 64 delete this._target; |
| 76 }, | 65 }, |
| 77 | 66 |
| 78 /** | 67 _updateSectionVisibility: function() |
| 79 * @param {!Event} event | |
| 80 */ | |
| 81 _onShowAllCheckboxChanged: function(event) | |
| 82 { | 68 { |
| 83 this._showAll = this._showAllCheckbox.checked(); | 69 var securityOrigins = new Set(this._target.resourceTreeModel.securityOri gins()); |
| 84 if (this._showAll) { | 70 for (var section of this._sections.values()) { |
| 85 for (var originWidget of this._originHostToOriginWidgetMap.values()) { | 71 var visible = this._showAllCheckbox.checked() || securityOrigins.has (section._registration.securityOrigin); |
| 86 if (!originWidget.parentWidget()) | 72 section._section.element.classList.toggle("hidden", !visible); |
| 87 originWidget.show(this._root); | |
| 88 } | |
| 89 } else { | |
| 90 for (var originWidget of this._originHostToOriginWidgetMap.values()) { | |
| 91 if (originWidget.parentWidget() && !this._securityOriginHosts.ha s(originWidget._originHost)) | |
| 92 originWidget.detach(); | |
| 93 } | |
| 94 } | 73 } |
| 95 }, | 74 }, |
| 96 | 75 |
| 97 /** | 76 /** |
| 98 * @param {!WebInspector.Event} event | 77 * @param {!WebInspector.Event} event |
| 99 */ | 78 */ |
| 100 _registrationUpdated: function(event) | 79 _registrationUpdated: function(event) |
| 101 { | 80 { |
| 102 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data); | 81 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data); |
| 103 this._updateRegistration(registration); | 82 this._updateRegistration(registration); |
| 104 }, | 83 }, |
| 105 | 84 |
| 106 /** | 85 /** |
| 107 * @param {!WebInspector.ServiceWorkerRegistration} registration | |
| 108 */ | |
| 109 _updateRegistration: function(registration) | |
| 110 { | |
| 111 var parsedURL = registration.scopeURL.asParsedURL(); | |
| 112 if (!parsedURL) | |
| 113 return; | |
| 114 var originHost = parsedURL.securityOrigin(); | |
| 115 var originWidget = this._originHostToOriginWidgetMap.get(originHost); | |
| 116 if (!originWidget) { | |
| 117 originWidget = new WebInspector.ServiceWorkerOriginWidget(this._mana ger, originHost); | |
| 118 if (this._securityOriginHosts.has(originHost) || this._showAll) | |
| 119 originWidget.show(this._root); | |
| 120 this._originHostToOriginWidgetMap.set(originHost, originWidget); | |
| 121 } | |
| 122 this._registrationIdToOriginWidgetMap.set(registration.id, originWidget) ; | |
| 123 originWidget._updateRegistration(registration); | |
| 124 }, | |
| 125 | |
| 126 /** | |
| 127 * @param {!WebInspector.Event} event | 86 * @param {!WebInspector.Event} event |
| 128 */ | 87 */ |
| 129 _registrationDeleted: function(event) | 88 _registrationErrorAdded: function(event) |
| 130 { | 89 { |
| 131 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data); | 90 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data["registration"]); |
| 132 var registrationId = registration.id; | 91 var error = /** @type {!ServiceWorkerAgent.ServiceWorkerErrorMessage} */ (event.data["error"]); |
| 133 var originWidget = this._registrationIdToOriginWidgetMap.get(registratio nId); | 92 var section = this._sections.get(registration); |
| 134 if (!originWidget) | 93 if (!section) |
| 135 return; | 94 return; |
| 136 this._registrationIdToOriginWidgetMap.delete(registrationId); | 95 section._addError(error); |
| 137 originWidget._deleteRegistration(registrationId); | |
| 138 if (originWidget._hasRegistration()) | |
| 139 return; | |
| 140 if (originWidget.parentWidget()) | |
| 141 originWidget.detach(); | |
| 142 this._originHostToOriginWidgetMap.delete(originWidget._originHost); | |
| 143 }, | 96 }, |
| 144 | 97 |
| 145 /** | 98 /** |
| 146 * @param {!WebInspector.Event} event | |
| 147 */ | |
| 148 _securityOriginAdded: function(event) | |
| 149 { | |
| 150 this._addOrigin(/** @type {string} */ (event.data)); | |
| 151 }, | |
| 152 | |
| 153 /** | |
| 154 * @param {string} securityOrigin | |
| 155 */ | |
| 156 _addOrigin: function(securityOrigin) | |
| 157 { | |
| 158 var parsedURL = securityOrigin.asParsedURL(); | |
| 159 if (!parsedURL) | |
| 160 return; | |
| 161 var originHost = parsedURL.securityOrigin(); | |
| 162 if (this._securityOriginHosts.has(originHost)) | |
| 163 return; | |
| 164 this._securityOriginHosts.add(originHost); | |
| 165 var originWidget = this._originHostToOriginWidgetMap.get(originHost); | |
| 166 if (!originWidget) | |
| 167 return; | |
| 168 originWidget.show(this._root); | |
| 169 }, | |
| 170 | |
| 171 /** | |
| 172 * @param {!WebInspector.Event} event | |
| 173 */ | |
| 174 _securityOriginRemoved: function(event) | |
| 175 { | |
| 176 var securityOrigin = /** @type {string} */ (event.data); | |
| 177 var parsedURL = securityOrigin.asParsedURL(); | |
| 178 if (!parsedURL) | |
| 179 return; | |
| 180 var originHost = parsedURL.securityOrigin(); | |
| 181 if (!this._securityOriginHosts.has(originHost)) | |
| 182 return; | |
| 183 this._securityOriginHosts.delete(originHost); | |
| 184 if (this._showAll) | |
| 185 return; | |
| 186 var originWidget = this._originHostToOriginWidgetMap.get(originHost); | |
| 187 if (!originWidget) | |
| 188 return; | |
| 189 originWidget.detach(); | |
| 190 }, | |
| 191 | |
| 192 __proto__: WebInspector.VBox.prototype | |
| 193 } | |
| 194 | |
| 195 /** | |
| 196 * @constructor | |
| 197 * @extends {WebInspector.VBox} | |
| 198 * @param {!WebInspector.ServiceWorkerManager} manager | |
| 199 * @param {string} originHost | |
| 200 */ | |
| 201 WebInspector.ServiceWorkerOriginWidget = function(manager, originHost) | |
| 202 { | |
| 203 WebInspector.VBox.call(this); | |
| 204 this._manager = manager; | |
| 205 /** @type {!Map.<string, !WebInspector.SWRegistrationWidget>} */ | |
| 206 this._registrationWidgets = new Map(); | |
| 207 this._originHost = originHost; | |
| 208 this.element.classList.add("service-workers-origin"); | |
| 209 this._titleElement = this.element.createChild("span", "service-workers-origi n-title"); | |
| 210 } | |
| 211 | |
| 212 WebInspector.ServiceWorkerOriginWidget.prototype = { | |
| 213 /** | |
| 214 * @return {boolean} | |
| 215 */ | |
| 216 _hasRegistration: function() | |
| 217 { | |
| 218 return this._registrationWidgets.size != 0; | |
| 219 }, | |
| 220 | |
| 221 /** | |
| 222 * @param {!WebInspector.ServiceWorkerRegistration} registration | 99 * @param {!WebInspector.ServiceWorkerRegistration} registration |
| 223 */ | 100 */ |
| 224 _updateRegistration: function(registration) | 101 _updateRegistration: function(registration) |
| 225 { | 102 { |
| 226 this._titleElement.setTextAndTitle(WebInspector.UIString(registration.is Deleted ? "%s%s - deleted" : "%s%s", this._originHost, registration.scopeURL.asP arsedURL().path)); | 103 var section = this._sections.get(registration); |
| 227 | 104 if (!section) { |
| 228 var registrationWidget = this._registrationWidgets.get(registration.id); | 105 section = new WebInspector.ServiceWorkersView.Section(this._manager, this._reportView.appendSection(""), registration); |
| 229 if (registrationWidget) { | 106 this._sections.set(registration, section); |
| 230 registrationWidget._updateRegistration(registration); | |
| 231 return; | |
| 232 } | 107 } |
| 233 registrationWidget = new WebInspector.SWRegistrationWidget(this._manager , this, registration); | 108 this._updateSectionVisibility(); |
| 234 this._registrationWidgets.set(registration.id, registrationWidget); | 109 section._scheduleUpdate(); |
| 235 registrationWidget.show(this.element); | |
| 236 }, | 110 }, |
| 237 | 111 |
| 238 /** | 112 /** |
| 239 * @param {string} registrationId | 113 * @param {!WebInspector.Event} event |
| 240 */ | 114 */ |
| 241 _deleteRegistration: function(registrationId) | 115 _registrationDeleted: function(event) |
| 242 { | 116 { |
| 243 var registrationWidget = this._registrationWidgets.get(registrationId); | 117 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data); |
| 244 if (!registrationWidget) | 118 var section = this._sections.get(registration); |
| 245 return; | 119 if (section) |
| 246 this._registrationWidgets.delete(registrationId); | 120 section._section.remove(); |
| 247 registrationWidget.detach(); | 121 this._sections.delete(registration); |
| 248 }, | 122 }, |
| 249 | 123 |
| 250 __proto__: WebInspector.VBox.prototype | 124 __proto__: WebInspector.VBox.prototype |
| 251 } | 125 } |
| 252 | 126 |
| 253 /** | 127 /** |
| 254 * @constructor | 128 * @constructor |
| 255 * @extends {WebInspector.VBox} | |
| 256 * @param {!WebInspector.ServiceWorkerManager} manager | 129 * @param {!WebInspector.ServiceWorkerManager} manager |
| 257 * @param {!WebInspector.ServiceWorkerOriginWidget} originWidget | 130 * @param {!WebInspector.ReportView.Section} section |
| 258 * @param {!WebInspector.ServiceWorkerRegistration} registration | 131 * @param {!WebInspector.ServiceWorkerRegistration} registration |
| 259 */ | 132 */ |
| 260 WebInspector.SWRegistrationWidget = function(manager, originWidget, registration ) | 133 WebInspector.ServiceWorkersView.Section = function(manager, section, registratio n) |
| 261 { | 134 { |
| 262 WebInspector.VBox.call(this); | |
| 263 this._manager = manager; | 135 this._manager = manager; |
| 264 this._originWidget = originWidget; | 136 this._section = section; |
| 265 this._registration = registration; | 137 this._registration = registration; |
| 266 this.element.classList.add("service-workers-registration"); | |
| 267 | 138 |
| 268 var toolbar = new WebInspector.Toolbar("", this.element); | 139 this._toolbar = section.createToolbar(); |
| 269 this._updateButton = new WebInspector.ToolbarButton(WebInspector.UIString("U pdate"), "refresh-toolbar-item", WebInspector.UIString("Update")); | 140 this._toolbar.renderAsLinks(); |
| 141 this._updateButton = new WebInspector.ToolbarButton(WebInspector.UIString("U pdate"), undefined, WebInspector.UIString("Update")); | |
| 270 this._updateButton.addEventListener("click", this._updateButtonClicked.bind( this)); | 142 this._updateButton.addEventListener("click", this._updateButtonClicked.bind( this)); |
| 271 toolbar.appendToolbarItem(this._updateButton); | 143 this._toolbar.appendToolbarItem(this._updateButton); |
| 272 | 144 |
| 273 toolbar.appendSeparator(); | 145 // Preserve the order. |
|
caseq
2016/05/05 04:04:06
move the entire section after toolbar construction
pfeldman
2016/05/05 04:28:31
Done.
| |
| 274 this._pushButton = new WebInspector.ToolbarButton(WebInspector.UIString("Emu late push event"), "notification-toolbar-item", WebInspector.UIString("Push")); | 146 this._section.appendField(WebInspector.UIString("Source")); |
| 147 this._section.appendField(WebInspector.UIString("Status")); | |
| 148 this._section.appendField(WebInspector.UIString("Clients")); | |
| 149 this._section.appendField(WebInspector.UIString("Errors")); | |
| 150 this._errorsList = this._wrapWidget(this._section.appendRow()); | |
| 151 this._errorsList.classList.add("service-worker-error-stack", "monospace", "h idden"); | |
| 152 | |
| 153 this._pushButton = new WebInspector.ToolbarButton(WebInspector.UIString("Emu late push event"), undefined, WebInspector.UIString("Push")); | |
| 275 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this )); | 154 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this )); |
| 276 toolbar.appendToolbarItem(this._pushButton); | 155 this._toolbar.appendToolbarItem(this._pushButton); |
| 277 toolbar.appendSpacer(); | 156 this._deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString("U nregister service worker"), undefined, WebInspector.UIString("Unregister")); |
| 278 this._deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString("U nregister service worker"), "garbage-collect-toolbar-item", WebInspector.UIStrin g("Unregister")); | 157 this._deleteButton.addEventListener("click", this._unregisterButtonClicked.b ind(this)); |
| 279 this._deleteButton.addEventListener("click", this._deleteButtonClicked.bind( this)); | 158 this._toolbar.appendToolbarItem(this._deleteButton); |
| 280 toolbar.appendToolbarItem(this._deleteButton); | |
| 281 | 159 |
| 282 this._tabbedPane = new WebInspector.TabbedPane(); | 160 this._linkifier = new WebInspector.Linkifier(); |
| 283 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele cted, this._tabSelected, this); | 161 /** @type {!Map<string, !WebInspector.TargetInfo>} */ |
| 284 var modes = WebInspector.ServiceWorkerVersion.Modes; | 162 this._clientInfoCache = new Map(); |
| 285 this._tabbedPane.appendTab(modes.Installing, WebInspector.UIString("Installi ng"), new WebInspector.VBox()); | 163 for (var error of registration.errors) |
| 286 this._tabbedPane.appendTab(modes.Waiting, WebInspector.UIString("Waiting"), new WebInspector.VBox()); | 164 this._addError(error); |
| 287 this._tabbedPane.appendTab(modes.Active, WebInspector.UIString("Active"), ne w WebInspector.VBox()); | 165 this._throttler = new WebInspector.Throttler(500); |
|
caseq
2016/05/05 04:04:06
Wouldn't this defeat throttling considering we may
pfeldman
2016/05/05 04:28:31
Nope, this throttling is against the rapid changes
| |
| 288 this._tabbedPane.appendTab(modes.Redundant, WebInspector.UIString("Redundant "), new WebInspector.VBox()); | |
| 289 this._tabbedPane.show(this.element); | |
| 290 | |
| 291 /** @type {!Map<string, !WebInspector.SWVersionWidget>} */ | |
| 292 this._versionWidgets = new Map(); | |
| 293 | |
| 294 this._updateRegistration(registration); | |
| 295 } | 166 } |
| 296 | 167 |
| 297 WebInspector.SWRegistrationWidget.prototype = { | 168 WebInspector.ServiceWorkersView.Section.prototype = { |
| 298 /** | 169 _scheduleUpdate: function() |
| 299 * @param {!WebInspector.Event} event | |
| 300 */ | |
| 301 _tabSelected: function(event) | |
| 302 { | 170 { |
| 303 if (event.data["isUserGesture"]) | 171 if (WebInspector.ServiceWorkersView._noThrottle) { |
| 304 this._lastManuallySelectedTab = event.data["tabId"]; | 172 this._update(); |
| 173 return; | |
| 174 } | |
| 175 this._throttler.schedule(this._update.bind(this)); | |
| 305 }, | 176 }, |
| 306 | 177 |
| 307 /** | 178 /** |
| 308 * @param {!WebInspector.ServiceWorkerRegistration} registration | 179 * @return {!Promise} |
| 309 */ | 180 */ |
| 310 _updateRegistration: function(registration) | 181 _update: function() |
| 311 { | 182 { |
| 312 this._registration = registration; | 183 var fingerprint = this._registration.fingerprint(); |
| 313 this._updateButton.setEnabled(!registration.isDeleted); | 184 if (fingerprint === this._fingerprint) |
| 314 this._deleteButton.setEnabled(!registration.isDeleted); | 185 return Promise.resolve(); |
| 186 this._fingerprint = fingerprint; | |
| 315 | 187 |
| 316 /** @type {!Map<string, !WebInspector.SWVersionWidget>} */ | 188 this._toolbar.setEnabled(!this._registration.isDeleted); |
| 317 var versionWidgets = new Map(); | |
| 318 | 189 |
| 319 // Remove all the redundant workers that are older than the | 190 var versions = this._registration.versionsByMode(); |
| 320 // active version. | 191 var title = this._registration.isDeleted ? WebInspector.UIString("%s - d eleted", this._registration.scopeURL) : this._registration.scopeURL; |
| 321 var versions = registration.versions.valuesArray(); | 192 this._section.setTitle(title); |
| 322 var activeVersion = versions.find(version => version.mode() === WebInspe ctor.ServiceWorkerVersion.Modes.Active); | 193 |
| 323 if (activeVersion) { | 194 var active = versions.get(WebInspector.ServiceWorkerVersion.Modes.Active ); |
| 324 versions = versions.filter(version => { | 195 var waiting = versions.get(WebInspector.ServiceWorkerVersion.Modes.Waiti ng); |
| 325 if (version.mode() == WebInspector.ServiceWorkerVersion.Modes.Re dundant) | 196 var installing = versions.get(WebInspector.ServiceWorkerVersion.Modes.In stalling); |
| 326 return version.scriptLastModified > activeVersion.scriptLast Modified; | 197 |
| 327 return true; | 198 var statusValue = this._wrapWidget(this._section.appendField(WebInspecto r.UIString("Status"))); |
| 328 }); | 199 statusValue.removeChildren(); |
| 200 var versionsStack = statusValue.createChild("div", "service-worker-versi on-stack"); | |
| 201 versionsStack.createChild("div", "service-worker-version-stack-bar"); | |
| 202 | |
| 203 if (active) { | |
| 204 var scriptElement = this._section.appendField(WebInspector.UIString( "Source")); | |
| 205 scriptElement.removeChildren(); | |
| 206 var components = WebInspector.ParsedURL.splitURLIntoPathComponents(a ctive.scriptURL); | |
| 207 scriptElement.appendChild(WebInspector.linkifyURLAsNode(active.scrip tURL, components.peekLast())); | |
| 208 scriptElement.createChild("div", "report-field-value-subtitle").text Content = WebInspector.UIString("Last modified %s", new Date(active.scriptLastMo dified * 1000).toLocaleString()); | |
| 209 | |
| 210 var activeEntry = versionsStack.createChild("div", "service-worker-v ersion"); | |
| 211 activeEntry.createChild("div", "service-worker-active-circle"); | |
| 212 activeEntry.createChild("span").textContent = WebInspector.UIString( "#%s active and is %s", active.id, active.runningStatus); | |
| 213 | |
| 214 if (active.isRunning() || active.isStarting()) { | |
| 215 var stopButton = createLink(activeEntry, WebInspector.UIString(" stop"), this._stopButtonClicked.bind(this, active.id)); | |
| 216 if (!this._manager.targetForVersionId(active.id)) { | |
| 217 var inspectButton = createLink(activeEntry, WebInspector.UIS tring("inspect"), this._inspectButtonClicked.bind(this, active.id)); | |
| 218 } | |
| 219 } else if (active.isStartable()) { | |
| 220 var startButton = createLink(activeEntry, WebInspector.UIString( "start"), this._startButtonClicked.bind(this)); | |
| 221 } | |
| 222 | |
| 223 var clientsList = this._wrapWidget(this._section.appendField(WebInsp ector.UIString("Clients"))); | |
| 224 clientsList.removeChildren(); | |
| 225 this._section.setFieldVisible(WebInspector.UIString("Clients"), acti ve.controlledClients.length); | |
| 226 for (var client of active.controlledClients) { | |
| 227 var clientLabelText = clientsList.createChild("div", "service-wo rker-client"); | |
| 228 if (this._clientInfoCache.has(client)) | |
| 229 this._updateClientInfo(clientLabelText, /** @type {!WebInspe ctor.TargetInfo} */(this._clientInfoCache.get(client))); | |
| 230 this._manager.getTargetInfo(client, this._onClientInfo.bind(this , clientLabelText)); | |
| 231 } | |
| 329 } | 232 } |
| 330 | 233 |
| 331 var firstMode; | 234 if (waiting) { |
| 332 var modesWithVersions = new Set(); | 235 var waitingEntry = versionsStack.createChild("div", "service-worker- version"); |
| 333 for (var version of versions) { | 236 waitingEntry.createChild("div", "service-worker-waiting-circle"); |
| 334 if (version.isStoppedAndRedundant() && !version.errorMessages.length ) | 237 waitingEntry.createChild("span").textContent = WebInspector.UIString ("#%s waiting to activate", waiting.id); |
| 335 continue; | 238 var skipButton = createLink(waitingEntry, WebInspector.UIString("ski pWaiting"), this._skipButtonClicked.bind(this)); |
| 336 var mode = version.mode(); | 239 waitingEntry.createChild("div", "service-worker-subtitle").textConte nt = new Date(waiting.scriptLastModified * 1000).toLocaleString(); |
| 337 if (!firstMode) | |
| 338 firstMode = mode; | |
| 339 modesWithVersions.add(mode); | |
| 340 var view = this._tabbedPane.tabView(mode); | |
| 341 var versionWidget = this._versionWidgets.get(version.id); | |
| 342 if (versionWidget) | |
| 343 versionWidget._updateVersion(version); | |
| 344 else | |
| 345 versionWidget = new WebInspector.SWVersionWidget(this._manager, this._registration.scopeURL, version); | |
| 346 versionWidget.show(view.element, view.element.firstElementChild); | |
| 347 versionWidgets.set(version.id, versionWidget); | |
| 348 } | 240 } |
| 349 for (var id of this._versionWidgets.keys()) { | 241 if (installing) { |
| 350 if (!versionWidgets.has(id)) | 242 var installingEntry = versionsStack.createChild("div", "service-work er-version"); |
| 351 this._versionWidgets.get(id).detach(); | 243 installingEntry.createChild("div", "service-worker-installing-circle "); |
| 244 installingEntry.createChild("span").textContent = WebInspector.UIStr ing("#%s installing", installing.id); | |
| 245 installingEntry.createChild("div", "service-worker-subtitle").textCo ntent = new Date(installing.scriptLastModified * 1000).toLocaleString(); | |
| 352 } | 246 } |
| 353 this._versionWidgets = versionWidgets; | |
| 354 | 247 |
| 355 for (var id of this._tabbedPane.tabIds()) | 248 this._section.setFieldVisible(WebInspector.UIString("Errors"), !!this._r egistration.errors.length); |
| 356 this._tabbedPane.setTabEnabled(id, modesWithVersions.has(id)); | 249 var errorsValue = this._wrapWidget(this._section.appendField(WebInspecto r.UIString("Errors"))); |
| 250 var errorsLabel = createLabel(String(this._registration.errors.length), "error-icon"); | |
| 251 errorsLabel.classList.add("service-worker-errors-label"); | |
| 252 errorsValue.appendChild(errorsLabel); | |
| 253 this._moreButton = createLink(errorsValue, this._errorsList.classList.co ntains("hidden") ? WebInspector.UIString("details") : WebInspector.UIString("hid e"), this._moreErrorsButtonClicked.bind(this)); | |
| 254 var clearButton = createLink(errorsValue, WebInspector.UIString("clear") , this._clearErrorsButtonClicked.bind(this)); | |
| 357 | 255 |
| 358 this._pushButton.setEnabled(modesWithVersions.has(WebInspector.ServiceWo rkerVersion.Modes.Active) && !this._registration.isDeleted); | 256 /** |
| 359 | 257 * @param {!Element} parent |
| 360 if (modesWithVersions.has(this._lastManuallySelectedTab)) { | 258 * @param {string} title |
| 361 this._tabbedPane.selectTab(this._lastManuallySelectedTab); | 259 * @param {function()} listener |
| 362 return; | 260 */ |
| 261 function createLink(parent, title, listener) | |
| 262 { | |
| 263 var span = parent.createChild("span", "link"); | |
| 264 span.textContent = title; | |
| 265 span.addEventListener("click", listener, false); | |
| 363 } | 266 } |
| 364 if (activeVersion) { | 267 return Promise.resolve(); |
| 365 this._tabbedPane.selectTab(WebInspector.ServiceWorkerVersion.Modes.A ctive); | |
| 366 return; | |
| 367 } | |
| 368 if (firstMode) | |
| 369 this._tabbedPane.selectTab(firstMode); | |
| 370 }, | 268 }, |
| 371 | 269 |
| 372 /** | 270 /** |
| 373 * @param {!WebInspector.Event} event | 271 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} error |
| 374 */ | 272 */ |
| 375 _deleteButtonClicked: function(event) | 273 _addError: function(error) |
| 274 { | |
| 275 var target = this._manager.targetForVersionId(error.versionId); | |
| 276 var message = this._errorsList.createChild("div"); | |
| 277 if (this._errorsList.childElementCount > 100) | |
| 278 this._errorsList.firstElementChild.remove(); | |
| 279 message.appendChild(this._linkifier.linkifyScriptLocation(target, null, error.sourceURL, error.lineNumber)); | |
| 280 message.appendChild(createLabel("#" + error.versionId + ": " + error.err orMessage, "error-icon")); | |
| 281 }, | |
| 282 | |
| 283 _unregisterButtonClicked: function() | |
| 376 { | 284 { |
| 377 this._manager.deleteRegistration(this._registration.id); | 285 this._manager.deleteRegistration(this._registration.id); |
| 378 }, | 286 }, |
| 379 | 287 |
| 380 /** | 288 _updateButtonClicked: function() |
| 381 * @param {!WebInspector.Event} event | |
| 382 */ | |
| 383 _updateButtonClicked: function(event) | |
| 384 { | 289 { |
| 385 this._manager.updateRegistration(this._registration.id); | 290 this._manager.updateRegistration(this._registration.id); |
| 386 }, | 291 }, |
| 387 | 292 |
| 388 /** | 293 _pushButtonClicked: function() |
| 389 * @param {!WebInspector.Event} event | |
| 390 */ | |
| 391 _pushButtonClicked: function(event) | |
| 392 { | 294 { |
| 393 var data = "Test push message from DevTools." | 295 var data = "Test push message from DevTools." |
| 394 this._manager.deliverPushMessage(this._registration.id, data); | 296 this._manager.deliverPushMessage(this._registration.id, data); |
| 395 }, | 297 }, |
| 396 | 298 |
| 397 __proto__: WebInspector.VBox.prototype | |
| 398 } | |
| 399 | |
| 400 /** | |
| 401 * @constructor | |
| 402 * @extends {WebInspector.VBox} | |
| 403 * @param {!WebInspector.ServiceWorkerManager} manager | |
| 404 * @param {string} scopeURL | |
| 405 * @param {!WebInspector.ServiceWorkerVersion} version | |
| 406 */ | |
| 407 WebInspector.SWVersionWidget = function(manager, scopeURL, version) | |
| 408 { | |
| 409 WebInspector.VBox.call(this); | |
| 410 this._manager = manager; | |
| 411 this._scopeURL = scopeURL; | |
| 412 this._version = version; | |
| 413 this.element.classList.add("service-workers-version", "flex-none"); | |
| 414 | |
| 415 /** | |
| 416 * @type {!Object.<string, !WebInspector.TargetInfo>} | |
| 417 */ | |
| 418 this._clientInfoCache = {}; | |
| 419 this._createElements(); | |
| 420 this._updateVersion(version); | |
| 421 } | |
| 422 | |
| 423 WebInspector.SWVersionWidget.prototype = { | |
| 424 _createElements: function() | |
| 425 { | |
| 426 var panel = createElementWithClass("div", "service-workers-versions-pane l"); | |
| 427 var leftPanel = panel.createChild("div", "service-workers-versions-panel -top"); | |
| 428 var rightPanel = panel.createChild("div", "service-workers-versions-pane l-bottom"); | |
| 429 this._scriptCell = this._addTableRow(leftPanel, WebInspector.UIString("U RL")); | |
| 430 this._workerCell = this._addTableRow(leftPanel, WebInspector.UIString("S tate")); | |
| 431 this._updatedCell = this._addTableRow(leftPanel, WebInspector.UIString(" Updated")); | |
| 432 this._updatedCell.classList.add("service-worker-script-response-time"); | |
| 433 this._scriptLastModifiedCell = this._addTableRow(leftPanel, WebInspector .UIString("Last-Modified")); | |
| 434 this._scriptLastModifiedCell.classList.add("service-worker-script-last-m odified"); | |
| 435 rightPanel.createChild("div", "service-workers-versions-table-title").cr eateTextChild(WebInspector.UIString("Recent messages")); | |
| 436 this._messagesPanel = rightPanel.createChild("div", "service-workers-ver sions-table-messages-content"); | |
| 437 this._clientsTitle = rightPanel.createChild("div", "service-workers-vers ions-table-title"); | |
| 438 this._clientsTitle.createTextChild(WebInspector.UIString("Controlled cli ents")); | |
| 439 this._clientsPanel = rightPanel.createChild("div", "service-workers-vers ions-table-clients-content"); | |
| 440 this.element.appendChild(panel); | |
| 441 }, | |
| 442 | |
| 443 /** | |
| 444 * @param {!WebInspector.ServiceWorkerVersion} version | |
| 445 */ | |
| 446 _updateVersion: function(version) | |
| 447 { | |
| 448 this._workerCell.removeChildren(); | |
| 449 if (version.isRunning() || version.isStarting() || version.isStartable() ) { | |
| 450 var runningStatusCell = this._workerCell.createChild("div", "service -workers-versions-table-worker-running-status-cell"); | |
| 451 var runningStatusLeftCell = runningStatusCell.createChild("div"); | |
| 452 var runningStatusRightCell = runningStatusCell.createChild("div"); | |
| 453 if (version.isRunning() || version.isStarting()) { | |
| 454 var toolbar = new WebInspector.Toolbar("", runningStatusRightCel l); | |
| 455 var stopButton = new WebInspector.ToolbarButton(WebInspector.UIS tring("Stop"), "stop-toolbar-item"); | |
| 456 stopButton.addEventListener("click", this._stopButtonClicked.bin d(this, version.id)); | |
| 457 toolbar.appendToolbarItem(stopButton); | |
| 458 } else if (version.isStartable()) { | |
| 459 var toolbar = new WebInspector.Toolbar("", runningStatusRightCel l); | |
| 460 var startButton = new WebInspector.ToolbarButton(WebInspector.UI String("Start"), "play-toolbar-item"); | |
| 461 startButton.addEventListener("click", this._startButtonClicked.b ind(this)); | |
| 462 toolbar.appendToolbarItem(startButton); | |
| 463 } | |
| 464 runningStatusLeftCell.setTextAndTitle(version.runningStatus); | |
| 465 if ((version.isRunning() || version.isStarting()) && !this._manager. hasWorkerWithVersionId(version.id)) { | |
| 466 var inspectButton = runningStatusLeftCell.createChild("span", "s ervice-workers-versions-table-running-status-inspect"); | |
| 467 inspectButton.setTextAndTitle(WebInspector.UIString("inspect")); | |
| 468 inspectButton.addEventListener("click", this._inspectButtonClick ed.bind(this, version.id), false); | |
| 469 } | |
| 470 } else { | |
| 471 this._workerCell.setTextAndTitle(version.runningStatus); | |
| 472 } | |
| 473 | |
| 474 this._scriptCell.setTextAndTitle(version.scriptURL.asParsedURL().path); | |
| 475 this._updatedCell.setTextAndTitle(version.scriptResponseTime ? (new Date (version.scriptResponseTime * 1000)).toConsoleTime() : ""); | |
| 476 this._scriptLastModifiedCell.setTextAndTitle(version.scriptLastModified ? (new Date(version.scriptLastModified * 1000)).toConsoleTime() : ""); | |
| 477 | |
| 478 this._messagesPanel.removeChildren(); | |
| 479 if (version.scriptLastModified) { | |
| 480 var scriptLastModifiedLabel = this._messagesPanel.createChild("label ", " service-workers-info service-worker-script-last-modified", "dt-icon-label") ; | |
| 481 scriptLastModifiedLabel.type = "info-icon"; | |
| 482 scriptLastModifiedLabel.createTextChild(WebInspector.UIString("Last- Modified: %s", (new Date(version.scriptLastModified * 1000)).toConsoleTime())); | |
| 483 } | |
| 484 if (version.scriptResponseTime) { | |
| 485 var scriptResponseTimeDiv = this._messagesPanel.createChild("label", " service-workers-info service-worker-script-response-time", "dt-icon-label"); | |
| 486 scriptResponseTimeDiv.type = "info-icon"; | |
| 487 scriptResponseTimeDiv.createTextChild(WebInspector.UIString("Server response time: %s", (new Date(version.scriptResponseTime * 1000)).toConsoleTime( ))); | |
| 488 } | |
| 489 | |
| 490 var errorMessages = version.errorMessages; | |
| 491 for (var index = 0; index < errorMessages.length; ++index) { | |
| 492 var errorDiv = this._messagesPanel.createChild("div", "service-worke rs-error"); | |
| 493 errorDiv.createChild("label", "", "dt-icon-label").type = "error-ico n"; | |
| 494 errorDiv.createChild("div", "service-workers-error-message").createT extChild(errorMessages[index].errorMessage); | |
| 495 var script_path = errorMessages[index].sourceURL; | |
| 496 var script_url; | |
| 497 if (script_url = script_path.asParsedURL()) | |
| 498 script_path = script_url.displayName; | |
| 499 if (script_path.length && errorMessages[index].lineNumber != -1) | |
| 500 script_path = String.sprintf("(%s:%d)", script_path, errorMessag es[index].lineNumber); | |
| 501 errorDiv.createChild("div", "service-workers-error-line").createText Child(script_path); | |
| 502 } | |
| 503 | |
| 504 this._clientsTitle.classList.toggle("hidden", version.controlledClients. length == 0); | |
| 505 | |
| 506 this._clientsPanel.removeChildren(); | |
| 507 for (var i = 0; i < version.controlledClients.length; ++i) { | |
| 508 var client = version.controlledClients[i]; | |
| 509 var clientLabelText = this._clientsPanel.createChild("div", "service -worker-client"); | |
| 510 if (this._clientInfoCache[client]) { | |
| 511 this._updateClientInfo(clientLabelText, this._clientInfoCache[cl ient]); | |
| 512 } | |
| 513 this._manager.getTargetInfo(client, this._onClientInfo.bind(this, cl ientLabelText)); | |
| 514 } | |
| 515 }, | |
| 516 | |
| 517 /** | |
| 518 * @param {!Element} tableElement | |
| 519 * @param {string} title | |
| 520 * @return {!Element} | |
| 521 */ | |
| 522 _addTableRow: function(tableElement, title) | |
| 523 { | |
| 524 var rowElement = tableElement.createChild("div", "service-workers-versio ns-table-row"); | |
| 525 rowElement.createChild("div", "service-workers-versions-table-row-title" ).setTextAndTitle(title); | |
| 526 return rowElement.createChild("div", "service-workers-versions-table-row -content"); | |
| 527 }, | |
| 528 | |
| 529 /** | 299 /** |
| 530 * @param {!Element} element | 300 * @param {!Element} element |
| 531 * @param {?WebInspector.TargetInfo} targetInfo | 301 * @param {?WebInspector.TargetInfo} targetInfo |
| 532 */ | 302 */ |
| 533 _onClientInfo: function(element, targetInfo) | 303 _onClientInfo: function(element, targetInfo) |
| 534 { | 304 { |
| 535 if (!targetInfo) | 305 if (!targetInfo) |
| 536 return; | 306 return; |
| 537 this._clientInfoCache[targetInfo.id] = targetInfo; | 307 this._clientInfoCache.set(targetInfo.id, targetInfo); |
| 538 this._updateClientInfo(element, targetInfo); | 308 this._updateClientInfo(element, targetInfo); |
| 539 }, | 309 }, |
| 540 | 310 |
| 541 /** | 311 /** |
| 542 * @param {!Element} element | 312 * @param {!Element} element |
| 543 * @param {!WebInspector.TargetInfo} targetInfo | 313 * @param {!WebInspector.TargetInfo} targetInfo |
| 544 */ | 314 */ |
| 545 _updateClientInfo: function(element, targetInfo) | 315 _updateClientInfo: function(element, targetInfo) |
| 546 { | 316 { |
| 547 if (!(targetInfo.isWebContents() || targetInfo.isFrame())) { | 317 if (!(targetInfo.isWebContents() || targetInfo.isFrame())) { |
| 548 element.createTextChild(WebInspector.UIString("Worker: %s", targetIn fo.url)); | 318 element.createTextChild(WebInspector.UIString("Worker: %s", targetIn fo.url)); |
| 549 return; | 319 return; |
| 550 } | 320 } |
| 551 element.removeChildren(); | 321 element.removeChildren(); |
| 552 element.createTextChild(WebInspector.UIString("Tab: %s", targetInfo.url) ); | 322 element.createTextChild(targetInfo.url); |
| 553 var focusLabel = element.createChild("label", "service-worker-client-foc us"); | 323 var focusLabel = element.createChild("label", "link"); |
| 554 focusLabel.createTextChild("focus"); | 324 focusLabel.createTextChild("focus"); |
| 555 focusLabel.addEventListener("click", this._activateTarget.bind(this, tar getInfo.id), true); | 325 focusLabel.addEventListener("click", this._activateTarget.bind(this, tar getInfo.id), true); |
| 556 }, | 326 }, |
| 557 | 327 |
| 558 /** | 328 /** |
| 559 * @param {string} targetId | 329 * @param {string} targetId |
| 560 */ | 330 */ |
| 561 _activateTarget: function(targetId) | 331 _activateTarget: function(targetId) |
| 562 { | 332 { |
| 563 this._manager.activateTarget(targetId); | 333 this._manager.activateTarget(targetId); |
| 564 }, | 334 }, |
| 565 | 335 |
| 566 /** | 336 _startButtonClicked: function() |
| 567 * @param {!WebInspector.Event} event | |
| 568 */ | |
| 569 _startButtonClicked: function(event) | |
| 570 { | 337 { |
| 571 this._manager.startWorker(this._scopeURL); | 338 this._manager.startWorker(this._registration.scopeURL); |
| 339 }, | |
| 340 | |
| 341 _skipButtonClicked: function() | |
| 342 { | |
| 343 this._manager.skipWaiting(this._registration.scopeURL); | |
| 572 }, | 344 }, |
| 573 | 345 |
| 574 /** | 346 /** |
| 575 * @param {string} versionId | 347 * @param {string} versionId |
| 576 * @param {!WebInspector.Event} event | |
| 577 */ | 348 */ |
| 578 _stopButtonClicked: function(versionId, event) | 349 _stopButtonClicked: function(versionId) |
| 579 { | 350 { |
| 580 this._manager.stopWorker(versionId); | 351 this._manager.stopWorker(versionId); |
| 581 }, | 352 }, |
| 582 | 353 |
| 354 _moreErrorsButtonClicked: function() | |
| 355 { | |
| 356 var newVisible = this._errorsList.classList.contains("hidden"); | |
| 357 this._moreButton.textContent = newVisible ? WebInspector.UIString("hide" ) : WebInspector.UIString("details"); | |
| 358 this._errorsList.classList.toggle("hidden", !newVisible); | |
| 359 }, | |
| 360 | |
| 361 _clearErrorsButtonClicked: function() | |
| 362 { | |
| 363 this._errorsList.removeChildren(); | |
| 364 this._registration.clearErrors(); | |
| 365 this._scheduleUpdate(); | |
| 366 if (!this._errorsList.classList.contains("hidden")) | |
| 367 this._moreErrorsButtonClicked(); | |
| 368 }, | |
| 369 | |
| 583 /** | 370 /** |
| 584 * @param {string} versionId | 371 * @param {string} versionId |
| 585 * @param {!Event} event | |
| 586 */ | 372 */ |
| 587 _inspectButtonClicked: function(versionId, event) | 373 _inspectButtonClicked: function(versionId) |
| 588 { | 374 { |
| 589 this._manager.inspectWorker(versionId); | 375 this._manager.inspectWorker(versionId); |
| 590 }, | 376 }, |
| 591 | 377 |
| 592 __proto__: WebInspector.VBox.prototype | 378 /** |
| 379 * @param {!Element} container | |
| 380 * @return {!Element} | |
| 381 */ | |
| 382 _wrapWidget: function(container) | |
| 383 { | |
| 384 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container); | |
| 385 WebInspector.appendStyle(shadowRoot, "resources/serviceWorkersView.css") ; | |
| 386 var contentElement = createElement("div"); | |
| 387 shadowRoot.appendChild(contentElement); | |
| 388 return contentElement; | |
| 389 }, | |
| 390 | |
| 391 _dispose: function() | |
| 392 { | |
| 393 this._linkifier.dispose(); | |
| 394 if (this._pendingUpdate) | |
| 395 clearTimeout(this._pendingUpdate); | |
| 396 } | |
| 593 } | 397 } |
| OLD | NEW |