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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js

Issue 1940993002: DevTools: simplify Service Workers panel UI, remove non-actionable data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comment addressed. Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke rUpdateOnReload", false); 47 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke rUpdateOnReload", false);
48 if (this._forceUpdateSetting.get()) 48 if (this._forceUpdateSetting.get())
49 this._forceUpdateSettingChanged(); 49 this._forceUpdateSettingChanged();
50 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged, this); 50 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged, this);
51 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat ed, this); 51 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat ed, this);
52 } 52 }
53 53
54 WebInspector.ServiceWorkerManager.Events = { 54 WebInspector.ServiceWorkerManager.Events = {
55 WorkersUpdated: "WorkersUpdated", 55 WorkersUpdated: "WorkersUpdated",
56 RegistrationUpdated: "RegistrationUpdated", 56 RegistrationUpdated: "RegistrationUpdated",
57 RegistrationErrorAdded: "RegistrationErrorAdded",
57 RegistrationDeleted: "RegistrationDeleted" 58 RegistrationDeleted: "RegistrationDeleted"
58 } 59 }
59 60
60 WebInspector.ServiceWorkerManager.prototype = { 61 WebInspector.ServiceWorkerManager.prototype = {
61 enable: function() 62 enable: function()
62 { 63 {
63 if (this._enabled) 64 if (this._enabled)
64 return; 65 return;
65 this._enabled = true; 66 this._enabled = true;
66 67
(...skipping 18 matching lines...) Expand all
85 /** 86 /**
86 * @return {!Iterable.<!WebInspector.ServiceWorker>} 87 * @return {!Iterable.<!WebInspector.ServiceWorker>}
87 */ 88 */
88 workers: function() 89 workers: function()
89 { 90 {
90 return this._workers.values(); 91 return this._workers.values();
91 }, 92 },
92 93
93 /** 94 /**
94 * @param {string} versionId 95 * @param {string} versionId
95 * @return {boolean} 96 * @return {?WebInspector.Target}
96 */ 97 */
97 hasWorkerWithVersionId: function(versionId) 98 targetForVersionId: function(versionId)
98 { 99 {
99 for (var pair of this._workers) { 100 for (var pair of this._workers) {
100 if (pair[1]._versionId === versionId) 101 if (pair[1]._versionId === versionId)
101 return true; 102 return pair[1]._target;
102 } 103 }
103 return false; 104 return null;
104 }, 105 },
105 106
106 /** 107 /**
107 * @return {boolean} 108 * @return {boolean}
108 */ 109 */
109 hasWorkers: function() 110 hasWorkers: function()
110 { 111 {
111 return !!this._workers.size; 112 return !!this._workers.size;
112 }, 113 },
113 114
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 195
195 /** 196 /**
196 * @param {string} scope 197 * @param {string} scope
197 */ 198 */
198 startWorker: function(scope) 199 startWorker: function(scope)
199 { 200 {
200 this._agent.startWorker(scope); 201 this._agent.startWorker(scope);
201 }, 202 },
202 203
203 /** 204 /**
205 * @param {string} scope
206 */
207 skipWaiting: function(scope)
208 {
209 this._agent.skipWaiting(scope);
210 },
211
212 /**
204 * @param {string} versionId 213 * @param {string} versionId
205 */ 214 */
206 stopWorker: function(versionId) 215 stopWorker: function(versionId)
207 { 216 {
208 this._agent.stopWorker(versionId); 217 this._agent.stopWorker(versionId);
209 }, 218 },
210 219
211 /** 220 /**
212 * @param {string} versionId 221 * @param {string} versionId
213 */ 222 */
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 for (var worker of this._workers.valuesArray()) { 347 for (var worker of this._workers.valuesArray()) {
339 var status = versionById.get(worker.versionId()); 348 var status = versionById.get(worker.versionId());
340 if (status) 349 if (status)
341 worker.setStatus(status); 350 worker.setStatus(status);
342 } 351 }
343 }, 352 },
344 353
345 /** 354 /**
346 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload 355 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
347 */ 356 */
348 _workerErrorReported: function(payload) 357 _workerErrorReported: function(payload)
349 { 358 {
350 var registration = this._registrations.get(payload.registrationId); 359 var registration = this._registrations.get(payload.registrationId);
351 if (!registration) 360 if (!registration)
352 return; 361 return;
353 registration._addError(payload); 362 registration.errors.push(payload);
354 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationUpdated, registration); 363 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationErrorAdded, { registration: registration, error: payload });
355 }, 364 },
356 365
357 /** 366 /**
358 * @param {!WebInspector.Event} event 367 * @param {!WebInspector.Event} event
359 */ 368 */
360 _mainFrameNavigated: function(event) 369 _mainFrameNavigated: function(event)
361 { 370 {
362 // Attach to the new worker set. 371 // Attach to the new worker set.
363 }, 372 },
364 373
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 }, 485 },
477 486
478 /** 487 /**
479 * @param {!WebInspector.ExecutionContext} context 488 * @param {!WebInspector.ExecutionContext} context
480 */ 489 */
481 _setContextLabelFor: function(context) 490 _setContextLabelFor: function(context)
482 { 491 {
483 var parsedUrl = context.origin.asParsedURL(); 492 var parsedUrl = context.origin.asParsedURL();
484 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : cont ext.name; 493 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : cont ext.name;
485 if (this._status) 494 if (this._status)
486 context.setLabel(label + " (" + this._status + ")"); 495 context.setLabel(label + " #" + this._versionId + " (" + this._statu s + ")");
487 else 496 else
488 context.setLabel(label); 497 context.setLabel(label);
489 }, 498 },
490 499
491 _closeConnection: function() 500 _closeConnection: function()
492 { 501 {
493 this._connection._close(); 502 this._connection._close();
494 delete this._connection; 503 delete this._connection;
495 } 504 }
496 } 505 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 * @return {boolean} 630 * @return {boolean}
622 */ 631 */
623 isFrame: function() 632 isFrame: function()
624 { 633 {
625 return this.type == "frame"; 634 return this.type == "frame";
626 }, 635 },
627 } 636 }
628 637
629 /** 638 /**
630 * @constructor 639 * @constructor
631 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
632 */
633 WebInspector.ServiceWorkerErrorMessage = function(payload)
634 {
635 this.errorMessage = payload.errorMessage;
636 this.sourceURL = payload.sourceURL;
637 this.lineNumber = payload.lineNumber;
638 this.columnNumber = payload.columnNumber;
639 }
640
641 /**
642 * @constructor
643 * @param {!WebInspector.ServiceWorkerRegistration} registration 640 * @param {!WebInspector.ServiceWorkerRegistration} registration
644 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 641 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
645 */ 642 */
646 WebInspector.ServiceWorkerVersion = function(registration, payload) 643 WebInspector.ServiceWorkerVersion = function(registration, payload)
647 { 644 {
648 this.registration = registration; 645 this.registration = registration;
649 this._update(payload); 646 this._update(payload);
650 /** @type {!Array<!WebInspector.ServiceWorkerErrorMessage>} */
651 this.errorMessages = [];
652 } 647 }
653 648
654 /** 649 /**
655 * @enum {string} 650 * @enum {string}
656 */ 651 */
657 WebInspector.ServiceWorkerVersion.Modes = { 652 WebInspector.ServiceWorkerVersion.Modes = {
658 Installing: "installing", 653 Installing: "installing",
659 Waiting: "waiting", 654 Waiting: "waiting",
660 Active: "active", 655 Active: "active",
661 Redundant: "redundant" 656 Redundant: "redundant"
662 } 657 }
663 658
664 WebInspector.ServiceWorkerVersion.prototype = { 659 WebInspector.ServiceWorkerVersion.prototype = {
665 /** 660 /**
666 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 661 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
667 */ 662 */
668 _update: function(payload) 663 _update: function(payload)
669 { 664 {
670 this.id = payload.versionId; 665 this.id = payload.versionId;
671 this.scriptURL = payload.scriptURL; 666 this.scriptURL = payload.scriptURL;
667 this.securityOrigin = payload.scriptURL.asParsedURL().securityOrigin();
672 this.runningStatus = payload.runningStatus; 668 this.runningStatus = payload.runningStatus;
673 this.status = payload.status; 669 this.status = payload.status;
674 this.scriptLastModified = payload.scriptLastModified; 670 this.scriptLastModified = payload.scriptLastModified;
675 this.scriptResponseTime = payload.scriptResponseTime; 671 this.scriptResponseTime = payload.scriptResponseTime;
676 this.controlledClients = [] 672 this.controlledClients = [];
677 for (var i = 0; i < payload.controlledClients.length; ++i) { 673 for (var i = 0; i < payload.controlledClients.length; ++i)
678 this.controlledClients.push(payload.controlledClients[i]); 674 this.controlledClients.push(payload.controlledClients[i]);
679 }
680 }, 675 },
681 676
682 /** 677 /**
683 * @return {boolean} 678 * @return {boolean}
684 */ 679 */
685 isStartable: function() 680 isStartable: function()
686 { 681 {
687 return !this.registration.isDeleted && this.isActivated() && this.isStop ped(); 682 return !this.registration.isDeleted && this.isActivated() && this.isStop ped();
688 }, 683 },
689 684
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 */ 775 */
781 mode: function() 776 mode: function()
782 { 777 {
783 if (this.isNew() || this.isInstalling()) 778 if (this.isNew() || this.isInstalling())
784 return WebInspector.ServiceWorkerVersion.Modes.Installing; 779 return WebInspector.ServiceWorkerVersion.Modes.Installing;
785 else if (this.isInstalled()) 780 else if (this.isInstalled())
786 return WebInspector.ServiceWorkerVersion.Modes.Waiting; 781 return WebInspector.ServiceWorkerVersion.Modes.Waiting;
787 else if (this.isActivating() || this.isActivated()) 782 else if (this.isActivating() || this.isActivated())
788 return WebInspector.ServiceWorkerVersion.Modes.Active; 783 return WebInspector.ServiceWorkerVersion.Modes.Active;
789 return WebInspector.ServiceWorkerVersion.Modes.Redundant; 784 return WebInspector.ServiceWorkerVersion.Modes.Redundant;
790 },
791
792 /**
793 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
794 */
795 _addError: function(payload)
796 {
797 this.errorMessages.push(new WebInspector.ServiceWorkerErrorMessage(paylo ad));
798 } 785 }
799 } 786 }
800 787
801 /** 788 /**
802 * @constructor 789 * @constructor
803 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload 790 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload
804 */ 791 */
805 WebInspector.ServiceWorkerRegistration = function(payload) 792 WebInspector.ServiceWorkerRegistration = function(payload)
806 { 793 {
807 this._update(payload); 794 this._update(payload);
808 /** @type {!Map.<string, !WebInspector.ServiceWorkerVersion>} */ 795 /** @type {!Map.<string, !WebInspector.ServiceWorkerVersion>} */
809 this.versions = new Map(); 796 this.versions = new Map();
810 this._deleting = false; 797 this._deleting = false;
798 /** @type {!Array<!ServiceWorkerAgent.ServiceWorkerErrorMessage>} */
799 this.errors = [];
811 } 800 }
812 801
813 WebInspector.ServiceWorkerRegistration.prototype = { 802 WebInspector.ServiceWorkerRegistration.prototype = {
814 /** 803 /**
815 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload 804 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload
816 */ 805 */
817 _update: function(payload) 806 _update: function(payload)
818 { 807 {
808 this._fingerprint = Symbol("fingerprint");
819 this.id = payload.registrationId; 809 this.id = payload.registrationId;
820 this.scopeURL = payload.scopeURL; 810 this.scopeURL = payload.scopeURL;
811 this.securityOrigin = payload.scopeURL.asParsedURL().securityOrigin();
821 this.isDeleted = payload.isDeleted; 812 this.isDeleted = payload.isDeleted;
822 this.forceUpdateOnPageLoad = payload.forceUpdateOnPageLoad; 813 this.forceUpdateOnPageLoad = payload.forceUpdateOnPageLoad;
823 }, 814 },
824 815
825 /** 816 /**
817 * @return {symbol}
818 */
819 fingerprint: function()
820 {
821 return this._fingerprint;
822 },
823
824 /**
825 * @return {!Map<string, !WebInspector.ServiceWorkerVersion>}
826 */
827 versionsByMode: function()
828 {
829 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */
830 var result = new Map();
831 for (var version of this.versions.values())
832 result.set(version.mode(), version);
833 return result;
834 },
835
836 /**
826 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 837 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
827 * @return {!WebInspector.ServiceWorkerVersion} 838 * @return {!WebInspector.ServiceWorkerVersion}
828 */ 839 */
829 _updateVersion: function(payload) 840 _updateVersion: function(payload)
830 { 841 {
842 this._fingerprint = Symbol("fingerprint");
831 var version = this.versions.get(payload.versionId); 843 var version = this.versions.get(payload.versionId);
832 if (!version) { 844 if (!version) {
833 version = new WebInspector.ServiceWorkerVersion(this, payload); 845 version = new WebInspector.ServiceWorkerVersion(this, payload);
834 this.versions.set(payload.versionId, version); 846 this.versions.set(payload.versionId, version);
835 return version; 847 return version;
836 } 848 }
837 version._update(payload); 849 version._update(payload);
838 return version; 850 return version;
839 }, 851 },
840 852
841 /** 853 /**
842 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
843 */
844 _addError: function(payload)
845 {
846 var version = this.versions.get(payload.versionId);
847 if (version)
848 version._addError(payload);
849 },
850
851 /**
852 * @return {boolean} 854 * @return {boolean}
853 */ 855 */
854 _isRedundant: function() 856 _isRedundant: function()
855 { 857 {
856 for (var version of this.versions.values()) { 858 for (var version of this.versions.values()) {
857 if (!version.isStoppedAndRedundant()) 859 if (!version.isStoppedAndRedundant())
858 return false; 860 return false;
859 } 861 }
860 return true; 862 return true;
861 }, 863 },
862 864
863 /** 865 /**
864 * @return {boolean} 866 * @return {boolean}
865 */ 867 */
866 _hasErrorLog: function()
867 {
868 for (var version of this.versions.values()) {
869 if (version.errorMessages.length)
870 return true;
871 }
872 return false;
873 },
874
875 /**
876 * @return {boolean}
877 */
878 _shouldBeRemoved: function() 868 _shouldBeRemoved: function()
879 { 869 {
880 return this._isRedundant() && (!this._hasErrorLog() || this._deleting); 870 return this._isRedundant() && (!this.errors.length || this._deleting);
871 },
872
873 clearErrors: function()
874 {
875 this._fingerprint = Symbol("fingerprint");
876 this.errors = [];
881 } 877 }
882 } 878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698