Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: go-back-with-backspace/background.js

Issue 2351743003: Inject automatically on install etc., add mime types, and fix nits. (Closed)
Patch Set: Review responses Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go-back-with-backspace/_locales/en/messages.json ('k') | go-back-with-backspace/build-zip.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..269b0bdf0f4b35b53cf3b4ed4db9f9d04e10ecc2 100644
--- a/go-back-with-backspace/background.js
+++ b/go-back-with-backspace/background.js
@@ -2,9 +2,42 @@
// 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) {
+ if (info.id === chrome.runtime.id)
+ injectContentScripts();
+});
+
+// Listen for messages from the content script, so an old version can detect
+// the loss of connection and disable itself when the extension has been
+// updated, disabled, or uninstalled.
+chrome.runtime.onMessage.addListener(function(message, from, reply) {
+ reply();
+});
+
+// Inject the content scripts into every open tab, on every window.
+function injectContentScripts() {
+ var scripts = chrome.runtime.getManifest().content_scripts[0].js;
+
+ chrome.tabs.query({}, function(tabs) {
+ tabs.forEach(function(tab) {
+ scripts.forEach(function(script) {
+ // This will produce an error if extensions are prohibited on the
+ // tab (e.g., chrome:// pages), but we can ignore it.
+ chrome.tabs.executeScript(tab.id,
+ {
+ file: script,
+ allFrames: true,
+ runAt: 'document_start'
+ });
+ });
+ });
+ });
+}
« no previous file with comments | « go-back-with-backspace/_locales/en/messages.json ('k') | go-back-with-backspace/build-zip.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698