| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 * @constructor | 32 * @constructor |
| 33 * @param {!Object<string, string>} prefs |
| 33 */ | 34 */ |
| 34 WebInspector.Settings = function() | 35 WebInspector.Settings = function(prefs) |
| 35 { | 36 { |
| 37 this._settingsStorage = prefs; |
| 36 this._eventSupport = new WebInspector.Object(); | 38 this._eventSupport = new WebInspector.Object(); |
| 37 /** @type {!Map<string, !WebInspector.Setting>} */ | 39 /** @type {!Map<string, !WebInspector.Setting>} */ |
| 38 this._registry = new Map(); | 40 this._registry = new Map(); |
| 39 /** @type {!Map<string, !WebInspector.Setting>} */ | 41 /** @type {!Map<string, !WebInspector.Setting>} */ |
| 40 this._moduleSettings = new Map(); | 42 this._moduleSettings = new Map(); |
| 41 self.runtime.extensions("setting").forEach(this._registerModuleSetting.bind(
this)); | 43 self.runtime.extensions("setting").forEach(this._registerModuleSetting.bind(
this)); |
| 42 } | 44 } |
| 43 | 45 |
| 44 WebInspector.Settings.prototype = { | 46 WebInspector.Settings.prototype = { |
| 45 /** | 47 /** |
| 46 * @param {!Runtime.Extension} extension | 48 * @param {!Runtime.Extension} extension |
| 47 */ | 49 */ |
| 48 _registerModuleSetting: function(extension) | 50 _registerModuleSetting: function(extension) |
| 49 { | 51 { |
| 50 var descriptor = extension.descriptor(); | 52 var descriptor = extension.descriptor(); |
| 51 var settingName = descriptor["settingName"]; | 53 var settingName = descriptor["settingName"]; |
| 52 var settingType = descriptor["settingType"]; | 54 var settingType = descriptor["settingType"]; |
| 53 var defaultValue = descriptor["defaultValue"]; | 55 var defaultValue = descriptor["defaultValue"]; |
| 54 var setting = settingType === "regex" ? this.createRegExpSetting(setting
Name, defaultValue) : this.createSetting(settingName, defaultValue); | 56 var isLocal = !!descriptor["local"]; |
| 57 var setting = settingType === "regex" ? this.createRegExpSetting(setting
Name, defaultValue, undefined, isLocal) : this.createSetting(settingName, defaul
tValue, isLocal); |
| 55 this._moduleSettings.set(settingName, setting); | 58 this._moduleSettings.set(settingName, setting); |
| 56 }, | 59 }, |
| 57 | 60 |
| 58 /** | 61 /** |
| 59 * @param {string} settingName | 62 * @param {string} settingName |
| 60 * @return {!WebInspector.Setting} | 63 * @return {!WebInspector.Setting} |
| 61 */ | 64 */ |
| 62 moduleSetting: function(settingName) | 65 moduleSetting: function(settingName) |
| 63 { | 66 { |
| 64 var setting = this._moduleSettings.get(settingName); | 67 var setting = this._moduleSettings.get(settingName); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 { | 78 { |
| 76 var setting = this._registry.get(settingName); | 79 var setting = this._registry.get(settingName); |
| 77 if (!setting) | 80 if (!setting) |
| 78 throw new Error("No setting registered: " + settingName); | 81 throw new Error("No setting registered: " + settingName); |
| 79 return setting; | 82 return setting; |
| 80 }, | 83 }, |
| 81 | 84 |
| 82 /** | 85 /** |
| 83 * @param {string} key | 86 * @param {string} key |
| 84 * @param {*} defaultValue | 87 * @param {*} defaultValue |
| 88 * @param {boolean=} isLocal |
| 89 * @return {!WebInspector.Setting} |
| 90 */ |
| 91 createSetting: function(key, defaultValue, isLocal) |
| 92 { |
| 93 if (!this._registry.get(key)) |
| 94 this._registry.set(key, new WebInspector.Setting(this, key, defaultV
alue, this._eventSupport, isLocal ? (window.localStorage || {}) : this._settings
Storage)); |
| 95 return /** @type {!WebInspector.Setting} */ (this._registry.get(key)); |
| 96 }, |
| 97 |
| 98 /** |
| 99 * @param {string} key |
| 100 * @param {*} defaultValue |
| 85 * @return {!WebInspector.Setting} | 101 * @return {!WebInspector.Setting} |
| 86 */ | 102 */ |
| 87 createSetting: function(key, defaultValue) | 103 createLocalSetting: function(key, defaultValue) |
| 88 { | 104 { |
| 89 if (!this._registry.get(key)) | 105 return this.createSetting(key, defaultValue, true); |
| 90 this._registry.set(key, new WebInspector.Setting(key, defaultValue,
this._eventSupport, window.localStorage)); | |
| 91 return /** @type {!WebInspector.Setting} */ (this._registry.get(key)); | |
| 92 }, | 106 }, |
| 93 | 107 |
| 94 /** | 108 /** |
| 95 * @param {string} key | 109 * @param {string} key |
| 96 * @param {string} defaultValue | 110 * @param {string} defaultValue |
| 97 * @param {string=} regexFlags | 111 * @param {string=} regexFlags |
| 112 * @param {boolean=} isLocal |
| 98 * @return {!WebInspector.RegExpSetting} | 113 * @return {!WebInspector.RegExpSetting} |
| 99 */ | 114 */ |
| 100 createRegExpSetting: function(key, defaultValue, regexFlags) | 115 createRegExpSetting: function(key, defaultValue, regexFlags, isLocal) |
| 101 { | 116 { |
| 102 if (!this._registry.get(key)) | 117 if (!this._registry.get(key)) |
| 103 this._registry.set(key, new WebInspector.RegExpSetting(key, defaultV
alue, this._eventSupport, window.localStorage, regexFlags)); | 118 this._registry.set(key, new WebInspector.RegExpSetting(this, key, de
faultValue, this._eventSupport, isLocal ? (window.localStorage || {}) : this._se
ttingsStorage, regexFlags)); |
| 104 return /** @type {!WebInspector.RegExpSetting} */ (this._registry.get(ke
y)); | 119 return /** @type {!WebInspector.RegExpSetting} */ (this._registry.get(ke
y)); |
| 120 }, |
| 121 |
| 122 clearAll: function() |
| 123 { |
| 124 if (window.localStorage) |
| 125 window.localStorage.clear(); |
| 126 for (var key in this._settingsStorage) |
| 127 delete this._settingsStorage[key]; |
| 128 var versionSetting = WebInspector.settings.createSetting(WebInspector.Ve
rsionController._currentVersionName, 0); |
| 129 versionSetting.set(WebInspector.VersionController.currentVersion); |
| 105 } | 130 } |
| 106 } | 131 } |
| 107 | 132 |
| 108 /** | 133 /** |
| 109 * @constructor | 134 * @constructor |
| 135 * @param {!WebInspector.Settings} settings |
| 110 * @param {string} name | 136 * @param {string} name |
| 111 * @param {V} defaultValue | 137 * @param {V} defaultValue |
| 112 * @param {!WebInspector.Object} eventSupport | 138 * @param {!WebInspector.Object} eventSupport |
| 113 * @param {?Storage} storage | 139 * @param {!Object} storage |
| 114 * @template V | 140 * @template V |
| 115 */ | 141 */ |
| 116 WebInspector.Setting = function(name, defaultValue, eventSupport, storage) | 142 WebInspector.Setting = function(settings, name, defaultValue, eventSupport, stor
age) |
| 117 { | 143 { |
| 144 this._settings = settings; |
| 118 this._name = name; | 145 this._name = name; |
| 119 this._defaultValue = defaultValue; | 146 this._defaultValue = defaultValue; |
| 120 this._eventSupport = eventSupport; | 147 this._eventSupport = eventSupport; |
| 121 this._storage = storage; | 148 this._storage = storage; |
| 122 } | 149 } |
| 123 | 150 |
| 124 WebInspector.Setting.prototype = { | 151 WebInspector.Setting.prototype = { |
| 125 /** | 152 /** |
| 126 * @param {function(!WebInspector.Event)} listener | 153 * @param {function(!WebInspector.Event)} listener |
| 127 * @param {!Object=} thisObject | 154 * @param {!Object=} thisObject |
| (...skipping 19 matching lines...) Expand all Loading... |
| 147 | 174 |
| 148 /** | 175 /** |
| 149 * @return {V} | 176 * @return {V} |
| 150 */ | 177 */ |
| 151 get: function() | 178 get: function() |
| 152 { | 179 { |
| 153 if (typeof this._value !== "undefined") | 180 if (typeof this._value !== "undefined") |
| 154 return this._value; | 181 return this._value; |
| 155 | 182 |
| 156 this._value = this._defaultValue; | 183 this._value = this._defaultValue; |
| 157 if (this._storage && this._name in this._storage) { | 184 if (this._name in this._storage) { |
| 158 try { | 185 try { |
| 159 this._value = JSON.parse(this._storage[this._name]); | 186 this._value = JSON.parse(this._storage[this._name]); |
| 160 } catch(e) { | 187 } catch(e) { |
| 161 delete this._storage[this._name]; | 188 this.remove(); |
| 162 } | 189 } |
| 163 } | 190 } |
| 164 return this._value; | 191 return this._value; |
| 165 }, | 192 }, |
| 166 | 193 |
| 167 /** | 194 /** |
| 168 * @param {V} value | 195 * @param {V} value |
| 169 */ | 196 */ |
| 170 set: function(value) | 197 set: function(value) |
| 171 { | 198 { |
| 172 this._value = value; | 199 this._value = value; |
| 173 if (this._storage) { | 200 try { |
| 201 var settingString = JSON.stringify(value); |
| 174 try { | 202 try { |
| 175 var settingString = JSON.stringify(value); | 203 this._storage[this._name] = settingString; |
| 176 try { | |
| 177 this._storage[this._name] = settingString; | |
| 178 } catch(e) { | |
| 179 this._printSettingsSavingError(e.message, this._name, settin
gString); | |
| 180 } | |
| 181 } catch(e) { | 204 } catch(e) { |
| 182 WebInspector.console.error("Cannot stringify setting with name:
" + this._name + ", error: " + e.message); | 205 this._printSettingsSavingError(e.message, this._name, settingStr
ing); |
| 183 } | 206 } |
| 207 } catch(e) { |
| 208 WebInspector.console.error("Cannot stringify setting with name: " +
this._name + ", error: " + e.message); |
| 184 } | 209 } |
| 185 this._eventSupport.dispatchEventToListeners(this._name, value); | 210 this._eventSupport.dispatchEventToListeners(this._name, value); |
| 186 }, | 211 }, |
| 187 | 212 |
| 213 remove: function() |
| 214 { |
| 215 this._settings._registry.delete(this._name); |
| 216 this._settings._moduleSettings.delete(this._name); |
| 217 delete this._storage[this._name]; |
| 218 }, |
| 219 |
| 188 /** | 220 /** |
| 189 * @param {string} message | 221 * @param {string} message |
| 190 * @param {string} name | 222 * @param {string} name |
| 191 * @param {string} value | 223 * @param {string} value |
| 192 */ | 224 */ |
| 193 _printSettingsSavingError: function(message, name, value) | 225 _printSettingsSavingError: function(message, name, value) |
| 194 { | 226 { |
| 195 var errorMessage = "Error saving setting with name: " + this._name + ",
value length: " + value.length + ". Error: " + message; | 227 var errorMessage = "Error saving setting with name: " + this._name + ",
value length: " + value.length + ". Error: " + message; |
| 196 console.error(errorMessage); | 228 console.error(errorMessage); |
| 197 WebInspector.console.error(errorMessage); | 229 WebInspector.console.error(errorMessage); |
| 198 WebInspector.console.log("Ten largest settings: "); | 230 WebInspector.console.log("Ten largest settings: "); |
| 199 | 231 |
| 200 var sizes = { __proto__: null }; | 232 var sizes = { __proto__: null }; |
| 201 for (var key in this._storage) | 233 for (var key in this._storage) |
| 202 sizes[key] = this._storage.getItem(key).length; | 234 sizes[key] = this._storage[key].length; |
| 203 var keys = Object.keys(sizes); | 235 var keys = Object.keys(sizes); |
| 204 | 236 |
| 205 function comparator(key1, key2) | 237 function comparator(key1, key2) |
| 206 { | 238 { |
| 207 return sizes[key2] - sizes[key1]; | 239 return sizes[key2] - sizes[key1]; |
| 208 } | 240 } |
| 209 | 241 |
| 210 keys.sort(comparator); | 242 keys.sort(comparator); |
| 211 | 243 |
| 212 for (var i = 0; i < 10 && i < keys.length; ++i) | 244 for (var i = 0; i < 10 && i < keys.length; ++i) |
| 213 WebInspector.console.log("Setting: '" + keys[i] + "', size: " + size
s[keys[i]]); | 245 WebInspector.console.log("Setting: '" + keys[i] + "', size: " + size
s[keys[i]]); |
| 214 }, | 246 } |
| 215 } | 247 } |
| 216 | 248 |
| 217 /** | 249 /** |
| 218 * @constructor | 250 * @constructor |
| 219 * @extends {WebInspector.Setting} | 251 * @extends {WebInspector.Setting} |
| 252 * @param {!WebInspector.Settings} settings |
| 220 * @param {string} name | 253 * @param {string} name |
| 221 * @param {string} defaultValue | 254 * @param {string} defaultValue |
| 222 * @param {!WebInspector.Object} eventSupport | 255 * @param {!WebInspector.Object} eventSupport |
| 223 * @param {?Storage} storage | 256 * @param {!Object<string, string>} storage |
| 224 * @param {string=} regexFlags | 257 * @param {string=} regexFlags |
| 225 */ | 258 */ |
| 226 WebInspector.RegExpSetting = function(name, defaultValue, eventSupport, storage,
regexFlags) | 259 WebInspector.RegExpSetting = function(settings, name, defaultValue, eventSupport
, storage, regexFlags) |
| 227 { | 260 { |
| 228 WebInspector.Setting.call(this, name, defaultValue ? [{ pattern: defaultValu
e }] : [], eventSupport, storage); | 261 WebInspector.Setting.call(this, settings, name, defaultValue ? [{ pattern: d
efaultValue }] : [], eventSupport, storage); |
| 229 this._regexFlags = regexFlags; | 262 this._regexFlags = regexFlags; |
| 230 } | 263 } |
| 231 | 264 |
| 232 WebInspector.RegExpSetting.prototype = { | 265 WebInspector.RegExpSetting.prototype = { |
| 233 /** | 266 /** |
| 234 * @override | 267 * @override |
| 235 * @return {string} | 268 * @return {string} |
| 236 */ | 269 */ |
| 237 get: function() | 270 get: function() |
| 238 { | 271 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 __proto__: WebInspector.Setting.prototype | 325 __proto__: WebInspector.Setting.prototype |
| 293 } | 326 } |
| 294 | 327 |
| 295 /** | 328 /** |
| 296 * @constructor | 329 * @constructor |
| 297 */ | 330 */ |
| 298 WebInspector.VersionController = function() | 331 WebInspector.VersionController = function() |
| 299 { | 332 { |
| 300 } | 333 } |
| 301 | 334 |
| 302 WebInspector.VersionController.currentVersion = 11; | 335 WebInspector.VersionController._currentVersionName = "inspectorVersion"; |
| 336 WebInspector.VersionController.currentVersion = 12; |
| 303 | 337 |
| 304 WebInspector.VersionController.prototype = { | 338 WebInspector.VersionController.prototype = { |
| 305 updateVersion: function() | 339 updateVersion: function() |
| 306 { | 340 { |
| 307 var versionSetting = WebInspector.settings.createSetting("inspectorVersi
on", 0); | 341 var versionSetting = WebInspector.settings.createSetting(WebInspector.Ve
rsionController._currentVersionName, 0); |
| 308 var currentVersion = WebInspector.VersionController.currentVersion; | 342 var currentVersion = WebInspector.VersionController.currentVersion; |
| 309 var oldVersion = versionSetting.get(); | 343 var oldVersion = versionSetting.get(); |
| 310 var methodsToRun = this._methodsToRunToUpdateVersion(oldVersion, current
Version); | 344 var methodsToRun = this._methodsToRunToUpdateVersion(oldVersion, current
Version); |
| 311 for (var i = 0; i < methodsToRun.length; ++i) | 345 for (var i = 0; i < methodsToRun.length; ++i) |
| 312 this[methodsToRun[i]].call(this); | 346 this[methodsToRun[i]].call(this); |
| 313 versionSetting.set(currentVersion); | 347 versionSetting.set(currentVersion); |
| 314 }, | 348 }, |
| 315 | 349 |
| 316 /** | 350 /** |
| 317 * @param {number} oldVersion | 351 * @param {number} oldVersion |
| 318 * @param {number} currentVersion | 352 * @param {number} currentVersion |
| 319 */ | 353 */ |
| 320 _methodsToRunToUpdateVersion: function(oldVersion, currentVersion) | 354 _methodsToRunToUpdateVersion: function(oldVersion, currentVersion) |
| 321 { | 355 { |
| 322 var result = []; | 356 var result = []; |
| 323 for (var i = oldVersion; i < currentVersion; ++i) | 357 for (var i = oldVersion; i < currentVersion; ++i) |
| 324 result.push("_updateVersionFrom" + i + "To" + (i + 1)); | 358 result.push("_updateVersionFrom" + i + "To" + (i + 1)); |
| 325 return result; | 359 return result; |
| 326 }, | 360 }, |
| 327 | 361 |
| 328 _updateVersionFrom0To1: function() | 362 _updateVersionFrom0To1: function() |
| 329 { | 363 { |
| 330 this._clearBreakpointsWhenTooMany(WebInspector.settings.createSetting("b
reakpoints", []), 500000); | 364 this._clearBreakpointsWhenTooMany(WebInspector.settings.createLocalSetti
ng("breakpoints", []), 500000); |
| 331 }, | 365 }, |
| 332 | 366 |
| 333 _updateVersionFrom1To2: function() | 367 _updateVersionFrom1To2: function() |
| 334 { | 368 { |
| 335 var versionSetting = WebInspector.settings.createSetting("previouslyView
edFiles", []); | 369 WebInspector.settings.createSetting("previouslyViewedFiles", []).set([])
; |
| 336 versionSetting.set([]); | |
| 337 }, | 370 }, |
| 338 | 371 |
| 339 _updateVersionFrom2To3: function() | 372 _updateVersionFrom2To3: function() |
| 340 { | 373 { |
| 341 var fileSystemMappingSetting = WebInspector.settings.createSetting("file
SystemMapping", {}); | 374 WebInspector.settings.createSetting("fileSystemMapping", {}).set({}); |
| 342 fileSystemMappingSetting.set({}); | 375 WebInspector.settings.createSetting("fileMappingEntries", []).remove(); |
| 343 if (window.localStorage) | |
| 344 delete window.localStorage["fileMappingEntries"]; | |
| 345 }, | 376 }, |
| 346 | 377 |
| 347 _updateVersionFrom3To4: function() | 378 _updateVersionFrom3To4: function() |
| 348 { | 379 { |
| 349 var advancedMode = WebInspector.settings.createSetting("showHeaSnapshotO
bjectsHiddenProperties", false).get(); | 380 var advancedMode = WebInspector.settings.createSetting("showHeaSnapshotO
bjectsHiddenProperties", false); |
| 350 WebInspector.moduleSetting("showAdvancedHeapSnapshotProperties").set(adv
ancedMode); | 381 WebInspector.moduleSetting("showAdvancedHeapSnapshotProperties").set(adv
ancedMode.get()); |
| 382 advancedMode.remove(); |
| 351 }, | 383 }, |
| 352 | 384 |
| 353 _updateVersionFrom4To5: function() | 385 _updateVersionFrom4To5: function() |
| 354 { | 386 { |
| 355 if (!window.localStorage) | |
| 356 return; | |
| 357 var settingNames = { | 387 var settingNames = { |
| 358 "FileSystemViewSidebarWidth": "fileSystemViewSplitViewState", | 388 "FileSystemViewSidebarWidth": "fileSystemViewSplitViewState", |
| 359 "elementsSidebarWidth": "elementsPanelSplitViewState", | 389 "elementsSidebarWidth": "elementsPanelSplitViewState", |
| 360 "StylesPaneSplitRatio": "stylesPaneSplitViewState", | 390 "StylesPaneSplitRatio": "stylesPaneSplitViewState", |
| 361 "heapSnapshotRetainersViewSize": "heapSnapshotSplitViewState", | 391 "heapSnapshotRetainersViewSize": "heapSnapshotSplitViewState", |
| 362 "InspectorView.splitView": "InspectorView.splitViewState", | 392 "InspectorView.splitView": "InspectorView.splitViewState", |
| 363 "InspectorView.screencastSplitView": "InspectorView.screencastSplitV
iewState", | 393 "InspectorView.screencastSplitView": "InspectorView.screencastSplitV
iewState", |
| 364 "Inspector.drawerSplitView": "Inspector.drawerSplitViewState", | 394 "Inspector.drawerSplitView": "Inspector.drawerSplitViewState", |
| 365 "layerDetailsSplitView": "layerDetailsSplitViewState", | 395 "layerDetailsSplitView": "layerDetailsSplitViewState", |
| 366 "networkSidebarWidth": "networkPanelSplitViewState", | 396 "networkSidebarWidth": "networkPanelSplitViewState", |
| 367 "sourcesSidebarWidth": "sourcesPanelSplitViewState", | 397 "sourcesSidebarWidth": "sourcesPanelSplitViewState", |
| 368 "scriptsPanelNavigatorSidebarWidth": "sourcesPanelNavigatorSplitView
State", | 398 "scriptsPanelNavigatorSidebarWidth": "sourcesPanelNavigatorSplitView
State", |
| 369 "sourcesPanelSplitSidebarRatio": "sourcesPanelDebuggerSidebarSplitVi
ewState", | 399 "sourcesPanelSplitSidebarRatio": "sourcesPanelDebuggerSidebarSplitVi
ewState", |
| 370 "timeline-details": "timelinePanelDetailsSplitViewState", | 400 "timeline-details": "timelinePanelDetailsSplitViewState", |
| 371 "timeline-split": "timelinePanelRecorsSplitViewState", | 401 "timeline-split": "timelinePanelRecorsSplitViewState", |
| 372 "timeline-view": "timelinePanelTimelineStackSplitViewState", | 402 "timeline-view": "timelinePanelTimelineStackSplitViewState", |
| 373 "auditsSidebarWidth": "auditsPanelSplitViewState", | 403 "auditsSidebarWidth": "auditsPanelSplitViewState", |
| 374 "layersSidebarWidth": "layersPanelSplitViewState", | 404 "layersSidebarWidth": "layersPanelSplitViewState", |
| 375 "profilesSidebarWidth": "profilesPanelSplitViewState", | 405 "profilesSidebarWidth": "profilesPanelSplitViewState", |
| 376 "resourcesSidebarWidth": "resourcesPanelSplitViewState" | 406 "resourcesSidebarWidth": "resourcesPanelSplitViewState" |
| 377 }; | 407 }; |
| 408 var empty = {}; |
| 378 for (var oldName in settingNames) { | 409 for (var oldName in settingNames) { |
| 379 var newName = settingNames[oldName]; | 410 var newName = settingNames[oldName]; |
| 380 var oldNameH = oldName + "H"; | 411 var oldNameH = oldName + "H"; |
| 381 | 412 |
| 382 var newValue = null; | 413 var newValue = null; |
| 383 var oldSetting = WebInspector.settings.createSetting(oldName, undefi
ned).get(); | 414 var oldSetting = WebInspector.settings.createSetting(oldName, empty)
; |
| 384 if (oldSetting) { | 415 if (oldSetting.get() !== empty) { |
| 385 newValue = newValue || {}; | 416 newValue = newValue || {}; |
| 386 newValue.vertical = {}; | 417 newValue.vertical = {}; |
| 387 newValue.vertical.size = oldSetting; | 418 newValue.vertical.size = oldSetting.get(); |
| 388 delete window.localStorage[oldName]; | 419 oldSetting.remove(); |
| 389 } | 420 } |
| 390 var oldSettingH = WebInspector.settings.createSetting(oldNameH, unde
fined).get(); | 421 var oldSettingH = WebInspector.settings.createSetting(oldNameH, empt
y); |
| 391 if (oldSettingH) { | 422 if (oldSettingH.get() !== empty) { |
| 392 newValue = newValue || {}; | 423 newValue = newValue || {}; |
| 393 newValue.horizontal = {}; | 424 newValue.horizontal = {}; |
| 394 newValue.horizontal.size = oldSettingH; | 425 newValue.horizontal.size = oldSettingH.get(); |
| 395 delete window.localStorage[oldNameH]; | 426 oldSettingH.remove(); |
| 396 } | 427 } |
| 397 var newSetting = WebInspector.settings.createSetting(newName, {}); | |
| 398 if (newValue) | 428 if (newValue) |
| 399 newSetting.set(newValue); | 429 WebInspector.settings.createSetting(newName, {}).set(newValue); |
| 400 } | 430 } |
| 401 }, | 431 }, |
| 402 | 432 |
| 403 _updateVersionFrom5To6: function() | 433 _updateVersionFrom5To6: function() |
| 404 { | 434 { |
| 405 if (!window.localStorage) | |
| 406 return; | |
| 407 | |
| 408 var settingNames = { | 435 var settingNames = { |
| 409 "debuggerSidebarHidden": "sourcesPanelSplitViewState", | 436 "debuggerSidebarHidden": "sourcesPanelSplitViewState", |
| 410 "navigatorHidden": "sourcesPanelNavigatorSplitViewState", | 437 "navigatorHidden": "sourcesPanelNavigatorSplitViewState", |
| 411 "WebInspector.Drawer.showOnLoad": "Inspector.drawerSplitViewState" | 438 "WebInspector.Drawer.showOnLoad": "Inspector.drawerSplitViewState" |
| 412 }; | 439 }; |
| 413 | 440 |
| 441 var empty = {}; |
| 414 for (var oldName in settingNames) { | 442 for (var oldName in settingNames) { |
| 415 var newName = settingNames[oldName]; | 443 var newName = settingNames[oldName]; |
| 416 | 444 |
| 417 var oldSetting = WebInspector.settings.createSetting(oldName, undefi
ned).get(); | 445 var oldSetting = WebInspector.settings.createSetting(oldName, empty)
; |
| 418 var invert = "WebInspector.Drawer.showOnLoad" === oldName; | 446 var invert = "WebInspector.Drawer.showOnLoad" === oldName; |
| 419 var hidden = !!oldSetting !== invert; | 447 var hidden = (oldSetting.get() !== empty) !== invert; |
| 420 delete window.localStorage[oldName]; | 448 oldSetting.remove(); |
| 421 var showMode = hidden ? "OnlyMain" : "Both"; | 449 var showMode = hidden ? "OnlyMain" : "Both"; |
| 422 | 450 |
| 423 var newSetting = WebInspector.settings.createSetting(newName, null); | 451 var newSetting = WebInspector.settings.createSetting(newName, empty)
; |
| 424 var newValue = newSetting.get() || {}; | 452 var newValue = newSetting.get() || {}; |
| 425 newValue.vertical = newValue.vertical || {}; | 453 newValue.vertical = newValue.vertical || {}; |
| 426 newValue.vertical.showMode = showMode; | 454 newValue.vertical.showMode = showMode; |
| 427 newValue.horizontal = newValue.horizontal || {}; | 455 newValue.horizontal = newValue.horizontal || {}; |
| 428 newValue.horizontal.showMode = showMode; | 456 newValue.horizontal.showMode = showMode; |
| 429 newSetting.set(newValue); | 457 newSetting.set(newValue); |
| 430 } | 458 } |
| 431 }, | 459 }, |
| 432 | 460 |
| 433 _updateVersionFrom6To7: function() | 461 _updateVersionFrom6To7: function() |
| 434 { | 462 { |
| 435 if (!window.localStorage) | |
| 436 return; | |
| 437 | |
| 438 var settingNames = { | 463 var settingNames = { |
| 439 "sourcesPanelNavigatorSplitViewState": "sourcesPanelNavigatorSplitVi
ewState", | 464 "sourcesPanelNavigatorSplitViewState": "sourcesPanelNavigatorSplitVi
ewState", |
| 440 "elementsPanelSplitViewState": "elementsPanelSplitViewState", | 465 "elementsPanelSplitViewState": "elementsPanelSplitViewState", |
| 441 "stylesPaneSplitViewState": "stylesPaneSplitViewState", | 466 "stylesPaneSplitViewState": "stylesPaneSplitViewState", |
| 442 "sourcesPanelDebuggerSidebarSplitViewState": "sourcesPanelDebuggerSi
debarSplitViewState" | 467 "sourcesPanelDebuggerSidebarSplitViewState": "sourcesPanelDebuggerSi
debarSplitViewState" |
| 443 }; | 468 }; |
| 444 | 469 |
| 470 var empty = {}; |
| 445 for (var name in settingNames) { | 471 for (var name in settingNames) { |
| 446 if (!(name in window.localStorage)) | 472 var setting = WebInspector.settings.createSetting(name, empty); |
| 447 continue; | |
| 448 var setting = WebInspector.settings.createSetting(name, undefined); | |
| 449 var value = setting.get(); | 473 var value = setting.get(); |
| 450 if (!value) | 474 if (value === empty) |
| 451 continue; | 475 continue; |
| 452 // Zero out saved percentage sizes, and they will be restored to def
aults. | 476 // Zero out saved percentage sizes, and they will be restored to def
aults. |
| 453 if (value.vertical && value.vertical.size && value.vertical.size < 1
) | 477 if (value.vertical && value.vertical.size && value.vertical.size < 1
) |
| 454 value.vertical.size = 0; | 478 value.vertical.size = 0; |
| 455 if (value.horizontal && value.horizontal.size && value.horizontal.si
ze < 1) | 479 if (value.horizontal && value.horizontal.size && value.horizontal.si
ze < 1) |
| 456 value.horizontal.size = 0; | 480 value.horizontal.size = 0; |
| 457 setting.set(value); | 481 setting.set(value); |
| 458 } | 482 } |
| 459 }, | 483 }, |
| 460 | 484 |
| 461 _updateVersionFrom7To8: function() | 485 _updateVersionFrom7To8: function() |
| 462 { | 486 { |
| 463 var settingName = "deviceMetrics"; | |
| 464 if (!window.localStorage || !(settingName in window.localStorage)) | |
| 465 return; | |
| 466 var setting = WebInspector.settings.createSetting(settingName, undefined
); | |
| 467 var value = setting.get(); | |
| 468 if (!value) | |
| 469 return; | |
| 470 | |
| 471 var components = value.split("x"); | |
| 472 if (components.length >= 3) { | |
| 473 var width = parseInt(components[0], 10); | |
| 474 var height = parseInt(components[1], 10); | |
| 475 var deviceScaleFactor = parseFloat(components[2]); | |
| 476 if (deviceScaleFactor) { | |
| 477 components[0] = "" + Math.round(width / deviceScaleFactor); | |
| 478 components[1] = "" + Math.round(height / deviceScaleFactor); | |
| 479 } | |
| 480 } | |
| 481 value = components.join("x"); | |
| 482 setting.set(value); | |
| 483 }, | 487 }, |
| 484 | 488 |
| 485 _updateVersionFrom8To9: function() | 489 _updateVersionFrom8To9: function() |
| 486 { | 490 { |
| 487 if (!window.localStorage) | |
| 488 return; | |
| 489 | |
| 490 var settingNames = [ | 491 var settingNames = [ |
| 491 "skipStackFramesPattern", | 492 "skipStackFramesPattern", |
| 492 "workspaceFolderExcludePattern" | 493 "workspaceFolderExcludePattern" |
| 493 ]; | 494 ]; |
| 494 | 495 |
| 495 for (var i = 0; i < settingNames.length; ++i) { | 496 for (var i = 0; i < settingNames.length; ++i) { |
| 496 var settingName = settingNames[i]; | 497 var setting = WebInspector.settings.createSetting(settingNames[i], "
"); |
| 497 if (!(settingName in window.localStorage)) | 498 var value = setting.get(); |
| 498 continue; | 499 if (!value) |
| 499 try { | 500 return; |
| 500 var value = JSON.parse(window.localStorage[settingName]); | 501 if (typeof value === "string") |
| 501 if (!value) | 502 value = [value]; |
| 502 continue; | 503 for (var j = 0; j < value.length; ++j) { |
| 503 if (typeof value === "string") | 504 if (typeof value[j] === "string") |
| 504 value = [value]; | 505 value[j] = { pattern: value[j] }; |
| 505 for (var j = 0; j < value.length; ++j) { | |
| 506 if (typeof value[j] === "string") | |
| 507 value[j] = { pattern: value[j] }; | |
| 508 } | |
| 509 window.localStorage[settingName] = JSON.stringify(value); | |
| 510 } catch(e) { | |
| 511 } | 506 } |
| 507 setting.set(value); |
| 512 } | 508 } |
| 513 }, | 509 }, |
| 514 | 510 |
| 515 _updateVersionFrom9To10: function() | 511 _updateVersionFrom9To10: function() |
| 516 { | 512 { |
| 513 // This one is localStorage specific, which is fine. |
| 517 if (!window.localStorage) | 514 if (!window.localStorage) |
| 518 return; | 515 return; |
| 519 | |
| 520 for (var key in window.localStorage) { | 516 for (var key in window.localStorage) { |
| 521 if (key.startsWith("revision-history")) | 517 if (key.startsWith("revision-history")) |
| 522 window.localStorage.removeItem(key); | 518 window.localStorage.removeItem(key); |
| 523 } | 519 } |
| 524 }, | 520 }, |
| 525 | 521 |
| 526 _updateVersionFrom10To11: function() | 522 _updateVersionFrom10To11: function() |
| 527 { | 523 { |
| 528 var setting = "customDevicePresets"; | 524 var oldSettingName = "customDevicePresets"; |
| 529 var newSetting = "customEmulatedDeviceList"; | 525 var newSettingName = "customEmulatedDeviceList"; |
| 526 var oldSetting = WebInspector.settings.createSetting(oldSettingName, und
efined); |
| 527 var list = oldSetting.get(); |
| 528 if (!Array.isArray(list)) |
| 529 return; |
| 530 var newList = []; |
| 531 for (var i = 0; i < list.length; ++i) { |
| 532 var value = list[i]; |
| 533 var device = {}; |
| 534 device["title"] = value["title"]; |
| 535 device["type"] = "unknown"; |
| 536 device["user-agent"] = value["userAgent"]; |
| 537 device["capabilities"] = []; |
| 538 if (value["touch"]) |
| 539 device["capabilities"].push("touch"); |
| 540 if (value["mobile"]) |
| 541 device["capabilities"].push("mobile"); |
| 542 device["screen"] = {}; |
| 543 device["screen"]["vertical"] = {width: value["width"], height: value
["height"]}; |
| 544 device["screen"]["horizontal"] = {width: value["height"], height: va
lue["width"]}; |
| 545 device["screen"]["device-pixel-ratio"] = value["deviceScaleFactor"]; |
| 546 device["modes"] = []; |
| 547 device["show-by-default"] = true; |
| 548 device["show"] = "Default"; |
| 549 newList.push(device); |
| 550 } |
| 551 if (newList.length) |
| 552 WebInspector.settings.createSetting(newSettingName, []).set(newList)
; |
| 553 oldSetting.remove(); |
| 554 }, |
| 555 |
| 556 _updateVersionFrom11To12: function() |
| 557 { |
| 558 // This step migrates all the settings except for the ones below into th
e browser profile. |
| 559 var localSettings = [ "advancedSearchConfig", "breakpoints", "consoleHis
tory", "domBreakpoints", "eventListenerBreakpoints", |
| 560 "fileSystemMapping", "lastSelectedSourcesSidebarPa
neTab", "previouslyViewedFiles", |
| 561 "savedURLs", "watchExpressions", "workspaceExclude
dFolders", "xhrBreakpoints" ].keySet(); |
| 530 if (!window.localStorage) | 562 if (!window.localStorage) |
| 531 return; | 563 return; |
| 532 if (!(setting in window.localStorage)) | 564 |
| 533 return; | 565 for (var key in window.localStorage) { |
| 534 try { | 566 if (key in localSettings) |
| 535 var list = JSON.parse(window.localStorage[setting]); | 567 continue; |
| 536 if (!Array.isArray(list)) | 568 var value = window.localStorage[key]; |
| 537 return; | 569 window.localStorage.removeItem(key); |
| 538 var newList = []; | 570 WebInspector.settings._settingsStorage[key] = value; |
| 539 for (var i = 0; i < list.length; ++i) { | |
| 540 var value = list[i]; | |
| 541 var device = {}; | |
| 542 device["title"] = value["title"]; | |
| 543 device["type"] = "unknown"; | |
| 544 device["user-agent"] = value["userAgent"]; | |
| 545 device["capabilities"] = []; | |
| 546 if (value["touch"]) | |
| 547 device["capabilities"].push("touch"); | |
| 548 if (value["mobile"]) | |
| 549 device["capabilities"].push("mobile"); | |
| 550 device["screen"] = {}; | |
| 551 device["screen"]["vertical"] = {width: value["width"], height: v
alue["height"]}; | |
| 552 device["screen"]["horizontal"] = {width: value["height"], height
: value["width"]}; | |
| 553 device["screen"]["device-pixel-ratio"] = value["deviceScaleFacto
r"]; | |
| 554 device["modes"] = []; | |
| 555 device["show-by-default"] = true; | |
| 556 device["show"] = "Default"; | |
| 557 newList.push(device); | |
| 558 } | |
| 559 window.localStorage[newSetting] = JSON.stringify(newList); | |
| 560 delete window.localStorage[setting]; | |
| 561 } catch(e) { | |
| 562 } | 571 } |
| 563 }, | 572 }, |
| 564 | 573 |
| 565 /** | 574 /** |
| 566 * @param {!WebInspector.Setting} breakpointsSetting | 575 * @param {!WebInspector.Setting} breakpointsSetting |
| 567 * @param {number} maxBreakpointsCount | 576 * @param {number} maxBreakpointsCount |
| 568 */ | 577 */ |
| 569 _clearBreakpointsWhenTooMany: function(breakpointsSetting, maxBreakpointsCou
nt) | 578 _clearBreakpointsWhenTooMany: function(breakpointsSetting, maxBreakpointsCou
nt) |
| 570 { | 579 { |
| 571 // If there are too many breakpoints in a storage, it is likely due to a
recent bug that caused | 580 // If there are too many breakpoints in a storage, it is likely due to a
recent bug that caused |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 } | 674 } |
| 666 | 675 |
| 667 /** | 676 /** |
| 668 * @param {string} settingName | 677 * @param {string} settingName |
| 669 * @return {!WebInspector.Setting} | 678 * @return {!WebInspector.Setting} |
| 670 */ | 679 */ |
| 671 WebInspector.settingForTest = function(settingName) | 680 WebInspector.settingForTest = function(settingName) |
| 672 { | 681 { |
| 673 return WebInspector.settings.settingForTest(settingName); | 682 return WebInspector.settings.settingForTest(settingName); |
| 674 } | 683 } |
| OLD | NEW |