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 | |
apavlov
2013/07/31 12:51:35
This should be @interface instead
| |
110 * @param {WebInspector.DOMStorage} domStorage | |
111 */ | |
112 WebInspector.DOMStorageAction = function(domStorage) | |
113 { | |
114 this._domStorage = domStorage; | |
115 } | |
116 | |
117 WebInspector.DOMStorageAction.prototype = { | |
118 perform: function(callback) | |
apavlov
2013/07/31 12:51:35
callback should be annotated using @param
| |
119 { | |
120 }, | |
121 | |
122 undo: function() | |
123 { | |
124 }, | |
125 | |
126 redo: function() | |
127 { | |
128 } | |
129 } | |
130 | |
131 /** | |
132 * @constructor | |
133 * @param {WebInspector.DOMStorage} domStorage | |
apavlov
2013/07/31 12:51:35
also add the @implements annotation
| |
134 * @param {string} key | |
135 * @extends {WebInspector.DOMStorageAction} | |
apavlov
2013/07/31 12:51:35
this should be removed
| |
136 */ | |
137 WebInspector.DOMStorageRemoveItemAction = function(domStorage, key) | |
138 { | |
139 WebInspector.DOMStorageAction.call(this, domStorage); | |
140 this._key = key; | |
141 } | |
142 | |
143 WebInspector.DOMStorageRemoveItemAction.prototype = { | |
144 __proto__: WebInspector.DOMStorageAction.prototype, | |
apavlov
2013/07/31 12:51:35
We usually put these last in the prototype definit
| |
145 | |
146 perform: function(callback) | |
147 { | |
148 function valueReceived(error, exists, value) | |
149 { | |
150 this._exists = exists; | |
151 this._value = value; | |
152 this.redo(); | |
153 callback(); | |
154 } | |
155 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueR eceived.bind(this)); | |
156 }, | |
157 | |
158 undo: function() | |
159 { | |
160 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value); | |
161 }, | |
162 | |
163 redo: function() | |
164 { | |
165 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); | |
166 } | |
167 } | |
168 | |
169 /** | |
170 * @constructor | |
apavlov
2013/07/31 12:51:35
ditto re @implements
| |
171 * @param {WebInspector.DOMStorage} domStorage | |
172 * @param {string} key | |
173 * @extends {WebInspector.DOMStorageAction} | |
174 */ | |
175 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value) | |
176 { | |
177 WebInspector.DOMStorageAction.call(this, domStorage); | |
178 this._key = key; | |
179 this._value = value; | |
180 } | |
181 | |
182 WebInspector.DOMStorageSetItemAction.prototype = { | |
183 __proto__: WebInspector.DOMStorageAction.prototype, | |
184 | |
185 perform: function(callback) | |
apavlov
2013/07/31 12:51:35
JsDoc (perhaps just @inherit)
| |
186 { | |
187 function valueReceived(error, exists, value) | |
188 { | |
189 this._exists = exists; | |
190 this._oldValue = value; | |
191 this.redo(); | |
192 callback(); | |
193 } | |
194 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueR eceived.bind(this)); | |
195 }, | |
196 | |
197 undo: function() | |
198 { | |
199 if (this._exists) | |
200 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, th is._oldValue); | |
201 else | |
202 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key) ; | |
203 }, | |
204 | |
205 redo: function() | |
206 { | |
207 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value); | |
208 } | |
209 } | |
210 | |
211 /** | |
212 * @constructor | |
213 */ | |
214 WebInspector.DOMStorageHistory = function(domStorage) | |
apavlov
2013/07/31 12:51:35
JsDoc for domStorage
| |
215 { | |
216 this._domStorage = domStorage; | |
217 this._actions = []; | |
218 this._currentActionIndex = -1; | |
219 } | |
220 | |
221 WebInspector.DOMStorageHistory.prototype = { | |
222 perform: function(action) | |
apavlov
2013/07/31 12:51:35
JsDoc
| |
223 { | |
224 if (!action) | |
225 return; | |
226 | |
227 action.perform(function() { | |
228 this._actions.push(action); | |
229 ++this._currentActionIndex; | |
230 }.bind(this)); | |
231 }, | |
232 | |
233 undo: function() | |
234 { | |
235 if (this._currentActionIndex < 0) | |
236 return; | |
237 | |
238 var action = this._actions[this._currentActionIndex]; | |
239 if (action) | |
apavlov
2013/07/31 12:51:35
I believe you should console.assert(action) here,
| |
240 action.undo(); | |
241 --this._currentActionIndex; | |
242 }, | |
243 | |
244 redo: function() | |
245 { | |
246 if (this._currentActionIndex > this._actions.length) | |
247 return; | |
248 | |
249 var action = this._actions[++this._currentActionIndex]; | |
250 if (action) | |
apavlov
2013/07/31 12:51:35
I believe you should console.assert(action) here,
| |
251 action.redo(); | |
252 } | |
253 } | |
254 | |
97 /** | 255 /** |
98 * @constructor | 256 * @constructor |
99 * @extends {WebInspector.Object} | 257 * @extends {WebInspector.Object} |
100 */ | 258 */ |
101 WebInspector.DOMStorageModel = function() | 259 WebInspector.DOMStorageModel = function() |
102 { | 260 { |
103 this._storages = {}; | 261 this._storages = {}; |
104 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); | 262 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); |
105 DOMStorageAgent.enable(); | 263 DOMStorageAgent.enable(); |
106 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 264 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) | 455 domStorageItemUpdated: function(storageId, key, oldValue, newValue) |
298 { | 456 { |
299 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); | 457 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); |
300 }, | 458 }, |
301 } | 459 } |
302 | 460 |
303 /** | 461 /** |
304 * @type {WebInspector.DOMStorageModel} | 462 * @type {WebInspector.DOMStorageModel} |
305 */ | 463 */ |
306 WebInspector.domStorageModel = null; | 464 WebInspector.domStorageModel = null; |
OLD | NEW |