aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Sand2013-02-18 23:54:52 +0000
committerTimo Sand2014-05-09 10:16:04 +0300
commitc7d70966a862b115fec9eee8a77fb0817e9a85bc (patch)
tree5c41cda6ccc99829a20d29c32bf5aa4fadb99ebb
parent1aa7ba3a5810742d14edfb738120b70f4a0f7619 (diff)
downloadvimium-c7d70966a862b115fec9eee8a77fb0817e9a85bc.tar.bz2
Added support for chromes upcoming sessionRestore API
-rw-r--r--background_scripts/main.coffee38
1 files changed, 21 insertions, 17 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index b2b4669c..9a1efe11 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -238,23 +238,27 @@ BackgroundCommands =
chrome.tabs.getSelected(null, (tab) ->
chrome.tabs.remove(tab.id))
restoreTab: (callback) ->
- # TODO(ilya): Should this be getLastFocused instead?
- chrome.windows.getCurrent((window) ->
- return unless (tabQueue[window.id] && tabQueue[window.id].length > 0)
- tabQueueEntry = tabQueue[window.id].pop()
- # Clean out the tabQueue so we don't have unused windows laying about.
- delete tabQueue[window.id] if (tabQueue[window.id].length == 0)
-
- # 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.url, index: tabQueueEntry.positionIndex }, (tab) ->
- tabLoadedHandlers[tab.id] = ->
- chrome.tabs.sendMessage(tab.id,
- name: "setScrollPosition",
- scrollX: tabQueueEntry.scrollX,
- scrollY: tabQueueEntry.scrollY)
- callback()))
+ if chrome.sessionRestore
+ chrome.sessionRestore.getRecentlyClosed((closed) ->
+ chrome.sessionRestore.restore(closed[0]))
+ else
+ # TODO(ilya): Should this be getLastFocused instead?
+ chrome.windows.getCurrent((window) ->
+ return unless (tabQueue[window.id] && tabQueue[window.id].length > 0)
+ tabQueueEntry = tabQueue[window.id].pop()
+ # Clean out the tabQueue so we don't have unused windows laying about.
+ delete tabQueue[window.id] if (tabQueue[window.id].length == 0)
+
+ # 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.url, index: tabQueueEntry.positionIndex }, (tab) ->
+ tabLoadedHandlers[tab.id] = ->
+ chrome.tabs.sendRequest(tab.id,
+ name: "setScrollPosition",
+ scrollX: tabQueueEntry.scrollX,
+ scrollY: tabQueueEntry.scrollY)
+ callback()))
openCopiedUrlInCurrentTab: (request) -> openUrlInCurrentTab({ url: Clipboard.paste() })
openCopiedUrlInNewTab: (request) -> openUrlInNewTab({ url: Clipboard.paste() })
togglePinTab: (request) ->