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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/ServiceWorkersView.js

Issue 2354973003: [DevTools] Move subtargets functionality from ServiceWorker to Target domain. (Closed)
Patch Set: review comments Created 4 years, 2 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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @implements {WebInspector.TargetManager.Observer} 8 * @implements {WebInspector.TargetManager.Observer}
9 */ 9 */
10 WebInspector.ServiceWorkersView = function() 10 WebInspector.ServiceWorkersView = function()
(...skipping 15 matching lines...) Expand all
26 /** 26 /**
27 * @override 27 * @override
28 * @param {!WebInspector.Target} target 28 * @param {!WebInspector.Target} target
29 */ 29 */
30 targetAdded: function(target) 30 targetAdded: function(target)
31 { 31 {
32 var securityOriginManager = WebInspector.SecurityOriginManager.fromTarge t(target); 32 var securityOriginManager = WebInspector.SecurityOriginManager.fromTarge t(target);
33 if (this._manager || !target.serviceWorkerManager || !securityOriginMana ger) 33 if (this._manager || !target.serviceWorkerManager || !securityOriginMana ger)
34 return; 34 return;
35 this._manager = target.serviceWorkerManager; 35 this._manager = target.serviceWorkerManager;
36 this._subTargetsManager = target.subTargetsManager;
36 this._securityOriginManager = securityOriginManager; 37 this._securityOriginManager = securityOriginManager;
37 38
38 this._toolbar.appendToolbarItem(WebInspector.NetworkConditionsSelector.c reateOfflineToolbarCheckbox()); 39 this._toolbar.appendToolbarItem(WebInspector.NetworkConditionsSelector.c reateOfflineToolbarCheckbox());
39 var forceUpdate = new WebInspector.ToolbarCheckbox(WebInspector.UIString ("Update on reload"), WebInspector.UIString("Force update Service Worker on page reload"), this._manager.forceUpdateOnReloadSetting()); 40 var forceUpdate = new WebInspector.ToolbarCheckbox(WebInspector.UIString ("Update on reload"), WebInspector.UIString("Force update Service Worker on page reload"), this._manager.forceUpdateOnReloadSetting());
40 this._toolbar.appendToolbarItem(forceUpdate); 41 this._toolbar.appendToolbarItem(forceUpdate);
41 var networkManager = target && WebInspector.NetworkManager.fromTarget(ta rget); 42 var networkManager = target && WebInspector.NetworkManager.fromTarget(ta rget);
42 if (networkManager) { 43 if (networkManager) {
43 var fallbackToNetwork = new WebInspector.ToolbarCheckbox(WebInspecto r.UIString("Bypass for network"), WebInspector.UIString("Bypass Service Worker a nd load resources from the network"), networkManager.bypassServiceWorkerSetting( )); 44 var fallbackToNetwork = new WebInspector.ToolbarCheckbox(WebInspecto r.UIString("Bypass for network"), WebInspector.UIString("Bypass Service Worker a nd load resources from the network"), networkManager.bypassServiceWorkerSetting( ));
44 this._toolbar.appendToolbarItem(fallbackToNetwork); 45 this._toolbar.appendToolbarItem(fallbackToNetwork);
45 this._toolbar.appendSpacer(); 46 this._toolbar.appendSpacer();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 section._addError(error); 102 section._addError(error);
102 }, 103 },
103 104
104 /** 105 /**
105 * @param {!WebInspector.ServiceWorkerRegistration} registration 106 * @param {!WebInspector.ServiceWorkerRegistration} registration
106 */ 107 */
107 _updateRegistration: function(registration) 108 _updateRegistration: function(registration)
108 { 109 {
109 var section = this._sections.get(registration); 110 var section = this._sections.get(registration);
110 if (!section) { 111 if (!section) {
111 section = new WebInspector.ServiceWorkersView.Section(this._manager, this._reportView.appendSection(""), registration); 112 section = new WebInspector.ServiceWorkersView.Section(this._manager, this._subTargetsManager, this._reportView.appendSection(""), registration);
112 this._sections.set(registration, section); 113 this._sections.set(registration, section);
113 } 114 }
114 this._updateSectionVisibility(); 115 this._updateSectionVisibility();
115 section._scheduleUpdate(); 116 section._scheduleUpdate();
116 }, 117 },
117 118
118 /** 119 /**
119 * @param {!WebInspector.Event} event 120 * @param {!WebInspector.Event} event
120 */ 121 */
121 _registrationDeleted: function(event) 122 _registrationDeleted: function(event)
122 { 123 {
123 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data); 124 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} * / (event.data);
124 var section = this._sections.get(registration); 125 var section = this._sections.get(registration);
125 if (section) 126 if (section)
126 section._section.remove(); 127 section._section.remove();
127 this._sections.delete(registration); 128 this._sections.delete(registration);
128 }, 129 },
129 130
130 __proto__: WebInspector.VBox.prototype 131 __proto__: WebInspector.VBox.prototype
131 } 132 }
132 133
133 /** 134 /**
134 * @constructor 135 * @constructor
135 * @param {!WebInspector.ServiceWorkerManager} manager 136 * @param {!WebInspector.ServiceWorkerManager} manager
137 * @param {!WebInspector.SubTargetsManager} subTargetsManager
136 * @param {!WebInspector.ReportView.Section} section 138 * @param {!WebInspector.ReportView.Section} section
137 * @param {!WebInspector.ServiceWorkerRegistration} registration 139 * @param {!WebInspector.ServiceWorkerRegistration} registration
138 */ 140 */
139 WebInspector.ServiceWorkersView.Section = function(manager, section, registratio n) 141 WebInspector.ServiceWorkersView.Section = function(manager, subTargetsManager, s ection, registration)
140 { 142 {
141 this._manager = manager; 143 this._manager = manager;
144 this._subTargetsManager = subTargetsManager;
142 this._section = section; 145 this._section = section;
143 this._registration = registration; 146 this._registration = registration;
144 147
145 this._toolbar = section.createToolbar(); 148 this._toolbar = section.createToolbar();
146 this._toolbar.renderAsLinks(); 149 this._toolbar.renderAsLinks();
147 this._updateButton = new WebInspector.ToolbarButton(WebInspector.UIString("U pdate"), undefined, WebInspector.UIString("Update")); 150 this._updateButton = new WebInspector.ToolbarButton(WebInspector.UIString("U pdate"), undefined, WebInspector.UIString("Update"));
148 this._updateButton.addEventListener("click", this._updateButtonClicked.bind( this)); 151 this._updateButton.addEventListener("click", this._updateButtonClicked.bind( this));
149 this._toolbar.appendToolbarItem(this._updateButton); 152 this._toolbar.appendToolbarItem(this._updateButton);
150 this._pushButton = new WebInspector.ToolbarButton(WebInspector.UIString("Emu late push event"), undefined, WebInspector.UIString("Push")); 153 this._pushButton = new WebInspector.ToolbarButton(WebInspector.UIString("Emu late push event"), undefined, WebInspector.UIString("Push"));
151 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this )); 154 this._pushButton.addEventListener("click", this._pushButtonClicked.bind(this ));
(...skipping 25 matching lines...) Expand all
177 _scheduleUpdate: function() 180 _scheduleUpdate: function()
178 { 181 {
179 if (WebInspector.ServiceWorkersView._noThrottle) { 182 if (WebInspector.ServiceWorkersView._noThrottle) {
180 this._update(); 183 this._update();
181 return; 184 return;
182 } 185 }
183 this._throttler.schedule(this._update.bind(this)); 186 this._throttler.schedule(this._update.bind(this));
184 }, 187 },
185 188
186 /** 189 /**
190 * @param {string} versionId
191 * @return {?WebInspector.Target}
192 */
193 _targetForVersionId: function(versionId)
194 {
195 var version = this._manager.findVersion(versionId);
196 if (!version || !version.targetId)
197 return null;
198 return this._subTargetsManager.targetForId(version.targetId);
199 },
200
201 /**
187 * @return {!Promise} 202 * @return {!Promise}
188 */ 203 */
189 _update: function() 204 _update: function()
190 { 205 {
191 var fingerprint = this._registration.fingerprint(); 206 var fingerprint = this._registration.fingerprint();
192 if (fingerprint === this._fingerprint) 207 if (fingerprint === this._fingerprint)
193 return Promise.resolve(); 208 return Promise.resolve();
194 this._fingerprint = fingerprint; 209 this._fingerprint = fingerprint;
195 210
196 this._toolbar.setEnabled(!this._registration.isDeleted); 211 this._toolbar.setEnabled(!this._registration.isDeleted);
(...skipping 17 matching lines...) Expand all
214 var fileName = WebInspector.ParsedURL.extractName(active.scriptURL); 229 var fileName = WebInspector.ParsedURL.extractName(active.scriptURL);
215 scriptElement.appendChild(WebInspector.linkifyURLAsNode(active.scrip tURL, fileName)); 230 scriptElement.appendChild(WebInspector.linkifyURLAsNode(active.scrip tURL, fileName));
216 scriptElement.createChild("div", "report-field-value-subtitle").text Content = WebInspector.UIString("Received %s", new Date(active.scriptResponseTim e * 1000).toLocaleString()); 231 scriptElement.createChild("div", "report-field-value-subtitle").text Content = WebInspector.UIString("Received %s", new Date(active.scriptResponseTim e * 1000).toLocaleString());
217 232
218 var activeEntry = versionsStack.createChild("div", "service-worker-v ersion"); 233 var activeEntry = versionsStack.createChild("div", "service-worker-v ersion");
219 activeEntry.createChild("div", "service-worker-active-circle"); 234 activeEntry.createChild("div", "service-worker-active-circle");
220 activeEntry.createChild("span").textContent = WebInspector.UIString( "#%s activated and is %s", active.id, active.runningStatus); 235 activeEntry.createChild("span").textContent = WebInspector.UIString( "#%s activated and is %s", active.id, active.runningStatus);
221 236
222 if (active.isRunning() || active.isStarting()) { 237 if (active.isRunning() || active.isStarting()) {
223 createLink(activeEntry, WebInspector.UIString("stop"), this._sto pButtonClicked.bind(this, active.id)); 238 createLink(activeEntry, WebInspector.UIString("stop"), this._sto pButtonClicked.bind(this, active.id));
224 if (!this._manager.targetForVersionId(active.id)) 239 if (!this._targetForVersionId(active.id))
225 createLink(activeEntry, WebInspector.UIString("inspect"), th is._inspectButtonClicked.bind(this, active.id)); 240 createLink(activeEntry, WebInspector.UIString("inspect"), th is._inspectButtonClicked.bind(this, active.id));
226 } else if (active.isStartable()) { 241 } else if (active.isStartable()) {
227 createLink(activeEntry, WebInspector.UIString("start"), this._st artButtonClicked.bind(this)); 242 createLink(activeEntry, WebInspector.UIString("start"), this._st artButtonClicked.bind(this));
228 } 243 }
229 244
230 var clientsList = this._wrapWidget(this._section.appendField(WebInsp ector.UIString("Clients"))); 245 var clientsList = this._wrapWidget(this._section.appendField(WebInsp ector.UIString("Clients")));
231 clientsList.removeChildren(); 246 clientsList.removeChildren();
232 this._section.setFieldVisible(WebInspector.UIString("Clients"), acti ve.controlledClients.length); 247 this._section.setFieldVisible(WebInspector.UIString("Clients"), acti ve.controlledClients.length);
233 for (var client of active.controlledClients) { 248 for (var client of active.controlledClients) {
234 var clientLabelText = clientsList.createChild("div", "service-wo rker-client"); 249 var clientLabelText = clientsList.createChild("div", "service-wo rker-client");
235 if (this._clientInfoCache.has(client)) 250 if (this._clientInfoCache.has(client))
236 this._updateClientInfo(clientLabelText, /** @type {!WebInspe ctor.TargetInfo} */(this._clientInfoCache.get(client))); 251 this._updateClientInfo(clientLabelText, /** @type {!WebInspe ctor.TargetInfo} */(this._clientInfoCache.get(client)));
237 this._manager.getTargetInfo(client, this._onClientInfo.bind(this , clientLabelText)); 252 this._subTargetsManager.getTargetInfo(client, this._onClientInfo .bind(this, clientLabelText));
238 } 253 }
239 } 254 }
240 255
241 if (waiting) { 256 if (waiting) {
242 var waitingEntry = versionsStack.createChild("div", "service-worker- version"); 257 var waitingEntry = versionsStack.createChild("div", "service-worker- version");
243 waitingEntry.createChild("div", "service-worker-waiting-circle"); 258 waitingEntry.createChild("div", "service-worker-waiting-circle");
244 waitingEntry.createChild("span").textContent = WebInspector.UIString ("#%s waiting to activate", waiting.id); 259 waitingEntry.createChild("span").textContent = WebInspector.UIString ("#%s waiting to activate", waiting.id);
245 createLink(waitingEntry, WebInspector.UIString("skipWaiting"), this. _skipButtonClicked.bind(this)); 260 createLink(waitingEntry, WebInspector.UIString("skipWaiting"), this. _skipButtonClicked.bind(this));
246 waitingEntry.createChild("div", "service-worker-subtitle").textConte nt = new Date(waiting.scriptResponseTime * 1000).toLocaleString(); 261 waitingEntry.createChild("div", "service-worker-subtitle").textConte nt = new Date(waiting.scriptResponseTime * 1000).toLocaleString();
247 if (!this._manager.targetForVersionId(waiting.id) && (waiting.isRunn ing() || waiting.isStarting())) 262 if (!this._targetForVersionId(waiting.id) && (waiting.isRunning() || waiting.isStarting()))
248 createLink(waitingEntry, WebInspector.UIString("inspect"), this. _inspectButtonClicked.bind(this, waiting.id)); 263 createLink(waitingEntry, WebInspector.UIString("inspect"), this. _inspectButtonClicked.bind(this, waiting.id));
249 } 264 }
250 if (installing) { 265 if (installing) {
251 var installingEntry = versionsStack.createChild("div", "service-work er-version"); 266 var installingEntry = versionsStack.createChild("div", "service-work er-version");
252 installingEntry.createChild("div", "service-worker-installing-circle "); 267 installingEntry.createChild("div", "service-worker-installing-circle ");
253 installingEntry.createChild("span").textContent = WebInspector.UIStr ing("#%s installing", installing.id); 268 installingEntry.createChild("span").textContent = WebInspector.UIStr ing("#%s installing", installing.id);
254 installingEntry.createChild("div", "service-worker-subtitle").textCo ntent = new Date(installing.scriptResponseTime * 1000).toLocaleString(); 269 installingEntry.createChild("div", "service-worker-subtitle").textCo ntent = new Date(installing.scriptResponseTime * 1000).toLocaleString();
255 if (!this._manager.targetForVersionId(installing.id) && (installing. isRunning() || installing.isStarting())) 270 if (!this._targetForVersionId(installing.id) && (installing.isRunnin g() || installing.isStarting()))
256 createLink(installingEntry, WebInspector.UIString("inspect"), th is._inspectButtonClicked.bind(this, installing.id)); 271 createLink(installingEntry, WebInspector.UIString("inspect"), th is._inspectButtonClicked.bind(this, installing.id));
257 } 272 }
258 273
259 this._section.setFieldVisible(WebInspector.UIString("Errors"), !!this._r egistration.errors.length); 274 this._section.setFieldVisible(WebInspector.UIString("Errors"), !!this._r egistration.errors.length);
260 var errorsValue = this._wrapWidget(this._section.appendField(WebInspecto r.UIString("Errors"))); 275 var errorsValue = this._wrapWidget(this._section.appendField(WebInspecto r.UIString("Errors")));
261 var errorsLabel = createLabel(String(this._registration.errors.length), "error-icon"); 276 var errorsLabel = createLabel(String(this._registration.errors.length), "error-icon");
262 errorsLabel.classList.add("service-worker-errors-label"); 277 errorsLabel.classList.add("service-worker-errors-label");
263 errorsValue.appendChild(errorsLabel); 278 errorsValue.appendChild(errorsLabel);
264 this._moreButton = createLink(errorsValue, this._errorsList.classList.co ntains("hidden") ? WebInspector.UIString("details") : WebInspector.UIString("hid e"), this._moreErrorsButtonClicked.bind(this)); 279 this._moreButton = createLink(errorsValue, this._errorsList.classList.co ntains("hidden") ? WebInspector.UIString("details") : WebInspector.UIString("hid e"), this._moreErrorsButtonClicked.bind(this));
265 createLink(errorsValue, WebInspector.UIString("clear"), this._clearError sButtonClicked.bind(this)); 280 createLink(errorsValue, WebInspector.UIString("clear"), this._clearError sButtonClicked.bind(this));
(...skipping 12 matching lines...) Expand all
278 return span; 293 return span;
279 } 294 }
280 return Promise.resolve(); 295 return Promise.resolve();
281 }, 296 },
282 297
283 /** 298 /**
284 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} error 299 * @param {!ServiceWorkerAgent.ServiceWorkerErrorMessage} error
285 */ 300 */
286 _addError: function(error) 301 _addError: function(error)
287 { 302 {
288 var target = this._manager.targetForVersionId(error.versionId); 303 var target = this._targetForVersionId(error.versionId);
289 var message = this._errorsList.createChild("div"); 304 var message = this._errorsList.createChild("div");
290 if (this._errorsList.childElementCount > 100) 305 if (this._errorsList.childElementCount > 100)
291 this._errorsList.firstElementChild.remove(); 306 this._errorsList.firstElementChild.remove();
292 message.appendChild(this._linkifier.linkifyScriptLocation(target, null, error.sourceURL, error.lineNumber)); 307 message.appendChild(this._linkifier.linkifyScriptLocation(target, null, error.sourceURL, error.lineNumber));
293 message.appendChild(createLabel("#" + error.versionId + ": " + error.err orMessage, "error-icon")); 308 message.appendChild(createLabel("#" + error.versionId + ": " + error.err orMessage, "error-icon"));
294 }, 309 },
295 310
296 _unregisterButtonClicked: function() 311 _unregisterButtonClicked: function()
297 { 312 {
298 this._manager.deleteRegistration(this._registration.id); 313 this._manager.deleteRegistration(this._registration.id);
(...skipping 28 matching lines...) Expand all
327 this._clientInfoCache.set(targetInfo.id, targetInfo); 342 this._clientInfoCache.set(targetInfo.id, targetInfo);
328 this._updateClientInfo(element, targetInfo); 343 this._updateClientInfo(element, targetInfo);
329 }, 344 },
330 345
331 /** 346 /**
332 * @param {!Element} element 347 * @param {!Element} element
333 * @param {!WebInspector.TargetInfo} targetInfo 348 * @param {!WebInspector.TargetInfo} targetInfo
334 */ 349 */
335 _updateClientInfo: function(element, targetInfo) 350 _updateClientInfo: function(element, targetInfo)
336 { 351 {
337 if (!(targetInfo.isWebContents() || targetInfo.isFrame())) { 352 if (!targetInfo.canActivate) {
338 element.createTextChild(WebInspector.UIString("Worker: %s", targetIn fo.url)); 353 element.createTextChild(targetInfo.title);
339 return; 354 return;
340 } 355 }
341 element.removeChildren(); 356 element.removeChildren();
342 element.createTextChild(targetInfo.url); 357 element.createTextChild(targetInfo.url);
343 var focusLabel = element.createChild("label", "link"); 358 var focusLabel = element.createChild("label", "link");
344 focusLabel.createTextChild("focus"); 359 focusLabel.createTextChild("focus");
345 focusLabel.addEventListener("click", this._activateTarget.bind(this, tar getInfo.id), true); 360 focusLabel.addEventListener("click", this._activateTarget.bind(this, tar getInfo.id), true);
346 }, 361 },
347 362
348 /** 363 /**
349 * @param {string} targetId 364 * @param {string} targetId
350 */ 365 */
351 _activateTarget: function(targetId) 366 _activateTarget: function(targetId)
352 { 367 {
353 this._manager.activateTarget(targetId); 368 this._subTargetsManager.activateTarget(targetId);
354 }, 369 },
355 370
356 _startButtonClicked: function() 371 _startButtonClicked: function()
357 { 372 {
358 this._manager.startWorker(this._registration.scopeURL); 373 this._manager.startWorker(this._registration.scopeURL);
359 }, 374 },
360 375
361 _skipButtonClicked: function() 376 _skipButtonClicked: function()
362 { 377 {
363 this._manager.skipWaiting(this._registration.scopeURL); 378 this._manager.skipWaiting(this._registration.scopeURL);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 return contentElement; 423 return contentElement;
409 }, 424 },
410 425
411 _dispose: function() 426 _dispose: function()
412 { 427 {
413 this._linkifier.dispose(); 428 this._linkifier.dispose();
414 if (this._pendingUpdate) 429 if (this._pendingUpdate)
415 clearTimeout(this._pendingUpdate); 430 clearTimeout(this._pendingUpdate);
416 } 431 }
417 } 432 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698