2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.VBox}
34 * @implements {WebInspector.TargetManager.Observer}
35 * @param {!WebInspector.ProfilesPanel} profilesPanel
37 WebInspector.ProfileLauncherView = function(profilesPanel)
39 WebInspector.VBox.call(this);
41 this._panel = profilesPanel;
43 this.element.classList.add("profile-launcher-view");
44 this.element.classList.add("panel-enabler-view");
46 this._contentElement = this.element.createChild("div", "profile-launcher-view-content");
47 this._innerContentElement = this._contentElement.createChild("div");
48 var targetSpan = this._contentElement.createChild("span");
49 var selectTargetText = targetSpan.createChild("span");
50 selectTargetText.textContent = WebInspector.UIString("Target:");
51 var targetsSelect = targetSpan.createChild("select", "chrome-select");
52 new WebInspector.TargetsComboBoxController(targetsSelect, targetSpan);
53 this._controlButton = this._contentElement.createChild("button", "text-button control-profiling");
54 this._controlButton.addEventListener("click", this._controlButtonClicked.bind(this), false);
55 this._recordButtonEnabled = true;
56 this._loadButton = this._contentElement.createChild("button", "text-button load-profile");
57 this._loadButton.textContent = WebInspector.UIString("Load");
58 this._loadButton.addEventListener("click", this._loadButtonClicked.bind(this), false);
59 WebInspector.targetManager.observeTargets(this);
62 WebInspector.ProfileLauncherView.prototype = {
64 * @param {!WebInspector.Target} target
66 targetAdded: function(target)
68 this._updateLoadButtonLayout();
72 * @param {!WebInspector.Target} target
74 targetRemoved: function(target)
76 this._updateLoadButtonLayout();
79 _updateLoadButtonLayout: function()
81 this._loadButton.classList.toggle("multi-target", WebInspector.targetManager.targets().length > 1);
85 * @param {!WebInspector.ProfileType} profileType
87 addProfileType: function(profileType)
89 var descriptionElement = this._innerContentElement.createChild("h1");
90 descriptionElement.textContent = profileType.description;
91 var decorationElement = profileType.decorationElement();
92 if (decorationElement)
93 this._innerContentElement.appendChild(decorationElement);
94 this._isInstantProfile = profileType.isInstantProfile();
95 this._isEnabled = profileType.isEnabled();
96 this._profileTypeId = profileType.id;
99 _controlButtonClicked: function()
101 this._panel.toggleRecordButton();
104 _loadButtonClicked: function()
106 this._panel.showLoadFromFileDialog();
109 _updateControls: function()
111 if (this._isEnabled && this._recordButtonEnabled)
112 this._controlButton.removeAttribute("disabled");
114 this._controlButton.setAttribute("disabled", "");
115 this._controlButton.title = this._recordButtonEnabled ? "" : WebInspector.anotherProfilerActiveLabel();
116 if (this._isInstantProfile) {
117 this._controlButton.classList.remove("running");
118 this._controlButton.textContent = WebInspector.UIString("Take Snapshot");
119 } else if (this._isProfiling) {
120 this._controlButton.classList.add("running");
121 this._controlButton.textContent = WebInspector.UIString("Stop");
123 this._controlButton.classList.remove("running");
124 this._controlButton.textContent = WebInspector.UIString("Start");
128 profileStarted: function()
130 this._isProfiling = true;
131 this._updateControls();
134 profileFinished: function()
136 this._isProfiling = false;
137 this._updateControls();
141 * @param {!WebInspector.ProfileType} profileType
142 * @param {boolean} recordButtonEnabled
144 updateProfileType: function(profileType, recordButtonEnabled)
146 this._isInstantProfile = profileType.isInstantProfile();
147 this._recordButtonEnabled = recordButtonEnabled;
148 this._isEnabled = profileType.isEnabled();
149 this._profileTypeId = profileType.id;
150 this._updateControls();
153 __proto__: WebInspector.VBox.prototype
159 * @extends {WebInspector.ProfileLauncherView}
160 * @param {!WebInspector.ProfilesPanel} profilesPanel
162 WebInspector.MultiProfileLauncherView = function(profilesPanel)
164 WebInspector.ProfileLauncherView.call(this, profilesPanel);
166 WebInspector.settings.selectedProfileType = WebInspector.settings.createSetting("selectedProfileType", "CPU");
168 var header = this._innerContentElement.createChild("h1");
169 header.textContent = WebInspector.UIString("Select profiling type");
171 this._profileTypeSelectorForm = this._innerContentElement.createChild("form");
173 this._innerContentElement.createChild("div", "flexible-space");
175 this._typeIdToOptionElement = {};
178 WebInspector.MultiProfileLauncherView.EventTypes = {
179 ProfileTypeSelected: "profile-type-selected"
182 WebInspector.MultiProfileLauncherView.prototype = {
185 * @param {!WebInspector.ProfileType} profileType
187 addProfileType: function(profileType)
189 var labelElement = this._profileTypeSelectorForm.createChild("label");
190 labelElement.textContent = profileType.name;
191 var optionElement = document.createElement("input");
192 labelElement.insertBefore(optionElement, labelElement.firstChild);
193 this._typeIdToOptionElement[profileType.id] = optionElement;
194 optionElement._profileType = profileType;
195 optionElement.type = "radio";
196 optionElement.name = "profile-type";
197 optionElement.style.hidden = true;
198 optionElement.addEventListener("change", this._profileTypeChanged.bind(this, profileType), false);
199 var descriptionElement = labelElement.createChild("p");
200 descriptionElement.textContent = profileType.description;
201 var decorationElement = profileType.decorationElement();
202 if (decorationElement)
203 labelElement.appendChild(decorationElement);
206 restoreSelectedProfileType: function()
208 var typeId = WebInspector.settings.selectedProfileType.get();
209 if (!(typeId in this._typeIdToOptionElement))
210 typeId = Object.keys(this._typeIdToOptionElement)[0];
211 this._typeIdToOptionElement[typeId].checked = true;
212 var type = this._typeIdToOptionElement[typeId]._profileType;
213 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.EventTypes.ProfileTypeSelected, type);
216 _controlButtonClicked: function()
218 this._panel.toggleRecordButton();
221 _updateControls: function()
223 WebInspector.ProfileLauncherView.prototype._updateControls.call(this);
224 var items = this._profileTypeSelectorForm.elements;
225 for (var i = 0; i < items.length; ++i) {
226 if (items[i].type === "radio")
227 items[i].disabled = this._isProfiling;
232 * @param {!WebInspector.ProfileType} profileType
234 _profileTypeChanged: function(profileType)
236 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.EventTypes.ProfileTypeSelected, profileType);
237 this._isInstantProfile = profileType.isInstantProfile();
238 this._isEnabled = profileType.isEnabled();
239 this._profileTypeId = profileType.id;
240 this._updateControls();
241 WebInspector.settings.selectedProfileType.set(profileType.id);
244 profileStarted: function()
246 this._isProfiling = true;
247 this._updateControls();
250 profileFinished: function()
252 this._isProfiling = false;
253 this._updateControls();
256 __proto__: WebInspector.ProfileLauncherView.prototype