Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: Source/devtools/front_end/promises/PromisesPanel.js

Issue 603623002: Rename PromisesPanel to PromisePane. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: REBASE Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 /**
6 * @constructor
7 * @extends {WebInspector.VBox}
8 */
9 WebInspector.PromisesPanel = function()
10 {
11 WebInspector.VBox.call(this);
12 this.registerRequiredCSS("promises/promisesPanel.css");
13 this.element.classList.add("promises");
14
15 var statusBar = this.element.createChild("div", "panel-status-bar");
16 this._recordButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Record Promises"), "record-profile-status-bar-item");
17 this._recordButton.addEventListener("click", this._recordButtonClicked.bind( this));
18 statusBar.appendChild(this._recordButton.element);
19 var clearButton = new WebInspector.StatusBarButton(WebInspector.UIString("Cl ear"), "clear-status-bar-item");
20 clearButton.addEventListener("click", this._clearButtonClicked.bind(this));
21 statusBar.appendChild(clearButton.element);
22 this._refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString ("Refresh"), "refresh-storage-status-bar-item");
23 this._refreshButton.addEventListener("click", this._refreshButtonClicked.bin d(this));
24 this._refreshButton.setEnabled(false);
25 statusBar.appendChild(this._refreshButton.element);
26 this._liveCheckbox = new WebInspector.StatusBarCheckbox(WebInspector.UIStrin g("Live"));
27 this._liveCheckbox.element.title = WebInspector.UIString("Live Recording");
28 this._liveCheckbox.inputElement.disabled = true;
29 statusBar.appendChild(this._liveCheckbox.element);
30
31 this._dataGridContainer = new WebInspector.VBox();
32 this._dataGridContainer.show(this.element);
33 var columns = [
34 { id: "location", title: WebInspector.UIString("Location"), disclosure: true },
35 { id: "status", title: WebInspector.UIString("Status") },
36 { id: "tts", title: WebInspector.UIString("Time to settle") }
37 ];
38 this._dataGrid = new WebInspector.DataGrid(columns, undefined, undefined, un defined, this._onContextMenu.bind(this));
39 this._dataGrid.show(this._dataGridContainer.element);
40
41 this._linkifier = new WebInspector.Linkifier();
42 }
43
44 WebInspector.PromisesPanel.prototype = {
45 _recordButtonClicked: function(event)
46 {
47 var recording = !this._recordButton.toggled;
48 this._recordButton.toggled = recording;
49 this._refreshButton.setEnabled(recording);
50 if (recording)
51 this._enablePromiseTracker();
52 else
53 this._disablePromiseTracker();
54 },
55
56 _refreshButtonClicked: function(event)
57 {
58 this._updateData();
59 },
60
61 _clearButtonClicked: function(event)
62 {
63 this._clear();
64 },
65
66 _enablePromiseTracker: function()
67 {
68 var mainTarget = WebInspector.targetManager.mainTarget();
69 if (mainTarget) {
70 mainTarget.debuggerAgent().enablePromiseTracker();
71 this._target = mainTarget;
72 }
73 },
74
75 _disablePromiseTracker: function()
76 {
77 if (this._target) {
78 this._target.debuggerAgent().disablePromiseTracker();
79 delete this._target;
80 }
81 this._clear();
82 },
83
84 /**
85 * @param {!DebuggerAgent.PromiseDetails} p1
86 * @param {!DebuggerAgent.PromiseDetails} p2
87 * @return {number}
88 */
89 _comparePromises: function(p1, p2) {
90 var t1 = p1.creationTime || 0;
91 var t2 = p2.creationTime || 0;
92 return t1 - t2;
93 },
94
95 _updateData: function()
96 {
97 /**
98 * @param {?Protocol.Error} error
99 * @param {?Array.<!DebuggerAgent.PromiseDetails>} promiseData
100 * @this {WebInspector.PromisesPanel}
101 */
102 function callback(error, promiseData)
103 {
104 if (error || !promiseData)
105 return;
106
107 promiseData.sort(this._comparePromises);
108 var nodesToInsert = { __proto__: null };
109 for (var i = 0; i < promiseData.length; i++) {
110 var promise = promiseData[i];
111 var status = createElementWithClass("div", "status");
112 status.classList.add(promise.status);
113 status.createTextChild(promise.status);
114 var data = {
115 promiseId: promise.id,
116 status: status
117 };
118 if (promise.callFrame)
119 data.location = this._linkifier.linkifyConsoleCallFrame(this ._target, promise.callFrame);
120 if (promise.creationTime && promise.settlementTime && promise.se ttlementTime >= promise.creationTime)
121 data.tts = Number.millisToString(promise.settlementTime - pr omise.creationTime, true);
122 var node = new WebInspector.DataGridNode(data, false);
123 nodesToInsert[promise.id] = { node: node, parentId: promise.pare ntId };
124 }
125
126 var rootNode = this._dataGrid.rootNode();
127
128 for (var id in nodesToInsert) {
129 var node = nodesToInsert[id].node;
130 var parentId = nodesToInsert[id].parentId;
131 var parentNode = (parentId && nodesToInsert[parentId]) ? nodesTo Insert[parentId].node : rootNode;
132 parentNode.appendChild(node);
133 parentNode.expanded = true;
134 }
135 }
136
137 this._clear();
138 if (this._target)
139 this._target.debuggerAgent().getPromises(callback.bind(this));
140 },
141
142 _clear: function()
143 {
144 this._dataGrid.rootNode().removeChildren();
145 this._linkifier.reset();
146 },
147
148 /**
149 * @param {!WebInspector.ContextMenu} contextMenu
150 * @param {!WebInspector.DataGridNode} node
151 */
152 _onContextMenu: function(contextMenu, node)
153 {
154 if (!this._target)
155 return;
156 var promiseId = node.data.promiseId;
157
158 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMe nuTitles() ? "Show in console" : "Show In Console"), showPromiseInConsole.bind(t his));
159 contextMenu.show();
160
161 /**
162 * @this {WebInspector.PromisesPanel}
163 */
164 function showPromiseInConsole()
165 {
166 if (this._target)
167 this._target.debuggerAgent().getPromiseById(promiseId, "console" , didGetPromiseById.bind(this));
168 }
169
170 /**
171 * @param {?Protocol.Error} error
172 * @param {?RuntimeAgent.RemoteObject} promise
173 * @this {WebInspector.PromisesPanel}
174 */
175 function didGetPromiseById(error, promise)
176 {
177 if (error || !promise)
178 return;
179
180 if (!this._target)
181 return;
182
183 this._target.consoleAgent().setLastEvaluationResult(promise.objectId );
184 var message = new WebInspector.ConsoleMessage(this._target,
185 WebInspector.ConsoleMe ssage.MessageSource.Other,
186 WebInspector.ConsoleMe ssage.MessageLevel.Log,
187 "",
188 WebInspector.ConsoleMe ssage.MessageType.Log,
189 undefined,
190 undefined,
191 undefined,
192 undefined,
193 [promise]);
194 this._target.consoleModel.addMessage(message);
195 WebInspector.console.show();
196 }
197 },
198
199 __proto__: WebInspector.VBox.prototype
200 }
201
OLDNEW
« no previous file with comments | « Source/devtools/front_end/promises/PromisePane.js ('k') | Source/devtools/front_end/promises/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698