aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorunknown2010-04-01 02:50:37 +0800
committerilya2010-03-31 21:23:46 -0700
commit9b7d7074d0c86569b24e5457713411140ad6df7d (patch)
tree6b9341f0efc712ddf9b24636947e3a28c2834fc3
parentb9bf74fc6c02afed77da3ec991f8ac5da6687842 (diff)
downloadvimium-9b7d7074d0c86569b24e5457713411140ad6df7d.tar.bz2
Restore Tab now recreates the tab in its old position.
Also, Restore Tab is now able to restore all tabs, no matter how they were closed (via vimium keys, with the mouse, or with native Chrome shortcuts).
-rw-r--r--background_page.html59
1 files changed, 50 insertions, 9 deletions
diff --git a/background_page.html b/background_page.html
index 0bed6594..15ffca92 100644
--- a/background_page.html
+++ b/background_page.html
@@ -7,6 +7,7 @@
var currentVersion = "1.16";
var tabQueue = {}; // windowId -> Array
+ var tabTracker = {}; // tabId -> URL
var keyQueue = ""; // Queue of keys typed
var validFirstKeys = {};
var singleKeyCommands = [];
@@ -297,14 +298,12 @@
function removeTab(callback) {
getCurrentTabWithScrollPosition(function(tab, scrollX, scrollY) {
- var tabQueueEntry = { tabUrl: tab.url,
- scrollX: scrollX,
- scrollY: scrollY };
-
- if (tabQueue[tab.windowId])
- tabQueue[tab.windowId].push(tabQueueEntry);
- else
- tabQueue[tab.windowId] = [tabQueueEntry];
+ if (!tabTracker[tab.id]) {
+ console.log('removeTab error: tab not found in tabTracker');
+ return;
+ }
+ tabTracker[tab.id][scrollX] = scrollX;
+ tabTracker[tab.id][scrollY] = scrollY;
chrome.tabs.remove(tab.id);
// We can't just call the callback here because we actually need to wait
@@ -313,6 +312,48 @@
});
}
+ /*
+ * Since it is impossible to find out anything but the tabId
+ * from the onRemoved event, we have to keep track of the
+ * tab properties ourselves.
+ */
+ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
+ if (changeInfo.status !== "loading") return; // only do this once per URL change
+ tabTracker[tabId] = { url: tab.url,
+ index: tab.index,
+ windowId: tab.windowId,
+ scrollX: 0,
+ scrollY: 0 };
+ });
+
+ chrome.tabs.onAttached.addListener(function(tabId, attachedInfo) {
+ if (!tabTracker[tab.id]) {
+ console.log('onAttached error: tab not found in tabTracker');
+ return;
+ }
+ tabTracker[tabId][windowId] = attachedInfo.newWindowId;
+ tabTracker[tabId][index] = attachedInfo.newPosition;
+ });
+
+ chrome.tabs.onRemoved.addListener(function(tabId) {
+ if (!tabTracker[tabId]) {
+ console.log('onRemoved error: tab not found in tabTracker');
+ return;
+ }
+ var tab = tabTracker[tabId]; // Note: not a real tab object, only key properties are recorded
+ var tabQueueEntry = { tabUrl: tab.url,
+ tabIndex: tab.index,
+ scrollX: tab.scrollX,
+ scrollY: tab.scrollY };
+
+ if (tabQueue[tab.windowId])
+ tabQueue[tab.windowId].push(tabQueueEntry);
+ else
+ tabQueue[tab.windowId] = [tabQueueEntry];
+
+ delete tabTracker[tabId];
+ });
+
function restoreTab(callback) {
// TODO(ilya): Should this be getLastFocused instead?
chrome.windows.getCurrent(function(window) {
@@ -327,7 +368,7 @@
// We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until the
// tab is created because the content script is not available during the "loading" state. We need to
// wait until that's over before we can call setScrollPosition.
- chrome.tabs.create({ url: tabQueueEntry.tabUrl }, function(tab) {
+ chrome.tabs.create({ url: tabQueueEntry.tabUrl, index: tabQueueEntry.tabIndex }, function(tab) {
tabLoadedHandlers[tab.id] = function() {
var scrollPort = chrome.tabs.connect(tab.id, {name: "setScrollPosition"});
scrollPort.postMessage({ scrollX: tabQueueEntry.scrollX, scrollY: tabQueueEntry.scrollY });