X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebView.java;h=542a1baf0e296159b4d8b303b117764c13359063;hb=3326976f52dfb9ab06530128c8ef6bb4027b0391;hp=2e5503b639c752084ff3d11305defe99fd0b1613;hpb=e59f99e8ba2f66916186c13dabea9686e1b6f70f;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 2e5503b6..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()`. @@ -528,7 +530,7 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN // Create a variable to track if this is an ad server. boolean requestHostIsAdServer = false; - // Check all the subdomains of `requestHost` if it is not null. + // Check all the subdomains of `requestHost` if it is not `null`. if (requestHost != null) { while (requestHost.contains(".")) { if (adServersSet.contains(requestHost)) { @@ -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();