Index: go-back-with-backspace/background.js |
diff --git a/go-back-with-backspace/background.js b/go-back-with-backspace/background.js |
index 0c822a5e3343b6905ee986942eeb4db54e21c2d3..8936579af87749502399306da978fe479b7110e3 100644 |
--- a/go-back-with-backspace/background.js |
+++ b/go-back-with-backspace/background.js |
@@ -2,9 +2,41 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// Put up an informative message on first install. |
+// Inject the content scripts into all open tabs on first install or update. |
chrome.runtime.onInstalled.addListener(function(details) { |
- if (details.reason == "install") { |
- chrome.tabs.create({url: "pages/installed.html"}); |
- } |
+ if (details.reason == 'install' || details.reason === 'update') |
+ injectContentScripts(); |
}); |
+ |
+// Inject the content scripts into all open tabs when this extension is |
+// re-enabled. |
+chrome.management.onEnabled.addListener(function(info) { |
Devlin
2016/09/19 21:22:31
(Just thinking) Hmm... I wonder if we should make
Pam (message me for reviews)
2016/09/20 21:42:59
I'd star that bug. Perhaps also onDisabled, since
Devlin
2016/09/27 16:08:57
(Orthogonal, but FYI) onDisabled wouldn't make sen
|
+ if (info.id === chrome.runtime.id) |
+ injectContentScripts(); |
+}); |
+ |
+// Maintain a longstanding connection to the content script, so the old version |
+// can disable itself when the extension has been updated, disabled, or |
+// uninstalled. |
Devlin
2016/09/19 21:22:31
This is kind of an abuse of the API. It means we'
Pam (message me for reviews)
2016/09/20 21:42:59
Chrome can't really clean up content scripts, but
Devlin
2016/09/27 16:08:57
Can you file a bug for that?
|
+chrome.runtime.onConnect.addListener(function(port) {}); |
+ |
+function injectContentScripts() { |
+ var scripts = chrome.runtime.getManifest().content_scripts[0].js; |
Devlin
2016/09/19 21:22:31
given the fact that you're already relying on mani
Pam (message me for reviews)
2016/09/20 21:42:59
True, although the manifest structure is likely to
|
+ |
+ chrome.windows.getAll({populate: true}, function(windows) { |
Devlin
2016/09/19 21:22:31
this would be easier with chrome.tabs.query({}, ta
Pam (message me for reviews)
2016/09/20 21:42:59
Done, thanks (except that I used function() syntax
|
+ for (var window_index = 0; window_index < windows.length; ++window_index) { |
+ var win = windows[window_index]; |
+ for (var tab_index = 0; tab_index < win.tabs.length; ++tab_index) { |
+ var tab = win.tabs[tab_index]; |
+ for (var i = 0; i < scripts.length; ++i) { |
+ chrome.tabs.executeScript(tab.id, |
+ { |
+ file: scripts[i], |
+ allFrames: true, |
+ runAt: 'document_start' |
Devlin
2016/09/19 21:22:31
Why document start?
Pam (message me for reviews)
2016/09/20 21:42:59
A number of users want to be able to hit back-back
|
+ }); |
+ } |
+ } |
+ } |
+ }); |
+} |