Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/ResourcesPanel.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 4 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived 16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 /**
31 * @implements {WebInspector.TargetManager.Observer}
32 * @unrestricted
33 */
34 WebInspector.ResourcesPanel = class extends WebInspector.PanelWithSidebar {
35 constructor() {
36 super('resources');
37 this.registerRequiredCSS('resources/resourcesPanel.css');
30 38
31 /** 39 this._resourcesLastSelectedItemSetting = WebInspector.settings.createSetting ('resourcesLastSelectedItem', {});
32 * @constructor
33 * @extends {WebInspector.PanelWithSidebar}
34 * @implements {WebInspector.TargetManager.Observer}
35 */
36 WebInspector.ResourcesPanel = function()
37 {
38 WebInspector.PanelWithSidebar.call(this, "resources");
39 this.registerRequiredCSS("resources/resourcesPanel.css");
40
41 this._resourcesLastSelectedItemSetting = WebInspector.settings.createSetting ("resourcesLastSelectedItem", {});
42 40
43 this._sidebarTree = new TreeOutlineInShadow(); 41 this._sidebarTree = new TreeOutlineInShadow();
44 this._sidebarTree.element.classList.add("resources-sidebar"); 42 this._sidebarTree.element.classList.add('resources-sidebar');
45 this._sidebarTree.registerRequiredCSS("resources/resourcesSidebar.css"); 43 this._sidebarTree.registerRequiredCSS('resources/resourcesSidebar.css');
46 this._sidebarTree.element.classList.add("filter-all"); 44 this._sidebarTree.element.classList.add('filter-all');
47 this.panelSidebarElement().appendChild(this._sidebarTree.element); 45 this.panelSidebarElement().appendChild(this._sidebarTree.element);
48 46
49 this._applicationTreeElement = this._addSidebarSection(WebInspector.UIString ("Application")); 47 this._applicationTreeElement = this._addSidebarSection(WebInspector.UIString ('Application'));
50 this._manifestTreeElement = new WebInspector.AppManifestTreeElement(this); 48 this._manifestTreeElement = new WebInspector.AppManifestTreeElement(this);
51 this._applicationTreeElement.appendChild(this._manifestTreeElement); 49 this._applicationTreeElement.appendChild(this._manifestTreeElement);
52 this.serviceWorkersTreeElement = new WebInspector.ServiceWorkersTreeElement( this); 50 this.serviceWorkersTreeElement = new WebInspector.ServiceWorkersTreeElement( this);
53 this._applicationTreeElement.appendChild(this.serviceWorkersTreeElement); 51 this._applicationTreeElement.appendChild(this.serviceWorkersTreeElement);
54 var clearStorageTreeElement = new WebInspector.ClearStorageTreeElement(this) ; 52 var clearStorageTreeElement = new WebInspector.ClearStorageTreeElement(this) ;
55 this._applicationTreeElement.appendChild(clearStorageTreeElement); 53 this._applicationTreeElement.appendChild(clearStorageTreeElement);
56 54
57 var storageTreeElement = this._addSidebarSection(WebInspector.UIString("Stor age")); 55 var storageTreeElement = this._addSidebarSection(WebInspector.UIString('Stor age'));
58 this.localStorageListTreeElement = new WebInspector.StorageCategoryTreeEleme nt(this, WebInspector.UIString("Local Storage"), "LocalStorage", ["table-tree-it em", "resource-tree-item"]); 56 this.localStorageListTreeElement = new WebInspector.StorageCategoryTreeEleme nt(
57 this, WebInspector.UIString('Local Storage'), 'LocalStorage', ['table-tr ee-item', 'resource-tree-item']);
59 storageTreeElement.appendChild(this.localStorageListTreeElement); 58 storageTreeElement.appendChild(this.localStorageListTreeElement);
60 this.sessionStorageListTreeElement = new WebInspector.StorageCategoryTreeEle ment(this, WebInspector.UIString("Session Storage"), "SessionStorage", ["table-t ree-item", "resource-tree-item"]); 59 this.sessionStorageListTreeElement = new WebInspector.StorageCategoryTreeEle ment(
60 this, WebInspector.UIString('Session Storage'), 'SessionStorage', ['tabl e-tree-item', 'resource-tree-item']);
61 storageTreeElement.appendChild(this.sessionStorageListTreeElement); 61 storageTreeElement.appendChild(this.sessionStorageListTreeElement);
62 this.indexedDBListTreeElement = new WebInspector.IndexedDBTreeElement(this); 62 this.indexedDBListTreeElement = new WebInspector.IndexedDBTreeElement(this);
63 storageTreeElement.appendChild(this.indexedDBListTreeElement); 63 storageTreeElement.appendChild(this.indexedDBListTreeElement);
64 this.databasesListTreeElement = new WebInspector.StorageCategoryTreeElement( this, WebInspector.UIString("Web SQL"), "Databases", ["database-tree-item", "res ource-tree-item"]); 64 this.databasesListTreeElement = new WebInspector.StorageCategoryTreeElement(
65 this, WebInspector.UIString('Web SQL'), 'Databases', ['database-tree-ite m', 'resource-tree-item']);
65 storageTreeElement.appendChild(this.databasesListTreeElement); 66 storageTreeElement.appendChild(this.databasesListTreeElement);
66 this.cookieListTreeElement = new WebInspector.StorageCategoryTreeElement(thi s, WebInspector.UIString("Cookies"), "Cookies", ["cookie-tree-item", "resource-t ree-item"]); 67 this.cookieListTreeElement = new WebInspector.StorageCategoryTreeElement(
68 this, WebInspector.UIString('Cookies'), 'Cookies', ['cookie-tree-item', 'resource-tree-item']);
67 storageTreeElement.appendChild(this.cookieListTreeElement); 69 storageTreeElement.appendChild(this.cookieListTreeElement);
68 70
69 var cacheTreeElement = this._addSidebarSection(WebInspector.UIString("Cache" )); 71 var cacheTreeElement = this._addSidebarSection(WebInspector.UIString('Cache' ));
70 this.cacheStorageListTreeElement = new WebInspector.ServiceWorkerCacheTreeEl ement(this); 72 this.cacheStorageListTreeElement = new WebInspector.ServiceWorkerCacheTreeEl ement(this);
71 cacheTreeElement.appendChild(this.cacheStorageListTreeElement); 73 cacheTreeElement.appendChild(this.cacheStorageListTreeElement);
72 this.applicationCacheListTreeElement = new WebInspector.StorageCategoryTreeE lement(this, WebInspector.UIString("Application Cache"), "ApplicationCache", ["a ppcache-tree-item", "table-tree-item", "resource-tree-item"]); 74 this.applicationCacheListTreeElement = new WebInspector.StorageCategoryTreeE lement(
75 this, WebInspector.UIString('Application Cache'), 'ApplicationCache',
76 ['appcache-tree-item', 'table-tree-item', 'resource-tree-item']);
73 cacheTreeElement.appendChild(this.applicationCacheListTreeElement); 77 cacheTreeElement.appendChild(this.applicationCacheListTreeElement);
74 78
75 this.resourcesListTreeElement = this._addSidebarSection(WebInspector.UIStrin g("Frames")); 79 this.resourcesListTreeElement = this._addSidebarSection(WebInspector.UIStrin g('Frames'));
76 80
77 var mainContainer = new WebInspector.VBox(); 81 var mainContainer = new WebInspector.VBox();
78 this.storageViews = mainContainer.element.createChild("div", "vbox flex-auto "); 82 this.storageViews = mainContainer.element.createChild('div', 'vbox flex-auto ');
79 this._storageViewToolbar = new WebInspector.Toolbar("resources-toolbar", mai nContainer.element); 83 this._storageViewToolbar = new WebInspector.Toolbar('resources-toolbar', mai nContainer.element);
80 this.splitWidget().setMainWidget(mainContainer); 84 this.splitWidget().setMainWidget(mainContainer);
81 85
82 /** @type {!Map.<!WebInspector.Database, !Object.<string, !WebInspector.Data baseTableView>>} */ 86 /** @type {!Map.<!WebInspector.Database, !Object.<string, !WebInspector.Data baseTableView>>} */
83 this._databaseTableViews = new Map(); 87 this._databaseTableViews = new Map();
84 /** @type {!Map.<!WebInspector.Database, !WebInspector.DatabaseQueryView>} * / 88 /** @type {!Map.<!WebInspector.Database, !WebInspector.DatabaseQueryView>} * /
85 this._databaseQueryViews = new Map(); 89 this._databaseQueryViews = new Map();
86 /** @type {!Map.<!WebInspector.Database, !WebInspector.DatabaseTreeElement>} */ 90 /** @type {!Map.<!WebInspector.Database, !WebInspector.DatabaseTreeElement>} */
87 this._databaseTreeElements = new Map(); 91 this._databaseTreeElements = new Map();
88 /** @type {!Map.<!WebInspector.DOMStorage, !WebInspector.DOMStorageItemsView >} */ 92 /** @type {!Map.<!WebInspector.DOMStorage, !WebInspector.DOMStorageItemsView >} */
89 this._domStorageViews = new Map(); 93 this._domStorageViews = new Map();
90 /** @type {!Map.<!WebInspector.DOMStorage, !WebInspector.DOMStorageTreeEleme nt>} */ 94 /** @type {!Map.<!WebInspector.DOMStorage, !WebInspector.DOMStorageTreeEleme nt>} */
91 this._domStorageTreeElements = new Map(); 95 this._domStorageTreeElements = new Map();
92 /** @type {!Object.<string, !WebInspector.CookieItemsView>} */ 96 /** @type {!Object.<string, !WebInspector.CookieItemsView>} */
93 this._cookieViews = {}; 97 this._cookieViews = {};
94 /** @type {!Object.<string, boolean>} */ 98 /** @type {!Object.<string, boolean>} */
95 this._domains = {}; 99 this._domains = {};
96 100
97 this.panelSidebarElement().addEventListener("mousemove", this._onmousemove.b ind(this), false); 101 this.panelSidebarElement().addEventListener('mousemove', this._onmousemove.b ind(this), false);
98 this.panelSidebarElement().addEventListener("mouseleave", this._onmouseleave .bind(this), false); 102 this.panelSidebarElement().addEventListener('mouseleave', this._onmouseleave .bind(this), false);
99 103
100 WebInspector.targetManager.observeTargets(this); 104 WebInspector.targetManager.observeTargets(this);
101 }; 105 }
102 106
103 WebInspector.ResourcesPanel.prototype = { 107 /**
108 * @return {!WebInspector.ResourcesPanel}
109 */
110 static _instance() {
111 return /** @type {!WebInspector.ResourcesPanel} */ (self.runtime.sharedInsta nce(WebInspector.ResourcesPanel));
112 }
113
114 /**
115 * @param {string} title
116 * @return {!TreeElement}
117 */
118 _addSidebarSection(title) {
119 var treeElement = new TreeElement(title, true);
120 treeElement.listItemElement.classList.add('storage-group-list-item');
121 treeElement.setCollapsible(false);
122 treeElement.selectable = false;
123 this._sidebarTree.appendChild(treeElement);
124 return treeElement;
125 }
126
127 /**
128 * @override
129 * @param {!WebInspector.Target} target
130 */
131 targetAdded(target) {
132 if (this._target)
133 return;
134 this._target = target;
135 this._databaseModel = WebInspector.DatabaseModel.fromTarget(target);
136
137 this._databaseModel.addEventListener(WebInspector.DatabaseModel.Events.Datab aseAdded, this._databaseAdded, this);
138 this._databaseModel.addEventListener(WebInspector.DatabaseModel.Events.Datab asesRemoved, this._resetWebSQL, this);
139
140 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target);
141 if (!resourceTreeModel)
142 return;
143
144 if (resourceTreeModel.cachedResourcesLoaded())
145 this._initialize();
146
147 resourceTreeModel.addEventListener(
148 WebInspector.ResourceTreeModel.Events.CachedResourcesLoaded, this._initi alize, this);
149 resourceTreeModel.addEventListener(
150 WebInspector.ResourceTreeModel.Events.WillLoadCachedResources, this._res etWithFrames, this);
151 }
152
153 /**
154 * @override
155 * @param {!WebInspector.Target} target
156 */
157 targetRemoved(target) {
158 if (target !== this._target)
159 return;
160 delete this._target;
161
162 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target);
163 if (resourceTreeModel) {
164 resourceTreeModel.removeEventListener(
165 WebInspector.ResourceTreeModel.Events.CachedResourcesLoaded, this._ini tialize, this);
166 resourceTreeModel.removeEventListener(
167 WebInspector.ResourceTreeModel.Events.WillLoadCachedResources, this._r esetWithFrames, this);
168 }
169 this._databaseModel.removeEventListener(WebInspector.DatabaseModel.Events.Da tabaseAdded, this._databaseAdded, this);
170 this._databaseModel.removeEventListener(
171 WebInspector.DatabaseModel.Events.DatabasesRemoved, this._resetWebSQL, t his);
172
173 this._resetWithFrames();
174 }
175
176 /**
177 * @override
178 */
179 focus() {
180 this._sidebarTree.focus();
181 }
182
183 _initialize() {
184 this._databaseModel.enable();
185
186 var indexedDBModel = WebInspector.IndexedDBModel.fromTarget(this._target);
187 if (indexedDBModel)
188 indexedDBModel.enable();
189
190 var cacheStorageModel = WebInspector.ServiceWorkerCacheModel.fromTarget(this ._target);
191 if (cacheStorageModel)
192 cacheStorageModel.enable();
193 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this._targ et);
194 if (resourceTreeModel) {
195 this._populateResourceTree(resourceTreeModel);
196 this._populateApplicationCacheTree(resourceTreeModel);
197 }
198 var domStorageModel = WebInspector.DOMStorageModel.fromTarget(this._target);
199 if (domStorageModel)
200 this._populateDOMStorageTree(domStorageModel);
201 this.indexedDBListTreeElement._initialize();
202 this.cacheStorageListTreeElement._initialize();
203 this._initDefaultSelection();
204 }
205
206 _initDefaultSelection() {
207 var itemURL = this._resourcesLastSelectedItemSetting.get();
208 if (itemURL) {
209 var rootElement = this._sidebarTree.rootElement();
210 for (var treeElement = rootElement.firstChild(); treeElement;
211 treeElement = treeElement.traverseNextTreeElement(false, rootElement, true)) {
212 if (treeElement.itemURL === itemURL) {
213 treeElement.revealAndSelect(true);
214 return;
215 }
216 }
217 }
218 this._manifestTreeElement.select();
219 }
220
221 _resetWithFrames() {
222 this.resourcesListTreeElement.removeChildren();
223 this._treeElementForFrameId = {};
224 this._reset();
225 }
226
227 _resetWebSQL() {
228 if (this.visibleView instanceof WebInspector.DatabaseQueryView ||
229 this.visibleView instanceof WebInspector.DatabaseTableView) {
230 this.visibleView.detach();
231 delete this.visibleView;
232 }
233
234 var queryViews = this._databaseQueryViews.valuesArray();
235 for (var i = 0; i < queryViews.length; ++i)
236 queryViews[i].removeEventListener(
237 WebInspector.DatabaseQueryView.Events.SchemaUpdated, this._updateDatab aseTables, this);
238 this._databaseTableViews.clear();
239 this._databaseQueryViews.clear();
240 this._databaseTreeElements.clear();
241 this.databasesListTreeElement.removeChildren();
242 this.databasesListTreeElement.setExpandable(false);
243 }
244
245 _resetDOMStorage() {
246 if (this.visibleView instanceof WebInspector.DOMStorageItemsView) {
247 this.visibleView.detach();
248 delete this.visibleView;
249 }
250
251 this._domStorageViews.clear();
252 this._domStorageTreeElements.clear();
253 this.localStorageListTreeElement.removeChildren();
254 this.sessionStorageListTreeElement.removeChildren();
255 }
256
257 _resetCookies() {
258 if (this.visibleView instanceof WebInspector.CookieItemsView) {
259 this.visibleView.detach();
260 delete this.visibleView;
261 }
262 this._cookieViews = {};
263 this.cookieListTreeElement.removeChildren();
264 }
265
266 _resetCacheStorage() {
267 if (this.visibleView instanceof WebInspector.ServiceWorkerCacheView) {
268 this.visibleView.detach();
269 delete this.visibleView;
270 }
271 this.cacheStorageListTreeElement.removeChildren();
272 this.cacheStorageListTreeElement.setExpandable(false);
273 }
274
275 _resetAppCache() {
276 for (var frameId of Object.keys(this._applicationCacheFrameElements))
277 this._applicationCacheFrameManifestRemoved({data: frameId});
278 this.applicationCacheListTreeElement.setExpandable(false);
279 }
280
281 _reset() {
282 this._domains = {};
283 this._resetWebSQL();
284 this._resetDOMStorage();
285 this._resetCookies();
286 this._resetCacheStorage();
287 // No need to this._resetAppCache.
288
289 if ((this.visibleView instanceof WebInspector.ResourceSourceFrame) ||
290 (this.visibleView instanceof WebInspector.ImageView) || (this.visibleVie w instanceof WebInspector.FontView)) {
291 this.visibleView.detach();
292 delete this.visibleView;
293 }
294
295 this._storageViewToolbar.removeToolbarItems();
296
297 if (this._sidebarTree.selectedTreeElement)
298 this._sidebarTree.selectedTreeElement.deselect();
299 }
300
301 /**
302 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel
303 */
304 _populateResourceTree(resourceTreeModel) {
305 this._treeElementForFrameId = {};
306 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Fra meAdded, this._frameAdded, this);
307 resourceTreeModel.addEventListener(
308 WebInspector.ResourceTreeModel.Events.FrameNavigated, this._frameNavigat ed, this);
309 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Fra meDetached, this._frameDetached, this);
310 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Res ourceAdded, this._resourceAdded, this);
311
104 /** 312 /**
105 * @param {string} title 313 * @param {!WebInspector.ResourceTreeFrame} frame
106 * @return {!TreeElement} 314 * @this {WebInspector.ResourcesPanel}
107 */ 315 */
108 _addSidebarSection: function(title) 316 function populateFrame(frame) {
109 { 317 this._frameAdded({data: frame});
110 var treeElement = new TreeElement(title, true); 318 for (var i = 0; i < frame.childFrames.length; ++i)
111 treeElement.listItemElement.classList.add("storage-group-list-item"); 319 populateFrame.call(this, frame.childFrames[i]);
112 treeElement.setCollapsible(false); 320
113 treeElement.selectable = false; 321 var resources = frame.resources();
114 this._sidebarTree.appendChild(treeElement); 322 for (var i = 0; i < resources.length; ++i)
115 return treeElement; 323 this._resourceAdded({data: resources[i]});
116 }, 324 }
117 325 populateFrame.call(this, resourceTreeModel.mainFrame);
118 /** 326 }
119 * @override 327
120 * @param {!WebInspector.Target} target 328 _frameAdded(event) {
121 */ 329 var frame = event.data;
122 targetAdded: function(target) 330 var parentFrame = frame.parentFrame;
123 { 331
124 if (this._target) 332 var parentTreeElement = parentFrame ? this._treeElementForFrameId[parentFram e.id] : this.resourcesListTreeElement;
125 return; 333 if (!parentTreeElement) {
126 this._target = target; 334 console.warn('No frame to route ' + frame.url + ' to.');
127 this._databaseModel = WebInspector.DatabaseModel.fromTarget(target); 335 return;
128 336 }
129 this._databaseModel.addEventListener(WebInspector.DatabaseModel.Events.D atabaseAdded, this._databaseAdded, this); 337
130 this._databaseModel.addEventListener(WebInspector.DatabaseModel.Events.D atabasesRemoved, this._resetWebSQL, this); 338 var frameTreeElement = new WebInspector.FrameTreeElement(this, frame);
131 339 this._treeElementForFrameId[frame.id] = frameTreeElement;
132 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target ); 340 parentTreeElement.appendChild(frameTreeElement);
133 if (!resourceTreeModel) 341 }
134 return; 342
135 343 _frameDetached(event) {
136 if (resourceTreeModel.cachedResourcesLoaded()) 344 var frame = event.data;
137 this._initialize(); 345 var frameTreeElement = this._treeElementForFrameId[frame.id];
138 346 if (!frameTreeElement)
139 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .CachedResourcesLoaded, this._initialize, this); 347 return;
140 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .WillLoadCachedResources, this._resetWithFrames, this); 348
141 }, 349 delete this._treeElementForFrameId[frame.id];
142 350 if (frameTreeElement.parent)
143 /** 351 frameTreeElement.parent.removeChild(frameTreeElement);
144 * @override 352 }
145 * @param {!WebInspector.Target} target 353
146 */ 354 _resourceAdded(event) {
147 targetRemoved: function(target) 355 var resource = event.data;
148 { 356 var frameId = resource.frameId;
149 if (target !== this._target) 357
150 return; 358 if (resource.statusCode >= 301 && resource.statusCode <= 303)
151 delete this._target; 359 return;
152 360
153 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target ); 361 var frameTreeElement = this._treeElementForFrameId[frameId];
154 if (resourceTreeModel) { 362 if (!frameTreeElement) {
155 resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel .Events.CachedResourcesLoaded, this._initialize, this); 363 // This is a frame's main resource, it will be retained
156 resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel .Events.WillLoadCachedResources, this._resetWithFrames, this); 364 // and re-added by the resource manager;
365 return;
366 }
367
368 frameTreeElement.appendResource(resource);
369 }
370
371 _frameNavigated(event) {
372 var frame = event.data;
373
374 if (!frame.parentFrame)
375 this._reset();
376
377 var frameId = frame.id;
378 var frameTreeElement = this._treeElementForFrameId[frameId];
379 if (frameTreeElement)
380 frameTreeElement.frameNavigated(frame);
381
382 var applicationCacheFrameTreeElement = this._applicationCacheFrameElements[f rameId];
383 if (applicationCacheFrameTreeElement)
384 applicationCacheFrameTreeElement.frameNavigated(frame);
385 }
386
387 /**
388 * @param {!WebInspector.Event} event
389 */
390 _databaseAdded(event) {
391 var database = /** @type {!WebInspector.Database} */ (event.data);
392 this._addDatabase(database);
393 }
394
395 /**
396 * @param {!WebInspector.Database} database
397 */
398 _addDatabase(database) {
399 var databaseTreeElement = new WebInspector.DatabaseTreeElement(this, databas e);
400 this._databaseTreeElements.set(database, databaseTreeElement);
401 this.databasesListTreeElement.appendChild(databaseTreeElement);
402 }
403
404 addDocumentURL(url) {
405 var parsedURL = url.asParsedURL();
406 if (!parsedURL)
407 return;
408
409 var domain = parsedURL.securityOrigin();
410 if (!this._domains[domain]) {
411 this._domains[domain] = true;
412 var cookieDomainTreeElement = new WebInspector.CookieTreeElement(this, dom ain);
413 this.cookieListTreeElement.appendChild(cookieDomainTreeElement);
414 }
415 }
416
417 /**
418 * @param {!WebInspector.Event} event
419 */
420 _domStorageAdded(event) {
421 var domStorage = /** @type {!WebInspector.DOMStorage} */ (event.data);
422 this._addDOMStorage(domStorage);
423 }
424
425 /**
426 * @param {!WebInspector.DOMStorage} domStorage
427 */
428 _addDOMStorage(domStorage) {
429 console.assert(!this._domStorageTreeElements.get(domStorage));
430
431 var domStorageTreeElement = new WebInspector.DOMStorageTreeElement(this, dom Storage);
432 this._domStorageTreeElements.set(domStorage, domStorageTreeElement);
433 if (domStorage.isLocalStorage)
434 this.localStorageListTreeElement.appendChild(domStorageTreeElement);
435 else
436 this.sessionStorageListTreeElement.appendChild(domStorageTreeElement);
437 }
438
439 /**
440 * @param {!WebInspector.Event} event
441 */
442 _domStorageRemoved(event) {
443 var domStorage = /** @type {!WebInspector.DOMStorage} */ (event.data);
444 this._removeDOMStorage(domStorage);
445 }
446
447 /**
448 * @param {!WebInspector.DOMStorage} domStorage
449 */
450 _removeDOMStorage(domStorage) {
451 var treeElement = this._domStorageTreeElements.get(domStorage);
452 if (!treeElement)
453 return;
454 var wasSelected = treeElement.selected;
455 var parentListTreeElement = treeElement.parent;
456 parentListTreeElement.removeChild(treeElement);
457 if (wasSelected)
458 parentListTreeElement.select();
459 this._domStorageTreeElements.remove(domStorage);
460 this._domStorageViews.remove(domStorage);
461 }
462
463 /**
464 * @param {!WebInspector.Database} database
465 */
466 selectDatabase(database) {
467 if (database) {
468 this._showDatabase(database);
469 this._databaseTreeElements.get(database).select();
470 }
471 }
472
473 /**
474 * @param {!WebInspector.DOMStorage} domStorage
475 */
476 selectDOMStorage(domStorage) {
477 if (domStorage) {
478 this._showDOMStorage(domStorage);
479 this._domStorageTreeElements.get(domStorage).select();
480 }
481 }
482
483 /**
484 * @param {!WebInspector.Resource} resource
485 * @param {number=} line
486 * @param {number=} column
487 * @return {boolean}
488 */
489 showResource(resource, line, column) {
490 var resourceTreeElement = this._findTreeElementForResource(resource);
491 if (resourceTreeElement)
492 resourceTreeElement.revealAndSelect(true);
493
494 if (typeof line === 'number') {
495 var resourceSourceFrame = this._resourceSourceFrameViewForResource(resourc e);
496 if (resourceSourceFrame)
497 resourceSourceFrame.revealPosition(line, column, true);
498 }
499 return true;
500 }
501
502 _showResourceView(resource) {
503 var view = this._resourceViewForResource(resource);
504 if (!view) {
505 this.visibleView.detach();
506 return;
507 }
508 this._innerShowView(view);
509 }
510
511 /**
512 * @param {!WebInspector.Resource} resource
513 * @return {?WebInspector.Widget}
514 */
515 _resourceViewForResource(resource) {
516 if (resource.hasTextContent()) {
517 var treeElement = this._findTreeElementForResource(resource);
518 if (!treeElement)
519 return null;
520 return treeElement.sourceView();
521 }
522
523 switch (resource.resourceType()) {
524 case WebInspector.resourceTypes.Image:
525 return new WebInspector.ImageView(resource.mimeType, resource);
526 case WebInspector.resourceTypes.Font:
527 return new WebInspector.FontView(resource.mimeType, resource);
528 default:
529 return new WebInspector.EmptyWidget(resource.url);
530 }
531 }
532
533 /**
534 * @param {!WebInspector.Resource} resource
535 * @return {?WebInspector.ResourceSourceFrame}
536 */
537 _resourceSourceFrameViewForResource(resource) {
538 var resourceView = this._resourceViewForResource(resource);
539 if (resourceView && resourceView instanceof WebInspector.ResourceSourceFrame )
540 return /** @type {!WebInspector.ResourceSourceFrame} */ (resourceView);
541 return null;
542 }
543
544 /**
545 * @param {!WebInspector.Database} database
546 * @param {string=} tableName
547 */
548 _showDatabase(database, tableName) {
549 if (!database)
550 return;
551
552 var view;
553 if (tableName) {
554 var tableViews = this._databaseTableViews.get(database);
555 if (!tableViews) {
556 tableViews = /** @type {!Object.<string, !WebInspector.DatabaseTableView >} */ ({});
557 this._databaseTableViews.set(database, tableViews);
558 }
559 view = tableViews[tableName];
560 if (!view) {
561 view = new WebInspector.DatabaseTableView(database, tableName);
562 tableViews[tableName] = view;
563 }
564 } else {
565 view = this._databaseQueryViews.get(database);
566 if (!view) {
567 view = new WebInspector.DatabaseQueryView(database);
568 this._databaseQueryViews.set(database, view);
569 view.addEventListener(WebInspector.DatabaseQueryView.Events.SchemaUpdate d, this._updateDatabaseTables, this);
570 }
571 }
572
573 this._innerShowView(view);
574 }
575
576 /**
577 * @param {!WebInspector.DOMStorage} domStorage
578 */
579 _showDOMStorage(domStorage) {
580 if (!domStorage)
581 return;
582
583 var view;
584 view = this._domStorageViews.get(domStorage);
585 if (!view) {
586 view = new WebInspector.DOMStorageItemsView(domStorage);
587 this._domStorageViews.set(domStorage, view);
588 }
589
590 this._innerShowView(view);
591 }
592
593 /**
594 * @param {!WebInspector.CookieTreeElement} treeElement
595 * @param {string} cookieDomain
596 */
597 showCookies(treeElement, cookieDomain) {
598 var view = this._cookieViews[cookieDomain];
599 if (!view) {
600 view = new WebInspector.CookieItemsView(treeElement, cookieDomain);
601 this._cookieViews[cookieDomain] = view;
602 }
603
604 this._innerShowView(view);
605 }
606
607 /**
608 * @param {string} cookieDomain
609 */
610 clearCookies(cookieDomain) {
611 if (this._cookieViews[cookieDomain])
612 this._cookieViews[cookieDomain].clear();
613 }
614
615 showApplicationCache(frameId) {
616 if (!this._applicationCacheViews[frameId])
617 this._applicationCacheViews[frameId] =
618 new WebInspector.ApplicationCacheItemsView(this._applicationCacheModel , frameId);
619
620 this._innerShowView(this._applicationCacheViews[frameId]);
621 }
622
623 /**
624 * @param {!WebInspector.Widget} view
625 */
626 showFileSystem(view) {
627 this._innerShowView(view);
628 }
629
630 showCategoryView(categoryName) {
631 if (!this._categoryView)
632 this._categoryView = new WebInspector.StorageCategoryView();
633 this._categoryView.setText(categoryName);
634 this._innerShowView(this._categoryView);
635 }
636
637 _innerShowView(view) {
638 if (this.visibleView === view)
639 return;
640
641 if (this.visibleView)
642 this.visibleView.detach();
643
644 view.show(this.storageViews);
645 this.visibleView = view;
646
647 this._storageViewToolbar.removeToolbarItems();
648 var toolbarItems = view instanceof WebInspector.SimpleView ? view.syncToolba rItems() : null;
649 for (var i = 0; toolbarItems && i < toolbarItems.length; ++i)
650 this._storageViewToolbar.appendToolbarItem(toolbarItems[i]);
651 }
652
653 closeVisibleView() {
654 if (!this.visibleView)
655 return;
656 this.visibleView.detach();
657 delete this.visibleView;
658 }
659
660 _updateDatabaseTables(event) {
661 var database = event.data;
662
663 if (!database)
664 return;
665
666 var databasesTreeElement = this._databaseTreeElements.get(database);
667 if (!databasesTreeElement)
668 return;
669
670 databasesTreeElement.invalidateChildren();
671 var tableViews = this._databaseTableViews.get(database);
672
673 if (!tableViews)
674 return;
675
676 var tableNamesHash = {};
677 var self = this;
678 function tableNamesCallback(tableNames) {
679 var tableNamesLength = tableNames.length;
680 for (var i = 0; i < tableNamesLength; ++i)
681 tableNamesHash[tableNames[i]] = true;
682
683 for (var tableName in tableViews) {
684 if (!(tableName in tableNamesHash)) {
685 if (self.visibleView === tableViews[tableName])
686 self.closeVisibleView();
687 delete tableViews[tableName];
157 } 688 }
158 this._databaseModel.removeEventListener(WebInspector.DatabaseModel.Event s.DatabaseAdded, this._databaseAdded, this); 689 }
159 this._databaseModel.removeEventListener(WebInspector.DatabaseModel.Event s.DatabasesRemoved, this._resetWebSQL, this); 690 }
160 691 database.getTableNames(tableNamesCallback);
161 this._resetWithFrames(); 692 }
162 }, 693
163 694 /**
164 /** 695 * @param {!WebInspector.DOMStorageModel} domStorageModel
165 * @override 696 */
166 */ 697 _populateDOMStorageTree(domStorageModel) {
167 focus: function() 698 domStorageModel.enable();
168 { 699 domStorageModel.storages().forEach(this._addDOMStorage.bind(this));
169 this._sidebarTree.focus(); 700 domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOMStor ageAdded, this._domStorageAdded, this);
170 }, 701 domStorageModel.addEventListener(
171 702 WebInspector.DOMStorageModel.Events.DOMStorageRemoved, this._domStorageR emoved, this);
172 _initialize: function() 703 }
173 { 704
174 this._databaseModel.enable(); 705 /**
175 706 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel
176 var indexedDBModel = WebInspector.IndexedDBModel.fromTarget(this._target ); 707 */
177 if (indexedDBModel) 708 _populateApplicationCacheTree(resourceTreeModel) {
178 indexedDBModel.enable(); 709 this._applicationCacheModel = new WebInspector.ApplicationCacheModel(this._t arget, resourceTreeModel);
179 710
180 var cacheStorageModel = WebInspector.ServiceWorkerCacheModel.fromTarget( this._target); 711 this._applicationCacheViews = {};
181 if (cacheStorageModel) 712 this._applicationCacheFrameElements = {};
182 cacheStorageModel.enable(); 713 this._applicationCacheManifestElements = {};
183 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this._ target); 714
184 if (resourceTreeModel) { 715 this._applicationCacheModel.addEventListener(
185 this._populateResourceTree(resourceTreeModel); 716 WebInspector.ApplicationCacheModel.Events.FrameManifestAdded, this._appl icationCacheFrameManifestAdded, this);
186 this._populateApplicationCacheTree(resourceTreeModel); 717 this._applicationCacheModel.addEventListener(
187 } 718 WebInspector.ApplicationCacheModel.Events.FrameManifestRemoved, this._ap plicationCacheFrameManifestRemoved,
188 var domStorageModel = WebInspector.DOMStorageModel.fromTarget(this._targ et); 719 this);
189 if (domStorageModel) 720 this._applicationCacheModel.addEventListener(
190 this._populateDOMStorageTree(domStorageModel); 721 WebInspector.ApplicationCacheModel.Events.FrameManifestsReset, this._res etAppCache, this);
191 this.indexedDBListTreeElement._initialize(); 722
192 this.cacheStorageListTreeElement._initialize(); 723 this._applicationCacheModel.addEventListener(
193 this._initDefaultSelection(); 724 WebInspector.ApplicationCacheModel.Events.FrameManifestStatusUpdated,
194 }, 725 this._applicationCacheFrameManifestStatusChanged, this);
195 726 this._applicationCacheModel.addEventListener(
196 _initDefaultSelection: function() 727 WebInspector.ApplicationCacheModel.Events.NetworkStateChanged, this._app licationCacheNetworkStateChanged, this);
197 { 728 }
198 var itemURL = this._resourcesLastSelectedItemSetting.get(); 729
199 if (itemURL) { 730 _applicationCacheFrameManifestAdded(event) {
200 var rootElement = this._sidebarTree.rootElement(); 731 var frameId = event.data;
201 for (var treeElement = rootElement.firstChild(); treeElement; treeEl ement = treeElement.traverseNextTreeElement(false, rootElement, true)) { 732 var manifestURL = this._applicationCacheModel.frameManifestURL(frameId);
202 if (treeElement.itemURL === itemURL) { 733
203 treeElement.revealAndSelect(true); 734 var manifestTreeElement = this._applicationCacheManifestElements[manifestURL ];
204 return; 735 if (!manifestTreeElement) {
205 } 736 manifestTreeElement = new WebInspector.ApplicationCacheManifestTreeElement (this, manifestURL);
206 } 737 this.applicationCacheListTreeElement.appendChild(manifestTreeElement);
207 } 738 this._applicationCacheManifestElements[manifestURL] = manifestTreeElement;
208 this._manifestTreeElement.select(); 739 }
209 }, 740
210 741 var frameTreeElement = new WebInspector.ApplicationCacheFrameTreeElement(thi s, frameId, manifestURL);
211 _resetWithFrames: function() 742 manifestTreeElement.appendChild(frameTreeElement);
212 { 743 manifestTreeElement.expand();
213 this.resourcesListTreeElement.removeChildren(); 744 this._applicationCacheFrameElements[frameId] = frameTreeElement;
214 this._treeElementForFrameId = {}; 745 }
215 this._reset(); 746
216 }, 747 _applicationCacheFrameManifestRemoved(event) {
217 748 var frameId = event.data;
218 _resetWebSQL: function() 749 var frameTreeElement = this._applicationCacheFrameElements[frameId];
219 { 750 if (!frameTreeElement)
220 if (this.visibleView instanceof WebInspector.DatabaseQueryView || this.v isibleView instanceof WebInspector.DatabaseTableView) { 751 return;
221 this.visibleView.detach(); 752
222 delete this.visibleView; 753 var manifestURL = frameTreeElement.manifestURL;
223 } 754 delete this._applicationCacheFrameElements[frameId];
224 755 delete this._applicationCacheViews[frameId];
225 var queryViews = this._databaseQueryViews.valuesArray(); 756 frameTreeElement.parent.removeChild(frameTreeElement);
226 for (var i = 0; i < queryViews.length; ++i) 757
227 queryViews[i].removeEventListener(WebInspector.DatabaseQueryView.Eve nts.SchemaUpdated, this._updateDatabaseTables, this); 758 var manifestTreeElement = this._applicationCacheManifestElements[manifestURL ];
228 this._databaseTableViews.clear(); 759 if (manifestTreeElement.childCount())
229 this._databaseQueryViews.clear(); 760 return;
230 this._databaseTreeElements.clear(); 761
231 this.databasesListTreeElement.removeChildren(); 762 delete this._applicationCacheManifestElements[manifestURL];
232 this.databasesListTreeElement.setExpandable(false); 763 manifestTreeElement.parent.removeChild(manifestTreeElement);
233 }, 764 }
234 765
235 _resetDOMStorage: function() 766 _applicationCacheFrameManifestStatusChanged(event) {
236 { 767 var frameId = event.data;
237 if (this.visibleView instanceof WebInspector.DOMStorageItemsView) { 768 var status = this._applicationCacheModel.frameManifestStatus(frameId);
238 this.visibleView.detach(); 769
239 delete this.visibleView; 770 if (this._applicationCacheViews[frameId])
240 } 771 this._applicationCacheViews[frameId].updateStatus(status);
241 772 }
242 this._domStorageViews.clear(); 773
243 this._domStorageTreeElements.clear(); 774 _applicationCacheNetworkStateChanged(event) {
244 this.localStorageListTreeElement.removeChildren(); 775 var isNowOnline = event.data;
245 this.sessionStorageListTreeElement.removeChildren(); 776
246 }, 777 for (var manifestURL in this._applicationCacheViews)
247 778 this._applicationCacheViews[manifestURL].updateNetworkState(isNowOnline);
248 _resetCookies: function() 779 }
249 { 780
250 if (this.visibleView instanceof WebInspector.CookieItemsView) { 781 _findTreeElementForResource(resource) {
251 this.visibleView.detach(); 782 return resource[WebInspector.FrameResourceTreeElement._symbol];
252 delete this.visibleView; 783 }
253 } 784
254 this._cookieViews = {}; 785 showView(view) {
255 this.cookieListTreeElement.removeChildren(); 786 if (view)
256 }, 787 this.showResource(view.resource);
257 788 }
258 _resetCacheStorage: function() 789
259 { 790 _onmousemove(event) {
260 if (this.visibleView instanceof WebInspector.ServiceWorkerCacheView) { 791 var nodeUnderMouse = event.target;
261 this.visibleView.detach(); 792 if (!nodeUnderMouse)
262 delete this.visibleView; 793 return;
263 } 794
264 this.cacheStorageListTreeElement.removeChildren(); 795 var listNode = nodeUnderMouse.enclosingNodeOrSelfWithNodeName('li');
265 this.cacheStorageListTreeElement.setExpandable(false); 796 if (!listNode)
266 }, 797 return;
267 798
268 _resetAppCache: function() 799 var element = listNode.treeElement;
269 { 800 if (this._previousHoveredElement === element)
270 for (var frameId of Object.keys(this._applicationCacheFrameElements)) 801 return;
271 this._applicationCacheFrameManifestRemoved({data: frameId}); 802
272 this.applicationCacheListTreeElement.setExpandable(false); 803 if (this._previousHoveredElement) {
273 }, 804 this._previousHoveredElement.hovered = false;
274 805 delete this._previousHoveredElement;
275 _reset: function() 806 }
276 { 807
277 this._domains = {}; 808 if (element instanceof WebInspector.FrameTreeElement) {
278 this._resetWebSQL(); 809 this._previousHoveredElement = element;
279 this._resetDOMStorage(); 810 element.hovered = true;
280 this._resetCookies(); 811 }
281 this._resetCacheStorage(); 812 }
282 // No need to this._resetAppCache. 813
283 814 _onmouseleave(event) {
284 if ((this.visibleView instanceof WebInspector.ResourceSourceFrame) 815 if (this._previousHoveredElement) {
285 || (this.visibleView instanceof WebInspector.ImageView) 816 this._previousHoveredElement.hovered = false;
286 || (this.visibleView instanceof WebInspector.FontView)) { 817 delete this._previousHoveredElement;
287 this.visibleView.detach(); 818 }
288 delete this.visibleView; 819 }
289 } 820 };
290 821
291 this._storageViewToolbar.removeToolbarItems(); 822 /**
292
293 if (this._sidebarTree.selectedTreeElement)
294 this._sidebarTree.selectedTreeElement.deselect();
295 },
296
297 /**
298 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel
299 */
300 _populateResourceTree: function(resourceTreeModel)
301 {
302 this._treeElementForFrameId = {};
303 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .FrameAdded, this._frameAdded, this);
304 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .FrameNavigated, this._frameNavigated, this);
305 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .FrameDetached, this._frameDetached, this);
306 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .ResourceAdded, this._resourceAdded, this);
307
308 /**
309 * @param {!WebInspector.ResourceTreeFrame} frame
310 * @this {WebInspector.ResourcesPanel}
311 */
312 function populateFrame(frame)
313 {
314 this._frameAdded({data:frame});
315 for (var i = 0; i < frame.childFrames.length; ++i)
316 populateFrame.call(this, frame.childFrames[i]);
317
318 var resources = frame.resources();
319 for (var i = 0; i < resources.length; ++i)
320 this._resourceAdded({data:resources[i]});
321 }
322 populateFrame.call(this, resourceTreeModel.mainFrame);
323 },
324
325 _frameAdded: function(event)
326 {
327 var frame = event.data;
328 var parentFrame = frame.parentFrame;
329
330 var parentTreeElement = parentFrame ? this._treeElementForFrameId[parent Frame.id] : this.resourcesListTreeElement;
331 if (!parentTreeElement) {
332 console.warn("No frame to route " + frame.url + " to.");
333 return;
334 }
335
336 var frameTreeElement = new WebInspector.FrameTreeElement(this, frame);
337 this._treeElementForFrameId[frame.id] = frameTreeElement;
338 parentTreeElement.appendChild(frameTreeElement);
339 },
340
341 _frameDetached: function(event)
342 {
343 var frame = event.data;
344 var frameTreeElement = this._treeElementForFrameId[frame.id];
345 if (!frameTreeElement)
346 return;
347
348 delete this._treeElementForFrameId[frame.id];
349 if (frameTreeElement.parent)
350 frameTreeElement.parent.removeChild(frameTreeElement);
351 },
352
353 _resourceAdded: function(event)
354 {
355 var resource = event.data;
356 var frameId = resource.frameId;
357
358 if (resource.statusCode >= 301 && resource.statusCode <= 303)
359 return;
360
361 var frameTreeElement = this._treeElementForFrameId[frameId];
362 if (!frameTreeElement) {
363 // This is a frame's main resource, it will be retained
364 // and re-added by the resource manager;
365 return;
366 }
367
368 frameTreeElement.appendResource(resource);
369 },
370
371 _frameNavigated: function(event)
372 {
373 var frame = event.data;
374
375 if (!frame.parentFrame)
376 this._reset();
377
378 var frameId = frame.id;
379 var frameTreeElement = this._treeElementForFrameId[frameId];
380 if (frameTreeElement)
381 frameTreeElement.frameNavigated(frame);
382
383 var applicationCacheFrameTreeElement = this._applicationCacheFrameElemen ts[frameId];
384 if (applicationCacheFrameTreeElement)
385 applicationCacheFrameTreeElement.frameNavigated(frame);
386 },
387
388 /**
389 * @param {!WebInspector.Event} event
390 */
391 _databaseAdded: function(event)
392 {
393 var database = /** @type {!WebInspector.Database} */ (event.data);
394 this._addDatabase(database);
395 },
396
397 /**
398 * @param {!WebInspector.Database} database
399 */
400 _addDatabase: function(database)
401 {
402 var databaseTreeElement = new WebInspector.DatabaseTreeElement(this, dat abase);
403 this._databaseTreeElements.set(database, databaseTreeElement);
404 this.databasesListTreeElement.appendChild(databaseTreeElement);
405 },
406
407 addDocumentURL: function(url)
408 {
409 var parsedURL = url.asParsedURL();
410 if (!parsedURL)
411 return;
412
413 var domain = parsedURL.securityOrigin();
414 if (!this._domains[domain]) {
415 this._domains[domain] = true;
416 var cookieDomainTreeElement = new WebInspector.CookieTreeElement(thi s, domain);
417 this.cookieListTreeElement.appendChild(cookieDomainTreeElement);
418 }
419 },
420
421 /**
422 * @param {!WebInspector.Event} event
423 */
424 _domStorageAdded: function(event)
425 {
426 var domStorage = /** @type {!WebInspector.DOMStorage} */ (event.data);
427 this._addDOMStorage(domStorage);
428 },
429
430 /**
431 * @param {!WebInspector.DOMStorage} domStorage
432 */
433 _addDOMStorage: function(domStorage)
434 {
435 console.assert(!this._domStorageTreeElements.get(domStorage));
436
437 var domStorageTreeElement = new WebInspector.DOMStorageTreeElement(this, domStorage);
438 this._domStorageTreeElements.set(domStorage, domStorageTreeElement);
439 if (domStorage.isLocalStorage)
440 this.localStorageListTreeElement.appendChild(domStorageTreeElement);
441 else
442 this.sessionStorageListTreeElement.appendChild(domStorageTreeElement );
443 },
444
445 /**
446 * @param {!WebInspector.Event} event
447 */
448 _domStorageRemoved: function(event)
449 {
450 var domStorage = /** @type {!WebInspector.DOMStorage} */ (event.data);
451 this._removeDOMStorage(domStorage);
452 },
453
454 /**
455 * @param {!WebInspector.DOMStorage} domStorage
456 */
457 _removeDOMStorage: function(domStorage)
458 {
459 var treeElement = this._domStorageTreeElements.get(domStorage);
460 if (!treeElement)
461 return;
462 var wasSelected = treeElement.selected;
463 var parentListTreeElement = treeElement.parent;
464 parentListTreeElement.removeChild(treeElement);
465 if (wasSelected)
466 parentListTreeElement.select();
467 this._domStorageTreeElements.remove(domStorage);
468 this._domStorageViews.remove(domStorage);
469 },
470
471 /**
472 * @param {!WebInspector.Database} database
473 */
474 selectDatabase: function(database)
475 {
476 if (database) {
477 this._showDatabase(database);
478 this._databaseTreeElements.get(database).select();
479 }
480 },
481
482 /**
483 * @param {!WebInspector.DOMStorage} domStorage
484 */
485 selectDOMStorage: function(domStorage)
486 {
487 if (domStorage) {
488 this._showDOMStorage(domStorage);
489 this._domStorageTreeElements.get(domStorage).select();
490 }
491 },
492
493 /**
494 * @param {!WebInspector.Resource} resource
495 * @param {number=} line
496 * @param {number=} column
497 * @return {boolean}
498 */
499 showResource: function(resource, line, column)
500 {
501 var resourceTreeElement = this._findTreeElementForResource(resource);
502 if (resourceTreeElement)
503 resourceTreeElement.revealAndSelect(true);
504
505 if (typeof line === "number") {
506 var resourceSourceFrame = this._resourceSourceFrameViewForResource(r esource);
507 if (resourceSourceFrame)
508 resourceSourceFrame.revealPosition(line, column, true);
509 }
510 return true;
511 },
512
513 _showResourceView: function(resource)
514 {
515 var view = this._resourceViewForResource(resource);
516 if (!view) {
517 this.visibleView.detach();
518 return;
519 }
520 this._innerShowView(view);
521 },
522
523 /**
524 * @param {!WebInspector.Resource} resource
525 * @return {?WebInspector.Widget}
526 */
527 _resourceViewForResource: function(resource)
528 {
529 if (resource.hasTextContent()) {
530 var treeElement = this._findTreeElementForResource(resource);
531 if (!treeElement)
532 return null;
533 return treeElement.sourceView();
534 }
535
536 switch (resource.resourceType()) {
537 case WebInspector.resourceTypes.Image:
538 return new WebInspector.ImageView(resource.mimeType, resource);
539 case WebInspector.resourceTypes.Font:
540 return new WebInspector.FontView(resource.mimeType, resource);
541 default:
542 return new WebInspector.EmptyWidget(resource.url);
543 }
544 },
545
546 /**
547 * @param {!WebInspector.Resource} resource
548 * @return {?WebInspector.ResourceSourceFrame}
549 */
550 _resourceSourceFrameViewForResource: function(resource)
551 {
552 var resourceView = this._resourceViewForResource(resource);
553 if (resourceView && resourceView instanceof WebInspector.ResourceSourceF rame)
554 return /** @type {!WebInspector.ResourceSourceFrame} */ (resourceVie w);
555 return null;
556 },
557
558 /**
559 * @param {!WebInspector.Database} database
560 * @param {string=} tableName
561 */
562 _showDatabase: function(database, tableName)
563 {
564 if (!database)
565 return;
566
567 var view;
568 if (tableName) {
569 var tableViews = this._databaseTableViews.get(database);
570 if (!tableViews) {
571 tableViews = /** @type {!Object.<string, !WebInspector.DatabaseT ableView>} */ ({});
572 this._databaseTableViews.set(database, tableViews);
573 }
574 view = tableViews[tableName];
575 if (!view) {
576 view = new WebInspector.DatabaseTableView(database, tableName);
577 tableViews[tableName] = view;
578 }
579 } else {
580 view = this._databaseQueryViews.get(database);
581 if (!view) {
582 view = new WebInspector.DatabaseQueryView(database);
583 this._databaseQueryViews.set(database, view);
584 view.addEventListener(WebInspector.DatabaseQueryView.Events.Sche maUpdated, this._updateDatabaseTables, this);
585 }
586 }
587
588 this._innerShowView(view);
589 },
590
591 /**
592 * @param {!WebInspector.DOMStorage} domStorage
593 */
594 _showDOMStorage: function(domStorage)
595 {
596 if (!domStorage)
597 return;
598
599 var view;
600 view = this._domStorageViews.get(domStorage);
601 if (!view) {
602 view = new WebInspector.DOMStorageItemsView(domStorage);
603 this._domStorageViews.set(domStorage, view);
604 }
605
606 this._innerShowView(view);
607 },
608
609 /**
610 * @param {!WebInspector.CookieTreeElement} treeElement
611 * @param {string} cookieDomain
612 */
613 showCookies: function(treeElement, cookieDomain)
614 {
615 var view = this._cookieViews[cookieDomain];
616 if (!view) {
617 view = new WebInspector.CookieItemsView(treeElement, cookieDomain);
618 this._cookieViews[cookieDomain] = view;
619 }
620
621 this._innerShowView(view);
622 },
623
624 /**
625 * @param {string} cookieDomain
626 */
627 clearCookies: function(cookieDomain)
628 {
629 if (this._cookieViews[cookieDomain])
630 this._cookieViews[cookieDomain].clear();
631 },
632
633 showApplicationCache: function(frameId)
634 {
635 if (!this._applicationCacheViews[frameId])
636 this._applicationCacheViews[frameId] = new WebInspector.ApplicationC acheItemsView(this._applicationCacheModel, frameId);
637
638 this._innerShowView(this._applicationCacheViews[frameId]);
639 },
640
641 /**
642 * @param {!WebInspector.Widget} view
643 */
644 showFileSystem: function(view)
645 {
646 this._innerShowView(view);
647 },
648
649 showCategoryView: function(categoryName)
650 {
651 if (!this._categoryView)
652 this._categoryView = new WebInspector.StorageCategoryView();
653 this._categoryView.setText(categoryName);
654 this._innerShowView(this._categoryView);
655 },
656
657 _innerShowView: function(view)
658 {
659 if (this.visibleView === view)
660 return;
661
662 if (this.visibleView)
663 this.visibleView.detach();
664
665 view.show(this.storageViews);
666 this.visibleView = view;
667
668 this._storageViewToolbar.removeToolbarItems();
669 var toolbarItems = view instanceof WebInspector.SimpleView ? view.syncTo olbarItems() : null;
670 for (var i = 0; toolbarItems && i < toolbarItems.length; ++i)
671 this._storageViewToolbar.appendToolbarItem(toolbarItems[i]);
672 },
673
674 closeVisibleView: function()
675 {
676 if (!this.visibleView)
677 return;
678 this.visibleView.detach();
679 delete this.visibleView;
680 },
681
682 _updateDatabaseTables: function(event)
683 {
684 var database = event.data;
685
686 if (!database)
687 return;
688
689 var databasesTreeElement = this._databaseTreeElements.get(database);
690 if (!databasesTreeElement)
691 return;
692
693 databasesTreeElement.invalidateChildren();
694 var tableViews = this._databaseTableViews.get(database);
695
696 if (!tableViews)
697 return;
698
699 var tableNamesHash = {};
700 var self = this;
701 function tableNamesCallback(tableNames)
702 {
703 var tableNamesLength = tableNames.length;
704 for (var i = 0; i < tableNamesLength; ++i)
705 tableNamesHash[tableNames[i]] = true;
706
707 for (var tableName in tableViews) {
708 if (!(tableName in tableNamesHash)) {
709 if (self.visibleView === tableViews[tableName])
710 self.closeVisibleView();
711 delete tableViews[tableName];
712 }
713 }
714 }
715 database.getTableNames(tableNamesCallback);
716 },
717
718 /**
719 * @param {!WebInspector.DOMStorageModel} domStorageModel
720 */
721 _populateDOMStorageTree: function(domStorageModel)
722 {
723 domStorageModel.enable();
724 domStorageModel.storages().forEach(this._addDOMStorage.bind(this));
725 domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOM StorageAdded, this._domStorageAdded, this);
726 domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOM StorageRemoved, this._domStorageRemoved, this);
727 },
728
729 /**
730 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel
731 */
732 _populateApplicationCacheTree: function(resourceTreeModel)
733 {
734 this._applicationCacheModel = new WebInspector.ApplicationCacheModel(thi s._target, resourceTreeModel);
735
736 this._applicationCacheViews = {};
737 this._applicationCacheFrameElements = {};
738 this._applicationCacheManifestElements = {};
739
740 this._applicationCacheModel.addEventListener(WebInspector.ApplicationCac heModel.Events.FrameManifestAdded, this._applicationCacheFrameManifestAdded, thi s);
741 this._applicationCacheModel.addEventListener(WebInspector.ApplicationCac heModel.Events.FrameManifestRemoved, this._applicationCacheFrameManifestRemoved, this);
742 this._applicationCacheModel.addEventListener(WebInspector.ApplicationCac heModel.Events.FrameManifestsReset, this._resetAppCache, this);
743
744 this._applicationCacheModel.addEventListener(WebInspector.ApplicationCac heModel.Events.FrameManifestStatusUpdated, this._applicationCacheFrameManifestSt atusChanged, this);
745 this._applicationCacheModel.addEventListener(WebInspector.ApplicationCac heModel.Events.NetworkStateChanged, this._applicationCacheNetworkStateChanged, t his);
746 },
747
748 _applicationCacheFrameManifestAdded: function(event)
749 {
750 var frameId = event.data;
751 var manifestURL = this._applicationCacheModel.frameManifestURL(frameId);
752
753 var manifestTreeElement = this._applicationCacheManifestElements[manifes tURL];
754 if (!manifestTreeElement) {
755 manifestTreeElement = new WebInspector.ApplicationCacheManifestTreeE lement(this, manifestURL);
756 this.applicationCacheListTreeElement.appendChild(manifestTreeElement );
757 this._applicationCacheManifestElements[manifestURL] = manifestTreeEl ement;
758 }
759
760 var frameTreeElement = new WebInspector.ApplicationCacheFrameTreeElement (this, frameId, manifestURL);
761 manifestTreeElement.appendChild(frameTreeElement);
762 manifestTreeElement.expand();
763 this._applicationCacheFrameElements[frameId] = frameTreeElement;
764 },
765
766 _applicationCacheFrameManifestRemoved: function(event)
767 {
768 var frameId = event.data;
769 var frameTreeElement = this._applicationCacheFrameElements[frameId];
770 if (!frameTreeElement)
771 return;
772
773 var manifestURL = frameTreeElement.manifestURL;
774 delete this._applicationCacheFrameElements[frameId];
775 delete this._applicationCacheViews[frameId];
776 frameTreeElement.parent.removeChild(frameTreeElement);
777
778 var manifestTreeElement = this._applicationCacheManifestElements[manifes tURL];
779 if (manifestTreeElement.childCount())
780 return;
781
782 delete this._applicationCacheManifestElements[manifestURL];
783 manifestTreeElement.parent.removeChild(manifestTreeElement);
784 },
785
786 _applicationCacheFrameManifestStatusChanged: function(event)
787 {
788 var frameId = event.data;
789 var status = this._applicationCacheModel.frameManifestStatus(frameId);
790
791 if (this._applicationCacheViews[frameId])
792 this._applicationCacheViews[frameId].updateStatus(status);
793 },
794
795 _applicationCacheNetworkStateChanged: function(event)
796 {
797 var isNowOnline = event.data;
798
799 for (var manifestURL in this._applicationCacheViews)
800 this._applicationCacheViews[manifestURL].updateNetworkState(isNowOnl ine);
801 },
802
803 _findTreeElementForResource: function(resource)
804 {
805 return resource[WebInspector.FrameResourceTreeElement._symbol];
806 },
807
808 showView: function(view)
809 {
810 if (view)
811 this.showResource(view.resource);
812 },
813
814 _onmousemove: function(event)
815 {
816 var nodeUnderMouse = event.target;
817 if (!nodeUnderMouse)
818 return;
819
820 var listNode = nodeUnderMouse.enclosingNodeOrSelfWithNodeName("li");
821 if (!listNode)
822 return;
823
824 var element = listNode.treeElement;
825 if (this._previousHoveredElement === element)
826 return;
827
828 if (this._previousHoveredElement) {
829 this._previousHoveredElement.hovered = false;
830 delete this._previousHoveredElement;
831 }
832
833 if (element instanceof WebInspector.FrameTreeElement) {
834 this._previousHoveredElement = element;
835 element.hovered = true;
836 }
837 },
838
839 _onmouseleave: function(event)
840 {
841 if (this._previousHoveredElement) {
842 this._previousHoveredElement.hovered = false;
843 delete this._previousHoveredElement;
844 }
845 },
846
847 __proto__: WebInspector.PanelWithSidebar.prototype
848 };
849
850 /**
851 * @constructor
852 * @implements {WebInspector.Revealer} 823 * @implements {WebInspector.Revealer}
853 */ 824 * @unrestricted
854 WebInspector.ResourcesPanel.ResourceRevealer = function() 825 */
855 { 826 WebInspector.ResourcesPanel.ResourceRevealer = class {
856 }; 827 /**
857 828 * @override
858 WebInspector.ResourcesPanel.ResourceRevealer.prototype = { 829 * @param {!Object} resource
859 /** 830 * @return {!Promise}
860 * @override 831 */
861 * @param {!Object} resource 832 reveal(resource) {
862 * @return {!Promise} 833 if (!(resource instanceof WebInspector.Resource))
863 */ 834 return Promise.reject(new Error('Internal error: not a resource'));
864 reveal: function(resource) 835 var panel = WebInspector.ResourcesPanel._instance();
865 { 836 return WebInspector.viewManager.showView('resources').then(panel.showResourc e.bind(panel, resource));
866 if (!(resource instanceof WebInspector.Resource)) 837 }
867 return Promise.reject(new Error("Internal error: not a resource")); 838 };
868 var panel = WebInspector.ResourcesPanel._instance(); 839
869 return WebInspector.viewManager.showView("resources").then(panel.showRes ource.bind(panel, resource)); 840 /**
870 } 841 * @unrestricted
871 }; 842 */
872 843 WebInspector.BaseStorageTreeElement = class extends TreeElement {
873 /** 844 /**
874 * @constructor 845 * @param {!WebInspector.ResourcesPanel} storagePanel
875 * @extends {TreeElement} 846 * @param {string} title
876 * @param {!WebInspector.ResourcesPanel} storagePanel 847 * @param {?Array.<string>=} iconClasses
877 * @param {string} title 848 * @param {boolean=} expandable
878 * @param {?Array.<string>=} iconClasses 849 * @param {boolean=} noIcon
879 * @param {boolean=} expandable 850 */
880 * @param {boolean=} noIcon 851 constructor(storagePanel, title, iconClasses, expandable, noIcon) {
881 */ 852 super(title, expandable);
882 WebInspector.BaseStorageTreeElement = function(storagePanel, title, iconClasses, expandable, noIcon)
883 {
884 TreeElement.call(this, title, expandable);
885 this._storagePanel = storagePanel; 853 this._storagePanel = storagePanel;
886 for (var i = 0; iconClasses && i < iconClasses.length; ++i) 854 for (var i = 0; iconClasses && i < iconClasses.length; ++i)
887 this.listItemElement.classList.add(iconClasses[i]); 855 this.listItemElement.classList.add(iconClasses[i]);
888 856
889 this._iconClasses = iconClasses; 857 this._iconClasses = iconClasses;
890 if (!noIcon) 858 if (!noIcon)
891 this.createIcon(); 859 this.createIcon();
892 }; 860 }
893 861
894 WebInspector.BaseStorageTreeElement.prototype = { 862 /**
895 /** 863 * @override
896 * @override 864 * @return {boolean}
897 * @return {boolean} 865 */
898 */ 866 onselect(selectedByUser) {
899 onselect: function(selectedByUser) 867 if (!selectedByUser)
900 { 868 return false;
901 if (!selectedByUser) 869 var itemURL = this.itemURL;
902 return false; 870 if (itemURL)
903 var itemURL = this.itemURL; 871 this._storagePanel._resourcesLastSelectedItemSetting.set(itemURL);
904 if (itemURL) 872 return false;
905 this._storagePanel._resourcesLastSelectedItemSetting.set(itemURL); 873 }
906 return false; 874 };
907 }, 875
908 876 /**
909 __proto__: TreeElement.prototype 877 * @unrestricted
910 }; 878 */
911 879 WebInspector.StorageCategoryTreeElement = class extends WebInspector.BaseStorage TreeElement {
912 /** 880 /**
913 * @constructor 881 * @param {!WebInspector.ResourcesPanel} storagePanel
914 * @extends {WebInspector.BaseStorageTreeElement} 882 * @param {string} categoryName
915 * @param {!WebInspector.ResourcesPanel} storagePanel 883 * @param {string} settingsKey
916 * @param {string} categoryName 884 * @param {?Array.<string>=} iconClasses
917 * @param {string} settingsKey 885 * @param {boolean=} noIcon
918 * @param {?Array.<string>=} iconClasses 886 */
919 * @param {boolean=} noIcon 887 constructor(storagePanel, categoryName, settingsKey, iconClasses, noIcon) {
920 */ 888 super(storagePanel, categoryName, iconClasses, false, noIcon);
921 WebInspector.StorageCategoryTreeElement = function(storagePanel, categoryName, s ettingsKey, iconClasses, noIcon) 889 this._expandedSetting =
922 { 890 WebInspector.settings.createSetting('resources' + settingsKey + 'Expande d', settingsKey === 'Frames');
923 WebInspector.BaseStorageTreeElement.call(this, storagePanel, categoryName, i conClasses, false, noIcon);
924 this._expandedSetting = WebInspector.settings.createSetting("resources" + se ttingsKey + "Expanded", settingsKey === "Frames");
925 this._categoryName = categoryName; 891 this._categoryName = categoryName;
926 }; 892 }
927 893
928 WebInspector.StorageCategoryTreeElement.prototype = { 894 /**
929 /** 895 * @return {!WebInspector.Target}
930 * @return {!WebInspector.Target} 896 */
931 */ 897 target() {
932 target: function() 898 return this._storagePanel._target;
933 { 899 }
934 return this._storagePanel._target; 900
935 }, 901 get itemURL() {
936 902 return 'category://' + this._categoryName;
937 get itemURL() 903 }
938 { 904
939 return "category://" + this._categoryName; 905 /**
940 }, 906 * @override
941 907 * @return {boolean}
942 /** 908 */
943 * @override 909 onselect(selectedByUser) {
944 * @return {boolean} 910 super.onselect(selectedByUser);
945 */ 911 this._storagePanel.showCategoryView(this._categoryName);
946 onselect: function(selectedByUser) 912 return false;
947 { 913 }
948 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 914
949 this._storagePanel.showCategoryView(this._categoryName); 915 /**
950 return false; 916 * @override
951 }, 917 */
952 918 onattach() {
953 /** 919 super.onattach();
954 * @override 920 if (this._expandedSetting.get())
955 */ 921 this.expand();
956 onattach: function() 922 }
957 { 923
958 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this); 924 /**
959 if (this._expandedSetting.get()) 925 * @override
960 this.expand(); 926 */
961 }, 927 onexpand() {
962 928 this._expandedSetting.set(true);
963 /** 929 }
964 * @override 930
965 */ 931 /**
966 onexpand: function() 932 * @override
967 { 933 */
968 this._expandedSetting.set(true); 934 oncollapse() {
969 }, 935 this._expandedSetting.set(false);
970 936 }
971 /** 937 };
972 * @override 938
973 */ 939 /**
974 oncollapse: function() 940 * @unrestricted
975 { 941 */
976 this._expandedSetting.set(false); 942 WebInspector.FrameTreeElement = class extends WebInspector.BaseStorageTreeElemen t {
977 }, 943 /**
978 944 * @param {!WebInspector.ResourcesPanel} storagePanel
979 __proto__: WebInspector.BaseStorageTreeElement.prototype 945 * @param {!WebInspector.ResourceTreeFrame} frame
980 }; 946 */
981 947 constructor(storagePanel, frame) {
982 /** 948 super(storagePanel, '', ['navigator-tree-item', 'navigator-frame-tree-item'] );
983 * @constructor
984 * @extends {WebInspector.BaseStorageTreeElement}
985 * @param {!WebInspector.ResourcesPanel} storagePanel
986 * @param {!WebInspector.ResourceTreeFrame} frame
987 */
988 WebInspector.FrameTreeElement = function(storagePanel, frame)
989 {
990 WebInspector.BaseStorageTreeElement.call(this, storagePanel, "", ["navigator -tree-item", "navigator-frame-tree-item"]);
991 this._frame = frame; 949 this._frame = frame;
992 this.frameNavigated(frame); 950 this.frameNavigated(frame);
993 }; 951 }
994 952
995 WebInspector.FrameTreeElement.prototype = { 953 frameNavigated(frame) {
996 frameNavigated: function(frame) 954 this.removeChildren();
997 { 955 this._frameId = frame.id;
998 this.removeChildren(); 956 this.title = frame.displayName();
999 this._frameId = frame.id; 957 this._categoryElements = {};
1000 this.title = frame.displayName(); 958 this._treeElementForResource = {};
1001 this._categoryElements = {}; 959
1002 this._treeElementForResource = {}; 960 this._storagePanel.addDocumentURL(frame.url);
1003 961 }
1004 this._storagePanel.addDocumentURL(frame.url); 962
1005 }, 963 get itemURL() {
1006 964 return 'frame://' + encodeURI(this.titleAsText());
1007 get itemURL() 965 }
1008 { 966
1009 return "frame://" + encodeURI(this.titleAsText()); 967 /**
1010 }, 968 * @override
1011 969 * @return {boolean}
1012 /** 970 */
1013 * @override 971 onselect(selectedByUser) {
1014 * @return {boolean} 972 super.onselect(selectedByUser);
1015 */ 973 this._storagePanel.showCategoryView(this.titleAsText());
1016 onselect: function(selectedByUser) 974
1017 { 975 this.listItemElement.classList.remove('hovered');
1018 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 976 WebInspector.DOMModel.hideDOMNodeHighlight();
1019 this._storagePanel.showCategoryView(this.titleAsText()); 977 return false;
1020 978 }
1021 this.listItemElement.classList.remove("hovered"); 979
1022 WebInspector.DOMModel.hideDOMNodeHighlight(); 980 set hovered(hovered) {
1023 return false; 981 if (hovered) {
1024 }, 982 this.listItemElement.classList.add('hovered');
1025 983 var domModel = WebInspector.DOMModel.fromTarget(this._frame.target());
1026 set hovered(hovered) 984 if (domModel)
1027 { 985 domModel.highlightFrame(this._frameId);
1028 if (hovered) { 986 } else {
1029 this.listItemElement.classList.add("hovered"); 987 this.listItemElement.classList.remove('hovered');
1030 var domModel = WebInspector.DOMModel.fromTarget(this._frame.target() ); 988 WebInspector.DOMModel.hideDOMNodeHighlight();
1031 if (domModel) 989 }
1032 domModel.highlightFrame(this._frameId); 990 }
1033 } else { 991
1034 this.listItemElement.classList.remove("hovered"); 992 /**
1035 WebInspector.DOMModel.hideDOMNodeHighlight(); 993 * @param {!WebInspector.Resource} resource
1036 } 994 */
1037 }, 995 appendResource(resource) {
1038 996 var resourceType = resource.resourceType();
1039 /** 997 var categoryName = resourceType.name();
1040 * @param {!WebInspector.Resource} resource 998 var categoryElement =
1041 */ 999 resourceType === WebInspector.resourceTypes.Document ? this : this._cate goryElements[categoryName];
1042 appendResource: function(resource) 1000 if (!categoryElement) {
1043 { 1001 categoryElement = new WebInspector.StorageCategoryTreeElement(
1044 var resourceType = resource.resourceType(); 1002 this._storagePanel, resource.resourceType().category().title, category Name, null, true);
1045 var categoryName = resourceType.name(); 1003 this._categoryElements[resourceType.name()] = categoryElement;
1046 var categoryElement = resourceType === WebInspector.resourceTypes.Docume nt ? this : this._categoryElements[categoryName]; 1004 this._insertInPresentationOrder(this, categoryElement);
1047 if (!categoryElement) { 1005 }
1048 categoryElement = new WebInspector.StorageCategoryTreeElement(this._ storagePanel, resource.resourceType().category().title, categoryName, null, true ); 1006 var resourceTreeElement = new WebInspector.FrameResourceTreeElement(this._st oragePanel, resource);
1049 this._categoryElements[resourceType.name()] = categoryElement; 1007 this._insertInPresentationOrder(categoryElement, resourceTreeElement);
1050 this._insertInPresentationOrder(this, categoryElement); 1008 this._treeElementForResource[resource.url] = resourceTreeElement;
1051 } 1009 }
1052 var resourceTreeElement = new WebInspector.FrameResourceTreeElement(this ._storagePanel, resource); 1010
1053 this._insertInPresentationOrder(categoryElement, resourceTreeElement); 1011 /**
1054 this._treeElementForResource[resource.url] = resourceTreeElement; 1012 * @param {string} url
1055 }, 1013 * @return {?WebInspector.Resource}
1056 1014 */
1057 /** 1015 resourceByURL(url) {
1058 * @param {string} url 1016 var treeElement = this._treeElementForResource[url];
1059 * @return {?WebInspector.Resource} 1017 return treeElement ? treeElement._resource : null;
1060 */ 1018 }
1061 resourceByURL: function(url) 1019
1062 { 1020 /**
1063 var treeElement = this._treeElementForResource[url]; 1021 * @override
1064 return treeElement ? treeElement._resource : null; 1022 */
1065 }, 1023 appendChild(treeElement) {
1066 1024 this._insertInPresentationOrder(this, treeElement);
1067 appendChild: function(treeElement) 1025 }
1068 { 1026
1069 this._insertInPresentationOrder(this, treeElement); 1027 _insertInPresentationOrder(parentTreeElement, childTreeElement) {
1070 }, 1028 // Insert in the alphabetical order, first frames, then resources. Document resource goes last.
1071 1029 function typeWeight(treeElement) {
1072 _insertInPresentationOrder: function(parentTreeElement, childTreeElement) 1030 if (treeElement instanceof WebInspector.StorageCategoryTreeElement)
1073 { 1031 return 2;
1074 // Insert in the alphabetical order, first frames, then resources. Docum ent resource goes last. 1032 if (treeElement instanceof WebInspector.FrameTreeElement)
1075 function typeWeight(treeElement) 1033 return 1;
1076 { 1034 return 3;
1077 if (treeElement instanceof WebInspector.StorageCategoryTreeElement) 1035 }
1078 return 2; 1036
1079 if (treeElement instanceof WebInspector.FrameTreeElement) 1037 function compare(treeElement1, treeElement2) {
1080 return 1; 1038 var typeWeight1 = typeWeight(treeElement1);
1081 return 3; 1039 var typeWeight2 = typeWeight(treeElement2);
1082 } 1040
1083 1041 var result;
1084 function compare(treeElement1, treeElement2) 1042 if (typeWeight1 > typeWeight2)
1085 { 1043 result = 1;
1086 var typeWeight1 = typeWeight(treeElement1); 1044 else if (typeWeight1 < typeWeight2)
1087 var typeWeight2 = typeWeight(treeElement2); 1045 result = -1;
1088 1046 else
1089 var result; 1047 result = treeElement1.titleAsText().localeCompare(treeElement2.titleAsTe xt());
1090 if (typeWeight1 > typeWeight2) 1048 return result;
1091 result = 1; 1049 }
1092 else if (typeWeight1 < typeWeight2) 1050
1093 result = -1; 1051 var childCount = parentTreeElement.childCount();
1094 else 1052 var i;
1095 result = treeElement1.titleAsText().localeCompare(treeElement2.t itleAsText()); 1053 for (i = 0; i < childCount; ++i) {
1096 return result; 1054 if (compare(childTreeElement, parentTreeElement.childAt(i)) < 0)
1097 } 1055 break;
1098 1056 }
1099 var childCount = parentTreeElement.childCount(); 1057 parentTreeElement.insertChild(childTreeElement, i);
1100 var i; 1058 }
1101 for (i = 0; i < childCount; ++i) { 1059 };
1102 if (compare(childTreeElement, parentTreeElement.childAt(i)) < 0) 1060
1103 break; 1061 /**
1104 } 1062 * @unrestricted
1105 parentTreeElement.insertChild(childTreeElement, i); 1063 */
1106 }, 1064 WebInspector.FrameResourceTreeElement = class extends WebInspector.BaseStorageTr eeElement {
1107 1065 /**
1108 __proto__: WebInspector.BaseStorageTreeElement.prototype 1066 * @param {!WebInspector.ResourcesPanel} storagePanel
1109 }; 1067 * @param {!WebInspector.Resource} resource
1110 1068 */
1111 /** 1069 constructor(storagePanel, resource) {
1112 * @constructor 1070 super(storagePanel, resource.displayName, [
1113 * @extends {WebInspector.BaseStorageTreeElement} 1071 'navigator-tree-item', 'navigator-file-tree-item', 'navigator-' + resource .resourceType().name() + '-tree-item'
1114 * @param {!WebInspector.ResourcesPanel} storagePanel 1072 ]);
1115 * @param {!WebInspector.Resource} resource
1116 */
1117 WebInspector.FrameResourceTreeElement = function(storagePanel, resource)
1118 {
1119 WebInspector.BaseStorageTreeElement.call(this, storagePanel, resource.displa yName, ["navigator-tree-item", "navigator-file-tree-item", "navigator-" + resour ce.resourceType().name() + "-tree-item"]);
1120 /** @type {!WebInspector.Resource} */ 1073 /** @type {!WebInspector.Resource} */
1121 this._resource = resource; 1074 this._resource = resource;
1122 this.tooltip = resource.url; 1075 this.tooltip = resource.url;
1123 this._resource[WebInspector.FrameResourceTreeElement._symbol] = this; 1076 this._resource[WebInspector.FrameResourceTreeElement._symbol] = this;
1124 }; 1077 }
1125 1078
1126 WebInspector.FrameResourceTreeElement._symbol = Symbol("treeElement"); 1079 get itemURL() {
1127 1080 return this._resource.url;
1128 WebInspector.FrameResourceTreeElement.prototype = { 1081 }
1129 get itemURL() 1082
1130 { 1083 /**
1131 return this._resource.url; 1084 * @override
1132 }, 1085 * @return {boolean}
1086 */
1087 onselect(selectedByUser) {
1088 super.onselect(selectedByUser);
1089 this._storagePanel._showResourceView(this._resource);
1090 return false;
1091 }
1092
1093 /**
1094 * @override
1095 * @return {boolean}
1096 */
1097 ondblclick(event) {
1098 InspectorFrontendHost.openInNewTab(this._resource.url);
1099 return false;
1100 }
1101
1102 /**
1103 * @override
1104 */
1105 onattach() {
1106 super.onattach();
1107 this.listItemElement.draggable = true;
1108 this.listItemElement.addEventListener('dragstart', this._ondragstart.bind(th is), false);
1109 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1110 }
1111
1112 /**
1113 * @param {!MouseEvent} event
1114 * @return {boolean}
1115 */
1116 _ondragstart(event) {
1117 event.dataTransfer.setData('text/plain', this._resource.content || '');
1118 event.dataTransfer.effectAllowed = 'copy';
1119 return true;
1120 }
1121
1122 _handleContextMenuEvent(event) {
1123 var contextMenu = new WebInspector.ContextMenu(event);
1124 contextMenu.appendApplicableItems(this._resource);
1125 contextMenu.show();
1126 }
1127
1128 /**
1129 * @return {!WebInspector.ResourceSourceFrame}
1130 */
1131 sourceView() {
1132 if (!this._sourceView) {
1133 var sourceFrame = new WebInspector.ResourceSourceFrame(this._resource);
1134 sourceFrame.setHighlighterType(this._resource.canonicalMimeType());
1135 this._sourceView = sourceFrame;
1136 }
1137 return this._sourceView;
1138 }
1139 };
1140
1141 WebInspector.FrameResourceTreeElement._symbol = Symbol('treeElement');
1142
1143 /**
1144 * @unrestricted
1145 */
1146 WebInspector.DatabaseTreeElement = class extends WebInspector.BaseStorageTreeEle ment {
1147 /**
1148 * @param {!WebInspector.ResourcesPanel} storagePanel
1149 * @param {!WebInspector.Database} database
1150 */
1151 constructor(storagePanel, database) {
1152 super(storagePanel, database.name, ['database-tree-item', 'resource-tree-ite m'], true);
1153 this._database = database;
1154 }
1155
1156 get itemURL() {
1157 return 'database://' + encodeURI(this._database.name);
1158 }
1159
1160 /**
1161 * @override
1162 * @return {boolean}
1163 */
1164 onselect(selectedByUser) {
1165 super.onselect(selectedByUser);
1166 this._storagePanel._showDatabase(this._database);
1167 return false;
1168 }
1169
1170 /**
1171 * @override
1172 */
1173 onexpand() {
1174 this._updateChildren();
1175 }
1176
1177 _updateChildren() {
1178 this.removeChildren();
1133 1179
1134 /** 1180 /**
1135 * @override 1181 * @param {!Array.<string>} tableNames
1136 * @return {boolean} 1182 * @this {WebInspector.DatabaseTreeElement}
1137 */ 1183 */
1138 onselect: function(selectedByUser) 1184 function tableNamesCallback(tableNames) {
1139 { 1185 var tableNamesLength = tableNames.length;
1140 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1186 for (var i = 0; i < tableNamesLength; ++i)
1141 this._storagePanel._showResourceView(this._resource); 1187 this.appendChild(new WebInspector.DatabaseTableTreeElement(this._storage Panel, this._database, tableNames[i]));
1142 return false; 1188 }
1143 }, 1189 this._database.getTableNames(tableNamesCallback.bind(this));
1144 1190 }
1145 /** 1191 };
1146 * @override 1192
1147 * @return {boolean} 1193 /**
1148 */ 1194 * @unrestricted
1149 ondblclick: function(event) 1195 */
1150 { 1196 WebInspector.DatabaseTableTreeElement = class extends WebInspector.BaseStorageTr eeElement {
1151 InspectorFrontendHost.openInNewTab(this._resource.url); 1197 constructor(storagePanel, database, tableName) {
1152 return false; 1198 super(storagePanel, tableName, ['table-tree-item', 'resource-tree-item']);
1153 },
1154
1155 /**
1156 * @override
1157 */
1158 onattach: function()
1159 {
1160 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
1161 this.listItemElement.draggable = true;
1162 this.listItemElement.addEventListener("dragstart", this._ondragstart.bin d(this), false);
1163 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true);
1164 },
1165
1166 /**
1167 * @param {!MouseEvent} event
1168 * @return {boolean}
1169 */
1170 _ondragstart: function(event)
1171 {
1172 event.dataTransfer.setData("text/plain", this._resource.content || "");
1173 event.dataTransfer.effectAllowed = "copy";
1174 return true;
1175 },
1176
1177 _handleContextMenuEvent: function(event)
1178 {
1179 var contextMenu = new WebInspector.ContextMenu(event);
1180 contextMenu.appendApplicableItems(this._resource);
1181 contextMenu.show();
1182 },
1183
1184 /**
1185 * @return {!WebInspector.ResourceSourceFrame}
1186 */
1187 sourceView: function()
1188 {
1189 if (!this._sourceView) {
1190 var sourceFrame = new WebInspector.ResourceSourceFrame(this._resourc e);
1191 sourceFrame.setHighlighterType(this._resource.canonicalMimeType());
1192 this._sourceView = sourceFrame;
1193 }
1194 return this._sourceView;
1195 },
1196
1197 __proto__: WebInspector.BaseStorageTreeElement.prototype
1198 };
1199
1200 /**
1201 * @constructor
1202 * @extends {WebInspector.BaseStorageTreeElement}
1203 * @param {!WebInspector.ResourcesPanel} storagePanel
1204 * @param {!WebInspector.Database} database
1205 */
1206 WebInspector.DatabaseTreeElement = function(storagePanel, database)
1207 {
1208 WebInspector.BaseStorageTreeElement.call(this, storagePanel, database.name, ["database-tree-item", "resource-tree-item"], true);
1209 this._database = database;
1210 };
1211
1212 WebInspector.DatabaseTreeElement.prototype = {
1213 get itemURL()
1214 {
1215 return "database://" + encodeURI(this._database.name);
1216 },
1217
1218 /**
1219 * @override
1220 * @return {boolean}
1221 */
1222 onselect: function(selectedByUser)
1223 {
1224 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser);
1225 this._storagePanel._showDatabase(this._database);
1226 return false;
1227 },
1228
1229 /**
1230 * @override
1231 */
1232 onexpand: function()
1233 {
1234 this._updateChildren();
1235 },
1236
1237 _updateChildren: function()
1238 {
1239 this.removeChildren();
1240
1241 /**
1242 * @param {!Array.<string>} tableNames
1243 * @this {WebInspector.DatabaseTreeElement}
1244 */
1245 function tableNamesCallback(tableNames)
1246 {
1247 var tableNamesLength = tableNames.length;
1248 for (var i = 0; i < tableNamesLength; ++i)
1249 this.appendChild(new WebInspector.DatabaseTableTreeElement(this. _storagePanel, this._database, tableNames[i]));
1250 }
1251 this._database.getTableNames(tableNamesCallback.bind(this));
1252 },
1253
1254 __proto__: WebInspector.BaseStorageTreeElement.prototype
1255 };
1256
1257 /**
1258 * @constructor
1259 * @extends {WebInspector.BaseStorageTreeElement}
1260 */
1261 WebInspector.DatabaseTableTreeElement = function(storagePanel, database, tableNa me)
1262 {
1263 WebInspector.BaseStorageTreeElement.call(this, storagePanel, tableName, ["ta ble-tree-item", "resource-tree-item"]);
1264 this._database = database; 1199 this._database = database;
1265 this._tableName = tableName; 1200 this._tableName = tableName;
1266 }; 1201 }
1267 1202
1268 WebInspector.DatabaseTableTreeElement.prototype = { 1203 get itemURL() {
1269 get itemURL() 1204 return 'database://' + encodeURI(this._database.name) + '/' + encodeURI(this ._tableName);
1270 { 1205 }
1271 return "database://" + encodeURI(this._database.name) + "/" + encodeURI( this._tableName); 1206
1272 }, 1207 /**
1273 1208 * @override
1274 /** 1209 * @return {boolean}
1275 * @override 1210 */
1276 * @return {boolean} 1211 onselect(selectedByUser) {
1277 */ 1212 super.onselect(selectedByUser);
1278 onselect: function(selectedByUser) 1213 this._storagePanel._showDatabase(this._database, this._tableName);
1279 { 1214 return false;
1280 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1215 }
1281 this._storagePanel._showDatabase(this._database, this._tableName); 1216 };
1282 return false; 1217
1283 }, 1218 /**
1284 1219 * @unrestricted
1285 __proto__: WebInspector.BaseStorageTreeElement.prototype 1220 */
1286 }; 1221 WebInspector.ServiceWorkerCacheTreeElement = class extends WebInspector.StorageC ategoryTreeElement {
1287 1222 /**
1288 1223 * @param {!WebInspector.ResourcesPanel} storagePanel
1289 /** 1224 */
1290 * @constructor 1225 constructor(storagePanel) {
1291 * @extends {WebInspector.StorageCategoryTreeElement} 1226 super(
1292 * @param {!WebInspector.ResourcesPanel} storagePanel 1227 storagePanel, WebInspector.UIString('Cache Storage'), 'CacheStorage',
1293 */ 1228 ['database-tree-item', 'resource-tree-item']);
1294 WebInspector.ServiceWorkerCacheTreeElement = function(storagePanel) 1229 }
1295 { 1230
1296 WebInspector.StorageCategoryTreeElement.call(this, storagePanel, WebInspecto r.UIString("Cache Storage"), "CacheStorage", ["database-tree-item", "resource-tr ee-item"]); 1231 _initialize() {
1297 }; 1232 /** @type {!Array.<!WebInspector.SWCacheTreeElement>} */
1298 1233 this._swCacheTreeElements = [];
1299 WebInspector.ServiceWorkerCacheTreeElement.prototype = { 1234 var target = this._storagePanel._target;
1300 _initialize: function() 1235 var model = target && WebInspector.ServiceWorkerCacheModel.fromTarget(target );
1301 { 1236 if (model) {
1302 /** @type {!Array.<!WebInspector.SWCacheTreeElement>} */ 1237 for (var cache of model.caches())
1303 this._swCacheTreeElements = [];
1304 var target = this._storagePanel._target;
1305 var model = target && WebInspector.ServiceWorkerCacheModel.fromTarget(ta rget);
1306 if (model) {
1307 for (var cache of model.caches())
1308 this._addCache(model, cache);
1309 }
1310 WebInspector.targetManager.addModelListener(WebInspector.ServiceWorkerCa cheModel, WebInspector.ServiceWorkerCacheModel.Events.CacheAdded, this._cacheAdd ed, this);
1311 WebInspector.targetManager.addModelListener(WebInspector.ServiceWorkerCa cheModel, WebInspector.ServiceWorkerCacheModel.Events.CacheRemoved, this._cacheR emoved, this);
1312 },
1313
1314 onattach: function()
1315 {
1316 WebInspector.StorageCategoryTreeElement.prototype.onattach.call(this);
1317 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true);
1318 },
1319
1320 _handleContextMenuEvent: function(event)
1321 {
1322 var contextMenu = new WebInspector.ContextMenu(event);
1323 contextMenu.appendItem(WebInspector.UIString("Refresh Caches"), this._re freshCaches.bind(this));
1324 contextMenu.show();
1325 },
1326
1327 _refreshCaches: function()
1328 {
1329 var target = this._storagePanel._target;
1330 if (target) {
1331 var model = WebInspector.ServiceWorkerCacheModel.fromTarget(target);
1332 if (!model)
1333 return;
1334 model.refreshCacheNames();
1335 }
1336 },
1337
1338 /**
1339 * @param {!WebInspector.Event} event
1340 */
1341 _cacheAdded: function(event)
1342 {
1343 var cache = /** @type {!WebInspector.ServiceWorkerCacheModel.Cache} */ ( event.data);
1344 var model = /** @type {!WebInspector.ServiceWorkerCacheModel} */ (event. target);
1345 this._addCache(model, cache); 1238 this._addCache(model, cache);
1346 }, 1239 }
1347 1240 WebInspector.targetManager.addModelListener(
1348 /** 1241 WebInspector.ServiceWorkerCacheModel, WebInspector.ServiceWorkerCacheMod el.Events.CacheAdded, this._cacheAdded,
1349 * @param {!WebInspector.ServiceWorkerCacheModel} model 1242 this);
1350 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache 1243 WebInspector.targetManager.addModelListener(
1351 */ 1244 WebInspector.ServiceWorkerCacheModel, WebInspector.ServiceWorkerCacheMod el.Events.CacheRemoved,
1352 _addCache: function(model, cache) 1245 this._cacheRemoved, this);
1353 { 1246 }
1354 var swCacheTreeElement = new WebInspector.SWCacheTreeElement(this._stora gePanel, model, cache); 1247
1355 this._swCacheTreeElements.push(swCacheTreeElement); 1248 /**
1356 this.appendChild(swCacheTreeElement); 1249 * @override
1357 }, 1250 */
1358 1251 onattach() {
1359 /** 1252 super.onattach();
1360 * @param {!WebInspector.Event} event 1253 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1361 */ 1254 }
1362 _cacheRemoved: function(event) 1255
1363 { 1256 _handleContextMenuEvent(event) {
1364 var cache = /** @type {!WebInspector.ServiceWorkerCacheModel.Cache} */ ( event.data); 1257 var contextMenu = new WebInspector.ContextMenu(event);
1365 var model = /** @type {!WebInspector.ServiceWorkerCacheModel} */ (event. target); 1258 contextMenu.appendItem(WebInspector.UIString('Refresh Caches'), this._refres hCaches.bind(this));
1366 1259 contextMenu.show();
1367 var swCacheTreeElement = this._cacheTreeElement(model, cache); 1260 }
1368 if (!swCacheTreeElement) 1261
1369 return; 1262 _refreshCaches() {
1370 1263 var target = this._storagePanel._target;
1371 swCacheTreeElement.clear(); 1264 if (target) {
1372 this.removeChild(swCacheTreeElement); 1265 var model = WebInspector.ServiceWorkerCacheModel.fromTarget(target);
1373 this._swCacheTreeElements.remove(swCacheTreeElement); 1266 if (!model)
1374 }, 1267 return;
1375 1268 model.refreshCacheNames();
1376 /** 1269 }
1377 * @param {!WebInspector.ServiceWorkerCacheModel} model 1270 }
1378 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache 1271
1379 * @return {?WebInspector.SWCacheTreeElement} 1272 /**
1380 */ 1273 * @param {!WebInspector.Event} event
1381 _cacheTreeElement: function(model, cache) 1274 */
1382 { 1275 _cacheAdded(event) {
1383 var index = -1; 1276 var cache = /** @type {!WebInspector.ServiceWorkerCacheModel.Cache} */ (even t.data);
1384 for (var i = 0; i < this._swCacheTreeElements.length; ++i) { 1277 var model = /** @type {!WebInspector.ServiceWorkerCacheModel} */ (event.targ et);
1385 if (this._swCacheTreeElements[i]._cache.equals(cache) && this._swCac heTreeElements[i]._model === model) { 1278 this._addCache(model, cache);
1386 index = i; 1279 }
1387 break; 1280
1388 } 1281 /**
1389 } 1282 * @param {!WebInspector.ServiceWorkerCacheModel} model
1390 if (index !== -1) 1283 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
1391 return this._swCacheTreeElements[i]; 1284 */
1392 return null; 1285 _addCache(model, cache) {
1393 }, 1286 var swCacheTreeElement = new WebInspector.SWCacheTreeElement(this._storagePa nel, model, cache);
1394 1287 this._swCacheTreeElements.push(swCacheTreeElement);
1395 __proto__: WebInspector.StorageCategoryTreeElement.prototype 1288 this.appendChild(swCacheTreeElement);
1396 }; 1289 }
1397 1290
1398 /** 1291 /**
1399 * @constructor 1292 * @param {!WebInspector.Event} event
1400 * @extends {WebInspector.BaseStorageTreeElement} 1293 */
1401 * @param {!WebInspector.ResourcesPanel} storagePanel 1294 _cacheRemoved(event) {
1402 * @param {!WebInspector.ServiceWorkerCacheModel} model 1295 var cache = /** @type {!WebInspector.ServiceWorkerCacheModel.Cache} */ (even t.data);
1403 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache 1296 var model = /** @type {!WebInspector.ServiceWorkerCacheModel} */ (event.targ et);
1404 */ 1297
1405 WebInspector.SWCacheTreeElement = function(storagePanel, model, cache) 1298 var swCacheTreeElement = this._cacheTreeElement(model, cache);
1406 { 1299 if (!swCacheTreeElement)
1407 WebInspector.BaseStorageTreeElement.call(this, storagePanel, cache.cacheName + " - " + cache.securityOrigin, ["table-tree-item", "resource-tree-item"]); 1300 return;
1301
1302 swCacheTreeElement.clear();
1303 this.removeChild(swCacheTreeElement);
1304 this._swCacheTreeElements.remove(swCacheTreeElement);
1305 }
1306
1307 /**
1308 * @param {!WebInspector.ServiceWorkerCacheModel} model
1309 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
1310 * @return {?WebInspector.SWCacheTreeElement}
1311 */
1312 _cacheTreeElement(model, cache) {
1313 var index = -1;
1314 for (var i = 0; i < this._swCacheTreeElements.length; ++i) {
1315 if (this._swCacheTreeElements[i]._cache.equals(cache) && this._swCacheTree Elements[i]._model === model) {
1316 index = i;
1317 break;
1318 }
1319 }
1320 if (index !== -1)
1321 return this._swCacheTreeElements[i];
1322 return null;
1323 }
1324 };
1325
1326 /**
1327 * @unrestricted
1328 */
1329 WebInspector.SWCacheTreeElement = class extends WebInspector.BaseStorageTreeElem ent {
1330 /**
1331 * @param {!WebInspector.ResourcesPanel} storagePanel
1332 * @param {!WebInspector.ServiceWorkerCacheModel} model
1333 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
1334 */
1335 constructor(storagePanel, model, cache) {
1336 super(storagePanel, cache.cacheName + ' - ' + cache.securityOrigin, ['table- tree-item', 'resource-tree-item']);
1408 this._model = model; 1337 this._model = model;
1409 this._cache = cache; 1338 this._cache = cache;
1410 }; 1339 }
1411 1340
1412 WebInspector.SWCacheTreeElement.prototype = { 1341 get itemURL() {
1413 get itemURL() 1342 // I don't think this will work at all.
1414 { 1343 return 'cache://' + this._cache.cacheId;
1415 // I don't think this will work at all. 1344 }
1416 return "cache://" + this._cache.cacheId; 1345
1417 }, 1346 /**
1418 1347 * @override
1419 onattach: function() 1348 */
1420 { 1349 onattach() {
1421 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this); 1350 super.onattach();
1422 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true); 1351 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1423 }, 1352 }
1424 1353
1425 _handleContextMenuEvent: function(event) 1354 _handleContextMenuEvent(event) {
1426 { 1355 var contextMenu = new WebInspector.ContextMenu(event);
1427 var contextMenu = new WebInspector.ContextMenu(event); 1356 contextMenu.appendItem(WebInspector.UIString('Delete'), this._clearCache.bin d(this));
1428 contextMenu.appendItem(WebInspector.UIString("Delete"), this._clearCache .bind(this)); 1357 contextMenu.show();
1429 contextMenu.show(); 1358 }
1430 }, 1359
1431 1360 _clearCache() {
1432 _clearCache: function() 1361 this._model.deleteCache(this._cache);
1433 { 1362 }
1434 this._model.deleteCache(this._cache); 1363
1435 }, 1364 /**
1436 1365 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
1437 /** 1366 */
1438 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache 1367 update(cache) {
1439 */ 1368 this._cache = cache;
1440 update: function(cache) 1369 if (this._view)
1441 { 1370 this._view.update(cache);
1442 this._cache = cache; 1371 }
1443 if (this._view) 1372
1444 this._view.update(cache); 1373 /**
1445 }, 1374 * @override
1446 1375 * @return {boolean}
1447 /** 1376 */
1448 * @override 1377 onselect(selectedByUser) {
1449 * @return {boolean} 1378 super.onselect(selectedByUser);
1450 */ 1379 if (!this._view)
1451 onselect: function(selectedByUser) 1380 this._view = new WebInspector.ServiceWorkerCacheView(this._model, this._ca che);
1452 { 1381
1453 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1382 this._storagePanel._innerShowView(this._view);
1454 if (!this._view) 1383 return false;
1455 this._view = new WebInspector.ServiceWorkerCacheView(this._model, th is._cache); 1384 }
1456 1385
1457 this._storagePanel._innerShowView(this._view); 1386 clear() {
1458 return false; 1387 if (this._view)
1459 }, 1388 this._view.clear();
1460 1389 }
1461 clear: function() 1390 };
1462 { 1391
1463 if (this._view) 1392 /**
1464 this._view.clear(); 1393 * @unrestricted
1465 }, 1394 */
1466 1395 WebInspector.ServiceWorkersTreeElement = class extends WebInspector.BaseStorageT reeElement {
1467 __proto__: WebInspector.BaseStorageTreeElement.prototype 1396 /**
1468 }; 1397 * @param {!WebInspector.ResourcesPanel} storagePanel
1469 1398 */
1470 1399 constructor(storagePanel) {
1471 /** 1400 super(
1472 * @constructor 1401 storagePanel, WebInspector.UIString('Service Workers'), ['service-worker -tree-item', 'resource-tree-item'],
1473 * @extends {WebInspector.BaseStorageTreeElement} 1402 false);
1474 * @param {!WebInspector.ResourcesPanel} storagePanel 1403 }
1475 */ 1404
1476 WebInspector.ServiceWorkersTreeElement = function(storagePanel) 1405 /**
1477 { 1406 * @return {string}
1478 WebInspector.BaseStorageTreeElement.call(this, storagePanel, WebInspector.UI String("Service Workers"), ["service-worker-tree-item", "resource-tree-item"], f alse); 1407 */
1479 }; 1408 get itemURL() {
1480 1409 return 'service-workers://';
1481 WebInspector.ServiceWorkersTreeElement.prototype = { 1410 }
1482 /** 1411
1483 * @return {string} 1412 /**
1484 */ 1413 * @override
1485 get itemURL() 1414 * @return {boolean}
1486 { 1415 */
1487 return "service-workers://"; 1416 onselect(selectedByUser) {
1488 }, 1417 super.onselect(selectedByUser);
1489 1418 if (!this._view)
1490 /** 1419 this._view = new WebInspector.ServiceWorkersView();
1491 * @override 1420 this._storagePanel._innerShowView(this._view);
1492 * @return {boolean} 1421 return false;
1493 */ 1422 }
1494 onselect: function(selectedByUser) 1423 };
1495 { 1424
1496 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1425 /**
1497 if (!this._view) 1426 * @unrestricted
1498 this._view = new WebInspector.ServiceWorkersView(); 1427 */
1499 this._storagePanel._innerShowView(this._view); 1428 WebInspector.AppManifestTreeElement = class extends WebInspector.BaseStorageTree Element {
1500 return false; 1429 /**
1501 }, 1430 * @param {!WebInspector.ResourcesPanel} storagePanel
1502 1431 */
1503 __proto__: WebInspector.BaseStorageTreeElement.prototype 1432 constructor(storagePanel) {
1504 }; 1433 super(storagePanel, WebInspector.UIString('Manifest'), ['manifest-tree-item' , 'resource-tree-item'], false, false);
1505 1434 }
1506 /** 1435
1507 * @constructor 1436 /**
1508 * @extends {WebInspector.BaseStorageTreeElement} 1437 * @return {string}
1509 * @param {!WebInspector.ResourcesPanel} storagePanel 1438 */
1510 */ 1439 get itemURL() {
1511 WebInspector.AppManifestTreeElement = function(storagePanel) 1440 return 'manifest://';
1512 { 1441 }
1513 WebInspector.BaseStorageTreeElement.call(this, storagePanel, WebInspector.UI String("Manifest"), ["manifest-tree-item", "resource-tree-item"], false, false); 1442
1514 }; 1443 /**
1515 1444 * @override
1516 WebInspector.AppManifestTreeElement.prototype = { 1445 * @return {boolean}
1517 /** 1446 */
1518 * @return {string} 1447 onselect(selectedByUser) {
1519 */ 1448 super.onselect(selectedByUser);
1520 get itemURL() 1449 if (!this._view)
1521 { 1450 this._view = new WebInspector.AppManifestView();
1522 return "manifest://"; 1451 this._storagePanel._innerShowView(this._view);
1523 }, 1452 return false;
1524 1453 }
1525 /** 1454 };
1526 * @override 1455
1527 * @return {boolean} 1456 /**
1528 */ 1457 * @unrestricted
1529 onselect: function(selectedByUser) 1458 */
1530 { 1459 WebInspector.ClearStorageTreeElement = class extends WebInspector.BaseStorageTre eElement {
1531 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1460 /**
1532 if (!this._view) 1461 * @param {!WebInspector.ResourcesPanel} storagePanel
1533 this._view = new WebInspector.AppManifestView(); 1462 */
1534 this._storagePanel._innerShowView(this._view); 1463 constructor(storagePanel) {
1535 return false; 1464 super(
1536 }, 1465 storagePanel, WebInspector.UIString('Clear storage'), ['clear-storage-tr ee-item', 'resource-tree-item'], false,
1537 1466 false);
1538 __proto__: WebInspector.BaseStorageTreeElement.prototype 1467 }
1539 }; 1468
1540 1469 /**
1541 /** 1470 * @return {string}
1542 * @constructor 1471 */
1543 * @extends {WebInspector.BaseStorageTreeElement} 1472 get itemURL() {
1544 * @param {!WebInspector.ResourcesPanel} storagePanel 1473 return 'clear-storage://';
1545 */ 1474 }
1546 WebInspector.ClearStorageTreeElement = function(storagePanel) 1475
1547 { 1476 /**
1548 WebInspector.BaseStorageTreeElement.call(this, storagePanel, WebInspector.UI String("Clear storage"), ["clear-storage-tree-item", "resource-tree-item"], fals e, false); 1477 * @override
1549 }; 1478 * @return {boolean}
1550 1479 */
1551 WebInspector.ClearStorageTreeElement.prototype = { 1480 onselect(selectedByUser) {
1552 /** 1481 super.onselect(selectedByUser);
1553 * @return {string} 1482 if (!this._view)
1554 */ 1483 this._view = new WebInspector.ClearStorageView(this._storagePanel);
1555 get itemURL() 1484 this._storagePanel._innerShowView(this._view);
1556 { 1485 return false;
1557 return "clear-storage://"; 1486 }
1558 }, 1487 };
1559 1488
1560 /** 1489 /**
1561 * @override 1490 * @unrestricted
1562 * @return {boolean} 1491 */
1563 */ 1492 WebInspector.IndexedDBTreeElement = class extends WebInspector.StorageCategoryTr eeElement {
1564 onselect: function(selectedByUser) 1493 /**
1565 { 1494 * @param {!WebInspector.ResourcesPanel} storagePanel
1566 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1495 */
1567 if (!this._view) 1496 constructor(storagePanel) {
1568 this._view = new WebInspector.ClearStorageView(this._storagePanel); 1497 super(storagePanel, WebInspector.UIString('IndexedDB'), 'IndexedDB', ['datab ase-tree-item', 'resource-tree-item']);
1569 this._storagePanel._innerShowView(this._view); 1498 }
1570 return false; 1499
1571 }, 1500 _initialize() {
1572 1501 WebInspector.targetManager.addModelListener(
1573 __proto__: WebInspector.BaseStorageTreeElement.prototype 1502 WebInspector.IndexedDBModel, WebInspector.IndexedDBModel.Events.Database Added, this._indexedDBAdded, this);
1574 }; 1503 WebInspector.targetManager.addModelListener(
1575 1504 WebInspector.IndexedDBModel, WebInspector.IndexedDBModel.Events.Database Removed, this._indexedDBRemoved, this);
1576 /** 1505 WebInspector.targetManager.addModelListener(
1577 * @constructor 1506 WebInspector.IndexedDBModel, WebInspector.IndexedDBModel.Events.Database Loaded, this._indexedDBLoaded, this);
1578 * @extends {WebInspector.StorageCategoryTreeElement} 1507 /** @type {!Array.<!WebInspector.IDBDatabaseTreeElement>} */
1579 * @param {!WebInspector.ResourcesPanel} storagePanel 1508 this._idbDatabaseTreeElements = [];
1580 */ 1509
1581 WebInspector.IndexedDBTreeElement = function(storagePanel) 1510 var targets = WebInspector.targetManager.targets(WebInspector.Target.Capabil ity.Browser);
1582 { 1511 for (var i = 0; i < targets.length; ++i) {
1583 WebInspector.StorageCategoryTreeElement.call(this, storagePanel, WebInspecto r.UIString("IndexedDB"), "IndexedDB", ["database-tree-item", "resource-tree-item "]); 1512 var indexedDBModel = WebInspector.IndexedDBModel.fromTarget(targets[i]);
1584 }; 1513 var databases = indexedDBModel.databases();
1585 1514 for (var j = 0; j < databases.length; ++j)
1586 WebInspector.IndexedDBTreeElement.prototype = { 1515 this._addIndexedDB(indexedDBModel, databases[j]);
1587 _initialize: function() 1516 }
1588 { 1517 }
1589 WebInspector.targetManager.addModelListener(WebInspector.IndexedDBModel, WebInspector.IndexedDBModel.Events.DatabaseAdded, this._indexedDBAdded, this); 1518
1590 WebInspector.targetManager.addModelListener(WebInspector.IndexedDBModel, WebInspector.IndexedDBModel.Events.DatabaseRemoved, this._indexedDBRemoved, thi s); 1519 /**
1591 WebInspector.targetManager.addModelListener(WebInspector.IndexedDBModel, WebInspector.IndexedDBModel.Events.DatabaseLoaded, this._indexedDBLoaded, this) ; 1520 * @override
1592 /** @type {!Array.<!WebInspector.IDBDatabaseTreeElement>} */ 1521 */
1593 this._idbDatabaseTreeElements = []; 1522 onattach() {
1594 1523 super.onattach();
1595 var targets = WebInspector.targetManager.targets(WebInspector.Target.Cap ability.Browser); 1524 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1596 for (var i = 0; i < targets.length; ++i) { 1525 }
1597 var indexedDBModel = WebInspector.IndexedDBModel.fromTarget(targets[ i]); 1526
1598 var databases = indexedDBModel.databases(); 1527 _handleContextMenuEvent(event) {
1599 for (var j = 0; j < databases.length; ++j) 1528 var contextMenu = new WebInspector.ContextMenu(event);
1600 this._addIndexedDB(indexedDBModel, databases[j]); 1529 contextMenu.appendItem(WebInspector.UIString('Refresh IndexedDB'), this.refr eshIndexedDB.bind(this));
1601 } 1530 contextMenu.show();
1602 }, 1531 }
1603 1532
1604 onattach: function() 1533 refreshIndexedDB() {
1605 { 1534 var targets = WebInspector.targetManager.targets(WebInspector.Target.Capabil ity.Browser);
1606 WebInspector.StorageCategoryTreeElement.prototype.onattach.call(this); 1535 for (var i = 0; i < targets.length; ++i)
1607 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true); 1536 WebInspector.IndexedDBModel.fromTarget(targets[i]).refreshDatabaseNames();
1608 }, 1537 }
1609 1538
1610 _handleContextMenuEvent: function(event) 1539 /**
1611 { 1540 * @param {!WebInspector.Event} event
1612 var contextMenu = new WebInspector.ContextMenu(event); 1541 */
1613 contextMenu.appendItem(WebInspector.UIString("Refresh IndexedDB"), this. refreshIndexedDB.bind(this)); 1542 _indexedDBAdded(event) {
1614 contextMenu.show(); 1543 var databaseId = /** @type {!WebInspector.IndexedDBModel.DatabaseId} */ (eve nt.data);
1615 }, 1544 var model = /** @type {!WebInspector.IndexedDBModel} */ (event.target);
1616 1545 this._addIndexedDB(model, databaseId);
1617 refreshIndexedDB: function() 1546 }
1618 { 1547
1619 var targets = WebInspector.targetManager.targets(WebInspector.Target.Cap ability.Browser); 1548 /**
1620 for (var i = 0; i < targets.length; ++i) 1549 * @param {!WebInspector.IndexedDBModel} model
1621 WebInspector.IndexedDBModel.fromTarget(targets[i]).refreshDatabaseNa mes(); 1550 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1622 }, 1551 */
1623 1552 _addIndexedDB(model, databaseId) {
1624 /** 1553 var idbDatabaseTreeElement = new WebInspector.IDBDatabaseTreeElement(this._s toragePanel, model, databaseId);
1625 * @param {!WebInspector.Event} event 1554 this._idbDatabaseTreeElements.push(idbDatabaseTreeElement);
1626 */ 1555 this.appendChild(idbDatabaseTreeElement);
1627 _indexedDBAdded: function(event) 1556 model.refreshDatabase(databaseId);
1628 { 1557 }
1629 var databaseId = /** @type {!WebInspector.IndexedDBModel.DatabaseId} */ (event.data); 1558
1630 var model = /** @type {!WebInspector.IndexedDBModel} */ (event.target); 1559 /**
1631 this._addIndexedDB(model, databaseId); 1560 * @param {!WebInspector.Event} event
1632 }, 1561 */
1633 1562 _indexedDBRemoved(event) {
1634 /** 1563 var databaseId = /** @type {!WebInspector.IndexedDBModel.DatabaseId} */ (eve nt.data);
1635 * @param {!WebInspector.IndexedDBModel} model 1564 var model = /** @type {!WebInspector.IndexedDBModel} */ (event.target);
1636 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId 1565
1637 */ 1566 var idbDatabaseTreeElement = this._idbDatabaseTreeElement(model, databaseId) ;
1638 _addIndexedDB: function(model, databaseId) 1567 if (!idbDatabaseTreeElement)
1639 { 1568 return;
1640 var idbDatabaseTreeElement = new WebInspector.IDBDatabaseTreeElement(thi s._storagePanel, model, databaseId); 1569
1641 this._idbDatabaseTreeElements.push(idbDatabaseTreeElement); 1570 idbDatabaseTreeElement.clear();
1642 this.appendChild(idbDatabaseTreeElement); 1571 this.removeChild(idbDatabaseTreeElement);
1643 model.refreshDatabase(databaseId); 1572 this._idbDatabaseTreeElements.remove(idbDatabaseTreeElement);
1644 }, 1573 }
1645 1574
1646 /** 1575 /**
1647 * @param {!WebInspector.Event} event 1576 * @param {!WebInspector.Event} event
1648 */ 1577 */
1649 _indexedDBRemoved: function(event) 1578 _indexedDBLoaded(event) {
1650 { 1579 var database = /** @type {!WebInspector.IndexedDBModel.Database} */ (event.d ata);
1651 var databaseId = /** @type {!WebInspector.IndexedDBModel.DatabaseId} */ (event.data); 1580 var model = /** @type {!WebInspector.IndexedDBModel} */ (event.target);
1652 var model = /** @type {!WebInspector.IndexedDBModel} */ (event.target); 1581
1653 1582 var idbDatabaseTreeElement = this._idbDatabaseTreeElement(model, database.da tabaseId);
1654 var idbDatabaseTreeElement = this._idbDatabaseTreeElement(model, databas eId); 1583 if (!idbDatabaseTreeElement)
1655 if (!idbDatabaseTreeElement) 1584 return;
1656 return; 1585
1657 1586 idbDatabaseTreeElement.update(database);
1658 idbDatabaseTreeElement.clear(); 1587 }
1659 this.removeChild(idbDatabaseTreeElement); 1588
1660 this._idbDatabaseTreeElements.remove(idbDatabaseTreeElement); 1589 /**
1661 }, 1590 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1662 1591 * @param {!WebInspector.IndexedDBModel} model
1663 /** 1592 * @return {?WebInspector.IDBDatabaseTreeElement}
1664 * @param {!WebInspector.Event} event 1593 */
1665 */ 1594 _idbDatabaseTreeElement(model, databaseId) {
1666 _indexedDBLoaded: function(event) 1595 var index = -1;
1667 { 1596 for (var i = 0; i < this._idbDatabaseTreeElements.length; ++i) {
1668 var database = /** @type {!WebInspector.IndexedDBModel.Database} */ (eve nt.data); 1597 if (this._idbDatabaseTreeElements[i]._databaseId.equals(databaseId) &&
1669 var model = /** @type {!WebInspector.IndexedDBModel} */ (event.target); 1598 this._idbDatabaseTreeElements[i]._model === model) {
1670 1599 index = i;
1671 var idbDatabaseTreeElement = this._idbDatabaseTreeElement(model, databas e.databaseId); 1600 break;
1672 if (!idbDatabaseTreeElement) 1601 }
1673 return; 1602 }
1674 1603 if (index !== -1)
1675 idbDatabaseTreeElement.update(database); 1604 return this._idbDatabaseTreeElements[i];
1676 }, 1605 return null;
1677 1606 }
1678 /** 1607 };
1679 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId 1608
1680 * @param {!WebInspector.IndexedDBModel} model 1609 /**
1681 * @return {?WebInspector.IDBDatabaseTreeElement} 1610 * @unrestricted
1682 */ 1611 */
1683 _idbDatabaseTreeElement: function(model, databaseId) 1612 WebInspector.IDBDatabaseTreeElement = class extends WebInspector.BaseStorageTree Element {
1684 { 1613 /**
1685 var index = -1; 1614 * @param {!WebInspector.ResourcesPanel} storagePanel
1686 for (var i = 0; i < this._idbDatabaseTreeElements.length; ++i) { 1615 * @param {!WebInspector.IndexedDBModel} model
1687 if (this._idbDatabaseTreeElements[i]._databaseId.equals(databaseId) && this._idbDatabaseTreeElements[i]._model === model) { 1616 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1688 index = i; 1617 */
1689 break; 1618 constructor(storagePanel, model, databaseId) {
1690 } 1619 super(
1691 } 1620 storagePanel, databaseId.name + ' - ' + databaseId.securityOrigin,
1692 if (index !== -1) 1621 ['database-tree-item', 'resource-tree-item']);
1693 return this._idbDatabaseTreeElements[i];
1694 return null;
1695 },
1696
1697 __proto__: WebInspector.StorageCategoryTreeElement.prototype
1698 };
1699
1700 /**
1701 * @constructor
1702 * @extends {WebInspector.BaseStorageTreeElement}
1703 * @param {!WebInspector.ResourcesPanel} storagePanel
1704 * @param {!WebInspector.IndexedDBModel} model
1705 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1706 */
1707 WebInspector.IDBDatabaseTreeElement = function(storagePanel, model, databaseId)
1708 {
1709 WebInspector.BaseStorageTreeElement.call(this, storagePanel, databaseId.name + " - " + databaseId.securityOrigin, ["database-tree-item", "resource-tree-item "]);
1710 this._model = model; 1622 this._model = model;
1711 this._databaseId = databaseId; 1623 this._databaseId = databaseId;
1712 this._idbObjectStoreTreeElements = {}; 1624 this._idbObjectStoreTreeElements = {};
1713 }; 1625 }
1714 1626
1715 WebInspector.IDBDatabaseTreeElement.prototype = { 1627 get itemURL() {
1716 get itemURL() 1628 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name;
1717 { 1629 }
1718 return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._da tabaseId.name; 1630
1719 }, 1631 /**
1720 1632 * @override
1721 onattach: function() 1633 */
1722 { 1634 onattach() {
1723 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this); 1635 super.onattach();
1724 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true); 1636 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1725 }, 1637 }
1726 1638
1727 _handleContextMenuEvent: function(event) 1639 _handleContextMenuEvent(event) {
1728 { 1640 var contextMenu = new WebInspector.ContextMenu(event);
1729 var contextMenu = new WebInspector.ContextMenu(event); 1641 contextMenu.appendItem(WebInspector.UIString('Refresh IndexedDB'), this._ref reshIndexedDB.bind(this));
1730 contextMenu.appendItem(WebInspector.UIString("Refresh IndexedDB"), this. _refreshIndexedDB.bind(this)); 1642 contextMenu.show();
1731 contextMenu.show(); 1643 }
1732 }, 1644
1733 1645 _refreshIndexedDB() {
1734 _refreshIndexedDB: function() 1646 this._model.refreshDatabaseNames();
1735 { 1647 }
1736 this._model.refreshDatabaseNames(); 1648
1737 }, 1649 /**
1738 1650 * @param {!WebInspector.IndexedDBModel.Database} database
1739 /** 1651 */
1740 * @param {!WebInspector.IndexedDBModel.Database} database 1652 update(database) {
1741 */ 1653 this._database = database;
1742 update: function(database) 1654 var objectStoreNames = {};
1743 { 1655 for (var objectStoreName in this._database.objectStores) {
1744 this._database = database; 1656 var objectStore = this._database.objectStores[objectStoreName];
1745 var objectStoreNames = {}; 1657 objectStoreNames[objectStore.name] = true;
1746 for (var objectStoreName in this._database.objectStores) { 1658 if (!this._idbObjectStoreTreeElements[objectStore.name]) {
1747 var objectStore = this._database.objectStores[objectStoreName]; 1659 var idbObjectStoreTreeElement =
1748 objectStoreNames[objectStore.name] = true; 1660 new WebInspector.IDBObjectStoreTreeElement(this._storagePanel, this. _model, this._databaseId, objectStore);
1749 if (!this._idbObjectStoreTreeElements[objectStore.name]) { 1661 this._idbObjectStoreTreeElements[objectStore.name] = idbObjectStoreTreeE lement;
1750 var idbObjectStoreTreeElement = new WebInspector.IDBObjectStoreT reeElement(this._storagePanel, this._model, this._databaseId, objectStore); 1662 this.appendChild(idbObjectStoreTreeElement);
1751 this._idbObjectStoreTreeElements[objectStore.name] = idbObjectSt oreTreeElement; 1663 }
1752 this.appendChild(idbObjectStoreTreeElement); 1664 this._idbObjectStoreTreeElements[objectStore.name].update(objectStore);
1753 } 1665 }
1754 this._idbObjectStoreTreeElements[objectStore.name].update(objectStor e); 1666 for (var objectStoreName in this._idbObjectStoreTreeElements) {
1755 } 1667 if (!objectStoreNames[objectStoreName])
1756 for (var objectStoreName in this._idbObjectStoreTreeElements) { 1668 this._objectStoreRemoved(objectStoreName);
1757 if (!objectStoreNames[objectStoreName]) 1669 }
1758 this._objectStoreRemoved(objectStoreName); 1670
1759 } 1671 if (this._view)
1760 1672 this._view.update(database);
1761 if (this._view) 1673
1762 this._view.update(database); 1674 this._updateTooltip();
1763 1675 }
1764 this._updateTooltip(); 1676
1765 }, 1677 _updateTooltip() {
1766 1678 this.tooltip = WebInspector.UIString('Version') + ': ' + this._database.vers ion;
1767 _updateTooltip: function() 1679 }
1768 { 1680
1769 this.tooltip = WebInspector.UIString("Version") + ": " + this._database. version; 1681 /**
1770 }, 1682 * @override
1771 1683 * @return {boolean}
1772 /** 1684 */
1773 * @override 1685 onselect(selectedByUser) {
1774 * @return {boolean} 1686 super.onselect(selectedByUser);
1775 */ 1687 if (!this._view)
1776 onselect: function(selectedByUser) 1688 this._view = new WebInspector.IDBDatabaseView(this._database);
1777 { 1689
1778 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1690 this._storagePanel._innerShowView(this._view);
1779 if (!this._view) 1691 return false;
1780 this._view = new WebInspector.IDBDatabaseView(this._database); 1692 }
1781 1693
1782 this._storagePanel._innerShowView(this._view); 1694 /**
1783 return false; 1695 * @param {string} objectStoreName
1784 }, 1696 */
1785 1697 _objectStoreRemoved(objectStoreName) {
1786 /** 1698 var objectStoreTreeElement = this._idbObjectStoreTreeElements[objectStoreNam e];
1787 * @param {string} objectStoreName 1699 objectStoreTreeElement.clear();
1788 */ 1700 this.removeChild(objectStoreTreeElement);
1789 _objectStoreRemoved: function(objectStoreName) 1701 delete this._idbObjectStoreTreeElements[objectStoreName];
1790 { 1702 }
1791 var objectStoreTreeElement = this._idbObjectStoreTreeElements[objectStor eName]; 1703
1792 objectStoreTreeElement.clear(); 1704 clear() {
1793 this.removeChild(objectStoreTreeElement); 1705 for (var objectStoreName in this._idbObjectStoreTreeElements)
1794 delete this._idbObjectStoreTreeElements[objectStoreName]; 1706 this._objectStoreRemoved(objectStoreName);
1795 }, 1707 }
1796 1708 };
1797 clear: function() 1709
1798 { 1710 /**
1799 for (var objectStoreName in this._idbObjectStoreTreeElements) 1711 * @unrestricted
1800 this._objectStoreRemoved(objectStoreName); 1712 */
1801 }, 1713 WebInspector.IDBObjectStoreTreeElement = class extends WebInspector.BaseStorageT reeElement {
1802 1714 /**
1803 __proto__: WebInspector.BaseStorageTreeElement.prototype 1715 * @param {!WebInspector.ResourcesPanel} storagePanel
1804 }; 1716 * @param {!WebInspector.IndexedDBModel} model
1805 1717 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1806 /** 1718 * @param {!WebInspector.IndexedDBModel.ObjectStore} objectStore
1807 * @constructor 1719 */
1808 * @extends {WebInspector.BaseStorageTreeElement} 1720 constructor(storagePanel, model, databaseId, objectStore) {
1809 * @param {!WebInspector.ResourcesPanel} storagePanel 1721 super(storagePanel, objectStore.name, ['table-tree-item', 'resource-tree-ite m']);
1810 * @param {!WebInspector.IndexedDBModel} model
1811 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1812 * @param {!WebInspector.IndexedDBModel.ObjectStore} objectStore
1813 */
1814 WebInspector.IDBObjectStoreTreeElement = function(storagePanel, model, databaseI d, objectStore)
1815 {
1816 WebInspector.BaseStorageTreeElement.call(this, storagePanel, objectStore.nam e, ["table-tree-item", "resource-tree-item"]);
1817 this._model = model; 1722 this._model = model;
1818 this._databaseId = databaseId; 1723 this._databaseId = databaseId;
1819 this._idbIndexTreeElements = {}; 1724 this._idbIndexTreeElements = {};
1820 }; 1725 }
1821 1726
1822 WebInspector.IDBObjectStoreTreeElement.prototype = { 1727 get itemURL() {
1823 get itemURL() 1728 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name + '/' +
1824 { 1729 this._objectStore.name;
1825 return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._da tabaseId.name + "/" + this._objectStore.name; 1730 }
1826 }, 1731
1827 1732 /**
1828 onattach: function() 1733 * @override
1829 { 1734 */
1830 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this); 1735 onattach() {
1831 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true); 1736 super.onattach();
1832 }, 1737 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1833 1738 }
1834 _handleContextMenuEvent: function(event) 1739
1835 { 1740 _handleContextMenuEvent(event) {
1836 var contextMenu = new WebInspector.ContextMenu(event); 1741 var contextMenu = new WebInspector.ContextMenu(event);
1837 contextMenu.appendItem(WebInspector.UIString("Clear"), this._clearObject Store.bind(this)); 1742 contextMenu.appendItem(WebInspector.UIString('Clear'), this._clearObjectStor e.bind(this));
1838 contextMenu.show(); 1743 contextMenu.show();
1839 }, 1744 }
1840 1745
1841 _clearObjectStore: function() 1746 _clearObjectStore() {
1842 { 1747 /**
1843 /** 1748 * @this {WebInspector.IDBObjectStoreTreeElement}
1844 * @this {WebInspector.IDBObjectStoreTreeElement}
1845 */
1846 function callback() {
1847 this.update(this._objectStore);
1848 }
1849 this._model.clearObjectStore(this._databaseId, this._objectStore.name, c allback.bind(this));
1850 },
1851
1852 /**
1853 * @param {!WebInspector.IndexedDBModel.ObjectStore} objectStore
1854 */ 1749 */
1855 update: function(objectStore) 1750 function callback() {
1856 { 1751 this.update(this._objectStore);
1857 this._objectStore = objectStore; 1752 }
1858 1753 this._model.clearObjectStore(this._databaseId, this._objectStore.name, callb ack.bind(this));
1859 var indexNames = {}; 1754 }
1860 for (var indexName in this._objectStore.indexes) { 1755
1861 var index = this._objectStore.indexes[indexName]; 1756 /**
1862 indexNames[index.name] = true; 1757 * @param {!WebInspector.IndexedDBModel.ObjectStore} objectStore
1863 if (!this._idbIndexTreeElements[index.name]) { 1758 */
1864 var idbIndexTreeElement = new WebInspector.IDBIndexTreeElement(t his._storagePanel, this._model, this._databaseId, this._objectStore, index); 1759 update(objectStore) {
1865 this._idbIndexTreeElements[index.name] = idbIndexTreeElement; 1760 this._objectStore = objectStore;
1866 this.appendChild(idbIndexTreeElement); 1761
1867 } 1762 var indexNames = {};
1868 this._idbIndexTreeElements[index.name].update(index); 1763 for (var indexName in this._objectStore.indexes) {
1869 } 1764 var index = this._objectStore.indexes[indexName];
1870 for (var indexName in this._idbIndexTreeElements) { 1765 indexNames[index.name] = true;
1871 if (!indexNames[indexName]) 1766 if (!this._idbIndexTreeElements[index.name]) {
1872 this._indexRemoved(indexName); 1767 var idbIndexTreeElement = new WebInspector.IDBIndexTreeElement(
1873 } 1768 this._storagePanel, this._model, this._databaseId, this._objectStore , index);
1874 for (var indexName in this._idbIndexTreeElements) { 1769 this._idbIndexTreeElements[index.name] = idbIndexTreeElement;
1875 if (!indexNames[indexName]) { 1770 this.appendChild(idbIndexTreeElement);
1876 this.removeChild(this._idbIndexTreeElements[indexName]); 1771 }
1877 delete this._idbIndexTreeElements[indexName]; 1772 this._idbIndexTreeElements[index.name].update(index);
1878 } 1773 }
1879 } 1774 for (var indexName in this._idbIndexTreeElements) {
1880 1775 if (!indexNames[indexName])
1881 if (this.childCount()) 1776 this._indexRemoved(indexName);
1882 this.expand(); 1777 }
1883 1778 for (var indexName in this._idbIndexTreeElements) {
1884 if (this._view) 1779 if (!indexNames[indexName]) {
1885 this._view.update(this._objectStore); 1780 this.removeChild(this._idbIndexTreeElements[indexName]);
1886
1887 this._updateTooltip();
1888 },
1889
1890 _updateTooltip: function()
1891 {
1892
1893 var keyPathString = this._objectStore.keyPathString;
1894 var tooltipString = keyPathString !== null ? (WebInspector.UIString("Key path: ") + keyPathString) : "";
1895 if (this._objectStore.autoIncrement)
1896 tooltipString += "\n" + WebInspector.UIString("autoIncrement");
1897 this.tooltip = tooltipString;
1898 },
1899
1900 /**
1901 * @override
1902 * @return {boolean}
1903 */
1904 onselect: function(selectedByUser)
1905 {
1906 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser);
1907 if (!this._view)
1908 this._view = new WebInspector.IDBDataView(this._model, this._databas eId, this._objectStore, null);
1909
1910 this._storagePanel._innerShowView(this._view);
1911 return false;
1912 },
1913
1914 /**
1915 * @param {string} indexName
1916 */
1917 _indexRemoved: function(indexName)
1918 {
1919 var indexTreeElement = this._idbIndexTreeElements[indexName];
1920 indexTreeElement.clear();
1921 this.removeChild(indexTreeElement);
1922 delete this._idbIndexTreeElements[indexName]; 1781 delete this._idbIndexTreeElements[indexName];
1923 }, 1782 }
1924 1783 }
1925 clear: function() 1784
1926 { 1785 if (this.childCount())
1927 for (var indexName in this._idbIndexTreeElements) 1786 this.expand();
1928 this._indexRemoved(indexName); 1787
1929 if (this._view) 1788 if (this._view)
1930 this._view.clear(); 1789 this._view.update(this._objectStore);
1931 }, 1790
1932 1791 this._updateTooltip();
1933 __proto__: WebInspector.BaseStorageTreeElement.prototype 1792 }
1934 }; 1793
1935 1794 _updateTooltip() {
1936 /** 1795 var keyPathString = this._objectStore.keyPathString;
1937 * @constructor 1796 var tooltipString = keyPathString !== null ? (WebInspector.UIString('Key pat h: ') + keyPathString) : '';
1938 * @extends {WebInspector.BaseStorageTreeElement} 1797 if (this._objectStore.autoIncrement)
1939 * @param {!WebInspector.ResourcesPanel} storagePanel 1798 tooltipString += '\n' + WebInspector.UIString('autoIncrement');
1940 * @param {!WebInspector.IndexedDBModel} model 1799 this.tooltip = tooltipString;
1941 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId 1800 }
1942 * @param {!WebInspector.IndexedDBModel.ObjectStore} objectStore 1801
1943 * @param {!WebInspector.IndexedDBModel.Index} index 1802 /**
1944 */ 1803 * @override
1945 WebInspector.IDBIndexTreeElement = function(storagePanel, model, databaseId, obj ectStore, index) 1804 * @return {boolean}
1946 { 1805 */
1947 WebInspector.BaseStorageTreeElement.call(this, storagePanel, index.name, ["i ndex-tree-item", "resource-tree-item"]); 1806 onselect(selectedByUser) {
1807 super.onselect(selectedByUser);
1808 if (!this._view)
1809 this._view = new WebInspector.IDBDataView(this._model, this._databaseId, t his._objectStore, null);
1810
1811 this._storagePanel._innerShowView(this._view);
1812 return false;
1813 }
1814
1815 /**
1816 * @param {string} indexName
1817 */
1818 _indexRemoved(indexName) {
1819 var indexTreeElement = this._idbIndexTreeElements[indexName];
1820 indexTreeElement.clear();
1821 this.removeChild(indexTreeElement);
1822 delete this._idbIndexTreeElements[indexName];
1823 }
1824
1825 clear() {
1826 for (var indexName in this._idbIndexTreeElements)
1827 this._indexRemoved(indexName);
1828 if (this._view)
1829 this._view.clear();
1830 }
1831 };
1832
1833 /**
1834 * @unrestricted
1835 */
1836 WebInspector.IDBIndexTreeElement = class extends WebInspector.BaseStorageTreeEle ment {
1837 /**
1838 * @param {!WebInspector.ResourcesPanel} storagePanel
1839 * @param {!WebInspector.IndexedDBModel} model
1840 * @param {!WebInspector.IndexedDBModel.DatabaseId} databaseId
1841 * @param {!WebInspector.IndexedDBModel.ObjectStore} objectStore
1842 * @param {!WebInspector.IndexedDBModel.Index} index
1843 */
1844 constructor(storagePanel, model, databaseId, objectStore, index) {
1845 super(storagePanel, index.name, ['index-tree-item', 'resource-tree-item']);
1948 this._model = model; 1846 this._model = model;
1949 this._databaseId = databaseId; 1847 this._databaseId = databaseId;
1950 this._objectStore = objectStore; 1848 this._objectStore = objectStore;
1951 this._index = index; 1849 this._index = index;
1952 }; 1850 }
1953 1851
1954 WebInspector.IDBIndexTreeElement.prototype = { 1852 get itemURL() {
1955 get itemURL() 1853 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name + '/' +
1956 { 1854 this._objectStore.name + '/' + this._index.name;
1957 return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._da tabaseId.name + "/" + this._objectStore.name + "/" + this._index.name; 1855 }
1958 }, 1856
1959 1857 /**
1960 /** 1858 * @param {!WebInspector.IndexedDBModel.Index} index
1961 * @param {!WebInspector.IndexedDBModel.Index} index 1859 */
1962 */ 1860 update(index) {
1963 update: function(index) 1861 this._index = index;
1964 { 1862
1965 this._index = index; 1863 if (this._view)
1966 1864 this._view.update(this._index);
1967 if (this._view) 1865
1968 this._view.update(this._index); 1866 this._updateTooltip();
1969 1867 }
1970 this._updateTooltip(); 1868
1971 }, 1869 _updateTooltip() {
1972 1870 var tooltipLines = [];
1973 _updateTooltip: function() 1871 var keyPathString = this._index.keyPathString;
1974 { 1872 tooltipLines.push(WebInspector.UIString('Key path: ') + keyPathString);
1975 var tooltipLines = []; 1873 if (this._index.unique)
1976 var keyPathString = this._index.keyPathString; 1874 tooltipLines.push(WebInspector.UIString('unique'));
1977 tooltipLines.push(WebInspector.UIString("Key path: ") + keyPathString); 1875 if (this._index.multiEntry)
1978 if (this._index.unique) 1876 tooltipLines.push(WebInspector.UIString('multiEntry'));
1979 tooltipLines.push(WebInspector.UIString("unique")); 1877 this.tooltip = tooltipLines.join('\n');
1980 if (this._index.multiEntry) 1878 }
1981 tooltipLines.push(WebInspector.UIString("multiEntry")); 1879
1982 this.tooltip = tooltipLines.join("\n"); 1880 /**
1983 }, 1881 * @override
1984 1882 * @return {boolean}
1985 /** 1883 */
1986 * @override 1884 onselect(selectedByUser) {
1987 * @return {boolean} 1885 super.onselect(selectedByUser);
1988 */ 1886 if (!this._view)
1989 onselect: function(selectedByUser) 1887 this._view = new WebInspector.IDBDataView(this._model, this._databaseId, t his._objectStore, this._index);
1990 { 1888
1991 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1889 this._storagePanel._innerShowView(this._view);
1992 if (!this._view) 1890 return false;
1993 this._view = new WebInspector.IDBDataView(this._model, this._databas eId, this._objectStore, this._index); 1891 }
1994 1892
1995 this._storagePanel._innerShowView(this._view); 1893 clear() {
1996 return false; 1894 if (this._view)
1997 }, 1895 this._view.clear();
1998 1896 }
1999 clear: function() 1897 };
2000 { 1898
2001 if (this._view) 1899 /**
2002 this._view.clear(); 1900 * @unrestricted
2003 }, 1901 */
2004 1902 WebInspector.DOMStorageTreeElement = class extends WebInspector.BaseStorageTreeE lement {
2005 __proto__: WebInspector.BaseStorageTreeElement.prototype 1903 constructor(storagePanel, domStorage) {
2006 }; 1904 super(
2007 1905 storagePanel, domStorage.securityOrigin ? domStorage.securityOrigin : We bInspector.UIString('Local Files'),
2008 /** 1906 ['table-tree-item', 'resource-tree-item']);
2009 * @constructor
2010 * @extends {WebInspector.BaseStorageTreeElement}
2011 */
2012 WebInspector.DOMStorageTreeElement = function(storagePanel, domStorage)
2013 {
2014 WebInspector.BaseStorageTreeElement.call(this, storagePanel, domStorage.secu rityOrigin ? domStorage.securityOrigin : WebInspector.UIString("Local Files"), [ "table-tree-item", "resource-tree-item"]);
2015 this._domStorage = domStorage; 1907 this._domStorage = domStorage;
2016 }; 1908 }
2017 1909
2018 WebInspector.DOMStorageTreeElement.prototype = { 1910 get itemURL() {
2019 get itemURL() 1911 return 'storage://' + this._domStorage.securityOrigin + '/' +
2020 { 1912 (this._domStorage.isLocalStorage ? 'local' : 'session');
2021 return "storage://" + this._domStorage.securityOrigin + "/" + (this._dom Storage.isLocalStorage ? "local" : "session"); 1913 }
2022 }, 1914
2023 1915 /**
2024 /** 1916 * @override
2025 * @override 1917 * @return {boolean}
2026 * @return {boolean} 1918 */
2027 */ 1919 onselect(selectedByUser) {
2028 onselect: function(selectedByUser) 1920 super.onselect(selectedByUser);
2029 { 1921 this._storagePanel._showDOMStorage(this._domStorage);
2030 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1922 return false;
2031 this._storagePanel._showDOMStorage(this._domStorage); 1923 }
2032 return false; 1924 };
2033 }, 1925
2034 1926 /**
2035 __proto__: WebInspector.BaseStorageTreeElement.prototype 1927 * @unrestricted
2036 }; 1928 */
2037 1929 WebInspector.CookieTreeElement = class extends WebInspector.BaseStorageTreeEleme nt {
2038 /** 1930 constructor(storagePanel, cookieDomain) {
2039 * @constructor 1931 super(
2040 * @extends {WebInspector.BaseStorageTreeElement} 1932 storagePanel, cookieDomain ? cookieDomain : WebInspector.UIString('Local Files'),
2041 */ 1933 ['cookie-tree-item', 'resource-tree-item']);
2042 WebInspector.CookieTreeElement = function(storagePanel, cookieDomain)
2043 {
2044 WebInspector.BaseStorageTreeElement.call(this, storagePanel, cookieDomain ? cookieDomain : WebInspector.UIString("Local Files"), ["cookie-tree-item", "resou rce-tree-item"]);
2045 this._cookieDomain = cookieDomain; 1934 this._cookieDomain = cookieDomain;
2046 }; 1935 }
2047 1936
2048 WebInspector.CookieTreeElement.prototype = { 1937 get itemURL() {
2049 get itemURL() 1938 return 'cookies://' + this._cookieDomain;
2050 { 1939 }
2051 return "cookies://" + this._cookieDomain; 1940
2052 }, 1941 /**
2053 1942 * @override
2054 onattach: function() 1943 */
2055 { 1944 onattach() {
2056 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this); 1945 super.onattach();
2057 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true); 1946 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
2058 }, 1947 }
2059 1948
2060 /** 1949 /**
2061 * @param {!Event} event 1950 * @param {!Event} event
2062 */ 1951 */
2063 _handleContextMenuEvent: function(event) 1952 _handleContextMenuEvent(event) {
2064 { 1953 var contextMenu = new WebInspector.ContextMenu(event);
2065 var contextMenu = new WebInspector.ContextMenu(event); 1954 contextMenu.appendItem(WebInspector.UIString('Clear'), this._clearCookies.bi nd(this));
2066 contextMenu.appendItem(WebInspector.UIString("Clear"), this._clearCookie s.bind(this)); 1955 contextMenu.show();
2067 contextMenu.show(); 1956 }
2068 }, 1957
2069 1958 /**
2070 /** 1959 * @param {string} domain
2071 * @param {string} domain 1960 */
2072 */ 1961 _clearCookies(domain) {
2073 _clearCookies: function(domain) 1962 this._storagePanel.clearCookies(this._cookieDomain);
2074 { 1963 }
2075 this._storagePanel.clearCookies(this._cookieDomain); 1964
2076 }, 1965 /**
2077 1966 * @override
2078 /** 1967 * @return {boolean}
2079 * @override 1968 */
2080 * @return {boolean} 1969 onselect(selectedByUser) {
2081 */ 1970 super.onselect(selectedByUser);
2082 onselect: function(selectedByUser) 1971 this._storagePanel.showCookies(this, this._cookieDomain);
2083 { 1972 return false;
2084 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 1973 }
2085 this._storagePanel.showCookies(this, this._cookieDomain); 1974 };
2086 return false; 1975
2087 }, 1976 /**
2088 1977 * @unrestricted
2089 __proto__: WebInspector.BaseStorageTreeElement.prototype 1978 */
2090 }; 1979 WebInspector.ApplicationCacheManifestTreeElement = class extends WebInspector.Ba seStorageTreeElement {
2091 1980 constructor(storagePanel, manifestURL) {
2092 /**
2093 * @constructor
2094 * @extends {WebInspector.BaseStorageTreeElement}
2095 */
2096 WebInspector.ApplicationCacheManifestTreeElement = function(storagePanel, manife stURL)
2097 {
2098 var title = new WebInspector.ParsedURL(manifestURL).displayName; 1981 var title = new WebInspector.ParsedURL(manifestURL).displayName;
2099 WebInspector.BaseStorageTreeElement.call(this, storagePanel, title, ["applic ation-cache-storage-tree-item"]); 1982 super(storagePanel, title, ['application-cache-storage-tree-item']);
2100 this.tooltip = manifestURL; 1983 this.tooltip = manifestURL;
2101 this._manifestURL = manifestURL; 1984 this._manifestURL = manifestURL;
2102 }; 1985 }
2103 1986
2104 WebInspector.ApplicationCacheManifestTreeElement.prototype = { 1987 get itemURL() {
2105 get itemURL() 1988 return 'appcache://' + this._manifestURL;
2106 { 1989 }
2107 return "appcache://" + this._manifestURL; 1990
2108 }, 1991 get manifestURL() {
2109 1992 return this._manifestURL;
2110 get manifestURL() 1993 }
2111 { 1994
2112 return this._manifestURL; 1995 /**
2113 }, 1996 * @override
2114 1997 * @return {boolean}
2115 /** 1998 */
2116 * @override 1999 onselect(selectedByUser) {
2117 * @return {boolean} 2000 super.onselect(selectedByUser);
2118 */ 2001 this._storagePanel.showCategoryView(this._manifestURL);
2119 onselect: function(selectedByUser) 2002 return false;
2120 { 2003 }
2121 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 2004 };
2122 this._storagePanel.showCategoryView(this._manifestURL); 2005
2123 return false; 2006 /**
2124 }, 2007 * @unrestricted
2125 2008 */
2126 __proto__: WebInspector.BaseStorageTreeElement.prototype 2009 WebInspector.ApplicationCacheFrameTreeElement = class extends WebInspector.BaseS torageTreeElement {
2127 }; 2010 /**
2128 2011 * @param {!WebInspector.ResourcesPanel} storagePanel
2129 /** 2012 * @param {!PageAgent.FrameId} frameId
2130 * @constructor 2013 * @param {string} manifestURL
2131 * @extends {WebInspector.BaseStorageTreeElement} 2014 */
2132 * @param {!WebInspector.ResourcesPanel} storagePanel 2015 constructor(storagePanel, frameId, manifestURL) {
2133 * @param {!PageAgent.FrameId} frameId 2016 super(storagePanel, '', ['navigator-tree-item', 'navigator-folder-tree-item' ]);
2134 * @param {string} manifestURL
2135 */
2136 WebInspector.ApplicationCacheFrameTreeElement = function(storagePanel, frameId, manifestURL)
2137 {
2138 WebInspector.BaseStorageTreeElement.call(this, storagePanel, "", ["navigator -tree-item", "navigator-folder-tree-item"]);
2139 this._frameId = frameId; 2017 this._frameId = frameId;
2140 this._manifestURL = manifestURL; 2018 this._manifestURL = manifestURL;
2141 this._refreshTitles(); 2019 this._refreshTitles();
2142 }; 2020 }
2143 2021
2144 WebInspector.ApplicationCacheFrameTreeElement.prototype = { 2022 get itemURL() {
2145 get itemURL() 2023 return 'appcache://' + this._manifestURL + '/' + encodeURI(this.titleAsText( ));
2146 { 2024 }
2147 return "appcache://" + this._manifestURL + "/" + encodeURI(this.titleAsT ext()); 2025
2148 }, 2026 get frameId() {
2149 2027 return this._frameId;
2150 get frameId() 2028 }
2151 { 2029
2152 return this._frameId; 2030 get manifestURL() {
2153 }, 2031 return this._manifestURL;
2154 2032 }
2155 get manifestURL() 2033
2156 { 2034 _refreshTitles() {
2157 return this._manifestURL; 2035 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this._stor agePanel._target);
2158 }, 2036 var frame = resourceTreeModel.frameForId(this._frameId);
2159 2037 this.title = frame.displayName();
2160 _refreshTitles: function() 2038 }
2161 { 2039
2162 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this._ storagePanel._target); 2040 frameNavigated() {
2163 var frame = resourceTreeModel.frameForId(this._frameId); 2041 this._refreshTitles();
2164 this.title = frame.displayName(); 2042 }
2165 }, 2043
2166 2044 /**
2167 frameNavigated: function() 2045 * @override
2168 { 2046 * @return {boolean}
2169 this._refreshTitles(); 2047 */
2170 }, 2048 onselect(selectedByUser) {
2171 2049 super.onselect(selectedByUser);
2172 /** 2050 this._storagePanel.showApplicationCache(this._frameId);
2173 * @override 2051 return false;
2174 * @return {boolean} 2052 }
2175 */ 2053 };
2176 onselect: function(selectedByUser) 2054
2177 { 2055 /**
2178 WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, select edByUser); 2056 * @unrestricted
2179 this._storagePanel.showApplicationCache(this._frameId); 2057 */
2180 return false; 2058 WebInspector.StorageCategoryView = class extends WebInspector.VBox {
2181 }, 2059 constructor() {
2182 2060 super();
2183 __proto__: WebInspector.BaseStorageTreeElement.prototype 2061
2184 }; 2062 this.element.classList.add('storage-view');
2185 2063 this._emptyWidget = new WebInspector.EmptyWidget('');
2186 /**
2187 * @constructor
2188 * @extends {WebInspector.VBox}
2189 */
2190 WebInspector.StorageCategoryView = function()
2191 {
2192 WebInspector.VBox.call(this);
2193
2194 this.element.classList.add("storage-view");
2195 this._emptyWidget = new WebInspector.EmptyWidget("");
2196 this._emptyWidget.show(this.element); 2064 this._emptyWidget.show(this.element);
2197 }; 2065 }
2198 2066
2199 WebInspector.StorageCategoryView.prototype = { 2067 setText(text) {
2200 setText: function(text) 2068 this._emptyWidget.text = text;
2201 { 2069 }
2202 this._emptyWidget.text = text; 2070 };
2203 }, 2071
2204 2072
2205 __proto__: WebInspector.VBox.prototype
2206 };
2207
2208 /**
2209 * @return {!WebInspector.ResourcesPanel}
2210 */
2211 WebInspector.ResourcesPanel._instance = function()
2212 {
2213 return /** @type {!WebInspector.ResourcesPanel} */ (self.runtime.sharedInsta nce(WebInspector.ResourcesPanel));
2214 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698