Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5600)

Unified Diff: chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js

Issue 8318001: Adding `content_security_policy` to a few sample extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Docs. Zips. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js
diff --git a/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js b/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js
new file mode 100644
index 0000000000000000000000000000000000000000..a92829cfc361a4dd71f51728a1daaaa6fadc3964
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js
@@ -0,0 +1,69 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// 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.getProcessIdForTab(selectedTab.id,
+ function(pid) {
+ var outputDiv = document.getElementById("tab-list");
+ var titleDiv = document.getElementById("title");
+ titleDiv.innerHTML = "<b>Tabs in Process " + pid + ":</b>";
+ displayTabInfo(currentWindow.id, selectedTab, outputDiv);
+ displaySameProcessTabs(selectedTab, pid, 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.getProcessIdForTab(tab.id,
+ function(pid) {
+ if (pid == 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='chrome://favicon/" + tab.url + "'>\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();
+}
+
+// Kick things off.
+document.addEventListener('DOMContentLoaded', init);

Powered by Google App Engine
This is Rietveld 408576698