aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/main.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-03-07 16:49:32 +0000
committerStephen Blott2015-03-07 16:58:02 +0000
commitb05276ed8264e5a71f20a7068690ba2a414ee6d8 (patch)
tree9c96d165dd536f696a1f0e5638ba9ca5f4c34cb1 /background_scripts/main.coffee
parentae60abb94665446200db8a750bbc1362895d04d2 (diff)
downloadvimium-b05276ed8264e5a71f20a7068690ba2a414ee6d8.tar.bz2
Reload content scripts after install/update.
This is @mrmr1993's work from #1041. Reload content scripts when vimium is installed or updates. (@mrmr1993: The automatic merge was really messy (or, at least, I couldn't figure out what was going on). Since the bulk of #1041 was actually quite compact, I took the liberty of just copying it in. Hope you don't mind.)
Diffstat (limited to 'background_scripts/main.coffee')
-rw-r--r--background_scripts/main.coffee19
1 files changed, 19 insertions, 0 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 23950e6e..7b360efd 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -2,6 +2,25 @@ root = exports ? window
currentVersion = Utils.getCurrentVersion()
+# Iterate over existing tabs and inject the necessary javascript/css into each.
+injectContentScriptsIntoOpenTabs = ->
+ manifest = chrome.runtime.getManifest()
+ # Content scripts loaded on every page should be in the same group. We assume it is the first.
+ contentScripts = manifest.content_scripts[0]
+ chrome.tabs.query { status: "complete" }, (tabs) ->
+ jobs = [ [ chrome.tabs.executeScript, contentScripts.js ], [ chrome.tabs.insertCSS, contentScripts.css ] ]
+ # Chrome complains if we don't evaluate chrome.runtime.lastError on errors (and we get errors for tabs on
+ # which Vimium cannot run).
+ checkLastRuntimeError = -> chrome.runtime.lastError
+ for tab in tabs
+ for [ func, files ] in jobs
+ for file in files
+ func tab.id, { file: file, allFrames: contentScripts.allFrames }, checkLastRuntimeError
+
+# The browser may have tabs already open. We inject the content scripts immediately so that they work straight
+# away.
+chrome.runtime.onInstalled.addListener injectContentScriptsIntoOpenTabs
+
tabQueue = {} # windowId -> Array
tabInfoMap = {} # tabId -> object with various tab properties
keyQueue = "" # Queue of keys typed