Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
pfeldman
2016/12/10 00:05:20
The class name should match the file name. You def
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** @typedef {!{id: string, title: string, description: string, setting: string} } */ | |
| 6 Timeline.RecordingOption; | |
| 7 | |
| 8 /** @type {!Object<string, !Timeline.RecordingOption>} */ | |
| 9 Timeline.RecordingConfig = { | |
| 10 network: { | |
| 11 id: 'network', | |
| 12 title: Common.UIString('Network'), | |
| 13 description: Common.UIString('Capture network requests information.'), | |
| 14 setting: 'timelineCaptureNetwork' | |
| 15 }, | |
| 16 javascript: { | |
| 17 id: 'javascript', | |
| 18 title: Common.UIString('JavaScript'), | |
| 19 description: Common.UIString('Use sampling CPU profiler to collect JavaScrip t stacks.'), | |
| 20 setting: 'timelineEnableJSSampling' | |
| 21 }, | |
| 22 screenshots: { | |
| 23 id: 'screenshots', | |
| 24 title: Common.UIString('Screenshots'), | |
| 25 description: | |
| 26 Common.UIString('Collect page screenshots, so you can observe how the pa ge was evolving during recording.'), | |
| 27 setting: 'timelineCaptureFilmStrip' | |
| 28 }, | |
| 29 paints: { | |
| 30 id: 'paints', | |
| 31 title: Common.UIString('Paints'), | |
| 32 description: Common.UIString( | |
| 33 'Capture graphics layer positions and rasterization draw calls (moderate performance overhead).'), | |
| 34 setting: 'timelineCaptureLayersAndPictures' | |
| 35 }, | |
| 36 memory: { | |
| 37 id: 'memory', | |
| 38 title: Common.UIString('Memory'), | |
| 39 description: Common.UIString('Capture memory statistics on every timeline ev ent.'), | |
| 40 setting: 'timelineCaptureMemory' | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 Timeline.Perspective = class extends UI.VBox { | |
|
pfeldman
2016/12/10 00:05:20
...TabWidget?
| |
| 45 /** | |
| 46 * @param {string} description | |
| 47 * @param {!Array<!Timeline.RecordingOption>=} visibleOptions | |
| 48 * @param {!Array<!Timeline.RecordingOption>=} enabledOptions | |
| 49 */ | |
| 50 constructor(description, visibleOptions, enabledOptions) { | |
| 51 super(false); | |
| 52 enabledOptions = enabledOptions || []; | |
| 53 this._enabledOptions = new Set(enabledOptions.map(option => option.id)); | |
| 54 this._enabledOptions.add(Timeline.RecordingConfig.javascript.id); | |
| 55 this.contentElement.classList.add('timeline-perspective-body'); | |
| 56 this.contentElement.createChild('div', 'timeline-perspective-description').t extContent = description; | |
| 57 for (const config of visibleOptions || []) | |
| 58 this._createSettingCheckBox(this.contentElement, config); | |
| 59 const actionButton = this.contentElement.createChild('div').createChild('but ton', 'action-button'); | |
| 60 actionButton.textContent = Common.UIString('Start'); | |
| 61 actionButton.addEventListener('click', () => this.action()); | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * @param {!Element} parent | |
| 66 * @param {!Timeline.RecordingOption} config | |
| 67 */ | |
| 68 _createSettingCheckBox(parent, config) { | |
| 69 const div = parent.createChild('div', 'recording-setting'); | |
| 70 const value = this._enabledOptions.has(config.id); | |
| 71 const setting = Common.settings.createSetting(config.setting, value); | |
| 72 div.appendChild(UI.SettingsUI.createSettingCheckbox(config.title, setting, t rue)); | |
| 73 if (config.description) | |
| 74 div.createChild('div', 'recording-setting-description').textContent = conf ig.description; | |
| 75 } | |
| 76 | |
| 77 activate() { | |
| 78 for (let id in Timeline.RecordingConfig) { | |
| 79 const config = Timeline.RecordingConfig[id]; | |
| 80 const setting = Common.settings.createSetting(config.setting, false); | |
| 81 setting.set(this._enabledOptions.has(id)); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 action() { | |
| 86 UI.actionRegistry.action('timeline.toggle-recording').execute(); | |
| 87 } | |
| 88 }; | |
| 89 | |
| 90 Timeline.LoadPerspective = class extends Timeline.Perspective { | |
|
pfeldman
2016/12/10 00:05:20
Inheritance should be out last resort, you don't n
| |
| 91 constructor() { | |
| 92 const config = Timeline.RecordingConfig; | |
| 93 super( | |
| 94 Common.UIString( | |
| 95 'Page Load mode allows you to analyze how fast the page is loaded an d becomes responsive.\n' + | |
| 96 'In this mode the page is automatically reloaded right after the rec ording has started. ' + | |
| 97 'During recording it collects information about network requests, sc reen state updates, ' + | |
| 98 'and CPU threads acivity along with JavaScript stacks. ' + | |
| 99 'Recording is stopped automatically shortly after the page processes load event.'), | |
| 100 [config.screenshots], [config.network, config.screenshots]); | |
| 101 } | |
| 102 | |
| 103 /** | |
| 104 * @override | |
| 105 */ | |
| 106 action() { | |
| 107 SDK.targetManager.reloadPage(); | |
| 108 } | |
| 109 }; | |
| 110 | |
| 111 Timeline.ResponsivenessPerspective = class extends Timeline.Perspective { | |
| 112 constructor() { | |
| 113 const config = Timeline.RecordingConfig; | |
| 114 super(Common.UIString('Record page responsiveness.'), [config.screenshots], [config.network]); | |
| 115 } | |
| 116 }; | |
| 117 | |
| 118 Timeline.JavaScriptPerspective = class extends Timeline.Perspective { | |
| 119 constructor() { | |
| 120 super(Common.UIString( | |
| 121 'This mode is useful when you want to focus on JavaScript performance. ' + | |
| 122 'All the options besides sampling CPU profiler are turned off to minimiz e measurement errors.')); | |
| 123 } | |
| 124 }; | |
| 125 | |
| 126 Timeline.CustomPerspective = class extends Timeline.Perspective { | |
| 127 constructor() { | |
| 128 const config = Timeline.RecordingConfig; | |
| 129 super( | |
| 130 Common.UIString('Advanced mode that allows you to customize recording op tions.'), | |
| 131 [config.network, config.javascript, config.screenshots, config.memory, c onfig.paints], | |
| 132 [config.network, config.screenshots]); | |
| 133 } | |
| 134 }; | |
| 135 | |
| 136 Timeline.LandingPage = class extends UI.VBox { | |
| 137 constructor() { | |
| 138 super(true); | |
| 139 this.registerRequiredCSS('timeline/timelineLandingPage.css'); | |
| 140 this.contentElement.classList.add('timeline-landing-page', 'fill'); | |
| 141 const perspectives = Timeline.TimelinePanel.Perspectives; | |
| 142 this._tabbedPane = new UI.TabbedPane(); | |
| 143 this._tabbedPane.registerRequiredCSS('timeline/timelineLandingPage.css'); | |
|
pfeldman
2016/12/10 00:05:20
We should not abuse tabbed pane and style it exter
| |
| 144 this._tabbedPane.registerRequiredCSS('ui_lazy/dialog.css'); | |
|
pfeldman
2016/12/10 00:05:20
ditto
| |
| 145 this._tabbedPane.contentElement.classList.add('timeline-landing-page'); | |
|
pfeldman
2016/12/10 00:05:20
Also don't
| |
| 146 this._tabbedPane.setTabSlider(true); | |
| 147 this._tabbedPane.appendTab(perspectives.Load, Common.UIString('Page Load'), new Timeline.LoadPerspective()); | |
| 148 this._tabbedPane.appendTab( | |
| 149 perspectives.Responsiveness, Common.UIString('Responsiveness'), new Time line.ResponsivenessPerspective()); | |
| 150 this._tabbedPane.appendTab( | |
| 151 perspectives.JavaScript, Common.UIString('JavaScript'), new Timeline.Jav aScriptPerspective()); | |
| 152 this._tabbedPane.appendTab(perspectives.Custom, Common.UIString('Custom'), n ew Timeline.CustomPerspective()); | |
| 153 this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabSelected, this._ta bSelected, this); | |
| 154 this._tabbedPane.show(this.contentElement); | |
| 155 this._perspectiveSetting = | |
| 156 Common.settings.createSetting('timelinePerspective', Timeline.TimelinePa nel.Perspectives.Load); | |
| 157 this._perspectiveSetting.addChangeListener(this._perspectiveChanged, this); | |
| 158 } | |
| 159 | |
| 160 /** | |
| 161 * @param {!Common.Event} event | |
| 162 */ | |
| 163 _tabSelected(event) { | |
| 164 if (this._perspectiveSetting.get() !== event.data.tabId) | |
| 165 this._perspectiveSetting.set(event.data.tabId); | |
| 166 } | |
| 167 | |
| 168 _perspectiveChanged() { | |
| 169 this._tabbedPane.selectTab(this._perspectiveSetting.get()); | |
| 170 const perspective = /** @type {!Timeline.Perspective} */ (this._tabbedPane.v isibleView); | |
| 171 perspective.activate(); | |
| 172 } | |
| 173 }; | |
| OLD | NEW |