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

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: 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 + ")");
caseq 2016/05/05 01:09:22 Looks like WebInspector.UIString().. Wait.. A UISt
pfeldman 2016/05/05 02:21:42 Nope
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 = []
caseq 2016/05/05 01:09:22 ; while you're here
pfeldman 2016/05/05 02:21:42 Done.
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 } 675 delete this._fingerprint;
680 }, 676 },
681 677
682 /** 678 /**
679 * @return {string}
680 */
681 fingerprint: function()
682 {
683 if (!this._fingerprint)
684 this._fingerprint = JSON.stringify(this);
caseq 2016/05/05 01:09:22 Please don't. Perhaps, keep payload around and str
pfeldman 2016/05/05 02:21:41 Done.
685 return this._fingerprint;
686 },
687
688 /**
683 * @return {boolean} 689 * @return {boolean}
684 */ 690 */
685 isStartable: function() 691 isStartable: function()
686 { 692 {
687 return !this.registration.isDeleted && this.isActivated() && this.isStop ped(); 693 return !this.registration.isDeleted && this.isActivated() && this.isStop ped();
688 }, 694 },
689 695
690 /** 696 /**
691 * @return {boolean} 697 * @return {boolean}
692 */ 698 */
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 */ 786 */
781 mode: function() 787 mode: function()
782 { 788 {
783 if (this.isNew() || this.isInstalling()) 789 if (this.isNew() || this.isInstalling())
784 return WebInspector.ServiceWorkerVersion.Modes.Installing; 790 return WebInspector.ServiceWorkerVersion.Modes.Installing;
785 else if (this.isInstalled()) 791 else if (this.isInstalled())
786 return WebInspector.ServiceWorkerVersion.Modes.Waiting; 792 return WebInspector.ServiceWorkerVersion.Modes.Waiting;
787 else if (this.isActivating() || this.isActivated()) 793 else if (this.isActivating() || this.isActivated())
788 return WebInspector.ServiceWorkerVersion.Modes.Active; 794 return WebInspector.ServiceWorkerVersion.Modes.Active;
789 return WebInspector.ServiceWorkerVersion.Modes.Redundant; 795 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 } 796 }
799 } 797 }
800 798
801 /** 799 /**
802 * @constructor 800 * @constructor
803 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload 801 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload
802 * @extends {WebInspector.Object}
caseq 2016/05/05 01:09:22 Why?
pfeldman 2016/05/05 02:21:42 Done.
804 */ 803 */
805 WebInspector.ServiceWorkerRegistration = function(payload) 804 WebInspector.ServiceWorkerRegistration = function(payload)
806 { 805 {
807 this._update(payload); 806 this._update(payload);
808 /** @type {!Map.<string, !WebInspector.ServiceWorkerVersion>} */ 807 /** @type {!Map.<string, !WebInspector.ServiceWorkerVersion>} */
809 this.versions = new Map(); 808 this.versions = new Map();
810 this._deleting = false; 809 this._deleting = false;
810 /** @type {!Array<!ServiceWorkerAgent.ServiceWorkerErrorMessage>} */
811 this.errors = [];
811 } 812 }
812 813
813 WebInspector.ServiceWorkerRegistration.prototype = { 814 WebInspector.ServiceWorkerRegistration.prototype = {
814 /** 815 /**
815 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload 816 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload
816 */ 817 */
817 _update: function(payload) 818 _update: function(payload)
818 { 819 {
820 delete this._fingerprint;
819 this.id = payload.registrationId; 821 this.id = payload.registrationId;
820 this.scopeURL = payload.scopeURL; 822 this.scopeURL = payload.scopeURL;
823 this.securityOrigin = payload.scopeURL.asParsedURL().securityOrigin();
821 this.isDeleted = payload.isDeleted; 824 this.isDeleted = payload.isDeleted;
822 this.forceUpdateOnPageLoad = payload.forceUpdateOnPageLoad; 825 this.forceUpdateOnPageLoad = payload.forceUpdateOnPageLoad;
823 }, 826 },
824 827
825 /** 828 /**
829 * @return {string}
830 */
831 fingerprint: function()
832 {
833 if (this._fingerprint)
834 return this._fingerprint;
835
836 var result = [this.errors.length];
837 var ids = this.versions.keysArray().sort();
838 for (var id of ids)
839 result.push(this.versions.get(id).fingerprint());
840 this._fingerprint = result.join(",");
841 return this._fingerprint;
842 },
843
844 /**
845 * @return {!Map<string, !WebInspector.ServiceWorkerVersion>}
846 */
847 versionsByMode: function()
848 {
849 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */
850 var result = new Map();
851 for (var version of this.versions.values())
852 result.set(version.mode(), version);
853 return result;
caseq 2016/05/05 01:09:22 return new Map(this.versions.values().map(version
pfeldman 2016/05/05 02:21:42 this.versions.values(...).map is not a function
854 },
855
856 /**
826 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 857 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
827 * @return {!WebInspector.ServiceWorkerVersion} 858 * @return {!WebInspector.ServiceWorkerVersion}
828 */ 859 */
829 _updateVersion: function(payload) 860 _updateVersion: function(payload)
830 { 861 {
862 delete this._fingerprint;
831 var version = this.versions.get(payload.versionId); 863 var version = this.versions.get(payload.versionId);
832 if (!version) { 864 if (!version) {
833 version = new WebInspector.ServiceWorkerVersion(this, payload); 865 version = new WebInspector.ServiceWorkerVersion(this, payload);
834 this.versions.set(payload.versionId, version); 866 this.versions.set(payload.versionId, version);
835 return version; 867 return version;
836 } 868 }
837 version._update(payload); 869 version._update(payload);
838 return version; 870 return version;
839 }, 871 },
840 872
841 /** 873 /**
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} 874 * @return {boolean}
853 */ 875 */
854 _isRedundant: function() 876 _isRedundant: function()
855 { 877 {
856 for (var version of this.versions.values()) { 878 for (var version of this.versions.values()) {
857 if (!version.isStoppedAndRedundant()) 879 if (!version.isStoppedAndRedundant())
858 return false; 880 return false;
859 } 881 }
860 return true; 882 return true;
861 }, 883 },
862 884
863 /** 885 /**
864 * @return {boolean} 886 * @return {boolean}
865 */ 887 */
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() 888 _shouldBeRemoved: function()
879 { 889 {
880 return this._isRedundant() && (!this._hasErrorLog() || this._deleting); 890 return this._isRedundant() && (!this.errors.length || this._deleting);
881 } 891 },
892
893 clearErrors: function()
894 {
895 delete this._fingerprint;
896 this.errors = [];
897 },
898
899 __proto__: WebInspector.Object.prototype
882 } 900 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698