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
3 changes: 0 additions & 3 deletions android/Gutenberg/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
<ID>MaxLineLength:RESTAPIRepositoryTest.kt$RESTAPIRepositoryTest$val rawJSON = """{"styles":[{"css":".theme-style{color:blue}","isGlobalStyles":true},{"css":".another{margin:0}","isGlobalStyles":false}]}"""</ID>
<ID>MaxLineLength:RequestBody.kt$Buffer$internal</ID>
<ID>NestedBlockDepth:EditorAssetsLibrary.kt$EditorAssetsLibrary$private fun cleanupOldCache()</ID>
<ID>NestedBlockDepth:FileCache.kt$FileCache$fun copyToCache(context: Context, uri: Uri, maxSizeBytes: Long = DEFAULT_MAX_FILE_SIZE): Uri?</ID>
<ID>NestedBlockDepth:FileCache.kt$FileCache$private fun getFileSize(context: Context, uri: Uri): Long?</ID>
<ID>NestedBlockDepth:FixtureTests.kt$FixtureTests$@Test fun `multipart parsing - all cases pass`()</ID>
<ID>NestedBlockDepth:FixtureTests.kt$FixtureTests$@Test fun `request parsing - all incremental cases pass`()</ID>
<ID>NestedBlockDepth:MultipartPart.kt$MultipartPart.Companion$fun parseChunked( source: RequestBody.FileBacked, boundary: String ): List&lt;MultipartPart&gt;</ID>
Expand All @@ -66,7 +64,6 @@
<ID>TooGenericExceptionCaught:EditorDependenciesSerializer.kt$EditorDependenciesSerializer$e: Exception</ID>
<ID>TooGenericExceptionCaught:EditorHTTPClient.kt$EditorHTTPClient$e: Exception</ID>
<ID>TooGenericExceptionCaught:EditorURLResponse.kt$EditorURLResponse$e: Exception</ID>
<ID>TooGenericExceptionCaught:FileCache.kt$FileCache$e: Exception</ID>
<ID>TooGenericExceptionCaught:GutenbergView.kt$GutenbergView$e: Exception</ID>
<ID>TooGenericExceptionCaught:HttpServer.kt$HttpServer$e: Exception</ID>
<ID>TooGenericExceptionCaught:LocalEditorAssetManifest.kt$LocalEditorAssetManifest$e: Exception</ID>
Expand Down
202 changes: 0 additions & 202 deletions android/Gutenberg/src/main/java/org/wordpress/gutenberg/FileCache.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.webkit.WebViewAssetLoader.AssetsPathHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONException
import org.json.JSONObject
import org.wordpress.gutenberg.model.EditorConfiguration
Expand Down Expand Up @@ -455,7 +454,12 @@ class GutenbergView : FrameLayout {
// Only use `acceptTypes` if it is not merely an empty string
val mimeTypes = fileChooserParams?.acceptTypes?.takeUnless { it.size == 1 && it[0].isEmpty() } ?: arrayOf("*/*")

val intent = Intent(Intent.ACTION_GET_CONTENT)
// Use ACTION_OPEN_DOCUMENT instead of ACTION_PICK_IMAGES to
// bypass the Android Photo Picker, which returns proxy URIs
// that trigger Chromium's ERR_UPLOAD_FILE_CHANGED error.
// ACTION_OPEN_DOCUMENT routes directly to DocumentsUI, which
// returns stable content URIs suitable for WebView uploads.
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.setType(mimeTypes[0])
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
intent.addCategory(Intent.CATEGORY_OPENABLE)
Expand All @@ -466,7 +470,7 @@ class GutenbergView : FrameLayout {

onFileChooserRequested?.let { callback ->
handler.post {
callback(Intent.createChooser(intent, "Select Files"), pickImageRequestCode)
callback(intent, pickImageRequestCode)
}
}
return true
Expand Down Expand Up @@ -953,48 +957,6 @@ class GutenbergView : FrameLayout {
} else null
}

/**
* Processes file URIs to work around Chrome ERR_UPLOAD_FILE_CHANGED bug.
*
* This method caches files from cloud storage providers (Google Drive, OneDrive, etc.)
* to local storage to prevent upload failures. Files from known-safe local providers
* (MediaStore, Downloads) are passed through unchanged for optimal performance.
*
* Apps should call this method with URIs from the file picker, then pass the result
* to filePathCallback.onReceiveValue() to complete the file selection.
*
* @param context Android context for file operations
* @param uris Array of URIs from file picker
* @return Array of processed URIs (cached for cloud URIs, original for local URIs)
*/
suspend fun processFileUris(context: Context, uris: Array<Uri?>?): Array<Uri?>? {
if (uris == null) return null

return withContext(Dispatchers.IO) {
uris.map { uri ->
if (uri == null) return@map null

if (uri.scheme == "content") {
if (FileCache.isKnownSafeLocalProvider(uri)) {
Log.i("GutenbergView", "Using local provider URI directly: $uri")
uri
} else {
val cachedUri = FileCache.copyToCache(context, uri)
if (cachedUri != null) {
Log.i("GutenbergView", "Copied content URI to cache: $uri -> $cachedUri")
cachedUri
} else {
Log.w("GutenbergView", "Failed to copy content URI to cache, using original: $uri")
uri
}
}
} else {
uri
}
}.toTypedArray()
}
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()
startNetworkMonitoring()
Expand All @@ -1011,7 +973,6 @@ class GutenbergView : FrameLayout {
errorView.animate().cancel()
webView.animate().cancel()
webView.stopLoading()
FileCache.clearCache(context)
contentChangeListener = null
historyChangeListener = null
featuredImageChangeListener = null
Expand Down
Loading
Loading