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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
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..f819f4ca9fbdcca64deabdaa9789403083a205e8 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,164 @@ 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
apavlov 2013/07/31 12:51:35 This should be @interface instead
+ * @param {WebInspector.DOMStorage} domStorage
+ */
+WebInspector.DOMStorageAction = function(domStorage)
+{
+ this._domStorage = domStorage;
+}
+
+WebInspector.DOMStorageAction.prototype = {
+ perform: function(callback)
apavlov 2013/07/31 12:51:35 callback should be annotated using @param
+ {
+ },
+
+ undo: function()
+ {
+ },
+
+ redo: function()
+ {
+ }
+}
+
+/**
+ * @constructor
+ * @param {WebInspector.DOMStorage} domStorage
apavlov 2013/07/31 12:51:35 also add the @implements annotation
+ * @param {string} key
+ * @extends {WebInspector.DOMStorageAction}
apavlov 2013/07/31 12:51:35 this should be removed
+ */
+WebInspector.DOMStorageRemoveItemAction = function(domStorage, key)
+{
+ WebInspector.DOMStorageAction.call(this, domStorage);
+ this._key = key;
+}
+
+WebInspector.DOMStorageRemoveItemAction.prototype = {
+ __proto__: WebInspector.DOMStorageAction.prototype,
apavlov 2013/07/31 12:51:35 We usually put these last in the prototype definit
+
+ perform: function(callback)
+ {
+ function valueReceived(error, exists, value)
+ {
+ this._exists = exists;
+ this._value = value;
+ this.redo();
+ callback();
+ }
+ DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueReceived.bind(this));
+ },
+
+ undo: function()
+ {
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._value);
+ },
+
+ redo: function()
+ {
+ DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key);
+ }
+}
+
+/**
+ * @constructor
apavlov 2013/07/31 12:51:35 ditto re @implements
+ * @param {WebInspector.DOMStorage} domStorage
+ * @param {string} key
+ * @extends {WebInspector.DOMStorageAction}
+ */
+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(callback)
apavlov 2013/07/31 12:51:35 JsDoc (perhaps just @inherit)
+ {
+ function valueReceived(error, exists, value)
+ {
+ this._exists = exists;
+ this._oldValue = value;
+ this.redo();
+ callback();
+ }
+ DOMStorageAgent.getDOMStorageItem(this._domStorage.id, this._key, valueReceived.bind(this));
+ },
+
+ undo: function()
+ {
+ if (this._exists)
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._oldValue);
+ else
+ DOMStorageAgent.removeDOMStorageItem(this._domStorage.id, this._key);
+ },
+
+ redo: function()
+ {
+ DOMStorageAgent.setDOMStorageItem(this._domStorage.id, this._key, this._value);
+ }
+}
+
+/**
+ * @constructor
+ */
+WebInspector.DOMStorageHistory = function(domStorage)
apavlov 2013/07/31 12:51:35 JsDoc for domStorage
+{
+ this._domStorage = domStorage;
+ this._actions = [];
+ this._currentActionIndex = -1;
+}
+
+WebInspector.DOMStorageHistory.prototype = {
+ perform: function(action)
apavlov 2013/07/31 12:51:35 JsDoc
+ {
+ if (!action)
+ return;
+
+ action.perform(function() {
+ this._actions.push(action);
+ ++this._currentActionIndex;
+ }.bind(this));
+ },
+
+ undo: function()
+ {
+ if (this._currentActionIndex < 0)
+ return;
+
+ var action = this._actions[this._currentActionIndex];
+ if (action)
apavlov 2013/07/31 12:51:35 I believe you should console.assert(action) here,
+ action.undo();
+ --this._currentActionIndex;
+ },
+
+ redo: function()
+ {
+ if (this._currentActionIndex > this._actions.length)
+ return;
+
+ var action = this._actions[++this._currentActionIndex];
+ if (action)
apavlov 2013/07/31 12:51:35 I believe you should console.assert(action) here,
+ action.redo();
}
}

Powered by Google App Engine
This is Rietveld 408576698