Chromium Code Reviews| 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 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { | 8 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { |
| 9 constructor() { | 9 constructor() { |
| 10 super('audits2'); | 10 super('audits2'); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 * @return {!Element} | 135 * @return {!Element} |
| 136 */ | 136 */ |
| 137 _createStatusView(launcherUIElement) { | 137 _createStatusView(launcherUIElement) { |
| 138 var statusView = launcherUIElement.createChild('div', 'audits2-status vbox h idden'); | 138 var statusView = launcherUIElement.createChild('div', 'audits2-status vbox h idden'); |
| 139 this._statusIcon = statusView.createChild('div', 'icon'); | 139 this._statusIcon = statusView.createChild('div', 'icon'); |
| 140 this._statusElement = statusView.createChild('div'); | 140 this._statusElement = statusView.createChild('div'); |
| 141 this._updateStatus(Common.UIString('Loading...')); | 141 this._updateStatus(Common.UIString('Loading...')); |
| 142 return statusView; | 142 return statusView; |
| 143 } | 143 } |
| 144 | 144 |
| 145 _updateInspectedURL() { | |
|
dgozman
2017/05/22 18:50:34
JSDoc please.
phulce
2017/05/22 19:10:16
Done.
| |
| 146 var mainTarget = SDK.targetManager.mainTarget(); | |
| 147 var runtimeModel = /** @type {!SDK.RuntimeModel} */ (mainTarget.model(SDK.Ru ntimeModel)); | |
|
dgozman
2017/05/22 18:50:34
No need to cast, instead do the following in next
phulce
2017/05/22 19:10:16
Done.
| |
| 148 var executionContext = runtimeModel.defaultExecutionContext(); | |
| 149 if (!executionContext) { | |
| 150 this.inspectedURL = mainTarget.inspectedURL(); | |
|
caseq
2017/05/22 18:53:06
did you mean _inspectedURL?
phulce
2017/05/22 19:10:16
whoops, yes :)
| |
| 151 return; | |
| 152 } | |
| 153 | |
| 154 return new Promise((resolve, reject) => { | |
|
dgozman
2017/05/22 18:50:34
We don't usually reject promises.
phulce
2017/05/22 19:10:16
Gotcha, so we have a general preference to silentl
| |
| 155 executionContext.evaluate('window.location.href', 'audits', false, false, true, false, false, (object, err) => { | |
| 156 if (err || !object) | |
| 157 return reject(err || new Error('Failed to retrieve page URL')); | |
|
dgozman
2017/05/22 18:50:34
Just resolve with mainTarget.inspectedURL()
phulce
2017/05/22 19:10:16
Done.
| |
| 158 this._inspectedURL = object.value; | |
| 159 resolve(); | |
| 160 }); | |
| 161 }); | |
| 162 } | |
| 163 | |
| 145 _start() { | 164 _start() { |
| 146 var emulationModel = self.singleton(Emulation.DeviceModeModel); | 165 var emulationModel = self.singleton(Emulation.DeviceModeModel); |
| 147 this._emulationEnabledBefore = emulationModel.enabledSetting().get(); | 166 this._emulationEnabledBefore = emulationModel.enabledSetting().get(); |
| 148 this._emulationOutlineEnabledBefore = emulationModel.deviceOutlineSetting(). get(); | 167 this._emulationOutlineEnabledBefore = emulationModel.deviceOutlineSetting(). get(); |
| 149 emulationModel.enabledSetting().set(true); | 168 emulationModel.enabledSetting().set(true); |
| 150 emulationModel.deviceOutlineSetting().set(true); | 169 emulationModel.deviceOutlineSetting().set(true); |
| 151 emulationModel.toolbarControlsEnabledSetting().set(false); | 170 emulationModel.toolbarControlsEnabledSetting().set(false); |
| 152 | 171 |
| 153 for (var device of Emulation.EmulatedDevicesList.instance().standard()) { | 172 for (var device of Emulation.EmulatedDevicesList.instance().standard()) { |
| 154 if (device.title === 'Nexus 5X') | 173 if (device.title === 'Nexus 5X') |
| 155 emulationModel.emulate(Emulation.DeviceModeModel.Type.Device, device, de vice.modes[0], 1); | 174 emulationModel.emulate(Emulation.DeviceModeModel.Type.Device, device, de vice.modes[0], 1); |
| 156 } | 175 } |
| 157 this._dialog.setCloseOnEscape(false); | 176 this._dialog.setCloseOnEscape(false); |
| 158 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); | |
| 159 | 177 |
| 160 var categoryIDs = []; | 178 var categoryIDs = []; |
| 161 for (var preset of Audits2.Audits2Panel.Presets) { | 179 for (var preset of Audits2.Audits2Panel.Presets) { |
| 162 if (preset.setting.get()) | 180 if (preset.setting.get()) |
| 163 categoryIDs.push(preset.configID); | 181 categoryIDs.push(preset.configID); |
| 164 } | 182 } |
| 165 | 183 |
| 166 return Promise.resolve() | 184 return Promise.resolve() |
| 185 .then(_ => this._updateInspectedURL()) | |
| 167 .then(_ => this._protocolService.attach()) | 186 .then(_ => this._protocolService.attach()) |
| 168 .then(_ => { | 187 .then(_ => { |
| 169 this._auditRunning = true; | 188 this._auditRunning = true; |
| 170 this._updateButton(); | 189 this._updateButton(); |
| 171 this._updateStatus(Common.UIString('Loading\u2026')); | 190 this._updateStatus(Common.UIString('Loading\u2026')); |
| 172 }) | 191 }) |
| 173 .then(_ => this._protocolService.startLighthouse(this._inspectedURL, cat egoryIDs)) | 192 .then(_ => this._protocolService.startLighthouse(this._inspectedURL, cat egoryIDs)) |
| 174 .then(lighthouseResult => { | 193 .then(lighthouseResult => { |
| 175 if (lighthouseResult && lighthouseResult.fatal) { | 194 if (lighthouseResult && lighthouseResult.fatal) { |
| 176 const error = new Error(lighthouseResult.message); | 195 const error = new Error(lighthouseResult.message); |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 return; | 676 return; |
| 658 | 677 |
| 659 var element = Components.DOMPresentationUtils.linkifyNodeReference(node, undefined, detailsItem.snippet); | 678 var element = Components.DOMPresentationUtils.linkifyNodeReference(node, undefined, detailsItem.snippet); |
| 660 origElement.title = ''; | 679 origElement.title = ''; |
| 661 origElement.textContent = ''; | 680 origElement.textContent = ''; |
| 662 origElement.appendChild(element); | 681 origElement.appendChild(element); |
| 663 }); | 682 }); |
| 664 }); | 683 }); |
| 665 } | 684 } |
| 666 }; | 685 }; |
| OLD | NEW |