1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Switch to stream converter for extension.

This commit is contained in:
Brendan Dahl 2012-01-23 16:50:45 -08:00
parent edc632e469
commit 178b89342a
8 changed files with 115 additions and 72 deletions

View file

@ -0,0 +1,14 @@
<!-- This snippet is used in firefox extension, see Makefile -->
<base href="resource://pdf.js/web/" />
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">
<!--
// pdf.js is inlined here because resource:// urls won't work
// for loading workers.
/* PDFJSSCRIPT_INCLUDE_BUNDLE */
-->
</script>
<script type="text/javascript">
// This specifies the location of the pdf.js file.
PDFJS.isFirefoxExtension = true;
PDFJS.workerSrc = 'none';
</script>

View file

@ -2,9 +2,11 @@
<html>
<head>
<title>Simple pdf.js page viewer</title>
<!-- PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION -->
<link rel="stylesheet" href="viewer.css"/>
<script type="text/javascript" src="compatibility.js"></script>
<script type="text/javascript" src="compatibility.js"></script> <!-- PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION -->
<!-- PDFJSSCRIPT_INCLUDE_BUILD -->
<script type="text/javascript" src="../src/core.js"></script> <!-- PDFJSSCRIPT_REMOVE -->

View file

@ -73,23 +73,11 @@ var Settings = (function SettingsClosure() {
}
return true;
})();
var extPrefix = 'extensions.uriloader@pdf.js';
var isExtension = location.protocol == 'chrome:' && !isLocalStorageEnabled;
var inPrivateBrowsing = false;
if (isExtension) {
var pbs = Components.classes['@mozilla.org/privatebrowsing;1']
.getService(Components.interfaces.nsIPrivateBrowsingService);
inPrivateBrowsing = pbs.privateBrowsingEnabled;
}
function Settings(fingerprint) {
var database = null;
var index;
if (inPrivateBrowsing)
return false;
else if (isExtension)
database = Application.prefs.getValue(extPrefix + '.database', '{}');
else if (isLocalStorageEnabled)
if (isLocalStorageEnabled)
database = localStorage.getItem('database') || '{}';
else
return false;
@ -110,31 +98,20 @@ var Settings = (function SettingsClosure() {
index = database.files.push({fingerprint: fingerprint}) - 1;
this.file = database.files[index];
this.database = database;
if (isExtension)
Application.prefs.setValue(extPrefix + '.database',
JSON.stringify(database));
else if (isLocalStorageEnabled)
if (isLocalStorageEnabled)
localStorage.setItem('database', JSON.stringify(database));
}
Settings.prototype = {
set: function settingsSet(name, val) {
if (inPrivateBrowsing)
return false;
var file = this.file;
file[name] = val;
if (isExtension)
Application.prefs.setValue(extPrefix + '.database',
JSON.stringify(this.database));
else if (isLocalStorageEnabled)
if (isLocalStorageEnabled)
localStorage.setItem('database', JSON.stringify(this.database));
},
get: function settingsGet(name, defaultValue) {
if (inPrivateBrowsing)
return defaultValue;
else
return this.file[name] || defaultValue;
return this.file[name] || defaultValue;
}
};
@ -1011,7 +988,9 @@ window.addEventListener('load', function webViewerLoad(evt) {
}
var scale = ('scale' in params) ? params.scale : 0;
PDFView.open(params.file || kDefaultURL, parseFloat(scale));
var file = PDFJS.isFirefoxExtension ?
window.location.toString() : params.file || kDefaultURL;
PDFView.open(file, parseFloat(scale));
if (!window.File || !window.FileReader || !window.FileList || !window.Blob)
document.getElementById('fileInput').setAttribute('hidden', 'true');