mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Merge pull request #6233 from Rob--W/crx-local-files
Improve support for viewing PDFs from file://-URLs in the Chrome extension
This commit is contained in:
commit
421289c7bc
11 changed files with 353 additions and 1 deletions
|
@ -226,3 +226,51 @@ chrome.webRequest.onBeforeRequest.addListener(
|
|||
types: ['main_frame', 'sub_frame']
|
||||
},
|
||||
['blocking']);
|
||||
|
||||
chrome.extension.isAllowedFileSchemeAccess(function(isAllowedAccess) {
|
||||
if (isAllowedAccess) {
|
||||
return;
|
||||
}
|
||||
// If the user has not granted access to file:-URLs, then the webRequest API
|
||||
// will not catch the request. It is still visible through the webNavigation
|
||||
// API though, and we can replace the tab with the viewer.
|
||||
// The viewer will detect that it has no access to file:-URLs, and prompt the
|
||||
// user to activate file permissions.
|
||||
chrome.webNavigation.onBeforeNavigate.addListener(function(details) {
|
||||
if (details.frameId === 0 && !isPdfDownloadable(details)) {
|
||||
chrome.tabs.update(details.tabId, {
|
||||
url: getViewerURL(details.url)
|
||||
});
|
||||
}
|
||||
}, {
|
||||
url: [{
|
||||
urlPrefix: 'file://',
|
||||
pathSuffix: '.pdf'
|
||||
}, {
|
||||
urlPrefix: 'file://',
|
||||
pathSuffix: '.PDF'
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
|
||||
if (message && message.action === 'isAllowedFileSchemeAccess') {
|
||||
chrome.extension.isAllowedFileSchemeAccess(sendResponse);
|
||||
return true;
|
||||
}
|
||||
if (message && message.action === 'openExtensionsPageForFileAccess') {
|
||||
var url = 'chrome://extensions/?id=' + chrome.runtime.id;
|
||||
if (message.data.newTab) {
|
||||
chrome.tabs.create({
|
||||
windowId: sender.tab.windowId,
|
||||
index: sender.tab.index + 1,
|
||||
url: url,
|
||||
openerTabId: sender.tab.id
|
||||
});
|
||||
} else {
|
||||
chrome.tabs.update(sender.tab.id, {
|
||||
url: url
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue