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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.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 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 /** 30 /**
32 * @constructor 31 * @unrestricted
33 * @extends {WebInspector.SDKObject} 32 */
34 * @param {!WebInspector.Target} target 33 WebInspector.ServiceWorkerManager = class extends WebInspector.SDKObject {
35 * @param {!WebInspector.SubTargetsManager} subTargetsManager 34 /**
36 */ 35 * @param {!WebInspector.Target} target
37 WebInspector.ServiceWorkerManager = function(target, subTargetsManager) 36 * @param {!WebInspector.SubTargetsManager} subTargetsManager
38 { 37 */
39 WebInspector.SDKObject.call(this, target); 38 constructor(target, subTargetsManager) {
39 super(target);
40 target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatc her(this)); 40 target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatc her(this));
41 this._lastAnonymousTargetId = 0; 41 this._lastAnonymousTargetId = 0;
42 this._agent = target.serviceWorkerAgent(); 42 this._agent = target.serviceWorkerAgent();
43 /** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */ 43 /** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */
44 this._registrations = new Map(); 44 this._registrations = new Map();
45 this.enable(); 45 this.enable();
46 this._forceUpdateSetting = WebInspector.settings.createSetting("serviceWorke rUpdateOnReload", false); 46 this._forceUpdateSetting = WebInspector.settings.createSetting('serviceWorke rUpdateOnReload', false);
47 if (this._forceUpdateSetting.get()) 47 if (this._forceUpdateSetting.get())
48 this._forceUpdateSettingChanged(); 48 this._forceUpdateSettingChanged();
49 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged, this); 49 this._forceUpdateSetting.addChangeListener(this._forceUpdateSettingChanged, this);
50 new WebInspector.ServiceWorkerContextNamer(target, this, subTargetsManager); 50 new WebInspector.ServiceWorkerContextNamer(target, this, subTargetsManager);
51 }
52
53 enable() {
54 if (this._enabled)
55 return;
56 this._enabled = true;
57 this._agent.enable();
58 }
59
60 disable() {
61 if (!this._enabled)
62 return;
63 this._enabled = false;
64 this._registrations.clear();
65 this._agent.disable();
66 }
67
68 /**
69 * @return {!Map.<string, !WebInspector.ServiceWorkerRegistration>}
70 */
71 registrations() {
72 return this._registrations;
73 }
74
75 /**
76 * @param {string} versionId
77 * @return {?WebInspector.ServiceWorkerVersion}
78 */
79 findVersion(versionId) {
80 for (var registration of this.registrations().values()) {
81 var version = registration.versions.get(versionId);
82 if (version)
83 return version;
84 }
85 return null;
86 }
87
88 /**
89 * @param {string} registrationId
90 */
91 deleteRegistration(registrationId) {
92 var registration = this._registrations.get(registrationId);
93 if (!registration)
94 return;
95 if (registration._isRedundant()) {
96 this._registrations.delete(registrationId);
97 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.Reg istrationDeleted, registration);
98 return;
99 }
100 registration._deleting = true;
101 for (var version of registration.versions.values())
102 this.stopWorker(version.id);
103 this._unregister(registration.scopeURL);
104 }
105
106 /**
107 * @param {string} registrationId
108 */
109 updateRegistration(registrationId) {
110 var registration = this._registrations.get(registrationId);
111 if (!registration)
112 return;
113 this._agent.updateRegistration(registration.scopeURL);
114 }
115
116 /**
117 * @param {string} registrationId
118 * @param {string} data
119 */
120 deliverPushMessage(registrationId, data) {
121 var registration = this._registrations.get(registrationId);
122 if (!registration)
123 return;
124 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL);
125 this._agent.deliverPushMessage(origin, registrationId, data);
126 }
127
128 /**
129 * @param {string} registrationId
130 * @param {string} tag
131 * @param {boolean} lastChance
132 */
133 dispatchSyncEvent(registrationId, tag, lastChance) {
134 var registration = this._registrations.get(registrationId);
135 if (!registration)
136 return;
137 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL);
138 this._agent.dispatchSyncEvent(origin, registrationId, tag, lastChance);
139 }
140
141 /**
142 * @param {string} scope
143 */
144 _unregister(scope) {
145 this._agent.unregister(scope);
146 }
147
148 /**
149 * @param {string} scope
150 */
151 startWorker(scope) {
152 this._agent.startWorker(scope);
153 }
154
155 /**
156 * @param {string} scope
157 */
158 skipWaiting(scope) {
159 this._agent.skipWaiting(scope);
160 }
161
162 /**
163 * @param {string} versionId
164 */
165 stopWorker(versionId) {
166 this._agent.stopWorker(versionId);
167 }
168
169 /**
170 * @param {string} versionId
171 */
172 inspectWorker(versionId) {
173 this._agent.inspectWorker(versionId);
174 }
175
176 /**
177 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registratio ns
178 */
179 _workerRegistrationUpdated(registrations) {
180 for (var payload of registrations) {
181 var registration = this._registrations.get(payload.registrationId);
182 if (!registration) {
183 registration = new WebInspector.ServiceWorkerRegistration(payload);
184 this._registrations.set(payload.registrationId, registration);
185 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationUpdated, registration);
186 continue;
187 }
188 registration._update(payload);
189
190 if (registration._shouldBeRemoved()) {
191 this._registrations.delete(registration.id);
192 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationDeleted, registration);
193 } else {
194 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationUpdated, registration);
195 }
196 }
197 }
198
199 /**
200 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions
201 */
202 _workerVersionUpdated(versions) {
203 /** @type {!Set.<!WebInspector.ServiceWorkerRegistration>} */
204 var registrations = new Set();
205 for (var payload of versions) {
206 var registration = this._registrations.get(payload.registrationId);
207 if (!registration)
208 continue;
209 registration._updateVersion(payload);
210 registrations.add(registration);
211 }
212 for (var registration of registrations) {
213 if (registration._shouldBeRemoved()) {
214 this._registrations.delete(registration.id);
215 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationDeleted, registration);
216 } else {
217 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationUpdated, registration);
218 }
219 }
220 }
221
222 /**
223 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
224 */
225 _workerErrorReported(payload) {
226 var registration = this._registrations.get(payload.registrationId);
227 if (!registration)
228 return;
229 registration.errors.push(payload);
230 this.dispatchEventToListeners(
231 WebInspector.ServiceWorkerManager.Events.RegistrationErrorAdded, {regist ration: registration, error: payload});
232 }
233
234 /**
235 * @return {!WebInspector.Setting}
236 */
237 forceUpdateOnReloadSetting() {
238 return this._forceUpdateSetting;
239 }
240
241 _forceUpdateSettingChanged() {
242 this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get());
243 }
51 }; 244 };
52 245
53 /** @enum {symbol} */ 246 /** @enum {symbol} */
54 WebInspector.ServiceWorkerManager.Events = { 247 WebInspector.ServiceWorkerManager.Events = {
55 RegistrationUpdated: Symbol("RegistrationUpdated"), 248 RegistrationUpdated: Symbol('RegistrationUpdated'),
56 RegistrationErrorAdded: Symbol("RegistrationErrorAdded"), 249 RegistrationErrorAdded: Symbol('RegistrationErrorAdded'),
57 RegistrationDeleted: Symbol("RegistrationDeleted") 250 RegistrationDeleted: Symbol('RegistrationDeleted')
58 };
59
60 WebInspector.ServiceWorkerManager.prototype = {
61 enable: function()
62 {
63 if (this._enabled)
64 return;
65 this._enabled = true;
66 this._agent.enable();
67 },
68
69 disable: function()
70 {
71 if (!this._enabled)
72 return;
73 this._enabled = false;
74 this._registrations.clear();
75 this._agent.disable();
76 },
77
78 /**
79 * @return {!Map.<string, !WebInspector.ServiceWorkerRegistration>}
80 */
81 registrations: function()
82 {
83 return this._registrations;
84 },
85
86 /**
87 * @param {string} versionId
88 * @return {?WebInspector.ServiceWorkerVersion}
89 */
90 findVersion: function(versionId)
91 {
92 for (var registration of this.registrations().values()) {
93 var version = registration.versions.get(versionId);
94 if (version)
95 return version;
96 }
97 return null;
98 },
99
100 /**
101 * @param {string} registrationId
102 */
103 deleteRegistration: function(registrationId)
104 {
105 var registration = this._registrations.get(registrationId);
106 if (!registration)
107 return;
108 if (registration._isRedundant()) {
109 this._registrations.delete(registrationId);
110 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Even ts.RegistrationDeleted, registration);
111 return;
112 }
113 registration._deleting = true;
114 for (var version of registration.versions.values())
115 this.stopWorker(version.id);
116 this._unregister(registration.scopeURL);
117 },
118
119 /**
120 * @param {string} registrationId
121 */
122 updateRegistration: function(registrationId)
123 {
124 var registration = this._registrations.get(registrationId);
125 if (!registration)
126 return;
127 this._agent.updateRegistration(registration.scopeURL);
128 },
129
130 /**
131 * @param {string} registrationId
132 * @param {string} data
133 */
134 deliverPushMessage: function(registrationId, data)
135 {
136 var registration = this._registrations.get(registrationId);
137 if (!registration)
138 return;
139 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL) ;
140 this._agent.deliverPushMessage(origin, registrationId, data);
141 },
142
143 /**
144 * @param {string} registrationId
145 * @param {string} tag
146 * @param {boolean} lastChance
147 */
148 dispatchSyncEvent: function(registrationId, tag, lastChance)
149 {
150 var registration = this._registrations.get(registrationId);
151 if (!registration)
152 return;
153 var origin = WebInspector.ParsedURL.extractOrigin(registration.scopeURL) ;
154 this._agent.dispatchSyncEvent(origin, registrationId, tag, lastChance);
155 },
156
157 /**
158 * @param {string} scope
159 */
160 _unregister: function(scope)
161 {
162 this._agent.unregister(scope);
163 },
164
165 /**
166 * @param {string} scope
167 */
168 startWorker: function(scope)
169 {
170 this._agent.startWorker(scope);
171 },
172
173 /**
174 * @param {string} scope
175 */
176 skipWaiting: function(scope)
177 {
178 this._agent.skipWaiting(scope);
179 },
180
181 /**
182 * @param {string} versionId
183 */
184 stopWorker: function(versionId)
185 {
186 this._agent.stopWorker(versionId);
187 },
188
189 /**
190 * @param {string} versionId
191 */
192 inspectWorker: function(versionId)
193 {
194 this._agent.inspectWorker(versionId);
195 },
196
197 /**
198 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat ions
199 */
200 _workerRegistrationUpdated: function(registrations)
201 {
202 for (var payload of registrations) {
203 var registration = this._registrations.get(payload.registrationId);
204 if (!registration) {
205 registration = new WebInspector.ServiceWorkerRegistration(payloa d);
206 this._registrations.set(payload.registrationId, registration);
207 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration);
208 continue;
209 }
210 registration._update(payload);
211
212 if (registration._shouldBeRemoved()) {
213 this._registrations.delete(registration.id);
214 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationDeleted, registration);
215 } else {
216 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration);
217 }
218 }
219 },
220
221 /**
222 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions
223 */
224 _workerVersionUpdated: function(versions)
225 {
226 /** @type {!Set.<!WebInspector.ServiceWorkerRegistration>} */
227 var registrations = new Set();
228 for (var payload of versions) {
229 var registration = this._registrations.get(payload.registrationId);
230 if (!registration)
231 continue;
232 registration._updateVersion(payload);
233 registrations.add(registration);
234 }
235 for (var registration of registrations) {
236 if (registration._shouldBeRemoved()) {
237 this._registrations.delete(registration.id);
238 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationDeleted, registration);
239 } else {
240 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager. Events.RegistrationUpdated, registration);
241 }
242 }
243 },
244
245 /**
246 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} payload
247 */
248 _workerErrorReported: function(payload)
249 {
250 var registration = this._registrations.get(payload.registrationId);
251 if (!registration)
252 return;
253 registration.errors.push(payload);
254 this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.R egistrationErrorAdded, { registration: registration, error: payload });
255 },
256
257 /**
258 * @return {!WebInspector.Setting}
259 */
260 forceUpdateOnReloadSetting: function()
261 {
262 return this._forceUpdateSetting;
263 },
264
265 _forceUpdateSettingChanged: function()
266 {
267 this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get());
268 },
269
270 __proto__: WebInspector.SDKObject.prototype
271 }; 251 };
272 252
273 /** 253 /**
274 * @constructor
275 * @implements {ServiceWorkerAgent.Dispatcher} 254 * @implements {ServiceWorkerAgent.Dispatcher}
276 * @param {!WebInspector.ServiceWorkerManager} manager 255 * @unrestricted
277 */ 256 */
278 WebInspector.ServiceWorkerDispatcher = function(manager) 257 WebInspector.ServiceWorkerDispatcher = class {
279 { 258 /**
259 * @param {!WebInspector.ServiceWorkerManager} manager
260 */
261 constructor(manager) {
280 this._manager = manager; 262 this._manager = manager;
281 }; 263 }
282 264
283 WebInspector.ServiceWorkerDispatcher.prototype = { 265 /**
284 /** 266 * @override
285 * @override 267 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registratio ns
286 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrat ions 268 */
287 */ 269 workerRegistrationUpdated(registrations) {
288 workerRegistrationUpdated: function(registrations) 270 this._manager._workerRegistrationUpdated(registrations);
289 { 271 }
290 this._manager._workerRegistrationUpdated(registrations); 272
291 }, 273 /**
292 274 * @override
293 /** 275 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions
294 * @override 276 */
295 * @param {!Array.<!ServiceWorkerAgent.ServiceWorkerVersion>} versions 277 workerVersionUpdated(versions) {
296 */ 278 this._manager._workerVersionUpdated(versions);
297 workerVersionUpdated: function(versions) 279 }
298 { 280
299 this._manager._workerVersionUpdated(versions); 281 /**
300 }, 282 * @override
301 283 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} errorMessage
302 /** 284 */
303 * @override 285 workerErrorReported(errorMessage) {
304 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} errorMessage 286 this._manager._workerErrorReported(errorMessage);
305 */ 287 }
306 workerErrorReported: function(errorMessage)
307 {
308 this._manager._workerErrorReported(errorMessage);
309 }
310 }; 288 };
311 289
312 /** 290 /**
313 * @constructor 291 * @unrestricted
314 * @param {!WebInspector.ServiceWorkerRegistration} registration 292 */
315 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 293 WebInspector.ServiceWorkerVersion = class {
316 */ 294 /**
317 WebInspector.ServiceWorkerVersion = function(registration, payload) 295 * @param {!WebInspector.ServiceWorkerRegistration} registration
318 { 296 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
297 */
298 constructor(registration, payload) {
319 this.registration = registration; 299 this.registration = registration;
320 this._update(payload); 300 this._update(payload);
301 }
302
303 /**
304 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
305 */
306 _update(payload) {
307 this.id = payload.versionId;
308 this.scriptURL = payload.scriptURL;
309 var parsedURL = new WebInspector.ParsedURL(payload.scriptURL);
310 this.securityOrigin = parsedURL.securityOrigin();
311 this.runningStatus = payload.runningStatus;
312 this.status = payload.status;
313 this.scriptLastModified = payload.scriptLastModified;
314 this.scriptResponseTime = payload.scriptResponseTime;
315 this.controlledClients = [];
316 for (var i = 0; i < payload.controlledClients.length; ++i)
317 this.controlledClients.push(payload.controlledClients[i]);
318 this.targetId = payload.targetId || null;
319 }
320
321 /**
322 * @return {boolean}
323 */
324 isStartable() {
325 return !this.registration.isDeleted && this.isActivated() && this.isStopped( );
326 }
327
328 /**
329 * @return {boolean}
330 */
331 isStoppedAndRedundant() {
332 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRunning Status.Stopped &&
333 this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Redundant;
334 }
335
336 /**
337 * @return {boolean}
338 */
339 isStopped() {
340 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRunning Status.Stopped;
341 }
342
343 /**
344 * @return {boolean}
345 */
346 isStarting() {
347 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRunning Status.Starting;
348 }
349
350 /**
351 * @return {boolean}
352 */
353 isRunning() {
354 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRunning Status.Running;
355 }
356
357 /**
358 * @return {boolean}
359 */
360 isStopping() {
361 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRunning Status.Stopping;
362 }
363
364 /**
365 * @return {boolean}
366 */
367 isNew() {
368 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.New;
369 }
370
371 /**
372 * @return {boolean}
373 */
374 isInstalling() {
375 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Install ing;
376 }
377
378 /**
379 * @return {boolean}
380 */
381 isInstalled() {
382 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Install ed;
383 }
384
385 /**
386 * @return {boolean}
387 */
388 isActivating() {
389 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Activat ing;
390 }
391
392 /**
393 * @return {boolean}
394 */
395 isActivated() {
396 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Activat ed;
397 }
398
399 /**
400 * @return {boolean}
401 */
402 isRedundant() {
403 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Redunda nt;
404 }
405
406 /**
407 * @return {string}
408 */
409 mode() {
410 if (this.isNew() || this.isInstalling())
411 return WebInspector.ServiceWorkerVersion.Modes.Installing;
412 else if (this.isInstalled())
413 return WebInspector.ServiceWorkerVersion.Modes.Waiting;
414 else if (this.isActivating() || this.isActivated())
415 return WebInspector.ServiceWorkerVersion.Modes.Active;
416 return WebInspector.ServiceWorkerVersion.Modes.Redundant;
417 }
321 }; 418 };
322 419
323 /** 420 /**
324 * @enum {string} 421 * @enum {string}
325 */ 422 */
326 WebInspector.ServiceWorkerVersion.Modes = { 423 WebInspector.ServiceWorkerVersion.Modes = {
327 Installing: "installing", 424 Installing: 'installing',
328 Waiting: "waiting", 425 Waiting: 'waiting',
329 Active: "active", 426 Active: 'active',
330 Redundant: "redundant" 427 Redundant: 'redundant'
331 };
332
333 WebInspector.ServiceWorkerVersion.prototype = {
334 /**
335 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
336 */
337 _update: function(payload)
338 {
339 this.id = payload.versionId;
340 this.scriptURL = payload.scriptURL;
341 var parsedURL = new WebInspector.ParsedURL(payload.scriptURL);
342 this.securityOrigin = parsedURL.securityOrigin();
343 this.runningStatus = payload.runningStatus;
344 this.status = payload.status;
345 this.scriptLastModified = payload.scriptLastModified;
346 this.scriptResponseTime = payload.scriptResponseTime;
347 this.controlledClients = [];
348 for (var i = 0; i < payload.controlledClients.length; ++i)
349 this.controlledClients.push(payload.controlledClients[i]);
350 this.targetId = payload.targetId || null;
351 },
352
353 /**
354 * @return {boolean}
355 */
356 isStartable: function()
357 {
358 return !this.registration.isDeleted && this.isActivated() && this.isStop ped();
359 },
360
361 /**
362 * @return {boolean}
363 */
364 isStoppedAndRedundant: function()
365 {
366 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRun ningStatus.Stopped && this.status === ServiceWorkerAgent.ServiceWorkerVersionSta tus.Redundant;
367 },
368
369 /**
370 * @return {boolean}
371 */
372 isStopped: function()
373 {
374 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRun ningStatus.Stopped;
375 },
376
377 /**
378 * @return {boolean}
379 */
380 isStarting: function()
381 {
382 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRun ningStatus.Starting;
383 },
384
385 /**
386 * @return {boolean}
387 */
388 isRunning: function()
389 {
390 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRun ningStatus.Running;
391 },
392
393 /**
394 * @return {boolean}
395 */
396 isStopping: function()
397 {
398 return this.runningStatus === ServiceWorkerAgent.ServiceWorkerVersionRun ningStatus.Stopping;
399 },
400
401 /**
402 * @return {boolean}
403 */
404 isNew: function()
405 {
406 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.New ;
407 },
408
409 /**
410 * @return {boolean}
411 */
412 isInstalling: function()
413 {
414 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Ins talling;
415 },
416
417 /**
418 * @return {boolean}
419 */
420 isInstalled: function()
421 {
422 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Ins talled;
423 },
424
425 /**
426 * @return {boolean}
427 */
428 isActivating: function()
429 {
430 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Act ivating;
431 },
432
433 /**
434 * @return {boolean}
435 */
436 isActivated: function()
437 {
438 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Act ivated;
439 },
440
441 /**
442 * @return {boolean}
443 */
444 isRedundant: function()
445 {
446 return this.status === ServiceWorkerAgent.ServiceWorkerVersionStatus.Red undant;
447 },
448
449 /**
450 * @return {string}
451 */
452 mode: function()
453 {
454 if (this.isNew() || this.isInstalling())
455 return WebInspector.ServiceWorkerVersion.Modes.Installing;
456 else if (this.isInstalled())
457 return WebInspector.ServiceWorkerVersion.Modes.Waiting;
458 else if (this.isActivating() || this.isActivated())
459 return WebInspector.ServiceWorkerVersion.Modes.Active;
460 return WebInspector.ServiceWorkerVersion.Modes.Redundant;
461 }
462 }; 428 };
463 429
464 /** 430 /**
465 * @constructor 431 * @unrestricted
466 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload 432 */
467 */ 433 WebInspector.ServiceWorkerRegistration = class {
468 WebInspector.ServiceWorkerRegistration = function(payload) 434 /**
469 { 435 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload
436 */
437 constructor(payload) {
470 this._update(payload); 438 this._update(payload);
471 /** @type {!Map.<string, !WebInspector.ServiceWorkerVersion>} */ 439 /** @type {!Map.<string, !WebInspector.ServiceWorkerVersion>} */
472 this.versions = new Map(); 440 this.versions = new Map();
473 this._deleting = false; 441 this._deleting = false;
474 /** @type {!Array<!ServiceWorkerAgent.ServiceWorkerErrorMessage>} */ 442 /** @type {!Array<!ServiceWorkerAgent.ServiceWorkerErrorMessage>} */
475 this.errors = []; 443 this.errors = [];
476 }; 444 }
477 445
478 WebInspector.ServiceWorkerRegistration.prototype = { 446 /**
479 /** 447 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload
480 * @param {!ServiceWorkerAgent.ServiceWorkerRegistration} payload 448 */
481 */ 449 _update(payload) {
482 _update: function(payload) 450 this._fingerprint = Symbol('fingerprint');
483 { 451 this.id = payload.registrationId;
484 this._fingerprint = Symbol("fingerprint"); 452 this.scopeURL = payload.scopeURL;
485 this.id = payload.registrationId; 453 var parsedURL = new WebInspector.ParsedURL(payload.scopeURL);
486 this.scopeURL = payload.scopeURL; 454 this.securityOrigin = parsedURL.securityOrigin();
487 var parsedURL = new WebInspector.ParsedURL(payload.scopeURL); 455 this.isDeleted = payload.isDeleted;
488 this.securityOrigin = parsedURL.securityOrigin(); 456 this.forceUpdateOnPageLoad = payload.forceUpdateOnPageLoad;
489 this.isDeleted = payload.isDeleted; 457 }
490 this.forceUpdateOnPageLoad = payload.forceUpdateOnPageLoad; 458
491 }, 459 /**
492 460 * @return {symbol}
493 /** 461 */
494 * @return {symbol} 462 fingerprint() {
495 */ 463 return this._fingerprint;
496 fingerprint: function() 464 }
497 { 465
498 return this._fingerprint; 466 /**
499 }, 467 * @return {!Map<string, !WebInspector.ServiceWorkerVersion>}
500 468 */
501 /** 469 versionsByMode() {
502 * @return {!Map<string, !WebInspector.ServiceWorkerVersion>} 470 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */
503 */ 471 var result = new Map();
504 versionsByMode: function() 472 for (var version of this.versions.values())
505 { 473 result.set(version.mode(), version);
506 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */ 474 return result;
507 var result = new Map(); 475 }
508 for (var version of this.versions.values()) 476
509 result.set(version.mode(), version); 477 /**
510 return result; 478 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
511 }, 479 * @return {!WebInspector.ServiceWorkerVersion}
512 480 */
513 /** 481 _updateVersion(payload) {
514 * @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload 482 this._fingerprint = Symbol('fingerprint');
515 * @return {!WebInspector.ServiceWorkerVersion} 483 var version = this.versions.get(payload.versionId);
516 */ 484 if (!version) {
517 _updateVersion: function(payload) 485 version = new WebInspector.ServiceWorkerVersion(this, payload);
518 { 486 this.versions.set(payload.versionId, version);
519 this._fingerprint = Symbol("fingerprint"); 487 return version;
520 var version = this.versions.get(payload.versionId); 488 }
521 if (!version) { 489 version._update(payload);
522 version = new WebInspector.ServiceWorkerVersion(this, payload); 490 return version;
523 this.versions.set(payload.versionId, version); 491 }
524 return version; 492
525 } 493 /**
526 version._update(payload); 494 * @return {boolean}
527 return version; 495 */
528 }, 496 _isRedundant() {
529 497 for (var version of this.versions.values()) {
530 /** 498 if (!version.isStoppedAndRedundant())
531 * @return {boolean} 499 return false;
532 */ 500 }
533 _isRedundant: function() 501 return true;
534 { 502 }
535 for (var version of this.versions.values()) { 503
536 if (!version.isStoppedAndRedundant()) 504 /**
537 return false; 505 * @return {boolean}
538 } 506 */
539 return true; 507 _shouldBeRemoved() {
540 }, 508 return this._isRedundant() && (!this.errors.length || this._deleting);
541 509 }
542 /** 510
543 * @return {boolean} 511 clearErrors() {
544 */ 512 this._fingerprint = Symbol('fingerprint');
545 _shouldBeRemoved: function() 513 this.errors = [];
546 { 514 }
547 return this._isRedundant() && (!this.errors.length || this._deleting);
548 },
549
550 clearErrors: function()
551 {
552 this._fingerprint = Symbol("fingerprint");
553 this.errors = [];
554 }
555 }; 515 };
556 516
557 /** 517 /**
558 * @constructor 518 * @unrestricted
559 * @param {!WebInspector.Target} target 519 */
560 * @param {!WebInspector.ServiceWorkerManager} serviceWorkerManager 520 WebInspector.ServiceWorkerContextNamer = class {
561 * @param {!WebInspector.SubTargetsManager} subTargetsManager 521 /**
562 */ 522 * @param {!WebInspector.Target} target
563 WebInspector.ServiceWorkerContextNamer = function(target, serviceWorkerManager, subTargetsManager) 523 * @param {!WebInspector.ServiceWorkerManager} serviceWorkerManager
564 { 524 * @param {!WebInspector.SubTargetsManager} subTargetsManager
525 */
526 constructor(target, serviceWorkerManager, subTargetsManager) {
565 this._target = target; 527 this._target = target;
566 this._serviceWorkerManager = serviceWorkerManager; 528 this._serviceWorkerManager = serviceWorkerManager;
567 this._subTargetsManager = subTargetsManager; 529 this._subTargetsManager = subTargetsManager;
568 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */ 530 /** @type {!Map<string, !WebInspector.ServiceWorkerVersion>} */
569 this._versionByTargetId = new Map(); 531 this._versionByTargetId = new Map();
570 serviceWorkerManager.addEventListener(WebInspector.ServiceWorkerManager.Even ts.RegistrationUpdated, this._registrationsUpdated, this); 532 serviceWorkerManager.addEventListener(
571 serviceWorkerManager.addEventListener(WebInspector.ServiceWorkerManager.Even ts.RegistrationDeleted, this._registrationsUpdated, this); 533 WebInspector.ServiceWorkerManager.Events.RegistrationUpdated, this._regi strationsUpdated, this);
572 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextCreated, this._executionContextCreat ed, this); 534 serviceWorkerManager.addEventListener(
573 }; 535 WebInspector.ServiceWorkerManager.Events.RegistrationDeleted, this._regi strationsUpdated, this);
574 536 WebInspector.targetManager.addModelListener(
575 WebInspector.ServiceWorkerContextNamer.prototype = { 537 WebInspector.RuntimeModel, WebInspector.RuntimeModel.Events.ExecutionCon textCreated,
576 /** 538 this._executionContextCreated, this);
577 * @param {!WebInspector.Event} event 539 }
578 */ 540
579 _registrationsUpdated: function(event) 541 /**
580 { 542 * @param {!WebInspector.Event} event
581 this._versionByTargetId.clear(); 543 */
582 var registrations = this._serviceWorkerManager.registrations().valuesArr ay(); 544 _registrationsUpdated(event) {
583 for (var registration of registrations) { 545 this._versionByTargetId.clear();
584 var versions = registration.versions.valuesArray(); 546 var registrations = this._serviceWorkerManager.registrations().valuesArray() ;
585 for (var version of versions) { 547 for (var registration of registrations) {
586 if (version.targetId) 548 var versions = registration.versions.valuesArray();
587 this._versionByTargetId.set(version.targetId, version); 549 for (var version of versions) {
588 } 550 if (version.targetId)
589 } 551 this._versionByTargetId.set(version.targetId, version);
590 this._updateAllContextLabels(); 552 }
591 }, 553 }
592 554 this._updateAllContextLabels();
593 /** 555 }
594 * @param {!WebInspector.Event} event 556
595 */ 557 /**
596 _executionContextCreated: function(event) 558 * @param {!WebInspector.Event} event
597 { 559 */
598 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (ev ent.data); 560 _executionContextCreated(event) {
599 var serviceWorkerTargetId = this._serviceWorkerTargetIdForWorker(executi onContext.target()); 561 var executionContext = /** @type {!WebInspector.ExecutionContext} */ (event. data);
600 if (!serviceWorkerTargetId) 562 var serviceWorkerTargetId = this._serviceWorkerTargetIdForWorker(executionCo ntext.target());
601 return; 563 if (!serviceWorkerTargetId)
602 this._updateContextLabel(executionContext, this._versionByTargetId.get(s erviceWorkerTargetId) || null); 564 return;
603 }, 565 this._updateContextLabel(executionContext, this._versionByTargetId.get(servi ceWorkerTargetId) || null);
604 566 }
605 /** 567
606 * @param {!WebInspector.Target} target 568 /**
607 * @return {?string} 569 * @param {!WebInspector.Target} target
608 */ 570 * @return {?string}
609 _serviceWorkerTargetIdForWorker: function(target) 571 */
610 { 572 _serviceWorkerTargetIdForWorker(target) {
611 var parent = target.parentTarget(); 573 var parent = target.parentTarget();
612 if (!parent || parent.parentTarget() !== this._target) 574 if (!parent || parent.parentTarget() !== this._target)
613 return null; 575 return null;
614 var targetInfo = this._subTargetsManager.targetInfo(parent); 576 var targetInfo = this._subTargetsManager.targetInfo(parent);
615 if (!targetInfo || targetInfo.type !== "service_worker") 577 if (!targetInfo || targetInfo.type !== 'service_worker')
616 return null; 578 return null;
617 return targetInfo.id; 579 return targetInfo.id;
618 }, 580 }
619 581
620 _updateAllContextLabels: function() 582 _updateAllContextLabels() {
621 { 583 for (var target of WebInspector.targetManager.targets()) {
622 for (var target of WebInspector.targetManager.targets()) { 584 var serviceWorkerTargetId = this._serviceWorkerTargetIdForWorker(target);
623 var serviceWorkerTargetId = this._serviceWorkerTargetIdForWorker(tar get); 585 if (!serviceWorkerTargetId)
624 if (!serviceWorkerTargetId) 586 continue;
625 continue; 587 var version = this._versionByTargetId.get(serviceWorkerTargetId) || null;
626 var version = this._versionByTargetId.get(serviceWorkerTargetId) || null; 588 for (var context of target.runtimeModel.executionContexts())
627 for (var context of target.runtimeModel.executionContexts()) 589 this._updateContextLabel(context, version);
628 this._updateContextLabel(context, version); 590 }
629 } 591 }
630 }, 592
631 593 /**
632 /** 594 * @param {!WebInspector.ExecutionContext} context
633 * @param {!WebInspector.ExecutionContext} context 595 * @param {?WebInspector.ServiceWorkerVersion} version
634 * @param {?WebInspector.ServiceWorkerVersion} version 596 */
635 */ 597 _updateContextLabel(context, version) {
636 _updateContextLabel: function(context, version) 598 var parsedUrl = context.origin.asParsedURL();
637 { 599 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : context. name;
638 var parsedUrl = context.origin.asParsedURL(); 600 if (version)
639 var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : cont ext.name; 601 context.setLabel(label + ' #' + version.id + ' (' + version.status + ')');
640 if (version) 602 else
641 context.setLabel(label + " #" + version.id + " (" + version.status + ")"); 603 context.setLabel(label);
642 else 604 }
643 context.setLabel(label); 605 };
644 },
645 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698