Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: Source/devtools/front_end/resources/ServiceWorkersView.js

Issue 1023293004: [DevTools] Introduce Unregister/Start/Stop/Inspect buttons to ServiceWorkersView [2/2 blink] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/devtools/front_end/resources/serviceWorkersView.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @implements {WebInspector.TargetManager.Observer} 8 * @implements {WebInspector.TargetManager.Observer}
9 */ 9 */
10 WebInspector.ServiceWorkersView = function() 10 WebInspector.ServiceWorkersView = function()
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration 78 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration
79 */ 79 */
80 _updateRegistration: function(registration) 80 _updateRegistration: function(registration)
81 { 81 {
82 var parsedURL = registration.scopeURL.asParsedURL(); 82 var parsedURL = registration.scopeURL.asParsedURL();
83 if (!parsedURL) 83 if (!parsedURL)
84 return; 84 return;
85 var originHost = parsedURL.host; 85 var originHost = parsedURL.host;
86 var originElement = this._originHostToOriginElementMap.get(originHost); 86 var originElement = this._originHostToOriginElementMap.get(originHost);
87 if (!originElement) { 87 if (!originElement) {
88 originElement = new WebInspector.ServiceWorkerOriginElement(originHo st); 88 originElement = new WebInspector.ServiceWorkerOriginElement(this._ma nager, originHost);
89 if (this._securityOriginHosts.has(originHost)) 89 if (this._securityOriginHosts.has(originHost))
90 this._appendOriginNode(originElement); 90 this._appendOriginNode(originElement);
91 this._originHostToOriginElementMap.set(originHost, originElement); 91 this._originHostToOriginElementMap.set(originHost, originElement);
92 } 92 }
93 this._registrationIdToOriginElementMap.set(registration.registrationId, originElement); 93 this._registrationIdToOriginElementMap.set(registration.registrationId, originElement);
94 originElement._updateRegistration(registration); 94 originElement._updateRegistration(registration);
95 }, 95 },
96 96
97 /** 97 /**
98 * @param {!WebInspector.Event} event 98 * @param {!WebInspector.Event} event
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 _removeOriginNode: function(originElement) 200 _removeOriginNode: function(originElement)
201 { 201 {
202 this.root.removeChild(originElement.element); 202 this.root.removeChild(originElement.element);
203 }, 203 },
204 204
205 __proto__: WebInspector.VBox.prototype 205 __proto__: WebInspector.VBox.prototype
206 } 206 }
207 207
208 /** 208 /**
209 * @constructor 209 * @constructor
210 * @param {!WebInspector.ServiceWorkerManager} manager
210 * @param {string} originHost 211 * @param {string} originHost
211 */ 212 */
212 WebInspector.ServiceWorkerOriginElement = function(originHost) 213 WebInspector.ServiceWorkerOriginElement = function(manager, originHost)
213 { 214 {
215 this._manager = manager;
214 /** @type {!Map.<string, !WebInspector.SWRegistrationElement>} */ 216 /** @type {!Map.<string, !WebInspector.SWRegistrationElement>} */
215 this._registrationElements = new Map(); 217 this._registrationElements = new Map();
216 this.originHost = originHost; 218 this.originHost = originHost;
217 this.element = createElementWithClass("div", "service-workers-origin"); 219 this.element = createElementWithClass("div", "service-workers-origin");
218 this._listItemNode = this.element.createChild("li", "service-workers-origin- title"); 220 this._listItemNode = this.element.createChild("li", "service-workers-origin- title");
219 this._listItemNode.createChild("div").createTextChild(originHost); 221 this._listItemNode.createChild("div").createTextChild(originHost);
220 this._childrenListNode = this.element.createChild("ol"); 222 this._childrenListNode = this.element.createChild("ol");
221 } 223 }
222 224
223 WebInspector.ServiceWorkerOriginElement.prototype = { 225 WebInspector.ServiceWorkerOriginElement.prototype = {
224 /** 226 /**
225 * @return {boolean} 227 * @return {boolean}
226 */ 228 */
227 _hasRegistration: function() 229 _hasRegistration: function()
228 { 230 {
229 return this._registrationElements.size != 0; 231 return this._registrationElements.size != 0;
230 }, 232 },
231 233
232 /** 234 /**
233 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration 235 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration
234 */ 236 */
235 _updateRegistration: function(registration) 237 _updateRegistration: function(registration)
236 { 238 {
237 var swRegistrationElement = this._registrationElements.get(registration. registrationId); 239 var swRegistrationElement = this._registrationElements.get(registration. registrationId);
238 if (swRegistrationElement) { 240 if (swRegistrationElement) {
239 swRegistrationElement._updateRegistration(registration); 241 swRegistrationElement._updateRegistration(registration);
240 return; 242 return;
241 } 243 }
242 swRegistrationElement = new WebInspector.SWRegistrationElement(registrat ion); 244 swRegistrationElement = new WebInspector.SWRegistrationElement(this._man ager, registration);
243 this._registrationElements.set(registration.registrationId, swRegistrati onElement); 245 this._registrationElements.set(registration.registrationId, swRegistrati onElement);
244 this._childrenListNode.appendChild(swRegistrationElement.element); 246 this._childrenListNode.appendChild(swRegistrationElement.element);
245 }, 247 },
246 248
247 /** 249 /**
248 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration 250 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration
249 */ 251 */
250 _deleteRegistration: function(registration) 252 _deleteRegistration: function(registration)
251 { 253 {
252 var swRegistrationElement = this._registrationElements.get(registration. registrationId); 254 var swRegistrationElement = this._registrationElements.get(registration. registrationId);
(...skipping 21 matching lines...) Expand all
274 { 276 {
275 var swRegistrationElement = this._registrationElements.get(version.regis trationId); 277 var swRegistrationElement = this._registrationElements.get(version.regis trationId);
276 if (!swRegistrationElement) 278 if (!swRegistrationElement)
277 return; 279 return;
278 swRegistrationElement._deleteVersion(version); 280 swRegistrationElement._deleteVersion(version);
279 } 281 }
280 } 282 }
281 283
282 /** 284 /**
283 * @constructor 285 * @constructor
286 * @param {!WebInspector.ServiceWorkerManager} manager
284 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration 287 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration
285 */ 288 */
286 WebInspector.SWRegistrationElement = function(registration) 289 WebInspector.SWRegistrationElement = function(manager, registration)
287 { 290 {
291 this._manager = manager;
288 /** @type {!ServiceWorkerAgent.ServiceWorkerRegistration} */ 292 /** @type {!ServiceWorkerAgent.ServiceWorkerRegistration} */
289 this._registration = registration; 293 this._registration = registration;
290 /** @type {!Map.<string, !ServiceWorkerAgent.ServiceWorkerVersion>} */ 294 /** @type {!Map.<string, !ServiceWorkerAgent.ServiceWorkerVersion>} */
291 this._versions = new Map(); 295 this._versions = new Map();
292 this.element = createElementWithClass("div", "service-workers-registration") ; 296 this.element = createElementWithClass("div", "service-workers-registration") ;
293 this._titleNode = this.element.createChild("li").createChild("div", "service -workers-registration-title"); 297 var headerNode = this.element.createChild("li").createChild("div", "service- workers-registration-header");
298 this._titleNode = headerNode.createChild("div", "service-workers-registratio n-title");
299 this._unregisterButton = headerNode.createChild("button", "service-workers-b utton service-workers-unregister-button");
300 this._unregisterButton.addEventListener("click", this._unregisterButtonClick ed.bind(this), false);
301 this._unregisterButton.title = WebInspector.UIString("Unregister");
294 this._childrenListNode = this.element.createChild("ol"); 302 this._childrenListNode = this.element.createChild("ol");
295 this._updateRegistration(registration); 303 this._updateRegistration(registration);
296 } 304 }
297 305
298 /** @enum {string} */ 306 /** @enum {string} */
299 WebInspector.SWRegistrationElement.VersionMode = { 307 WebInspector.SWRegistrationElement.VersionMode = {
300 Installing: "installing", 308 Installing: "installing",
301 Waiting: "waiting", 309 Waiting: "waiting",
302 Active: "active", 310 Active: "active",
303 Redundant: "redundant", 311 Redundant: "redundant",
304 } 312 }
305 313
306 /** @type {!Map.<string, string>} */ 314 /** @type {!Map.<string, string>} */
307 WebInspector.SWRegistrationElement.VersionStausToModeMap = new Map([ 315 WebInspector.SWRegistrationElement.VersionStausToModeMap = new Map([
308 [ServiceWorkerAgent.ServiceWorkerVersionStatus.New, WebInspector.SWRegistrat ionElement.VersionMode.Installing], 316 [ServiceWorkerAgent.ServiceWorkerVersionStatus.New, WebInspector.SWRegistrat ionElement.VersionMode.Installing],
309 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installing, WebInspector.SWRe gistrationElement.VersionMode.Installing], 317 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installing, WebInspector.SWRe gistrationElement.VersionMode.Installing],
310 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installed, WebInspector.SWReg istrationElement.VersionMode.Waiting], 318 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Installed, WebInspector.SWReg istrationElement.VersionMode.Waiting],
311 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activating, WebInspector.SWRe gistrationElement.VersionMode.Active], 319 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activating, WebInspector.SWRe gistrationElement.VersionMode.Active],
312 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activated, WebInspector.SWReg istrationElement.VersionMode.Active], 320 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Activated, WebInspector.SWReg istrationElement.VersionMode.Active],
313 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Redundant, WebInspector.SWReg istrationElement.VersionMode.Redundant]]); 321 [ServiceWorkerAgent.ServiceWorkerVersionStatus.Redundant, WebInspector.SWReg istrationElement.VersionMode.Redundant]]);
314 322
315 WebInspector.SWRegistrationElement.prototype = { 323 WebInspector.SWRegistrationElement.prototype = {
316 /** 324 /**
317 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration 325 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} registration
318 */ 326 */
319 _updateRegistration: function(registration) 327 _updateRegistration: function(registration)
320 { 328 {
321 this._registration = registration; 329 this._registration = registration;
322 var text = WebInspector.UIString("Scope: ") + registration.scopeURL.asPa rsedURL().path; 330 var text = WebInspector.UIString("Scope: ") + registration.scopeURL.asPa rsedURL().path;
323 if (registration.isDeleted) 331 if (registration.isDeleted) {
324 text += " - deleted"; 332 this._unregisterButton.style.display = "none";
333 text += " - deleted";
pfeldman 2015/03/23 10:51:09 WebInspector.UIString supports message format %s,
horo 2015/03/23 11:22:24 Done.
334 } else {
335 this._unregisterButton.style.display = "block";
336 }
325 this._titleNode.textContent = text; 337 this._titleNode.textContent = text;
338 this._updateVersionList();
326 }, 339 },
327 340
328 /** 341 /**
329 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} version 342 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} version
330 */ 343 */
331 _updateVersion: function(version) 344 _updateVersion: function(version)
332 { 345 {
333 this._versions.set(version.versionId, version); 346 this._versions.set(version.versionId, version);
334 this._updateVersionList(); 347 this._updateVersionList();
335 }, 348 },
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 this._childrenListNode.appendChild(fragment); 387 this._childrenListNode.appendChild(fragment);
375 }, 388 },
376 389
377 /** 390 /**
378 * @param {!Map.<string, !Array.<!ServiceWorkerAgent.ServiceWorkerVersion>>} modeVersionArrayMap 391 * @param {!Map.<string, !Array.<!ServiceWorkerAgent.ServiceWorkerVersion>>} modeVersionArrayMap
379 * @param {string} mode 392 * @param {string} mode
380 */ 393 */
381 _createVersionModeRow: function(modeVersionArrayMap, mode) { 394 _createVersionModeRow: function(modeVersionArrayMap, mode) {
382 var versionList = /** @type {!Array.<!ServiceWorkerAgent.ServiceWorkerVe rsion>} */(modeVersionArrayMap.get(mode)); 395 var versionList = /** @type {!Array.<!ServiceWorkerAgent.ServiceWorkerVe rsion>} */(modeVersionArrayMap.get(mode));
383 var modeRowElement = createElementWithClass("div", "service-workers-vers ion-mode-row service-workers-version-mode-row-" + mode); 396 var modeRowElement = createElementWithClass("div", "service-workers-vers ion-mode-row service-workers-version-mode-row-" + mode);
384 modeRowElement.createChild("div", "service-workers-version-mode").create TextChild(mode); 397 modeRowElement.createChild("div", "service-workers-version-mode").create Child("div", "service-workers-version-mode-text").createTextChild(mode);
385 var versionsElement = modeRowElement.createChild("div", "service-workers -versions" + mode); 398 var versionsElement = modeRowElement.createChild("div", "service-workers -versions");
386 for (var version of versionList) { 399 for (var version of versionList) {
387 var stateRowElement = versionsElement.createChild("div", "service-wo rkers-version-row"); 400 var stateRowElement = versionsElement.createChild("div", "service-wo rkers-version-row");
388 stateRowElement.createChild("div", "service-workers-version-status") .createTextChild(version.status); 401 var statusDiv = stateRowElement.createChild("div", "service-workers- version-status");
389 stateRowElement.createChild("div", "service-workers-version-running- status").createTextChild(version.runningStatus); 402 statusDiv.createChild("div", "service-workers-version-status-text"). createTextChild(version.status);
390 stateRowElement.createChild("div", "service-workers-version-script-u rl").createTextChild(version.scriptURL.asParsedURL().path); 403 var runningStatusDiv = stateRowElement.createChild("div", "service-w orkers-version-running-status");
404 if (version.runningStatus == ServiceWorkerAgent.ServiceWorkerVersion RunningStatus.Running || version.runningStatus == ServiceWorkerAgent.ServiceWork erVersionRunningStatus.Starting) {
405 var stopButton = runningStatusDiv.createChild("button", "service -workers-button service-workers-stop-button service-workers-version-running-stat us-button");
406 stopButton.addEventListener("click", this._stopButtonClicked.bin d(this, version.versionId), false);
407 stopButton.title = WebInspector.UIString("Stop");
408 } else if (version.runningStatus == ServiceWorkerAgent.ServiceWorker VersionRunningStatus.Stopped && !this._registration.isDeleted) {
409 var startButton = runningStatusDiv.createChild("button", "servic e-workers-button service-workers-start-button service-workers-version-running-st atus-button");
410 startButton.addEventListener("click", this._startButtonClicked.b ind(this), false);
411 startButton.title = WebInspector.UIString("Start");
412 }
413 runningStatusDiv.createChild("div", "service-workers-version-running -status-text").createTextChild(version.runningStatus);
414 var scriptURLDiv = stateRowElement.createChild("div", "service-worke rs-version-script-url");
415 scriptURLDiv.createChild("div", "service-workers-version-script-url- text").createTextChild(version.scriptURL.asParsedURL().path);
416 if (version.runningStatus == ServiceWorkerAgent.ServiceWorkerVersion RunningStatus.Running || version.runningStatus == ServiceWorkerAgent.ServiceWork erVersionRunningStatus.Starting) {
417 var inspectButton = scriptURLDiv.createChild("span", "service-wo rkers-version-inspect");
418 inspectButton.createTextChild(WebInspector.UIString("inspect"));
419 inspectButton.addEventListener("click", this._inspectButtonClick ed.bind(this, version.versionId), false);
420 }
391 } 421 }
392 if (versionList.length == 0) { 422 if (versionList.length == 0) {
393 var stateRowElement = versionsElement.createChild("div", "service-wo rkers-version-row"); 423 var stateRowElement = versionsElement.createChild("div", "service-wo rkers-version-row");
394 stateRowElement.createChild("div", "service-workers-version-status") ; 424 stateRowElement.createChild("div", "service-workers-version-status") ;
395 stateRowElement.createChild("div", "service-workers-version-running- status"); 425 stateRowElement.createChild("div", "service-workers-version-running- status");
396 stateRowElement.createChild("div", "service-workers-version-script-u rl"); 426 stateRowElement.createChild("div", "service-workers-version-script-u rl");
397 } 427 }
398 return modeRowElement; 428 return modeRowElement;
429 },
430
431 /**
432 * @param {!Event} event
433 */
434 _unregisterButtonClicked: function(event) {
pfeldman 2015/03/23 10:51:09 { goes to the next line.
horo 2015/03/23 11:22:24 Done.
435 this._manager.target().serviceWorkerAgent().unregister(this._registratio n.scopeURL);
pfeldman 2015/03/23 10:51:09 You should not talk to the agent from here, all ag
horo 2015/03/23 11:22:24 Done.
436 },
437
438 /**
439 * @param {!Event} event
440 */
441 _startButtonClicked: function(event) {
442 this._manager.target().serviceWorkerAgent().startWorker(this._registrati on.scopeURL);
443 },
444
445 /**
446 * @param {string} versionId
447 * @param {!Event} event
448 */
449 _stopButtonClicked: function(versionId, event) {
450 this._manager.target().serviceWorkerAgent().stopWorker(versionId);
451 },
452
453 /**
454 * @param {string} versionId
455 * @param {!Event} event
456 */
457 _inspectButtonClicked: function(versionId, event) {
458 this._manager.target().serviceWorkerAgent().inspectWorker(versionId);
399 } 459 }
400 } 460 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/resources/serviceWorkersView.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698