browser/devtools/profiler/sidebar.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 let { Cu } = require("chrome");
michael@0 8 let EventEmitter = require("devtools/toolkit/event-emitter");
michael@0 9
michael@0 10 Cu.import("resource:///modules/devtools/SideMenuWidget.jsm");
michael@0 11 Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
michael@0 12
michael@0 13 const {
michael@0 14 PROFILE_IDLE,
michael@0 15 PROFILE_COMPLETED,
michael@0 16 PROFILE_RUNNING,
michael@0 17 L10N_BUNDLE
michael@0 18 } = require("devtools/profiler/consts");
michael@0 19
michael@0 20 loader.lazyGetter(this, "L10N", () => new ViewHelpers.L10N(L10N_BUNDLE));
michael@0 21
michael@0 22 let stopProfilingString = L10N.getStr("profiler.stopProfilerString");
michael@0 23 let startProfilingString = L10N.getStr("profiler.startProfilerString");
michael@0 24
michael@0 25 function Sidebar(el) {
michael@0 26 EventEmitter.decorate(this);
michael@0 27
michael@0 28 this.document = el.ownerDocument;
michael@0 29 this.widget = new SideMenuWidget(el, { showArrows: true });
michael@0 30 this.emptyText = L10N.getStr("profiler.sidebarNotice");
michael@0 31
michael@0 32 this.widget.addEventListener("select", (ev) => {
michael@0 33 if (!ev.detail)
michael@0 34 return;
michael@0 35
michael@0 36 this.emit("select", parseInt(ev.detail.value, 10));
michael@0 37 });
michael@0 38 }
michael@0 39
michael@0 40 Sidebar.prototype = Heritage.extend(WidgetMethods, {
michael@0 41 /**
michael@0 42 * Adds a new item for a profile to the sidebar. Markup
michael@0 43 * example:
michael@0 44 *
michael@0 45 * <vbox id="profile-1" class="profiler-sidebar-item">
michael@0 46 * <h3>Profile 1</h3>
michael@0 47 * <hbox>
michael@0 48 * <span flex="1">Completed</span>
michael@0 49 * <a>Save</a>
michael@0 50 * </hbox>
michael@0 51 * </vbox>
michael@0 52 *
michael@0 53 */
michael@0 54 addProfile: function (profile) {
michael@0 55 let doc = this.document;
michael@0 56 let vbox = doc.createElement("vbox");
michael@0 57 let hbox = doc.createElement("hbox");
michael@0 58 let h3 = doc.createElement("h3");
michael@0 59 let span = doc.createElement("span");
michael@0 60 let save = doc.createElement("a");
michael@0 61
michael@0 62 vbox.id = "profile-" + profile.uid;
michael@0 63 vbox.className = "profiler-sidebar-item";
michael@0 64
michael@0 65 h3.textContent = profile.name;
michael@0 66 span.setAttribute("flex", 1);
michael@0 67 span.textContent = L10N.getStr("profiler.stateIdle");
michael@0 68
michael@0 69 save.textContent = L10N.getStr("profiler.save");
michael@0 70 save.addEventListener("click", (ev) => {
michael@0 71 ev.preventDefault();
michael@0 72 this.emit("save", profile.uid);
michael@0 73 });
michael@0 74
michael@0 75 hbox.appendChild(span);
michael@0 76 hbox.appendChild(save);
michael@0 77
michael@0 78 vbox.appendChild(h3);
michael@0 79 vbox.appendChild(hbox);
michael@0 80
michael@0 81 this.push([vbox, profile.uid], {
michael@0 82 attachment: {
michael@0 83 name: profile.name,
michael@0 84 state: PROFILE_IDLE
michael@0 85 }
michael@0 86 });
michael@0 87 },
michael@0 88
michael@0 89 getElementByProfile: function (profile) {
michael@0 90 return this.document.querySelector("#profile-" + profile.uid);
michael@0 91 },
michael@0 92
michael@0 93 getItemByProfile: function (profile) {
michael@0 94 return this.getItemByValue(profile.uid.toString());
michael@0 95 },
michael@0 96
michael@0 97 setProfileState: function (profile, state) {
michael@0 98 let item = this.getItemByProfile(profile);
michael@0 99 let doc = this.document;
michael@0 100 let label = item.target.querySelector(".profiler-sidebar-item > hbox > span");
michael@0 101 let toggleButton = doc.getElementById("profiler-start");
michael@0 102
michael@0 103 switch (state) {
michael@0 104 case PROFILE_IDLE:
michael@0 105 item.target.setAttribute("state", "idle");
michael@0 106 label.textContent = L10N.getStr("profiler.stateIdle");
michael@0 107 break;
michael@0 108 case PROFILE_RUNNING:
michael@0 109 item.target.setAttribute("state", "running");
michael@0 110 label.textContent = L10N.getStr("profiler.stateRunning");
michael@0 111 toggleButton.setAttribute("tooltiptext",stopProfilingString);
michael@0 112 break;
michael@0 113 case PROFILE_COMPLETED:
michael@0 114 item.target.setAttribute("state", "completed");
michael@0 115 label.textContent = L10N.getStr("profiler.stateCompleted");
michael@0 116 toggleButton.setAttribute("tooltiptext",startProfilingString);
michael@0 117 break;
michael@0 118 default: // Wrong state, do nothing.
michael@0 119 return;
michael@0 120 }
michael@0 121
michael@0 122 item.attachment.state = state;
michael@0 123 this.emit("stateChanged", item);
michael@0 124 }
michael@0 125 });
michael@0 126
michael@0 127 module.exports = Sidebar;

mercurial