Index: Source/devtools/front_end/DOMStorage.js |
diff --git a/Source/devtools/front_end/DOMStorage.js b/Source/devtools/front_end/DOMStorage.js |
index 29094228273d83c168b18a6df240f0f1a201471c..c43322d3a0c540eb5678cf32b23a65f8ccfbf536 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); |
} |
/** |
@@ -82,7 +83,7 @@ WebInspector.DOMStorage.prototype = { |
*/ |
setItem: function(key, value) |
{ |
- DOMStorageAgent.setDOMStorageItem(this.id, key, value); |
+ this._storageHistory.perform(new WebInspector.DOMStorageSetItemAction(this, key, value)); |
}, |
/** |
@@ -90,7 +91,205 @@ WebInspector.DOMStorage.prototype = { |
*/ |
removeItem: function(key) |
{ |
- DOMStorageAgent.removeDOMStorageItem(this.id, key); |
+ this._storageHistory.perform(new WebInspector.DOMStorageRemoveItemAction(this, key)); |
+ }, |
+ |
+ undo: function() |
+ { |
+ this._storageHistory.undo(); |
+ }, |
+ |
+ redo: function() |
+ { |
+ this._storageHistory.redo(); |
+ } |
+} |
+ |
+/** |
+ * @constructor |
+ * @param {WebInspector.DOMStorage} domStorage |
+ */ |
+WebInspector.DOMStorageAction = function(domStorage) |
+{ |
+ this._domStorage = domStorage; |
+} |
+ |
+WebInspector.DOMStorageAction.prototype = { |
+ /** |
+ * @param {function(): void} callback |
apavlov
2013/08/01 09:19:16
we typically omit "void" in signatures. In fact, i
|
+ */ |
+ perform: function(callback) |
+ { |
+ }, |
+ |
+ undo: function() |
+ { |
+ }, |
+ |
+ redo: function() |
+ { |
+ } |
+} |
+ |
+/** |
+ * @constructor |
+ * @param {!WebInspector.DOMStorage} domStorage |
+ * @param {!string} key |
+ * @extends {WebInspector.DOMStorageAction} |
apavlov
2013/08/01 09:19:16
@extends should immediately follow @constructor fo
|
+ */ |
+WebInspector.DOMStorageRemoveItemAction = function(domStorage, key) |
+{ |
+ WebInspector.DOMStorageAction.call(this, domStorage); |
+ this._key = key; |
+} |
+ |
+WebInspector.DOMStorageRemoveItemAction.prototype = { |
+ /** |
+ * @override |
+ * @param {function(): void} callback |
apavlov
2013/08/01 09:19:16
ditto re void (and more below)
|
+ */ |
+ perform: function(callback) |
+ { |
+ /** |
+ * @param {?Protocol.Error} error |
+ * @param {string=} value |
+ */ |
+ function valueReceived(error, value) |
+ { |
+ this._value = value; |
+ this.redo(); |
+ callback(); |
+ } |
+ DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueReceived.bind(this)); |
+ }, |
+ |
+ /* |
apavlov
2013/08/01 09:19:16
/**
|
+ * @override |
+ */ |
+ undo: function() |
+ { |
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._value); |
+ }, |
+ |
+ /* |
apavlov
2013/08/01 09:19:16
/**
|
+ * @override |
+ */ |
+ redo: function() |
+ { |
+ DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); |
+ }, |
+ |
+ __proto__: WebInspector.DOMStorageAction.prototype |
+} |
+ |
+/** |
+ * @constructor |
+ * @param {WebInspector.DOMStorage} domStorage |
+ * @param {string} key |
+ * @extends {WebInspector.DOMStorageAction} |
apavlov
2013/08/01 09:19:16
Please move next to @constructor
|
+ */ |
+WebInspector.DOMStorageSetItemAction = function(domStorage, key, value) |
+{ |
+ WebInspector.DOMStorageAction.call(this, domStorage); |
+ this._key = key; |
+ this._value = value; |
+} |
+ |
+WebInspector.DOMStorageSetItemAction.prototype = { |
+ /** |
+ * @override |
+ * @param {function(): void} callback |
+ */ |
+ perform: function(callback) |
+ { |
+ /** |
+ * @param {?Protocol.Error} error |
+ * @param {string=} value |
+ */ |
+ function valueReceived(error, value) |
+ { |
+ if (typeof value === 'undefined' || value === null) |
+ this._exists = false; |
+ else { |
+ this._exists = true; |
+ this._oldValue = value; |
+ } |
+ this.redo(); |
+ callback(); |
+ } |
+ DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueReceived.bind(this)); |
+ }, |
+ |
+ /* |
apavlov
2013/08/01 09:19:16
/**
|
+ * @override |
+ */ |
+ undo: function() |
+ { |
+ if (!this._exists) |
+ DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key); |
+ else |
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._oldValue); |
+ }, |
+ |
+ /* |
apavlov
2013/08/01 09:19:16
/**
|
+ * @override |
+ */ |
+ redo: function() |
+ { |
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._value); |
+ }, |
+ |
+ __proto__: WebInspector.DOMStorageAction.prototype |
+} |
+ |
+/** |
+ * @constructor |
+ * @param {WebInspector.DOMStorage} domStorage |
+ */ |
+WebInspector.DOMStorageHistory = function(domStorage) |
+{ |
+ this._domStorage = domStorage; |
+ this._actions = []; |
+ this._currentActionIndex = -1; |
+} |
+ |
+WebInspector.DOMStorageHistory.prototype = { |
+ /* |
apavlov
2013/08/01 09:19:16
/**
|
+ * @param {WebInspector.DOMStorageAction} action |
+ */ |
+ perform: function(action) |
+ { |
+ if (!action) |
+ return; |
+ |
+ function completed() |
+ { |
+ this._actions.push(action); |
+ ++this._currentActionIndex; |
+ } |
+ |
+ action.perform(completed.bind(this)); |
+ }, |
+ |
+ undo: function() |
+ { |
+ if (this._currentActionIndex < 0) |
+ return; |
+ |
+ var action = this._actions[this._currentActionIndex]; |
+ console.assert(action); |
+ action.undo(); |
+ --this._currentActionIndex; |
+ }, |
+ |
+ redo: function() |
+ { |
+ if (this._currentActionIndex >= this._actions.length - 1) |
+ return; |
+ |
+ var action = this._actions[++this._currentActionIndex]; |
+ console.assert(action); |
+ action.redo(); |
} |
} |