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

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: Patch for landing may be! :) 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
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.getDOMStorageItemValue(this._domStorage.id, this._key, v alueReceived.bind(this));
153
154 /**
155 * @param {?Protocol.Error} error
156 * @param {string=} value
157 */
158 function valueReceived(error, value)
159 {
160 this._value = value;
apavlov 2013/08/05 09:53:00 Ugh... hm... this doesn't handle the error, it see
vivekg__ 2013/08/05 10:16:58 Oops had missed this one. Sorry! Corrected now!
161 this.redo();
162 callback();
163 }
164 },
165
166 /**
167 * @override
168 */
169 undo: function()
170 {
171 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value);
172 },
173
174 /**
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 * @extends {WebInspector.DOMStorageAction}
188 * @param {WebInspector.DOMStorage} domStorage
189 * @param {string} key
190 * @param {string} value
191 */
192 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value)
193 {
194 WebInspector.DOMStorageAction.call(this, domStorage);
195 this._key = key;
196 this._value = value;
197 }
198
199 WebInspector.DOMStorageSetItemAction.prototype = {
200 /**
201 * @override
202 */
203 perform: function(callback)
204 {
205 DOMStorageAgent.getDOMStorageItemValue(this._domStorage.id, this._key, v alueReceived.bind(this));
206
207 /**
208 * @param {?Protocol.Error} error
209 * @param {string=} value
210 */
211 function valueReceived(error, value)
212 {
213 if (error)
214 return;
apavlov 2013/08/05 09:53:00 So, you are leaving the callback to hang around fo
vivekg__ 2013/08/05 10:16:58 The history only processes the action only upon co
215
216 if (typeof value === "undefined")
217 delete this._exists;
218 else {
219 this._exists = true;
220 this._oldValue = value;
221 }
222 this.redo();
223 callback();
224 }
225 },
226
227 /**
228 * @override
229 */
230 undo: function()
231 {
232 if (!this._exists)
233 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key) ;
234 else
235 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, th is._oldValue);
236 },
237
238 /**
239 * @override
240 */
241 redo: function()
242 {
243 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value);
244 },
245
246 __proto__: WebInspector.DOMStorageAction.prototype
247 }
248
249 /**
250 * @constructor
251 * @param {WebInspector.DOMStorage} domStorage
252 */
253 WebInspector.DOMStorageHistory = function(domStorage)
254 {
255 this._domStorage = domStorage;
256
257 /** @type {!Array.<!WebInspector.DOMStorageAction>} */
258 this._actions = [];
259 this._redoableActionIndex = -1;
260 }
261
262 WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH = 20;
263
264 WebInspector.DOMStorageHistory.prototype = {
265 /**
266 * @param {WebInspector.DOMStorageAction} action
267 */
268 perform: function(action)
269 {
270 if (!action)
271 return;
272
273 action.perform(actionCompleted.bind(this));
274 function actionCompleted()
275 {
276 if (this._redoableActionIndex + 1 === WebInspector.DOMStorageHistory .MAX_UNDO_STACK_DEPTH) {
277 this._actions.shift();
278 --this._redoableActionIndex;
279 } else if (this._redoableActionIndex + 1 < this._actions.length)
280 this._actions.splice(this._redoableActionIndex + 1);
281
282 this._actions.push(action);
283 ++this._redoableActionIndex;
284 }
285 },
286
287 undo: function()
288 {
289 if (this._redoableActionIndex < 0)
apavlov 2013/08/05 09:53:00 ugh... I got confused by the naming, sorry. This s
vivekg__ 2013/08/05 10:16:58 Done.
290 return;
291
292 var action = this._actions[this._redoableActionIndex];
293 console.assert(action);
294 action.undo();
295 --this._redoableActionIndex;
296 },
297
298 redo: function()
299 {
300 if (this._redoableActionIndex >= this._actions.length - 1)
301 return;
302
303 var action = this._actions[++this._redoableActionIndex];
apavlov 2013/08/05 09:53:00 This confirms the previous comment. In order to re
vivekg__ 2013/08/05 10:16:58 Done.
304 console.assert(action);
305 action.redo();
306 }
307 }
308
97 /** 309 /**
98 * @constructor 310 * @constructor
99 * @extends {WebInspector.Object} 311 * @extends {WebInspector.Object}
100 */ 312 */
101 WebInspector.DOMStorageModel = function() 313 WebInspector.DOMStorageModel = function()
102 { 314 {
103 this._storages = {}; 315 this._storages = {};
104 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); 316 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this));
105 DOMStorageAgent.enable(); 317 DOMStorageAgent.enable();
106 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 318 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) 509 domStorageItemUpdated: function(storageId, key, oldValue, newValue)
298 { 510 {
299 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); 511 this._model._domStorageItemUpdated(storageId, key, oldValue, newValue);
300 }, 512 },
301 } 513 }
302 514
303 /** 515 /**
304 * @type {WebInspector.DOMStorageModel} 516 * @type {WebInspector.DOMStorageModel}
305 */ 517 */
306 WebInspector.domStorageModel = null; 518 WebInspector.domStorageModel = null;
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorDOMStorageAgent.cpp ('k') | Source/devtools/front_end/DOMStorageItemsView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698