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 23 matching lines...) Expand all Loading... | |
72 * @param {function(?Protocol.Error, Array.<DOMStorageAgent.Item>):void=} ca llback | 73 * @param {function(?Protocol.Error, Array.<DOMStorageAgent.Item>):void=} ca llback |
73 */ | 74 */ |
74 getItems: function(callback) | 75 getItems: function(callback) |
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 * @param {function(?Protocol.Error):void=} callback | |
83 */ | 83 */ |
84 setItem: function(key, value, callback) | 84 setItem: function(key, value) |
85 { | 85 { |
86 DOMStorageAgent.setDOMStorageItem(this.id, key, value, callback); | 86 this._storageHistory.perform(new WebInspector.DOMStorageSetItemAction(th is, key, value)); |
87 }, | 87 }, |
88 | 88 |
89 /** | 89 /** |
90 * @param {string} key | 90 * @param {string} key |
91 * @param {function(?Protocol.Error):void=} callback | |
92 */ | 91 */ |
93 removeItem: function(key, callback) | 92 removeItem: function(key) |
94 { | 93 { |
95 DOMStorageAgent.removeDOMStorageItem(this.id, key, callback); | 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(); | |
96 } | 105 } |
97 } | 106 } |
98 | 107 |
108 /** | |
109 * @constructor | |
110 */ | |
111 WebInspector.DOMStorageAction = function(domStorage) | |
apavlov
2013/05/08 11:41:36
I would defer the decision on this to pfeldman, bu
| |
112 { | |
113 this._domStorage = domStorage; | |
114 } | |
115 | |
116 WebInspector.DOMStorageAction.prototype = { | |
117 perform: function() | |
118 { | |
119 }, | |
120 | |
121 undo: function() | |
122 { | |
123 }, | |
124 | |
125 redo: function() | |
126 { | |
127 } | |
128 } | |
129 | |
130 WebInspector.DOMStorageRemoveItemAction = function(domStorage, key) | |
131 { | |
132 WebInspector.DOMStorageAction.call(this, domStorage); | |
133 this._key = key; | |
134 } | |
135 | |
136 WebInspector.DOMStorageRemoveItemAction.prototype = { | |
137 __proto__: WebInspector.DOMStorageAction.prototype, | |
138 | |
139 perform: function() | |
140 { | |
141 function callback(error, value) | |
142 { | |
143 this._value = value; | |
144 this.redo(); | |
145 } | |
146 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, callba ck.bind(this)); | |
147 }, | |
148 | |
149 undo: function() | |
150 { | |
151 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value); | |
152 }, | |
153 | |
154 redo: function() | |
155 { | |
156 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); | |
157 } | |
158 } | |
159 | |
160 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value) | |
161 { | |
162 WebInspector.DOMStorageAction.call(this, domStorage); | |
163 this._key = key; | |
164 this._value = value; | |
165 } | |
166 | |
167 WebInspector.DOMStorageSetItemAction.prototype = { | |
168 __proto__: WebInspector.DOMStorageAction.prototype, | |
169 | |
170 perform: function() | |
171 { | |
172 function callback(error, value) | |
173 { | |
174 this._oldValue = value; | |
175 this.redo(); | |
176 } | |
177 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, callba ck.bind(this)); | |
178 }, | |
179 | |
180 undo: function() | |
181 { | |
182 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ oldValue); | |
183 }, | |
184 | |
185 redo: function() | |
186 { | |
187 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value); | |
188 } | |
189 } | |
190 | |
191 /** | |
192 * @constructor | |
193 */ | |
194 WebInspector.DOMStorageHistory = function(domStorage) | |
195 { | |
196 this._domStorage = domStorage; | |
197 this._actions = []; | |
198 this._currentActionIndex = -1; | |
199 } | |
200 | |
201 WebInspector.DOMStorageHistory.prototype = { | |
202 perform: function(action) | |
203 { | |
204 if (!action) | |
205 return; | |
206 | |
207 action.perform(); | |
208 | |
209 this._actions.push(action); | |
210 ++this._currentActionIndex; | |
211 }, | |
212 | |
213 undo: function() | |
214 { | |
215 if (this._currentActionIndex < 0) | |
216 return; | |
217 | |
218 var action = this._actions[this._currentActionIndex]; | |
219 if (action) | |
220 action.undo(); | |
221 --this._currentActionIndex; | |
222 }, | |
223 | |
224 redo: function() | |
225 { | |
226 if (this._currentActionIndex > this._actions.length) | |
227 return; | |
228 | |
229 var action = this._actions[++this._currentActionIndex]; | |
230 if (action) | |
231 action.redo(); | |
232 } | |
233 } | |
234 | |
99 /** | 235 /** |
100 * @constructor | 236 * @constructor |
101 * @extends {WebInspector.Object} | 237 * @extends {WebInspector.Object} |
102 */ | 238 */ |
103 WebInspector.DOMStorageModel = function() | 239 WebInspector.DOMStorageModel = function() |
104 { | 240 { |
105 this._storages = {}; | 241 this._storages = {}; |
106 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); | 242 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); |
107 DOMStorageAgent.enable(); | 243 DOMStorageAgent.enable(); |
108 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 244 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 domStorageItemUpdated: function(storageId, key, oldValue, newValue) | 435 domStorageItemUpdated: function(storageId, key, oldValue, newValue) |
300 { | 436 { |
301 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); | 437 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); |
302 }, | 438 }, |
303 } | 439 } |
304 | 440 |
305 /** | 441 /** |
306 * @type {WebInspector.DOMStorageModel} | 442 * @type {WebInspector.DOMStorageModel} |
307 */ | 443 */ |
308 WebInspector.domStorageModel = null; | 444 WebInspector.domStorageModel = null; |
OLD | NEW |