OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @constructor | |
7 * @extends {WebInspector.SidebarPane} | |
8 * @implements {WebInspector.TargetManager.Observer} | |
9 */ | |
10 WebInspector.ServiceWorkersSidebarPane = function() | |
11 { | |
12 WebInspector.SidebarPane.call(this, WebInspector.UIString("\u2699 Service Wo
rkers")); | |
13 this.registerRequiredCSS("sources/serviceWorkersSidebar.css"); | |
14 this._bodyElement = this.element.createChild("div", "vbox"); | |
15 this.setVisible(false); | |
16 | |
17 /** @type {?WebInspector.ServiceWorkerManager} */ | |
18 this._manager = null; | |
19 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag
e); | |
20 this._placeholderElement = createElementWithClass("div", "info"); | |
21 this._placeholderElement.textContent = WebInspector.UIString("No service wor
kers control this page"); | |
22 | |
23 /** @type {!Map.<string, !Element>} */ | |
24 this._versionIdCheckBoxMap = new Map(); | |
25 } | |
26 | |
27 WebInspector.ServiceWorkersSidebarPane.prototype = { | |
28 /** | |
29 * @override | |
30 * @param {!WebInspector.Target} target | |
31 */ | |
32 targetAdded: function(target) | |
33 { | |
34 if (this._manager) | |
35 return; | |
36 this._manager = target.serviceWorkerManager; | |
37 this._updateVisibility(); | |
38 target.serviceWorkerManager.addEventListener(WebInspector.ServiceWorkerM
anager.Events.WorkersUpdated, this._update, this); | |
39 target.serviceWorkerManager.addEventListener(WebInspector.ServiceWorkerM
anager.Events.RegistrationUpdated, this._registrationUpdated, this); | |
40 }, | |
41 | |
42 /** | |
43 * @override | |
44 * @param {!WebInspector.Target} target | |
45 */ | |
46 targetRemoved: function(target) | |
47 { | |
48 target.serviceWorkerManager.removeEventListener(WebInspector.ServiceWork
erManager.Events.WorkersUpdated, this._update, this); | |
49 target.serviceWorkerManager.removeEventListener(WebInspector.ServiceWork
erManager.Events.RegistrationUpdated, this._registrationUpdated, this); | |
50 this._updateVisibility(); | |
51 }, | |
52 | |
53 _update: function() | |
54 { | |
55 this._updateVisibility(); | |
56 this._bodyElement.removeChildren(); | |
57 this._versionIdCheckBoxMap.clear(); | |
58 | |
59 if (!this.isShowing() || !this._manager) | |
60 return; | |
61 | |
62 if (!this._manager.hasWorkers()) { | |
63 this._bodyElement.appendChild(this._placeholderElement); | |
64 return; | |
65 } | |
66 | |
67 for (var worker of this._manager.workers()) { | |
68 var workerElement = this._bodyElement.createChild("div", "service-wo
rker"); | |
69 var leftBox = workerElement.createChild("div", "vbox flex-auto"); | |
70 leftBox.appendChild(WebInspector.linkifyURLAsNode(worker.url(), work
er.name())); | |
71 var scopeElement = leftBox.createChild("span", "service-worker-scope
"); | |
72 scopeElement.textContent = worker.scope(); | |
73 scopeElement.title = worker.scope(); | |
74 var forceUpdateOnPageLoadCheckboxLabel = createCheckboxLabel(WebInsp
ector.UIString("Force update on page load")); | |
75 var forceUpdateOnPageLoadCheckbox = forceUpdateOnPageLoadCheckboxLab
el.checkboxElement; | |
76 this._versionIdCheckBoxMap.set(worker.versionId(), forceUpdateOnPage
LoadCheckbox); | |
77 forceUpdateOnPageLoadCheckbox.addEventListener("click", this._forceU
pdateOnPageLoadCheckboxClicked.bind(this, forceUpdateOnPageLoadCheckbox, worker.
versionId()), false); | |
78 var version = this._manager.findVersion(worker.versionId()); | |
79 if (version) | |
80 forceUpdateOnPageLoadCheckbox.checked = version.registration.for
ceUpdateOnPageLoad; | |
81 leftBox.appendChild(forceUpdateOnPageLoadCheckboxLabel); | |
82 workerElement.appendChild(createTextButton(WebInspector.UIString("Un
register"), worker.stop.bind(worker))); | |
83 } | |
84 }, | |
85 | |
86 /** | |
87 * @param {!WebInspector.Event} event | |
88 */ | |
89 _registrationUpdated: function(event) | |
90 { | |
91 var registration = /** @type {!WebInspector.ServiceWorkerRegistration} *
/ (event.data); | |
92 for (var version of registration.versions.values()) { | |
93 var checkBox = this._versionIdCheckBoxMap.get(version.id); | |
94 if (checkBox) | |
95 checkBox.checked = registration.forceUpdateOnPageLoad; | |
96 } | |
97 }, | |
98 | |
99 /** | |
100 * @param {!Element} checkbox | |
101 * @param {string} versionId | |
102 * @param {!Event} event | |
103 */ | |
104 _forceUpdateOnPageLoadCheckboxClicked: function(checkbox, versionId, event) | |
105 { | |
106 event.preventDefault() | |
107 var version = this._manager.findVersion(versionId); | |
108 if (!version) | |
109 return; | |
110 this._manager.setForceUpdateOnPageLoad(version.registration.id, checkbox
.checked); | |
111 }, | |
112 | |
113 _updateVisibility: function() | |
114 { | |
115 this._wasVisibleAtLeastOnce = this._wasVisibleAtLeastOnce || !!this._man
ager && this._manager.hasWorkers(); | |
116 this.setVisible(this._wasVisibleAtLeastOnce); | |
117 }, | |
118 | |
119 wasShown: function() | |
120 { | |
121 this._update(); | |
122 }, | |
123 | |
124 __proto__: WebInspector.SidebarPane.prototype | |
125 } | |
OLD | NEW |