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()} callback |
| 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 * @extends {WebInspector.DOMStorageAction} |
| 137 * @param {WebInspector.DOMStorage} domStorage |
| 138 * @param {string} key |
| 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 */ |
| 150 perform: function(callback) |
| 151 { |
| 152 DOMStorageAgent.getValue(this._domStorage.id, this._key, valueReceived.b
ind(this)); |
| 153 |
| 154 /** |
| 155 * @param {?Protocol.Error} error |
| 156 * @param {string=} value |
| 157 */ |
| 158 function valueReceived(error, value) |
| 159 { |
| 160 if (error) |
| 161 return; |
| 162 |
| 163 this._value = value; |
| 164 this.redo(); |
| 165 callback(); |
| 166 } |
| 167 }, |
| 168 |
| 169 /** |
| 170 * @override |
| 171 */ |
| 172 undo: function() |
| 173 { |
| 174 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._
value); |
| 175 }, |
| 176 |
| 177 /** |
| 178 * @override |
| 179 */ |
| 180 redo: function() |
| 181 { |
| 182 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); |
| 183 }, |
| 184 |
| 185 __proto__: WebInspector.DOMStorageAction.prototype |
| 186 } |
| 187 |
| 188 /** |
| 189 * @constructor |
| 190 * @extends {WebInspector.DOMStorageAction} |
| 191 * @param {WebInspector.DOMStorage} domStorage |
| 192 * @param {string} key |
| 193 * @param {string} value |
| 194 */ |
| 195 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value) |
| 196 { |
| 197 WebInspector.DOMStorageAction.call(this, domStorage); |
| 198 this._key = key; |
| 199 this._value = value; |
| 200 } |
| 201 |
| 202 WebInspector.DOMStorageSetItemAction.prototype = { |
| 203 /** |
| 204 * @override |
| 205 */ |
| 206 perform: function(callback) |
| 207 { |
| 208 DOMStorageAgent.getValue(this._domStorage.id, this._key, valueReceived.b
ind(this)); |
| 209 |
| 210 /** |
| 211 * @param {?Protocol.Error} error |
| 212 * @param {string=} value |
| 213 */ |
| 214 function valueReceived(error, value) |
| 215 { |
| 216 if (error) |
| 217 return; |
| 218 |
| 219 if (typeof value === "undefined") |
| 220 delete this._exists; |
| 221 else { |
| 222 this._exists = true; |
| 223 this._oldValue = value; |
| 224 } |
| 225 this.redo(); |
| 226 callback(); |
| 227 } |
| 228 }, |
| 229 |
| 230 /** |
| 231 * @override |
| 232 */ |
| 233 undo: function() |
| 234 { |
| 235 if (!this._exists) |
| 236 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key)
; |
| 237 else |
| 238 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, th
is._oldValue); |
| 239 }, |
| 240 |
| 241 /** |
| 242 * @override |
| 243 */ |
| 244 redo: function() |
| 245 { |
| 246 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._
value); |
| 247 }, |
| 248 |
| 249 __proto__: WebInspector.DOMStorageAction.prototype |
| 250 } |
| 251 |
| 252 /** |
| 253 * @constructor |
| 254 * @param {WebInspector.DOMStorage} domStorage |
| 255 */ |
| 256 WebInspector.DOMStorageHistory = function(domStorage) |
| 257 { |
| 258 this._domStorage = domStorage; |
| 259 |
| 260 /** @type {!Array.<!WebInspector.DOMStorageAction>} */ |
| 261 this._actions = []; |
| 262 this._undoableActionIndex = -1; |
| 263 } |
| 264 |
| 265 WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH = 256; |
| 266 |
| 267 WebInspector.DOMStorageHistory.prototype = { |
| 268 /** |
| 269 * @param {WebInspector.DOMStorageAction} action |
| 270 */ |
| 271 perform: function(action) |
| 272 { |
| 273 if (!action) |
| 274 return; |
| 275 |
| 276 action.perform(actionCompleted.bind(this)); |
| 277 function actionCompleted() |
| 278 { |
| 279 if (this._undoableActionIndex + 1 === WebInspector.DOMStorageHistory
.MAX_UNDO_STACK_DEPTH) { |
| 280 this._actions.shift(); |
| 281 --this._undoableActionIndex; |
| 282 } else if (this._undoableActionIndex + 1 < this._actions.length) |
| 283 this._actions.splice(this._undoableActionIndex + 1); |
| 284 |
| 285 this._actions.push(action); |
| 286 ++this._undoableActionIndex; |
| 287 } |
| 288 }, |
| 289 |
| 290 undo: function() |
| 291 { |
| 292 if (this._undoableActionIndex < 0) |
| 293 return; |
| 294 |
| 295 var action = this._actions[this._undoableActionIndex]; |
| 296 console.assert(action); |
| 297 action.undo(); |
| 298 --this._undoableActionIndex; |
| 299 }, |
| 300 |
| 301 redo: function() |
| 302 { |
| 303 if (this._undoableActionIndex >= this._actions.length - 1) |
| 304 return; |
| 305 |
| 306 var action = this._actions[++this._undoableActionIndex]; |
| 307 console.assert(action); |
| 308 action.redo(); |
| 309 } |
| 310 } |
| 311 |
97 /** | 312 /** |
98 * @constructor | 313 * @constructor |
99 * @extends {WebInspector.Object} | 314 * @extends {WebInspector.Object} |
100 */ | 315 */ |
101 WebInspector.DOMStorageModel = function() | 316 WebInspector.DOMStorageModel = function() |
102 { | 317 { |
103 this._storages = {}; | 318 this._storages = {}; |
104 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis
patcher(this)); | 319 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis
patcher(this)); |
105 DOMStorageAgent.enable(); | 320 DOMStorageAgent.enable(); |
106 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 321 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) | 512 domStorageItemUpdated: function(storageId, key, oldValue, newValue) |
298 { | 513 { |
299 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); | 514 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); |
300 }, | 515 }, |
301 } | 516 } |
302 | 517 |
303 /** | 518 /** |
304 * @type {WebInspector.DOMStorageModel} | 519 * @type {WebInspector.DOMStorageModel} |
305 */ | 520 */ |
306 WebInspector.domStorageModel = null; | 521 WebInspector.domStorageModel = null; |
OLD | NEW |