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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerCacheModel.js

Issue 2122353002: [DevTools] Make resource tree model optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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
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 */ 9 */
10 WebInspector.ServiceWorkerCacheModel = function(target) 10 WebInspector.ServiceWorkerCacheModel = function(target)
(...skipping 13 matching lines...) Expand all
24 CacheAdded: "CacheAdded", 24 CacheAdded: "CacheAdded",
25 CacheRemoved: "CacheRemoved" 25 CacheRemoved: "CacheRemoved"
26 } 26 }
27 27
28 WebInspector.ServiceWorkerCacheModel.prototype = { 28 WebInspector.ServiceWorkerCacheModel.prototype = {
29 enable: function() 29 enable: function()
30 { 30 {
31 if (this._enabled) 31 if (this._enabled)
32 return; 32 return;
33 33
34 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr eeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 34 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this.t arget());
35 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr eeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this); 35 if (resourceTreeModel) {
dgozman 2016/07/14 16:29:29 Require it.
eostroukhov-old 2016/07/20 23:46:16 Done.
36 36 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Ev entTypes.SecurityOriginAdded, this._securityOriginAdded, this);
37 var securityOrigins = this.target().resourceTreeModel.securityOrigins(); 37 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Ev entTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
38 for (var i = 0; i < securityOrigins.length; ++i) 38 var securityOrigins = resourceTreeModel.securityOrigins();
39 this._addOrigin(securityOrigins[i]); 39 for (var i = 0; i < securityOrigins.length; ++i)
40 this._addOrigin(securityOrigins[i]);
41 }
40 this._enabled = true; 42 this._enabled = true;
41 }, 43 },
42 44
43 /** 45 /**
44 * @param {string} origin 46 * @param {string} origin
45 */ 47 */
46 clearForOrigin: function(origin) 48 clearForOrigin: function(origin)
47 { 49 {
48 this._removeOrigin(origin); 50 this._removeOrigin(origin);
49 this._addOrigin(origin); 51 this._addOrigin(origin);
50 }, 52 },
51 53
52 refreshCacheNames: function() 54 refreshCacheNames: function()
53 { 55 {
54 for (var cache of this._caches.values()) 56 for (var cache of this._caches.values())
55 this._cacheRemoved(cache); 57 this._cacheRemoved(cache);
56 this._caches.clear(); 58 this._caches.clear();
57 var securityOrigins = this.target().resourceTreeModel.securityOrigins(); 59 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this.t arget());
60 var securityOrigins = resourceTreeModel ? resourceTreeModel.securityOrig ins() : [];
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 for (var cache of this._caches.values()) 124 for (var cache of this._caches.values())
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 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this.t arget());
132 this.target().resourceTreeModel.removeEventListener(WebInspector.Res ourceTreeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 135 if (this._enabled && resourceTreeModel) {
133 this.target().resourceTreeModel.removeEventListener(WebInspector.Res ourceTreeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, th is); 136 resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel .EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
137 resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel .EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
134 } 138 }
135 }, 139 },
136 140
137 _addOrigin: function(securityOrigin) 141 _addOrigin: function(securityOrigin)
138 { 142 {
139 this._loadCacheNames(securityOrigin); 143 this._loadCacheNames(securityOrigin);
140 }, 144 },
141 145
142 /** 146 /**
143 * @param {string} securityOrigin 147 * @param {string} securityOrigin
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 * @param {!WebInspector.Target} target 331 * @param {!WebInspector.Target} target
328 * @return {!WebInspector.ServiceWorkerCacheModel} 332 * @return {!WebInspector.ServiceWorkerCacheModel}
329 */ 333 */
330 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target) 334 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target)
331 { 335 {
332 if (!target[WebInspector.ServiceWorkerCacheModel._symbol]) 336 if (!target[WebInspector.ServiceWorkerCacheModel._symbol])
333 target[WebInspector.ServiceWorkerCacheModel._symbol] = new WebInspector. ServiceWorkerCacheModel(target); 337 target[WebInspector.ServiceWorkerCacheModel._symbol] = new WebInspector. ServiceWorkerCacheModel(target);
334 338
335 return target[WebInspector.ServiceWorkerCacheModel._symbol]; 339 return target[WebInspector.ServiceWorkerCacheModel._symbol];
336 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698