Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rdh resource fetcher plugin #149

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion js/Readium.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ define(['readium_shared_js/globals', 'text!version.json', 'jquery', 'underscore'


this.openPackageDocument = function(ebookURL, callback, openPageRequest) {

var resourcePluginKey='ResourceFetcherPlugin';
var plugins = ReadiumSDK.Plugins.getLoadedPlugins()
if (_.has(plugins, resourcePluginKey)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to test for whether or not a plugin is loaded, based on its registered name:
https://github.com/readium/readium-js/blob/develop/dev/index.js#L146

if (ReadiumSDK.reader.plugins.ResourceFetcherPlugin) {
...
}

(I'm not 100% sure that ReadiumSDK.reader is valid ... to be verified)

_resourceFetcher = plugins[resourcePluginKey].CustomResourceFetcher.openPackageDocument(ebookURL, callback, openPageRequest, openPackageDocument_)
return;
}

if (!(ebookURL instanceof Blob)
&& !(ebookURL instanceof File)
// && ebookURL.indexOf("file://") != 0
Expand Down
37 changes: 14 additions & 23 deletions js/epub-fetch/publication_fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip

// Non exploded EPUBs (i.e. zipped .epub documents) should be fetched in a programmatical manner:
_shouldConstructDomProgrammatically = !isEpubExploded;
console.log("_shouldConstructDomProgrammatically INIT: " + _shouldConstructDomProgrammatically);

createResourceFetcher(isEpubExploded, function(resourceFetcher) {

//NOTE: _resourceFetcher == resourceFetcher
Expand Down Expand Up @@ -95,18 +93,27 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip
}

function createResourceFetcher(isExploded, callback) {

var resourcePluginKey='ResourceFetcherPlugin';
var plugins = ReadiumSDK.Plugins.getLoadedPlugins()
if (_.has(plugins, resourcePluginKey)) {
_resourceFetcher = new plugins[resourcePluginKey].CustomResourceFetcher(self);
if (_resourceFetcher.shouldConstructDomProgrammatically)
_shouldConstructDomProgrammatically = _resourceFetcher.shouldConstructDomProgrammatically();
callback(_resourceFetcher);
return;
}

if (isExploded) {
console.log(' --- using PlainResourceFetcher');
_resourceFetcher = new PlainResourceFetcher(self);
callback(_resourceFetcher);
} else {
console.log(' --- using ZipResourceFetcher');
_resourceFetcher = new ZipResourceFetcher(self, jsLibRoot);
callback(_resourceFetcher);
}
}


// PUBLIC API

/**
Expand All @@ -133,9 +140,7 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip
* the base URI of their content document.
*/
this.shouldFetchMediaAssetsProgrammatically = function() {

var ret = _shouldConstructDomProgrammatically && !isExploded();
return ret;
return _shouldConstructDomProgrammatically;
};

this.getEbookURL = function() {
Expand Down Expand Up @@ -234,11 +239,7 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip

_packageFullPath = packageFullPath;
_packageDocumentAbsoluteUrl = _resourceFetcher.resolveURI(_packageFullPath);

console.debug("PACKAGE: ");
console.log(_packageFullPath);
console.log(_packageDocumentAbsoluteUrl);


if (packageFullPath && packageFullPath.charAt(0) != '/') {
packageFullPath = '/' + packageFullPath;
}
Expand Down Expand Up @@ -315,8 +316,6 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip
&&
new URI(relativeToPackagePath).scheme() !== '') {

console.log("shouldConstructDomProgrammatically EXTERNAL RESOURCE ...");

if (fetchMode === 'blob') {

var xhr = new XMLHttpRequest();
Expand All @@ -338,11 +337,6 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip
} else {

$.ajax({
// encoding: "UTF-8",
// mimeType: "text/plain; charset=UTF-8",
// beforeSend: function( xhr ) {
// xhr.overrideMimeType("text/plain; charset=UTF-8");
// },
isLocal: false,
url: relativeToPackagePath,
dataType: 'text', //https://api.jquery.com/jQuery.ajax/
Expand Down Expand Up @@ -400,8 +394,6 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip
var cipherReference = $('CipherReference', encryptedData);
cipherReference.each(function (index, CipherReference) {
var cipherReferenceURI = $(CipherReference).attr('URI');
console.log('Encryption/obfuscation algorithm ' + encryptionAlgorithm + ' specified for ' +
cipherReferenceURI);
encryptions[cipherReferenceURI] = encryptionAlgorithm;
});
});
Expand All @@ -422,7 +414,6 @@ define(['jquery', 'URIjs', './markup_parser', './plain_resource_fetcher', './zip
if (_encryptionHandler.isEncryptionSpecified()) {
// EPUBs that use encryption for any resources should be fetched in a programmatical manner:
_shouldConstructDomProgrammatically = true;
console.log("_shouldConstructDomProgrammatically ENCRYPTION ACTIVE: " + _shouldConstructDomProgrammatically);
}

settingFinishedCallback();
Expand Down
2 changes: 1 addition & 1 deletion readium-shared-js