Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Side by Side Diff: Source/devtools/front_end/DOMStorage.js

Issue 21163003: DevTools: Implement undo, redo operations for the DOMStorage views. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
apavlov 2013/08/02 08:16:59 ! is not required for non-object types (and is the
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()} callback
apavlov 2013/08/02 08:16:59 With @override, you can omit other annotations alt
150 */
151 perform: function(callback)
152 {
153 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueR eceived.bind(this));
154
155 /**
156 * @param {?Protocol.Error} error
157 * @param {string=} value
158 */
159 function valueReceived(error, value)
160 {
161 this._value = value;
162 this.redo();
163 callback();
164 }
165 },
166
167 /**
168 * @override
169 */
170 undo: function()
171 {
172 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value);
173 },
174
175 /**
176 * @override
177 */
178 redo: function()
179 {
180 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key);
181 },
182
183 __proto__: WebInspector.DOMStorageAction.prototype
184 }
185
186 /**
187 * @constructor
188 * @extends {WebInspector.DOMStorageAction}
189 * @param {!WebInspector.DOMStorage} domStorage
190 * @param {!string} key
apavlov 2013/08/02 08:16:59 ditto for !
191 * @param {!string} value
192 */
193 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value)
194 {
195 WebInspector.DOMStorageAction.call(this, domStorage);
196 this._key = key;
197 this._value = value;
198 }
199
200 WebInspector.DOMStorageSetItemAction.prototype = {
201 /**
202 * @override
203 * @param {function(): void} callback
apavlov 2013/08/02 08:16:59 ditto for JsDoc
204 */
205 perform: function(callback)
206 {
207 DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueR eceived.bind(this));
208
209 /**
210 * @param {?Protocol.Error} error
211 * @param {string=} value
212 */
213 function valueReceived(error, value)
214 {
215 if (typeof value === 'undefined' || value === null) {
apavlov 2013/08/02 08:16:59 double-quotes, please. Also, you can never get "nu
216 this._exists = false;
apavlov 2013/08/02 08:16:59 this can be "delete this._exists"
217 } else {
218 this._exists = true;
219 this._oldValue = value;
220 }
221 this.redo();
222 callback();
223 }
224 },
225
226 /**
227 * @override
228 */
229 undo: function()
230 {
231 if (!this._exists)
232 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key) ;
233 else
234 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, th is._oldValue);
235 },
236
237 /**
238 * @override
239 */
240 redo: function()
241 {
242 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value);
243 },
244
245 __proto__: WebInspector.DOMStorageAction.prototype
246 }
247
248 /**
249 * @constructor
250 * @param {WebInspector.DOMStorage} domStorage
251 */
252 WebInspector.DOMStorageHistory = function(domStorage)
253 {
254 this._domStorage = domStorage;
255 this._actions = [];
256 this._currentActionIndex = -1;
257 }
258
259 WebInspector.DOMStorageHistory.prototype = {
260 /**
261 * @param {WebInspector.DOMStorageAction} action
262 */
263 perform: function(action)
264 {
265 if (!action)
266 return;
267
268 action.perform(actionCompleted.bind(this));
269 function actionCompleted()
270 {
271 this._actions.push(action);
272 ++this._currentActionIndex;
273 }
274 },
275
276 undo: function()
277 {
278 if (this._currentActionIndex < 0)
279 return;
280
281 var action = this._actions[this._currentActionIndex];
282 console.assert(action);
283 action.undo();
284 --this._currentActionIndex;
285 },
286
287 redo: function()
288 {
289 if (this._currentActionIndex >= this._actions.length - 1)
290 return;
291
292 var action = this._actions[++this._currentActionIndex];
293 console.assert(action);
294 action.redo();
295 }
296 }
297
97 /** 298 /**
98 * @constructor 299 * @constructor
99 * @extends {WebInspector.Object} 300 * @extends {WebInspector.Object}
100 */ 301 */
101 WebInspector.DOMStorageModel = function() 302 WebInspector.DOMStorageModel = function()
102 { 303 {
103 this._storages = {}; 304 this._storages = {};
104 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); 305 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this));
105 DOMStorageAgent.enable(); 306 DOMStorageAgent.enable();
106 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 307 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 domStorageItemUpdated: function(storageId, key, oldValue, newValue) 498 domStorageItemUpdated: function(storageId, key, oldValue, newValue)
298 { 499 {
299 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); 500 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue);
300 }, 501 },
301 } 502 }
302 503
303 /** 504 /**
304 * @type {WebInspector.DOMStorageModel} 505 * @type {WebInspector.DOMStorageModel}
305 */ 506 */
306 WebInspector.domStorageModel = null; 507 WebInspector.domStorageModel = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698