Skip to content

Commit

Permalink
Fix brave#10554, brave#11059: remove check for .pdf in URL, prefer re…
Browse files Browse the repository at this point in the history
…sponse headers.
  • Loading branch information
humphd committed Mar 23, 2018
1 parent 5bd5b15 commit 173bc36
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 33 deletions.
5 changes: 1 addition & 4 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const tabState = require('../common/state/tabState')
const {app, BrowserWindow, extensions, session, ipcMain} = require('electron')
const {makeImmutable, makeJS} = require('../common/state/immutableUtil')
const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil')
const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl, isHttpOrHttps, getLocationIfPDF} = require('../../js/lib/urlutil')
const {isURL, getUrlFromInput, getDefaultFaviconUrl, isHttpOrHttps, getLocationIfPDF} = require('../../js/lib/urlutil')
const {isSessionPartition} = require('../../js/state/frameStateUtil')
const {getOrigin} = require('../../js/lib/urlutil')
const settingsStore = require('../../js/settings')
Expand Down Expand Up @@ -50,9 +50,6 @@ const normalizeUrl = function (url) {
if (isURL(url)) {
url = getUrlFromInput(url)
}
if (settingsStore.getSetting(settings.PDFJS_ENABLED)) {
url = toPDFJSLocation(url)
}
return url
}

Expand Down
13 changes: 0 additions & 13 deletions js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,6 @@ const UrlUtil = {
return `${viewerBaseUrl}?file=${encodeURIComponent(url)}`
},

/**
* Converts a potential PDF URL to the PDFJS URL.
* XXX: This only looks at the URL file extension, not MIME types.
* @param {string} url
* @return {string}
*/
toPDFJSLocation: function (url) {
if (url && UrlUtil.isHttpOrHttps(url) && UrlUtil.isFileType(url, 'pdf')) {
return UrlUtil.getPDFViewerUrl(url)
}
return url
},

/**
* Gets the default favicon URL for a URL.
* @param {string} url The URL to find a favicon for
Expand Down
Binary file added test/fixtures/html_with_pdf_extension.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions test/tab-components/frameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Brave = require('../lib/brave')
const {urlInput,
activeTabTitle,
pinnedTabsTabs,
backButtonEnabled,
backButtonDisabled,
Expand Down Expand Up @@ -278,6 +279,15 @@ describe('frame tests', function () {
.url(url)
.waitForVisible('#viewerContainer')
})

it('loads HTML properly despite having .pdf extension', function * () {
let url = Brave.server.url('html_with-pdf_extension.pdf')
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.tabByIndex(0)
.loadUrl(url)
.waitForTextValue(activeTabTitle, 'HTML using .pdf Extension')
})
})
})

Expand Down
16 changes: 0 additions & 16 deletions test/unit/lib/urlutilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,6 @@ describe('urlutil', function () {
})
})

describe('toPDFJSLocation', function () {
const baseUrl = 'chrome-extension://jdbefljfgobbmcidnmpjamcbhnbphjnb/'
it('pdf', function () {
assert.equal(urlUtil.toPDFJSLocation('http://abc.com/test.pdf'), baseUrl + 'content/web/viewer.html?file=http%3A%2F%2Fabc.com%2Ftest.pdf')
})
it('non-pdf', function () {
assert.equal(urlUtil.toPDFJSLocation('http://abc.com/test.pdf.txt'), 'http://abc.com/test.pdf.txt')
})
it('file url', function () {
assert.equal(urlUtil.toPDFJSLocation('file://abc.com/test.pdf.txt'), 'file://abc.com/test.pdf.txt')
})
it('empty', function () {
assert.equal(urlUtil.toPDFJSLocation(''), '')
})
})

describe('getPDFViewerUrl', function () {
const baseUrl = 'chrome-extension://jdbefljfgobbmcidnmpjamcbhnbphjnb/content/web/viewer.html?file='
it('regular url', function () {
Expand Down

0 comments on commit 173bc36

Please sign in to comment.