-
Notifications
You must be signed in to change notification settings - Fork 973
move pdf.js loading logic into browser-laptop #12138
Conversation
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 getViewerUrl = UrlUtil.getPDFViewerUrl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of the changes below are just copied from pdfhandler.js and extension-router.js in our pdf.js fork. Those scripts used to run as background scripts in the pdf.js extension but this PR deprecates them.
Codecov Report
@@ Coverage Diff @@
## master #12138 +/- ##
==========================================
+ Coverage 55.29% 55.3% +<.01%
==========================================
Files 276 276
Lines 26740 26745 +5
Branches 4310 4310
==========================================
+ Hits 14786 14791 +5
Misses 11954 11954
|
498bc75
to
68f188f
Compare
@@ -394,10 +393,6 @@ module.exports.init = () => { | |||
} | |||
}) | |||
|
|||
ipcMain.on(messages.LOAD_URL_REQUESTED, (e, tabId, url) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why this was removed? What is/was emitting this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bsclifton Good question! This is actually being emitted in PDF.JS: https://github.com/brave/pdf.js/blob/master/extensions/chromium/pdfHandler.js#L136. However I moved all of that logic into this PR [1], so it no longer needs to be handled in browser-laptop once this is merged.
[1] Technically all of this code is still in the PDF.JS extension since we can't update browser-laptop and PDF.JS at the same time. However the manifest override in line 452 means that once someone updates to this version of browser-laptop, the deprecated background scripts in PDF.JS will no longer run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah- perfect 😄 Thanks for the explanation!
app/pdfJS.js
Outdated
* are read. | ||
* @return {boolean} True if the resource is a PDF file. | ||
*/ | ||
function isPdfFile (details) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match other places, this (and the function below) might be named with the same casing (ex: isPDFFile
). If the functions aren't being exported, they could be changed to isFile
and isDownloadable
since this file is already named pdfJS.js
app/pdfJS.js
Outdated
* @return {boolean} True if the resource is a PDF file. | ||
*/ | ||
function isPdfFile (details) { | ||
var header = details.responseHeaders['Content-Type'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: potentially falsey values could be weeded out to prevent null exception when called. For example:
var header = details && details.responseHeaders && details.responseHeaders['Content-Type']
name: 'PDF Viewer', | ||
manifest_version: 2, | ||
version: '1.9.457', | ||
description: 'Uses HTML5 to display PDF files directly in the browser.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By having this here, do we lose any translation that was being done? Should this be loading using locale.translation()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bsclifton I don't think translation would be lost. It was also a literal string in the old manifest: https://github.com/brave/pdf.js/blob/master/extensions/chromium/manifest.json#L5. AFAIK passing a manifest object to the extension-loading function is the same as reading a manifest.json file, so if it was translated before, it would be translated now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually tested- works great 😄
Code reviewed, comments left. Otherwise, LGTM! 😄 👍
68f188f
to
ddf13d6
Compare
@bsclifton ready for re-approval! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ 😄
move pdf.js loading logic into browser-laptop
move pdf.js loading logic into browser-laptop
assert.equal(urlUtil.getPDFViewerUrl('http://example.com'), baseUrl + 'http%3A%2F%2Fexample.com') | ||
}) | ||
it('file url', function () { | ||
assert.equal(urlUtil.getPDFViewerUrl('file:///Users/yan/some files/test.pdf'), baseUrl + 'file%3A%2F%2F%2FUsers%2Fyan%2Fsome%20files%2Ftest.pdf') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly a silly question, but will this path work on other machines? Seems to me the path is hardcoded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pureooze since the function just builds the path (using the provided input), the actual input itself isn't important 😄 The important part to note is that the output is prefixed with baseUrl
(and the parts afterword are URL encoded)
fix #4651
probably fixes #2715 but ideally the workaround in brave/pdf.js should be removed too
may also fix other PDF loading errors
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
Tests