OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Show a list of all tabs in the same process as this one. | 5 // Show a list of all tabs in the same process as this one. |
6 function init() { | 6 function init() { |
7 chrome.windows.getCurrent({populate: true}, function(currentWindow) { | 7 chrome.windows.getCurrent({populate: true}, function(currentWindow) { |
8 chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { | 8 chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { |
9 var current = currentWindow.tabs.filter(function(tab) { | 9 var current = currentWindow.tabs.filter(function(tab) { |
10 return tab.active; | 10 return tab.active; |
11 })[0]; | 11 })[0]; |
12 chrome.experimental.processes.getProcessIdForTab(current.id, | 12 chrome.processes.getProcessIdForTab(current.id, |
13 function(pid) { | 13 function(pid) { |
14 var outputDiv = document.getElementById("tab-list"); | 14 var outputDiv = document.getElementById("tab-list"); |
15 var titleDiv = document.getElementById("title"); | 15 var titleDiv = document.getElementById("title"); |
16 titleDiv.innerHTML = "<b>Tabs in Process " + pid + ":</b>"; | 16 titleDiv.innerHTML = "<b>Tabs in Process " + pid + ":</b>"; |
17 displayTabInfo(currentWindow.id, current, outputDiv); | 17 displayTabInfo(currentWindow.id, current, outputDiv); |
18 displaySameProcessTabs(current, pid, outputDiv); | 18 displaySameProcessTabs(current, pid, outputDiv); |
19 } | 19 } |
20 ); | 20 ); |
21 | 21 |
22 }); | 22 }); |
23 }); | 23 }); |
24 } | 24 } |
25 | 25 |
26 function displaySameProcessTabs(selectedTab, processId, outputDiv) { | 26 function displaySameProcessTabs(selectedTab, processId, outputDiv) { |
27 // Loop over all windows and their tabs | 27 // Loop over all windows and their tabs |
28 var tabs = []; | 28 var tabs = []; |
29 chrome.windows.getAll({ populate: true }, function(windowList) { | 29 chrome.windows.getAll({ populate: true }, function(windowList) { |
30 for (var i = 0; i < windowList.length; i++) { | 30 for (var i = 0; i < windowList.length; i++) { |
31 for (var j = 0; j < windowList[i].tabs.length; j++) { | 31 for (var j = 0; j < windowList[i].tabs.length; j++) { |
32 var tab = windowList[i].tabs[j]; | 32 var tab = windowList[i].tabs[j]; |
33 if (tab.id != selectedTab.id) { | 33 if (tab.id != selectedTab.id) { |
34 tabs.push(tab); | 34 tabs.push(tab); |
35 } | 35 } |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 // Display tab in list if it is in the same process | 39 // Display tab in list if it is in the same process |
40 tabs.forEach(function(tab) { | 40 tabs.forEach(function(tab) { |
41 chrome.experimental.processes.getProcessIdForTab(tab.id, | 41 chrome.processes.getProcessIdForTab(tab.id, |
42 function(pid) { | 42 function(pid) { |
43 if (pid == processId) { | 43 if (pid == processId) { |
44 displayTabInfo(tab.windowId, tab, outputDiv); | 44 displayTabInfo(tab.windowId, tab, outputDiv); |
45 } | 45 } |
46 } | 46 } |
47 ); | 47 ); |
48 }); | 48 }); |
49 }); | 49 }); |
50 } | 50 } |
51 | 51 |
(...skipping 11 matching lines...) Expand all Loading... |
63 // Bring the selected tab to the front | 63 // Bring the selected tab to the front |
64 function showTab(origWindow, windowId, tabId) { | 64 function showTab(origWindow, windowId, tabId) { |
65 // TODO: Bring the window to the front. (See http://crbug.com/31434) | 65 // TODO: Bring the window to the front. (See http://crbug.com/31434) |
66 //chrome.windows.update(windowId, {focused: true}); | 66 //chrome.windows.update(windowId, {focused: true}); |
67 chrome.tabs.update(tabId, { selected: true }); | 67 chrome.tabs.update(tabId, { selected: true }); |
68 origWindow.close(); | 68 origWindow.close(); |
69 } | 69 } |
70 | 70 |
71 // Kick things off. | 71 // Kick things off. |
72 document.addEventListener('DOMContentLoaded', init); | 72 document.addEventListener('DOMContentLoaded', init); |
OLD | NEW |