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 {!WebInspector.DOMStorageModel} model
34 * @param {string} securityOrigin
35 * @param {boolean} isLocalStorage
37 WebInspector.DOMStorage = function(model, securityOrigin, isLocalStorage)
40 this._securityOrigin = securityOrigin;
41 this._isLocalStorage = isLocalStorage;
45 * @param {string} securityOrigin
46 * @param {boolean} isLocalStorage
47 * @return {!DOMStorageAgent.StorageId}
49 WebInspector.DOMStorage.storageId = function(securityOrigin, isLocalStorage)
51 return { securityOrigin: securityOrigin, isLocalStorage: isLocalStorage };
54 WebInspector.DOMStorage.Events = {
55 DOMStorageItemsCleared: "DOMStorageItemsCleared",
56 DOMStorageItemRemoved: "DOMStorageItemRemoved",
57 DOMStorageItemAdded: "DOMStorageItemAdded",
58 DOMStorageItemUpdated: "DOMStorageItemUpdated"
61 WebInspector.DOMStorage.prototype = {
63 /** @return {!DOMStorageAgent.StorageId} */
66 return WebInspector.DOMStorage.storageId(this._securityOrigin, this._isLocalStorage);
69 /** @return {string} */
72 return this._securityOrigin;
75 /** @return {boolean} */
78 return this._isLocalStorage;
82 * @param {function(?Protocol.Error, !Array.<!DOMStorageAgent.Item>):void=} callback
84 getItems: function(callback)
86 this._model._agent.getDOMStorageItems(this.id, callback);
91 * @param {string} value
93 setItem: function(key, value)
95 this._model._agent.setDOMStorageItem(this.id, key, value);
101 removeItem: function(key)
103 this._model._agent.removeDOMStorageItem(this.id, key);
106 __proto__: WebInspector.Object.prototype
111 * @extends {WebInspector.SDKModel}
112 * @param {!WebInspector.Target} target
114 WebInspector.DOMStorageModel = function(target)
116 WebInspector.SDKModel.call(this, WebInspector.DOMStorageModel, target);
118 /** @type {!Object.<string, !WebInspector.DOMStorage>} */
120 target.registerDOMStorageDispatcher(new WebInspector.DOMStorageDispatcher(this));
121 this._agent = target.domstorageAgent();
122 this._agent.enable();
123 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
124 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
127 WebInspector.DOMStorageModel.Events = {
128 DOMStorageAdded: "DOMStorageAdded",
129 DOMStorageRemoved: "DOMStorageRemoved"
132 WebInspector.DOMStorageModel.prototype = {
135 * @param {!WebInspector.Event} event
137 _securityOriginAdded: function(event)
139 var securityOrigin = /** @type {string} */ (event.data);
140 var localStorageKey = this._storageKey(securityOrigin, true);
141 console.assert(!this._storages[localStorageKey]);
142 var localStorage = new WebInspector.DOMStorage(this, securityOrigin, true);
143 this._storages[localStorageKey] = localStorage;
144 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, localStorage);
146 var sessionStorageKey = this._storageKey(securityOrigin, false);
147 console.assert(!this._storages[sessionStorageKey]);
148 var sessionStorage = new WebInspector.DOMStorage(this, securityOrigin, false);
149 this._storages[sessionStorageKey] = sessionStorage;
150 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, sessionStorage);
154 * @param {!WebInspector.Event} event
156 _securityOriginRemoved: function(event)
158 var securityOrigin = /** @type {string} */ (event.data);
159 var localStorageKey = this._storageKey(securityOrigin, true);
160 var localStorage = this._storages[localStorageKey];
161 console.assert(localStorage);
162 delete this._storages[localStorageKey];
163 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, localStorage);
165 var sessionStorageKey = this._storageKey(securityOrigin, false);
166 var sessionStorage = this._storages[sessionStorageKey];
167 console.assert(sessionStorage);
168 delete this._storages[sessionStorageKey];
169 this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, sessionStorage);
173 * @param {string} securityOrigin
174 * @param {boolean} isLocalStorage
177 _storageKey: function(securityOrigin, isLocalStorage)
179 return JSON.stringify(WebInspector.DOMStorage.storageId(securityOrigin, isLocalStorage));
183 * @param {!DOMStorageAgent.StorageId} storageId
185 _domStorageItemsCleared: function(storageId)
187 var domStorage = this.storageForId(storageId);
192 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemsCleared, eventData);
196 * @param {!DOMStorageAgent.StorageId} storageId
197 * @param {string} key
199 _domStorageItemRemoved: function(storageId, key)
201 var domStorage = this.storageForId(storageId);
205 var eventData = { key: key };
206 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemRemoved, eventData);
210 * @param {!DOMStorageAgent.StorageId} storageId
211 * @param {string} key
212 * @param {string} value
214 _domStorageItemAdded: function(storageId, key, value)
216 var domStorage = this.storageForId(storageId);
220 var eventData = { key: key, value: value };
221 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemAdded, eventData);
225 * @param {!DOMStorageAgent.StorageId} storageId
226 * @param {string} key
227 * @param {string} oldValue
228 * @param {string} value
230 _domStorageItemUpdated: function(storageId, key, oldValue, value)
232 var domStorage = this.storageForId(storageId);
236 var eventData = { key: key, oldValue: oldValue, value: value };
237 domStorage.dispatchEventToListeners(WebInspector.DOMStorage.Events.DOMStorageItemUpdated, eventData);
241 * @param {!DOMStorageAgent.StorageId} storageId
242 * @return {!WebInspector.DOMStorage}
244 storageForId: function(storageId)
246 return this._storages[JSON.stringify(storageId)];
250 * @return {!Array.<!WebInspector.DOMStorage>}
255 for (var id in this._storages)
256 result.push(this._storages[id]);
260 __proto__: WebInspector.SDKModel.prototype
265 * @implements {DOMStorageAgent.Dispatcher}
266 * @param {!WebInspector.DOMStorageModel} model
268 WebInspector.DOMStorageDispatcher = function(model)
273 WebInspector.DOMStorageDispatcher.prototype = {
276 * @param {!DOMStorageAgent.StorageId} storageId
278 domStorageItemsCleared: function(storageId)
280 this._model._domStorageItemsCleared(storageId);
284 * @param {!DOMStorageAgent.StorageId} storageId
285 * @param {string} key
287 domStorageItemRemoved: function(storageId, key)
289 this._model._domStorageItemRemoved(storageId, key);
293 * @param {!DOMStorageAgent.StorageId} storageId
294 * @param {string} key
295 * @param {string} value
297 domStorageItemAdded: function(storageId, key, value)
299 this._model._domStorageItemAdded(storageId, key, value);
303 * @param {!DOMStorageAgent.StorageId} storageId
304 * @param {string} key
305 * @param {string} oldValue
306 * @param {string} value
308 domStorageItemUpdated: function(storageId, key, oldValue, value)
310 this._model._domStorageItemUpdated(storageId, key, oldValue, value);
315 * @type {!WebInspector.DOMStorageModel}
317 WebInspector.domStorageModel;