Created
August 6, 2013 10:17
-
-
Save vivekgalatage/6163361 to your computer and use it in GitHub Desktop.
DOMStorage undo/redo stack reset when the page modifies the storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html b/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html | |
index 1412ef6..fd5d5f0 100644 | |
--- a/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html | |
+++ b/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html | |
@@ -24,7 +24,7 @@ function getDOMStorageEntries(isLocalStorage) | |
function test() | |
{ | |
- WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH = 20; | |
+ WebInspector.DOMStorageActionHistory.MAX_UNDO_STACK_DEPTH = 20; | |
WebInspector.showPanel("resources"); | |
@@ -303,7 +303,7 @@ function test() | |
function domStorageViewShown() | |
{ | |
- var stackDepth = WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH; | |
+ var stackDepth = WebInspector.DOMStorageActionHistory.MAX_UNDO_STACK_DEPTH; | |
InspectorTest.addResult("Undo/redo stack depth limit is " + stackDepth); | |
InspectorTest.addResult("Performing " + (2 * stackDepth) + " actions"); | |
for (var i = 1; i <= stackDepth; ++i) | |
diff --git a/Source/core/inspector/InspectorDOMStorageAgent.cpp b/Source/core/inspector/InspectorDOMStorageAgent.cpp | |
index 4b2a118..91d9a51 100644 | |
--- a/Source/core/inspector/InspectorDOMStorageAgent.cpp | |
+++ b/Source/core/inspector/InspectorDOMStorageAgent.cpp | |
@@ -73,6 +73,7 @@ InspectorDOMStorageAgent::InspectorDOMStorageAgent(InstrumentingAgents* instrume | |
: InspectorBaseAgent<InspectorDOMStorageAgent>("DOMStorage", instrumentingAgents, state) | |
, m_pageAgent(pageAgent) | |
, m_frontend(0) | |
+ , m_agentTriggered(false) | |
{ | |
} | |
@@ -88,6 +89,7 @@ void InspectorDOMStorageAgent::setFrontend(InspectorFrontend* frontend) | |
void InspectorDOMStorageAgent::clearFrontend() | |
{ | |
m_frontend = 0; | |
+ m_agentTriggered = false; | |
disable(0); | |
} | |
@@ -165,6 +167,7 @@ void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString* errorString, const | |
return; | |
} | |
+ m_agentTriggered = true; | |
TrackExceptionState es; | |
storageArea->setItem(key, value, es, frame); | |
*errorString = toErrorString(es); | |
@@ -179,6 +182,7 @@ void InspectorDOMStorageAgent::removeDOMStorageItem(ErrorString* errorString, co | |
return; | |
} | |
+ m_agentTriggered = true; | |
TrackExceptionState es; | |
storageArea->removeItem(key, es, frame); | |
*errorString = toErrorString(es); | |
@@ -210,14 +214,18 @@ void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, con | |
RefPtr<TypeBuilder::DOMStorage::StorageId> id = storageId(securityOrigin, storageType == LocalStorage); | |
+ bool* agentTriggered = m_agentTriggered ? &m_agentTriggered : 0; | |
+ | |
if (key.isNull()) | |
- m_frontend->domstorage()->domStorageItemsCleared(id); | |
+ m_frontend->domstorage()->domStorageItemsCleared(id, agentTriggered); | |
else if (newValue.isNull()) | |
- m_frontend->domstorage()->domStorageItemRemoved(id, key); | |
+ m_frontend->domstorage()->domStorageItemRemoved(id, key, agentTriggered); | |
else if (oldValue.isNull()) | |
- m_frontend->domstorage()->domStorageItemAdded(id, key, newValue); | |
+ m_frontend->domstorage()->domStorageItemAdded(id, key, newValue, agentTriggered); | |
else | |
- m_frontend->domstorage()->domStorageItemUpdated(id, key, oldValue, newValue); | |
+ m_frontend->domstorage()->domStorageItemUpdated(id, key, oldValue, newValue, agentTriggered); | |
+ | |
+ m_agentTriggered = false; | |
} | |
PassOwnPtr<StorageArea> InspectorDOMStorageAgent::findStorageArea(ErrorString* errorString, const RefPtr<JSONObject>& storageId, Frame*& targetFrame) | |
diff --git a/Source/core/inspector/InspectorDOMStorageAgent.h b/Source/core/inspector/InspectorDOMStorageAgent.h | |
index ec583ed..5068c4b 100644 | |
--- a/Source/core/inspector/InspectorDOMStorageAgent.h | |
+++ b/Source/core/inspector/InspectorDOMStorageAgent.h | |
@@ -83,6 +83,7 @@ private: | |
InspectorPageAgent* m_pageAgent; | |
InspectorFrontend* m_frontend; | |
+ bool m_agentTriggered; | |
}; | |
} // namespace WebCore | |
diff --git a/Source/devtools/front_end/DOMStorage.js b/Source/devtools/front_end/DOMStorage.js | |
index 0cbe6ee..c2736fa 100644 | |
--- a/Source/devtools/front_end/DOMStorage.js | |
+++ b/Source/devtools/front_end/DOMStorage.js | |
@@ -36,7 +36,7 @@ WebInspector.DOMStorage = function(securityOrigin, isLocalStorage) | |
{ | |
this._securityOrigin = securityOrigin; | |
this._isLocalStorage = isLocalStorage; | |
- this._storageHistory = new WebInspector.DOMStorageHistory(this); | |
+ this._storageActionHistory = new WebInspector.DOMStorageActionHistory(this); | |
} | |
/** | |
@@ -83,7 +83,7 @@ WebInspector.DOMStorage.prototype = { | |
*/ | |
setItem: function(key, value) | |
{ | |
- this._storageHistory.perform(new WebInspector.DOMStorageSetItemAction(this, key, value)); | |
+ this._storageActionHistory.perform(new WebInspector.DOMStorageSetItemAction(this, key, value)); | |
}, | |
/** | |
@@ -91,17 +91,22 @@ WebInspector.DOMStorage.prototype = { | |
*/ | |
removeItem: function(key) | |
{ | |
- this._storageHistory.perform(new WebInspector.DOMStorageRemoveItemAction(this, key)); | |
+ this._storageActionHistory.perform(new WebInspector.DOMStorageRemoveItemAction(this, key)); | |
}, | |
undo: function() | |
{ | |
- this._storageHistory.undo(); | |
+ this._storageActionHistory.undo(); | |
}, | |
redo: function() | |
{ | |
- this._storageHistory.redo(); | |
+ this._storageActionHistory.redo(); | |
+ }, | |
+ | |
+ resetStorageActionHistory: function() | |
+ { | |
+ this._storageActionHistory.reset(); | |
} | |
} | |
@@ -253,7 +258,7 @@ WebInspector.DOMStorageSetItemAction.prototype = { | |
* @constructor | |
* @param {WebInspector.DOMStorage} domStorage | |
*/ | |
-WebInspector.DOMStorageHistory = function(domStorage) | |
+WebInspector.DOMStorageActionHistory = function(domStorage) | |
{ | |
this._domStorage = domStorage; | |
@@ -262,9 +267,9 @@ WebInspector.DOMStorageHistory = function(domStorage) | |
this._undoableActionIndex = -1; | |
} | |
-WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH = 256; | |
+WebInspector.DOMStorageActionHistory.MAX_UNDO_STACK_DEPTH = 256; | |
-WebInspector.DOMStorageHistory.prototype = { | |
+WebInspector.DOMStorageActionHistory.prototype = { | |
/** | |
* @param {WebInspector.DOMStorageAction} action | |
*/ | |
@@ -276,7 +281,7 @@ WebInspector.DOMStorageHistory.prototype = { | |
action.perform(actionCompleted.bind(this)); | |
function actionCompleted() | |
{ | |
- if (this._undoableActionIndex + 1 === WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH) { | |
+ if (this._undoableActionIndex + 1 === WebInspector.DOMStorageActionHistory.MAX_UNDO_STACK_DEPTH) { | |
this._actions.shift(); | |
--this._undoableActionIndex; | |
} else if (this._undoableActionIndex + 1 < this._actions.length) | |
@@ -306,6 +311,12 @@ WebInspector.DOMStorageHistory.prototype = { | |
var action = this._actions[++this._undoableActionIndex]; | |
console.assert(action); | |
action.redo(); | |
+ }, | |
+ | |
+ reset: function() | |
+ { | |
+ this._actions.splice(0, this._actions.length); | |
+ this._undoableActionIndex = -1; | |
} | |
} | |
@@ -384,9 +395,11 @@ WebInspector.DOMStorageModel.prototype = { | |
/** | |
* @param {DOMStorageAgent.StorageId} storageId | |
*/ | |
- _domStorageItemsCleared: function(storageId) | |
+ _domStorageItemsCleared: function(storageId, agentTriggered) | |
{ | |
var domStorage = this.storageForId(storageId); | |
+ if (domStorage && !agentTriggered) | |
+ domStorage.resetStorageActionHistory(); | |
var storageData = { | |
storage: domStorage | |
}; | |
@@ -397,9 +410,11 @@ WebInspector.DOMStorageModel.prototype = { | |
* @param {DOMStorageAgent.StorageId} storageId | |
* @param {string} key | |
*/ | |
- _domStorageItemRemoved: function(storageId, key) | |
+ _domStorageItemRemoved: function(storageId, key, agentTriggered) | |
{ | |
var domStorage = this.storageForId(storageId); | |
+ if (domStorage && !agentTriggered) | |
+ domStorage.resetStorageActionHistory(); | |
var storageData = { | |
storage: domStorage, | |
key: key | |
@@ -412,9 +427,11 @@ WebInspector.DOMStorageModel.prototype = { | |
* @param {string} key | |
* @param {string} newValue | |
*/ | |
- _domStorageItemAdded: function(storageId, key, newValue) | |
+ _domStorageItemAdded: function(storageId, key, newValue, agentTriggered) | |
{ | |
var domStorage = this.storageForId(storageId); | |
+ if (domStorage && !agentTriggered) | |
+ domStorage.resetStorageActionHistory(); | |
var storageData = { | |
storage: domStorage, | |
key: key, | |
@@ -429,9 +446,11 @@ WebInspector.DOMStorageModel.prototype = { | |
* @param {string} oldValue | |
* @param {string} newValue | |
*/ | |
- _domStorageItemUpdated: function(storageId, key, oldValue, newValue) | |
+ _domStorageItemUpdated: function(storageId, key, oldValue, newValue, agentTriggered) | |
{ | |
- var domStorage = this._storages[storageId]; | |
+ var domStorage = this.storageForId(storageId); | |
+ if (domStorage && !agentTriggered) | |
+ domStorage.resetStorageActionHistory(); | |
var storageData = { | |
storage: domStorage, | |
key: key, | |
@@ -479,18 +498,18 @@ WebInspector.DOMStorageDispatcher.prototype = { | |
/** | |
* @param {DOMStorageAgent.StorageId} storageId | |
*/ | |
- domStorageItemsCleared: function(storageId) | |
+ domStorageItemsCleared: function(storageId, agentTriggered) | |
{ | |
- this._model._domStorageItemsCleared(storageId); | |
+ this._model._domStorageItemsCleared(storageId, agentTriggered); | |
}, | |
/** | |
* @param {DOMStorageAgent.StorageId} storageId | |
* @param {string} key | |
*/ | |
- domStorageItemRemoved: function(storageId, key) | |
+ domStorageItemRemoved: function(storageId, key, agentTriggered) | |
{ | |
- this._model._domStorageItemRemoved(storageId, key); | |
+ this._model._domStorageItemRemoved(storageId, key, agentTriggered); | |
}, | |
/** | |
@@ -498,9 +517,9 @@ WebInspector.DOMStorageDispatcher.prototype = { | |
* @param {string} key | |
* @param {string} newValue | |
*/ | |
- domStorageItemAdded: function(storageId, key, newValue) | |
+ domStorageItemAdded: function(storageId, key, newValue, agentTriggered) | |
{ | |
- this._model._domStorageItemAdded(storageId, key, newValue); | |
+ this._model._domStorageItemAdded(storageId, key, newValue, agentTriggered); | |
}, | |
/** | |
@@ -509,9 +528,9 @@ WebInspector.DOMStorageDispatcher.prototype = { | |
* @param {string} oldValue | |
* @param {string} newValue | |
*/ | |
- domStorageItemUpdated: function(storageId, key, oldValue, newValue) | |
+ domStorageItemUpdated: function(storageId, key, oldValue, newValue, agentTriggered) | |
{ | |
- this._model._domStorageItemUpdated(storageId, key, oldValue, newValue); | |
+ this._model._domStorageItemUpdated(storageId, key, oldValue, newValue, agentTriggered); | |
}, | |
} | |
diff --git a/Source/devtools/protocol.json b/Source/devtools/protocol.json | |
index 0dade10..f8b6a9e 100644 | |
--- a/Source/devtools/protocol.json | |
+++ b/Source/devtools/protocol.json | |
@@ -1024,7 +1024,7 @@ | |
{ "name": "cacheDisabled", "type": "boolean", "description": "Cache disabled state." } | |
], | |
"description": "Toggles ignoring cache for each request. If <code>true</code>, cache will not be used." | |
- }, | |
+ }, | |
{ | |
"name": "loadResourceForFrontend", | |
"async": true, | |
@@ -1476,14 +1476,16 @@ | |
{ | |
"name": "domStorageItemsCleared", | |
"parameters": [ | |
- { "name": "storageId", "$ref": "StorageId" } | |
+ { "name": "storageId", "$ref": "StorageId" }, | |
+ { "name": "agentTriggered", "type": "boolean", "optional": true } | |
] | |
}, | |
{ | |
"name": "domStorageItemRemoved", | |
"parameters": [ | |
{ "name": "storageId", "$ref": "StorageId" }, | |
- { "name": "key", "type": "string" } | |
+ { "name": "key", "type": "string" }, | |
+ { "name": "agentTriggered", "type": "boolean", "optional": true } | |
] | |
}, | |
{ | |
@@ -1491,7 +1493,8 @@ | |
"parameters": [ | |
{ "name": "storageId", "$ref": "StorageId" }, | |
{ "name": "key", "type": "string" }, | |
- { "name": "newValue", "type": "string" } | |
+ { "name": "newValue", "type": "string" }, | |
+ { "name": "agentTriggered", "type": "boolean", "optional": true } | |
] | |
}, | |
{ | |
@@ -1500,7 +1503,8 @@ | |
{ "name": "storageId", "$ref": "StorageId" }, | |
{ "name": "key", "type": "string" }, | |
{ "name": "oldValue", "type": "string" }, | |
- { "name": "newValue", "type": "string" } | |
+ { "name": "newValue", "type": "string" }, | |
+ { "name": "agentTriggered", "type": "boolean", "optional": true } | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment