From b96152b19a826ff1eda62d8e9a621fe76220ae5d Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Wed, 22 Aug 2012 23:16:29 +0200 Subject: [PATCH 1/4] Support for building .crx file (re-visited) --- make.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/make.js b/make.js index 2d6696c3a..5090bfc3c 100755 --- a/make.js +++ b/make.js @@ -7,6 +7,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root BUILD_DIR = 'build/', BUILD_TARGET = BUILD_DIR + 'pdf.js', FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/', + CHROME_BUILD_DIR = BUILD_DIR + '/chrome/', EXTENSION_SRC_DIR = 'extensions/', LOCALE_SRC_DIR = 'l10n/', GH_PAGES_DIR = BUILD_DIR + 'gh-pages/', @@ -107,6 +108,8 @@ target.web = function() { cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR); cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf', GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/'); + cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf', + GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chrome/'); cp('web/index.html.template', GH_PAGES_DIR + '/index.html'); cd(GH_PAGES_DIR); @@ -256,6 +259,7 @@ target.pagesrepo = function() { mkdir('-p', GH_PAGES_DIR + '/web/images'); mkdir('-p', GH_PAGES_DIR + BUILD_DIR); mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox'); + mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome'); }; @@ -556,6 +560,70 @@ target.chrome = function() { ] }; builder.build(setup); + + // Bundle the files to a Chrome extension file .crx if path to key is set + var pem = env['PDFJS_CHROME_KEY']; + if (!pem) { + return; + } + + echo(); + echo('### Bundling .crx extension into ' + CHROME_BUILD_DIR); + + if (!test('-f', pem)) { + echo('Incorrect PDFJS_CHROME_KEY path'); + exit(1); + } + + var browserManifest = env['PDF_BROWSERS'] || + 'test/resources/browser_manifests/browser_manifest.json'; + + if (!test('-f', browserManifest)) { + echo('Browser manifest file ' + browserManifest + ' does not exist.'); + echo('Try copying one of the examples in test/resources/browser_manifests'); + exit(1); + } + + try { + var manifest = JSON.parse(cat(browserManifest)); + } catch (e) { + echo('Malformed browser manifest file'); + echo(e.message); + exit(1); + } + + var executable; + manifest.forEach(function(browser) { + if (browser.name === 'chrome') { + executable = browser.path; + } + }); + + // If there was no chrome entry in the browser manifest, exit + if(!executable) { + echo('There was no \'chrome\' entry in the browser manifest'); + exit(1); + } + + // If we're on a Darwin (Mac) OS, then let's check for an .app path + if (process.platform === 'darwin' && executable.indexOf('.app') !== -1) { + executable = path.join(executable, 'Contents', 'MacOS', 'Google Chrome'); + } + + // If the chrome executable doesn't exist + if(!test('-f', executable)) { + echo('Incorrect executable path to chrome'); + exit(1); + } + + // Let chrome pack the extension for us + exec('"' + executable + '"' + + ' --no-message-box' + + ' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' + + ' "--pack-extension-key=' + pem + '"'); + + // Rename to pdf.js.crx + mv(BUILD_DIR + 'chrome.crx', CHROME_BUILD_DIR + 'pdf.js.crx'); }; From 1548676f56ae2b380ed3dc64003257e3de372fee Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Sun, 26 Aug 2012 13:23:26 +0200 Subject: [PATCH 2/4] Use manual join instead of path.join --- make.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.js b/make.js index 5090bfc3c..8283e79af 100755 --- a/make.js +++ b/make.js @@ -607,7 +607,7 @@ target.chrome = function() { // If we're on a Darwin (Mac) OS, then let's check for an .app path if (process.platform === 'darwin' && executable.indexOf('.app') !== -1) { - executable = path.join(executable, 'Contents', 'MacOS', 'Google Chrome'); + executable = executable + '/Contents/MacOS/Google Chrome'); } // If the chrome executable doesn't exist From d64bb603c817e655788dbf16832b97003cab4591 Mon Sep 17 00:00:00 2001 From: gigaherz Date: Mon, 27 Aug 2012 01:49:07 +0200 Subject: [PATCH 3/4] Gracefully fail if the URL filename cannot be decoded. --- web/viewer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index f93c5247b..685b99184 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -385,7 +385,12 @@ var PDFView = { setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) { this.url = url; - document.title = decodeURIComponent(getFileName(url)) || url; + try { + document.title = decodeURIComponent(getFileName(url)) || url; + } catch (Exception) { + console.log('WARNING: Unable to decode: ' + getFileName(url)); + document.title = url; + } }, open: function pdfViewOpen(url, scale, password) { From 1a915943cd127d40b79db2805ac6586008397be3 Mon Sep 17 00:00:00 2001 From: gigaherz Date: Mon, 27 Aug 2012 09:02:10 +0200 Subject: [PATCH 4/4] Fix review comments. --- web/viewer.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 685b99184..0d88aae23 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -387,8 +387,9 @@ var PDFView = { this.url = url; try { document.title = decodeURIComponent(getFileName(url)) || url; - } catch (Exception) { - console.log('WARNING: Unable to decode: ' + getFileName(url)); + } catch (e) { + // decodeURIComponent may throw URIError, + // fall back to using the unprocessed url in that case document.title = url; } },