From: Soren Stoutner Date: Thu, 15 Sep 2016 06:55:33 +0000 (-0700) Subject: Use the last path segment in the URLs as the default download file name if `Content... X-Git-Tag: v1.10~1 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=e8bcccda781e0aa65ee4cc11428f3e99dc400015;p=PrivacyBrowserAndroid.git Use the last path segment in the URLs as the default download file name if `Content-Disposition` is `null`. --- diff --git a/app/src/main/assets/en/guide_tor.html b/app/src/main/assets/en/guide_tor.html index 1ce0d59d..bc56b69c 100644 --- a/app/src/main/assets/en/guide_tor.html +++ b/app/src/main/assets/en/guide_tor.html @@ -70,7 +70,7 @@ make a purchase, every address that items are shipped to, and the GPS metadata of every picture that is uploaded to the internet. They build a profile of a user's age, gender, marital status, address, political affiliations, religious affiliations, family circumstance, number of pets, and everything else they can get their hands on. - They even buy up databases of credit card usage at stores, so they can track the off-line purchasing patterns of the users + They even buy up databases of credit card usage at local stores, so they can track the off-line purchasing patterns of the users in their profiles. Because they already have much more accurate address information about a user than an IP address discloses, Tor provides no real privacy protection against mega corporations.

diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java index 4bdc879a..a35091fb 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java +++ b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; +import android.net.Uri; import android.os.Bundle; // `android.support.v7.app.AlertDialog` uses more of the horizontal screen real estate versus `android.app.AlertDialog's` smaller width. import android.support.v7.app.AlertDialog; @@ -45,12 +46,11 @@ public class DownloadFile extends DialogFragment { // Create `argumentsBundle`. Bundle argumentsBundle = new Bundle(); - // If `contentDisposition` is empty, use Android's standard string of `downloadfile.bin`. String fileNameString; - if (contentDisposition.isEmpty()) { - fileNameString = "downloadfile.bin"; - } else { - // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending one character before the end of `contentDisposition`. + if (contentDisposition.isEmpty()) { // If `contentDisposition` is empty, use the last path segment of the URL as the file name. + Uri downloadUri = Uri.parse(urlString); + fileNameString = downloadUri.getLastPathSegment(); + } else { // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending one character before the end of `contentDisposition`. fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10, contentDisposition.length() - 1); } @@ -103,7 +103,7 @@ public class DownloadFile extends DialogFragment { // Use `AlertDialog.Builder` to create the `AlertDialog`. `R.style.lightAlertDialog` formats the color of the button text. AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); - dialogBuilder.setTitle(R.string.file_download); + dialogBuilder.setTitle(R.string.save_as); // The parent view is `null` because it will be assigned by `AlertDialog`. dialogBuilder.setView(layoutInflater.inflate(R.layout.download_file_dialog, null)); diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index 54f6d8ff..87f30afe 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -361,7 +361,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { // Show the `DownloadFile` `AlertDialog` and name this instance `@string/download`. DialogFragment downloadFileDialogFragment = DownloadFile.fromUrl(url, contentDisposition, contentLength); - downloadFileDialogFragment.show(getFragmentManager(), getResources().getString(R.string.file_download)); + downloadFileDialogFragment.show(getFragmentManager(), getResources().getString(R.string.download)); } }); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b6a969d..51886aad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,7 +45,7 @@ DOM Storage deleted Open Navigation Drawer Close Navigation Drawer - File Download + Save as File name Download