| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Invariant: This model can only be constructed on a ServiceWorker target. | 5 * @unrestricted |
| 7 * @constructor | |
| 8 * @extends {WebInspector.SDKModel} | |
| 9 * @param {!WebInspector.Target} target | |
| 10 * @param {!WebInspector.SecurityOriginManager} securityOriginManager | |
| 11 */ | 6 */ |
| 12 WebInspector.ServiceWorkerCacheModel = function(target, securityOriginManager) | 7 WebInspector.ServiceWorkerCacheModel = class extends WebInspector.SDKModel { |
| 13 { | 8 /** |
| 14 WebInspector.SDKModel.call(this, WebInspector.ServiceWorkerCacheModel, targe
t); | 9 * Invariant: This model can only be constructed on a ServiceWorker target. |
| 10 * @param {!WebInspector.Target} target |
| 11 * @param {!WebInspector.SecurityOriginManager} securityOriginManager |
| 12 */ |
| 13 constructor(target, securityOriginManager) { |
| 14 super(WebInspector.ServiceWorkerCacheModel, target); |
| 15 | 15 |
| 16 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ | 16 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ |
| 17 this._caches = new Map(); | 17 this._caches = new Map(); |
| 18 | 18 |
| 19 this._agent = target.cacheStorageAgent(); | 19 this._agent = target.cacheStorageAgent(); |
| 20 | 20 |
| 21 this._securityOriginManager = securityOriginManager; | 21 this._securityOriginManager = securityOriginManager; |
| 22 | 22 |
| 23 /** @type {boolean} */ | 23 /** @type {boolean} */ |
| 24 this._enabled = false; | 24 this._enabled = false; |
| 25 } |
| 26 |
| 27 /** |
| 28 * @param {!WebInspector.Target} target |
| 29 * @return {?WebInspector.ServiceWorkerCacheModel} |
| 30 */ |
| 31 static fromTarget(target) { |
| 32 if (!target.hasBrowserCapability()) |
| 33 return null; |
| 34 var instance = |
| 35 /** @type {?WebInspector.ServiceWorkerCacheModel} */ (target.model(WebIn
spector.ServiceWorkerCacheModel)); |
| 36 if (!instance) |
| 37 instance = |
| 38 new WebInspector.ServiceWorkerCacheModel(target, WebInspector.Security
OriginManager.fromTarget(target)); |
| 39 return instance; |
| 40 } |
| 41 |
| 42 enable() { |
| 43 if (this._enabled) |
| 44 return; |
| 45 |
| 46 this._securityOriginManager.addEventListener( |
| 47 WebInspector.SecurityOriginManager.Events.SecurityOriginAdded, this._sec
urityOriginAdded, this); |
| 48 this._securityOriginManager.addEventListener( |
| 49 WebInspector.SecurityOriginManager.Events.SecurityOriginRemoved, this._s
ecurityOriginRemoved, this); |
| 50 |
| 51 for (var securityOrigin of this._securityOriginManager.securityOrigins()) |
| 52 this._addOrigin(securityOrigin); |
| 53 this._enabled = true; |
| 54 } |
| 55 |
| 56 /** |
| 57 * @param {string} origin |
| 58 */ |
| 59 clearForOrigin(origin) { |
| 60 this._removeOrigin(origin); |
| 61 this._addOrigin(origin); |
| 62 } |
| 63 |
| 64 refreshCacheNames() { |
| 65 for (var cache of this._caches.values()) |
| 66 this._cacheRemoved(cache); |
| 67 this._caches.clear(); |
| 68 var securityOrigins = this._securityOriginManager.securityOrigins(); |
| 69 for (var securityOrigin of securityOrigins) |
| 70 this._loadCacheNames(securityOrigin); |
| 71 } |
| 72 |
| 73 /** |
| 74 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 75 */ |
| 76 deleteCache(cache) { |
| 77 /** |
| 78 * @this {WebInspector.ServiceWorkerCacheModel} |
| 79 */ |
| 80 function callback(error) { |
| 81 if (error) { |
| 82 console.error('ServiceWorkerCacheAgent error deleting cache ', cache.toS
tring(), ': ', error); |
| 83 return; |
| 84 } |
| 85 this._caches.delete(cache.cacheId); |
| 86 this._cacheRemoved(cache); |
| 87 } |
| 88 this._agent.deleteCache(cache.cacheId, callback.bind(this)); |
| 89 } |
| 90 |
| 91 /** |
| 92 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 93 * @param {string} request |
| 94 * @param {function()} callback |
| 95 */ |
| 96 deleteCacheEntry(cache, request, callback) { |
| 97 /** |
| 98 * @param {?Protocol.Error} error |
| 99 */ |
| 100 function myCallback(error) { |
| 101 if (error) { |
| 102 WebInspector.console.error(WebInspector.UIString( |
| 103 'ServiceWorkerCacheAgent error deleting cache entry %s in cache: %s'
, cache.toString(), error)); |
| 104 return; |
| 105 } |
| 106 callback(); |
| 107 } |
| 108 this._agent.deleteEntry(cache.cacheId, request, myCallback); |
| 109 } |
| 110 |
| 111 /** |
| 112 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 113 * @param {number} skipCount |
| 114 * @param {number} pageSize |
| 115 * @param {function(!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>, bool
ean)} callback |
| 116 */ |
| 117 loadCacheData(cache, skipCount, pageSize, callback) { |
| 118 this._requestEntries(cache, skipCount, pageSize, callback); |
| 119 } |
| 120 |
| 121 /** |
| 122 * @return {!Array.<!WebInspector.ServiceWorkerCacheModel.Cache>} |
| 123 */ |
| 124 caches() { |
| 125 var caches = new Array(); |
| 126 for (var cache of this._caches.values()) |
| 127 caches.push(cache); |
| 128 return caches; |
| 129 } |
| 130 |
| 131 /** |
| 132 * @override |
| 133 */ |
| 134 dispose() { |
| 135 for (var cache of this._caches.values()) |
| 136 this._cacheRemoved(cache); |
| 137 this._caches.clear(); |
| 138 if (this._enabled) { |
| 139 this._securityOriginManager.removeEventListener( |
| 140 WebInspector.SecurityOriginManager.Events.SecurityOriginAdded, this._s
ecurityOriginAdded, this); |
| 141 this._securityOriginManager.removeEventListener( |
| 142 WebInspector.SecurityOriginManager.Events.SecurityOriginRemoved, this.
_securityOriginRemoved, this); |
| 143 } |
| 144 } |
| 145 |
| 146 _addOrigin(securityOrigin) { |
| 147 this._loadCacheNames(securityOrigin); |
| 148 } |
| 149 |
| 150 /** |
| 151 * @param {string} securityOrigin |
| 152 */ |
| 153 _removeOrigin(securityOrigin) { |
| 154 for (var opaqueId of this._caches.keys()) { |
| 155 var cache = this._caches.get(opaqueId); |
| 156 if (cache.securityOrigin === securityOrigin) { |
| 157 this._caches.delete(opaqueId); |
| 158 this._cacheRemoved(cache); |
| 159 } |
| 160 } |
| 161 } |
| 162 |
| 163 /** |
| 164 * @param {string} securityOrigin |
| 165 */ |
| 166 _loadCacheNames(securityOrigin) { |
| 167 /** |
| 168 * @param {?Protocol.Error} error |
| 169 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Cache>} caches |
| 170 * @this {WebInspector.ServiceWorkerCacheModel} |
| 171 */ |
| 172 function callback(error, caches) { |
| 173 if (error) { |
| 174 console.error('ServiceWorkerCacheAgent error while loading caches: ', er
ror); |
| 175 return; |
| 176 } |
| 177 this._updateCacheNames(securityOrigin, caches); |
| 178 } |
| 179 this._agent.requestCacheNames(securityOrigin, callback.bind(this)); |
| 180 } |
| 181 |
| 182 /** |
| 183 * @param {string} securityOrigin |
| 184 * @param {!Array} cachesJson |
| 185 */ |
| 186 _updateCacheNames(securityOrigin, cachesJson) { |
| 187 /** |
| 188 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 189 * @this {WebInspector.ServiceWorkerCacheModel} |
| 190 */ |
| 191 function deleteAndSaveOldCaches(cache) { |
| 192 if (cache.securityOrigin === securityOrigin && !updatingCachesIds.has(cach
e.cacheId)) { |
| 193 oldCaches.set(cache.cacheId, cache); |
| 194 this._caches.delete(cache.cacheId); |
| 195 } |
| 196 } |
| 197 |
| 198 /** @type {!Set<string>} */ |
| 199 var updatingCachesIds = new Set(); |
| 200 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ |
| 201 var newCaches = new Map(); |
| 202 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ |
| 203 var oldCaches = new Map(); |
| 204 |
| 205 for (var cacheJson of cachesJson) { |
| 206 var cache = new WebInspector.ServiceWorkerCacheModel.Cache( |
| 207 cacheJson.securityOrigin, cacheJson.cacheName, cacheJson.cacheId); |
| 208 updatingCachesIds.add(cache.cacheId); |
| 209 if (this._caches.has(cache.cacheId)) |
| 210 continue; |
| 211 newCaches.set(cache.cacheId, cache); |
| 212 this._caches.set(cache.cacheId, cache); |
| 213 } |
| 214 this._caches.forEach(deleteAndSaveOldCaches, this); |
| 215 newCaches.forEach(this._cacheAdded, this); |
| 216 oldCaches.forEach(this._cacheRemoved, this); |
| 217 } |
| 218 |
| 219 /** |
| 220 * @param {!WebInspector.Event} event |
| 221 */ |
| 222 _securityOriginAdded(event) { |
| 223 var securityOrigin = /** @type {string} */ (event.data); |
| 224 this._addOrigin(securityOrigin); |
| 225 } |
| 226 |
| 227 /** |
| 228 * @param {!WebInspector.Event} event |
| 229 */ |
| 230 _securityOriginRemoved(event) { |
| 231 var securityOrigin = /** @type {string} */ (event.data); |
| 232 this._removeOrigin(securityOrigin); |
| 233 } |
| 234 |
| 235 /** |
| 236 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 237 */ |
| 238 _cacheAdded(cache) { |
| 239 this.dispatchEventToListeners(WebInspector.ServiceWorkerCacheModel.Events.Ca
cheAdded, cache); |
| 240 } |
| 241 |
| 242 /** |
| 243 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 244 */ |
| 245 _cacheRemoved(cache) { |
| 246 this.dispatchEventToListeners(WebInspector.ServiceWorkerCacheModel.Events.Ca
cheRemoved, cache); |
| 247 } |
| 248 |
| 249 /** |
| 250 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 251 * @param {number} skipCount |
| 252 * @param {number} pageSize |
| 253 * @param {function(!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>, bool
ean)} callback |
| 254 */ |
| 255 _requestEntries(cache, skipCount, pageSize, callback) { |
| 256 /** |
| 257 * @param {?Protocol.Error} error |
| 258 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} dataEntries |
| 259 * @param {boolean} hasMore |
| 260 */ |
| 261 function innerCallback(error, dataEntries, hasMore) { |
| 262 if (error) { |
| 263 console.error('ServiceWorkerCacheAgent error while requesting entries: '
, error); |
| 264 return; |
| 265 } |
| 266 var entries = []; |
| 267 for (var i = 0; i < dataEntries.length; ++i) { |
| 268 entries.push(new WebInspector.ServiceWorkerCacheModel.Entry(dataEntries[
i].request, dataEntries[i].response)); |
| 269 } |
| 270 callback(entries, hasMore); |
| 271 } |
| 272 this._agent.requestEntries(cache.cacheId, skipCount, pageSize, innerCallback
); |
| 273 } |
| 25 }; | 274 }; |
| 26 | 275 |
| 27 /** @enum {symbol} */ | 276 /** @enum {symbol} */ |
| 28 WebInspector.ServiceWorkerCacheModel.Events = { | 277 WebInspector.ServiceWorkerCacheModel.Events = { |
| 29 CacheAdded: Symbol("CacheAdded"), | 278 CacheAdded: Symbol('CacheAdded'), |
| 30 CacheRemoved: Symbol("CacheRemoved") | 279 CacheRemoved: Symbol('CacheRemoved') |
| 31 }; | 280 }; |
| 32 | 281 |
| 33 WebInspector.ServiceWorkerCacheModel.prototype = { | |
| 34 enable: function() | |
| 35 { | |
| 36 if (this._enabled) | |
| 37 return; | |
| 38 | |
| 39 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin
Manager.Events.SecurityOriginAdded, this._securityOriginAdded, this); | |
| 40 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin
Manager.Events.SecurityOriginRemoved, this._securityOriginRemoved, this); | |
| 41 | |
| 42 for (var securityOrigin of this._securityOriginManager.securityOrigins()
) | |
| 43 this._addOrigin(securityOrigin); | |
| 44 this._enabled = true; | |
| 45 }, | |
| 46 | |
| 47 /** | |
| 48 * @param {string} origin | |
| 49 */ | |
| 50 clearForOrigin: function(origin) | |
| 51 { | |
| 52 this._removeOrigin(origin); | |
| 53 this._addOrigin(origin); | |
| 54 }, | |
| 55 | |
| 56 refreshCacheNames: function() | |
| 57 { | |
| 58 for (var cache of this._caches.values()) | |
| 59 this._cacheRemoved(cache); | |
| 60 this._caches.clear(); | |
| 61 var securityOrigins = this._securityOriginManager.securityOrigins(); | |
| 62 for (var securityOrigin of securityOrigins) | |
| 63 this._loadCacheNames(securityOrigin); | |
| 64 }, | |
| 65 | |
| 66 /** | |
| 67 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 68 */ | |
| 69 deleteCache: function(cache) | |
| 70 { | |
| 71 /** | |
| 72 * @this {WebInspector.ServiceWorkerCacheModel} | |
| 73 */ | |
| 74 function callback(error) | |
| 75 { | |
| 76 if (error) { | |
| 77 console.error("ServiceWorkerCacheAgent error deleting cache ", c
ache.toString(), ": ", error); | |
| 78 return; | |
| 79 } | |
| 80 this._caches.delete(cache.cacheId); | |
| 81 this._cacheRemoved(cache); | |
| 82 } | |
| 83 this._agent.deleteCache(cache.cacheId, callback.bind(this)); | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 88 * @param {string} request | |
| 89 * @param {function()} callback | |
| 90 */ | |
| 91 deleteCacheEntry: function(cache, request, callback) | |
| 92 { | |
| 93 | |
| 94 /** | |
| 95 * @param {?Protocol.Error} error | |
| 96 */ | |
| 97 function myCallback(error) | |
| 98 { | |
| 99 if (error) { | |
| 100 WebInspector.console.error(WebInspector.UIString("ServiceWorkerC
acheAgent error deleting cache entry %s in cache: %s", cache.toString(), error))
; | |
| 101 return; | |
| 102 } | |
| 103 callback(); | |
| 104 } | |
| 105 this._agent.deleteEntry(cache.cacheId, request, myCallback); | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 110 * @param {number} skipCount | |
| 111 * @param {number} pageSize | |
| 112 * @param {function(!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>, bo
olean)} callback | |
| 113 */ | |
| 114 loadCacheData: function(cache, skipCount, pageSize, callback) | |
| 115 { | |
| 116 this._requestEntries(cache, skipCount, pageSize, callback); | |
| 117 }, | |
| 118 | |
| 119 /** | |
| 120 * @return {!Array.<!WebInspector.ServiceWorkerCacheModel.Cache>} | |
| 121 */ | |
| 122 caches: function() | |
| 123 { | |
| 124 var caches = new Array(); | |
| 125 for (var cache of this._caches.values()) | |
| 126 caches.push(cache); | |
| 127 return caches; | |
| 128 }, | |
| 129 | |
| 130 dispose: function() | |
| 131 { | |
| 132 for (var cache of this._caches.values()) | |
| 133 this._cacheRemoved(cache); | |
| 134 this._caches.clear(); | |
| 135 if (this._enabled) { | |
| 136 this._securityOriginManager.removeEventListener(WebInspector.Securit
yOriginManager.Events.SecurityOriginAdded, this._securityOriginAdded, this); | |
| 137 this._securityOriginManager.removeEventListener(WebInspector.Securit
yOriginManager.Events.SecurityOriginRemoved, this._securityOriginRemoved, this); | |
| 138 } | |
| 139 }, | |
| 140 | |
| 141 _addOrigin: function(securityOrigin) | |
| 142 { | |
| 143 this._loadCacheNames(securityOrigin); | |
| 144 }, | |
| 145 | |
| 146 /** | |
| 147 * @param {string} securityOrigin | |
| 148 */ | |
| 149 _removeOrigin: function(securityOrigin) | |
| 150 { | |
| 151 for (var opaqueId of this._caches.keys()) { | |
| 152 var cache = this._caches.get(opaqueId); | |
| 153 if (cache.securityOrigin === securityOrigin) { | |
| 154 this._caches.delete(opaqueId); | |
| 155 this._cacheRemoved(cache); | |
| 156 } | |
| 157 } | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * @param {string} securityOrigin | |
| 162 */ | |
| 163 _loadCacheNames: function(securityOrigin) | |
| 164 { | |
| 165 /** | |
| 166 * @param {?Protocol.Error} error | |
| 167 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Cache>} caches | |
| 168 * @this {WebInspector.ServiceWorkerCacheModel} | |
| 169 */ | |
| 170 function callback(error, caches) | |
| 171 { | |
| 172 if (error) { | |
| 173 console.error("ServiceWorkerCacheAgent error while loading cache
s: ", error); | |
| 174 return; | |
| 175 } | |
| 176 this._updateCacheNames(securityOrigin, caches); | |
| 177 } | |
| 178 this._agent.requestCacheNames(securityOrigin, callback.bind(this)); | |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * @param {string} securityOrigin | |
| 183 * @param {!Array} cachesJson | |
| 184 */ | |
| 185 _updateCacheNames: function(securityOrigin, cachesJson) | |
| 186 { | |
| 187 /** | |
| 188 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 189 * @this {WebInspector.ServiceWorkerCacheModel} | |
| 190 */ | |
| 191 function deleteAndSaveOldCaches(cache) | |
| 192 { | |
| 193 if (cache.securityOrigin === securityOrigin && !updatingCachesIds.ha
s(cache.cacheId)) { | |
| 194 oldCaches.set(cache.cacheId, cache); | |
| 195 this._caches.delete(cache.cacheId); | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 /** @type {!Set<string>} */ | |
| 200 var updatingCachesIds = new Set(); | |
| 201 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ | |
| 202 var newCaches = new Map(); | |
| 203 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ | |
| 204 var oldCaches = new Map(); | |
| 205 | |
| 206 for (var cacheJson of cachesJson) { | |
| 207 var cache = new WebInspector.ServiceWorkerCacheModel.Cache(cacheJson
.securityOrigin, cacheJson.cacheName, cacheJson.cacheId); | |
| 208 updatingCachesIds.add(cache.cacheId); | |
| 209 if (this._caches.has(cache.cacheId)) | |
| 210 continue; | |
| 211 newCaches.set(cache.cacheId, cache); | |
| 212 this._caches.set(cache.cacheId, cache); | |
| 213 } | |
| 214 this._caches.forEach(deleteAndSaveOldCaches, this); | |
| 215 newCaches.forEach(this._cacheAdded, this); | |
| 216 oldCaches.forEach(this._cacheRemoved, this); | |
| 217 }, | |
| 218 | |
| 219 /** | |
| 220 * @param {!WebInspector.Event} event | |
| 221 */ | |
| 222 _securityOriginAdded: function(event) | |
| 223 { | |
| 224 var securityOrigin = /** @type {string} */ (event.data); | |
| 225 this._addOrigin(securityOrigin); | |
| 226 }, | |
| 227 | |
| 228 /** | |
| 229 * @param {!WebInspector.Event} event | |
| 230 */ | |
| 231 _securityOriginRemoved: function(event) | |
| 232 { | |
| 233 var securityOrigin = /** @type {string} */ (event.data); | |
| 234 this._removeOrigin(securityOrigin); | |
| 235 }, | |
| 236 | |
| 237 /** | |
| 238 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 239 */ | |
| 240 _cacheAdded: function(cache) | |
| 241 { | |
| 242 this.dispatchEventToListeners(WebInspector.ServiceWorkerCacheModel.Event
s.CacheAdded, cache); | |
| 243 }, | |
| 244 | |
| 245 /** | |
| 246 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 247 */ | |
| 248 _cacheRemoved: function(cache) | |
| 249 { | |
| 250 this.dispatchEventToListeners(WebInspector.ServiceWorkerCacheModel.Event
s.CacheRemoved, cache); | |
| 251 }, | |
| 252 | |
| 253 /** | |
| 254 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 255 * @param {number} skipCount | |
| 256 * @param {number} pageSize | |
| 257 * @param {function(!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>, bo
olean)} callback | |
| 258 */ | |
| 259 _requestEntries: function(cache, skipCount, pageSize, callback) | |
| 260 { | |
| 261 /** | |
| 262 * @param {?Protocol.Error} error | |
| 263 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} dataEnt
ries | |
| 264 * @param {boolean} hasMore | |
| 265 */ | |
| 266 function innerCallback(error, dataEntries, hasMore) | |
| 267 { | |
| 268 if (error) { | |
| 269 console.error("ServiceWorkerCacheAgent error while requesting en
tries: ", error); | |
| 270 return; | |
| 271 } | |
| 272 var entries = []; | |
| 273 for (var i = 0; i < dataEntries.length; ++i) { | |
| 274 entries.push(new WebInspector.ServiceWorkerCacheModel.Entry(data
Entries[i].request, dataEntries[i].response)); | |
| 275 } | |
| 276 callback(entries, hasMore); | |
| 277 } | |
| 278 this._agent.requestEntries(cache.cacheId, skipCount, pageSize, innerCall
back); | |
| 279 }, | |
| 280 | |
| 281 __proto__: WebInspector.SDKModel.prototype | |
| 282 }; | |
| 283 | |
| 284 /** | 282 /** |
| 285 * @constructor | 283 * @unrestricted |
| 286 * @param {string} request | |
| 287 * @param {string} response | |
| 288 */ | 284 */ |
| 289 WebInspector.ServiceWorkerCacheModel.Entry = function(request, response) | 285 WebInspector.ServiceWorkerCacheModel.Entry = class { |
| 290 { | 286 /** |
| 287 * @param {string} request |
| 288 * @param {string} response |
| 289 */ |
| 290 constructor(request, response) { |
| 291 this.request = request; | 291 this.request = request; |
| 292 this.response = response; | 292 this.response = response; |
| 293 } |
| 293 }; | 294 }; |
| 294 | 295 |
| 295 /** | 296 /** |
| 296 * @constructor | 297 * @unrestricted |
| 297 * @param {string} securityOrigin | |
| 298 * @param {string} cacheName | |
| 299 * @param {string} cacheId | |
| 300 */ | 298 */ |
| 301 WebInspector.ServiceWorkerCacheModel.Cache = function(securityOrigin, cacheName,
cacheId) | 299 WebInspector.ServiceWorkerCacheModel.Cache = class { |
| 302 { | 300 /** |
| 301 * @param {string} securityOrigin |
| 302 * @param {string} cacheName |
| 303 * @param {string} cacheId |
| 304 */ |
| 305 constructor(securityOrigin, cacheName, cacheId) { |
| 303 this.securityOrigin = securityOrigin; | 306 this.securityOrigin = securityOrigin; |
| 304 this.cacheName = cacheName; | 307 this.cacheName = cacheName; |
| 305 this.cacheId = cacheId; | 308 this.cacheId = cacheId; |
| 309 } |
| 310 |
| 311 /** |
| 312 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 313 * @return {boolean} |
| 314 */ |
| 315 equals(cache) { |
| 316 return this.cacheId === cache.cacheId; |
| 317 } |
| 318 |
| 319 /** |
| 320 * @override |
| 321 * @return {string} |
| 322 */ |
| 323 toString() { |
| 324 return this.securityOrigin + this.cacheName; |
| 325 } |
| 306 }; | 326 }; |
| 307 | 327 |
| 308 WebInspector.ServiceWorkerCacheModel.Cache.prototype = { | 328 |
| 309 /** | |
| 310 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
| 311 * @return {boolean} | |
| 312 */ | |
| 313 equals: function(cache) | |
| 314 { | |
| 315 return this.cacheId === cache.cacheId; | |
| 316 }, | |
| 317 | |
| 318 /** | |
| 319 * @override | |
| 320 * @return {string} | |
| 321 */ | |
| 322 toString: function() | |
| 323 { | |
| 324 return this.securityOrigin + this.cacheName; | |
| 325 } | |
| 326 }; | |
| 327 | |
| 328 /** | |
| 329 * @param {!WebInspector.Target} target | |
| 330 * @return {?WebInspector.ServiceWorkerCacheModel} | |
| 331 */ | |
| 332 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target) | |
| 333 { | |
| 334 if (!target.hasBrowserCapability()) | |
| 335 return null; | |
| 336 var instance = /** @type {?WebInspector.ServiceWorkerCacheModel} */ (target.
model(WebInspector.ServiceWorkerCacheModel)); | |
| 337 if (!instance) | |
| 338 instance = new WebInspector.ServiceWorkerCacheModel(target, WebInspector
.SecurityOriginManager.fromTarget(target)); | |
| 339 return instance; | |
| 340 }; | |
| 341 | |
| OLD | NEW |