Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 Timeline.Perspective = class { | |
| 6 /** | |
| 7 * @param {string} id | |
| 8 * @param {string} title | |
| 9 * @param {string} description | |
| 10 * @param {!Array<string>=} visibleOptions | |
| 11 */ | |
| 12 constructor(id, title, description, visibleOptions) { | |
| 13 this.id = id; | |
| 14 this.title = title; | |
| 15 this.description = description; | |
| 16 /** @type {!Object<string, !Timeline.Perspective.Config>} */ | |
| 17 this.settings = { | |
|
caseq
2016/12/07 20:17:29
Why do we make the base class aware of all possibl
alph
2016/12/08 07:22:45
Done.
| |
| 18 'network': { | |
| 19 value: false, | |
| 20 title: Common.UIString('Network'), | |
| 21 description: Common.UIString('Capture network requests information.'), | |
| 22 setting: 'timelineCaptureNetwork' | |
|
caseq
2016/12/07 20:17:29
I wonder whether we should better use actual insta
alph
2016/12/08 07:22:45
I want it to be a config template. No objects allo
| |
| 23 }, | |
| 24 'javascript': { | |
| 25 value: true, | |
| 26 title: Common.UIString('JavaScript'), | |
| 27 description: Common.UIString('Use sampling CPU profiler to collect JavaS cript stacks.'), | |
| 28 setting: 'timelineEnableJSSampling' | |
| 29 }, | |
| 30 'screenshots': { | |
| 31 value: false, | |
| 32 title: Common.UIString('Screenshots'), | |
| 33 description: | |
| 34 Common.UIString('Collect page screenshots, so you can observe how th e page was evolving during recording.'), | |
| 35 setting: 'timelineCaptureFilmStrip' | |
| 36 }, | |
| 37 'paints': { | |
| 38 value: false, | |
| 39 title: Common.UIString('Paints'), | |
| 40 description: Common.UIString( | |
| 41 'Capture graphics layer positions and rasterization draw calls (mode rate performance overhead).'), | |
| 42 setting: 'timelineCaptureLayersAndPictures' | |
| 43 }, | |
| 44 'memory': { | |
| 45 value: true, | |
| 46 title: Common.UIString('Memory'), | |
| 47 description: Common.UIString('Capture memory information on every timeli ne event.'), | |
| 48 setting: 'timelineCaptureMemory' | |
| 49 }, | |
| 50 'reload': { | |
| 51 value: false, | |
| 52 title: Common.UIString('Auto Reload'), | |
| 53 description: Common.UIString('Automatically reload page when recoring ha s started.') | |
| 54 } | |
| 55 }; | |
| 56 this._visibleOptions = visibleOptions || []; | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * @param {!Element} parent | |
| 61 */ | |
| 62 appendElements(parent) { | |
| 63 for (let id of this._visibleOptions) { | |
| 64 const config = this.settings[id]; | |
| 65 this._createSettingCheckBox(parent, id, config); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 /** | |
| 70 * @param {!Element} parent | |
| 71 * @param {string} id | |
| 72 * @param {!Timeline.Perspective.Config} config | |
| 73 */ | |
| 74 _createSettingCheckBox(parent, id, config) { | |
| 75 const setting = config.setting ? Common.settings.createSetting(config.settin g, config.value) : null; | |
| 76 const div = parent.createChild('div', 'recording-setting'); | |
| 77 const checkbox = div.createChild('input'); | |
| 78 checkbox.setAttribute('type', 'checkbox'); | |
| 79 checkbox.setAttribute('id', id); | |
| 80 if (setting ? setting.get() : config.value) | |
| 81 checkbox.setAttribute('checked', true); | |
| 82 if (setting) | |
| 83 checkbox.addEventListener('change', event => setting.set(event.target.chec ked)); | |
| 84 const label = div.createChild('label'); | |
| 85 label.setAttribute('for', id); | |
| 86 label.textContent = config.title; | |
| 87 if (config.description) | |
| 88 div.createChild('div', 'recording-setting-description').textContent = conf ig.description; | |
| 89 } | |
| 90 | |
| 91 action() { | |
| 92 UI.actionRegistry.action('timeline.toggle-recording').execute(); | |
| 93 } | |
| 94 }; | |
| 95 | |
| 96 /** @typedef {!{value: boolean, title: string, description: string, setting: ?st ring}} */ | |
| 97 Timeline.Perspective.Config; | |
| 98 | |
| 99 Timeline.LoadPerspective = class extends Timeline.Perspective { | |
| 100 constructor() { | |
| 101 super( | |
| 102 Timeline.TimelinePanel.Perspectives.Load, Common.UIString('Page Load'), | |
| 103 Common.UIString( | |
| 104 'Page Load mode allows you to analyze how fast the page is loaded an d becomes responsive.\n' + | |
| 105 'In this mode the page is automatically reloaded right after the rec ording has started. ' + | |
| 106 'During recording it collects information about network requests, sc reen state updates, ' + | |
| 107 'and CPU threads acivity along with JavaScript stacks. ' + | |
| 108 'Recording is stopped automatically shortly after the page processes load event.'), | |
| 109 ['screenshots']); | |
| 110 this.settings.network.value = true; | |
| 111 this.settings.reload.value = true; | |
| 112 this.settings.screenshots.value = true; | |
| 113 } | |
| 114 | |
| 115 /** | |
| 116 * @override | |
| 117 */ | |
| 118 action() { | |
| 119 SDK.targetManager.reloadPage(); | |
| 120 } | |
| 121 }; | |
| 122 | |
| 123 Timeline.ResponsivenessPerspective = class extends Timeline.Perspective { | |
| 124 constructor() { | |
| 125 super( | |
| 126 Timeline.TimelinePanel.Perspectives.Responsiveness, Common.UIString('Res ponsiveness'), | |
| 127 Common.UIString('Record page responsiveness.'), ['screenshots']); | |
| 128 this.settings.network.value = true; | |
| 129 } | |
| 130 }; | |
| 131 | |
| 132 Timeline.JavaScriptPerspective = class extends Timeline.Perspective { | |
| 133 constructor() { | |
| 134 super( | |
| 135 Timeline.TimelinePanel.Perspectives.JavaScript, Common.UIString('JavaScr ipt'), | |
| 136 Common.UIString('Record JavaScript execution profile.')); | |
| 137 } | |
| 138 }; | |
| 139 | |
| 140 Timeline.CustomPerspective = class extends Timeline.Perspective { | |
| 141 constructor() { | |
| 142 super( | |
| 143 Timeline.TimelinePanel.Perspectives.Custom, Common.UIString('Custom'), | |
| 144 Common.UIString('Advanced mode that allows you to customize recording op tions.'), | |
| 145 ['network', 'javascript', 'screenshots', 'memory', 'paints']); | |
| 146 } | |
| 147 }; | |
| 148 | |
| 149 Timeline.LandingPage = class extends UI.VBox { | |
| 150 constructor() { | |
| 151 super(true); | |
| 152 this.registerRequiredCSS('ui_lazy/dialog.css'); | |
| 153 this.registerRequiredCSS('timeline/timelineLandingPage.css'); | |
| 154 this.contentElement.classList.add('timeline-landing-page', 'fill'); | |
| 155 const headerDiv = this.contentElement.createChild('div', 'timeline-perspecti ve-header-bar'); | |
| 156 this._perspectiveSetting = Common.settings.createSetting('timelinePerspectiv e', 'load'); | |
| 157 this._perspectiveSetting.addChangeListener(this._updatePerspective, this); | |
| 158 | |
| 159 this._perspectives = [ | |
| 160 Timeline.LoadPerspective, Timeline.ResponsivenessPerspective, Timeline.Jav aScriptPerspective, | |
| 161 Timeline.CustomPerspective | |
| 162 ].map(cls => new cls()); | |
|
caseq
2016/12/07 20:17:29
let's just call constructors expecitly.
alph
2016/12/08 07:22:45
Done.
| |
| 163 this._inputByPerspective = new Map(); | |
| 164 for (const perspective of this._perspectives) { | |
| 165 const div = headerDiv.createChild('div', 'timeline-perspective-header'); | |
|
caseq
2016/12/07 20:17:29
Does this fail gracefully when the window is too n
alph
2016/12/08 07:22:45
Done.
| |
| 166 const input = div.createChild('input'); | |
| 167 input.setAttribute('type', 'radio'); | |
| 168 input.setAttribute('name', 'perspective-select'); | |
| 169 input.setAttribute('id', perspective.id); | |
| 170 input.setAttribute('value', perspective.id); | |
| 171 input.addEventListener('change', event => this._perspectiveSetting.set(eve nt.target.id)); | |
| 172 const label = div.createChild('label'); | |
| 173 label.setAttribute('for', perspective.id); | |
| 174 label.textContent = perspective.title; | |
| 175 if (perspective.id === this._perspectiveSetting.get()) | |
| 176 input.checked = true; | |
| 177 this._inputByPerspective.set(perspective.id, input); | |
| 178 } | |
| 179 | |
| 180 this._bodyDiv = this.contentElement.createChild('div', 'timeline-perspective -body'); | |
| 181 const footer = this.contentElement.createChild('div', 'timeline-perspective- footer'); | |
| 182 const actionButton = footer.createChild('button'); | |
| 183 actionButton.textContent = Common.UIString('Start'); | |
| 184 actionButton.addEventListener('click', this._onAction.bind(this)); | |
| 185 this._updatePerspective(); | |
| 186 } | |
| 187 | |
| 188 dispose() { | |
| 189 this._perspectiveSetting.removeChangeListener(this._updatePerspective, this) ; | |
|
caseq
2016/12/07 20:17:29
why do you need it?
alph
2016/12/08 07:22:45
Done.
| |
| 190 } | |
| 191 | |
| 192 /** | |
| 193 * @return {!Timeline.Perspective} | |
| 194 */ | |
| 195 _currentPerspective() { | |
| 196 const id = this._perspectiveSetting.get(); | |
| 197 return this._perspectives.find(p => p.id === id) || this._perspectives[0]; | |
| 198 } | |
| 199 | |
| 200 _updatePerspective() { | |
| 201 const perspective = this._currentPerspective(); | |
| 202 const input = this._inputByPerspective.get(perspective.id); | |
| 203 if (input && !input.checked) | |
| 204 input.checked = true; | |
| 205 this._bodyDiv.removeChildren(); | |
| 206 this._bodyDiv.createChild('div', 'timeline-perspective-description').textCon tent = perspective.description; | |
| 207 perspective.appendElements(this._bodyDiv); | |
| 208 } | |
| 209 | |
| 210 _onAction() { | |
| 211 this._currentPerspective().action(); | |
| 212 } | |
| 213 }; | |
| OLD | NEW |