From: Soren Stoutner Date: Sun, 27 Sep 2020 00:38:28 +0000 (-0700) Subject: Use Content-Type to guess files extensions for downloads with unknown names. https... X-Git-Tag: v3.6~19 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=b870c254c26d19749fef9e3dbe9894f8f40c32eb;p=PrivacyBrowserAndroid.git Use Content-Type to guess files extensions for downloads with unknown names. https://redmine.stoutner.com/issues/548 --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 600db329..eff9c68d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -5411,7 +5411,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Get the file name from the content disposition. - String fileNameString = PrepareSaveDialog.getFileNameFromContentDisposition(this, contentDisposition, downloadUrl); + String fileNameString = PrepareSaveDialog.getFileNameFromHeaders(this, contentDisposition, mimetype, downloadUrl); // Instantiate the save dialog. DialogFragment saveDialogFragment = SaveWebpageDialog.saveWebpage(StoragePermissionDialog.SAVE_URL, downloadUrl, formattedFileSizeString, fileNameString, userAgent, diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java index 5bfae1e3..641bbe07 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java @@ -24,6 +24,7 @@ import android.content.Context; import android.net.Uri; import android.os.AsyncTask; import android.webkit.CookieManager; +import android.webkit.MimeTypeMap; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentManager; @@ -124,11 +125,18 @@ public class PrepareSaveDialog extends AsyncTask { formattedFileSize = context.getString(R.string.invalid_url); // Set the file name according to the URL. - fileNameString = getFileNameFromUrl(context, urlString); + fileNameString = getFileNameFromUrl(context, urlString, null); } else { // The response code is not an error message. - // Get the content length and disposition headers. + // Get the headers. String contentLengthString = httpUrlConnection.getHeaderField("Content-Length"); String contentDispositionString = httpUrlConnection.getHeaderField("Content-Disposition"); + String contentTypeString = httpUrlConnection.getContentType(); + + // Remove anything after the MIME type in the content type string. + if (contentTypeString.contains(";")) { + // Remove everything beginning with the `;`. + contentTypeString = contentTypeString.substring(0, contentTypeString.indexOf(";")); + } // Only process the content length string if it isn't null. if (contentLengthString != null) { @@ -140,7 +148,7 @@ public class PrepareSaveDialog extends AsyncTask { } // Get the file name string from the content disposition. - fileNameString = getFileNameFromContentDisposition(context, contentDispositionString, urlString); + fileNameString = getFileNameFromHeaders(context, contentDispositionString, contentTypeString, urlString); } } finally { // Disconnect the HTTP URL connection. @@ -151,7 +159,7 @@ public class PrepareSaveDialog extends AsyncTask { formattedFileSize = context.getString(R.string.invalid_url); // Set the file name according to the URL. - fileNameString = getFileNameFromUrl(context, urlString); + fileNameString = getFileNameFromUrl(context, urlString, null); } // Return the formatted file size and name as a string array. @@ -180,7 +188,7 @@ public class PrepareSaveDialog extends AsyncTask { // Content dispositions can contain other text besides the file name, and they can be in any order. // Elements are separated by semicolons. Sometimes the file names are contained in quotes. - public static String getFileNameFromContentDisposition(Context context, String contentDispositionString, String urlString) { + public static String getFileNameFromHeaders(Context context, String contentDispositionString, String contentTypeString, String urlString) { // Define a file name string. String fileNameString; @@ -208,20 +216,20 @@ public class PrepareSaveDialog extends AsyncTask { // Remove the last character. fileNameString = fileNameString.substring(0, fileNameString.length() - 1); } - } else { // The content disposition does not contain a filename. + } else { // The headers contain no useful information. // Get the file name string from the URL. - fileNameString = getFileNameFromUrl(context, urlString); + fileNameString = getFileNameFromUrl(context, urlString, contentTypeString); } } else { // The content disposition is null. // Get the file name string from the URL. - fileNameString = getFileNameFromUrl(context, urlString); + fileNameString = getFileNameFromUrl(context, urlString, contentTypeString); } // Return the file name string. return fileNameString; } - private static String getFileNameFromUrl(Context context, String urlString) { + private static String getFileNameFromUrl(Context context, String urlString, String contentTypeString) { // Convert the URL string to a URI. Uri uri = Uri.parse(urlString); @@ -231,6 +239,11 @@ public class PrepareSaveDialog extends AsyncTask { // Use a default file name if the last path segment is null. if (lastPathSegment == null) { lastPathSegment = context.getString(R.string.file); + + if (MimeTypeMap.getSingleton().hasMimeType(contentTypeString)) { // The content type contains a MIME type. + // Add the file extension that matches the MIME type. + lastPathSegment = lastPathSegment + "." + MimeTypeMap.getSingleton().getExtensionFromMimeType(contentTypeString); + } } // Return the last path segment as the file name. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 289ce656..3b1555c3 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -399,45 +399,45 @@ Über Privacy Browser Version - Versions-Code - Hardware - Marke: - Hersteller: - Modell: - Gerät: - Bootloader: - Radio: - Software - Android: - API - Build: - Sicherheits-Patch: - WebView-Anbieter: - WebView-Version: - Orbot: - I2P: - OpenKeychain: - Speicher-Nutzung - von der App genutzter Speicher: - für die App verfügbarer Speicher: - gesamter App-Speicher: - maximaler App-Speicher: - vom System genutzter Speicher: - für das System verfügbarer Speicher: - gesamter System-Speicher: - MiB - EasyList: - EasyPrivacy: - Fanboy’s Annoyance Sperrliste: - Fanboy’s Social Blocking Sperrliste: - UltraList: - UltraPrivacy: - Paket-Signatur - Aussteller-DN: - Subject DN: - Zertifikat-Version: - Seriennummer: - Signaturalgorithmus: + Versions-Code + Hardware + Marke: + Hersteller: + Modell: + Gerät: + Bootloader: + Radio: + Software + Android: + API + Build: + Sicherheits-Patch: + WebView-Anbieter: + WebView-Version: + Orbot: + I2P: + OpenKeychain: + Speicher-Nutzung + von der App genutzter Speicher: + für die App verfügbarer Speicher: + gesamter App-Speicher: + maximaler App-Speicher: + vom System genutzter Speicher: + für das System verfügbarer Speicher: + gesamter System-Speicher: + MiB + EasyList: + EasyPrivacy: + Fanboy’s Annoyance Sperrliste: + Fanboy’s Social Blocking Sperrliste: + UltraList: + UltraPrivacy: + Paket-Signatur + Aussteller-DN: + Subject DN: + Zertifikat-Version: + Seriennummer: + Signaturalgorithmus: Berechtigungen Datenschutzrichtlinie Changelog diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4ddc50e4..f1bdbab9 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -189,6 +189,7 @@ Guardar URL Guardar archivo + Guardar texto Guardar imagen Guardar logcat Nombre de archivo @@ -201,6 +202,7 @@ URL inválida OK Guardando archivo: + Procesando imagen… : Archivo guardado: Error guardando archivo: @@ -397,45 +399,46 @@ Acerca de Navegador Privado Versión - código de versión - Hardware - Marca: - Fabricante: - Modelo: - Dispositivo: - Cargador de arranque: - Radio: - Software - Android: - API - Versión de compilación: - Parche de seguridad: - Proveedor de WebView: - Versión de WebView: - Orbot: - I2P: - OpenKeychain: - Uso de memoria - Memoria conumida de la app: - Memoria disponible de la app: - Memoria total de la app: - Memoria máxima de la app: - Memoria consumida del sistema: - Memoria disponible del sistema: - Memoria total del sistema: - MiB - EasyList: - EasyPrivacy: - Lista molesta de Fanboy: - Lista de bloqueo social de Fanboy: - UltraList: - Ultra Privacidad: - Firma del paquete - DN del emisor: - DN del sujeto: - Versión del certificado: - Número de serie: - Algoritmo de firma: + código de versión + Hardware + Marca: + Fabricante: + Modelo: + Dispositivo: + Cargador de arranque: + Radio: + Software + Android: + API + Versión de compilación: + Parche de seguridad: + Proveedor de WebView: + Versión de WebView: + Orbot: + I2P: + OpenKeychain: + Uso de memoria + Memoria conumida de la app: + Memoria disponible de la app: + Memoria total de la app: + Memoria máxima de la app: + Memoria consumida del sistema: + Memoria disponible del sistema: + Memoria total del sistema: + MiB + EasyList: + EasyPrivacy: + Lista molesta de Fanboy: + Lista de bloqueo social de Fanboy: + UltraList: + Ultra Privacidad: + Firma del paquete + DN del emisor: + DN del sujeto: + Versión del certificado: + Número de serie: + Algoritmo de firma: + Información de la versión copiada. Permisos Política de privacidad Historial de cambios diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9b6f5bad..41d5b2b2 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -396,36 +396,36 @@ À propos Version - version du code - Matériel - Marque : - Constructeur : - Modèle : - Terminal : - Bootloader : - Radio : - Logiciel - Android : - API - Version : - MAJ de sécurité : - Fournisseur WebView : - Version WebView : - Orbot : - I2P : - OpenKeychain : - EasyList : - EasyPrivacy : - Fanboy’s Annoyance List : - Fanboy’s Social Blocking List : - UltraList : - UltraPrivacy : - Signature de paquets - Emetteur DN : - Sujet DN : - Version du certificat : - Numéro de série : - Algorithme de chiffrement : + version du code + Matériel + Marque : + Constructeur : + Modèle : + Terminal : + Bootloader : + Radio : + Logiciel + Android : + API + Version : + MAJ de sécurité : + Fournisseur WebView : + Version WebView : + Orbot : + I2P : + OpenKeychain : + EasyList : + EasyPrivacy : + Fanboy’s Annoyance List : + Fanboy’s Social Blocking List : + UltraList : + UltraPrivacy : + Signature de paquets + Emetteur DN : + Sujet DN : + Version du certificat : + Numéro de série : + Algorithme de chiffrement : Permissions Politique de confidentialité Journal des changements diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0056084c..3c040eb3 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -189,18 +189,22 @@ Salva URL Salva Archivio + Salva Testo Salva Immagine Salva il log Nome File PaginaWeb.mht PaginaWeb.png Privacy Browser Logcat.txt + Versione di Privacy Browser.txt + Versione di Privacy Browser.png File byte Dimensione sconosciuta URL non valida OK Salvataggio file: + Creazione immagine… : File salvato: Errore salvataggio file: @@ -396,45 +400,46 @@ Informazioni su Privacy Browser Versione - codice versione - Hardware - Brand: - Costruttore: - Modello: - Dispositivo: - Bootloader: - Radio: - Software - Android: - API - Build: - Patch si sicurezza: - Provider di WebView: - Versione di WebView: - Orbot: - I2P: - OpenKeychain: - Utilizzo della Memoria - Memoria utilizzata dalla App: - Memoria disponibile App: - Memoria totale App: - Memoria massima App: - Memoria di sistema utilizzata: - Memoria di sistema disponibile: - Memoria totale del sistema: - MiB - EasyList: - EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: - UltraList: - UltraPrivacy: - Firma del Pacchetto - Emittente: - Soggetto: - Versione del Certificato: - Numero di Serie: - Algoritmo di firma: + codice versione + Hardware + Brand: + Costruttore: + Modello: + Dispositivo: + Bootloader: + Radio: + Software + Android: + API + Build: + Patch si sicurezza: + Provider di WebView: + Versione di WebView: + Orbot: + I2P: + OpenKeychain: + Utilizzo della Memoria + Memoria utilizzata dalla App: + Memoria disponibile App: + Memoria totale App: + Memoria massima App: + Memoria di sistema utilizzata: + Memoria di sistema disponibile: + Memoria totale del sistema: + MiB + EasyList: + EasyPrivacy: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: + UltraList: + UltraPrivacy: + Firma del Pacchetto + Emittente: + Soggetto: + Versione del Certificato: + Numero di Serie: + Algoritmo di firma: + Info sulla Versione copiate. Autorizzazioni Privacy Policy Changelog diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index cd1b67cd..bea89298 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -394,45 +394,45 @@ Sobre o Privacy Browser Versão - Código da Versão - Hardware - Marca: - Fabricante: - Modelo: - Dispositivo: - Bootloader: - Radio: - Software - Android: - API - Build: - Patch de segurança: - Fornecedor WebView: - Versão do WebView: - Orbot: - I2P: - OpenKeychain: - Uso da Memória - Consumo da Memória do Aplicativo: - Memória Disponível do Aplicativo: - Memória Total do Aplicativo: - Memória Máxima do Aplicativo: - Memória Consumida do Sistema: - Memória Disponível do Sistema: - Memória Total do Sistema: - MiB - EasyList: - EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: - UltraList: - UltraPrivacy: - Assinatura do Pacote - DN do emissor: - Assunto DN: - Versão do certificado: - Número de série: - Algoritmo de Assinatura: + Código da Versão + Hardware + Marca: + Fabricante: + Modelo: + Dispositivo: + Bootloader: + Radio: + Software + Android: + API + Build: + Patch de segurança: + Fornecedor WebView: + Versão do WebView: + Orbot: + I2P: + OpenKeychain: + Uso da Memória + Consumo da Memória do Aplicativo: + Memória Disponível do Aplicativo: + Memória Total do Aplicativo: + Memória Máxima do Aplicativo: + Memória Consumida do Sistema: + Memória Disponível do Sistema: + Memória Total do Sistema: + MiB + EasyList: + EasyPrivacy: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: + UltraList: + UltraPrivacy: + Assinatura do Pacote + DN do emissor: + Assunto DN: + Versão do certificado: + Número de série: + Algoritmo de Assinatura: Permissões Política de Privacidade Changelog diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index aa704486..184a8d0c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -186,18 +186,22 @@ Сохранить URL Сохранить архив + Сохранить текст Сохранить изображение Сохранить logcat Имя файла Webpage.mht Webpage.png Privacy Browser Logcat.txt + Версия Privacy Browser.txt + Версия Privacy Browser.png Файл байтов неизвестный размер неправильный URL OK Сохранение файла: + Обработка изображения… : Файл сохранен: Ошибка сохранения файла: @@ -391,45 +395,46 @@ О Privacy Browser Версия - код версии - Оборудование - Бренд: - Производитель: - Модель: - Устройство: - Загрузчик: - Радио: - Программное обеспечение - Android: - API - Сборка: - Патч безопасности: - Провайдер WebView: - Версия WebView: - Orbot: - I2P: - OpenKeychain: - Использование памяти - Потребляемая приложением память: - Доступная приложению память: - Общая память приложения: - Максимальная память приложения: - Потребляемая системой память: - Доступная системе память: - Общая память системы: - МиБ - EasyList: - EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: - UltraList: - UltraPrivacy: - Подпись пакета - DN эмитента: - DN субъекта: - Версия сертификата: - Серийный номер: - Алгоритм подписи: + код версии + Оборудование + Бренд: + Производитель: + Модель: + Устройство: + Загрузчик: + Радио: + Программное обеспечение + Android: + API + Сборка: + Патч безопасности: + Провайдер WebView: + Версия WebView: + Orbot: + I2P: + OpenKeychain: + Использование памяти + Потребляемая приложением память: + Доступная приложению память: + Общая память приложения: + Максимальная память приложения: + Потребляемая системой память: + Доступная системе память: + Общая память системы: + МиБ + EasyList: + EasyPrivacy: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: + UltraList: + UltraPrivacy: + Подпись пакета + DN эмитента: + DN субъекта: + Версия сертификата: + Серийный номер: + Алгоритм подписи: + Информация о версии скопирована. Разрешения Политика конфиденциальности История изменений diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 883b46d6..b6570695 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -364,35 +364,35 @@ Privacy Browser Hakkında Versiyon - versiyon kodu - Donanım - Marka: - Üretici: - Model: - Cihaz: - Bootloader: - Donanım Yazılımı: - Yazılım - Android: - API - Derleme: - Güvenlik Yaması: - WebView Sağlayıcısı: - WebView Versiyonu: - Orbot: - OpenKeychain: - EasyList: - EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: - UltraList: - UltraPrivacy: - Paket İmzası - Yayınlayan DN: - Özne DN: - Sertifika Versiyonu: - Seri Numarası: - İmza Algoritması: + versiyon kodu + Donanım + Marka: + Üretici: + Model: + Cihaz: + Bootloader: + Donanım Yazılımı: + Yazılım + Android: + API + Derleme: + Güvenlik Yaması: + WebView Sağlayıcısı: + WebView Versiyonu: + Orbot: + OpenKeychain: + EasyList: + EasyPrivacy: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: + UltraList: + UltraPrivacy: + Paket İmzası + Yayınlayan DN: + Özne DN: + Sertifika Versiyonu: + Seri Numarası: + İmza Algoritması: İzinler Privacy Politikası Değişiklik Günlüğü diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9bf2ae80..517fb268 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -406,53 +406,52 @@ About Privacy Browser Version - version code - Hardware - Brand: - Manufacturer: - Model: - Device: - Bootloader: - Radio: - Software - Android: - API - Build: - Security Patch: - WebView Provider: - WebView Version: - Orbot: - I2P: - OpenKeychain: - Memory Usage - App Consumed Memory: - App Available Memory: - App Total Memory: - App Maximum Memory: - System Consumed Memory: - System Available Memory: - System Total Memory: - MiB - EasyList: - EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: - UltraList: - UltraPrivacy: - Package Signature - Issuer DN: - Subject DN: - Certificate Version: - Serial Number: - Signature Algorithm: + version code + Hardware + Brand: + Manufacturer: + Model: + Device: + Bootloader: + Radio: + Software + Android: + API + Build: + Security Patch: + WebView Provider: + WebView Version: + Orbot: + I2P: + OpenKeychain: + Memory Usage + App Consumed Memory: + App Available Memory: + App Total Memory: + App Maximum Memory: + System Consumed Memory: + System Available Memory: + System Total Memory: + MiB + EasyList: + EasyPrivacy: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: + UltraList: + UltraPrivacy: + Package Signature + Issuer DN: + Subject DN: + Certificate Version: + Serial Number: + Signature Algorithm: + Version info copied. Permissions Privacy Policy Changelog Licenses Contributors Links - Version info copied. - Email Privacy