| OLD | NEW |
| 1 <!doctype html> |
| 1 <html> | 2 <html> |
| 2 <head> | 3 <head> |
| 3 <script> | 4 <title>Popup</title> |
| 4 // Show a list of all tabs in the same process as this one. | 5 <link href="popup.css" rel="stylesheet" type="text/css"> |
| 5 function init() { | 6 <script src="popup.js"></script> |
| 6 chrome.windows.getCurrent(function(currentWindow) { | 7 </head> |
| 7 chrome.tabs.getSelected(currentWindow.id, function(selectedTab) { | 8 <body> |
| 8 chrome.experimental.processes.getProcessIdForTab(selectedTab.id, | 9 <div id="title"></div> |
| 9 function(pid) { | 10 <div id="tab-list"></div> |
| 10 var outputDiv = document.getElementById("tab-list"); | 11 </body> |
| 11 var titleDiv = document.getElementById("title"); | |
| 12 titleDiv.innerHTML = "<b>Tabs in Process " + pid + ":</b>"; | |
| 13 displayTabInfo(currentWindow.id, selectedTab, outputDiv); | |
| 14 displaySameProcessTabs(selectedTab, pid, outputDiv); | |
| 15 } | |
| 16 ); | |
| 17 | |
| 18 }); | |
| 19 }); | |
| 20 } | |
| 21 | |
| 22 function displaySameProcessTabs(selectedTab, processId, outputDiv) { | |
| 23 // Loop over all windows and their tabs | |
| 24 var tabs = []; | |
| 25 chrome.windows.getAll({ populate: true }, function(windowList) { | |
| 26 for (var i = 0; i < windowList.length; i++) { | |
| 27 for (var j = 0; j < windowList[i].tabs.length; j++) { | |
| 28 var tab = windowList[i].tabs[j]; | |
| 29 if (tab.id != selectedTab.id) { | |
| 30 tabs.push(tab); | |
| 31 } | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 // Display tab in list if it is in the same process | |
| 36 tabs.forEach(function(tab) { | |
| 37 chrome.experimental.processes.getProcessIdForTab(tab.id, | |
| 38 function(pid) { | |
| 39 if (pid == processId) { | |
| 40 displayTabInfo(tab.windowId, tab, outputDiv); | |
| 41 } | |
| 42 } | |
| 43 ); | |
| 44 }); | |
| 45 }); | |
| 46 } | |
| 47 | |
| 48 // Print a link to a given tab | |
| 49 function displayTabInfo(windowId, tab, outputDiv) { | |
| 50 if (tab.favIconUrl != undefined) { | |
| 51 outputDiv.innerHTML += "<img src='" + tab.favIconUrl + "'>\n"; | |
| 52 } | |
| 53 outputDiv.innerHTML += | |
| 54 "<b><a href='#' onclick='showTab(window, " + windowId + ", " + tab.id + | |
| 55 ")'>" + tab.title + "</a></b><br>\n" + | |
| 56 "<i>" + tab.url + "</i><br>\n"; | |
| 57 } | |
| 58 | |
| 59 // Bring the selected tab to the front | |
| 60 function showTab(origWindow, windowId, tabId) { | |
| 61 // TODO: Bring the window to the front. (See http://crbug.com/31434) | |
| 62 //chrome.windows.update(windowId, {focused: true}); | |
| 63 chrome.tabs.update(tabId, { selected: true }); | |
| 64 origWindow.close(); | |
| 65 } | |
| 66 </script> | |
| 67 <style> | |
| 68 body { | |
| 69 overflow: hidden; | |
| 70 margin: 0px; | |
| 71 padding: 0px; | |
| 72 background: white; | |
| 73 } | |
| 74 | |
| 75 div:first-child { | |
| 76 margin-top: 0px; | |
| 77 } | |
| 78 | |
| 79 div { | |
| 80 padding: 1px 3px; | |
| 81 font-family: sans-serif; | |
| 82 font-size: 10pt; | |
| 83 width: 400px; | |
| 84 margin-top: 1px; | |
| 85 } | |
| 86 </style> | |
| 87 </head> | |
| 88 <body onload="init()" style="width: 400px"> | |
| 89 <div id="title"></div> | |
| 90 <div id="tab-list"></div> | |
| 91 </body> | |
| 92 </html> | 12 </html> |
| OLD | NEW |