OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 * @implements {SDK.SDKModelObserver<!SDK.ServiceWorkerManager>} | |
6 * @unrestricted | 7 * @unrestricted |
7 */ | 8 */ |
8 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { | 9 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { |
9 constructor() { | 10 constructor() { |
10 super('audits2'); | 11 super('audits2'); |
11 this.setHideOnDetach(); | 12 this.setHideOnDetach(); |
12 this.registerRequiredCSS('audits2/audits2Panel.css'); | 13 this.registerRequiredCSS('audits2/audits2Panel.css'); |
13 this.registerRequiredCSS('audits2/lighthouse/report-styles.css'); | 14 this.registerRequiredCSS('audits2/lighthouse/report-styles.css'); |
14 | 15 |
15 this._protocolService = new Audits2.ProtocolService(); | 16 this._protocolService = new Audits2.ProtocolService(); |
(...skipping 20 matching lines...) Expand all Loading... | |
36 this._treeOutline.registerRequiredCSS('audits2/audits2Tree.css'); | 37 this._treeOutline.registerRequiredCSS('audits2/audits2Tree.css'); |
37 this.panelSidebarElement().appendChild(this._treeOutline.element); | 38 this.panelSidebarElement().appendChild(this._treeOutline.element); |
38 | 39 |
39 this._dropTarget = new UI.DropTarget( | 40 this._dropTarget = new UI.DropTarget( |
40 this.contentElement, [UI.DropTarget.Types.Files], Common.UIString('Drop audit file here'), | 41 this.contentElement, [UI.DropTarget.Types.Files], Common.UIString('Drop audit file here'), |
41 this._handleDrop.bind(this)); | 42 this._handleDrop.bind(this)); |
42 | 43 |
43 for (var preset of Audits2.Audits2Panel.Presets) | 44 for (var preset of Audits2.Audits2Panel.Presets) |
44 preset.setting.addChangeListener(this._updateStartButtonEnabled.bind(this) ); | 45 preset.setting.addChangeListener(this._updateStartButtonEnabled.bind(this) ); |
45 this._showLandingPage(); | 46 this._showLandingPage(); |
47 SDK.targetManager.observeModels(SDK.ServiceWorkerManager, this); | |
48 } | |
49 | |
50 /** | |
51 * @override | |
52 * @param {!SDK.ServiceWorkerManager} serviceWorkerManager | |
53 */ | |
54 modelAdded(serviceWorkerManager) { | |
caseq
2017/05/23 21:44:00
Use SDK.targetManager.addModelListener() instead?
phulce
2017/05/23 22:13:32
Talked to pavel about this too, it's somewhat conv
| |
55 if (this._manager) | |
56 return; | |
57 | |
58 this._manager = serviceWorkerManager; | |
59 this._serviceWorkerListeners = [ | |
60 this._manager.addEventListener( | |
61 SDK.ServiceWorkerManager.Events.RegistrationUpdated, this._updateStart ButtonEnabled, this), | |
62 this._manager.addEventListener( | |
63 SDK.ServiceWorkerManager.Events.RegistrationDeleted, this._updateStart ButtonEnabled, this), | |
64 ]; | |
65 | |
66 this._updateStartButtonEnabled(); | |
67 } | |
68 | |
69 /** | |
70 * @override | |
71 * @param {!SDK.ServiceWorkerManager} serviceWorkerManager | |
72 */ | |
73 modelRemoved(serviceWorkerManager) { | |
74 if (!this._manager || this._manager !== serviceWorkerManager) | |
75 return; | |
76 | |
77 Common.EventTarget.removeEventListeners(this._serviceWorkerListeners); | |
78 this._manager = null; | |
79 this._serviceWorkerListeners = null; | |
80 this._updateStartButtonEnabled(); | |
81 } | |
82 | |
83 /** | |
84 * @return {boolean} | |
85 */ | |
86 _hasActiveServiceWorker() { | |
87 if (!this._manager) | |
88 return false; | |
89 | |
90 var inspectedURL = SDK.targetManager.mainTarget().inspectedURL().asParsedURL (); | |
91 var inspectedOrigin = inspectedURL && inspectedURL.securityOrigin(); | |
92 for (var registration of this._manager.registrations().values()) { | |
93 if (registration.securityOrigin !== inspectedOrigin) | |
94 continue; | |
95 | |
96 for (var version of registration.versions.values()) { | |
97 if (version.controlledClients.length > 1) | |
98 return true; | |
99 } | |
100 } | |
101 | |
102 return false; | |
103 } | |
104 | |
105 /** | |
106 * @return {boolean} | |
107 */ | |
108 _hasAtLeastOneCategory() { | |
109 return Audits2.Audits2Panel.Presets.some(preset => preset.setting.get()); | |
110 } | |
111 | |
112 _updateStartButtonEnabled() { | |
113 var hasActiveServiceWorker = this._hasActiveServiceWorker(); | |
114 var hasAtLeastOneCategory = this._hasAtLeastOneCategory(); | |
115 var isDisabled = hasActiveServiceWorker || !hasAtLeastOneCategory; | |
116 | |
117 if (this._dialogHelpText && hasActiveServiceWorker) { | |
118 this._dialogHelpText.textContent = Common.UIString( | |
119 'Multiple tabs are being controlled by the same service worker. ' + | |
120 'Close your other tabs on the same origin to audit this page.'); | |
121 } | |
122 | |
123 if (this._dialogHelpText && !hasAtLeastOneCategory) | |
124 this._dialogHelpText.textContent = Common.UIString('At least one category must be selected.'); | |
125 | |
126 if (this._dialogHelpText) | |
127 this._dialogHelpText.classList.toggle('hidden', !isDisabled); | |
128 | |
129 if (this._startButton) | |
130 this._startButton.disabled = isDisabled; | |
46 } | 131 } |
47 | 132 |
48 _clearAll() { | 133 _clearAll() { |
49 this._treeOutline.removeChildren(); | 134 this._treeOutline.removeChildren(); |
50 this._showLandingPage(); | 135 this._showLandingPage(); |
51 } | 136 } |
52 | 137 |
53 _deleteSelected() { | 138 _deleteSelected() { |
54 var selection = this._treeOutline.selectedTreeElement; | 139 var selection = this._treeOutline.selectedTreeElement; |
55 if (selection) | 140 if (selection) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 180 |
96 for (var preset of Audits2.Audits2Panel.Presets) { | 181 for (var preset of Audits2.Audits2Panel.Presets) { |
97 preset.setting.setTitle(preset.title); | 182 preset.setting.setTitle(preset.title); |
98 var checkbox = new UI.ToolbarSettingCheckbox(preset.setting); | 183 var checkbox = new UI.ToolbarSettingCheckbox(preset.setting); |
99 var row = this._auditSelectorForm.createChild('div', 'vbox audits2-launche r-row'); | 184 var row = this._auditSelectorForm.createChild('div', 'vbox audits2-launche r-row'); |
100 row.appendChild(checkbox.element); | 185 row.appendChild(checkbox.element); |
101 row.createChild('span', 'audits2-launcher-description dimmed').textContent = preset.description; | 186 row.createChild('span', 'audits2-launcher-description dimmed').textContent = preset.description; |
102 } | 187 } |
103 | 188 |
104 this._statusView = this._createStatusView(uiElement); | 189 this._statusView = this._createStatusView(uiElement); |
190 this._dialogHelpText = uiElement.createChild('div', 'audits2-dialog-help-tex t'); | |
105 | 191 |
106 var buttonsRow = uiElement.createChild('div', 'audits2-dialog-buttons hbox') ; | 192 var buttonsRow = uiElement.createChild('div', 'audits2-dialog-buttons hbox') ; |
107 this._startButton = | 193 this._startButton = |
108 UI.createTextButton(Common.UIString('Run audit'), this._start.bind(this) , 'material-button default'); | 194 UI.createTextButton(Common.UIString('Run audit'), this._start.bind(this) , 'material-button default'); |
109 this._updateStartButtonEnabled(); | 195 this._updateStartButtonEnabled(); |
110 buttonsRow.appendChild(this._startButton); | 196 buttonsRow.appendChild(this._startButton); |
111 this._cancelButton = UI.createTextButton(Common.UIString('Cancel'), this._ca ncel.bind(this), 'material-button'); | 197 this._cancelButton = UI.createTextButton(Common.UIString('Cancel'), this._ca ncel.bind(this), 'material-button'); |
112 buttonsRow.appendChild(this._cancelButton); | 198 buttonsRow.appendChild(this._cancelButton); |
113 | 199 |
114 this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeigh t); | 200 this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeigh t); |
115 this._dialog.setMaxContentSize(new UI.Size(500, 400)); | 201 this._dialog.setMaxContentSize(new UI.Size(500, 400)); |
116 this._dialog.show(this.mainElement()); | 202 this._dialog.show(this.mainElement()); |
117 auditsViewElement.tabIndex = 0; | 203 auditsViewElement.tabIndex = 0; |
118 auditsViewElement.focus(); | 204 auditsViewElement.focus(); |
119 } | 205 } |
120 | 206 |
121 _updateStartButtonEnabled() { | |
122 if (!this._startButton) | |
123 return; | |
124 for (var preset of Audits2.Audits2Panel.Presets) { | |
125 if (preset.setting.get()) { | |
126 this._startButton.disabled = false; | |
127 return; | |
128 } | |
129 } | |
130 this._startButton.disabled = true; | |
131 } | |
132 | |
133 /** | 207 /** |
134 * @param {!Element} launcherUIElement | 208 * @param {!Element} launcherUIElement |
135 * @return {!Element} | 209 * @return {!Element} |
136 */ | 210 */ |
137 _createStatusView(launcherUIElement) { | 211 _createStatusView(launcherUIElement) { |
138 var statusView = launcherUIElement.createChild('div', 'audits2-status vbox h idden'); | 212 var statusView = launcherUIElement.createChild('div', 'audits2-status vbox h idden'); |
139 this._statusIcon = statusView.createChild('div', 'icon'); | 213 this._statusIcon = statusView.createChild('div', 'icon'); |
140 this._statusElement = statusView.createChild('div'); | 214 this._statusElement = statusView.createChild('div'); |
141 this._updateStatus(Common.UIString('Loading...')); | 215 this._updateStatus(Common.UIString('Loading...')); |
142 return statusView; | 216 return statusView; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 return; | 754 return; |
681 | 755 |
682 var element = Components.DOMPresentationUtils.linkifyNodeReference(node, undefined, detailsItem.snippet); | 756 var element = Components.DOMPresentationUtils.linkifyNodeReference(node, undefined, detailsItem.snippet); |
683 origElement.title = ''; | 757 origElement.title = ''; |
684 origElement.textContent = ''; | 758 origElement.textContent = ''; |
685 origElement.appendChild(element); | 759 origElement.appendChild(element); |
686 }); | 760 }); |
687 }); | 761 }); |
688 } | 762 } |
689 }; | 763 }; |
OLD | NEW |