Chrome extension: uses encodeURIComponent; fixes download button

This commit is contained in:
notmasteryet 2012-03-03 19:27:35 -06:00
parent e1c6bfd77b
commit 0c7d45bbfb

View File

@ -1,18 +1,28 @@
<!doctype html> <!doctype html>
<script> <script>
function isPdfDownloadable(details) {
return details.url.indexOf('pdfjs.action=download') >= 0;
}
chrome.webRequest.onBeforeRequest.addListener( chrome.webRequest.onBeforeRequest.addListener(
function(details) { function(details) {
if (isPdfDownloadable(details))
return;
var viewerPage = 'content/web/viewer.html'; var viewerPage = 'content/web/viewer.html';
var url = chrome.extension.getURL(viewerPage) + '?file=' + details.url; var url = chrome.extension.getURL(viewerPage) +
'?file=' + encodeURIComponent(details.url);
return { redirectUrl: url }; return { redirectUrl: url };
}, },
{ {
urls: [ urls: [
"http://*/*.pdf", "http://*/*.pdf",
"file://*/*.pdf", "file://*/*.pdf"
], ],
types: [ "main_frame" ] types: [ "main_frame" ]
}, },
["blocking"]); ["blocking"]);
</script> </script>