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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above 11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
14 * distribution. 14 * distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28
29 /** 28 /**
30 * @constructor 29 * @unrestricted
31 * @extends {WebInspector.SDKModel}
32 * @param {!WebInspector.Target} target
33 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel
34 */ 30 */
35 WebInspector.ApplicationCacheModel = function(target, resourceTreeModel) 31 WebInspector.ApplicationCacheModel = class extends WebInspector.SDKModel {
36 { 32 /**
37 WebInspector.SDKModel.call(this, WebInspector.ApplicationCacheModel, target) ; 33 * @param {!WebInspector.Target} target
34 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel
35 */
36 constructor(target, resourceTreeModel) {
37 super(WebInspector.ApplicationCacheModel, target);
38 38
39 target.registerApplicationCacheDispatcher(new WebInspector.ApplicationCacheD ispatcher(this)); 39 target.registerApplicationCacheDispatcher(new WebInspector.ApplicationCacheD ispatcher(this));
40 this._agent = target.applicationCacheAgent(); 40 this._agent = target.applicationCacheAgent();
41 this._agent.enable(); 41 this._agent.enable();
42 42
43 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Fra meNavigated, this._frameNavigated, this); 43 resourceTreeModel.addEventListener(
44 WebInspector.ResourceTreeModel.Events.FrameNavigated, this._frameNavigat ed, this);
44 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Fra meDetached, this._frameDetached, this); 45 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Fra meDetached, this._frameDetached, this);
45 46
46 this._statuses = {}; 47 this._statuses = {};
47 this._manifestURLsByFrame = {}; 48 this._manifestURLsByFrame = {};
48 49
49 this._mainFrameNavigated(); 50 this._mainFrameNavigated();
50 this._onLine = true; 51 this._onLine = true;
52 }
53
54 /**
55 * @param {!WebInspector.Target} target
56 * @return {?WebInspector.ApplicationCacheModel}
57 */
58 static fromTarget(target) {
59 return /** @type {?WebInspector.ApplicationCacheModel} */ (target.model(WebI nspector.ApplicationCacheModel));
60 }
61
62 _frameNavigated(event) {
63 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data);
64 if (frame.isMainFrame()) {
65 this._mainFrameNavigated();
66 return;
67 }
68
69 this._agent.getManifestForFrame(frame.id, this._manifestForFrameLoaded.bind( this, frame.id));
70 }
71
72 /**
73 * @param {!WebInspector.Event} event
74 */
75 _frameDetached(event) {
76 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data);
77 this._frameManifestRemoved(frame.id);
78 }
79
80 reset() {
81 this._statuses = {};
82 this._manifestURLsByFrame = {};
83 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events.Fram eManifestsReset);
84 }
85
86 _mainFrameNavigated() {
87 this._agent.getFramesWithManifests(this._framesWithManifestsLoaded.bind(this ));
88 }
89
90 /**
91 * @param {string} frameId
92 * @param {?Protocol.Error} error
93 * @param {string} manifestURL
94 */
95 _manifestForFrameLoaded(frameId, error, manifestURL) {
96 if (error) {
97 console.error(error);
98 return;
99 }
100
101 if (!manifestURL)
102 this._frameManifestRemoved(frameId);
103 }
104
105 /**
106 * @param {?Protocol.Error} error
107 * @param {!Array.<!ApplicationCacheAgent.FrameWithManifest>} framesWithManife sts
108 */
109 _framesWithManifestsLoaded(error, framesWithManifests) {
110 if (error) {
111 console.error(error);
112 return;
113 }
114
115 for (var i = 0; i < framesWithManifests.length; ++i)
116 this._frameManifestUpdated(
117 framesWithManifests[i].frameId, framesWithManifests[i].manifestURL, fr amesWithManifests[i].status);
118 }
119
120 /**
121 * @param {string} frameId
122 * @param {string} manifestURL
123 * @param {number} status
124 */
125 _frameManifestUpdated(frameId, manifestURL, status) {
126 if (status === applicationCache.UNCACHED) {
127 this._frameManifestRemoved(frameId);
128 return;
129 }
130
131 if (!manifestURL)
132 return;
133
134 if (this._manifestURLsByFrame[frameId] && manifestURL !== this._manifestURLs ByFrame[frameId])
135 this._frameManifestRemoved(frameId);
136
137 var statusChanged = this._statuses[frameId] !== status;
138 this._statuses[frameId] = status;
139
140 if (!this._manifestURLsByFrame[frameId]) {
141 this._manifestURLsByFrame[frameId] = manifestURL;
142 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events.Fr ameManifestAdded, frameId);
143 }
144
145 if (statusChanged)
146 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events.Fr ameManifestStatusUpdated, frameId);
147 }
148
149 /**
150 * @param {string} frameId
151 */
152 _frameManifestRemoved(frameId) {
153 if (!this._manifestURLsByFrame[frameId])
154 return;
155
156 delete this._manifestURLsByFrame[frameId];
157 delete this._statuses[frameId];
158
159 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events.Fram eManifestRemoved, frameId);
160 }
161
162 /**
163 * @param {string} frameId
164 * @return {string}
165 */
166 frameManifestURL(frameId) {
167 return this._manifestURLsByFrame[frameId] || '';
168 }
169
170 /**
171 * @param {string} frameId
172 * @return {number}
173 */
174 frameManifestStatus(frameId) {
175 return this._statuses[frameId] || applicationCache.UNCACHED;
176 }
177
178 /**
179 * @return {boolean}
180 */
181 get onLine() {
182 return this._onLine;
183 }
184
185 /**
186 * @param {string} frameId
187 * @param {string} manifestURL
188 * @param {number} status
189 */
190 _statusUpdated(frameId, manifestURL, status) {
191 this._frameManifestUpdated(frameId, manifestURL, status);
192 }
193
194 /**
195 * @param {string} frameId
196 * @param {function(?ApplicationCacheAgent.ApplicationCache)} callback
197 */
198 requestApplicationCache(frameId, callback) {
199 /**
200 * @param {?Protocol.Error} error
201 * @param {!ApplicationCacheAgent.ApplicationCache} applicationCache
202 */
203 function callbackWrapper(error, applicationCache) {
204 if (error) {
205 console.error(error);
206 callback(null);
207 return;
208 }
209
210 callback(applicationCache);
211 }
212
213 this._agent.getApplicationCacheForFrame(frameId, callbackWrapper);
214 }
215
216 /**
217 * @param {boolean} isNowOnline
218 */
219 _networkStateUpdated(isNowOnline) {
220 this._onLine = isNowOnline;
221 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events.Netw orkStateChanged, isNowOnline);
222 }
51 }; 223 };
52 224
53 /** @enum {symbol} */ 225 /** @enum {symbol} */
54 WebInspector.ApplicationCacheModel.Events = { 226 WebInspector.ApplicationCacheModel.Events = {
55 FrameManifestStatusUpdated: Symbol("FrameManifestStatusUpdated"), 227 FrameManifestStatusUpdated: Symbol('FrameManifestStatusUpdated'),
56 FrameManifestAdded: Symbol("FrameManifestAdded"), 228 FrameManifestAdded: Symbol('FrameManifestAdded'),
57 FrameManifestRemoved: Symbol("FrameManifestRemoved"), 229 FrameManifestRemoved: Symbol('FrameManifestRemoved'),
58 FrameManifestsReset: Symbol("FrameManifestsReset"), 230 FrameManifestsReset: Symbol('FrameManifestsReset'),
59 NetworkStateChanged: Symbol("NetworkStateChanged") 231 NetworkStateChanged: Symbol('NetworkStateChanged')
60 }; 232 };
61 233
62 WebInspector.ApplicationCacheModel.prototype = { 234 /**
63 _frameNavigated: function(event) 235 * @implements {ApplicationCacheAgent.Dispatcher}
64 { 236 * @unrestricted
65 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data); 237 */
66 if (frame.isMainFrame()) { 238 WebInspector.ApplicationCacheDispatcher = class {
67 this._mainFrameNavigated(); 239 constructor(applicationCacheModel) {
68 return; 240 this._applicationCacheModel = applicationCacheModel;
69 } 241 }
70 242
71 this._agent.getManifestForFrame(frame.id, this._manifestForFrameLoaded.b ind(this, frame.id)); 243 /**
72 }, 244 * @override
73 245 * @param {string} frameId
74 /** 246 * @param {string} manifestURL
75 * @param {!WebInspector.Event} event 247 * @param {number} status
76 */ 248 */
77 _frameDetached: function(event) 249 applicationCacheStatusUpdated(frameId, manifestURL, status) {
78 { 250 this._applicationCacheModel._statusUpdated(frameId, manifestURL, status);
79 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data); 251 }
80 this._frameManifestRemoved(frame.id); 252
81 }, 253 /**
82 254 * @override
83 reset: function() 255 * @param {boolean} isNowOnline
84 { 256 */
85 this._statuses = {}; 257 networkStateUpdated(isNowOnline) {
86 this._manifestURLsByFrame = {}; 258 this._applicationCacheModel._networkStateUpdated(isNowOnline);
87 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events. FrameManifestsReset); 259 }
88 },
89
90 _mainFrameNavigated: function()
91 {
92 this._agent.getFramesWithManifests(this._framesWithManifestsLoaded.bind( this));
93 },
94
95 /**
96 * @param {string} frameId
97 * @param {?Protocol.Error} error
98 * @param {string} manifestURL
99 */
100 _manifestForFrameLoaded: function(frameId, error, manifestURL)
101 {
102 if (error) {
103 console.error(error);
104 return;
105 }
106
107 if (!manifestURL)
108 this._frameManifestRemoved(frameId);
109 },
110
111 /**
112 * @param {?Protocol.Error} error
113 * @param {!Array.<!ApplicationCacheAgent.FrameWithManifest>} framesWithMani fests
114 */
115 _framesWithManifestsLoaded: function(error, framesWithManifests)
116 {
117 if (error) {
118 console.error(error);
119 return;
120 }
121
122 for (var i = 0; i < framesWithManifests.length; ++i)
123 this._frameManifestUpdated(framesWithManifests[i].frameId, framesWit hManifests[i].manifestURL, framesWithManifests[i].status);
124 },
125
126 /**
127 * @param {string} frameId
128 * @param {string} manifestURL
129 * @param {number} status
130 */
131 _frameManifestUpdated: function(frameId, manifestURL, status)
132 {
133 if (status === applicationCache.UNCACHED) {
134 this._frameManifestRemoved(frameId);
135 return;
136 }
137
138 if (!manifestURL)
139 return;
140
141 if (this._manifestURLsByFrame[frameId] && manifestURL !== this._manifest URLsByFrame[frameId])
142 this._frameManifestRemoved(frameId);
143
144 var statusChanged = this._statuses[frameId] !== status;
145 this._statuses[frameId] = status;
146
147 if (!this._manifestURLsByFrame[frameId]) {
148 this._manifestURLsByFrame[frameId] = manifestURL;
149 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Eve nts.FrameManifestAdded, frameId);
150 }
151
152 if (statusChanged)
153 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Eve nts.FrameManifestStatusUpdated, frameId);
154 },
155
156 /**
157 * @param {string} frameId
158 */
159 _frameManifestRemoved: function(frameId)
160 {
161 if (!this._manifestURLsByFrame[frameId])
162 return;
163
164 delete this._manifestURLsByFrame[frameId];
165 delete this._statuses[frameId];
166
167 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events. FrameManifestRemoved, frameId);
168 },
169
170 /**
171 * @param {string} frameId
172 * @return {string}
173 */
174 frameManifestURL: function(frameId)
175 {
176 return this._manifestURLsByFrame[frameId] || "";
177 },
178
179 /**
180 * @param {string} frameId
181 * @return {number}
182 */
183 frameManifestStatus: function(frameId)
184 {
185 return this._statuses[frameId] || applicationCache.UNCACHED;
186 },
187
188 /**
189 * @return {boolean}
190 */
191 get onLine()
192 {
193 return this._onLine;
194 },
195
196 /**
197 * @param {string} frameId
198 * @param {string} manifestURL
199 * @param {number} status
200 */
201 _statusUpdated: function(frameId, manifestURL, status)
202 {
203 this._frameManifestUpdated(frameId, manifestURL, status);
204 },
205
206 /**
207 * @param {string} frameId
208 * @param {function(?ApplicationCacheAgent.ApplicationCache)} callback
209 */
210 requestApplicationCache: function(frameId, callback)
211 {
212 /**
213 * @param {?Protocol.Error} error
214 * @param {!ApplicationCacheAgent.ApplicationCache} applicationCache
215 */
216 function callbackWrapper(error, applicationCache)
217 {
218 if (error) {
219 console.error(error);
220 callback(null);
221 return;
222 }
223
224 callback(applicationCache);
225 }
226
227 this._agent.getApplicationCacheForFrame(frameId, callbackWrapper);
228 },
229
230 /**
231 * @param {boolean} isNowOnline
232 */
233 _networkStateUpdated: function(isNowOnline)
234 {
235 this._onLine = isNowOnline;
236 this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.Events. NetworkStateChanged, isNowOnline);
237 },
238
239 __proto__: WebInspector.SDKModel.prototype
240 }; 260 };
241 261
242 /** 262
243 * @constructor
244 * @implements {ApplicationCacheAgent.Dispatcher}
245 */
246 WebInspector.ApplicationCacheDispatcher = function(applicationCacheModel)
247 {
248 this._applicationCacheModel = applicationCacheModel;
249 };
250
251 WebInspector.ApplicationCacheDispatcher.prototype = {
252 /**
253 * @override
254 * @param {string} frameId
255 * @param {string} manifestURL
256 * @param {number} status
257 */
258 applicationCacheStatusUpdated: function(frameId, manifestURL, status)
259 {
260 this._applicationCacheModel._statusUpdated(frameId, manifestURL, status) ;
261 },
262
263 /**
264 * @override
265 * @param {boolean} isNowOnline
266 */
267 networkStateUpdated: function(isNowOnline)
268 {
269 this._applicationCacheModel._networkStateUpdated(isNowOnline);
270 }
271 };
272
273 /**
274 * @param {!WebInspector.Target} target
275 * @return {?WebInspector.ApplicationCacheModel}
276 */
277 WebInspector.ApplicationCacheModel.fromTarget = function(target)
278 {
279 return /** @type {?WebInspector.ApplicationCacheModel} */ (target.model(WebI nspector.ApplicationCacheModel));
280 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698