Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tab restoration #1166

Merged
merged 3 commits into from
Oct 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*.sublime*
node_modules/*
dist
jscoverage.json
tags
27 changes: 15 additions & 12 deletions background_scripts/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ BackgroundCommands =
restoreTab: (callback) ->
# TODO: remove if-else -block when adopted into stable
if chrome.sessions
chrome.sessions.restore(null, (restoredSession) -> callback())
chrome.sessions.restore(null, (restoredSession) ->
callback() unless chrome.runtime.lastError)
else
# TODO(ilya): Should this be getLastFocused instead?
chrome.windows.getCurrent((window) ->
Expand Down Expand Up @@ -410,16 +411,17 @@ chrome.tabs.onRemoved.addListener (tabId) ->
# If we restore pages that content scripts can't run on, they'll ignore Vimium keystrokes when they
# reappear. Pretend they never existed and adjust tab indices accordingly. Could possibly expand this into
# a blacklist in the future.
if (/^(chrome|view-source:)[^:]*:\/\/.*/.test(openTabInfo.url))
for i of tabQueue[openTabInfo.windowId]
if (tabQueue[openTabInfo.windowId][i].positionIndex > openTabInfo.positionIndex)
tabQueue[openTabInfo.windowId][i].positionIndex--
return

if (tabQueue[openTabInfo.windowId])
tabQueue[openTabInfo.windowId].push(openTabInfo)
else
tabQueue[openTabInfo.windowId] = [openTabInfo]
unless chrome.sessions
if (/^(chrome|view-source:)[^:]*:\/\/.*/.test(openTabInfo.url))
for i of tabQueue[openTabInfo.windowId]
if (tabQueue[openTabInfo.windowId][i].positionIndex > openTabInfo.positionIndex)
tabQueue[openTabInfo.windowId][i].positionIndex--
return

if (tabQueue[openTabInfo.windowId])
tabQueue[openTabInfo.windowId].push(openTabInfo)
else
tabQueue[openTabInfo.windowId] = [openTabInfo]

# keep the reference around for a while to wait for the last messages from the closed tab (e.g. for updating
# scroll position)
Expand All @@ -429,7 +431,8 @@ chrome.tabs.onRemoved.addListener (tabId) ->

chrome.tabs.onActiveChanged.addListener (tabId, selectInfo) -> updateActiveState(tabId)

chrome.windows.onRemoved.addListener (windowId) -> delete tabQueue[windowId]
unless chrome.sessions
chrome.windows.onRemoved.addListener (windowId) -> delete tabQueue[windowId]

# End action functions

Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"history",
"clipboardRead",
"storage",
"sessions",
"<all_urls>"
],
"content_scripts": [
Expand Down