OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 function requestData() { |
| 6 var xhr = new XMLHttpRequest(); |
| 7 xhr.open('GET', 'workers_data.json', false); |
| 8 xhr.send(null); |
| 9 if (xhr.status === 200) |
| 10 return JSON.parse(xhr.responseText); |
| 11 return []; |
| 12 } |
| 13 |
| 14 function addColumn(row, value) { |
| 15 var column = document.createElement("td"); |
| 16 column.textContent = value; |
| 17 row.appendChild(column); |
| 18 } |
| 19 |
| 20 function openDevTools(workerProcessHostId, workerRouteId) { |
| 21 chrome.send("openDevTools", |
| 22 [String(workerProcessHostId), String(workerRouteId)]); |
| 23 } |
| 24 |
| 25 function populateWorkerList() { |
| 26 var data = requestData(); |
| 27 |
| 28 var worker_properties = ["workerRouteId", "url", "name", "pid"]; |
| 29 |
| 30 var list = document.getElementById("workers-table"); |
| 31 for (var i = 0; i < data.length; i++) { |
| 32 var workerData = data[i]; |
| 33 var row = document.createElement("tr"); |
| 34 for (var j = 0; j < worker_properties.length; j++) |
| 35 addColumn(row, workerData[worker_properties[j]]); |
| 36 |
| 37 var column = document.createElement("td"); |
| 38 var link = document.createElement("a"); |
| 39 link.setAttribute("href", "#"); |
| 40 link.textContent = "inspect"; |
| 41 link.addEventListener( |
| 42 "click", |
| 43 openDevTools.bind(this, |
| 44 workerData.workerProcessHostId, |
| 45 workerData.workerRouteId), |
| 46 true); |
| 47 column.appendChild(link); |
| 48 row.appendChild(column); |
| 49 |
| 50 list.appendChild(row); |
| 51 } |
| 52 } |
| 53 |
| 54 document.addEventListener('DOMContentLoaded', populateWorkerList); |
OLD | NEW |