Index: Source/devtools/front_end/DOMStorage.js |
diff --git a/Source/devtools/front_end/DOMStorage.js b/Source/devtools/front_end/DOMStorage.js |
index b209f726c0934ddc46be269c2feb81061a41ae36..4446d7d238fe4553f7e0cdfa11bae94f3d0c8f16 100644 |
--- a/Source/devtools/front_end/DOMStorage.js |
+++ b/Source/devtools/front_end/DOMStorage.js |
@@ -36,6 +36,7 @@ WebInspector.DOMStorage = function(securityOrigin, isLocalStorage) |
{ |
this._securityOrigin = securityOrigin; |
this._isLocalStorage = isLocalStorage; |
+ this._storageHistory = new WebInspector.DOMStorageHistory(this); |
} |
/** |
@@ -79,20 +80,155 @@ WebInspector.DOMStorage.prototype = { |
/** |
* @param {string} key |
* @param {string} value |
- * @param {function(?Protocol.Error):void=} callback |
*/ |
- setItem: function(key, value, callback) |
+ setItem: function(key, value) |
{ |
- DOMStorageAgent.setDOMStorageItem(this.id, key, value, callback); |
+ this._storageHistory.perform(new WebInspector.DOMStorageSetItemAction(this, key, value)); |
}, |
/** |
* @param {string} key |
- * @param {function(?Protocol.Error):void=} callback |
*/ |
- removeItem: function(key, callback) |
+ removeItem: function(key) |
{ |
- DOMStorageAgent.removeDOMStorageItem(this.id, key, callback); |
+ this._storageHistory.perform(new WebInspector.DOMStorageRemoveItemAction(this, key)); |
+ }, |
+ |
+ undo: function() |
+ { |
+ this._storageHistory.undo(); |
+ }, |
+ |
+ redo: function() |
+ { |
+ this._storageHistory.redo(); |
+ } |
+} |
+ |
+/** |
+ * @constructor |
+ */ |
+WebInspector.DOMStorageAction = function(domStorage) |
apavlov
2013/05/08 11:41:36
I would defer the decision on this to pfeldman, bu
|
+{ |
+ this._domStorage = domStorage; |
+} |
+ |
+WebInspector.DOMStorageAction.prototype = { |
+ perform: function() |
+ { |
+ }, |
+ |
+ undo: function() |
+ { |
+ }, |
+ |
+ redo: function() |
+ { |
+ } |
+} |
+ |
+WebInspector.DOMStorageRemoveItemAction = function(domStorage, key) |
+{ |
+ WebInspector.DOMStorageAction.call(this, domStorage); |
+ this._key = key; |
+} |
+ |
+WebInspector.DOMStorageRemoveItemAction.prototype = { |
+ __proto__: WebInspector.DOMStorageAction.prototype, |
+ |
+ perform: function() |
+ { |
+ function callback(error, value) |
+ { |
+ this._value = value; |
+ this.redo(); |
+ } |
+ DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, callback.bind(this)); |
+ }, |
+ |
+ undo: function() |
+ { |
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._value); |
+ }, |
+ |
+ redo: function() |
+ { |
+ DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); |
+ } |
+} |
+ |
+WebInspector.DOMStorageSetItemAction = function(domStorage, key, value) |
+{ |
+ WebInspector.DOMStorageAction.call(this, domStorage); |
+ this._key = key; |
+ this._value = value; |
+} |
+ |
+WebInspector.DOMStorageSetItemAction.prototype = { |
+ __proto__: WebInspector.DOMStorageAction.prototype, |
+ |
+ perform: function() |
+ { |
+ function callback(error, value) |
+ { |
+ this._oldValue = value; |
+ this.redo(); |
+ } |
+ DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, callback.bind(this)); |
+ }, |
+ |
+ undo: function() |
+ { |
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._oldValue); |
+ }, |
+ |
+ redo: function() |
+ { |
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._value); |
+ } |
+} |
+ |
+/** |
+ * @constructor |
+ */ |
+WebInspector.DOMStorageHistory = function(domStorage) |
+{ |
+ this._domStorage = domStorage; |
+ this._actions = []; |
+ this._currentActionIndex = -1; |
+} |
+ |
+WebInspector.DOMStorageHistory.prototype = { |
+ perform: function(action) |
+ { |
+ if (!action) |
+ return; |
+ |
+ action.perform(); |
+ |
+ this._actions.push(action); |
+ ++this._currentActionIndex; |
+ }, |
+ |
+ undo: function() |
+ { |
+ if (this._currentActionIndex < 0) |
+ return; |
+ |
+ var action = this._actions[this._currentActionIndex]; |
+ if (action) |
+ action.undo(); |
+ --this._currentActionIndex; |
+ }, |
+ |
+ redo: function() |
+ { |
+ if (this._currentActionIndex > this._actions.length) |
+ return; |
+ |
+ var action = this._actions[++this._currentActionIndex]; |
+ if (action) |
+ action.redo(); |
} |
} |