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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/Settings.js

Issue 2708413003: DevTools: make disable javascript setting temporary (Closed)
Patch Set: ac Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 19 matching lines...) Expand all
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Common.Settings = class { 34 Common.Settings = class {
35 /** 35 /**
36 * @param {!Common.SettingsStorage} globalStorage 36 * @param {!Common.SettingsStorage} globalStorage
37 * @param {!Common.SettingsStorage} localStorage 37 * @param {!Common.SettingsStorage} localStorage
38 */ 38 */
39 constructor(globalStorage, localStorage) { 39 constructor(globalStorage, localStorage) {
40 this._settingsStorage = globalStorage; 40 this._globalStorage = globalStorage;
41 this._localStorage = localStorage; 41 this._localStorage = localStorage;
42 this._sessionStorage = new Common.SettingsStorage({});
42 43
43 this._eventSupport = new Common.Object(); 44 this._eventSupport = new Common.Object();
44 /** @type {!Map<string, !Common.Setting>} */ 45 /** @type {!Map<string, !Common.Setting>} */
45 this._registry = new Map(); 46 this._registry = new Map();
46 /** @type {!Map<string, !Common.Setting>} */ 47 /** @type {!Map<string, !Common.Setting>} */
47 this._moduleSettings = new Map(); 48 this._moduleSettings = new Map();
48 self.runtime.extensions('setting').forEach(this._registerModuleSetting.bind( this)); 49 self.runtime.extensions('setting').forEach(this._registerModuleSetting.bind( this));
49 } 50 }
50 51
51 /** 52 /**
52 * @param {!Runtime.Extension} extension 53 * @param {!Runtime.Extension} extension
53 */ 54 */
54 _registerModuleSetting(extension) { 55 _registerModuleSetting(extension) {
55 var descriptor = extension.descriptor(); 56 var descriptor = extension.descriptor();
56 var settingName = descriptor['settingName']; 57 var settingName = descriptor['settingName'];
57 var settingType = descriptor['settingType']; 58 var isRegex = descriptor['settingType'] === 'regex';
58 var defaultValue = descriptor['defaultValue']; 59 var defaultValue = descriptor['defaultValue'];
59 var isLocal = !!descriptor['local']; 60 var storageType;
60 var setting = settingType === 'regex' ? this.createRegExpSetting(settingName , defaultValue, undefined, isLocal) : 61 switch (descriptor['storageType']) {
61 this.createSetting(settingName, defa ultValue, isLocal); 62 case ('local'):
63 storageType = Common.SettingStorageType.Local;
64 break;
65 case ('session'):
66 storageType = Common.SettingStorageType.Session;
67 break;
68 default:
pfeldman 2017/03/01 23:23:19 You typically specify all the cases and then retur
luoe 2017/03/03 03:50:22 Done.
69 storageType = Common.SettingStorageType.Global;
70 break;
71 }
72 var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, storageType) :
73 this.createSetting(settingName, defaultValue, storag eType);
62 if (descriptor['title']) 74 if (descriptor['title'])
63 setting.setTitle(descriptor['title']); 75 setting.setTitle(descriptor['title']);
64 this._moduleSettings.set(settingName, setting); 76 this._moduleSettings.set(settingName, setting);
65 } 77 }
66 78
67 /** 79 /**
68 * @param {string} settingName 80 * @param {string} settingName
69 * @return {!Common.Setting} 81 * @return {!Common.Setting}
70 */ 82 */
71 moduleSetting(settingName) { 83 moduleSetting(settingName) {
(...skipping 10 matching lines...) Expand all
82 settingForTest(settingName) { 94 settingForTest(settingName) {
83 var setting = this._registry.get(settingName); 95 var setting = this._registry.get(settingName);
84 if (!setting) 96 if (!setting)
85 throw new Error('No setting registered: ' + settingName); 97 throw new Error('No setting registered: ' + settingName);
86 return setting; 98 return setting;
87 } 99 }
88 100
89 /** 101 /**
90 * @param {string} key 102 * @param {string} key
91 * @param {*} defaultValue 103 * @param {*} defaultValue
92 * @param {boolean=} isLocal 104 * @param {!Common.SettingStorageType=} storageType
93 * @return {!Common.Setting} 105 * @return {!Common.Setting}
94 */ 106 */
95 createSetting(key, defaultValue, isLocal) { 107 createSetting(key, defaultValue, storageType) {
96 if (!this._registry.get(key)) { 108 var storage = this._storageFromType(storageType);
97 this._registry.set( 109 if (!this._registry.get(key))
98 key, new Common.Setting( 110 this._registry.set(key, new Common.Setting(this, key, defaultValue, this._ eventSupport, storage));
99 this, key, defaultValue, this._eventSupport, isLocal ? this._ localStorage : this._settingsStorage));
100 }
101 return /** @type {!Common.Setting} */ (this._registry.get(key)); 111 return /** @type {!Common.Setting} */ (this._registry.get(key));
102 } 112 }
103 113
104 /** 114 /**
105 * @param {string} key 115 * @param {string} key
106 * @param {*} defaultValue 116 * @param {*} defaultValue
107 * @return {!Common.Setting} 117 * @return {!Common.Setting}
108 */ 118 */
109 createLocalSetting(key, defaultValue) { 119 createLocalSetting(key, defaultValue) {
110 return this.createSetting(key, defaultValue, true); 120 return this.createSetting(key, defaultValue, Common.SettingStorageType.Local );
111 } 121 }
112 122
113 /** 123 /**
114 * @param {string} key 124 * @param {string} key
115 * @param {string} defaultValue 125 * @param {string} defaultValue
116 * @param {string=} regexFlags 126 * @param {string=} regexFlags
117 * @param {boolean=} isLocal 127 * @param {!Common.SettingStorageType=} storageType
118 * @return {!Common.RegExpSetting} 128 * @return {!Common.RegExpSetting}
119 */ 129 */
120 createRegExpSetting(key, defaultValue, regexFlags, isLocal) { 130 createRegExpSetting(key, defaultValue, regexFlags, storageType) {
121 if (!this._registry.get(key)) { 131 if (!this._registry.get(key)) {
122 this._registry.set( 132 this._registry.set(
123 key, new Common.RegExpSetting( 133 key, new Common.RegExpSetting(
124 this, key, defaultValue, this._eventSupport, isLocal ? this._ localStorage : this._settingsStorage, 134 this, key, defaultValue, this._eventSupport, this._storageFro mType(storageType), regexFlags));
125 regexFlags));
126 } 135 }
127 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key)); 136 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key));
128 } 137 }
129 138
130 clearAll() { 139 clearAll() {
131 this._settingsStorage.removeAll(); 140 this._globalStorage.removeAll();
132 this._localStorage.removeAll(); 141 this._localStorage.removeAll();
133 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0); 142 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0);
134 versionSetting.set(Common.VersionController.currentVersion); 143 versionSetting.set(Common.VersionController.currentVersion);
135 } 144 }
145
146 /**
147 * @param {!Common.SettingStorageType=} storageType
148 * @return {!Common.SettingsStorage}
149 */
150 _storageFromType(storageType) {
151 switch (storageType) {
152 case (Common.SettingStorageType.Local):
153 return this._localStorage;
154 case (Common.SettingStorageType.Session):
155 return this._sessionStorage;
156 case (Common.SettingStorageType.Global):
157 default:
158 return this._globalStorage;
pfeldman 2017/03/01 23:23:19 ditto (no fall through). and I would actually defa
luoe 2017/03/03 03:50:22 Done.
159 }
160 }
136 }; 161 };
137 162
138 /** 163 /**
139 * @unrestricted 164 * @unrestricted
140 */ 165 */
141 Common.SettingsStorage = class { 166 Common.SettingsStorage = class {
142 /** 167 /**
143 * @param {!Object} object 168 * @param {!Object} object
144 * @param {function(string, string)=} setCallback 169 * @param {function(string, string)=} setCallback
145 * @param {function(string)=} removeCallback 170 * @param {function(string)=} removeCallback
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 'watchExpressions', 'workspaceExcludedFolders', 'xhrBreakpoints' 771 'watchExpressions', 'workspaceExcludedFolders', 'xhrBreakpoints'
747 ]); 772 ]);
748 if (!window.localStorage) 773 if (!window.localStorage)
749 return; 774 return;
750 775
751 for (var key in window.localStorage) { 776 for (var key in window.localStorage) {
752 if (localSettings.has(key)) 777 if (localSettings.has(key))
753 continue; 778 continue;
754 var value = window.localStorage[key]; 779 var value = window.localStorage[key];
755 window.localStorage.removeItem(key); 780 window.localStorage.removeItem(key);
756 Common.settings._settingsStorage[key] = value; 781 Common.settings._globalStorage[key] = value;
757 } 782 }
758 } 783 }
759 784
760 /** 785 /**
761 * @param {!Common.Setting} breakpointsSetting 786 * @param {!Common.Setting} breakpointsSetting
762 * @param {number} maxBreakpointsCount 787 * @param {number} maxBreakpointsCount
763 */ 788 */
764 _clearBreakpointsWhenTooMany(breakpointsSetting, maxBreakpointsCount) { 789 _clearBreakpointsWhenTooMany(breakpointsSetting, maxBreakpointsCount) {
765 // If there are too many breakpoints in a storage, it is likely due to a rec ent bug that caused 790 // If there are too many breakpoints in a storage, it is likely due to a rec ent bug that caused
766 // periodical breakpoints duplication leading to inspector slowness. 791 // periodical breakpoints duplication leading to inspector slowness.
767 if (breakpointsSetting.get().length > maxBreakpointsCount) 792 if (breakpointsSetting.get().length > maxBreakpointsCount)
768 breakpointsSetting.set([]); 793 breakpointsSetting.set([]);
769 } 794 }
770 }; 795 };
771 796
772 Common.VersionController._currentVersionName = 'inspectorVersion'; 797 Common.VersionController._currentVersionName = 'inspectorVersion';
773 Common.VersionController.currentVersion = 24; 798 Common.VersionController.currentVersion = 24;
774 799
775 /** 800 /**
776 * @type {!Common.Settings} 801 * @type {!Common.Settings}
777 */ 802 */
778 Common.settings; 803 Common.settings;
779 804
780 /** 805 /**
806 * @enum {symbol}
807 */
808 Common.SettingStorageType = {
809 Global: Symbol('Global'),
810 Local: Symbol('Local'),
811 Session: Symbol('Session')
812 };
813
814 /**
781 * @param {string} settingName 815 * @param {string} settingName
782 * @return {!Common.Setting} 816 * @return {!Common.Setting}
783 */ 817 */
784 Common.moduleSetting = function(settingName) { 818 Common.moduleSetting = function(settingName) {
785 return Common.settings.moduleSetting(settingName); 819 return Common.settings.moduleSetting(settingName);
786 }; 820 };
787 821
788 /** 822 /**
789 * @param {string} settingName 823 * @param {string} settingName
790 * @return {!Common.Setting} 824 * @return {!Common.Setting}
791 */ 825 */
792 Common.settingForTest = function(settingName) { 826 Common.settingForTest = function(settingName) {
793 return Common.settings.settingForTest(settingName); 827 return Common.settings.settingForTest(settingName);
794 }; 828 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/Tests.js ('k') | third_party/WebKit/Source/devtools/front_end/help/Help.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698