Skip to content

Commit

Permalink
Fix loophole where Esc can cancel blocking a page
Browse files Browse the repository at this point in the history
  • Loading branch information
q-- committed Aug 26, 2016
1 parent 1d1938b commit ec10529
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version 1.0.6 (26 Aug 2016)
* Fixed loophole where blocking a page could be cancelled using <kbd>Escape</kbd> (issue 10)

### Version 1.0.5 (07 Aug 2016)
* Minor code improvements (per AMO reviewer recommendation).

Expand Down
14 changes: 14 additions & 0 deletions chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ LeechBlock.checkWindow = function (parsedURL, win, isRepeat) {
win.location.replace(blockURL);
}

// Prevent bypassing the block by pressing Escape to cancel the redirect to blockURL (issue #10)

// Remove old listener first
LeechBlock.preventEscapeListener && gBrowser.removeEventListener("keydown", LeechBlock.preventEscapeListener);

gBrowser.addEventListener("keydown",
LeechBlock.preventEscapeListener = // Assign for use with removeEventListener
evt => //Using an arrow function so the variable doc is available to it (thanks to autobinding)
evt.key === 'Escape' &&
gBrowser.getBrowserForTab(gBrowser.selectedTab).contentDocument === doc ? // Is this still the tab we're trying to redirect to the block page?
evt.preventDefault() : // Yes? Then block the default action of Escape, which is to cancel navigation
gBrowser.removeEventListener("keydown", LeechBlock.preventEscapeListener) //No? Then remove the eventListener
);

return; // nothing more to do
}

Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>{a95d8332-e4b4-6e7f-98ac-20b733364387}</em:id>
<em:version>1.0.5</em:version>
<em:version>1.0.6</em:version>
<em:type>2</em:type>
<em:unpack>true</em:unpack>
<em:name>LeechBlock</em:name>
Expand Down

0 comments on commit ec10529

Please sign in to comment.