Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ All notable changes to this project will be documented in this file. Take a look

### Added

* The new `HyperlinkNavigator.shouldFollowInternalLink(Link, LinkContext?)` allows you to handle footnotes according to your preference.
#### Navigator

* The new `HyperlinkNavigator.shouldfollowinternallink(Link, LinkContext?)` allows you to handle footnotes according to your preference.
* By default, the navigator now moves to the footnote content instead of displaying a pop-up as it did in version 2.x.

#### LCP

* You can use `LcpService.injectLicenseDocument()` to insert an LCPL into a package, if you downloaded it manually instead of using `LcpService.acquirePublication()`.


## [3.0.0-alpha.1]

Expand Down
16 changes: 16 additions & 0 deletions readium/lcp/src/main/java/org/readium/r2/lcp/LcpService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.readium.r2.shared.util.Try
import org.readium.r2.shared.util.asset.Asset
import org.readium.r2.shared.util.asset.AssetRetriever
import org.readium.r2.shared.util.format.Format
import org.readium.r2.shared.util.mediatype.MediaType

/**
* Service used to acquire and open publications protected with LCP.
Expand All @@ -49,6 +50,8 @@ public interface LcpService {
/**
* Acquires a protected publication from a standalone LCPL's bytes.
*
* License will be injected into the publication archive without explicitly calling
* [injectLicenseDocument].
* You can cancel the on-going acquisition by cancelling its parent coroutine context.
*
* @param onProgress Callback to follow the acquisition progress from 0.0 to 1.0.
Expand All @@ -61,6 +64,8 @@ public interface LcpService {
/**
* Acquires a protected publication from a standalone LCPL file.
*
* License will be injected into the publication archive without explicitly calling
* [injectLicenseDocument].
* You can cancel the on-going acquisition by cancelling its parent coroutine context.
*
* @param onProgress Callback to follow the acquisition progress from 0.0 to 1.0.
Expand Down Expand Up @@ -114,6 +119,17 @@ public interface LcpService {
allowUserInteraction: Boolean
): Try<LcpLicense, LcpError>

/**
* Injects a [licenseDocument] into the given [publicationFile] package.
*
* This is useful if you downloaded the publication yourself instead of using [acquirePublication].
*/
public suspend fun injectLicenseDocument(
licenseDocument: LicenseDocument,
publicationFile: File,
mediaType: MediaType? = null
): Try<Unit, LcpError>

/**
* Creates a [ContentProtection] instance which can be used with a Streamer to unlock
* LCP protected publications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ internal class LicensesService(
): ContentProtection =
LcpContentProtection(this, authentication, assetRetriever)

override suspend fun injectLicenseDocument(
licenseDocument: LicenseDocument,
publicationFile: File,
mediaType: MediaType?
): Try<Unit, LcpError> {
val format = assetRetriever.sniffFormat(publicationFile, FormatHints(mediaType))
.getOrElse {
Format(
specification = FormatSpecification(
ZipSpecification,
EpubSpecification,
LcpSpecification
),
mediaType = MediaType.EPUB,
fileExtension = FileExtension("epub")
)
}

return try {
val container = createLicenseContainer(publicationFile, format.specification)
container.write(licenseDocument)
Try.success(Unit)
} catch (e: Exception) {
Try.failure(LcpError.wrap(e))
}
}

override suspend fun acquirePublication(
lcpl: File,
onProgress: (Double) -> Unit
Expand Down