Use disconnect list for tracking images

pull/184/head
M66B 5 years ago
parent 8f482a95fe
commit 46374b3f34

@ -5787,6 +5787,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final Group grpDifferent = dview.findViewById(R.id.grpDifferent);
final Group grpOwner = dview.findViewById(R.id.grpOwner);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
ibDifferent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -5888,7 +5890,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean(uri.getHost() + ".confirm_link", !isChecked).apply();
}
});
@ -5957,7 +5958,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
uriTitle.getHost().equalsIgnoreCase(uri.getHost())
? View.GONE : View.VISIBLE);
List<String> categories = DisconnectBlacklist.getCategories(uri.getHost());
boolean disconnect_links = prefs.getBoolean("disconnect_links", true);
List<String> categories = null;
if (disconnect_links)
categories = DisconnectBlacklist.getCategories(uri.getHost());
if (categories != null)
tvDisconnectCategories.setText(TextUtils.join(", ", categories));
tvDisconnect.setVisibility(categories == null ? View.GONE : View.VISIBLE);

@ -143,6 +143,18 @@ public class DisconnectBlacklist {
}
}
static boolean isTracking(String host) {
if (host == null)
return false;
synchronized (map) {
List<String> result = map.get(host.toLowerCase(Locale.ROOT));
if (result == null || result.size() == 0)
return false;
return !result.contains("Content");
}
}
private static File getFile(Context context) {
return new File(context.getFilesDir(), "disconnect-blacklist.json");
}

@ -75,6 +75,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private ImageButton ibDisconnectBlacklist;
private Button btnDisconnectBlacklist;
private TextView tvDisconnectBlacklistTime;
private SwitchCompat swDisconnectLinks;
private SwitchCompat swDisconnectImages;
private Group grpSafeBrowsing;
@ -82,7 +84,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
"confirm_links", "browse_links", "confirm_images", "confirm_html",
"disable_tracking", "hide_timezone",
"pin", "biometrics", "biometrics_timeout",
"display_hidden", "secure", "safe_browsing"
"display_hidden", "secure", "safe_browsing",
"disconnect_links", "disconnect_images"
};
@Override
@ -111,6 +114,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
ibDisconnectBlacklist = view.findViewById(R.id.ibDisconnectBlacklist);
btnDisconnectBlacklist = view.findViewById(R.id.btnDisconnectBlacklist);
tvDisconnectBlacklistTime = view.findViewById(R.id.tvDisconnectBlacklistTime);
swDisconnectLinks = view.findViewById(R.id.swDisconnectLinks);
swDisconnectImages = view.findViewById(R.id.swDisconnectImages);
grpSafeBrowsing = view.findViewById(R.id.grpSafeBrowsing);
@ -285,6 +290,20 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
}
});
swDisconnectLinks.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("disconnect_links", checked).apply();
}
});
swDisconnectImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("disconnect_images", checked).apply();
}
});
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
return view;
@ -360,6 +379,9 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
Long time = DisconnectBlacklist.getTime(getContext());
DateFormat DF = SimpleDateFormat.getDateTimeInstance();
tvDisconnectBlacklistTime.setText(time == null ? null : DF.format(time));
swDisconnectLinks.setChecked(prefs.getBoolean("disconnect_links", true));
swDisconnectImages.setChecked(prefs.getBoolean("disconnect_images", false));
}
public static class FragmentDialogPin extends FragmentDialogBase {

@ -1412,6 +1412,9 @@ public class HtmlHelper {
}
static void removeTrackingPixels(Context context, Document document) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean disconnect_images = prefs.getBoolean("disconnect_images", false);
Drawable d = ContextCompat.getDrawable(context, R.drawable.baseline_my_location_24);
d.setTint(Helper.resolveColor(context, R.attr.colorWarning));
@ -1427,33 +1430,20 @@ public class HtmlHelper {
sb.append("data:image/png;base64,");
sb.append(Base64.encodeToString(bos.toByteArray(), Base64.NO_WRAP));
// Build list of allowed hosts
List<String> hosts = new ArrayList<>();
//for (Element img : document.select("img")) {
// String src = img.attr("src");
// if (!TextUtils.isEmpty(src) && !isTrackingPixel(img)) {
// Uri uri = Uri.parse(img.attr("src"));
// String host = uri.getHost();
// if (host != null && !hosts.contains(host))
// hosts.add(host);
// }
//}
// Images
for (Element img : document.select("img")) {
img.removeAttr("x-tracking");
String src = img.attr("src");
if (!TextUtils.isEmpty(src) && isTrackingPixel(img)) {
Uri uri = Uri.parse(src);
String host = uri.getHost();
if (host != null && !hosts.contains(host)) {
img.attr("src", sb.toString());
img.attr("alt", context.getString(R.string.title_legend_tracking_pixel));
img.attr("height", "24");
img.attr("width", "24");
img.attr("style", "display:block !important; width:24px !important; height:24px !important;");
img.attr("x-tracking", src);
}
if (TextUtils.isEmpty(src))
continue;
if (isTrackingPixel(img) ||
(disconnect_images && DisconnectBlacklist.isTracking(Uri.parse(src).getHost()))) {
img.attr("src", sb.toString());
img.attr("alt", context.getString(R.string.title_legend_tracking_pixel));
img.attr("height", "24");
img.attr("width", "24");
img.attr("style", "display:block !important; width:24px !important; height:24px !important;");
img.attr("x-tracking", src);
}
}
}

@ -328,6 +328,29 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnDisconnectBlacklist" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDisconnectLinks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:enabled="true"
android:text="@string/title_advanced_disconnect_links"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvDisconnectBlacklistTime"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDisconnectImages"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_disconnect_images"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/swDisconnectLinks"
app:switchPadding="12dp" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpSafeBrowsing"
android:layout_width="0dp"

@ -448,6 +448,8 @@
<string name="title_advanced_biometrics_timeout">Biometric authentication timeout</string>
<string name="title_advanced_safe_browsing" translatable="false">Google Safe browsing</string>
<string name="title_advanced_disconnect_blacklist" translatable="false">Disconnect\'s tracker protection lists</string>
<string name="title_advanced_disconnect_links">Use lists to warn about tracking links</string>
<string name="title_advanced_disconnect_images">Use lists to recognize tracking images</string>
<string name="title_advanced_sign_default">Sign by default</string>
<string name="title_advanced_encrypt_default">Encrypt by default</string>

Loading…
Cancel
Save