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

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

Issue 2351743003: Inject automatically on install etc., add mime types, and fix nits. (Closed)
Patch Set: 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
Index: go-back-with-backspace/content_script.js
diff --git a/go-back-with-backspace/content_script.js b/go-back-with-backspace/content_script.js
index f80ab2a2b3eab5adedfd2c31ba8c9b1ea571fe0c..820ed255e271501a8fb628eb1fc8aac8c75ec22d 100644
--- a/go-back-with-backspace/content_script.js
+++ b/go-back-with-backspace/content_script.js
@@ -12,8 +12,14 @@ chrome.storage.sync.get({
whitelist: []
}, function(items) {
options = items;
- window.addEventListener('keydown', function(e) {
- handleBackspace(e);
+ window.addEventListener('keydown', handleBackspace);
+
+ // Set up a longstanding connection to the background page. When the
+ // extension updates, is disabled, or is uninstalled, this connection will
+ // drop, and we will know to remove the listener.
+ var port = chrome.runtime.connect();
+ port.onDisconnect.addListener(function(port) {
+ window.removeEventListener('keydown', handleBackspace);
});
});
@@ -36,7 +42,8 @@ function handleBackspace(e) {
e.key !== 'Backspace' ||
e.altKey ||
e.ctrlKey ||
- e.metaKey)
+ e.metaKey ||
+ window.history.length < 2) // Nowhere to go back or forward to anyway.
return;
// The blacklist overrides everything.
@@ -69,8 +76,11 @@ function disabledInApplet(target) {
var nodeType = target.type || '';
nodeType = nodeType.toLowerCase();
if ((nodeName === 'EMBED' || nodeName === 'OBJECT') &&
- (nodeType === 'application/x-shockwave-flash' ||
- nodeType === 'application/java')) {
+ (nodeType === 'application/java' ||
+ nodeType === 'application/pdf' ||
+ nodeType === 'application/x-chat' ||
+ nodeType === 'application/x-google-chrome-pdf' ||
+ nodeType === 'application/x-shockwave-flash')) {
return true;
}
return false;

Powered by Google App Engine
This is Rietveld 408576698