summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/examples
diff options
context:
space:
mode:
authorDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-11 22:25:33 +0000
committerDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-11 22:25:33 +0000
commit676fd48483e09deb32255e2e9189bca5fa664ecc (patch)
tree2d06f35d6ea0b03e372719fe4f0f64142f6e17f7 /chrome/common/extensions/docs/examples
parentbfe76950b14157c957460227ae4563313ef95c41 (diff)
downloadchromium_src-676fd48483e09deb32255e2e9189bca5fa664ecc.zip
chromium_src-676fd48483e09deb32255e2e9189bca5fa664ecc.tar.gz
chromium_src-676fd48483e09deb32255e2e9189bca5fa664ecc.tar.bz2
Replace references to deprecated tabs.getSelected with tabs.query.
BUG=128869 Review URL: https://chromiumcodereview.appspot.com/18769008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/examples')
-rw-r--r--chrome/common/extensions/docs/examples/api/contentSettings/popup.js7
-rw-r--r--chrome/common/extensions/docs/examples/api/debugger/live-headers/background.js11
-rw-r--r--chrome/common/extensions/docs/examples/api/debugger/pause-resume/background.js10
-rw-r--r--chrome/common/extensions/docs/examples/api/i18n/cld/background.js10
-rw-r--r--chrome/common/extensions/docs/examples/api/messaging/timer/popup.js8
-rw-r--r--chrome/common/extensions/docs/examples/api/pageAction/set_icon/background.js4
-rw-r--r--chrome/common/extensions/docs/examples/api/processes/show_tabs/popup.js13
-rw-r--r--chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.js9
-rw-r--r--chrome/common/extensions/docs/examples/api/tabs/pin/background.js5
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/background.js47
-rw-r--r--chrome/common/extensions/docs/examples/extensions/chrome_search/background.js4
-rw-r--r--chrome/common/extensions/docs/examples/extensions/gdocs/chrome_ex_oauth.js12
-rw-r--r--chrome/common/extensions/docs/examples/extensions/mappy/background.js4
-rw-r--r--chrome/common/extensions/docs/examples/extensions/oauth_contacts/chrome_ex_oauth.js12
14 files changed, 73 insertions, 83 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});
});
}
});
diff --git a/chrome/common/extensions/docs/examples/extensions/benchmark/background.js b/chrome/common/extensions/docs/examples/extensions/benchmark/background.js
index 06915ea..88c3c9c 100644
--- a/chrome/common/extensions/docs/examples/extensions/benchmark/background.js
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/background.js
@@ -96,31 +96,30 @@ function nextBenchmark() {
return benchmarks[benchmarkIndex];
}
-function show_options() {
- chrome.tabs.getSelected(null, function(tab) {
- if (window.testUrl == "") {
- window.testUrl = tab.url;
+function show_options(tabs) {
+ var tab = tabs[0];
+ if (window.testUrl == "") {
+ window.testUrl = tab.url;
+ }
+ var tabs = chrome.extension.getViews({"type": "tab"});
+ if (tabs && tabs.length) {
+ // To avoid "Uncaught TypeError: Object Window has no method
+ // 'setUrl' ". Sometimes tabs are not the desired extension tabs.
+ if (tabs[0].$suburl != undefined) {
+ tabs[0].setUrl(testUrl);
}
- var tabs = chrome.extension.getViews({"type": "tab"});
- if (tabs && tabs.length) {
- // To avoid "Uncaught TypeError: Object Window has no method
- // 'setUrl' ". Sometimes tabs are not the desired extension tabs.
- if (tabs[0].$suburl != undefined) {
- tabs[0].setUrl(testUrl);
- }
- var optionsUrl = chrome.extension.getURL("options.html");
- chrome.tabs.getAllInWindow(null, function(all) {
- for (var i = 0; i < all.length; i++) {
- if (all[i].url == optionsUrl) {
- chrome.tabs.update(all[i].id, {selected: true});
- return;
- }
+ var optionsUrl = chrome.extension.getURL("options.html");
+ chrome.tabs.getAllInWindow(null, function(all) {
+ for (var i = 0; i < all.length; i++) {
+ if (all[i].url == optionsUrl) {
+ chrome.tabs.update(all[i].id, {selected: true});
+ return;
}
- });
- } else {
- chrome.tabs.create({"url":"options.html"});
- }
- });
+ }
+ });
+ } else {
+ chrome.tabs.create({"url":"options.html"});
+ }
}
chrome.browserAction.onClicked.addListener(show_options);
@@ -191,7 +190,7 @@ function Benchmark() {
if (benchmarks.length == 0) {
chrome.tabs.remove(benchmarkWindow.id);
benchmarkWindow = 0;
- show_options();
+ chrome.tabs.query({active: true, currentWindow: true}, show_options);
}
};
diff --git a/chrome/common/extensions/docs/examples/extensions/chrome_search/background.js b/chrome/common/extensions/docs/examples/extensions/chrome_search/background.js
index f3272f8..1dda1e5 100644
--- a/chrome/common/extensions/docs/examples/extensions/chrome_search/background.js
+++ b/chrome/common/extensions/docs/examples/extensions/chrome_search/background.js
@@ -148,8 +148,8 @@ function getEntryUrl(entry) {
}
function navigate(url) {
- chrome.tabs.getSelected(null, function(tab) {
- chrome.tabs.update(tab.id, {url: url});
+ chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
+ chrome.tabs.update(tabs[0].id, {url: url});
});
}
diff --git a/chrome/common/extensions/docs/examples/extensions/gdocs/chrome_ex_oauth.js b/chrome/common/extensions/docs/examples/extensions/gdocs/chrome_ex_oauth.js
index 1b62882..e28a594 100644
--- a/chrome/common/extensions/docs/examples/extensions/gdocs/chrome_ex_oauth.js
+++ b/chrome/common/extensions/docs/examples/extensions/gdocs/chrome_ex_oauth.js
@@ -1,8 +1,6 @@
-/**
- * Copyright (c) 2010 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) 2010 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.
/**
* Constructor - no need to invoke directly, call initBackgroundPage instead.
@@ -269,8 +267,8 @@ ChromeExOAuth.initCallbackPage = function() {
oauth.initOAuthFlow(function (token, secret) {
background_page.chromeExOAuthOnAuthorize(token, secret);
background_page.chromeExOAuthRedirectStarted = false;
- chrome.tabs.getSelected(null, function (tab) {
- chrome.tabs.remove(tab.id);
+ chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
+ chrome.tabs.remove(tabs[0].id);
});
});
};
diff --git a/chrome/common/extensions/docs/examples/extensions/mappy/background.js b/chrome/common/extensions/docs/examples/extensions/mappy/background.js
index 7fbed30..9796f8c 100644
--- a/chrome/common/extensions/docs/examples/extensions/mappy/background.js
+++ b/chrome/common/extensions/docs/examples/extensions/mappy/background.js
@@ -39,6 +39,6 @@ chrome.tabs.onSelectionChanged.addListener(function(tabId, info) {
});
// Ensure the current selected tab is set up.
-chrome.tabs.getSelected(null, function(tab) {
- updateAddress(tab.id);
+chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
+ updateAddress(tabs[0].id);
});
diff --git a/chrome/common/extensions/docs/examples/extensions/oauth_contacts/chrome_ex_oauth.js b/chrome/common/extensions/docs/examples/extensions/oauth_contacts/chrome_ex_oauth.js
index 7e13710..036820e 100644
--- a/chrome/common/extensions/docs/examples/extensions/oauth_contacts/chrome_ex_oauth.js
+++ b/chrome/common/extensions/docs/examples/extensions/oauth_contacts/chrome_ex_oauth.js
@@ -1,8 +1,6 @@
-/**
- * Copyright (c) 2010 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) 2010 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.
/**
* Constructor - no need to invoke directly, call initBackgroundPage instead.
@@ -269,8 +267,8 @@ ChromeExOAuth.initCallbackPage = function() {
oauth.initOAuthFlow(function (token, secret) {
background_page.chromeExOAuthOnAuthorize(token, secret);
background_page.chromeExOAuthRedirectStarted = false;
- chrome.tabs.getSelected(null, function (tab) {
- chrome.tabs.remove(tab.id);
+ chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
+ chrome.tabs.remove(tabs[0].id);
});
});
};