Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
10fe08e
Revisit factories
qnga Oct 24, 2023
8fa923c
WIP
qnga Oct 24, 2023
8244e92
WIP
qnga Oct 26, 2023
0d433c4
WIP
qnga Oct 29, 2023
d35bd5c
WIP
qnga Oct 31, 2023
dec440a
Refactor ArchiveFactory
qnga Nov 3, 2023
9b80755
Refactor container and resource
qnga Nov 6, 2023
524d9cc
Various
qnga Nov 15, 2023
356cf8a
Introduce HttpStatus
qnga Nov 16, 2023
14b6f48
Remove entries
qnga Nov 16, 2023
06d64f7
Get rid of Other errors
qnga Nov 17, 2023
88ffc01
Update error handling in testapp
qnga Nov 17, 2023
dbd73a5
Lint
qnga Nov 17, 2023
2ce91e0
Refactor LcpException and move UserError to test-app
qnga Nov 19, 2023
6d5b5a3
Various changes
qnga Nov 20, 2023
69d9dd9
Fix uses of Try.assertSuccess
qnga Nov 20, 2023
e720ebc
Fix PsPDFKit errors
qnga Nov 20, 2023
7053cd3
Small fixes
qnga Nov 20, 2023
e25514d
Small fixes
qnga Nov 20, 2023
d89a6dd
Fix sniffing and AssetRetriever
qnga Nov 20, 2023
b683e06
Fix SingleResourceContainer
qnga Nov 20, 2023
c99001e
Optimize ZIP sniffing
qnga Nov 20, 2023
5257109
Remove ReadError.Other
qnga Nov 21, 2023
7d55985
Add media type and filename properties on Resource
qnga Nov 21, 2023
3c77ec1
Fix
qnga Nov 21, 2023
6b200b1
Remove MediaTypeRetriever from EpubParser
qnga Nov 23, 2023
efb5671
Clarify and move MediaTypeRetriever
qnga Nov 23, 2023
1d85516
Refactor ArchiveFactory
qnga Nov 23, 2023
2df5555
Introduce BlobMediaTypeRetriever
qnga Nov 23, 2023
d92f49d
Remove passwords from ArchiveFactory
qnga Nov 27, 2023
6b3688c
Cosmetic change
qnga Nov 27, 2023
58a9846
Remove Resource.mediaType()
qnga Nov 27, 2023
1b167a4
Fix most of the tests
qnga Nov 28, 2023
268c3f5
Cosmetic changes
qnga Nov 28, 2023
8ec36a8
Cosmetic changes
qnga Nov 29, 2023
026c4d7
Merge branch 'v3' into refactor-errors
qnga Nov 29, 2023
7b677d8
Various fixes
qnga Nov 29, 2023
4b6b77f
Renaming
qnga Nov 29, 2023
881772e
Naming
qnga Nov 29, 2023
41ebe8f
Moves
qnga Nov 29, 2023
faea60c
Cosmetic changes
qnga Nov 29, 2023
c0d3f86
Cosmetic changes
qnga Nov 29, 2023
8f4002f
Small fixes
qnga Nov 29, 2023
fd211ad
Remove FLAG_SECURE
mickael-menu Nov 30, 2023
1d7f896
Fix ReadableInputStream lifecycle issues
qnga Nov 30, 2023
57d5183
Rename OverflowableNavigator
qnga Nov 30, 2023
6755380
Cosmetic changes
qnga Nov 30, 2023
1b05cea
Move media type retriever back to `mediatype` package
mickael-menu Dec 1, 2023
61db1b1
Various fixes and cosmetic changes
qnga Dec 5, 2023
cb567c9
Minor changes
qnga Dec 6, 2023
16eca61
Fix SearchService errors
qnga Dec 6, 2023
2adb5c8
Fix ExoMediaPlayer
qnga Dec 6, 2023
101017f
Refactor BufferingResource
qnga Dec 6, 2023
b25739b
Cosmetic changes
qnga Dec 6, 2023
296c722
Fix LcpFallbackContentProtection
qnga Dec 6, 2023
10a1f5d
Improve MediaTypeRetriever hint sniffing efficiency
qnga Dec 6, 2023
678238b
Cosmetic changes
qnga Dec 6, 2023
77f11a7
Reorganization
qnga Dec 6, 2023
db48f8d
Doc
qnga Dec 6, 2023
632c8ca
Cosmetic changes
qnga Dec 6, 2023
fce3d33
Cosmetic changes
qnga Dec 6, 2023
ec16df2
Refactor decoding
qnga Dec 7, 2023
14a1456
Clean up decoding
qnga Dec 8, 2023
565df38
Cosmetic changes
qnga Dec 8, 2023
379bac0
Refactor user errors in testapp
qnga Dec 8, 2023
cc19717
Fix DownloadManager errors
qnga Dec 8, 2023
7100890
Small fix
qnga Dec 8, 2023
ce4dbd5
Small fix
qnga Dec 8, 2023
f65b677
Various changes
qnga Dec 8, 2023
c8e0066
Minor changes
mickael-menu Dec 10, 2023
e225659
Keep `HttpRequest.Builder.url` immutable
mickael-menu Dec 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import org.readium.r2.shared.extensions.tryOrNull
import org.readium.r2.shared.publication.Link
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.util.Url
import org.readium.r2.shared.util.data.readAsString
import org.readium.r2.shared.util.data.decodeString
import org.readium.r2.shared.util.flatMap
import org.readium.r2.shared.util.resource.Resource
import org.readium.r2.shared.util.toUrl
import org.readium.r2.shared.util.use
Expand Down Expand Up @@ -349,7 +350,8 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
tryOrLog {
listener?.resourceAtUrl(absoluteUrl)
?.use { res ->
res.readAsString()
res.read()
.flatMap { it.decodeString() }
.map { Jsoup.parse(it) }
.getOrNull()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import org.readium.r2.shared.util.Try
import org.readium.r2.shared.util.Url
import org.readium.r2.shared.util.asset.Asset
import org.readium.r2.shared.util.asset.ContainerAsset
import org.readium.r2.shared.util.data.DecodeError
import org.readium.r2.shared.util.data.ReadError
import org.readium.r2.shared.util.data.readAsXml
import org.readium.r2.shared.util.getOrElse
import org.readium.r2.shared.util.data.decodeXml
import org.readium.r2.shared.util.data.readDecodeOrElse
import org.readium.r2.shared.util.mediatype.MediaType

/**
Expand Down Expand Up @@ -68,30 +67,24 @@ public class AdeptFallbackContentProtection : ContentProtection {
}

asset.container[Url("META-INF/encryption.xml")!!]
?.readAsXml()
?.getOrElse {
when (it) {
is DecodeError.Decoding ->
return Try.success(false)
is DecodeError.Reading ->
return Try.failure(it.cause)
}
}?.get("EncryptedData", EpubEncryption.ENC)
?.readDecodeOrElse(
decode = { it.decodeXml() },
recoverRead = { return Try.success(false) },
recoverDecode = { return Try.success(false) }
)
?.get("EncryptedData", EpubEncryption.ENC)
?.flatMap { it.get("KeyInfo", EpubEncryption.SIG) }
?.flatMap { it.get("resource", "http://ns.adobe.com/adept") }
?.takeIf { it.isNotEmpty() }
?.let { return Try.success(true) }

return asset.container.get(Url("META-INF/rights.xml")!!)
?.readAsXml()
?.getOrElse {
when (it) {
is DecodeError.Decoding ->
return Try.success(false)
is DecodeError.Reading ->
return Try.failure(it.cause)
}
}?.takeIf { it.namespace == "http://ns.adobe.com/adept" }
return asset.container[Url("META-INF/rights.xml")!!]
?.readDecodeOrElse(
decode = { it.decodeXml() },
recoverRead = { return Try.success(false) },
recoverDecode = { return Try.success(false) }
)
?.takeIf { it.namespace == "http://ns.adobe.com/adept" }
?.let { Try.success(true) }
?: Try.success(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import org.readium.r2.shared.util.asset.Asset
import org.readium.r2.shared.util.asset.ContainerAsset
import org.readium.r2.shared.util.asset.ResourceAsset
import org.readium.r2.shared.util.data.Container
import org.readium.r2.shared.util.data.DecodeError
import org.readium.r2.shared.util.data.ReadError
import org.readium.r2.shared.util.data.readAsRwpm
import org.readium.r2.shared.util.data.readAsXml
import org.readium.r2.shared.util.getOrElse
import org.readium.r2.shared.util.data.decodeRwpm
import org.readium.r2.shared.util.data.decodeXml
import org.readium.r2.shared.util.data.readDecodeOrElse
import org.readium.r2.shared.util.mediatype.MediaType
import org.readium.r2.shared.util.resource.Resource

Expand Down Expand Up @@ -95,16 +94,11 @@ public class LcpFallbackContentProtection : ContentProtection {

private suspend fun hasLcpSchemeInManifest(container: Container<Resource>): Try<Boolean, ReadError> {
val manifest = container[Url("manifest.json")!!]
?.readAsRwpm()
?.getOrElse {
when (it) {
is DecodeError.Reading ->
return Try.failure(it.cause)
is DecodeError.Decoding ->
return Try.success(false)
}
}
?: return Try.success(false)
?.readDecodeOrElse(
decode = { it.decodeRwpm() },
recoverRead = { return Try.success(false) },
recoverDecode = { return Try.success(false) }
) ?: return Try.success(false)

val manifestHasLcpScheme = manifest
.readingOrder
Expand All @@ -115,16 +109,10 @@ public class LcpFallbackContentProtection : ContentProtection {

private suspend fun hasLcpSchemeInEncryptionXml(container: Container<Resource>): Try<Boolean, ReadError> {
val encryptionXml = container[Url("META-INF/encryption.xml")!!]
?.readAsXml()
?.getOrElse {
when (it) {
is DecodeError.Reading ->
return Try.failure(it.cause)
is DecodeError.Decoding ->
return Try.failure(ReadError.Decoding(it.cause))
}
}
?: return Try.success(false)
?.readDecodeOrElse(
decode = { it.decodeXml() },
recover = { return Try.failure(it) }
) ?: return Try.success(false)

val hasLcpScheme = encryptionXml
.get("EncryptedData", EpubEncryption.ENC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import org.readium.r2.shared.publication.ServiceFactory
import org.readium.r2.shared.publication.firstWithRel
import org.readium.r2.shared.util.Url
import org.readium.r2.shared.util.data.Container
import org.readium.r2.shared.util.data.readAsBitmap
import org.readium.r2.shared.util.data.decodeBitmap
import org.readium.r2.shared.util.flatMap
import org.readium.r2.shared.util.resource.Resource

/**
Expand Down Expand Up @@ -79,7 +80,9 @@ internal class ResourceCoverService(
val resource = container[coverUrl]
?: return null

return resource.readAsBitmap()
return resource
.read()
.flatMap { it.decodeBitmap() }
.getOrNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import org.readium.r2.shared.publication.services.positionsByReadingOrder
import org.readium.r2.shared.util.DebugError
import org.readium.r2.shared.util.Language
import org.readium.r2.shared.util.Url
import org.readium.r2.shared.util.data.readAsString
import org.readium.r2.shared.util.data.decodeString
import org.readium.r2.shared.util.flatMap
import org.readium.r2.shared.util.getOrElse
import org.readium.r2.shared.util.mediatype.MediaType
import org.readium.r2.shared.util.resource.Resource
Expand Down Expand Up @@ -155,11 +156,14 @@ public class HtmlResourceContentIterator internal constructor(
private suspend fun parseElements(): ParsedElements =
withContext(Dispatchers.Default) {
val document = resource.use { res ->
val html = res.readAsString().getOrElse {
val error = DebugError("Failed to read HTML resource", it.cause)
Timber.w(error.toDebugDescription())
return@withContext ParsedElements()
}
val html = res
.read()
.flatMap { it.decodeString() }
.getOrElse {
val error = DebugError("Failed to read HTML resource", it.cause)
Timber.w(error.toDebugDescription())
return@withContext ParsedElements()
}

Jsoup.parse(html)
}
Expand Down
Loading