2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 WebInspector.StorageSidebarPanel = class StorageSidebarPanel extends WebInspector.NavigationSidebarPanel
28 constructor(contentBrowser)
30 super("storage", WebInspector.UIString("Storage"));
32 this.contentBrowser = contentBrowser;
34 this.filterBar.placeholder = WebInspector.UIString("Filter Storage List");
36 this._localStorageRootTreeElement = null;
37 this._sessionStorageRootTreeElement = null;
39 this._databaseRootTreeElement = null;
40 this._databaseHostTreeElementMap = {};
42 this._indexedDatabaseRootTreeElement = null;
43 this._indexedDatabaseHostTreeElementMap = {};
45 this._cookieStorageRootTreeElement = null;
47 this._applicationCacheRootTreeElement = null;
48 this._applicationCacheURLTreeElementMap = {};
50 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.CookieStorageObjectWasAdded, this._cookieStorageObjectWasAdded, this);
51 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.DOMStorageObjectWasAdded, this._domStorageObjectWasAdded, this);
52 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.DOMStorageObjectWasInspected, this._domStorageObjectWasInspected, this);
53 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.DatabaseWasAdded, this._databaseWasAdded, this);
54 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.DatabaseWasInspected, this._databaseWasInspected, this);
55 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.IndexedDatabaseWasAdded, this._indexedDatabaseWasAdded, this);
56 WebInspector.storageManager.addEventListener(WebInspector.StorageManager.Event.Cleared, this._storageCleared, this);
58 WebInspector.applicationCacheManager.addEventListener(WebInspector.ApplicationCacheManager.Event.FrameManifestAdded, this._frameManifestAdded, this);
59 WebInspector.applicationCacheManager.addEventListener(WebInspector.ApplicationCacheManager.Event.FrameManifestRemoved, this._frameManifestRemoved, this);
61 this.contentTreeOutline.onselect = this._treeElementSelected.bind(this);
63 for (var domStorageObject of WebInspector.storageManager.domStorageObjects)
64 this._addDOMStorageObject(domStorageObject);
66 for (var cookieStorageObject of WebInspector.storageManager.cookieStorageObjects)
67 this._addCookieStorageObject(cookieStorageObject);
69 for (var database of WebInspector.storageManager.databases)
70 this._addDatabase(database);
72 for (var indexedDatabase of WebInspector.storageManager.indexedDatabases)
73 this._addIndexedDatabase(indexedDatabase);
75 for (var applicationCacheObject of WebInspector.applicationCacheManager.applicationCacheObjects)
76 this._addFrameManifest(applicationCacheObject);
81 showDefaultContentView()
83 // Don't show anything by default. It doesn't make a whole lot of sense here.
90 WebInspector.storageManager.removeEventListener(null, null, this);
91 WebInspector.applicationCacheManager.removeEventListener(null, null, this);
96 _treeElementSelected(treeElement, selectedByUser)
98 if (treeElement instanceof WebInspector.FolderTreeElement || treeElement instanceof WebInspector.DatabaseHostTreeElement ||
99 treeElement instanceof WebInspector.IndexedDatabaseHostTreeElement || treeElement instanceof WebInspector.IndexedDatabaseTreeElement)
102 if (treeElement instanceof WebInspector.StorageTreeElement || treeElement instanceof WebInspector.DatabaseTableTreeElement ||
103 treeElement instanceof WebInspector.DatabaseTreeElement || treeElement instanceof WebInspector.ApplicationCacheFrameTreeElement ||
104 treeElement instanceof WebInspector.IndexedDatabaseObjectStoreTreeElement || treeElement instanceof WebInspector.IndexedDatabaseObjectStoreIndexTreeElement) {
105 WebInspector.showRepresentedObject(treeElement.representedObject);
109 console.error("Unknown tree element", treeElement);
112 _domStorageObjectWasAdded(event)
114 var domStorage = event.data.domStorage;
115 this._addDOMStorageObject(event.data.domStorage);
118 _addDOMStorageObject(domStorage)
120 var storageElement = new WebInspector.DOMStorageTreeElement(domStorage);
122 if (domStorage.isLocalStorage())
123 this._localStorageRootTreeElement = this._addStorageChild(storageElement, this._localStorageRootTreeElement, WebInspector.UIString("Local Storage"));
125 this._sessionStorageRootTreeElement = this._addStorageChild(storageElement, this._sessionStorageRootTreeElement, WebInspector.UIString("Session Storage"));
128 _domStorageObjectWasInspected(event)
130 var domStorage = event.data.domStorage;
131 var treeElement = this.treeElementForRepresentedObject(domStorage);
132 treeElement.revealAndSelect(true);
135 _databaseWasAdded(event)
137 var database = event.data.database;
138 this._addDatabase(event.data.database);
141 _addDatabase(database)
143 console.assert(database instanceof WebInspector.DatabaseObject);
145 if (!this._databaseHostTreeElementMap[database.host]) {
146 this._databaseHostTreeElementMap[database.host] = new WebInspector.DatabaseHostTreeElement(database.host);
147 this._databaseRootTreeElement = this._addStorageChild(this._databaseHostTreeElementMap[database.host], this._databaseRootTreeElement, WebInspector.UIString("Databases"));
150 var databaseElement = new WebInspector.DatabaseTreeElement(database);
151 this._databaseHostTreeElementMap[database.host].appendChild(databaseElement);
154 _databaseWasInspected(event)
156 var database = event.data.database;
157 var treeElement = this.treeElementForRepresentedObject(database);
158 treeElement.revealAndSelect(true);
161 _indexedDatabaseWasAdded(event)
163 this._addIndexedDatabase(event.data.indexedDatabase);
166 _addIndexedDatabase(indexedDatabase)
168 console.assert(indexedDatabase instanceof WebInspector.IndexedDatabase);
170 if (!this._indexedDatabaseHostTreeElementMap[indexedDatabase.host]) {
171 this._indexedDatabaseHostTreeElementMap[indexedDatabase.host] = new WebInspector.IndexedDatabaseHostTreeElement(indexedDatabase.host);
172 this._indexedDatabaseRootTreeElement = this._addStorageChild(this._indexedDatabaseHostTreeElementMap[indexedDatabase.host], this._indexedDatabaseRootTreeElement, WebInspector.UIString("Indexed Databases"));
175 var indexedDatabaseElement = new WebInspector.IndexedDatabaseTreeElement(indexedDatabase);
176 this._indexedDatabaseHostTreeElementMap[indexedDatabase.host].appendChild(indexedDatabaseElement);
179 _cookieStorageObjectWasAdded(event)
181 this._addCookieStorageObject(event.data.cookieStorage);
184 _addCookieStorageObject(cookieStorage)
186 console.assert(cookieStorage instanceof WebInspector.CookieStorageObject);
188 var cookieElement = new WebInspector.CookieStorageTreeElement(cookieStorage);
189 this._cookieStorageRootTreeElement = this._addStorageChild(cookieElement, this._cookieStorageRootTreeElement, WebInspector.UIString("Cookies"));
192 _frameManifestAdded(event)
194 this._addFrameManifest(event.data.frameManifest);
197 _addFrameManifest(frameManifest)
199 console.assert(frameManifest instanceof WebInspector.ApplicationCacheFrame);
201 var manifest = frameManifest.manifest;
202 var manifestURL = manifest.manifestURL;
203 if (!this._applicationCacheURLTreeElementMap[manifestURL]) {
204 this._applicationCacheURLTreeElementMap[manifestURL] = new WebInspector.ApplicationCacheManifestTreeElement(manifest);
205 this._applicationCacheRootTreeElement = this._addStorageChild(this._applicationCacheURLTreeElementMap[manifestURL], this._applicationCacheRootTreeElement, WebInspector.UIString("Application Cache"));
208 var frameCacheElement = new WebInspector.ApplicationCacheFrameTreeElement(frameManifest);
209 this._applicationCacheURLTreeElementMap[manifestURL].appendChild(frameCacheElement);
212 _frameManifestRemoved(event)
214 // FIXME: Implement this.
217 _compareTreeElements(a, b)
219 console.assert(a.mainTitle);
220 console.assert(b.mainTitle);
222 return (a.mainTitle || "").localeCompare(b.mainTitle || "");
225 _addStorageChild(childElement, parentElement, folderName)
227 if (!parentElement) {
228 childElement.flattened = true;
230 this.contentTreeOutline.insertChild(childElement, insertionIndexForObjectInListSortedByFunction(childElement, this.contentTreeOutline.children, this._compareTreeElements));
235 if (parentElement instanceof WebInspector.StorageTreeElement) {
236 console.assert(parentElement.flattened);
238 var previousOnlyChild = parentElement;
239 previousOnlyChild.flattened = false;
240 this.contentTreeOutline.removeChild(previousOnlyChild);
242 var folderElement = new WebInspector.FolderTreeElement(folderName);
243 this.contentTreeOutline.insertChild(folderElement, insertionIndexForObjectInListSortedByFunction(folderElement, this.contentTreeOutline.children, this._compareTreeElements));
245 folderElement.appendChild(previousOnlyChild);
246 folderElement.insertChild(childElement, insertionIndexForObjectInListSortedByFunction(childElement, folderElement.children, this._compareTreeElements));
248 return folderElement;
251 console.assert(parentElement instanceof WebInspector.FolderTreeElement);
252 parentElement.insertChild(childElement, insertionIndexForObjectInListSortedByFunction(childElement, parentElement.children, this._compareTreeElements));
254 return parentElement;
257 _storageCleared(event)
259 // Close all DOM and cookie storage content views since the main frame has navigated and all storages are cleared.
260 this.contentBrowser.contentViewContainer.closeAllContentViewsOfPrototype(WebInspector.CookieStorageContentView);
261 this.contentBrowser.contentViewContainer.closeAllContentViewsOfPrototype(WebInspector.DOMStorageContentView);
262 this.contentBrowser.contentViewContainer.closeAllContentViewsOfPrototype(WebInspector.DatabaseTableContentView);
263 this.contentBrowser.contentViewContainer.closeAllContentViewsOfPrototype(WebInspector.DatabaseContentView);
264 this.contentBrowser.contentViewContainer.closeAllContentViewsOfPrototype(WebInspector.ApplicationCacheFrameContentView);
266 if (this._localStorageRootTreeElement && this._localStorageRootTreeElement.parent)
267 this._localStorageRootTreeElement.parent.removeChild(this._localStorageRootTreeElement);
269 if (this._sessionStorageRootTreeElement && this._sessionStorageRootTreeElement.parent)
270 this._sessionStorageRootTreeElement.parent.removeChild(this._sessionStorageRootTreeElement);
272 if (this._databaseRootTreeElement && this._databaseRootTreeElement.parent)
273 this._databaseRootTreeElement.parent.removeChild(this._databaseRootTreeElement);
275 if (this._indexedDatabaseRootTreeElement && this._indexedDatabaseRootTreeElement.parent)
276 this._indexedDatabaseRootTreeElement.parent.removeChild(this._indexedDatabaseRootTreeElement);
278 if (this._cookieStorageRootTreeElement && this._cookieStorageRootTreeElement.parent)
279 this._cookieStorageRootTreeElement.parent.removeChild(this._cookieStorageRootTreeElement);
281 if (this._applicationCacheRootTreeElement && this._applicationCacheRootTreeElement.parent)
282 this._applicationCacheRootTreeElement.parent.removeChild(this._applicationCacheRootTreeElement);
284 this._localStorageRootTreeElement = null;
285 this._sessionStorageRootTreeElement = null;
286 this._databaseRootTreeElement = null;
287 this._databaseHostTreeElementMap = {};
288 this._indexedDatabaseRootTreeElement = null;
289 this._indexedDatabaseHostTreeElementMap = {};
290 this._cookieStorageRootTreeElement = null;
291 this._applicationCacheRootTreeElement = null;
292 this._applicationCacheURLTreeElementMap = {};