Skip to content

Commit 0a2e948

Browse files
committed
[MBL-19721] Fix Studio video transcript download in Android
Intercept Instructure Media caption file downloads in CanvasWebView by checking for Authorization header to distinguish actual user-initiated downloads from resource loads during page initialization. refs: MBL-19721 test-plan: NONE
1 parent 3398d7a commit 0a2e948

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libs/pandautils/src/main/java/com/instructure/pandautils/views/CanvasWebView.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class CanvasWebView @JvmOverloads constructor(
226226
if (isInternalFileDownloadLink(url)) {
227227
val fileName = parseFileNameFromContentDisposition(contentDisposition, url)
228228
mediaDownloadCallback?.downloadInternalMedia(mimetype, url, fileName)
229+
} else if (isInstructureMediaDrmDownload(url)) {
230+
val fileName = parseFileNameFromContentDisposition(contentDisposition, url)
231+
mediaDownloadCallback?.downloadInternalMedia(mimetype, url, fileName)
229232
} else if (contentDisposition != null) {
230233
val fileName = parseFileNameFromContentDisposition(contentDisposition, url)
231234
canvasWebViewClientCallback?.openMediaFromWebView(mimetype, url, fileName)
@@ -425,6 +428,18 @@ class CanvasWebView @JvmOverloads constructor(
425428
mediaDownloadCallback?.downloadMedia("", url, fileName)
426429
view.post { stopLoading() } // Hack to stop loading the file in the WebView, since returning an empty response breaks what's being shown
427430
}
431+
432+
if (isInstructureMediaCaptionFile(url) &&
433+
request.hasGesture() &&
434+
request.requestHeaders.containsKey("Authorization") &&
435+
mediaDownloadCallback != null
436+
) {
437+
val fileName = parseFileNameFromContentDisposition(url, url)
438+
mediaDownloadCallback?.downloadInternalMedia(null, url, fileName)
439+
view.post { stopLoading() }
440+
return WebResourceResponse(null, null, null)
441+
}
442+
428443
return super.shouldInterceptRequest(view, request)
429444
}
430445

@@ -1006,6 +1021,14 @@ class CanvasWebView @JvmOverloads constructor(
10061021
return url.contains("canvadocs") && url.contains("/download/") && url.contains("single_use_token=")
10071022
}
10081023

1024+
private fun isInstructureMediaDrmDownload(url: String): Boolean {
1025+
return url.contains("instructuremedia.com") && url.contains("/downloadables/")
1026+
}
1027+
1028+
private fun isInstructureMediaCaptionFile(url: String): Boolean {
1029+
return url.contains("instructuremedia.com") && url.contains("/api/media_management/caption_files/")
1030+
}
1031+
10091032
fun containsLTI(html: String, encoding: String?): Boolean {
10101033
// BaseURL is set as Referer. Referer needed for some Vimeo videos to play
10111034
// Studio needs the protocol attached to the referrer, so use that if we're using Studio

0 commit comments

Comments
 (0)