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

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

Issue 23665003: DevTools: Revoke undo/redo due to inconsistent behavior determining the source of storage mutation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 19 matching lines...) Expand all
30 /** 30 /**
31 * @constructor 31 * @constructor
32 * @extends {WebInspector.Object} 32 * @extends {WebInspector.Object}
33 * @param {string} securityOrigin 33 * @param {string} securityOrigin
34 * @param {boolean} isLocalStorage 34 * @param {boolean} isLocalStorage
35 */ 35 */
36 WebInspector.DOMStorage = function(securityOrigin, isLocalStorage) 36 WebInspector.DOMStorage = function(securityOrigin, isLocalStorage)
37 { 37 {
38 this._securityOrigin = securityOrigin; 38 this._securityOrigin = securityOrigin;
39 this._isLocalStorage = isLocalStorage; 39 this._isLocalStorage = isLocalStorage;
40 this._storageHistory = new WebInspector.DOMStorageHistory(this);
41 } 40 }
42 41
43 /** 42 /**
44 * @param {string} securityOrigin 43 * @param {string} securityOrigin
45 * @param {boolean} isLocalStorage 44 * @param {boolean} isLocalStorage
46 * @return {DOMStorageAgent.StorageId} 45 * @return {DOMStorageAgent.StorageId}
47 */ 46 */
48 WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage) 47 WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage)
49 { 48 {
50 return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage }; 49 return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage };
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 { 83 {
85 DOMStorageAgent.getDOMStorageItems(this.id, callback); 84 DOMStorageAgent.getDOMStorageItems(this.id, callback);
86 }, 85 },
87 86
88 /** 87 /**
89 * @param {string} key 88 * @param {string} key
90 * @param {string} value 89 * @param {string} value
91 */ 90 */
92 setItem: function(key, value) 91 setItem: function(key, value)
93 { 92 {
94 this._storageHistory.perform(new WebInspector.DOMStorageSetItemAction(th is, key, value)); 93 DOMStorageAgent.setDOMStorageItem(this.id, key, value);
95 }, 94 },
96 95
97 /** 96 /**
98 * @param {string} key 97 * @param {string} key
99 */ 98 */
100 removeItem: function(key) 99 removeItem: function(key)
101 { 100 {
102 this._storageHistory.perform(new WebInspector.DOMStorageRemoveItemAction (this, key)); 101 DOMStorageAgent.removeDOMStorageItem(this.id, key);
103 },
104
105 undo: function()
106 {
107 this._storageHistory.undo();
108 },
109
110 redo: function()
111 {
112 this._storageHistory.redo();
113 }, 102 },
114 103
115 __proto__: WebInspector.Object.prototype 104 __proto__: WebInspector.Object.prototype
116 } 105 }
117 106
118 /** 107 /**
119 * @constructor 108 * @constructor
120 * @param {WebInspector.DOMStorage} domStorage
121 */
122 WebInspector.DOMStorageAction = function(domStorage)
123 {
124 this._domStorage = domStorage;
125 }
126
127 WebInspector.DOMStorageAction.prototype = {
128 /**
129 * @param {function()} callback
130 */
131 perform: function(callback)
132 {
133 },
134
135 undo: function()
136 {
137 },
138
139 redo: function()
140 {
141 }
142 }
143
144 /**
145 * @constructor
146 * @extends {WebInspector.DOMStorageAction}
147 * @param {WebInspector.DOMStorage} domStorage
148 * @param {string} key
149 */
150 WebInspector.DOMStorageRemoveItemAction = function(domStorage, key)
151 {
152 WebInspector.DOMStorageAction.call(this, domStorage);
153 this._key = key;
154 }
155
156 WebInspector.DOMStorageRemoveItemAction.prototype = {
157 /**
158 * @override
159 */
160 perform: function(callback)
161 {
162 DOMStorageAgent.getValue(this._domStorage.id, this._key, valueReceived.b ind(this));
163
164 /**
165 * @param {?Protocol.Error} error
166 * @param {string=} value
167 */
168 function valueReceived(error, value)
169 {
170 if (error)
171 return;
172
173 this._value = value;
174 this.redo();
175 callback();
176 }
177 },
178
179 /**
180 * @override
181 */
182 undo: function()
183 {
184 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value);
185 },
186
187 /**
188 * @override
189 */
190 redo: function()
191 {
192 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key);
193 },
194
195 __proto__: WebInspector.DOMStorageAction.prototype
196 }
197
198 /**
199 * @constructor
200 * @extends {WebInspector.DOMStorageAction}
201 * @param {WebInspector.DOMStorage} domStorage
202 * @param {string} key
203 * @param {string} value
204 */
205 WebInspector.DOMStorageSetItemAction = function(domStorage, key, value)
206 {
207 WebInspector.DOMStorageAction.call(this, domStorage);
208 this._key = key;
209 this._value = value;
210 }
211
212 WebInspector.DOMStorageSetItemAction.prototype = {
213 /**
214 * @override
215 */
216 perform: function(callback)
217 {
218 DOMStorageAgent.getValue(this._domStorage.id, this._key, valueReceived.b ind(this));
219
220 /**
221 * @param {?Protocol.Error} error
222 * @param {string=} value
223 */
224 function valueReceived(error, value)
225 {
226 if (error)
227 return;
228
229 if (typeof value === "undefined")
230 delete this._exists;
231 else {
232 this._exists = true;
233 this._oldValue = value;
234 }
235 this.redo();
236 callback();
237 }
238 },
239
240 /**
241 * @override
242 */
243 undo: function()
244 {
245 if (!this._exists)
246 DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key) ;
247 else
248 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, th is._oldValue);
249 },
250
251 /**
252 * @override
253 */
254 redo: function()
255 {
256 DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._ value);
257 },
258
259 __proto__: WebInspector.DOMStorageAction.prototype
260 }
261
262 /**
263 * @constructor
264 * @param {WebInspector.DOMStorage} domStorage
265 */
266 WebInspector.DOMStorageHistory = function(domStorage)
267 {
268 this._domStorage = domStorage;
269
270 /** @type {!Array.<!WebInspector.DOMStorageAction>} */
271 this._actions = [];
272 this._undoableActionIndex = -1;
273 }
274
275 WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH = 256;
276
277 WebInspector.DOMStorageHistory.prototype = {
278 /**
279 * @param {WebInspector.DOMStorageAction} action
280 */
281 perform: function(action)
282 {
283 if (!action)
284 return;
285
286 action.perform(actionCompleted.bind(this));
287 function actionCompleted()
288 {
289 if (this._undoableActionIndex + 1 === WebInspector.DOMStorageHistory .MAX_UNDO_STACK_DEPTH) {
290 this._actions.shift();
291 --this._undoableActionIndex;
292 } else if (this._undoableActionIndex + 1 < this._actions.length)
293 this._actions.splice(this._undoableActionIndex + 1);
294
295 this._actions.push(action);
296 ++this._undoableActionIndex;
297 }
298 },
299
300 undo: function()
301 {
302 if (this._undoableActionIndex < 0)
303 return;
304
305 var action = this._actions[this._undoableActionIndex];
306 console.assert(action);
307 action.undo();
308 --this._undoableActionIndex;
309 },
310
311 redo: function()
312 {
313 if (this._undoableActionIndex >= this._actions.length - 1)
314 return;
315
316 var action = this._actions[++this._undoableActionIndex];
317 console.assert(action);
318 action.redo();
319 }
320 }
321
322 /**
323 * @constructor
324 * @extends {WebInspector.Object} 109 * @extends {WebInspector.Object}
325 */ 110 */
326 WebInspector.DOMStorageModel = function() 111 WebInspector.DOMStorageModel = function()
327 { 112 {
328 /** @type {!Object.<string, !WebInspector.DOMStorage>} */ 113 /** @type {!Object.<string, !WebInspector.DOMStorage>} */
329 this._storages = {}; 114 this._storages = {};
330 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this)); 115 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDis patcher(this));
331 DOMStorageAgent.enable(); 116 DOMStorageAgent.enable();
332 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 117 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
333 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this); 118 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 domStorageItemUpdated: function(storageId, key, oldValue, value) 302 domStorageItemUpdated: function(storageId, key, oldValue, value)
518 { 303 {
519 this._model._domStorageItemUpdated(storageId, key, oldValue, value); 304 this._model._domStorageItemUpdated(storageId, key, oldValue, value);
520 }, 305 },
521 } 306 }
522 307
523 /** 308 /**
524 * @type {WebInspector.DOMStorageModel} 309 * @type {WebInspector.DOMStorageModel}
525 */ 310 */
526 WebInspector.domStorageModel = null; 311 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