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

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: 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/build-zip.sh ('k') | go-back-with-backspace/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cc7fca6218a17ebc7f28b84725daee28d3925a22 100644
--- a/go-back-with-backspace/content_script.js
+++ b/go-back-with-backspace/content_script.js
@@ -12,9 +12,7 @@ chrome.storage.sync.get({
whitelist: []
}, function(items) {
options = items;
- window.addEventListener('keydown', function(e) {
- handleBackspace(e);
- });
+ window.addEventListener('keydown', handleBackspace);
});
// Update the local options when they're changed externally.
@@ -36,7 +34,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.
@@ -55,8 +54,27 @@ function handleBackspace(e) {
if (isEditable(document.activeElement))
return;
- e.shiftKey ? window.history.forward(): window.history.back();
- e.preventDefault();
+ // Make sure this extension is still active.
+ // sendMessage throws an internal error, not reported in lastError, if the
+ // other end no longer exists. So we use JS error-catching rather than
+ // extension errors. See http://crbug.com/650872
+ try {
+ chrome.runtime.sendMessage('', function(response) {
+ // Future-proofing in case sendMessage ever changes to setting lastError
+ // instead of throwing a JS error.
+ if (chrome.runtime.lastError) {
+ window.removeEventListener('keydown', handleBackspace);
+ } else {
+ e.shiftKey ? window.history.forward(): window.history.back();
+ e.preventDefault();
+ }
+ });
+ } catch(error) {
+ // If we have no connection to the background page, the extension has
+ // been updated, disabled, or uninstalled. Remove our listener and do
+ // nothing.
+ window.removeEventListener('keydown', handleBackspace);
+ }
}
// Return true if the option to disable the extension in applets is enabled,
@@ -69,8 +87,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;
« no previous file with comments | « go-back-with-backspace/build-zip.sh ('k') | go-back-with-backspace/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698