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

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: default global 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 case ('global'):
69 storageType = Common.SettingStorageType.Global;
70 break;
71 default:
72 storageType = Common.SettingStorageType.Global;
73 }
74 var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, storageType) :
75 this.createSetting(settingName, defaultValue, storag eType);
62 if (descriptor['title']) 76 if (descriptor['title'])
63 setting.setTitle(descriptor['title']); 77 setting.setTitle(descriptor['title']);
64 this._moduleSettings.set(settingName, setting); 78 this._moduleSettings.set(settingName, setting);
65 } 79 }
66 80
67 /** 81 /**
68 * @param {string} settingName 82 * @param {string} settingName
69 * @return {!Common.Setting} 83 * @return {!Common.Setting}
70 */ 84 */
71 moduleSetting(settingName) { 85 moduleSetting(settingName) {
(...skipping 10 matching lines...) Expand all
82 settingForTest(settingName) { 96 settingForTest(settingName) {
83 var setting = this._registry.get(settingName); 97 var setting = this._registry.get(settingName);
84 if (!setting) 98 if (!setting)
85 throw new Error('No setting registered: ' + settingName); 99 throw new Error('No setting registered: ' + settingName);
86 return setting; 100 return setting;
87 } 101 }
88 102
89 /** 103 /**
90 * @param {string} key 104 * @param {string} key
91 * @param {*} defaultValue 105 * @param {*} defaultValue
92 * @param {boolean=} isLocal 106 * @param {!Common.SettingStorageType=} storageType
93 * @return {!Common.Setting} 107 * @return {!Common.Setting}
94 */ 108 */
95 createSetting(key, defaultValue, isLocal) { 109 createSetting(key, defaultValue, storageType) {
96 if (!this._registry.get(key)) { 110 var storage = this._storageFromType(storageType);
97 this._registry.set( 111 if (!this._registry.get(key))
98 key, new Common.Setting( 112 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)); 113 return /** @type {!Common.Setting} */ (this._registry.get(key));
102 } 114 }
103 115
104 /** 116 /**
105 * @param {string} key 117 * @param {string} key
106 * @param {*} defaultValue 118 * @param {*} defaultValue
107 * @return {!Common.Setting} 119 * @return {!Common.Setting}
108 */ 120 */
109 createLocalSetting(key, defaultValue) { 121 createLocalSetting(key, defaultValue) {
110 return this.createSetting(key, defaultValue, true); 122 return this.createSetting(key, defaultValue, Common.SettingStorageType.Local );
111 } 123 }
112 124
113 /** 125 /**
114 * @param {string} key 126 * @param {string} key
115 * @param {string} defaultValue 127 * @param {string} defaultValue
116 * @param {string=} regexFlags 128 * @param {string=} regexFlags
117 * @param {boolean=} isLocal 129 * @param {!Common.SettingStorageType=} storageType
118 * @return {!Common.RegExpSetting} 130 * @return {!Common.RegExpSetting}
119 */ 131 */
120 createRegExpSetting(key, defaultValue, regexFlags, isLocal) { 132 createRegExpSetting(key, defaultValue, regexFlags, storageType) {
121 if (!this._registry.get(key)) { 133 if (!this._registry.get(key)) {
122 this._registry.set( 134 this._registry.set(
123 key, new Common.RegExpSetting( 135 key,
124 this, key, defaultValue, this._eventSupport, isLocal ? this._ localStorage : this._settingsStorage, 136 new Common.RegExpSetting(
125 regexFlags)); 137 this, key, defaultValue, this._eventSupport, this._storageFromType (storageType), regexFlags));
126 } 138 }
127 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key)); 139 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key));
128 } 140 }
129 141
130 clearAll() { 142 clearAll() {
131 this._settingsStorage.removeAll(); 143 this._globalStorage.removeAll();
132 this._localStorage.removeAll(); 144 this._localStorage.removeAll();
133 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0); 145 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0);
134 versionSetting.set(Common.VersionController.currentVersion); 146 versionSetting.set(Common.VersionController.currentVersion);
135 } 147 }
148
149 /**
150 * @param {!Common.SettingStorageType=} storageType
151 * @return {!Common.SettingsStorage}
152 */
153 _storageFromType(storageType) {
154 switch (storageType) {
155 case (Common.SettingStorageType.Local):
156 return this._localStorage;
157 case (Common.SettingStorageType.Session):
158 return this._sessionStorage;
159 case (Common.SettingStorageType.Global):
160 return this._globalStorage;
161 }
162 return this._globalStorage;
163 }
136 }; 164 };
137 165
138 /** 166 /**
139 * @unrestricted 167 * @unrestricted
140 */ 168 */
141 Common.SettingsStorage = class { 169 Common.SettingsStorage = class {
142 /** 170 /**
143 * @param {!Object} object 171 * @param {!Object} object
144 * @param {function(string, string)=} setCallback 172 * @param {function(string, string)=} setCallback
145 * @param {function(string)=} removeCallback 173 * @param {function(string)=} removeCallback
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 'watchExpressions', 'workspaceExcludedFolders', 'xhrBreakpoints' 774 'watchExpressions', 'workspaceExcludedFolders', 'xhrBreakpoints'
747 ]); 775 ]);
748 if (!window.localStorage) 776 if (!window.localStorage)
749 return; 777 return;
750 778
751 for (var key in window.localStorage) { 779 for (var key in window.localStorage) {
752 if (localSettings.has(key)) 780 if (localSettings.has(key))
753 continue; 781 continue;
754 var value = window.localStorage[key]; 782 var value = window.localStorage[key];
755 window.localStorage.removeItem(key); 783 window.localStorage.removeItem(key);
756 Common.settings._settingsStorage[key] = value; 784 Common.settings._globalStorage[key] = value;
757 } 785 }
758 } 786 }
759 787
760 /** 788 /**
761 * @param {!Common.Setting} breakpointsSetting 789 * @param {!Common.Setting} breakpointsSetting
762 * @param {number} maxBreakpointsCount 790 * @param {number} maxBreakpointsCount
763 */ 791 */
764 _clearBreakpointsWhenTooMany(breakpointsSetting, maxBreakpointsCount) { 792 _clearBreakpointsWhenTooMany(breakpointsSetting, maxBreakpointsCount) {
765 // If there are too many breakpoints in a storage, it is likely due to a rec ent bug that caused 793 // 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. 794 // periodical breakpoints duplication leading to inspector slowness.
767 if (breakpointsSetting.get().length > maxBreakpointsCount) 795 if (breakpointsSetting.get().length > maxBreakpointsCount)
768 breakpointsSetting.set([]); 796 breakpointsSetting.set([]);
769 } 797 }
770 }; 798 };
771 799
772 Common.VersionController._currentVersionName = 'inspectorVersion'; 800 Common.VersionController._currentVersionName = 'inspectorVersion';
773 Common.VersionController.currentVersion = 24; 801 Common.VersionController.currentVersion = 24;
774 802
775 /** 803 /**
776 * @type {!Common.Settings} 804 * @type {!Common.Settings}
777 */ 805 */
778 Common.settings; 806 Common.settings;
779 807
780 /** 808 /**
809 * @enum {symbol}
810 */
811 Common.SettingStorageType = {
812 Global: Symbol('Global'),
813 Local: Symbol('Local'),
814 Session: Symbol('Session')
815 };
816
817 /**
781 * @param {string} settingName 818 * @param {string} settingName
782 * @return {!Common.Setting} 819 * @return {!Common.Setting}
783 */ 820 */
784 Common.moduleSetting = function(settingName) { 821 Common.moduleSetting = function(settingName) {
785 return Common.settings.moduleSetting(settingName); 822 return Common.settings.moduleSetting(settingName);
786 }; 823 };
787 824
788 /** 825 /**
789 * @param {string} settingName 826 * @param {string} settingName
790 * @return {!Common.Setting} 827 * @return {!Common.Setting}
791 */ 828 */
792 Common.settingForTest = function(settingName) { 829 Common.settingForTest = function(settingName) {
793 return Common.settings.settingForTest(settingName); 830 return Common.settings.settingForTest(settingName);
794 }; 831 };
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