Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Nokia Inc. All rights reserved. | 2 * Copyright (C) 2008 Nokia Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * @constructor | 31 * @constructor |
| 32 * @param {string} securityOrigin | 32 * @param {string} securityOrigin |
| 33 * @param {boolean} isLocalStorage | 33 * @param {boolean} isLocalStorage |
| 34 */ | 34 */ |
| 35 WebInspector.DOMStorage = function(securityOrigin, isLocalStorage) | 35 WebInspector.DOMStorage = function(securityOrigin, isLocalStorage) |
| 36 { | 36 { |
| 37 this._securityOrigin = securityOrigin; | 37 this._securityOrigin = securityOrigin; |
| 38 this._isLocalStorage = isLocalStorage; | 38 this._isLocalStorage = isLocalStorage; |
| 39 this._storageHistory = new WebInspector.DOMStorageHistory(this); | |
| 39 } | 40 } |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * @param {string} securityOrigin | 43 * @param {string} securityOrigin |
| 43 * @param {boolean} isLocalStorage | 44 * @param {boolean} isLocalStorage |
| 44 * @return {DOMStorageAgent.StorageId} | 45 * @return {DOMStorageAgent.StorageId} |
| 45 */ | 46 */ |
| 46 WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage) | 47 WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage) |
| 47 { | 48 { |
| 48 return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage }; | 49 return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage }; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 75 { | 76 { |
| 76 DOMStorageAgent.getDOMStorageItems(this.id, callback); | 77 DOMStorageAgent.getDOMStorageItems(this.id, callback); |
| 77 }, | 78 }, |
| 78 | 79 |
| 79 /** | 80 /** |
| 80 * @param {string} key | 81 * @param {string} key |
| 81 * @param {string} value | 82 * @param {string} value |
| 82 */ | 83 */ |
| 83 setItem: function(key, value) | 84 setItem: function(key, value) |
| 84 { | 85 { |
| 85 DOMStorageAgent.setDOMStorageItem(this.id, key, value); | 86 this._storageHistory.perform(new WebInspector.DOMStorageSetItemAction(th is, key, value)); |
| 86 }, | 87 }, |
| 87 | 88 |
| 88 /** | 89 /** |
| 89 * @param {string} key | 90 * @param {string} key |
| 90 */ | 91 */ |
| 91 removeItem: function(key) | 92 removeItem: function(key) |
| 92 { | 93 { |
| 93 DOMStorageAgent.removeDOMStorageItem(this.id, key); | 94 this._storageHistory.perform(new WebInspector.DOMStorageRemoveItemAction (this, key)); |
| 95 }, | |
| 96 | |
| 97 undo: function() | |
| 98 { | |
| 99 this._storageHistory.undo(); | |
| 100 }, | |
| 101 | |
| 102 redo: function() | |
| 103 { | |
| 104 this._storageHistory.redo(); | |
| 94 } | 105 } |
| 95 } | 106 } |
| 96 | 107 |
| 108 /** | |
| 109 * @constructor | |
| 110 * @param {WebInspector.DOMStorage} domStorage | |
| 111 */ | |
| 112 WebInspector.DOMStorageAction = function(domStorage) | |
| 113 { | |
| 114 this._domStorage = domStorage; | |
| 115 } | |
| 116 | |
| 117 WebInspector.DOMStorageAction.prototype = { | |
| 118 /** | |
| 119 * @param {function(): void} callback | |
|
apavlov
2013/08/01 09:19:16
we typically omit "void" in signatures. In fact, i
| |
| 120 */ | |
| 121 perform: function(callback) | |
| 122 { | |
| 123 }, | |
| 124 | |
| 125 undo: function() | |
| 126 { | |
| 127 }, | |
| 128 | |
| 129 redo: function() | |
| 130 { | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 /** | |
| 135 * @constructor | |
| 136 * @param {!WebInspector.DOMStorage} domStorage | |
| 137 * @param {!string} key | |
| 138 * @extends {WebInspector.DOMStorageAction} | |
|
apavlov
2013/08/01 09:19:16
@extends should immediately follow @constructor fo
| |
| 139 */ | |
| 140 WebInspector.DOMStorageRemoveItemAction = function(domStorage, key) | |
| 141 { | |
| 142 WebInspector.DOMStorageAction.call(this, domStorage); | |
| 143 this._key = key; | |
| 144 } | |
| 145 | |
| 146 WebInspector.DOMStorageRemoveItemAction.prototype = { | |
| 147 /** | |
| 148 * @override | |
| 149 * @param {function(): void} callback | |
|
apavlov
2013/08/01 09:19:16
ditto re void (and more below)
| |
| 150 */ | |
| 151 perform: function(callback) | |
| 152 { | |
| 153 /** | |
| 154 * @param {?Protocol.Error} error | |
| 155 * @param {string=} value | |
| 156 */ | |
| 157 function valueReceived(error, value) | |
| 158 { | |
| 159 this._value = value; | |
| 160 this.redo(); | |
| 161 callback(); | |
| 162 } | |
| 163 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueR eceived.bind(this)); | |
| 164 }, | |
| 165 | |
| 166 /* | |
|
apavlov
2013/08/01 09:19:16
/**
| |
| 167 * @override | |
| 168 */ | |
| 169 undo: function() | |
| 170 { | |
| 171 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value); | |
| 172 }, | |
| 173 | |
| 174 /* | |
|
apavlov
2013/08/01 09:19:16
/**
| |
| 175 * @override | |
| 176 */ | |
| 177 redo: function() | |
| 178 { | |
| 179 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); | |
| 180 }, | |
| 181 | |
| 182 __proto__: WebInspector.DOMStorageAction.prototype | |
| 183 } | |
| 184 | |
| 185 /** | |
| 186 * @constructor | |
| 187 * @param {WebInspector.DOMStorage} domStorage | |
| 188 * @param {string} key | |
| 189 * @extends {WebInspector.DOMStorageAction} | |
|
apavlov
2013/08/01 09:19:16
Please move next to @constructor
| |
| 190 */ | |
| 191 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value) | |
| 192 { | |
| 193 WebInspector.DOMStorageAction.call(this, domStorage); | |
| 194 this._key = key; | |
| 195 this._value = value; | |
| 196 } | |
| 197 | |
| 198 WebInspector.DOMStorageSetItemAction.prototype = { | |
| 199 /** | |
| 200 * @override | |
| 201 * @param {function(): void} callback | |
| 202 */ | |
| 203 perform: function(callback) | |
| 204 { | |
| 205 /** | |
| 206 * @param {?Protocol.Error} error | |
| 207 * @param {string=} value | |
| 208 */ | |
| 209 function valueReceived(error, value) | |
| 210 { | |
| 211 if (typeof value === 'undefined' || value === null) | |
| 212 this._exists = false; | |
| 213 else { | |
| 214 this._exists = true; | |
| 215 this._oldValue = value; | |
| 216 } | |
| 217 this.redo(); | |
| 218 callback(); | |
| 219 } | |
| 220 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueR eceived.bind(this)); | |
| 221 }, | |
| 222 | |
| 223 /* | |
|
apavlov
2013/08/01 09:19:16
/**
| |
| 224 * @override | |
| 225 */ | |
| 226 undo: function() | |
| 227 { | |
| 228 if (!this._exists) | |
| 229 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key) ; | |
| 230 else | |
| 231 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, th is._oldValue); | |
| 232 }, | |
| 233 | |
| 234 /* | |
|
apavlov
2013/08/01 09:19:16
/**
| |
| 235 * @override | |
| 236 */ | |
| 237 redo: function() | |
| 238 { | |
| 239 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value); | |
| 240 }, | |
| 241 | |
| 242 __proto__: WebInspector.DOMStorageAction.prototype | |
| 243 } | |
| 244 | |
| 245 /** | |
| 246 * @constructor | |
| 247 * @param {WebInspector.DOMStorage} domStorage | |
| 248 */ | |
| 249 WebInspector.DOMStorageHistory = function(domStorage) | |
| 250 { | |
| 251 this._domStorage = domStorage; | |
| 252 this._actions = []; | |
| 253 this._currentActionIndex = -1; | |
| 254 } | |
| 255 | |
| 256 WebInspector.DOMStorageHistory.prototype = { | |
| 257 /* | |
|
apavlov
2013/08/01 09:19:16
/**
| |
| 258 * @param {WebInspector.DOMStorageAction} action | |
| 259 */ | |
| 260 perform: function(action) | |
| 261 { | |
| 262 if (!action) | |
| 263 return; | |
| 264 | |
| 265 function completed() | |
| 266 { | |
| 267 this._actions.push(action); | |
| 268 ++this._currentActionIndex; | |
| 269 } | |
| 270 | |
| 271 action.perform(completed.bind(this)); | |
| 272 }, | |
| 273 | |
| 274 undo: function() | |
| 275 { | |
| 276 if (this._currentActionIndex < 0) | |
| 277 return; | |
| 278 | |
| 279 var action = this._actions[this._currentActionIndex]; | |
| 280 console.assert(action); | |
| 281 action.undo(); | |
| 282 --this._currentActionIndex; | |
| 283 }, | |
| 284 | |
| 285 redo: function() | |
| 286 { | |
| 287 if (this._currentActionIndex >= this._actions.length - 1) | |
| 288 return; | |
| 289 | |
| 290 var action = this._actions[++this._currentActionIndex]; | |
| 291 console.assert(action); | |
| 292 action.redo(); | |
| 293 } | |
| 294 } | |
| 295 | |
| 97 /** | 296 /** |
| 98 * @constructor | 297 * @constructor |
| 99 * @extends {WebInspector.Object} | 298 * @extends {WebInspector.Object} |
| 100 */ | 299 */ |
| 101 WebInspector.DOMStorageModel = function() | 300 WebInspector.DOMStorageModel = function() |
| 102 { | 301 { |
| 103 this._storages = {}; | 302 this._storages = {}; |
| 104 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); | 303 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); |
| 105 DOMStorageAgent.enable(); | 304 DOMStorageAgent.enable(); |
| 106 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 305 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 domStorageItemUpdated: function(storageId, key, oldValue, newValue) | 496 domStorageItemUpdated: function(storageId, key, oldValue, newValue) |
| 298 { | 497 { |
| 299 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); | 498 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); |
| 300 }, | 499 }, |
| 301 } | 500 } |
| 302 | 501 |
| 303 /** | 502 /** |
| 304 * @type {WebInspector.DOMStorageModel} | 503 * @type {WebInspector.DOMStorageModel} |
| 305 */ | 504 */ |
| 306 WebInspector.domStorageModel = null; | 505 WebInspector.domStorageModel = null; |
| OLD | NEW |