Skip to content

Commit

Permalink
Avoid a DRM connector crash (PP-1822).
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Oct 28, 2024
1 parent 2ba4463 commit b3201fa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
11 changes: 10 additions & 1 deletion README-CHANGES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<c:change date="2024-09-24T00:00:00+00:00" summary="Upgrade to Readium 2 3.0.0."/>
</c:changes>
</c:release>
<c:release date="2024-09-26T13:24:52+00:00" is-open="false" ticket-system="org.lyrasis.jira" version="6.4.0">
<c:release date="2024-09-26T00:00:00+00:00" is-open="false" ticket-system="org.lyrasis.jira" version="6.4.0">
<c:changes>
<c:change date="2024-09-26T00:00:00+00:00" summary="Add an attractive error page.">
<c:tickets>
Expand All @@ -157,6 +157,15 @@
</c:change>
</c:changes>
</c:release>
<c:release date="2024-10-28T10:18:54+00:00" is-open="true" ticket-system="org.lyrasis.jira" version="6.5.0">
<c:changes>
<c:change date="2024-10-28T10:18:54+00:00" summary="Avoid a DRM connector crash.">
<c:tickets>
<c:ticket id="PP-1822"/>
</c:tickets>
</c:change>
</c:changes>
</c:release>
</c:releases>
<c:ticket-systems>
<c:ticket-system default="true" id="org.lyrasis.jira" url="https://ebce-lyrasis.atlassian.net/browse/"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal class SR2WebViewClient(
private val errors =
ConcurrentHashMap<String, String>()

@Deprecated("Deprecated in Java")
override fun shouldOverrideUrlLoading(
view: WebView,
url: String,
Expand All @@ -60,30 +61,46 @@ internal class SR2WebViewClient(
view: WebView?,
request: WebResourceRequest?,
): WebResourceResponse? {
if (request != null) {
val url = request.url?.toString() ?: ""
try {
if (request != null) {
val url = request.url?.toString() ?: ""

if (url.startsWith(PREFIX_ASSETS)) {
return this.commandQueue.openAsset(url.removePrefix(PREFIX_ASSETS))
}
if (url.startsWith(PREFIX_ASSETS)) {
return this.commandQueue.openAsset(url.removePrefix(PREFIX_ASSETS))
}

if (url.startsWith(PREFIX_PUBLICATION)) {
return this.commandQueue.openPublicationResource(url.removePrefix(PREFIX_PUBLICATION))
}

if (url.startsWith(PREFIX_PUBLICATION)) {
return this.commandQueue.openPublicationResource(url.removePrefix(PREFIX_PUBLICATION))
if (url.endsWith("favicon.ico")) {
return WebResourceResponse(
"image/vnd.microsoft.icon",
null,
200,
"OK",
null,
faviconData.inputStream(),
)
}
}

if (url.endsWith("favicon.ico")) {
return WebResourceResponse(
"image/vnd.microsoft.icon",
null,
200,
"OK",
null,
faviconData.inputStream(),
)
return super.shouldInterceptRequest(view, request)
} catch (e: Throwable) {
/*
* Exceptions can be raised here by the DRM connector, amongst other things.
*/

this.logger.debug("shouldInterceptRequest: ", e)
val attributes = mutableMapOf<String, String>()
if (request != null) {
attributes["URL"] = request.url.toString()
}
return SR2CustomErrorPage.create(
attributes.toMap(),
e.message ?: e.javaClass.name,
).toResourceResponse()
}

return super.shouldInterceptRequest(view, request)
}

override fun onLoadResource(
Expand Down

0 comments on commit b3201fa

Please sign in to comment.