diff options
author | creis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-16 20:56:11 +0000 |
---|---|---|
committer | creis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-16 20:56:11 +0000 |
commit | 8b09aa8c25604d713d7732216d53b1678177dd7d (patch) | |
tree | 6bd1577b2c09393569cf3f34bfa9e8cf04da32dd /chrome/common | |
parent | be81bbaedde462e96cfbf63c0da98bf4cccb7a48 (diff) | |
download | chromium_src-8b09aa8c25604d713d7732216d53b1678177dd7d.zip chromium_src-8b09aa8c25604d713d7732216d53b1678177dd7d.tar.gz chromium_src-8b09aa8c25604d713d7732216d53b1678177dd7d.tar.bz2 |
Adds an example extension to demonstrate the processes experimental API.
The extension adds a browser action that can list all the tabs that share a
renderer process with the current tab.
BUG=32303
TEST=Install show_tabs as an extension.
Review URL: http://codereview.chromium.org/606061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
3 files changed, 105 insertions, 0 deletions
diff --git a/chrome/common/extensions/docs/examples/api/processes/show_tabs/icon.png b/chrome/common/extensions/docs/examples/api/processes/show_tabs/icon.png Binary files differnew file mode 100644 index 0000000..9a79a46 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/processes/show_tabs/icon.png diff --git a/chrome/common/extensions/docs/examples/api/processes/show_tabs/manifest.json b/chrome/common/extensions/docs/examples/api/processes/show_tabs/manifest.json new file mode 100644 index 0000000..c1711eb --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/processes/show_tabs/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "Show Tabs in Process", + "version": "1.0", + "description": "Adds a browser action showing which tabs share the current tab's process.", + "permissions": [ + "experimental", "tabs" + ], + "browser_action": { + "default_title": "Show Tabs in this Process", + "default_icon": "icon.png", + "popup": "popup.html" + } +} diff --git a/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.html b/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.html new file mode 100644 index 0000000..8f69fc0 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.html @@ -0,0 +1,92 @@ +<html> +<head> +<script> + // Show a list of all tabs in the same process as this one. + function init() { + chrome.windows.getCurrent(function(currentWindow) { + chrome.tabs.getSelected(currentWindow.id, function(selectedTab) { + chrome.experimental.processes.getProcessForTab(selectedTab.id, + function(process) { + var outputDiv = document.getElementById("tab-list"); + var titleDiv = document.getElementById("title"); + titleDiv.innerHTML = "<b>Tabs in Process " + process.id + ":</b>"; + displayTabInfo(currentWindow.id, selectedTab, outputDiv); + displaySameProcessTabs(selectedTab, process.id, outputDiv); + } + ); + + }); + }); + } + + function displaySameProcessTabs(selectedTab, processId, outputDiv) { + // Loop over all windows and their tabs + var tabs = []; + chrome.windows.getAll({ populate: true }, function(windowList) { + for (var i = 0; i < windowList.length; i++) { + for (var j = 0; j < windowList[i].tabs.length; j++) { + var tab = windowList[i].tabs[j]; + if (tab.id != selectedTab.id) { + tabs.push(tab); + } + } + } + + // Display tab in list if it is in the same process + tabs.forEach(function(tab) { + chrome.experimental.processes.getProcessForTab(tab.id, + function(process) { + if (process.id == processId) { + displayTabInfo(tab.windowId, tab, outputDiv); + } + } + ); + }); + }); + } + + // Print a link to a given tab + function displayTabInfo(windowId, tab, outputDiv) { + if (tab.favIconUrl != undefined) { + outputDiv.innerHTML += "<img src='" + tab.favIconUrl + "'>\n"; + } + outputDiv.innerHTML += + "<b><a href='#' onclick='showTab(window, " + windowId + ", " + tab.id + + ")'>" + tab.title + "</a></b><br>\n" + + "<i>" + tab.url + "</i><br>\n"; + } + + // Bring the selected tab to the front + function showTab(origWindow, windowId, tabId) { + // TODO: Bring the window to the front. (See http://crbug.com/31434) + //chrome.windows.update(windowId, {focused: true}); + chrome.tabs.update(tabId, { selected: true }); + origWindow.close(); + } +</script> +<style> +body { + overflow: hidden; + margin: 0px; + padding: 0px; + background: white; +} + +div:first-child { + margin-top: 0px; +} + +div { + padding: 1px 3px; + font-family: sans-serif; + font-size: 10pt; + width: 400px; + margin-top: 1px; +} +</style> +</head> +<body onload="init()" style="width: 400px"> +<div id="title"></div> +<div id="tab-list"></div> +</body> +</html> |