WebInspector.DOMStorage = function(securityOrigin, isLocalStorage)
{
this._securityOrigin = securityOrigin;
this._isLocalStorage = isLocalStorage;
}
WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage)
{
return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage };
}
WebInspector.DOMStorage.prototype = {
get id()
{
return WebInspector.DOMStorage.storageId(this._securityOrigin, this._isLocalStorage);
},
get securityOrigin()
{
return this._securityOrigin;
},
get isLocalStorage()
{
return this._isLocalStorage;
},
getItems: function(callback)
{
DOMStorageAgent.getDOMStorageItems(this.id, callback);
},
setItem: function(key, value, callback)
{
DOMStorageAgent.setDOMStorageItem(this.id, key, value, callback);
},
removeItem: function(key, callback)
{
DOMStorageAgent.removeDOMStorageItem(this.id, key, callback);
}
}
WebInspector.DOMStorageModel = function()
{
this._storages = {};
InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDispatcher(this));
DOMStorageAgent.enable();
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
}
WebInspector.DOMStorageModel.Events = {
DOMStorageAdded: "DOMStorageAdded",
DOMStorageRemoved: "DOMStorageRemoved",
DOMStorageItemsCleared: "DOMStorageItemsCleared",
DOMStorageItemRemoved: "DOMStorageItemRemoved",
DOMStorageItemAdded: "DOMStorageItemAdded",
DOMStorageItemUpdated: "DOMStorageItemUpdated"
}
WebInspector.DOMStorageModel.prototype = {
_securityOriginAdded: function(event)
{
var securityOrigin = (event.data);
var localStorageKey = this._storageKey(securityOrigin, true);
console.assert(!this._storages[localStorageKey]);
var localStorage = new WebInspector.DOMStorage(securityOrigin, true);
this._storages[localStorageKey] = localStorage;
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, localStorage);
var sessionStorageKey = this._storageKey(securityOrigin, false);
console.assert(!this._storages[sessionStorageKey]);
var sessionStorage = new WebInspector.DOMStorage(securityOrigin, false);
this._storages[sessionStorageKey] = sessionStorage;
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, sessionStorage);
},
_securityOriginRemoved: function(event)
{
var securityOrigin = (event.data);
var localStorageKey = this._storageKey(securityOrigin, true);
var localStorage = this._storages[localStorageKey];
console.assert(localStorage);
delete this._storages[localStorageKey];
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, localStorage);
var sessionStorageKey = this._storageKey(securityOrigin, false);
var sessionStorage = this._storages[sessionStorageKey];
console.assert(sessionStorage);
delete this._storages[sessionStorageKey];
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, sessionStorage);
},
_storageKey: function(securityOrigin, isLocalStorage)
{
return JSON.stringify(WebInspector.DOMStorage.storageId(securityOrigin, isLocalStorage));
},
_domStorageItemsCleared: function(storageId)
{
var domStorage = this.storageForId(storageId);
var storageData = {
storage: domStorage
};
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageItemsCleared, storageData);
},
_domStorageItemRemoved: function(storageId, key)
{
var domStorage = this.storageForId(storageId);
var storageData = {
storage: domStorage,
key: key
};
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageItemRemoved, storageData);
},
_domStorageItemAdded: function(storageId, key, newValue)
{
var domStorage = this.storageForId(storageId);
var storageData = {
storage: domStorage,
key: key,
newValue: newValue
};
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageItemAdded, storageData);
},
_domStorageItemUpdated: function(storageId, key, oldValue, newValue)
{
var domStorage = this._storages[storageId];
var storageData = {
storage: domStorage,
key: key,
oldValue: oldValue,
newValue: newValue
};
this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageItemUpdated, storageData);
},
storageForId: function(storageId)
{
return this._storages[JSON.stringify(storageId)];
},
storages: function()
{
var result = [];
for (var id in this._storages)
result.push(this._storages[id]);
return result;
},
__proto__: WebInspector.Object.prototype
}
WebInspector.DOMStorageDispatcher = function(model)
{
this._model = model;
}
WebInspector.DOMStorageDispatcher.prototype = {
domStorageItemsCleared: function(storageId)
{
this._model._domStorageItemsCleared(storageId);
},
domStorageItemRemoved: function(storageId, key)
{
this._model._domStorageItemRemoved(storageId, key);
},
domStorageItemAdded: function(storageId, key, newValue)
{
this._model._domStorageItemAdded(storageId, key, newValue);
},
domStorageItemUpdated: function(storageId, key, oldValue, newValue)
{
this._model._domStorageItemUpdated(storageId, key, oldValue, newValue);
},
}
WebInspector.domStorageModel = null;