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

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

Issue 1960663003: DevTools: introduce the Clear storage pane in the resources panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests fixed Created 4 years, 7 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
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @extends {WebInspector.VBox}
8 * @implements {WebInspector.TargetManager.Observer}
9 * @param {!WebInspector.ResourcesPanel} resourcesPanel
10 */
11 WebInspector.ClearStorageView = function(resourcesPanel)
12 {
13 WebInspector.VBox.call(this, true);
14
15 this._resourcesPanel = resourcesPanel;
16 this._reportView = new WebInspector.ReportView(WebInspector.UIString("Clear storage"));
17 this._reportView.registerRequiredCSS("resources/clearStorageView.css");
18 this._reportView.element.classList.add("clear-storage-header");
19 this._reportView.show(this.contentElement);
20
21 this._settings = new Map();
22 for (var type of [ StorageAgent.StorageType.Appcache,
23 StorageAgent.StorageType.Cache_storage,
24 StorageAgent.StorageType.Cookies,
25 StorageAgent.StorageType.Indexeddb,
26 StorageAgent.StorageType.Local_storage,
27 StorageAgent.StorageType.Service_workers,
28 StorageAgent.StorageType.Websql]) {
29 this._settings.set(type, WebInspector.settings.createSetting("clear-stor age-" + type, true));
30 }
31
32 var application = this._reportView.appendSection(WebInspector.UIString("Appl ication"));
33 this._appendItem(application, WebInspector.UIString("Unregister service work ers"), "service_workers");
34
35 var storage = this._reportView.appendSection(WebInspector.UIString("Storage" ));
36 this._appendItem(storage, WebInspector.UIString("Local and session storage") , "local_storage");
37 this._appendItem(storage, WebInspector.UIString("Indexed DB"), "indexeddb");
38 this._appendItem(storage, WebInspector.UIString("Web SQL"), "websql");
39 this._appendItem(storage, WebInspector.UIString("Cookies"), "cookies");
40
41 var caches = this._reportView.appendSection(WebInspector.UIString("Cache"));
42 this._appendItem(caches, WebInspector.UIString("Cache storage"), "cache_stor age");
43 this._appendItem(caches, WebInspector.UIString("Application cache"), "appcac he");
44
45 WebInspector.targetManager.observeTargets(this);
46 var footer = this._reportView.appendSection("", "clear-storage-button").appe ndRow();
47 this._clearButton = createTextButton(WebInspector.UIString("Clear selected") , this._clear.bind(this), WebInspector.UIString("Clear selected"));
48 footer.appendChild(this._clearButton);
49 }
50
51 WebInspector.ClearStorageView.prototype = {
52
53 /**
54 * @param {!WebInspector.ReportView.Section} section
55 * @param {string} title
56 * @param {string} settingName
57 */
58 _appendItem: function(section, title, settingName)
59 {
60 var row = section.appendRow();
61 row.appendChild(WebInspector.SettingsUI.createSettingCheckbox(title, thi s._settings.get(settingName), true));
62 },
63
64 /**
65 * @override
66 * @param {!WebInspector.Target} target
67 */
68 targetAdded: function(target)
69 {
70 if (this._target)
71 return;
72 this._target = target;
73 this._updateOrigin(target.resourceTreeModel.mainFrame ? target.resourceT reeModel.mainFrame.url : "");
74 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.MainFrameNavigated, this._updateFrame, this);
75 },
76
77 /**
78 * @param {!WebInspector.Event} event
79 */
80 _updateFrame: function(event)
81 {
82 var frame = /** *@type {!WebInspector.ResourceTreeFrame} */ (event.data) ;
83 this._updateOrigin(frame.url);
84 },
85
86 /**
87 * @param {string} url
88 */
89 _updateOrigin: function(url)
90 {
91 this._securityOrigin = new WebInspector.ParsedURL(url).securityOrigin();
92 this._reportView.setSubtitle(this._securityOrigin);
93 },
94
95 _clear: function()
96 {
97 var storageTypes = [];
98 for (var type of this._settings.keys()) {
99 if (this._settings.get(type).get())
100 storageTypes.push(type);
101 }
102
103 this._target.storageAgent().clearDataForOrigin(this._securityOrigin, sto rageTypes.join(","));
104
105 var set = new Set(storageTypes);
106 var hasAll = set.has(StorageAgent.StorageType.All);
107 if (set.has(StorageAgent.StorageType.Cookies) || hasAll)
108 this._resourcesPanel.clearCookies(this._securityOrigin);
109
110 if (set.has(StorageAgent.StorageType.Indexeddb) || hasAll) {
111 for (var target of WebInspector.targetManager.targets()) {
112 var indexedDBModel = WebInspector.IndexedDBModel.fromTarget(targ et);
113 if (indexedDBModel)
114 indexedDBModel.clearForOrigin(this._securityOrigin);
115 }
116 }
117
118 if (set.has(StorageAgent.StorageType.Local_storage) || hasAll) {
119 var storageModel = WebInspector.DOMStorageModel.fromTarget(this._tar get);
120 if (storageModel)
121 storageModel.clearForOrigin(this._securityOrigin);
122 }
123
124 if (set.has(StorageAgent.StorageType.Websql) || hasAll) {
125 var databaseModel = WebInspector.DatabaseModel.fromTarget(this._targ et);
126 if (databaseModel) {
127 databaseModel.disable();
128 databaseModel.enable();
129 }
130 }
131
132 if (set.has(StorageAgent.StorageType.Cache_storage) || hasAll) {
133 for (var target of WebInspector.targetManager.targets()) {
134 var model = WebInspector.ServiceWorkerCacheModel.fromTarget(targ et);
135 if (model)
136 model.clearForOrigin(this._securityOrigin);
137 }
138 }
139
140 if (set.has(StorageAgent.StorageType.Appcache) || hasAll) {
141 var appcacheModel = WebInspector.ApplicationCacheModel.fromTarget(th is._target);
142 if (appcacheModel)
143 appcacheModel.reset();
144 }
145
146 this._clearButton.disabled = true;
147 setTimeout(() => {
148 this._clearButton.disabled = false;
149 }, 500);
150 },
151
152 /**
153 * @override
154 * @param {!WebInspector.Target} target
155 */
156 targetRemoved: function(target)
157 {
158 },
159
160 __proto__: WebInspector.VBox.prototype
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698