This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #2714 test plan: 1. start Brave with PDFJS enabled and browse to a local PDF file. it should display correctly. the urlbar should show the 'file:' location. 2. turn off PDFJS and go to the file. it should prompt to download.
- Loading branch information
1 parent
8745bd5
commit ba8e3f5
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
'use strict' | ||
|
||
const UrlUtil = require('../js/lib/urlutil') | ||
const Filtering = require('./filtering') | ||
const config = require('../js/constants/config') | ||
const appActions = require('../js/actions/appActions') | ||
const getSetting = require('../js/settings').getSetting | ||
const settings = require('../js/constants/settings') | ||
|
||
const pdfjsBaseUrl = `chrome-extension://${config.PDFJSExtensionId}/` | ||
const viewerBaseUrl = `${pdfjsBaseUrl}content/web/viewer.html` | ||
|
||
const onBeforeRequest = (details) => { | ||
const result = { resourceName: 'pdfjs' } | ||
if (!(details.resourceType === 'mainFrame' && | ||
UrlUtil.isFileScheme(details.url) && | ||
UrlUtil.isFileType(details.url, 'pdf'))) { | ||
return result | ||
} | ||
appActions.loadURLRequested(details.tabId, `${viewerBaseUrl}?file=${encodeURIComponent(details.url)}`) | ||
result.cancel = true | ||
return result | ||
} | ||
|
||
/** | ||
* Load PDF.JS | ||
*/ | ||
module.exports.init = () => { | ||
if (getSetting(settings.PDFJS_ENABLED)) { | ||
Filtering.registerBeforeRequestFilteringCB(onBeforeRequest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters