X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebView.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebView.java;h=542a1baf0e296159b4d8b303b117764c13359063;hb=3326976f52dfb9ab06530128c8ef6bb4027b0391;hp=26237d7506af1cd5ee78c42c2e3fb7032031cced;hpb=64a6619a90b004521e549cd284f76d9a9d9e95f0;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java index 26237d75..542a1baf 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java @@ -1,6 +1,8 @@ /** * Copyright 2015-2017 Soren Stoutner . * + * Download cookie code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner . + * * This file is part of Privacy Browser . * * Privacy Browser is free software: you can redistribute it and/or modify @@ -152,10 +154,10 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN // It is `Boolean` instead of `boolean` because `applySettings()` needs to know if it is `null`. private Boolean javaScriptEnabled; - // `firstPartyCookiesEnabled` is used in `onCreate()`, `onCreateOptionsMenu()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `applySettings()`. + // `firstPartyCookiesEnabled` is used in `onCreate()`, `onCreateOptionsMenu()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, `onDownloadImage()`, `onDownloadFile()`, and `applySettings()`. private boolean firstPartyCookiesEnabled; - // `thirdPartyCookiesEnabled` used in `onCreate()`, `onCreateOptionsMenu()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `applySettings()`. + // `thirdPartyCookiesEnabled` used in `onCreate()`, `onCreateOptionsMenu()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, `onDownloadImage()`, `onDownloadFile()`, and `applySettings()`. private boolean thirdPartyCookiesEnabled; // `domStorageEnabled` is used in `onCreate()`, `onCreateOptionsMenu()`, `onOptionsItemSelected()`, and `applySettings()`. @@ -1482,6 +1484,13 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN // Parse `imageUrl`. DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(imageUrl)); + // Pass cookies to download manager if cookies are enabled. This is required to download item from websites that require a login. + if (firstPartyCookiesEnabled) { + String cookies = cookieManager.getCookie(imageUrl); + // In the HTTP request header, cookies are named `Cookie`. + downloadRequest.addRequestHeader("Cookie", cookies); + } + // Get the file name from `dialogFragment`. EditText downloadImageNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.download_image_name); String imageName = downloadImageNameEditText.getText().toString(); @@ -1514,6 +1523,13 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN // Parse `downloadUrl`. DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(downloadUrl)); + // Pass cookies to download manager if cookies are enabled. This is required to download item from websites that require a login. + if (firstPartyCookiesEnabled) { + String cookies = cookieManager.getCookie(downloadUrl); + // In the HTTP request header, cookies are named `Cookie`. + downloadRequest.addRequestHeader("Cookie", cookies); + } + // Get the file name from `dialogFragment`. EditText downloadFileNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.download_file_name); String fileName = downloadFileNameEditText.getText().toString();