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

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: introduce temporary sessionStorage Created 3 years, 10 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 | third_party/WebKit/Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
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 * @param {!Common.SettingsStorage} sessionStorage
38 */ 39 */
39 constructor(globalStorage, localStorage) { 40 constructor(globalStorage, localStorage, sessionStorage) {
40 this._settingsStorage = globalStorage; 41 this._settingsStorage = globalStorage;
41 this._localStorage = localStorage; 42 this._localStorage = localStorage;
43 this._sessionStorage = sessionStorage;
42 44
43 this._eventSupport = new Common.Object(); 45 this._eventSupport = new Common.Object();
44 /** @type {!Map<string, !Common.Setting>} */ 46 /** @type {!Map<string, !Common.Setting>} */
45 this._registry = new Map(); 47 this._registry = new Map();
46 /** @type {!Map<string, !Common.Setting>} */ 48 /** @type {!Map<string, !Common.Setting>} */
47 this._moduleSettings = new Map(); 49 this._moduleSettings = new Map();
48 self.runtime.extensions('setting').forEach(this._registerModuleSetting.bind( this)); 50 self.runtime.extensions('setting').forEach(this._registerModuleSetting.bind( this));
49 } 51 }
50 52
51 /** 53 /**
52 * @param {!Runtime.Extension} extension 54 * @param {!Runtime.Extension} extension
53 */ 55 */
54 _registerModuleSetting(extension) { 56 _registerModuleSetting(extension) {
55 var descriptor = extension.descriptor(); 57 var descriptor = extension.descriptor();
56 var settingName = descriptor['settingName']; 58 var settingName = descriptor['settingName'];
57 var settingType = descriptor['settingType']; 59 var isRegex = descriptor['settingType'] === 'regex';
58 var defaultValue = descriptor['defaultValue']; 60 var defaultValue = descriptor['defaultValue'];
59 var isLocal = !!descriptor['local']; 61 var localType = !!descriptor['local'] ? Common.SettingStorageType.Local : Co mmon.SettingStorageType.Global;
60 var setting = settingType === 'regex' ? this.createRegExpSetting(settingName , defaultValue, undefined, isLocal) : 62 var storageType = !!descriptor['session'] ? Common.SettingStorageType.Sessio n : localType;
61 this.createSetting(settingName, defa ultValue, isLocal); 63 var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, storageType) :
64 this.createSetting(settingName, defaultValue, storag eType);
62 if (descriptor['title']) 65 if (descriptor['title'])
63 setting.setTitle(descriptor['title']); 66 setting.setTitle(descriptor['title']);
64 this._moduleSettings.set(settingName, setting); 67 this._moduleSettings.set(settingName, setting);
65 } 68 }
luoe 2017/02/25 02:53:03 A very awkward part of this attempt is I've kept c
66 69
67 /** 70 /**
68 * @param {string} settingName 71 * @param {string} settingName
69 * @return {!Common.Setting} 72 * @return {!Common.Setting}
70 */ 73 */
71 moduleSetting(settingName) { 74 moduleSetting(settingName) {
72 var setting = this._moduleSettings.get(settingName); 75 var setting = this._moduleSettings.get(settingName);
73 if (!setting) 76 if (!setting)
74 throw new Error('No setting registered: ' + settingName); 77 throw new Error('No setting registered: ' + settingName);
75 return setting; 78 return setting;
76 } 79 }
77 80
78 /** 81 /**
79 * @param {string} settingName 82 * @param {string} settingName
80 * @return {!Common.Setting} 83 * @return {!Common.Setting}
81 */ 84 */
82 settingForTest(settingName) { 85 settingForTest(settingName) {
83 var setting = this._registry.get(settingName); 86 var setting = this._registry.get(settingName);
84 if (!setting) 87 if (!setting)
85 throw new Error('No setting registered: ' + settingName); 88 throw new Error('No setting registered: ' + settingName);
86 return setting; 89 return setting;
87 } 90 }
88 91
89 /** 92 /**
90 * @param {string} key 93 * @param {string} key
91 * @param {*} defaultValue 94 * @param {*} defaultValue
92 * @param {boolean=} isLocal 95 * @param {!Common.SettingStorageType=} storageType
93 * @return {!Common.Setting} 96 * @return {!Common.Setting}
94 */ 97 */
95 createSetting(key, defaultValue, isLocal) { 98 createSetting(key, defaultValue, storageType) {
96 if (!this._registry.get(key)) { 99 var storage = this._storageFromType(storageType);
97 this._registry.set( 100 if (!this._registry.get(key))
98 key, new Common.Setting( 101 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)); 102 return /** @type {!Common.Setting} */ (this._registry.get(key));
102 } 103 }
103 104
104 /** 105 /**
105 * @param {string} key 106 * @param {string} key
106 * @param {*} defaultValue 107 * @param {*} defaultValue
107 * @return {!Common.Setting} 108 * @return {!Common.Setting}
108 */ 109 */
109 createLocalSetting(key, defaultValue) { 110 createLocalSetting(key, defaultValue) {
110 return this.createSetting(key, defaultValue, true); 111 return this.createSetting(key, defaultValue, Common.SettingStorageType.Local );
111 } 112 }
112 113
113 /** 114 /**
114 * @param {string} key 115 * @param {string} key
115 * @param {string} defaultValue 116 * @param {string} defaultValue
116 * @param {string=} regexFlags 117 * @param {string=} regexFlags
117 * @param {boolean=} isLocal 118 * @param {!Common.SettingStorageType=} storageType
118 * @return {!Common.RegExpSetting} 119 * @return {!Common.RegExpSetting}
119 */ 120 */
120 createRegExpSetting(key, defaultValue, regexFlags, isLocal) { 121 createRegExpSetting(key, defaultValue, regexFlags, storageType) {
121 if (!this._registry.get(key)) { 122 if (!this._registry.get(key)) {
122 this._registry.set( 123 this._registry.set(
123 key, new Common.RegExpSetting( 124 key, new Common.RegExpSetting(
124 this, key, defaultValue, this._eventSupport, isLocal ? this._ localStorage : this._settingsStorage, 125 this, key, defaultValue, this._eventSupport, this._storageFro mType(storageType), regexFlags));
125 regexFlags));
126 } 126 }
127 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key)); 127 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key));
128 } 128 }
129 129
130 clearAll() { 130 clearAll() {
131 this._settingsStorage.removeAll(); 131 this._settingsStorage.removeAll();
132 this._localStorage.removeAll(); 132 this._localStorage.removeAll();
133 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0); 133 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0);
134 versionSetting.set(Common.VersionController.currentVersion); 134 versionSetting.set(Common.VersionController.currentVersion);
135 } 135 }
136
137 /**
138 * @param {!Common.SettingStorageType=} storageType
139 * @return {!Common.SettingsStorage}
140 */
141 _storageFromType(storageType) {
142 switch (storageType) {
143 case (Common.SettingStorageType.Local):
144 return this._localStorage;
145 case (Common.SettingStorageType.Session):
146 return this._sessionStorage;
147 case (Common.SettingStorageType.Global):
148 default:
149 return this._settingsStorage;
150 }
151 }
136 }; 152 };
137 153
138 /** 154 /**
139 * @unrestricted 155 * @unrestricted
140 */ 156 */
141 Common.SettingsStorage = class { 157 Common.SettingsStorage = class {
142 /** 158 /**
143 * @param {!Object} object 159 * @param {!Object} object
144 * @param {function(string, string)=} setCallback 160 * @param {function(string, string)=} setCallback
145 * @param {function(string)=} removeCallback 161 * @param {function(string)=} removeCallback
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 780
765 Common.VersionController._currentVersionName = 'inspectorVersion'; 781 Common.VersionController._currentVersionName = 'inspectorVersion';
766 Common.VersionController.currentVersion = 23; 782 Common.VersionController.currentVersion = 23;
767 783
768 /** 784 /**
769 * @type {!Common.Settings} 785 * @type {!Common.Settings}
770 */ 786 */
771 Common.settings; 787 Common.settings;
772 788
773 /** 789 /**
790 * @enum {symbol}
791 */
792 Common.SettingStorageType = {
793 Global: Symbol('Global'),
794 Local: Symbol('Local'),
795 Session: Symbol('Session')
796 };
797
798 /**
774 * @param {string} settingName 799 * @param {string} settingName
775 * @return {!Common.Setting} 800 * @return {!Common.Setting}
776 */ 801 */
777 Common.moduleSetting = function(settingName) { 802 Common.moduleSetting = function(settingName) {
778 return Common.settings.moduleSetting(settingName); 803 return Common.settings.moduleSetting(settingName);
779 }; 804 };
780 805
781 /** 806 /**
782 * @param {string} settingName 807 * @param {string} settingName
783 * @return {!Common.Setting} 808 * @return {!Common.Setting}
784 */ 809 */
785 Common.settingForTest = function(settingName) { 810 Common.settingForTest = function(settingName) {
786 return Common.settings.settingForTest(settingName); 811 return Common.settings.settingForTest(settingName);
787 }; 812 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698