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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Show a list of all tabs in the same process as this one.
6 function init() {
7 chrome.windows.getCurrent(function(currentWindow) {
8 chrome.tabs.getSelected(currentWindow.id, function(selectedTab) {
9 chrome.experimental.processes.getProcessIdForTab(selectedTab.id,
10 function(pid) {
11 var outputDiv = document.getElementById("tab-list");
12 var titleDiv = document.getElementById("title");
13 titleDiv.innerHTML = "<b>Tabs in Process " + pid + ":</b>";
14 displayTabInfo(currentWindow.id, selectedTab, outputDiv);
15 displaySameProcessTabs(selectedTab, pid, outputDiv);
16 }
17 );
18
19 });
20 });
21 }
22
23 function displaySameProcessTabs(selectedTab, processId, outputDiv) {
24 // Loop over all windows and their tabs
25 var tabs = [];
26 chrome.windows.getAll({ populate: true }, function(windowList) {
27 for (var i = 0; i < windowList.length; i++) {
28 for (var j = 0; j < windowList[i].tabs.length; j++) {
29 var tab = windowList[i].tabs[j];
30 if (tab.id != selectedTab.id) {
31 tabs.push(tab);
32 }
33 }
34 }
35
36 // Display tab in list if it is in the same process
37 tabs.forEach(function(tab) {
38 chrome.experimental.processes.getProcessIdForTab(tab.id,
39 function(pid) {
40 if (pid == processId) {
41 displayTabInfo(tab.windowId, tab, outputDiv);
42 }
43 }
44 );
45 });
46 });
47 }
48
49 // Print a link to a given tab
50 function displayTabInfo(windowId, tab, outputDiv) {
51 if (tab.favIconUrl != undefined) {
52 outputDiv.innerHTML += "<img src='chrome://favicon/" + tab.url + "'>\n";
53 }
54 outputDiv.innerHTML +=
55 "<b><a href='#' onclick='showTab(window, " + windowId + ", " + tab.id +
56 ")'>" + tab.title + "</a></b><br>\n" +
57 "<i>" + tab.url + "</i><br>\n";
58 }
59
60 // Bring the selected tab to the front
61 function showTab(origWindow, windowId, tabId) {
62 // TODO: Bring the window to the front. (See http://crbug.com/31434)
63 //chrome.windows.update(windowId, {focused: true});
64 chrome.tabs.update(tabId, { selected: true });
65 origWindow.close();
66 }
67
68 // Kick things off.
69 document.addEventListener('DOMContentLoaded', init);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698