| OLD | NEW |
| (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("promisesPanel.css"); | |
| 13 this.element.classList.add("promises"); | |
| 14 | |
| 15 var buttonsBar = this.element.createChild("div"); | |
| 16 var enableButton = buttonsBar.createChild("button"); | |
| 17 enableButton.textContent = WebInspector.UIString("Enable Promises tracking")
; | |
| 18 enableButton.addEventListener("click", this._enableButtonClicked.bind(this))
; | |
| 19 var disableButton = buttonsBar.createChild("button"); | |
| 20 disableButton.textContent = WebInspector.UIString("Disable Promises tracking
"); | |
| 21 disableButton.addEventListener("click", this._disableButtonClicked.bind(this
)); | |
| 22 var refreshButton = buttonsBar.createChild("button"); | |
| 23 refreshButton.textContent = WebInspector.UIString("Refresh"); | |
| 24 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this
)); | |
| 25 var clearButton = buttonsBar.createChild("button"); | |
| 26 clearButton.textContent = WebInspector.UIString("Clear"); | |
| 27 clearButton.addEventListener("click", this._clearButtonClicked.bind(this)); | |
| 28 | |
| 29 this._dataGridContainer = new WebInspector.VBox(); | |
| 30 this._dataGridContainer.show(this.element); | |
| 31 var columns = [ | |
| 32 { id: "promiseId", title: WebInspector.UIString("Promise ID"), disclosur
e: true }, | |
| 33 { id: "status", title: WebInspector.UIString("Status") }, | |
| 34 { id: "location", title: WebInspector.UIString("Location") } | |
| 35 ]; | |
| 36 this._dataGrid = new WebInspector.DataGrid(columns); | |
| 37 this._dataGrid.show(this._dataGridContainer.element); | |
| 38 | |
| 39 this._linkifier = new WebInspector.Linkifier(); | |
| 40 } | |
| 41 | |
| 42 WebInspector.PromisesPanel.prototype = { | |
| 43 _refreshButtonClicked: function(event) | |
| 44 { | |
| 45 this._updateData(); | |
| 46 }, | |
| 47 | |
| 48 _clearButtonClicked: function(event) | |
| 49 { | |
| 50 this._clear(); | |
| 51 }, | |
| 52 | |
| 53 _enableButtonClicked: function(event) | |
| 54 { | |
| 55 var mainTarget = WebInspector.targetManager.mainTarget(); | |
| 56 if (mainTarget) { | |
| 57 mainTarget.debuggerAgent().enablePromiseTracker(); | |
| 58 this._target = mainTarget; | |
| 59 } | |
| 60 }, | |
| 61 | |
| 62 _disableButtonClicked: function(event) | |
| 63 { | |
| 64 if (this._target) { | |
| 65 this._target.debuggerAgent().disablePromiseTracker(); | |
| 66 delete this._target; | |
| 67 } | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * @param {!DebuggerAgent.PromiseDetails} p1 | |
| 72 * @param {!DebuggerAgent.PromiseDetails} p2 | |
| 73 * @return {number} | |
| 74 */ | |
| 75 _comparePromises: function(p1, p2) { | |
| 76 if (p1.parentId < p2.parentId) | |
| 77 return -1 | |
| 78 if (p1.parentId > p2.parentId) | |
| 79 return 1 | |
| 80 if (p1.id < p2.id) | |
| 81 return -1; | |
| 82 if (p1.id > p2.id) | |
| 83 return 1; | |
| 84 return 0; | |
| 85 }, | |
| 86 | |
| 87 _updateData: function() | |
| 88 { | |
| 89 /** | |
| 90 * @param {?Protocol.Error} error | |
| 91 * @param {?Array.<!DebuggerAgent.PromiseDetails>} promiseData | |
| 92 * @this {WebInspector.PromisesPanel} | |
| 93 */ | |
| 94 function callback(error, promiseData) | |
| 95 { | |
| 96 if (error || !promiseData) | |
| 97 return; | |
| 98 | |
| 99 promiseData.sort(this._comparePromises); | |
| 100 var nodesToInsert = { __proto__: null }; | |
| 101 for (var i = 0; i < promiseData.length; i++) { | |
| 102 var promise = promiseData[i]; | |
| 103 var data = { | |
| 104 promiseId: promise.id, | |
| 105 status: promise.status | |
| 106 }; | |
| 107 if (promise.callFrame) | |
| 108 data.location = this._linkifier.linkifyConsoleCallFrame(this
._target, promise.callFrame); | |
| 109 var node = new WebInspector.DataGridNode(data, false); | |
| 110 nodesToInsert[promise.id] = { node: node, parentId: promise.pare
ntId }; | |
| 111 } | |
| 112 | |
| 113 var rootNode = this._dataGrid.rootNode(); | |
| 114 | |
| 115 for (var id in nodesToInsert) { | |
| 116 var node = nodesToInsert[id].node; | |
| 117 var parentId = nodesToInsert[id].parentId; | |
| 118 var parentNode = (parentId && nodesToInsert[parentId]) ? nodesTo
Insert[parentId].node : rootNode; | |
| 119 parentNode.appendChild(node); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 this._clear(); | |
| 124 if (this._target) | |
| 125 this._target.debuggerAgent().getPromises(callback.bind(this)); | |
| 126 }, | |
| 127 | |
| 128 _clear: function() | |
| 129 { | |
| 130 this._dataGrid.rootNode().removeChildren(); | |
| 131 this._linkifier.reset(); | |
| 132 }, | |
| 133 | |
| 134 __proto__: WebInspector.VBox.prototype | |
| 135 } | |
| 136 | |
| OLD | NEW |