| 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); |
| 144 this._pushButton = new WebInspector.ToolbarButton(WebInspector.UIString("Emu
late push event"), undefined, WebInspector.UIString("Push")); |
| 145 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this
)); |
| 146 this._toolbar.appendToolbarItem(this._pushButton); |
| 147 this._deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString("U
nregister service worker"), undefined, WebInspector.UIString("Unregister")); |
| 148 this._deleteButton.addEventListener("click", this._unregisterButtonClicked.b
ind(this)); |
| 149 this._toolbar.appendToolbarItem(this._deleteButton); |
| 272 | 150 |
| 273 toolbar.appendSeparator(); | 151 // Preserve the order. |
| 274 this._pushButton = new WebInspector.ToolbarButton(WebInspector.UIString("Emu
late push event"), "notification-toolbar-item", WebInspector.UIString("Push")); | 152 this._section.appendField(WebInspector.UIString("Source")); |
| 275 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this
)); | 153 this._section.appendField(WebInspector.UIString("Status")); |
| 276 toolbar.appendToolbarItem(this._pushButton); | 154 this._section.appendField(WebInspector.UIString("Clients")); |
| 277 toolbar.appendSpacer(); | 155 this._section.appendField(WebInspector.UIString("Errors")); |
| 278 this._deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString("U
nregister service worker"), "garbage-collect-toolbar-item", WebInspector.UIStrin
g("Unregister")); | 156 this._errorsList = this._wrapWidget(this._section.appendRow()); |
| 279 this._deleteButton.addEventListener("click", this._deleteButtonClicked.bind(
this)); | 157 this._errorsList.classList.add("service-worker-error-stack", "monospace", "h
idden"); |
| 280 toolbar.appendToolbarItem(this._deleteButton); | |
| 281 | 158 |
| 282 this._tabbedPane = new WebInspector.TabbedPane(); | 159 this._linkifier = new WebInspector.Linkifier(); |
| 283 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele
cted, this._tabSelected, this); | 160 /** @type {!Map<string, !WebInspector.TargetInfo>} */ |
| 284 var modes = WebInspector.ServiceWorkerVersion.Modes; | 161 this._clientInfoCache = new Map(); |
| 285 this._tabbedPane.appendTab(modes.Installing, WebInspector.UIString("Installi
ng"), new WebInspector.VBox()); | 162 for (var error of registration.errors) |
| 286 this._tabbedPane.appendTab(modes.Waiting, WebInspector.UIString("Waiting"),
new WebInspector.VBox()); | 163 this._addError(error); |
| 287 this._tabbedPane.appendTab(modes.Active, WebInspector.UIString("Active"), ne
w WebInspector.VBox()); | 164 this._throttler = new WebInspector.Throttler(500); |
| 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 } | 165 } |
| 296 | 166 |
| 297 WebInspector.SWRegistrationWidget.prototype = { | 167 WebInspector.ServiceWorkersView.Section.prototype = { |
| 298 /** | 168 _scheduleUpdate: function() |
| 299 * @param {!WebInspector.Event} event | |
| 300 */ | |
| 301 _tabSelected: function(event) | |
| 302 { | 169 { |
| 303 if (event.data["isUserGesture"]) | 170 if (WebInspector.ServiceWorkersView._noThrottle) { |
| 304 this._lastManuallySelectedTab = event.data["tabId"]; | 171 this._update(); |
| 172 return; |
| 173 } |
| 174 this._throttler.schedule(this._update.bind(this)); |
| 305 }, | 175 }, |
| 306 | 176 |
| 307 /** | 177 /** |
| 308 * @param {!WebInspector.ServiceWorkerRegistration} registration | 178 * @return {!Promise} |
| 309 */ | 179 */ |
| 310 _updateRegistration: function(registration) | 180 _update: function() |
| 311 { | 181 { |
| 312 this._registration = registration; | 182 var fingerprint = this._registration.fingerprint(); |
| 313 this._updateButton.setEnabled(!registration.isDeleted); | 183 if (fingerprint === this._fingerprint) |
| 314 this._deleteButton.setEnabled(!registration.isDeleted); | 184 return Promise.resolve(); |
| 185 this._fingerprint = fingerprint; |
| 315 | 186 |
| 316 /** @type {!Map<string, !WebInspector.SWVersionWidget>} */ | 187 this._toolbar.setEnabled(!this._registration.isDeleted); |
| 317 var versionWidgets = new Map(); | |
| 318 | 188 |
| 319 // Remove all the redundant workers that are older than the | 189 var versions = this._registration.versionsByMode(); |
| 320 // active version. | 190 var title = this._registration.isDeleted ? WebInspector.UIString("%s - d
eleted", this._registration.scopeURL) : this._registration.scopeURL; |
| 321 var versions = registration.versions.valuesArray(); | 191 this._section.setTitle(title); |
| 322 var activeVersion = versions.find(version => version.mode() === WebInspe
ctor.ServiceWorkerVersion.Modes.Active); | 192 |
| 323 if (activeVersion) { | 193 var active = versions.get(WebInspector.ServiceWorkerVersion.Modes.Active
); |
| 324 versions = versions.filter(version => { | 194 var waiting = versions.get(WebInspector.ServiceWorkerVersion.Modes.Waiti
ng); |
| 325 if (version.mode() == WebInspector.ServiceWorkerVersion.Modes.Re
dundant) | 195 var installing = versions.get(WebInspector.ServiceWorkerVersion.Modes.In
stalling); |
| 326 return version.scriptLastModified > activeVersion.scriptLast
Modified; | 196 |
| 327 return true; | 197 var statusValue = this._wrapWidget(this._section.appendField(WebInspecto
r.UIString("Status"))); |
| 328 }); | 198 statusValue.removeChildren(); |
| 199 var versionsStack = statusValue.createChild("div", "service-worker-versi
on-stack"); |
| 200 versionsStack.createChild("div", "service-worker-version-stack-bar"); |
| 201 |
| 202 if (active) { |
| 203 var scriptElement = this._section.appendField(WebInspector.UIString(
"Source")); |
| 204 scriptElement.removeChildren(); |
| 205 var components = WebInspector.ParsedURL.splitURLIntoPathComponents(a
ctive.scriptURL); |
| 206 scriptElement.appendChild(WebInspector.linkifyURLAsNode(active.scrip
tURL, components.peekLast())); |
| 207 scriptElement.createChild("div", "report-field-value-subtitle").text
Content = WebInspector.UIString("Last modified %s", new Date(active.scriptLastMo
dified * 1000).toLocaleString()); |
| 208 |
| 209 var activeEntry = versionsStack.createChild("div", "service-worker-v
ersion"); |
| 210 activeEntry.createChild("div", "service-worker-active-circle"); |
| 211 activeEntry.createChild("span").textContent = WebInspector.UIString(
"#%s active and is %s", active.id, active.runningStatus); |
| 212 |
| 213 if (active.isRunning() || active.isStarting()) { |
| 214 var stopButton = createLink(activeEntry, WebInspector.UIString("
stop"), this._stopButtonClicked.bind(this, active.id)); |
| 215 if (!this._manager.targetForVersionId(active.id)) { |
| 216 var inspectButton = createLink(activeEntry, WebInspector.UIS
tring("inspect"), this._inspectButtonClicked.bind(this, active.id)); |
| 217 } |
| 218 } else if (active.isStartable()) { |
| 219 var startButton = createLink(activeEntry, WebInspector.UIString(
"start"), this._startButtonClicked.bind(this)); |
| 220 } |
| 221 |
| 222 var clientsList = this._wrapWidget(this._section.appendField(WebInsp
ector.UIString("Clients"))); |
| 223 clientsList.removeChildren(); |
| 224 this._section.setFieldVisible(WebInspector.UIString("Clients"), acti
ve.controlledClients.length); |
| 225 for (var client of active.controlledClients) { |
| 226 var clientLabelText = clientsList.createChild("div", "service-wo
rker-client"); |
| 227 if (this._clientInfoCache.has(client)) |
| 228 this._updateClientInfo(clientLabelText, /** @type {!WebInspe
ctor.TargetInfo} */(this._clientInfoCache.get(client))); |
| 229 this._manager.getTargetInfo(client, this._onClientInfo.bind(this
, clientLabelText)); |
| 230 } |
| 329 } | 231 } |
| 330 | 232 |
| 331 var firstMode; | 233 if (waiting) { |
| 332 var modesWithVersions = new Set(); | 234 var waitingEntry = versionsStack.createChild("div", "service-worker-
version"); |
| 333 for (var version of versions) { | 235 waitingEntry.createChild("div", "service-worker-waiting-circle"); |
| 334 if (version.isStoppedAndRedundant() && !version.errorMessages.length
) | 236 waitingEntry.createChild("span").textContent = WebInspector.UIString
("#%s waiting to activate", waiting.id); |
| 335 continue; | 237 var skipButton = createLink(waitingEntry, WebInspector.UIString("ski
pWaiting"), this._skipButtonClicked.bind(this)); |
| 336 var mode = version.mode(); | 238 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 } | 239 } |
| 349 for (var id of this._versionWidgets.keys()) { | 240 if (installing) { |
| 350 if (!versionWidgets.has(id)) | 241 var installingEntry = versionsStack.createChild("div", "service-work
er-version"); |
| 351 this._versionWidgets.get(id).detach(); | 242 installingEntry.createChild("div", "service-worker-installing-circle
"); |
| 243 installingEntry.createChild("span").textContent = WebInspector.UIStr
ing("#%s installing", installing.id); |
| 244 installingEntry.createChild("div", "service-worker-subtitle").textCo
ntent = new Date(installing.scriptLastModified * 1000).toLocaleString(); |
| 352 } | 245 } |
| 353 this._versionWidgets = versionWidgets; | |
| 354 | 246 |
| 355 for (var id of this._tabbedPane.tabIds()) | 247 this._section.setFieldVisible(WebInspector.UIString("Errors"), !!this._r
egistration.errors.length); |
| 356 this._tabbedPane.setTabEnabled(id, modesWithVersions.has(id)); | 248 var errorsValue = this._wrapWidget(this._section.appendField(WebInspecto
r.UIString("Errors"))); |
| 249 var errorsLabel = createLabel(String(this._registration.errors.length),
"error-icon"); |
| 250 errorsLabel.classList.add("service-worker-errors-label"); |
| 251 errorsValue.appendChild(errorsLabel); |
| 252 this._moreButton = createLink(errorsValue, this._errorsList.classList.co
ntains("hidden") ? WebInspector.UIString("details") : WebInspector.UIString("hid
e"), this._moreErrorsButtonClicked.bind(this)); |
| 253 var clearButton = createLink(errorsValue, WebInspector.UIString("clear")
, this._clearErrorsButtonClicked.bind(this)); |
| 357 | 254 |
| 358 this._pushButton.setEnabled(modesWithVersions.has(WebInspector.ServiceWo
rkerVersion.Modes.Active) && !this._registration.isDeleted); | 255 /** |
| 359 | 256 * @param {!Element} parent |
| 360 if (modesWithVersions.has(this._lastManuallySelectedTab)) { | 257 * @param {string} title |
| 361 this._tabbedPane.selectTab(this._lastManuallySelectedTab); | 258 * @param {function()} listener |
| 362 return; | 259 */ |
| 260 function createLink(parent, title, listener) |
| 261 { |
| 262 var span = parent.createChild("span", "link"); |
| 263 span.textContent = title; |
| 264 span.addEventListener("click", listener, false); |
| 363 } | 265 } |
| 364 if (activeVersion) { | 266 return Promise.resolve(); |
| 365 this._tabbedPane.selectTab(WebInspector.ServiceWorkerVersion.Modes.A
ctive); | |
| 366 return; | |
| 367 } | |
| 368 if (firstMode) | |
| 369 this._tabbedPane.selectTab(firstMode); | |
| 370 }, | 267 }, |
| 371 | 268 |
| 372 /** | 269 /** |
| 373 * @param {!WebInspector.Event} event | 270 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} error |
| 374 */ | 271 */ |
| 375 _deleteButtonClicked: function(event) | 272 _addError: function(error) |
| 273 { |
| 274 var target = this._manager.targetForVersionId(error.versionId); |
| 275 var message = this._errorsList.createChild("div"); |
| 276 if (this._errorsList.childElementCount > 100) |
| 277 this._errorsList.firstElementChild.remove(); |
| 278 message.appendChild(this._linkifier.linkifyScriptLocation(target, null,
error.sourceURL, error.lineNumber)); |
| 279 message.appendChild(createLabel("#" + error.versionId + ": " + error.err
orMessage, "error-icon")); |
| 280 }, |
| 281 |
| 282 _unregisterButtonClicked: function() |
| 376 { | 283 { |
| 377 this._manager.deleteRegistration(this._registration.id); | 284 this._manager.deleteRegistration(this._registration.id); |
| 378 }, | 285 }, |
| 379 | 286 |
| 380 /** | 287 _updateButtonClicked: function() |
| 381 * @param {!WebInspector.Event} event | |
| 382 */ | |
| 383 _updateButtonClicked: function(event) | |
| 384 { | 288 { |
| 385 this._manager.updateRegistration(this._registration.id); | 289 this._manager.updateRegistration(this._registration.id); |
| 386 }, | 290 }, |
| 387 | 291 |
| 388 /** | 292 _pushButtonClicked: function() |
| 389 * @param {!WebInspector.Event} event | |
| 390 */ | |
| 391 _pushButtonClicked: function(event) | |
| 392 { | 293 { |
| 393 var data = "Test push message from DevTools." | 294 var data = "Test push message from DevTools." |
| 394 this._manager.deliverPushMessage(this._registration.id, data); | 295 this._manager.deliverPushMessage(this._registration.id, data); |
| 395 }, | 296 }, |
| 396 | 297 |
| 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 /** | 298 /** |
| 530 * @param {!Element} element | 299 * @param {!Element} element |
| 531 * @param {?WebInspector.TargetInfo} targetInfo | 300 * @param {?WebInspector.TargetInfo} targetInfo |
| 532 */ | 301 */ |
| 533 _onClientInfo: function(element, targetInfo) | 302 _onClientInfo: function(element, targetInfo) |
| 534 { | 303 { |
| 535 if (!targetInfo) | 304 if (!targetInfo) |
| 536 return; | 305 return; |
| 537 this._clientInfoCache[targetInfo.id] = targetInfo; | 306 this._clientInfoCache.set(targetInfo.id, targetInfo); |
| 538 this._updateClientInfo(element, targetInfo); | 307 this._updateClientInfo(element, targetInfo); |
| 539 }, | 308 }, |
| 540 | 309 |
| 541 /** | 310 /** |
| 542 * @param {!Element} element | 311 * @param {!Element} element |
| 543 * @param {!WebInspector.TargetInfo} targetInfo | 312 * @param {!WebInspector.TargetInfo} targetInfo |
| 544 */ | 313 */ |
| 545 _updateClientInfo: function(element, targetInfo) | 314 _updateClientInfo: function(element, targetInfo) |
| 546 { | 315 { |
| 547 if (!(targetInfo.isWebContents() || targetInfo.isFrame())) { | 316 if (!(targetInfo.isWebContents() || targetInfo.isFrame())) { |
| 548 element.createTextChild(WebInspector.UIString("Worker: %s", targetIn
fo.url)); | 317 element.createTextChild(WebInspector.UIString("Worker: %s", targetIn
fo.url)); |
| 549 return; | 318 return; |
| 550 } | 319 } |
| 551 element.removeChildren(); | 320 element.removeChildren(); |
| 552 element.createTextChild(WebInspector.UIString("Tab: %s", targetInfo.url)
); | 321 element.createTextChild(targetInfo.url); |
| 553 var focusLabel = element.createChild("label", "service-worker-client-foc
us"); | 322 var focusLabel = element.createChild("label", "link"); |
| 554 focusLabel.createTextChild("focus"); | 323 focusLabel.createTextChild("focus"); |
| 555 focusLabel.addEventListener("click", this._activateTarget.bind(this, tar
getInfo.id), true); | 324 focusLabel.addEventListener("click", this._activateTarget.bind(this, tar
getInfo.id), true); |
| 556 }, | 325 }, |
| 557 | 326 |
| 558 /** | 327 /** |
| 559 * @param {string} targetId | 328 * @param {string} targetId |
| 560 */ | 329 */ |
| 561 _activateTarget: function(targetId) | 330 _activateTarget: function(targetId) |
| 562 { | 331 { |
| 563 this._manager.activateTarget(targetId); | 332 this._manager.activateTarget(targetId); |
| 564 }, | 333 }, |
| 565 | 334 |
| 566 /** | 335 _startButtonClicked: function() |
| 567 * @param {!WebInspector.Event} event | |
| 568 */ | |
| 569 _startButtonClicked: function(event) | |
| 570 { | 336 { |
| 571 this._manager.startWorker(this._scopeURL); | 337 this._manager.startWorker(this._registration.scopeURL); |
| 338 }, |
| 339 |
| 340 _skipButtonClicked: function() |
| 341 { |
| 342 this._manager.skipWaiting(this._registration.scopeURL); |
| 572 }, | 343 }, |
| 573 | 344 |
| 574 /** | 345 /** |
| 575 * @param {string} versionId | 346 * @param {string} versionId |
| 576 * @param {!WebInspector.Event} event | |
| 577 */ | 347 */ |
| 578 _stopButtonClicked: function(versionId, event) | 348 _stopButtonClicked: function(versionId) |
| 579 { | 349 { |
| 580 this._manager.stopWorker(versionId); | 350 this._manager.stopWorker(versionId); |
| 581 }, | 351 }, |
| 582 | 352 |
| 353 _moreErrorsButtonClicked: function() |
| 354 { |
| 355 var newVisible = this._errorsList.classList.contains("hidden"); |
| 356 this._moreButton.textContent = newVisible ? WebInspector.UIString("hide"
) : WebInspector.UIString("details"); |
| 357 this._errorsList.classList.toggle("hidden", !newVisible); |
| 358 }, |
| 359 |
| 360 _clearErrorsButtonClicked: function() |
| 361 { |
| 362 this._errorsList.removeChildren(); |
| 363 this._registration.clearErrors(); |
| 364 this._scheduleUpdate(); |
| 365 if (!this._errorsList.classList.contains("hidden")) |
| 366 this._moreErrorsButtonClicked(); |
| 367 }, |
| 368 |
| 583 /** | 369 /** |
| 584 * @param {string} versionId | 370 * @param {string} versionId |
| 585 * @param {!Event} event | |
| 586 */ | 371 */ |
| 587 _inspectButtonClicked: function(versionId, event) | 372 _inspectButtonClicked: function(versionId) |
| 588 { | 373 { |
| 589 this._manager.inspectWorker(versionId); | 374 this._manager.inspectWorker(versionId); |
| 590 }, | 375 }, |
| 591 | 376 |
| 592 __proto__: WebInspector.VBox.prototype | 377 /** |
| 378 * @param {!Element} container |
| 379 * @return {!Element} |
| 380 */ |
| 381 _wrapWidget: function(container) |
| 382 { |
| 383 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container); |
| 384 WebInspector.appendStyle(shadowRoot, "resources/serviceWorkersView.css")
; |
| 385 var contentElement = createElement("div"); |
| 386 shadowRoot.appendChild(contentElement); |
| 387 return contentElement; |
| 388 }, |
| 389 |
| 390 _dispose: function() |
| 391 { |
| 392 this._linkifier.dispose(); |
| 393 if (this._pendingUpdate) |
| 394 clearTimeout(this._pendingUpdate); |
| 395 } |
| 593 } | 396 } |
| OLD | NEW |