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

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

Issue 2747123008: [DevTools] Separate old Application tab code (Closed)
Patch Set: Created 3 years, 9 months 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
(...skipping 10 matching lines...) Expand all
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 /** 30 /**
31 * @implements {SDK.TargetManager.Observer}
32 * @unrestricted 31 * @unrestricted
33 */ 32 */
34 Resources.ResourcesPanel = class extends UI.PanelWithSidebar { 33 Resources.ResourcesPanel = class extends UI.PanelWithSidebar {
35 constructor() { 34 constructor() {
36 super('resources'); 35 super('resources');
37 this.registerRequiredCSS('resources/resourcesPanel.css'); 36 this.registerRequiredCSS('resources/resourcesPanel.css');
38 37
39 this._resourcesLastSelectedItemSetting = Common.settings.createSetting('reso urcesLastSelectedItem', {}); 38 this._sidebar = new Resources.ApplicationPanelSidebar(this.panelSidebarEleme nt(), this.splitWidget());
40 39
41 this._sidebarTree = new UI.TreeOutlineInShadow(); 40 // This is a stop-gap to avoid having to modify the tests. As this tab gets rewritten, these
42 this._sidebarTree.element.classList.add('resources-sidebar'); 41 // tests will have to be updated as well. That's when this code is expected to go away.
43 this._sidebarTree.registerRequiredCSS('resources/resourcesSidebar.css'); 42 var exposeForTests = [
44 this._sidebarTree.element.classList.add('filter-all'); 43 '_applicationCacheModel', '_domStorageView', '_resourcesSection', 'cacheSt orageListTreeElement',
dgozman 2017/03/17 17:50:11 Let's do this manually, so that we can JSDoc it.
eostroukhov 2017/03/17 19:01:12 Done. I did not want to change visibility too much
45 this.panelSidebarElement().appendChild(this._sidebarTree.element); 44 'applicationCacheListTreeElement', 'serviceWorkersTreeElement', 'indexedDB ListTreeElement', 'visibleView'
45 ];
46 46
47 this._applicationTreeElement = this._addSidebarSection(Common.UIString('Appl ication')); 47 exposeForTests.forEach(propertyName => this._createPropertyForTest(propertyN ame));
48 this._manifestTreeElement = new Resources.AppManifestTreeElement(this);
49 this._applicationTreeElement.appendChild(this._manifestTreeElement);
50 this.serviceWorkersTreeElement = new Resources.ServiceWorkersTreeElement(thi s);
51 this._applicationTreeElement.appendChild(this.serviceWorkersTreeElement);
52 var clearStorageTreeElement = new Resources.ClearStorageTreeElement(this);
53 this._applicationTreeElement.appendChild(clearStorageTreeElement);
54
55 var storageTreeElement = this._addSidebarSection(Common.UIString('Storage')) ;
56 this.localStorageListTreeElement =
57 new Resources.StorageCategoryTreeElement(this, Common.UIString('Local St orage'), 'LocalStorage');
58 var localStorageIcon = UI.Icon.create('mediumicon-table', 'resource-tree-ite m');
59 this.localStorageListTreeElement.setLeadingIcons([localStorageIcon]);
60
61 storageTreeElement.appendChild(this.localStorageListTreeElement);
62 this.sessionStorageListTreeElement =
63 new Resources.StorageCategoryTreeElement(this, Common.UIString('Session Storage'), 'SessionStorage');
64 var sessionStorageIcon = UI.Icon.create('mediumicon-table', 'resource-tree-i tem');
65 this.sessionStorageListTreeElement.setLeadingIcons([sessionStorageIcon]);
66
67 storageTreeElement.appendChild(this.sessionStorageListTreeElement);
68 this.indexedDBListTreeElement = new Resources.IndexedDBTreeElement(this);
69 storageTreeElement.appendChild(this.indexedDBListTreeElement);
70 this.databasesListTreeElement =
71 new Resources.StorageCategoryTreeElement(this, Common.UIString('Web SQL' ), 'Databases');
72 var databaseIcon = UI.Icon.create('mediumicon-database', 'resource-tree-item ');
73 this.databasesListTreeElement.setLeadingIcons([databaseIcon]);
74
75 storageTreeElement.appendChild(this.databasesListTreeElement);
76 this.cookieListTreeElement = new Resources.StorageCategoryTreeElement(this, Common.UIString('Cookies'), 'Cookies');
77 var cookieIcon = UI.Icon.create('mediumicon-cookie', 'resource-tree-item');
78 this.cookieListTreeElement.setLeadingIcons([cookieIcon]);
79 storageTreeElement.appendChild(this.cookieListTreeElement);
80
81 var cacheTreeElement = this._addSidebarSection(Common.UIString('Cache'));
82 this.cacheStorageListTreeElement = new Resources.ServiceWorkerCacheTreeEleme nt(this);
83 cacheTreeElement.appendChild(this.cacheStorageListTreeElement);
84 this.applicationCacheListTreeElement =
85 new Resources.StorageCategoryTreeElement(this, Common.UIString('Applicat ion Cache'), 'ApplicationCache');
86 var applicationCacheIcon = UI.Icon.create('mediumicon-table', 'resource-tree -item');
87 this.applicationCacheListTreeElement.setLeadingIcons([applicationCacheIcon]) ;
88
89 cacheTreeElement.appendChild(this.applicationCacheListTreeElement);
90
91 this._resourcesSection = new Resources.ResourcesSection(this, this._addSideb arSection(Common.UIString('Frames')));
92
93 var mainContainer = new UI.VBox();
94 this.storageViews = mainContainer.element.createChild('div', 'vbox flex-auto ');
95 this._storageViewToolbar = new UI.Toolbar('resources-toolbar', mainContainer .element);
96 this.splitWidget().setMainWidget(mainContainer);
97
98 /** @type {!Map.<!Resources.Database, !Object.<string, !Resources.DatabaseTa bleView>>} */
99 this._databaseTableViews = new Map();
100 /** @type {!Map.<!Resources.Database, !Resources.DatabaseQueryView>} */
101 this._databaseQueryViews = new Map();
102 /** @type {!Map.<!Resources.Database, !Resources.DatabaseTreeElement>} */
103 this._databaseTreeElements = new Map();
104 /** @type {!Map.<!Resources.DOMStorage, !Resources.DOMStorageTreeElement>} * /
105 this._domStorageTreeElements = new Map();
106 /** @type {!Object.<string, boolean>} */
107 this._domains = {};
108
109 /** @type {?Resources.DOMStorageItemsView} */
110 this._domStorageView = null;
111 /** @type {?Resources.CookieItemsView} */
112 this._cookieView = null;
113
114 this.panelSidebarElement().addEventListener('mousemove', this._onmousemove.b ind(this), false);
115 this.panelSidebarElement().addEventListener('mouseleave', this._onmouseleave .bind(this), false);
116
117 SDK.targetManager.observeTargets(this);
118 SDK.targetManager.addModelListener(
119 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this ._frameNavigated, this);
120 } 48 }
121 49
122 /** 50 /**
123 * @return {!Resources.ResourcesPanel} 51 * @return {!Resources.ResourcesPanel}
124 */ 52 */
125 static _instance() { 53 static _instance() {
126 return /** @type {!Resources.ResourcesPanel} */ (self.runtime.sharedInstance (Resources.ResourcesPanel)); 54 return /** @type {!Resources.ResourcesPanel} */ (self.runtime.sharedInstance (Resources.ResourcesPanel));
127 } 55 }
128 56
129 /** 57 /**
130 * @param {string} title
131 * @return {!UI.TreeElement}
132 */
133 _addSidebarSection(title) {
134 var treeElement = new UI.TreeElement(title, true);
135 treeElement.listItemElement.classList.add('storage-group-list-item');
136 treeElement.setCollapsible(false);
137 treeElement.selectable = false;
138 this._sidebarTree.appendChild(treeElement);
139 return treeElement;
140 }
141
142 /**
143 * @override
144 * @param {!SDK.Target} target
145 */
146 targetAdded(target) {
147 if (this._target)
148 return;
149 this._target = target;
150 this._databaseModel = Resources.DatabaseModel.fromTarget(target);
151
152 this._databaseModel.on(Resources.DatabaseModel.DatabaseAddedEvent, this._dat abaseAdded, this);
153 this._databaseModel.on(Resources.DatabaseModel.DatabasesRemovedEvent, this._ resetWebSQL, this);
154
155 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target);
156 if (!resourceTreeModel)
157 return;
158
159 if (resourceTreeModel.cachedResourcesLoaded())
160 this._initialize();
161
162 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.CachedResour cesLoaded, this._initialize, this);
163 resourceTreeModel.addEventListener(
164 SDK.ResourceTreeModel.Events.WillLoadCachedResources, this._resetWithFra mes, this);
165 }
166
167 /**
168 * @override
169 * @param {!SDK.Target} target
170 */
171 targetRemoved(target) {
172 if (target !== this._target)
173 return;
174 delete this._target;
175
176 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target);
177 if (resourceTreeModel) {
178 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.CachedR esourcesLoaded, this._initialize, this);
179 resourceTreeModel.removeEventListener(
180 SDK.ResourceTreeModel.Events.WillLoadCachedResources, this._resetWithF rames, this);
181 }
182 this._databaseModel.off(Resources.DatabaseModel.DatabaseAddedEvent, this._da tabaseAdded, this);
183 this._databaseModel.off(Resources.DatabaseModel.DatabasesRemovedEvent, this. _resetWebSQL, this);
184
185 this._resetWithFrames();
186 }
187
188 /**
189 * @override 58 * @override
190 */ 59 */
191 focus() { 60 focus() {
192 this._sidebarTree.focus(); 61 this._sidebar.focus();
193 }
194
195 _initialize() {
196 for (var frame of SDK.ResourceTreeModel.frames())
197 this._addCookieDocument(frame);
198 this._databaseModel.enable();
199
200 var indexedDBModel = Resources.IndexedDBModel.fromTarget(this._target);
201 if (indexedDBModel)
202 indexedDBModel.enable();
203
204 var cacheStorageModel = SDK.ServiceWorkerCacheModel.fromTarget(this._target) ;
205 if (cacheStorageModel)
206 cacheStorageModel.enable();
207 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(this._target);
208 if (resourceTreeModel)
209 this._populateApplicationCacheTree(resourceTreeModel);
210 var domStorageModel = Resources.DOMStorageModel.fromTarget(this._target);
211 if (domStorageModel)
212 this._populateDOMStorageTree(domStorageModel);
213 this.indexedDBListTreeElement._initialize();
214 this.cacheStorageListTreeElement._initialize();
215 this._initDefaultSelection();
216 }
217
218 _initDefaultSelection() {
219 var itemURL = this._resourcesLastSelectedItemSetting.get();
220 if (itemURL) {
221 var rootElement = this._sidebarTree.rootElement();
222 for (var treeElement = rootElement.firstChild(); treeElement;
223 treeElement = treeElement.traverseNextTreeElement(false, rootElement, true)) {
224 if (treeElement.itemURL === itemURL) {
225 treeElement.revealAndSelect(true);
226 return;
227 }
228 }
229 }
230 this._manifestTreeElement.select();
231 }
232
233 _resetWithFrames() {
234 this._resourcesSection.reset();
235 this._reset();
236 }
237
238 _resetWebSQL() {
239 if (this.visibleView instanceof Resources.DatabaseQueryView ||
240 this.visibleView instanceof Resources.DatabaseTableView) {
241 this.visibleView.detach();
242 delete this.visibleView;
243 }
244
245 var queryViews = this._databaseQueryViews.valuesArray();
246 for (var i = 0; i < queryViews.length; ++i) {
247 queryViews[i].removeEventListener(
248 Resources.DatabaseQueryView.Events.SchemaUpdated, this._updateDatabase Tables, this);
249 }
250 this._databaseTableViews.clear();
251 this._databaseQueryViews.clear();
252 this._databaseTreeElements.clear();
253 this.databasesListTreeElement.removeChildren();
254 this.databasesListTreeElement.setExpandable(false);
255 }
256
257 _resetDOMStorage() {
258 if (this.visibleView === this._domStorageView) {
259 this.visibleView.detach();
260 delete this.visibleView;
261 }
262
263 this._domStorageTreeElements.clear();
264 this.localStorageListTreeElement.removeChildren();
265 this.sessionStorageListTreeElement.removeChildren();
266 }
267
268 _resetCookies() {
269 if (this.visibleView instanceof Resources.CookieItemsView) {
270 this.visibleView.detach();
271 delete this.visibleView;
272 }
273 this.cookieListTreeElement.removeChildren();
274 }
275
276 _resetCacheStorage() {
277 if (this.visibleView instanceof Resources.ServiceWorkerCacheView) {
278 this.visibleView.detach();
279 delete this.visibleView;
280 }
281 this.cacheStorageListTreeElement.removeChildren();
282 this.cacheStorageListTreeElement.setExpandable(false);
283 }
284
285 _resetAppCache() {
286 for (var frameId of Object.keys(this._applicationCacheFrameElements))
287 this._applicationCacheFrameManifestRemoved({data: frameId});
288 this.applicationCacheListTreeElement.setExpandable(false);
289 }
290
291 _reset() {
292 this._domains = {};
293 this._resetWebSQL();
294 this._resetDOMStorage();
295 this._resetCookies();
296 this._resetCacheStorage();
297 // No need to this._resetAppCache.
298
299 if ((this.visibleView instanceof SourceFrame.ResourceSourceFrame) ||
300 (this.visibleView instanceof SourceFrame.ImageView) || (this.visibleView instanceof SourceFrame.FontView)) {
301 this.visibleView.detach();
302 delete this.visibleView;
303 }
304
305 this._storageViewToolbar.removeToolbarItems();
306
307 if (this._sidebarTree.selectedTreeElement)
308 this._sidebarTree.selectedTreeElement.deselect();
309 }
310
311 _frameNavigated(event) {
312 var frame = event.data;
313
314 if (!frame.parentFrame)
315 this._reset();
316
317 var applicationCacheFrameTreeElement = this._applicationCacheFrameElements[f rame.id];
318 if (applicationCacheFrameTreeElement)
319 applicationCacheFrameTreeElement.frameNavigated(frame);
320 this._addCookieDocument(frame);
321 } 62 }
322 63
323 /** 64 /**
324 * @param {!Resources.DatabaseModel.DatabaseAddedEvent} event
325 */
326 _databaseAdded(event) {
327 var databaseTreeElement = new Resources.DatabaseTreeElement(this, event.data base);
328 this._databaseTreeElements.set(event.database, databaseTreeElement);
329 this.databasesListTreeElement.appendChild(databaseTreeElement);
330 }
331
332 /**
333 * @param {!SDK.ResourceTreeFrame} frame
334 */
335 _addCookieDocument(frame) {
336 var parsedURL = frame.url.asParsedURL();
337 if (!parsedURL || (parsedURL.scheme !== 'http' && parsedURL.scheme !== 'http s' && parsedURL.scheme !== 'file'))
338 return;
339
340 var domain = parsedURL.securityOrigin();
341 if (!this._domains[domain]) {
342 this._domains[domain] = true;
343 var cookieDomainTreeElement = new Resources.CookieTreeElement(this, frame, domain);
344 this.cookieListTreeElement.appendChild(cookieDomainTreeElement);
345 }
346 }
347
348 /**
349 * @param {!Common.Event} event
350 */
351 _domStorageAdded(event) {
352 var domStorage = /** @type {!Resources.DOMStorage} */ (event.data);
353 this._addDOMStorage(domStorage);
354 }
355
356 /**
357 * @param {!Resources.DOMStorage} domStorage
358 */
359 _addDOMStorage(domStorage) {
360 console.assert(!this._domStorageTreeElements.get(domStorage));
361
362 var domStorageTreeElement = new Resources.DOMStorageTreeElement(this, domSto rage);
363 this._domStorageTreeElements.set(domStorage, domStorageTreeElement);
364 if (domStorage.isLocalStorage)
365 this.localStorageListTreeElement.appendChild(domStorageTreeElement);
366 else
367 this.sessionStorageListTreeElement.appendChild(domStorageTreeElement);
368 }
369
370 /**
371 * @param {!Common.Event} event
372 */
373 _domStorageRemoved(event) {
374 var domStorage = /** @type {!Resources.DOMStorage} */ (event.data);
375 this._removeDOMStorage(domStorage);
376 }
377
378 /**
379 * @param {!Resources.DOMStorage} domStorage
380 */
381 _removeDOMStorage(domStorage) {
382 var treeElement = this._domStorageTreeElements.get(domStorage);
383 if (!treeElement)
384 return;
385 var wasSelected = treeElement.selected;
386 var parentListTreeElement = treeElement.parent;
387 parentListTreeElement.removeChild(treeElement);
388 if (wasSelected)
389 parentListTreeElement.select();
390 this._domStorageTreeElements.remove(domStorage);
391 }
392
393 /**
394 * @param {!Resources.Database} database
395 */
396 selectDatabase(database) {
397 if (database) {
398 this._showDatabase(database);
399 this._databaseTreeElements.get(database).select();
400 }
401 }
402
403 /**
404 * @param {!Resources.DOMStorage} domStorage
405 */
406 selectDOMStorage(domStorage) {
407 if (domStorage) {
408 this._showDOMStorage(domStorage);
409 this._domStorageTreeElements.get(domStorage).select();
410 }
411 }
412
413 /**
414 * @param {!SDK.Resource} resource 65 * @param {!SDK.Resource} resource
415 * @param {number=} line 66 * @param {number=} line
416 * @param {number=} column 67 * @param {number=} column
417 * @return {boolean} 68 * @return {boolean}
418 */ 69 */
419 showResource(resource, line, column) { 70 showResource(resource, line, column) {
420 var resourceTreeElement = Resources.FrameResourceTreeElement.forResource(res ource); 71 return this._sidebar.showResource(resource, line, column);
421 if (resourceTreeElement)
422 resourceTreeElement.revealAndSelect(true);
423
424 if (typeof line === 'number') {
425 var resourceSourceFrame = this._resourceSourceFrameViewForResource(resourc e);
426 if (resourceSourceFrame)
427 resourceSourceFrame.revealPosition(line, column, true);
428 }
429 return true;
430 }
431
432 /**
433 * @param {!SDK.Resource} resource
434 * @return {?SourceFrame.ResourceSourceFrame}
435 */
436 _resourceSourceFrameViewForResource(resource) {
437 var resourceView = Resources.FrameResourceTreeElement.resourceViewForResourc e(resource);
438 if (resourceView && resourceView instanceof SourceFrame.ResourceSourceFrame)
439 return /** @type {!SourceFrame.ResourceSourceFrame} */ (resourceView);
440 return null;
441 }
442
443 /**
444 * @param {!Resources.Database} database
445 * @param {string=} tableName
446 */
447 _showDatabase(database, tableName) {
448 if (!database)
449 return;
450
451 var view;
452 if (tableName) {
453 var tableViews = this._databaseTableViews.get(database);
454 if (!tableViews) {
455 tableViews = /** @type {!Object.<string, !Resources.DatabaseTableView>} */ ({});
456 this._databaseTableViews.set(database, tableViews);
457 }
458 view = tableViews[tableName];
459 if (!view) {
460 view = new Resources.DatabaseTableView(database, tableName);
461 tableViews[tableName] = view;
462 }
463 } else {
464 view = this._databaseQueryViews.get(database);
465 if (!view) {
466 view = new Resources.DatabaseQueryView(database);
467 this._databaseQueryViews.set(database, view);
468 view.addEventListener(Resources.DatabaseQueryView.Events.SchemaUpdated, this._updateDatabaseTables, this);
469 }
470 }
471
472 this._innerShowView(view);
473 } 72 }
474 73
475 /** 74 /**
476 * @param {!Resources.DOMStorage} domStorage 75 * @param {!Resources.DOMStorage} domStorage
477 */ 76 */
478 _showDOMStorage(domStorage) { 77 _showDOMStorage(domStorage) {
479 if (!domStorage) 78 this._sidebar.showDOMStorage(domStorage);
480 return;
481
482 if (!this._domStorageView)
483 this._domStorageView = new Resources.DOMStorageItemsView(domStorage);
484 else
485 this._domStorageView.setStorage(domStorage);
486 this._innerShowView(this._domStorageView);
487 } 79 }
488 80
489 /** 81 _createPropertyForTest(name) {
490 * @param {!Resources.CookieTreeElement} treeElement 82 Object.defineProperty(this, name, {get: () => this._sidebar[name]});
491 * @param {string} cookieDomain
492 * @param {!SDK.Target} cookieFrameTarget
493 */
494 showCookies(treeElement, cookieDomain, cookieFrameTarget) {
495 var model = SDK.CookieModel.fromTarget(cookieFrameTarget);
496 if (!this._cookieView)
497 this._cookieView = new Resources.CookieItemsView(treeElement, model, cooki eDomain);
498 else
499 this._cookieView.setCookiesDomain(model, cookieDomain);
500 this._innerShowView(this._cookieView);
501 } 83 }
502 84
503 /**
504 * @param {!SDK.Target} target
505 * @param {string} cookieDomain
506 */
507 _clearCookies(target, cookieDomain) {
508 SDK.CookieModel.fromTarget(target).clear(cookieDomain, () => {
509 if (this._cookieView)
510 this._cookieView.refreshItems();
511 });
512 }
513
514 showApplicationCache(frameId) {
515 if (!this._applicationCacheViews[frameId]) {
516 this._applicationCacheViews[frameId] =
517 new Resources.ApplicationCacheItemsView(this._applicationCacheModel, f rameId);
518 }
519
520 this._innerShowView(this._applicationCacheViews[frameId]);
521 }
522
523 /**
524 * @param {!UI.Widget} view
525 */
526 showFileSystem(view) {
527 this._innerShowView(view);
528 }
529
530 showCategoryView(categoryName) {
531 if (!this._categoryView)
532 this._categoryView = new Resources.StorageCategoryView();
533 this._categoryView.setText(categoryName);
534 this._innerShowView(this._categoryView);
535 }
536
537 _innerShowView(view) {
538 if (this.visibleView === view)
539 return;
540
541 if (this.visibleView)
542 this.visibleView.detach();
543
544 view.show(this.storageViews);
545 this.visibleView = view;
546
547 this._storageViewToolbar.removeToolbarItems();
548 var toolbarItems = (view instanceof UI.SimpleView && view.syncToolbarItems() ) || [];
549 for (var i = 0; i < toolbarItems.length; ++i)
550 this._storageViewToolbar.appendToolbarItem(toolbarItems[i]);
551 this._storageViewToolbar.element.classList.toggle('hidden', !toolbarItems.le ngth);
552 }
553
554 closeVisibleView() {
555 if (!this.visibleView)
556 return;
557 this.visibleView.detach();
558 delete this.visibleView;
559 }
560
561 _updateDatabaseTables(event) {
562 var database = event.data;
563
564 if (!database)
565 return;
566
567 var databasesTreeElement = this._databaseTreeElements.get(database);
568 if (!databasesTreeElement)
569 return;
570
571 databasesTreeElement.invalidateChildren();
572 var tableViews = this._databaseTableViews.get(database);
573
574 if (!tableViews)
575 return;
576
577 var tableNamesHash = {};
578 var self = this;
579 function tableNamesCallback(tableNames) {
580 var tableNamesLength = tableNames.length;
581 for (var i = 0; i < tableNamesLength; ++i)
582 tableNamesHash[tableNames[i]] = true;
583
584 for (var tableName in tableViews) {
585 if (!(tableName in tableNamesHash)) {
586 if (self.visibleView === tableViews[tableName])
587 self.closeVisibleView();
588 delete tableViews[tableName];
589 }
590 }
591 }
592 database.getTableNames(tableNamesCallback);
593 }
594
595 /**
596 * @param {!Resources.DOMStorageModel} domStorageModel
597 */
598 _populateDOMStorageTree(domStorageModel) {
599 domStorageModel.enable();
600 domStorageModel.storages().forEach(this._addDOMStorage.bind(this));
601 domStorageModel.addEventListener(Resources.DOMStorageModel.Events.DOMStorage Added, this._domStorageAdded, this);
602 domStorageModel.addEventListener(Resources.DOMStorageModel.Events.DOMStorage Removed, this._domStorageRemoved, this);
603 }
604
605 /**
606 * @param {!SDK.ResourceTreeModel} resourceTreeModel
607 */
608 _populateApplicationCacheTree(resourceTreeModel) {
609 this._applicationCacheModel = Resources.ApplicationCacheModel.fromTarget(thi s._target);
610
611 this._applicationCacheViews = {};
612 this._applicationCacheFrameElements = {};
613 this._applicationCacheManifestElements = {};
614
615 this._applicationCacheModel.addEventListener(
616 Resources.ApplicationCacheModel.Events.FrameManifestAdded, this._applica tionCacheFrameManifestAdded, this);
617 this._applicationCacheModel.addEventListener(
618 Resources.ApplicationCacheModel.Events.FrameManifestRemoved, this._appli cationCacheFrameManifestRemoved, this);
619 this._applicationCacheModel.addEventListener(
620 Resources.ApplicationCacheModel.Events.FrameManifestsReset, this._resetA ppCache, this);
621
622 this._applicationCacheModel.addEventListener(
623 Resources.ApplicationCacheModel.Events.FrameManifestStatusUpdated,
624 this._applicationCacheFrameManifestStatusChanged, this);
625 this._applicationCacheModel.addEventListener(
626 Resources.ApplicationCacheModel.Events.NetworkStateChanged, this._applic ationCacheNetworkStateChanged, this);
627 }
628
629 _applicationCacheFrameManifestAdded(event) {
630 var frameId = event.data;
631 var manifestURL = this._applicationCacheModel.frameManifestURL(frameId);
632
633 var manifestTreeElement = this._applicationCacheManifestElements[manifestURL ];
634 if (!manifestTreeElement) {
635 manifestTreeElement = new Resources.ApplicationCacheManifestTreeElement(th is, manifestURL);
636 this.applicationCacheListTreeElement.appendChild(manifestTreeElement);
637 this._applicationCacheManifestElements[manifestURL] = manifestTreeElement;
638 }
639
640 var frameTreeElement = new Resources.ApplicationCacheFrameTreeElement(this, frameId, manifestURL);
641 manifestTreeElement.appendChild(frameTreeElement);
642 manifestTreeElement.expand();
643 this._applicationCacheFrameElements[frameId] = frameTreeElement;
644 }
645
646 _applicationCacheFrameManifestRemoved(event) {
647 var frameId = event.data;
648 var frameTreeElement = this._applicationCacheFrameElements[frameId];
649 if (!frameTreeElement)
650 return;
651
652 var manifestURL = frameTreeElement.manifestURL;
653 delete this._applicationCacheFrameElements[frameId];
654 delete this._applicationCacheViews[frameId];
655 frameTreeElement.parent.removeChild(frameTreeElement);
656
657 var manifestTreeElement = this._applicationCacheManifestElements[manifestURL ];
658 if (manifestTreeElement.childCount())
659 return;
660
661 delete this._applicationCacheManifestElements[manifestURL];
662 manifestTreeElement.parent.removeChild(manifestTreeElement);
663 }
664
665 _applicationCacheFrameManifestStatusChanged(event) {
666 var frameId = event.data;
667 var status = this._applicationCacheModel.frameManifestStatus(frameId);
668
669 if (this._applicationCacheViews[frameId])
670 this._applicationCacheViews[frameId].updateStatus(status);
671 }
672
673 _applicationCacheNetworkStateChanged(event) {
674 var isNowOnline = event.data;
675
676 for (var manifestURL in this._applicationCacheViews)
677 this._applicationCacheViews[manifestURL].updateNetworkState(isNowOnline);
678 }
679
680 showView(view) {
681 if (view)
682 this.showResource(view.resource);
683 }
684
685 _onmousemove(event) {
686 var nodeUnderMouse = event.target;
687 if (!nodeUnderMouse)
688 return;
689
690 var listNode = nodeUnderMouse.enclosingNodeOrSelfWithNodeName('li');
691 if (!listNode)
692 return;
693
694 var element = listNode.treeElement;
695 if (this._previousHoveredElement === element)
696 return;
697
698 if (this._previousHoveredElement) {
699 this._previousHoveredElement.hovered = false;
700 delete this._previousHoveredElement;
701 }
702
703 if (element instanceof Resources.FrameTreeElement) {
704 this._previousHoveredElement = element;
705 element.hovered = true;
706 }
707 }
708
709 _onmouseleave(event) {
710 if (this._previousHoveredElement) {
711 this._previousHoveredElement.hovered = false;
712 delete this._previousHoveredElement;
713 }
714 }
715 }; 85 };
716 86
717 /** 87 /**
718 * @implements {Common.Revealer} 88 * @implements {Common.Revealer}
719 * @unrestricted 89 * @unrestricted
720 */ 90 */
721 Resources.ResourcesPanel.ResourceRevealer = class { 91 Resources.ResourcesPanel.ResourceRevealer = class {
722 /** 92 /**
723 * @override 93 * @override
724 * @param {!Object} resource 94 * @param {!Object} resource
725 * @return {!Promise} 95 * @return {!Promise}
726 */ 96 */
727 reveal(resource) { 97 reveal(resource) {
728 if (!(resource instanceof SDK.Resource)) 98 if (!(resource instanceof SDK.Resource))
729 return Promise.reject(new Error('Internal error: not a resource')); 99 return Promise.reject(new Error('Internal error: not a resource'));
730 var panel = Resources.ResourcesPanel._instance(); 100 var panel = Resources.ResourcesPanel._instance();
731 return UI.viewManager.showView('resources').then(panel.showResource.bind(pan el, resource)); 101 return UI.viewManager.showView('resources').then(panel.showResource.bind(pan el, resource));
732 } 102 }
733 }; 103 };
734
735 /**
736 * @unrestricted
737 */
738 Resources.BaseStorageTreeElement = class extends UI.TreeElement {
739 /**
740 * @param {!Resources.ResourcesPanel} storagePanel
741 * @param {string} title
742 * @param {boolean} expandable
743 */
744 constructor(storagePanel, title, expandable) {
745 super(title, expandable);
746 this._storagePanel = storagePanel;
747 }
748
749 /**
750 * @override
751 * @return {boolean}
752 */
753 onselect(selectedByUser) {
754 if (!selectedByUser)
755 return false;
756 var itemURL = this.itemURL;
757 if (itemURL)
758 this._storagePanel._resourcesLastSelectedItemSetting.set(itemURL);
759 return false;
760 }
761
762 /**
763 * @protected
764 * @param {?UI.Widget} view
765 */
766 showView(view) {
767 if (!view) {
768 this._storagePanel.visibleView.detach();
769 return;
770 }
771 this._storagePanel._innerShowView(view);
772 }
773 };
774
775 /**
776 * @unrestricted
777 */
778 Resources.StorageCategoryTreeElement = class extends Resources.BaseStorageTreeEl ement {
779 /**
780 * @param {!Resources.ResourcesPanel} storagePanel
781 * @param {string} categoryName
782 * @param {string} settingsKey
783 */
784 constructor(storagePanel, categoryName, settingsKey) {
785 super(storagePanel, categoryName, false);
786 this._expandedSetting =
787 Common.settings.createSetting('resources' + settingsKey + 'Expanded', se ttingsKey === 'Frames');
788 this._categoryName = categoryName;
789 }
790
791 /**
792 * @return {!SDK.Target}
793 */
794 target() {
795 return this._storagePanel._target;
796 }
797
798 get itemURL() {
799 return 'category://' + this._categoryName;
800 }
801
802 /**
803 * @override
804 * @return {boolean}
805 */
806 onselect(selectedByUser) {
807 super.onselect(selectedByUser);
808 this._storagePanel.showCategoryView(this._categoryName);
809 return false;
810 }
811
812 /**
813 * @override
814 */
815 onattach() {
816 super.onattach();
817 if (this._expandedSetting.get())
818 this.expand();
819 }
820
821 /**
822 * @override
823 */
824 onexpand() {
825 this._expandedSetting.set(true);
826 }
827
828 /**
829 * @override
830 */
831 oncollapse() {
832 this._expandedSetting.set(false);
833 }
834 };
835
836 /**
837 * @unrestricted
838 */
839 Resources.DatabaseTreeElement = class extends Resources.BaseStorageTreeElement {
840 /**
841 * @param {!Resources.ResourcesPanel} storagePanel
842 * @param {!Resources.Database} database
843 */
844 constructor(storagePanel, database) {
845 super(storagePanel, database.name, true);
846 this._database = database;
847
848 var icon = UI.Icon.create('mediumicon-database', 'resource-tree-item');
849 this.setLeadingIcons([icon]);
850 }
851
852 get itemURL() {
853 return 'database://' + encodeURI(this._database.name);
854 }
855
856 /**
857 * @override
858 * @return {boolean}
859 */
860 onselect(selectedByUser) {
861 super.onselect(selectedByUser);
862 this._storagePanel._showDatabase(this._database);
863 return false;
864 }
865
866 /**
867 * @override
868 */
869 onexpand() {
870 this._updateChildren();
871 }
872
873 _updateChildren() {
874 this.removeChildren();
875
876 /**
877 * @param {!Array.<string>} tableNames
878 * @this {Resources.DatabaseTreeElement}
879 */
880 function tableNamesCallback(tableNames) {
881 var tableNamesLength = tableNames.length;
882 for (var i = 0; i < tableNamesLength; ++i)
883 this.appendChild(new Resources.DatabaseTableTreeElement(this._storagePan el, this._database, tableNames[i]));
884 }
885 this._database.getTableNames(tableNamesCallback.bind(this));
886 }
887 };
888
889 /**
890 * @unrestricted
891 */
892 Resources.DatabaseTableTreeElement = class extends Resources.BaseStorageTreeElem ent {
893 constructor(storagePanel, database, tableName) {
894 super(storagePanel, tableName, false);
895 this._database = database;
896 this._tableName = tableName;
897 var icon = UI.Icon.create('mediumicon-table', 'resource-tree-item');
898 this.setLeadingIcons([icon]);
899 }
900
901 get itemURL() {
902 return 'database://' + encodeURI(this._database.name) + '/' + encodeURI(this ._tableName);
903 }
904
905 /**
906 * @override
907 * @return {boolean}
908 */
909 onselect(selectedByUser) {
910 super.onselect(selectedByUser);
911 this._storagePanel._showDatabase(this._database, this._tableName);
912 return false;
913 }
914 };
915
916 /**
917 * @unrestricted
918 */
919 Resources.ServiceWorkerCacheTreeElement = class extends Resources.StorageCategor yTreeElement {
920 /**
921 * @param {!Resources.ResourcesPanel} storagePanel
922 */
923 constructor(storagePanel) {
924 super(storagePanel, Common.UIString('Cache Storage'), 'CacheStorage');
925 var icon = UI.Icon.create('mediumicon-database', 'resource-tree-item');
926 this.setLeadingIcons([icon]);
927 }
928
929 _initialize() {
930 /** @type {!Array.<!Resources.SWCacheTreeElement>} */
931 this._swCacheTreeElements = [];
932 var target = this._storagePanel._target;
933 var model = target && SDK.ServiceWorkerCacheModel.fromTarget(target);
934 if (model) {
935 for (var cache of model.caches())
936 this._addCache(model, cache);
937 }
938 SDK.targetManager.addModelListener(
939 SDK.ServiceWorkerCacheModel, SDK.ServiceWorkerCacheModel.Events.CacheAdd ed, this._cacheAdded, this);
940 SDK.targetManager.addModelListener(
941 SDK.ServiceWorkerCacheModel, SDK.ServiceWorkerCacheModel.Events.CacheRem oved, this._cacheRemoved, this);
942 }
943
944 /**
945 * @override
946 */
947 onattach() {
948 super.onattach();
949 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
950 }
951
952 _handleContextMenuEvent(event) {
953 var contextMenu = new UI.ContextMenu(event);
954 contextMenu.appendItem(Common.UIString('Refresh Caches'), this._refreshCache s.bind(this));
955 contextMenu.show();
956 }
957
958 _refreshCaches() {
959 var target = this._storagePanel._target;
960 if (target) {
961 var model = SDK.ServiceWorkerCacheModel.fromTarget(target);
962 if (!model)
963 return;
964 model.refreshCacheNames();
965 }
966 }
967
968 /**
969 * @param {!Common.Event} event
970 */
971 _cacheAdded(event) {
972 var cache = /** @type {!SDK.ServiceWorkerCacheModel.Cache} */ (event.data.ca che);
973 var model = /** @type {!SDK.ServiceWorkerCacheModel} */ (event.data.model);
974 this._addCache(model, cache);
975 }
976
977 /**
978 * @param {!SDK.ServiceWorkerCacheModel} model
979 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache
980 */
981 _addCache(model, cache) {
982 var swCacheTreeElement = new Resources.SWCacheTreeElement(this._storagePanel , model, cache);
983 this._swCacheTreeElements.push(swCacheTreeElement);
984 this.appendChild(swCacheTreeElement);
985 }
986
987 /**
988 * @param {!Common.Event} event
989 */
990 _cacheRemoved(event) {
991 var cache = /** @type {!SDK.ServiceWorkerCacheModel.Cache} */ (event.data.ca che);
992 var model = /** @type {!SDK.ServiceWorkerCacheModel} */ (event.data.model);
993
994 var swCacheTreeElement = this._cacheTreeElement(model, cache);
995 if (!swCacheTreeElement)
996 return;
997
998 swCacheTreeElement.clear();
999 this.removeChild(swCacheTreeElement);
1000 this._swCacheTreeElements.remove(swCacheTreeElement);
1001 }
1002
1003 /**
1004 * @param {!SDK.ServiceWorkerCacheModel} model
1005 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache
1006 * @return {?Resources.SWCacheTreeElement}
1007 */
1008 _cacheTreeElement(model, cache) {
1009 var index = -1;
1010 for (var i = 0; i < this._swCacheTreeElements.length; ++i) {
1011 if (this._swCacheTreeElements[i]._cache.equals(cache) && this._swCacheTree Elements[i]._model === model) {
1012 index = i;
1013 break;
1014 }
1015 }
1016 if (index !== -1)
1017 return this._swCacheTreeElements[i];
1018 return null;
1019 }
1020 };
1021
1022 /**
1023 * @unrestricted
1024 */
1025 Resources.SWCacheTreeElement = class extends Resources.BaseStorageTreeElement {
1026 /**
1027 * @param {!Resources.ResourcesPanel} storagePanel
1028 * @param {!SDK.ServiceWorkerCacheModel} model
1029 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache
1030 */
1031 constructor(storagePanel, model, cache) {
1032 super(storagePanel, cache.cacheName + ' - ' + cache.securityOrigin, false);
1033 this._model = model;
1034 this._cache = cache;
1035 var icon = UI.Icon.create('mediumicon-table', 'resource-tree-item');
1036 this.setLeadingIcons([icon]);
1037 }
1038
1039 get itemURL() {
1040 // I don't think this will work at all.
1041 return 'cache://' + this._cache.cacheId;
1042 }
1043
1044 /**
1045 * @override
1046 */
1047 onattach() {
1048 super.onattach();
1049 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1050 }
1051
1052 _handleContextMenuEvent(event) {
1053 var contextMenu = new UI.ContextMenu(event);
1054 contextMenu.appendItem(Common.UIString('Delete'), this._clearCache.bind(this ));
1055 contextMenu.show();
1056 }
1057
1058 _clearCache() {
1059 this._model.deleteCache(this._cache);
1060 }
1061
1062 /**
1063 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache
1064 */
1065 update(cache) {
1066 this._cache = cache;
1067 if (this._view)
1068 this._view.update(cache);
1069 }
1070
1071 /**
1072 * @override
1073 * @return {boolean}
1074 */
1075 onselect(selectedByUser) {
1076 super.onselect(selectedByUser);
1077 if (!this._view)
1078 this._view = new Resources.ServiceWorkerCacheView(this._model, this._cache );
1079
1080 this.showView(this._view);
1081 return false;
1082 }
1083
1084 clear() {
1085 if (this._view)
1086 this._view.clear();
1087 }
1088 };
1089
1090 /**
1091 * @unrestricted
1092 */
1093 Resources.ServiceWorkersTreeElement = class extends Resources.BaseStorageTreeEle ment {
1094 /**
1095 * @param {!Resources.ResourcesPanel} storagePanel
1096 */
1097 constructor(storagePanel) {
1098 super(storagePanel, Common.UIString('Service Workers'), false);
1099 var icon = UI.Icon.create('mediumicon-service-worker', 'resource-tree-item') ;
1100 this.setLeadingIcons([icon]);
1101 }
1102
1103 /**
1104 * @return {string}
1105 */
1106 get itemURL() {
1107 return 'service-workers://';
1108 }
1109
1110 /**
1111 * @override
1112 * @return {boolean}
1113 */
1114 onselect(selectedByUser) {
1115 super.onselect(selectedByUser);
1116 if (!this._view)
1117 this._view = new Resources.ServiceWorkersView();
1118 this.showView(this._view);
1119 return false;
1120 }
1121 };
1122
1123 /**
1124 * @unrestricted
1125 */
1126 Resources.AppManifestTreeElement = class extends Resources.BaseStorageTreeElemen t {
1127 /**
1128 * @param {!Resources.ResourcesPanel} storagePanel
1129 */
1130 constructor(storagePanel) {
1131 super(storagePanel, Common.UIString('Manifest'), false);
1132 var icon = UI.Icon.create('mediumicon-manifest', 'resource-tree-item');
1133 this.setLeadingIcons([icon]);
1134 }
1135
1136 /**
1137 * @return {string}
1138 */
1139 get itemURL() {
1140 return 'manifest://';
1141 }
1142
1143 /**
1144 * @override
1145 * @return {boolean}
1146 */
1147 onselect(selectedByUser) {
1148 super.onselect(selectedByUser);
1149 if (!this._view)
1150 this._view = new Resources.AppManifestView();
1151 this.showView(this._view);
1152 return false;
1153 }
1154 };
1155
1156 /**
1157 * @unrestricted
1158 */
1159 Resources.ClearStorageTreeElement = class extends Resources.BaseStorageTreeEleme nt {
1160 /**
1161 * @param {!Resources.ResourcesPanel} storagePanel
1162 */
1163 constructor(storagePanel) {
1164 super(storagePanel, Common.UIString('Clear storage'), false);
1165 var icon = UI.Icon.create('mediumicon-clear-storage', 'resource-tree-item');
1166 this.setLeadingIcons([icon]);
1167 }
1168
1169 /**
1170 * @return {string}
1171 */
1172 get itemURL() {
1173 return 'clear-storage://';
1174 }
1175
1176 /**
1177 * @override
1178 * @return {boolean}
1179 */
1180 onselect(selectedByUser) {
1181 super.onselect(selectedByUser);
1182 if (!this._view)
1183 this._view = new Resources.ClearStorageView(this._storagePanel);
1184 this.showView(this._view);
1185 return false;
1186 }
1187 };
1188
1189 /**
1190 * @unrestricted
1191 */
1192 Resources.IndexedDBTreeElement = class extends Resources.StorageCategoryTreeElem ent {
1193 /**
1194 * @param {!Resources.ResourcesPanel} storagePanel
1195 */
1196 constructor(storagePanel) {
1197 super(storagePanel, Common.UIString('IndexedDB'), 'IndexedDB');
1198 var icon = UI.Icon.create('mediumicon-database', 'resource-tree-item');
1199 this.setLeadingIcons([icon]);
1200 }
1201
1202 _initialize() {
1203 SDK.targetManager.addModelListener(
1204 Resources.IndexedDBModel, Resources.IndexedDBModel.Events.DatabaseAdded, this._indexedDBAdded, this);
1205 SDK.targetManager.addModelListener(
1206 Resources.IndexedDBModel, Resources.IndexedDBModel.Events.DatabaseRemove d, this._indexedDBRemoved, this);
1207 SDK.targetManager.addModelListener(
1208 Resources.IndexedDBModel, Resources.IndexedDBModel.Events.DatabaseLoaded , this._indexedDBLoaded, this);
1209 /** @type {!Array.<!Resources.IDBDatabaseTreeElement>} */
1210 this._idbDatabaseTreeElements = [];
1211
1212 var targets = SDK.targetManager.targets(SDK.Target.Capability.Browser);
1213 for (var i = 0; i < targets.length; ++i) {
1214 var indexedDBModel = Resources.IndexedDBModel.fromTarget(targets[i]);
1215 var databases = indexedDBModel.databases();
1216 for (var j = 0; j < databases.length; ++j)
1217 this._addIndexedDB(indexedDBModel, databases[j]);
1218 }
1219 }
1220
1221 /**
1222 * @override
1223 */
1224 onattach() {
1225 super.onattach();
1226 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1227 }
1228
1229 _handleContextMenuEvent(event) {
1230 var contextMenu = new UI.ContextMenu(event);
1231 contextMenu.appendItem(Common.UIString('Refresh IndexedDB'), this.refreshInd exedDB.bind(this));
1232 contextMenu.show();
1233 }
1234
1235 refreshIndexedDB() {
1236 var targets = SDK.targetManager.targets(SDK.Target.Capability.Browser);
1237 for (var i = 0; i < targets.length; ++i)
1238 Resources.IndexedDBModel.fromTarget(targets[i]).refreshDatabaseNames();
1239 }
1240
1241 /**
1242 * @param {!Common.Event} event
1243 */
1244 _indexedDBAdded(event) {
1245 var databaseId = /** @type {!Resources.IndexedDBModel.DatabaseId} */ (event. data.databaseId);
1246 var model = /** @type {!Resources.IndexedDBModel} */ (event.data.model);
1247 this._addIndexedDB(model, databaseId);
1248 }
1249
1250 /**
1251 * @param {!Resources.IndexedDBModel} model
1252 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId
1253 */
1254 _addIndexedDB(model, databaseId) {
1255 var idbDatabaseTreeElement = new Resources.IDBDatabaseTreeElement(this._stor agePanel, model, databaseId);
1256 this._idbDatabaseTreeElements.push(idbDatabaseTreeElement);
1257 this.appendChild(idbDatabaseTreeElement);
1258 model.refreshDatabase(databaseId);
1259 }
1260
1261 /**
1262 * @param {!Common.Event} event
1263 */
1264 _indexedDBRemoved(event) {
1265 var databaseId = /** @type {!Resources.IndexedDBModel.DatabaseId} */ (event. data.databaseId);
1266 var model = /** @type {!Resources.IndexedDBModel} */ (event.data.model);
1267
1268 var idbDatabaseTreeElement = this._idbDatabaseTreeElement(model, databaseId) ;
1269 if (!idbDatabaseTreeElement)
1270 return;
1271
1272 idbDatabaseTreeElement.clear();
1273 this.removeChild(idbDatabaseTreeElement);
1274 this._idbDatabaseTreeElements.remove(idbDatabaseTreeElement);
1275 }
1276
1277 /**
1278 * @param {!Common.Event} event
1279 */
1280 _indexedDBLoaded(event) {
1281 var database = /** @type {!Resources.IndexedDBModel.Database} */ (event.data .database);
1282 var model = /** @type {!Resources.IndexedDBModel} */ (event.data.model);
1283
1284 var idbDatabaseTreeElement = this._idbDatabaseTreeElement(model, database.da tabaseId);
1285 if (!idbDatabaseTreeElement)
1286 return;
1287
1288 idbDatabaseTreeElement.update(database);
1289 }
1290
1291 /**
1292 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId
1293 * @param {!Resources.IndexedDBModel} model
1294 * @return {?Resources.IDBDatabaseTreeElement}
1295 */
1296 _idbDatabaseTreeElement(model, databaseId) {
1297 var index = -1;
1298 for (var i = 0; i < this._idbDatabaseTreeElements.length; ++i) {
1299 if (this._idbDatabaseTreeElements[i]._databaseId.equals(databaseId) &&
1300 this._idbDatabaseTreeElements[i]._model === model) {
1301 index = i;
1302 break;
1303 }
1304 }
1305 if (index !== -1)
1306 return this._idbDatabaseTreeElements[i];
1307 return null;
1308 }
1309 };
1310
1311 /**
1312 * @unrestricted
1313 */
1314 Resources.IDBDatabaseTreeElement = class extends Resources.BaseStorageTreeElemen t {
1315 /**
1316 * @param {!Resources.ResourcesPanel} storagePanel
1317 * @param {!Resources.IndexedDBModel} model
1318 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId
1319 */
1320 constructor(storagePanel, model, databaseId) {
1321 super(storagePanel, databaseId.name + ' - ' + databaseId.securityOrigin, fal se);
1322 this._model = model;
1323 this._databaseId = databaseId;
1324 this._idbObjectStoreTreeElements = {};
1325 var icon = UI.Icon.create('mediumicon-database', 'resource-tree-item');
1326 this.setLeadingIcons([icon]);
1327 }
1328
1329 get itemURL() {
1330 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name;
1331 }
1332
1333 /**
1334 * @override
1335 */
1336 onattach() {
1337 super.onattach();
1338 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1339 }
1340
1341 _handleContextMenuEvent(event) {
1342 var contextMenu = new UI.ContextMenu(event);
1343 contextMenu.appendItem(Common.UIString('Refresh IndexedDB'), this._refreshIn dexedDB.bind(this));
1344 contextMenu.show();
1345 }
1346
1347 _refreshIndexedDB() {
1348 this._model.refreshDatabaseNames();
1349 }
1350
1351 /**
1352 * @param {!Resources.IndexedDBModel.Database} database
1353 */
1354 update(database) {
1355 this._database = database;
1356 var objectStoreNames = {};
1357 for (var objectStoreName in this._database.objectStores) {
1358 var objectStore = this._database.objectStores[objectStoreName];
1359 objectStoreNames[objectStore.name] = true;
1360 if (!this._idbObjectStoreTreeElements[objectStore.name]) {
1361 var idbObjectStoreTreeElement =
1362 new Resources.IDBObjectStoreTreeElement(this._storagePanel, this._mo del, this._databaseId, objectStore);
1363 this._idbObjectStoreTreeElements[objectStore.name] = idbObjectStoreTreeE lement;
1364 this.appendChild(idbObjectStoreTreeElement);
1365 }
1366 this._idbObjectStoreTreeElements[objectStore.name].update(objectStore);
1367 }
1368 for (var objectStoreName in this._idbObjectStoreTreeElements) {
1369 if (!objectStoreNames[objectStoreName])
1370 this._objectStoreRemoved(objectStoreName);
1371 }
1372
1373 if (this._view)
1374 this._view.update(database);
1375
1376 this._updateTooltip();
1377 }
1378
1379 _updateTooltip() {
1380 this.tooltip = Common.UIString('Version') + ': ' + this._database.version;
1381 }
1382
1383 /**
1384 * @override
1385 * @return {boolean}
1386 */
1387 onselect(selectedByUser) {
1388 super.onselect(selectedByUser);
1389 if (!this._view)
1390 this._view = new Resources.IDBDatabaseView(this._model, this._database);
1391
1392 this.showView(this._view);
1393 return false;
1394 }
1395
1396 /**
1397 * @param {string} objectStoreName
1398 */
1399 _objectStoreRemoved(objectStoreName) {
1400 var objectStoreTreeElement = this._idbObjectStoreTreeElements[objectStoreNam e];
1401 objectStoreTreeElement.clear();
1402 this.removeChild(objectStoreTreeElement);
1403 delete this._idbObjectStoreTreeElements[objectStoreName];
1404 }
1405
1406 clear() {
1407 for (var objectStoreName in this._idbObjectStoreTreeElements)
1408 this._objectStoreRemoved(objectStoreName);
1409 }
1410 };
1411
1412 /**
1413 * @unrestricted
1414 */
1415 Resources.IDBObjectStoreTreeElement = class extends Resources.BaseStorageTreeEle ment {
1416 /**
1417 * @param {!Resources.ResourcesPanel} storagePanel
1418 * @param {!Resources.IndexedDBModel} model
1419 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId
1420 * @param {!Resources.IndexedDBModel.ObjectStore} objectStore
1421 */
1422 constructor(storagePanel, model, databaseId, objectStore) {
1423 super(storagePanel, objectStore.name, false);
1424 this._model = model;
1425 this._databaseId = databaseId;
1426 this._idbIndexTreeElements = {};
1427 var icon = UI.Icon.create('mediumicon-table', 'resource-tree-item');
1428 this.setLeadingIcons([icon]);
1429 }
1430
1431 get itemURL() {
1432 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name + '/' +
1433 this._objectStore.name;
1434 }
1435
1436 /**
1437 * @override
1438 */
1439 onattach() {
1440 super.onattach();
1441 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1442 }
1443
1444 _handleContextMenuEvent(event) {
1445 var contextMenu = new UI.ContextMenu(event);
1446 contextMenu.appendItem(Common.UIString('Clear'), this._clearObjectStore.bind (this));
1447 contextMenu.show();
1448 }
1449
1450 _clearObjectStore() {
1451 /**
1452 * @this {Resources.IDBObjectStoreTreeElement}
1453 */
1454 function callback() {
1455 this.update(this._objectStore);
1456 }
1457 this._model.clearObjectStore(this._databaseId, this._objectStore.name, callb ack.bind(this));
1458 }
1459
1460 /**
1461 * @param {!Resources.IndexedDBModel.ObjectStore} objectStore
1462 */
1463 update(objectStore) {
1464 this._objectStore = objectStore;
1465
1466 var indexNames = {};
1467 for (var indexName in this._objectStore.indexes) {
1468 var index = this._objectStore.indexes[indexName];
1469 indexNames[index.name] = true;
1470 if (!this._idbIndexTreeElements[index.name]) {
1471 var idbIndexTreeElement = new Resources.IDBIndexTreeElement(
1472 this._storagePanel, this._model, this._databaseId, this._objectStore , index);
1473 this._idbIndexTreeElements[index.name] = idbIndexTreeElement;
1474 this.appendChild(idbIndexTreeElement);
1475 }
1476 this._idbIndexTreeElements[index.name].update(index);
1477 }
1478 for (var indexName in this._idbIndexTreeElements) {
1479 if (!indexNames[indexName])
1480 this._indexRemoved(indexName);
1481 }
1482 for (var indexName in this._idbIndexTreeElements) {
1483 if (!indexNames[indexName]) {
1484 this.removeChild(this._idbIndexTreeElements[indexName]);
1485 delete this._idbIndexTreeElements[indexName];
1486 }
1487 }
1488
1489 if (this.childCount())
1490 this.expand();
1491
1492 if (this._view)
1493 this._view.update(this._objectStore);
1494
1495 this._updateTooltip();
1496 }
1497
1498 _updateTooltip() {
1499 var keyPathString = this._objectStore.keyPathString;
1500 var tooltipString = keyPathString !== null ? (Common.UIString('Key path: ') + keyPathString) : '';
1501 if (this._objectStore.autoIncrement)
1502 tooltipString += '\n' + Common.UIString('autoIncrement');
1503 this.tooltip = tooltipString;
1504 }
1505
1506 /**
1507 * @override
1508 * @return {boolean}
1509 */
1510 onselect(selectedByUser) {
1511 super.onselect(selectedByUser);
1512 if (!this._view)
1513 this._view = new Resources.IDBDataView(this._model, this._databaseId, this ._objectStore, null);
1514
1515 this.showView(this._view);
1516 return false;
1517 }
1518
1519 /**
1520 * @param {string} indexName
1521 */
1522 _indexRemoved(indexName) {
1523 var indexTreeElement = this._idbIndexTreeElements[indexName];
1524 indexTreeElement.clear();
1525 this.removeChild(indexTreeElement);
1526 delete this._idbIndexTreeElements[indexName];
1527 }
1528
1529 clear() {
1530 for (var indexName in this._idbIndexTreeElements)
1531 this._indexRemoved(indexName);
1532 if (this._view)
1533 this._view.clear();
1534 }
1535 };
1536
1537 /**
1538 * @unrestricted
1539 */
1540 Resources.IDBIndexTreeElement = class extends Resources.BaseStorageTreeElement {
1541 /**
1542 * @param {!Resources.ResourcesPanel} storagePanel
1543 * @param {!Resources.IndexedDBModel} model
1544 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId
1545 * @param {!Resources.IndexedDBModel.ObjectStore} objectStore
1546 * @param {!Resources.IndexedDBModel.Index} index
1547 */
1548 constructor(storagePanel, model, databaseId, objectStore, index) {
1549 super(storagePanel, index.name, false);
1550 this._model = model;
1551 this._databaseId = databaseId;
1552 this._objectStore = objectStore;
1553 this._index = index;
1554 }
1555
1556 get itemURL() {
1557 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name + '/' +
1558 this._objectStore.name + '/' + this._index.name;
1559 }
1560
1561 /**
1562 * @param {!Resources.IndexedDBModel.Index} index
1563 */
1564 update(index) {
1565 this._index = index;
1566
1567 if (this._view)
1568 this._view.update(this._index);
1569
1570 this._updateTooltip();
1571 }
1572
1573 _updateTooltip() {
1574 var tooltipLines = [];
1575 var keyPathString = this._index.keyPathString;
1576 tooltipLines.push(Common.UIString('Key path: ') + keyPathString);
1577 if (this._index.unique)
1578 tooltipLines.push(Common.UIString('unique'));
1579 if (this._index.multiEntry)
1580 tooltipLines.push(Common.UIString('multiEntry'));
1581 this.tooltip = tooltipLines.join('\n');
1582 }
1583
1584 /**
1585 * @override
1586 * @return {boolean}
1587 */
1588 onselect(selectedByUser) {
1589 super.onselect(selectedByUser);
1590 if (!this._view)
1591 this._view = new Resources.IDBDataView(this._model, this._databaseId, this ._objectStore, this._index);
1592
1593 this.showView(this._view);
1594 return false;
1595 }
1596
1597 clear() {
1598 if (this._view)
1599 this._view.clear();
1600 }
1601 };
1602
1603 /**
1604 * @unrestricted
1605 */
1606 Resources.DOMStorageTreeElement = class extends Resources.BaseStorageTreeElement {
1607 constructor(storagePanel, domStorage) {
1608 super(storagePanel, domStorage.securityOrigin ? domStorage.securityOrigin : Common.UIString('Local Files'), false);
1609 this._domStorage = domStorage;
1610 var icon = UI.Icon.create('mediumicon-table', 'resource-tree-item');
1611 this.setLeadingIcons([icon]);
1612 }
1613
1614 get itemURL() {
1615 return 'storage://' + this._domStorage.securityOrigin + '/' +
1616 (this._domStorage.isLocalStorage ? 'local' : 'session');
1617 }
1618
1619 /**
1620 * @override
1621 * @return {boolean}
1622 */
1623 onselect(selectedByUser) {
1624 super.onselect(selectedByUser);
1625 this._storagePanel._showDOMStorage(this._domStorage);
1626 return false;
1627 }
1628
1629 /**
1630 * @override
1631 */
1632 onattach() {
1633 super.onattach();
1634 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1635 }
1636
1637 _handleContextMenuEvent(event) {
1638 var contextMenu = new UI.ContextMenu(event);
1639 contextMenu.appendItem(Common.UIString('Clear'), () => this._domStorage.clea r());
1640 contextMenu.show();
1641 }
1642 };
1643
1644 Resources.CookieTreeElement = class extends Resources.BaseStorageTreeElement {
1645 /**
1646 * @param {!Resources.ResourcesPanel} storagePanel
1647 * @param {!SDK.ResourceTreeFrame} frame
1648 * @param {string} cookieDomain
1649 */
1650 constructor(storagePanel, frame, cookieDomain) {
1651 super(storagePanel, cookieDomain ? cookieDomain : Common.UIString('Local Fil es'), false);
1652 this._target = frame.target();
1653 this._cookieDomain = cookieDomain;
1654 var icon = UI.Icon.create('mediumicon-cookie', 'resource-tree-item');
1655 this.setLeadingIcons([icon]);
1656 }
1657
1658 get itemURL() {
1659 return 'cookies://' + this._cookieDomain;
1660 }
1661
1662 /**
1663 * @override
1664 */
1665 onattach() {
1666 super.onattach();
1667 this.listItemElement.addEventListener('contextmenu', this._handleContextMenu Event.bind(this), true);
1668 }
1669
1670 /**
1671 * @param {!Event} event
1672 */
1673 _handleContextMenuEvent(event) {
1674 var contextMenu = new UI.ContextMenu(event);
1675 contextMenu.appendItem(
1676 Common.UIString('Clear'), () => this._storagePanel._clearCookies(this._t arget, this._cookieDomain));
1677 contextMenu.show();
1678 }
1679
1680 /**
1681 * @override
1682 * @return {boolean}
1683 */
1684 onselect(selectedByUser) {
1685 super.onselect(selectedByUser);
1686 this._storagePanel.showCookies(this, this._cookieDomain, this._target);
1687 return false;
1688 }
1689 };
1690
1691 /**
1692 * @unrestricted
1693 */
1694 Resources.ApplicationCacheManifestTreeElement = class extends Resources.BaseStor ageTreeElement {
1695 constructor(storagePanel, manifestURL) {
1696 var title = new Common.ParsedURL(manifestURL).displayName;
1697 super(storagePanel, title, false);
1698 this.tooltip = manifestURL;
1699 this._manifestURL = manifestURL;
1700 }
1701
1702 get itemURL() {
1703 return 'appcache://' + this._manifestURL;
1704 }
1705
1706 get manifestURL() {
1707 return this._manifestURL;
1708 }
1709
1710 /**
1711 * @override
1712 * @return {boolean}
1713 */
1714 onselect(selectedByUser) {
1715 super.onselect(selectedByUser);
1716 this._storagePanel.showCategoryView(this._manifestURL);
1717 return false;
1718 }
1719 };
1720
1721 /**
1722 * @unrestricted
1723 */
1724 Resources.ApplicationCacheFrameTreeElement = class extends Resources.BaseStorage TreeElement {
1725 /**
1726 * @param {!Resources.ResourcesPanel} storagePanel
1727 * @param {!Protocol.Page.FrameId} frameId
1728 * @param {string} manifestURL
1729 */
1730 constructor(storagePanel, frameId, manifestURL) {
1731 super(storagePanel, '', false);
1732 this._frameId = frameId;
1733 this._manifestURL = manifestURL;
1734 this._refreshTitles();
1735
1736 var icon = UI.Icon.create('largeicon-navigator-folder', 'navigator-tree-item ');
1737 icon.classList.add('navigator-folder-tree-item');
1738 this.setLeadingIcons([icon]);
1739 }
1740
1741 get itemURL() {
1742 return 'appcache://' + this._manifestURL + '/' + encodeURI(this.titleAsText( ));
1743 }
1744
1745 get frameId() {
1746 return this._frameId;
1747 }
1748
1749 get manifestURL() {
1750 return this._manifestURL;
1751 }
1752
1753 _refreshTitles() {
1754 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(this._storagePanel. _target);
1755 var frame = resourceTreeModel.frameForId(this._frameId);
1756 this.title = frame.displayName();
1757 }
1758
1759 frameNavigated() {
1760 this._refreshTitles();
1761 }
1762
1763 /**
1764 * @override
1765 * @return {boolean}
1766 */
1767 onselect(selectedByUser) {
1768 super.onselect(selectedByUser);
1769 this._storagePanel.showApplicationCache(this._frameId);
1770 return false;
1771 }
1772 };
1773
1774 /**
1775 * @unrestricted
1776 */
1777 Resources.StorageCategoryView = class extends UI.VBox {
1778 constructor() {
1779 super();
1780
1781 this.element.classList.add('storage-view');
1782 this._emptyWidget = new UI.EmptyWidget('');
1783 this._emptyWidget.show(this.element);
1784 }
1785
1786 setText(text) {
1787 this._emptyWidget.text = text;
1788 }
1789 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698