diff options
Diffstat (limited to 'chrome/common/extensions/docs/examples/api')
9 files changed, 36 insertions, 41 deletions
diff --git a/chrome/common/extensions/docs/examples/api/contentSettings/popup.js b/chrome/common/extensions/docs/examples/api/contentSettings/popup.js index 45aeea5..c660d74 100644 --- a/chrome/common/extensions/docs/examples/api/contentSettings/popup.js +++ b/chrome/common/extensions/docs/examples/api/contentSettings/popup.js @@ -18,9 +18,10 @@ function settingChanged() { } document.addEventListener('DOMContentLoaded', function () { - chrome.tabs.getSelected(undefined, function(tab) { - incognito = tab.incognito; - url = tab.url; + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + var current = tabs[0]; + incognito = current.incognito; + url = current.url; var types = ['cookies', 'images', 'javascript', 'plugins', 'popups', 'notifications']; types.forEach(function(type) { diff --git a/chrome/common/extensions/docs/examples/api/debugger/live-headers/background.js b/chrome/common/extensions/docs/examples/api/debugger/live-headers/background.js index bba6065..45c0bbe 100644 --- a/chrome/common/extensions/docs/examples/api/debugger/live-headers/background.js +++ b/chrome/common/extensions/docs/examples/api/debugger/live-headers/background.js @@ -2,18 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -chrome.browserAction.onClicked.addListener(function() { - chrome.windows.getCurrent(function(win) { - chrome.tabs.getSelected(win.id, actionClicked); - }); +chrome.browserAction.onClicked.addListener(function(tab) { + chrome.debugger.attach({tabId:tab.id}, version, + onAttach.bind(null, tab.id)); }); var version = "1.0"; -function actionClicked(tab) { - chrome.debugger.attach({tabId:tab.id}, version, onAttach.bind(null, tab.id)); -} - function onAttach(tabId) { if (chrome.runtime.lastError) { alert(chrome.runtime.lastError.message); diff --git a/chrome/common/extensions/docs/examples/api/debugger/pause-resume/background.js b/chrome/common/extensions/docs/examples/api/debugger/pause-resume/background.js index 3d6b032..c5399a4 100644 --- a/chrome/common/extensions/docs/examples/api/debugger/pause-resume/background.js +++ b/chrome/common/extensions/docs/examples/api/debugger/pause-resume/background.js @@ -8,13 +8,7 @@ var version = "1.0"; chrome.debugger.onEvent.addListener(onEvent); chrome.debugger.onDetach.addListener(onDetach); -chrome.browserAction.onClicked.addListener(function() { - chrome.windows.getCurrent(function(win) { - chrome.tabs.getSelected(win.id, actionClicked); - }); -}); - -function actionClicked(tab) { +chrome.browserAction.onClicked.addListener(function(tab) { var tabId = tab.id; var debuggeeId = {tabId:tabId}; @@ -25,7 +19,7 @@ function actionClicked(tab) { chrome.debugger.attach(debuggeeId, version, onAttach.bind(null, debuggeeId)); else if (attachedTabs[tabId]) chrome.debugger.detach(debuggeeId, onDetach.bind(null, debuggeeId)); -} +}); function onAttach(debuggeeId) { if (chrome.runtime.lastError) { diff --git a/chrome/common/extensions/docs/examples/api/i18n/cld/background.js b/chrome/common/extensions/docs/examples/api/i18n/cld/background.js index 1bd7039..0c94849 100644 --- a/chrome/common/extensions/docs/examples/api/i18n/cld/background.js +++ b/chrome/common/extensions/docs/examples/api/i18n/cld/background.js @@ -1,6 +1,6 @@ -// Copyright (c) 2009 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. +// Copyright (c) 2009 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. var selectedId = -1; function refreshLanguage() { @@ -22,7 +22,7 @@ chrome.tabs.onSelectionChanged.addListener(function(tabId, props) { refreshLanguage(); }); -chrome.tabs.getSelected(null, function(tab) { - selectedId = tab.id; +chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + selectedId = tabs[0].id; refreshLanguage(); }); diff --git a/chrome/common/extensions/docs/examples/api/messaging/timer/popup.js b/chrome/common/extensions/docs/examples/api/messaging/timer/popup.js index c213baf..8b70f59 100644 --- a/chrome/common/extensions/docs/examples/api/messaging/timer/popup.js +++ b/chrome/common/extensions/docs/examples/api/messaging/timer/popup.js @@ -16,10 +16,10 @@ function setChildTextNode(elementId, text) { function testRequest() { setChildTextNode("resultsRequest", "running..."); - chrome.tabs.getSelected(null, function(tab) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { var timer = new chrome.Interval(); timer.start(); - + var tab = tabs[0]; chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { if (response.counter < 1000) { chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); @@ -36,11 +36,11 @@ function testRequest() { function testConnect() { setChildTextNode("resultsConnect", "running..."); - chrome.tabs.getSelected(null, function(tab) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { var timer = new chrome.Interval(); timer.start(); - var port = chrome.tabs.connect(tab.id); + var port = chrome.tabs.connect(tabs[0].id); port.postMessage({counter: 1}); port.onMessage.addListener(function getResp(response) { if (response.counter < 1000) { diff --git a/chrome/common/extensions/docs/examples/api/pageAction/set_icon/background.js b/chrome/common/extensions/docs/examples/api/pageAction/set_icon/background.js index ddfb894..f2e59ce 100644 --- a/chrome/common/extensions/docs/examples/api/pageAction/set_icon/background.js +++ b/chrome/common/extensions/docs/examples/api/pageAction/set_icon/background.js @@ -10,8 +10,8 @@ chrome.tabs.onSelectionChanged.addListener(function(tabId) { chrome.pageAction.show(lastTabId); }); -chrome.tabs.getSelected(null, function(tab) { - lastTabId = tab.id; +chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + lastTabId = tabs[0].id; chrome.pageAction.show(lastTabId); }); 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 index a92829c..76917a1 100644 --- a/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js +++ b/chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js @@ -4,15 +4,18 @@ // 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, + chrome.windows.getCurrent({populate: true}, function(currentWindow) { + chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { + var current = currentWindow.tabs.filter(function(tab) { + return tab.active; + })[0]; + chrome.experimental.processes.getProcessIdForTab(current.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); + displayTabInfo(currentWindow.id, current, outputDiv); + displaySameProcessTabs(current, pid, outputDiv); } ); diff --git a/chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.js b/chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.js index 1cd6e7a..a14e260 100644 --- a/chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.js +++ b/chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.js @@ -290,12 +290,13 @@ function removeWindow(windowId) { } function refreshSelectedTab(windowId) { - chrome.tabs.getSelected(windowId, function(tab) { - var input = new JsExprContext(tab); - var output = document.getElementById('tab_' + tab.id); + chrome.tabs.query({active: true, currentWindow: true} function(tabs) { + var input = new JsExprContext(tabs[0]); + var output = document.getElementById('tab_' + tabs[0].id); jstProcess(input, output); appendToLog( - 'selected tab refreshed -- tabId: ' + tab.id + ' url:' + tab.url); + 'selected tab refreshed -- tabId: ' + tabs[0].id + + ' url:' + tabs[0].url); }); } diff --git a/chrome/common/extensions/docs/examples/api/tabs/pin/background.js b/chrome/common/extensions/docs/examples/api/tabs/pin/background.js index cf54e3b..13d87cf 100644 --- a/chrome/common/extensions/docs/examples/api/tabs/pin/background.js +++ b/chrome/common/extensions/docs/examples/api/tabs/pin/background.js @@ -5,9 +5,10 @@ chrome.commands.onCommand.addListener(function(command) { if (command == "toggle-pin") { // Get the currently selected tab - chrome.tabs.getSelected(null, function(tab) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { // Toggle the pinned status - chrome.tabs.update(tab.id, {'pinned': !tab.pinned}); + var current = tabs[0] + chrome.tabs.update(current.id, {'pinned': !current.pinned}); }); } }); |