| 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 | 4 |
| 5 /** | 5 /** |
| 6 * Invariant: This model can only be constructed on a ServiceWorker target. | 6 * Invariant: This model can only be constructed on a ServiceWorker target. |
| 7 * @constructor | 7 * @constructor |
| 8 * @extends {WebInspector.SDKModel} | 8 * @extends {WebInspector.SDKModel} |
| 9 * @param {!WebInspector.Target} target |
| 10 * @param {!WebInspector.SecurityOriginManager} securityOriginManager |
| 9 */ | 11 */ |
| 10 WebInspector.ServiceWorkerCacheModel = function(target) | 12 WebInspector.ServiceWorkerCacheModel = function(target, securityOriginManager) |
| 11 { | 13 { |
| 12 WebInspector.SDKModel.call(this, WebInspector.ServiceWorkerCacheModel, targe
t); | 14 WebInspector.SDKModel.call(this, WebInspector.ServiceWorkerCacheModel, targe
t); |
| 13 | 15 |
| 14 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ | 16 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ |
| 15 this._caches = new Map(); | 17 this._caches = new Map(); |
| 16 | 18 |
| 17 this._agent = target.cacheStorageAgent(); | 19 this._agent = target.cacheStorageAgent(); |
| 18 | 20 |
| 21 this._securityOriginManager = securityOriginManager; |
| 22 |
| 19 /** @type {boolean} */ | 23 /** @type {boolean} */ |
| 20 this._enabled = false; | 24 this._enabled = false; |
| 21 } | 25 } |
| 22 | 26 |
| 23 WebInspector.ServiceWorkerCacheModel.EventTypes = { | 27 WebInspector.ServiceWorkerCacheModel.EventTypes = { |
| 24 CacheAdded: "CacheAdded", | 28 CacheAdded: "CacheAdded", |
| 25 CacheRemoved: "CacheRemoved" | 29 CacheRemoved: "CacheRemoved" |
| 26 } | 30 } |
| 27 | 31 |
| 28 WebInspector.ServiceWorkerCacheModel.prototype = { | 32 WebInspector.ServiceWorkerCacheModel.prototype = { |
| 29 enable: function() | 33 enable: function() |
| 30 { | 34 { |
| 31 if (this._enabled) | 35 if (this._enabled) |
| 32 return; | 36 return; |
| 33 | 37 |
| 34 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr
eeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 38 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin
Manager.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); |
| 35 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr
eeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this); | 39 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin
Manager.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this); |
| 36 | 40 |
| 37 var securityOrigins = this.target().resourceTreeModel.securityOrigins(); | 41 for (var securityOrigin of this._securityOriginManager.securityOrigins()
) |
| 38 for (var i = 0; i < securityOrigins.length; ++i) | 42 this._addOrigin(securityOrigin); |
| 39 this._addOrigin(securityOrigins[i]); | |
| 40 this._enabled = true; | 43 this._enabled = true; |
| 41 }, | 44 }, |
| 42 | 45 |
| 43 /** | 46 /** |
| 44 * @param {string} origin | 47 * @param {string} origin |
| 45 */ | 48 */ |
| 46 clearForOrigin: function(origin) | 49 clearForOrigin: function(origin) |
| 47 { | 50 { |
| 48 this._removeOrigin(origin); | 51 this._removeOrigin(origin); |
| 49 this._addOrigin(origin); | 52 this._addOrigin(origin); |
| 50 }, | 53 }, |
| 51 | 54 |
| 52 refreshCacheNames: function() | 55 refreshCacheNames: function() |
| 53 { | 56 { |
| 54 for (var cache of this._caches.values()) | 57 for (var cache of this._caches.values()) |
| 55 this._cacheRemoved(cache); | 58 this._cacheRemoved(cache); |
| 56 this._caches.clear(); | 59 this._caches.clear(); |
| 57 var securityOrigins = this.target().resourceTreeModel.securityOrigins(); | 60 var securityOrigins = this._securityOriginManager.securityOrigins(); |
| 58 for (var securityOrigin of securityOrigins) | 61 for (var securityOrigin of securityOrigins) |
| 59 this._loadCacheNames(securityOrigin); | 62 this._loadCacheNames(securityOrigin); |
| 60 }, | 63 }, |
| 61 | 64 |
| 62 /** | 65 /** |
| 63 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | 66 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 64 */ | 67 */ |
| 65 deleteCache: function(cache) | 68 deleteCache: function(cache) |
| 66 { | 69 { |
| 67 /** | 70 /** |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 caches.push(cache); | 125 caches.push(cache); |
| 123 return caches; | 126 return caches; |
| 124 }, | 127 }, |
| 125 | 128 |
| 126 dispose: function() | 129 dispose: function() |
| 127 { | 130 { |
| 128 for (var cache of this._caches.values()) | 131 for (var cache of this._caches.values()) |
| 129 this._cacheRemoved(cache); | 132 this._cacheRemoved(cache); |
| 130 this._caches.clear(); | 133 this._caches.clear(); |
| 131 if (this._enabled) { | 134 if (this._enabled) { |
| 132 this.target().resourceTreeModel.removeEventListener(WebInspector.Res
ourceTreeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); | 135 this._securityOriginManager.removeEventListener(WebInspector.Securit
yOriginManager.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); |
| 133 this.target().resourceTreeModel.removeEventListener(WebInspector.Res
ourceTreeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, th
is); | 136 this._securityOriginManager.removeEventListener(WebInspector.Securit
yOriginManager.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, th
is); |
| 134 } | 137 } |
| 135 }, | 138 }, |
| 136 | 139 |
| 137 _addOrigin: function(securityOrigin) | 140 _addOrigin: function(securityOrigin) |
| 138 { | 141 { |
| 139 this._loadCacheNames(securityOrigin); | 142 this._loadCacheNames(securityOrigin); |
| 140 }, | 143 }, |
| 141 | 144 |
| 142 /** | 145 /** |
| 143 * @param {string} securityOrigin | 146 * @param {string} securityOrigin |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 /** | 317 /** |
| 315 * @override | 318 * @override |
| 316 * @return {string} | 319 * @return {string} |
| 317 */ | 320 */ |
| 318 toString: function() | 321 toString: function() |
| 319 { | 322 { |
| 320 return this.securityOrigin + this.cacheName; | 323 return this.securityOrigin + this.cacheName; |
| 321 } | 324 } |
| 322 } | 325 } |
| 323 | 326 |
| 324 | |
| 325 WebInspector.ServiceWorkerCacheModel._symbol = Symbol("CacheStorageModel"); | |
| 326 /** | 327 /** |
| 327 * @param {!WebInspector.Target} target | 328 * @param {!WebInspector.Target} target |
| 328 * @return {!WebInspector.ServiceWorkerCacheModel} | 329 * @return {?WebInspector.ServiceWorkerCacheModel} |
| 329 */ | 330 */ |
| 330 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target) | 331 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target) |
| 331 { | 332 { |
| 332 if (!target[WebInspector.ServiceWorkerCacheModel._symbol]) | 333 if (!target.hasBrowserCapability()) |
| 333 target[WebInspector.ServiceWorkerCacheModel._symbol] = new WebInspector.
ServiceWorkerCacheModel(target); | 334 return null; |
| 335 var instance = /** @type {?WebInspector.ServiceWorkerCacheModel} */ (target.
model(WebInspector.ServiceWorkerCacheModel)); |
| 336 if (!instance) |
| 337 instance = new WebInspector.ServiceWorkerCacheModel(target, WebInspector
.SecurityOriginManager.fromTarget(target)); |
| 338 return instance; |
| 339 } |
| 334 | 340 |
| 335 return target[WebInspector.ServiceWorkerCacheModel._symbol]; | |
| 336 } | |
| OLD | NEW |