Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 0901059

Browse files
committed
Set PDFJS extension URL at runtime
Workaround https://github.com/brave/browser-laptop/pull/2527/files#r71074707.
1 parent 2828f43 commit 0901059

File tree

12 files changed

+36
-9
lines changed

12 files changed

+36
-9
lines changed

app/extensions/pdfjs/content/build/pdf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdf = {}));
2828
// Use strict in our context only - users might not want it
2929
'use strict';
3030

31-
var pdfjsVersion = '1.5.338';
32-
var pdfjsBuild = '5779432';
31+
var pdfjsVersion = '1.5.339';
32+
var pdfjsBuild = '3e89444';
3333

3434
var pdfjsFilePath =
3535
typeof document !== 'undefined' && document.currentScript ?

app/extensions/pdfjs/content/build/pdf.worker.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfWorker = {}));
2828
// Use strict in our context only - users might not want it
2929
'use strict';
3030

31-
var pdfjsVersion = '1.5.338';
32-
var pdfjsBuild = '5779432';
31+
var pdfjsVersion = '1.5.339';
32+
var pdfjsBuild = '3e89444';
3333

3434
var pdfjsFilePath =
3535
typeof document !== 'undefined' && document.currentScript ?

app/extensions/pdfjs/extension-router.js

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ limitations under the License.
2020
(function ExtensionRouterClosure() {
2121
var VIEWER_URL = chrome.extension.getURL('content/web/viewer.html');
2222
var CRX_BASE_URL = chrome.extension.getURL('/');
23+
if (chrome.ipc && chrome.ipc.send) {
24+
chrome.ipc.send('got-pdfjs-url', CRX_BASE_URL)
25+
}
2326

2427
var schemes = [
2528
'http',

app/extensions/pdfjs/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "PDF Viewer",
4-
"version": "1.5.338",
4+
"version": "1.5.339",
55
"description": "Uses HTML5 to display PDF files directly in the browser.",
66
"icons": {
77
"128": "icon128.png",

app/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ app.on('ready', () => {
512512
}
513513
})
514514

515+
ipcMain.on(messages.GOT_PDFJS_URL, (e, origin) => {
516+
appActions.setPDFJSOrigin(origin)
517+
})
518+
515519
ipcMain.on(messages.SHOW_USERNAME_LIST, (e, origin, action, boundingRect, value) => {
516520
const passwords = AppStore.getState().get('passwords')
517521
if (!passwords || passwords.size === 0) {

docs/state.md

+1
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,6 @@ WindowStore
338338
},
339339
flashInitialized: boolean, // Whether flash was initialized successfully. Cleared on shutdown.
340340
cleanedOnShutdown: boolean, // whether app data was successfully cleared on shutdown
341+
pdfjsOrigin: string // Origin of the PDFJS extension
341342
}
342343
```

js/actions/appActions.js

+12
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ const appActions = {
323323
actionType: AppConstants.APP_SET_DICTIONARY,
324324
locale
325325
})
326+
},
327+
328+
/**
329+
* Sets PDFJS origin
330+
* @param {string} origin - The origin of the PDFJS extension. Ends in
331+
* a slash.
332+
*/
333+
setPDFJSOrigin: function (origin) {
334+
AppDispatcher.dispatch({
335+
actionType: AppConstants.APP_SET_PDFJS_ORIGIN,
336+
origin
337+
})
326338
}
327339
}
328340

js/constants/appConstants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const AppConstants = {
3030
APP_SHOW_MESSAGE_BOX: _, /** @param {Object} detail */
3131
APP_HIDE_MESSAGE_BOX: _, /** @param {string} message */
3232
APP_ADD_WORD: _, /** @param {string} word, @param {boolean} learn */
33-
APP_SET_DICTIONARY: _ /** @param {string} locale */
33+
APP_SET_DICTIONARY: _, /** @param {string} locale */
34+
APP_SET_PDFJS_ORIGIN: _ /** @param {string} origin */
3435
}
3536

3637
module.exports = mapValuesByKeys(AppConstants)

js/constants/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ module.exports = {
4141
replacementUrl: adHost
4242
},
4343
braveExtensionId: 'mnojpmjdmbbfmejpflffifhffcmidifd',
44-
PDFJSExtensionId: 'ckglimbbooghmggmkikhbolcfmgniemo'
44+
PDFJSExtensionId: 'oemmndcbldboiebfnladdacbdfmadadm'
4545
}

js/constants/messages.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const messages = {
7474
SET_RESOURCE_ENABLED: _,
7575
GO_BACK: _,
7676
GO_FORWARD: _,
77+
GOT_PDFJS_URL: _, /** @arg {string} origin - of PDFJS extension */
7778
// Password manager
7879
GET_PASSWORDS: _, /** @arg {string} formOrigin, @arg {string} action */
7980
GOT_PASSWORD: _, /** @arg {string} username, @arg {string} password, @arg {string} origin, @arg {string} action, @arg {boolean} isUnique */

js/stores/appStore.js

+3
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ const handleAppAction = (action) => {
488488
case AppConstants.APP_SET_DICTIONARY:
489489
appState = appState.setIn(['dictionary', 'locale'], action.locale)
490490
break
491+
case AppConstants.APP_SET_PDFJS_ORIGIN:
492+
appState = appState.set('pdfjsOrigin', action.origin)
493+
break
491494
default:
492495
}
493496

js/stores/windowStore.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let windowState = Immutable.fromJS({
3636
let lastEmittedState
3737

3838
const CHANGE_EVENT = 'change'
39-
const PDFJS_ORIGIN = `chrome-extension://${config.PDFJSExtensionId}/`
39+
let PDFJS_ORIGIN = null
4040

4141
const frameStatePath = (key) =>
4242
['frames', FrameStateUtil.findIndexForFrameKey(windowState.get('frames'), key)]
@@ -55,7 +55,9 @@ const updateNavBarInput = (loc, frameStatePath = activeFrameStatePath()) => {
5555
* @param {string=} loc - Original URL
5656
*/
5757
const setPDFLocation = (loc) => {
58-
if (loc && UrlUtil.isFileType(loc, 'pdf') && !loc.startsWith(PDFJS_ORIGIN)) {
58+
PDFJS_ORIGIN = PDFJS_ORIGIN || require('./appStoreRenderer').state.get('pdfjsOrigin')
59+
if (loc && PDFJS_ORIGIN &&
60+
UrlUtil.isFileType(loc, 'pdf') && !loc.startsWith(PDFJS_ORIGIN)) {
5961
return PDFJS_ORIGIN + loc
6062
}
6163
return loc

0 commit comments

Comments
 (0)