Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 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 | * @implements {SDK.TargetManager.Observer} |
| 7 | */ |
| 8 | Resources.ClearStorageView = class extends UI.ThrottledWidget { |
| 9 | constructor() { |
| 10 | super(true, 1000); |
| 11 | const types = Protocol.Storage.StorageType; |
| 12 | this._pieColors = new Map([ |
| 13 | [types.Appcache, 'rgb(110, 161, 226)'], // blue |
| 14 | [types.Cache_storage, 'rgb(229, 113, 113)'], // red |
| 15 | [types.Cookies, 'rgb(239, 196, 87)'], // yellow |
| 16 | [types.Indexeddb, 'rgb(155, 127, 230)'], // purple |
| 17 | [types.Local_storage, 'rgb(116, 178, 102)'], // green |
| 18 | [types.Service_workers, 'rgb(255, 167, 36)'], // orange |
| 19 | [types.Websql, 'rgb(203, 220, 56)'], // lime |
| 20 | ]); |
| 21 | |
| 22 | this._reportView = new UI.ReportView(Common.UIString('Clear storage')); |
| 23 | this._reportView.registerRequiredCSS('resources/clearStorageView.css'); |
| 24 | this._reportView.element.classList.add('clear-storage-header'); |
| 25 | this._reportView.show(this.contentElement); |
| 26 | /** @type {?SDK.Target} */ |
| 27 | this._target = null; |
| 28 | /** @type {?string} */ |
| 29 | this._securityOrigin = null; |
| 30 | |
| 31 | this._settings = new Map(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 32 | for (const type of Resources.ClearStorageView.AllStorageTypes) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 33 | this._settings.set(type, Common.settings.createSetting('clear-storage-' + type, true)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 34 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 35 | |
| 36 | const quota = this._reportView.appendSection(Common.UIString('Usage')); |
Joey Arhar | 53f6345 | 2019-05-25 01:00:13 | [diff] [blame] | 37 | this._quotaRow = quota.appendSelectableRow(); |
Harley Li | 6b1c2da | 2018-11-29 23:19:30 | [diff] [blame] | 38 | const learnMoreRow = quota.appendRow(); |
| 39 | const learnMore = UI.XLink.create( |
| 40 | 'https://developers.google.com/web/tools/chrome-devtools/progressive-web-apps#opaque-responses', |
| 41 | ls`Learn more`); |
| 42 | learnMoreRow.appendChild(learnMore); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 43 | this._quotaUsage = null; |
Jeff Fisher | 76f4942 | 2019-05-21 22:42:01 | [diff] [blame] | 44 | this._pieChart = new PerfUI.PieChart( |
| 45 | {chartName: ls`Storage Usage`, size: 110, formatter: Number.bytesToString, showLegend: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 46 | const usageBreakdownRow = quota.appendRow(); |
| 47 | usageBreakdownRow.classList.add('usage-breakdown-row'); |
| 48 | usageBreakdownRow.appendChild(this._pieChart.element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 49 | |
Harley Li | 05120a9 | 2018-10-31 22:44:26 | [diff] [blame] | 50 | const clearButtonSection = this._reportView.appendSection('', 'clear-storage-button').appendRow(); |
| 51 | this._clearButton = UI.createTextButton(ls`Clear site data`, this._clear.bind(this)); |
| 52 | clearButtonSection.appendChild(this._clearButton); |
| 53 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | const application = this._reportView.appendSection(Common.UIString('Application')); |
| 55 | this._appendItem(application, Common.UIString('Unregister service workers'), 'service_workers'); |
Junyi Xiao | 3ddd8d1 | 2019-05-23 23:15:44 | [diff] [blame] | 56 | application.markFieldListAsGroup(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 57 | |
| 58 | const storage = this._reportView.appendSection(Common.UIString('Storage')); |
| 59 | this._appendItem(storage, Common.UIString('Local and session storage'), 'local_storage'); |
| 60 | this._appendItem(storage, Common.UIString('IndexedDB'), 'indexeddb'); |
| 61 | this._appendItem(storage, Common.UIString('Web SQL'), 'websql'); |
| 62 | this._appendItem(storage, Common.UIString('Cookies'), 'cookies'); |
Junyi Xiao | 3ddd8d1 | 2019-05-23 23:15:44 | [diff] [blame] | 63 | storage.markFieldListAsGroup(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 64 | |
| 65 | const caches = this._reportView.appendSection(Common.UIString('Cache')); |
| 66 | this._appendItem(caches, Common.UIString('Cache storage'), 'cache_storage'); |
| 67 | this._appendItem(caches, Common.UIString('Application cache'), 'appcache'); |
Junyi Xiao | 3ddd8d1 | 2019-05-23 23:15:44 | [diff] [blame] | 68 | caches.markFieldListAsGroup(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | |
Dmitry Gozman | 08dbcb6 | 2018-11-01 16:15:05 | [diff] [blame] | 70 | SDK.targetManager.observeTargets(this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @param {!UI.ReportView.Section} section |
| 75 | * @param {string} title |
| 76 | * @param {string} settingName |
| 77 | */ |
| 78 | _appendItem(section, title, settingName) { |
| 79 | const row = section.appendRow(); |
| 80 | row.appendChild(UI.SettingsUI.createSettingCheckbox(title, this._settings.get(settingName), true)); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @override |
| 85 | * @param {!SDK.Target} target |
| 86 | */ |
| 87 | targetAdded(target) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 88 | if (this._target) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 89 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 90 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 91 | this._target = target; |
| 92 | const securityOriginManager = target.model(SDK.SecurityOriginManager); |
Harley Li | ddf2b68 | 2019-03-08 22:35:23 | [diff] [blame] | 93 | this._updateOrigin( |
| 94 | securityOriginManager.mainSecurityOrigin(), securityOriginManager.unreachableMainSecurityOrigin()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 95 | securityOriginManager.addEventListener( |
| 96 | SDK.SecurityOriginManager.Events.MainSecurityOriginChanged, this._originChanged, this); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @override |
| 101 | * @param {!SDK.Target} target |
| 102 | */ |
| 103 | targetRemoved(target) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 104 | if (this._target !== target) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 105 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 106 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 107 | const securityOriginManager = target.model(SDK.SecurityOriginManager); |
| 108 | securityOriginManager.removeEventListener( |
| 109 | SDK.SecurityOriginManager.Events.MainSecurityOriginChanged, this._originChanged, this); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @param {!Common.Event} event |
| 114 | */ |
| 115 | _originChanged(event) { |
Harley Li | ddf2b68 | 2019-03-08 22:35:23 | [diff] [blame] | 116 | const mainOrigin = /** *@type {string} */ (event.data.mainSecurityOrigin); |
| 117 | const unreachableMainOrigin = /** @type {string} */ (event.data.unreachableMainSecurityOrigin); |
| 118 | this._updateOrigin(mainOrigin, unreachableMainOrigin); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Harley Li | ddf2b68 | 2019-03-08 22:35:23 | [diff] [blame] | 122 | * @param {string} mainOrigin |
| 123 | * @param {string} unreachableMainOrigin |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | */ |
Harley Li | ddf2b68 | 2019-03-08 22:35:23 | [diff] [blame] | 125 | _updateOrigin(mainOrigin, unreachableMainOrigin) { |
| 126 | if (unreachableMainOrigin) { |
| 127 | this._securityOrigin = unreachableMainOrigin; |
| 128 | this._reportView.setSubtitle(ls`${unreachableMainOrigin} (failed to load)`); |
Harley Li | 922a27b | 2019-02-01 20:38:39 | [diff] [blame] | 129 | } else { |
Harley Li | ddf2b68 | 2019-03-08 22:35:23 | [diff] [blame] | 130 | this._securityOrigin = mainOrigin; |
| 131 | this._reportView.setSubtitle(mainOrigin); |
Harley Li | 922a27b | 2019-02-01 20:38:39 | [diff] [blame] | 132 | } |
Harley Li | ddf2b68 | 2019-03-08 22:35:23 | [diff] [blame] | 133 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 134 | this.doUpdate(); |
| 135 | } |
| 136 | |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 137 | _clear() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 138 | if (!this._securityOrigin) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 139 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 140 | } |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 141 | const selectedStorageTypes = []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 142 | for (const type of this._settings.keys()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 143 | if (this._settings.get(type).get()) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 144 | selectedStorageTypes.push(type); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 145 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 146 | } |
| 147 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 148 | if (this._target) { |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 149 | Resources.ClearStorageView.clear(this._target, this._securityOrigin, selectedStorageTypes); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 150 | } |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 151 | |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 152 | this._clearButton.disabled = true; |
| 153 | const label = this._clearButton.textContent; |
| 154 | this._clearButton.textContent = Common.UIString('Clearing...'); |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 155 | setTimeout(() => { |
| 156 | this._clearButton.disabled = false; |
| 157 | this._clearButton.textContent = label; |
| 158 | }, 500); |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @param {!SDK.Target} target |
| 163 | * @param {string} securityOrigin |
| 164 | * @param {!Array<string>} selectedStorageTypes |
| 165 | */ |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 166 | static clear(target, securityOrigin, selectedStorageTypes) { |
| 167 | target.storageAgent().clearDataForOrigin(securityOrigin, selectedStorageTypes.join(',')); |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 168 | |
| 169 | const set = new Set(selectedStorageTypes); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 170 | const hasAll = set.has(Protocol.Storage.StorageType.All); |
| 171 | if (set.has(Protocol.Storage.StorageType.Cookies) || hasAll) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 172 | const cookieModel = target.model(SDK.CookieModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 173 | if (cookieModel) { |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 174 | cookieModel.clear(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 175 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if (set.has(Protocol.Storage.StorageType.Indexeddb) || hasAll) { |
| 179 | for (const target of SDK.targetManager.targets()) { |
| 180 | const indexedDBModel = target.model(Resources.IndexedDBModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 181 | if (indexedDBModel) { |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 182 | indexedDBModel.clearForOrigin(securityOrigin); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 183 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | if (set.has(Protocol.Storage.StorageType.Local_storage) || hasAll) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 188 | const storageModel = target.model(Resources.DOMStorageModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 189 | if (storageModel) { |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 190 | storageModel.clearForOrigin(securityOrigin); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 191 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | if (set.has(Protocol.Storage.StorageType.Websql) || hasAll) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 195 | const databaseModel = target.model(Resources.DatabaseModel); |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 196 | if (databaseModel) { |
| 197 | databaseModel.disable(); |
| 198 | databaseModel.enable(); |
| 199 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | if (set.has(Protocol.Storage.StorageType.Cache_storage) || hasAll) { |
| 203 | const target = SDK.targetManager.mainTarget(); |
| 204 | const model = target && target.model(SDK.ServiceWorkerCacheModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 205 | if (model) { |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 206 | model.clearForOrigin(securityOrigin); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 207 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (set.has(Protocol.Storage.StorageType.Appcache) || hasAll) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 211 | const appcacheModel = target.model(Resources.ApplicationCacheModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 212 | if (appcacheModel) { |
Sergey Poromov | 47ac039 | 2019-06-28 09:28:22 | [diff] [blame] | 213 | appcacheModel.reset(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 214 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 215 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /** |
| 219 | * @override |
| 220 | * @return {!Promise<?>} |
| 221 | */ |
| 222 | async doUpdate() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 223 | if (!this._securityOrigin) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 224 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 225 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 226 | |
| 227 | const securityOrigin = /** @type {string} */ (this._securityOrigin); |
| 228 | const response = await this._target.storageAgent().invoke_getUsageAndQuota({origin: securityOrigin}); |
| 229 | if (response[Protocol.Error]) { |
| 230 | this._quotaRow.textContent = ''; |
| 231 | this._resetPieChart(0); |
| 232 | return; |
| 233 | } |
| 234 | this._quotaRow.textContent = Common.UIString( |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 235 | '%s used out of %s storage quota.\xA0', Number.bytesToString(response.usage), |
Harley Li | d3a65ab | 2019-03-11 22:36:09 | [diff] [blame] | 236 | Number.bytesToString(response.quota)); |
| 237 | if (response.quota < 125829120) { // 120 MB |
| 238 | this._quotaRow.title = ls`Storage quota is limited in Incognito mode`; |
| 239 | this._quotaRow.appendChild(UI.Icon.create('smallicon-info')); |
| 240 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | |
| 242 | if (!this._quotaUsage || this._quotaUsage !== response.usage) { |
| 243 | this._quotaUsage = response.usage; |
| 244 | this._resetPieChart(response.usage); |
| 245 | for (const usageForType of response.usageBreakdown.sort((a, b) => b.usage - a.usage)) { |
| 246 | const value = usageForType.usage; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 247 | if (!value) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 249 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 250 | const title = this._getStorageTypeName(usageForType.storageType); |
| 251 | const color = this._pieColors.get(usageForType.storageType) || '#ccc'; |
Jeff Fisher | 76f4942 | 2019-05-21 22:42:01 | [diff] [blame] | 252 | this._pieChart.addSlice(value, color, title); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | this._usageUpdatedForTest(response.usage, response.quota, response.usageBreakdown); |
| 257 | this.update(); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * @param {number} total |
| 262 | */ |
| 263 | _resetPieChart(total) { |
| 264 | this._pieChart.setTotal(total); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * @param {string} type |
| 269 | * @return {string} |
| 270 | */ |
| 271 | _getStorageTypeName(type) { |
| 272 | switch (type) { |
| 273 | case Protocol.Storage.StorageType.File_systems: |
| 274 | return Common.UIString('File System'); |
| 275 | case Protocol.Storage.StorageType.Websql: |
| 276 | return Common.UIString('Web SQL'); |
| 277 | case Protocol.Storage.StorageType.Appcache: |
| 278 | return Common.UIString('Application Cache'); |
| 279 | case Protocol.Storage.StorageType.Indexeddb: |
| 280 | return Common.UIString('IndexedDB'); |
| 281 | case Protocol.Storage.StorageType.Cache_storage: |
| 282 | return Common.UIString('Cache Storage'); |
| 283 | case Protocol.Storage.StorageType.Service_workers: |
| 284 | return Common.UIString('Service Workers'); |
| 285 | default: |
| 286 | return Common.UIString('Other'); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * @param {number} usage |
| 292 | * @param {number} quota |
| 293 | * @param {!Array<!Protocol.Storage.UsageForType>} usageBreakdown |
| 294 | */ |
| 295 | _usageUpdatedForTest(usage, quota, usageBreakdown) { |
| 296 | } |
| 297 | }; |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 298 | |
| 299 | Resources.ClearStorageView.AllStorageTypes = [ |
| 300 | Protocol.Storage.StorageType.Appcache, Protocol.Storage.StorageType.Cache_storage, |
| 301 | Protocol.Storage.StorageType.Cookies, Protocol.Storage.StorageType.Indexeddb, |
| 302 | Protocol.Storage.StorageType.Local_storage, Protocol.Storage.StorageType.Service_workers, |
| 303 | Protocol.Storage.StorageType.Websql |
| 304 | ]; |
| 305 | |
| 306 | /** |
| 307 | * @implements {UI.ActionDelegate} |
| 308 | */ |
| 309 | Resources.ClearStorageView.ActionDelegate = class { |
| 310 | /** |
| 311 | * @override |
| 312 | * @param {!UI.Context} context |
| 313 | * @param {string} actionId |
| 314 | * @return {boolean} |
| 315 | */ |
| 316 | handleAction(context, actionId) { |
| 317 | switch (actionId) { |
| 318 | case 'resources.clear': |
| 319 | return this._handleClear(); |
| 320 | } |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * @return {boolean} |
| 326 | */ |
| 327 | _handleClear() { |
| 328 | const target = SDK.targetManager.mainTarget(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 329 | if (!target) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 330 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 331 | } |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 332 | const resourceTreeModel = target.model(SDK.ResourceTreeModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 333 | if (!resourceTreeModel) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 334 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 335 | } |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 336 | const securityOrigin = resourceTreeModel.getMainSecurityOrigin(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 337 | if (!securityOrigin) { |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 338 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 339 | } |
Harley Li | 2903887 | 2019-03-27 20:50:04 | [diff] [blame] | 340 | |
| 341 | Resources.ClearStorageView.clear(target, securityOrigin, Resources.ClearStorageView.AllStorageTypes); |
| 342 | return true; |
| 343 | } |
| 344 | }; |