2 * Copyright (C) 2008 Nokia Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * @extends {WebInspector.Object}
33 * @param {string} securityOrigin
34 * @param {boolean} isLocalStorage
36 WebInspector.DOMStorage = function(securityOrigin, isLocalStorage)
38 this._securityOrigin = securityOrigin;
39 this._isLocalStorage = isLocalStorage;
43 * @param {string} securityOrigin
44 * @param {boolean} isLocalStorage
45 * @return {!DOMStorageAgent.StorageId}
47 WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage)
49 return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage };
52 WebInspector.DOMStorage.Events = {
53 DOMStorageItemsCleared: "DOMStorageItemsCleared",
54 DOMStorageItemRemoved: "DOMStorageItemRemoved",
55 DOMStorageItemAdded: "DOMStorageItemAdded",
56 DOMStorageItemUpdated: "DOMStorageItemUpdated"
59 WebInspector.DOMStorage.prototype = {
61 /** @return {!DOMStorageAgent.StorageId} */
64 return WebInspector.DOMStorage.storageId(this._securityOrigin, this._isLocalStorage);
67 /** @return {string} */
70 return this._securityOrigin;
73 /** @return {boolean} */
76 return this._isLocalStorage;
80 * @param {function(?Protocol.Error, !Array.<!DOMStorageAgent.Item>):void=} callback
82 getItems: function(callback)
84 DOMStorageAgent.getDOMStorageItems(this.id, callback);
89 * @param {string} value
91 setItem: function(key, value)
93 DOMStorageAgent.setDOMStorageItem(this.id, key, value);
99 removeItem: function(key)
101 DOMStorageAgent.removeDOMStorageItem(this.id, key);
104 __proto__: WebInspector.Object.prototype
109 * @extends {WebInspector.Object}
111 WebInspector.DOMStorageModel = function()
113 /** @type {!Object.<string, !WebInspector.DOMStorage>} */
115 InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDispatcher(this));
116 DOMStorageAgent.enable();
117 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
118 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
121 WebInspector.DOMStorageModel.Events = {
122 DOMStorageAdded: "DOMStorageAdded",
123 DOMStorageRemoved: "DOMStorageRemoved"
126 WebInspector.DOMStorageModel.prototype = {
129 * @param {!WebInspector.Event} event
131 _securityOriginAdded: function(event)
133 var securityOrigin = /** @type {string} */ (event.data);
134 var localStorageKey = this._storageKey(securityOrigin, true);
135 console.assert(!this._storages[localStorageKey]);
136 var localStorage = new WebInspector.DOMStorage(securityOrigin, true);
137 this._storages[localStorageKey] = localStorage;
138 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, localStorage);
140 var sessionStorageKey = this._storageKey(securityOrigin, false);
141 console.assert(!this._storages[sessionStorageKey]);
142 var sessionStorage = new WebInspector.DOMStorage(securityOrigin, false);
143 this._storages[sessionStorageKey] = sessionStorage;
144 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, sessionStorage);
148 * @param {!WebInspector.Event} event
150 _securityOriginRemoved: function(event)
152 var securityOrigin = /** @type {string} */ (event.data);
153 var localStorageKey = this._storageKey(securityOrigin, true);
154 var localStorage = this._storages[localStorageKey];
155 console.assert(localStorage);
156 delete this._storages[localStorageKey];
157 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, localStorage);
159 var sessionStorageKey = this._storageKey(securityOrigin, false);
160 var sessionStorage = this._storages[sessionStorageKey];
161 console.assert(sessionStorage);
162 delete this._storages[sessionStorageKey];
163 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, sessionStorage);
167 * @param {string} securityOrigin
168 * @param {boolean} isLocalStorage
171 _storageKey: function(securityOrigin, isLocalStorage)
173 return JSON.stringify(WebInspector.DOMStorage.storageId(securityOrigin, isLocalStorage));
177 * @param {!DOMStorageAgent.StorageId} storageId
179 _domStorageItemsCleared: function(storageId)
181 var domStorage = this.storageForId(storageId);
186 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemsCleared, eventData);
190 * @param {!DOMStorageAgent.StorageId} storageId
191 * @param {string} key
193 _domStorageItemRemoved: function(storageId, key)
195 var domStorage = this.storageForId(storageId);
199 var eventData = { key: key };
200 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemRemoved, eventData);
204 * @param {!DOMStorageAgent.StorageId} storageId
205 * @param {string} key
206 * @param {string} value
208 _domStorageItemAdded: function(storageId, key, value)
210 var domStorage = this.storageForId(storageId);
214 var eventData = { key: key, value: value };
215 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemAdded, eventData);
219 * @param {!DOMStorageAgent.StorageId} storageId
220 * @param {string} key
221 * @param {string} oldValue
222 * @param {string} value
224 _domStorageItemUpdated: function(storageId, key, oldValue, value)
226 var domStorage = this.storageForId(storageId);
230 var eventData = { key: key, oldValue: oldValue, value: value };
231 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemUpdated, eventData);
235 * @param {!DOMStorageAgent.StorageId} storageId
236 * @return {!WebInspector.DOMStorage}
238 storageForId: function(storageId)
240 return this._storages[JSON.stringify(storageId)];
244 * @return {!Array.<!WebInspector.DOMStorage>}
249 for (var id in this._storages)
250 result.push(this._storages[id]);
254 __proto__: WebInspector.Object.prototype
259 * @implements {DOMStorageAgent.Dispatcher}
260 * @param {!WebInspector.DOMStorageModel} model
262 WebInspector.DOMStorageDispatcher = function(model)
267 WebInspector.DOMStorageDispatcher.prototype = {
270 * @param {!DOMStorageAgent.StorageId} storageId
272 domStorageItemsCleared: function(storageId)
274 this._model._domStorageItemsCleared(storageId);
278 * @param {!DOMStorageAgent.StorageId} storageId
279 * @param {string} key
281 domStorageItemRemoved: function(storageId, key)
283 this._model._domStorageItemRemoved(storageId, key);
287 * @param {!DOMStorageAgent.StorageId} storageId
288 * @param {string} key
289 * @param {string} value
291 domStorageItemAdded: function(storageId, key, value)
293 this._model._domStorageItemAdded(storageId, key, value);
297 * @param {!DOMStorageAgent.StorageId} storageId
298 * @param {string} key
299 * @param {string} oldValue
300 * @param {string} value
302 domStorageItemUpdated: function(storageId, key, oldValue, value)
304 this._model._domStorageItemUpdated(storageId, key, oldValue, value);
309 * @type {!WebInspector.DOMStorageModel}
311 WebInspector.domStorageModel;