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