[Adblock Plus 2.0]
-! Version: 1
+! Version: 2
! Title: UltraPrivacy
-! Last modified: 25 Jul 2018 20:41 UTC
+! Last modified: 22 May 2019 18:11 UTC
! Expires: 90 days (update frequency)
! Homepage: https://www.stoutner.com/privacy-browser/blocklists/ultraprivacy/
! Licence: GPLv3+ http://www.gnu.org/licenses/gpl-3.0.html
!
! I can't imagine that anything that includes `analytics` is good for your privacy. https://redmine.stoutner.com/issues/312.
analytics
+! Block Google Tag Services. https://redmine.stoutner.com/issues/449
+googletagservices
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.adapters.WebViewPagerAdapter;
import com.stoutner.privacybrowser.asynctasks.GetHostIpAddresses;
+import com.stoutner.privacybrowser.asynctasks.PopulateBlocklists;
import com.stoutner.privacybrowser.dialogs.AdConsentDialog;
import com.stoutner.privacybrowser.dialogs.CreateBookmarkDialog;
import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolderDialog;
// AppCompatActivity from android.support.v7.app.AppCompatActivity must be used to have access to the SupportActionBar until the minimum API is >= 21.
public class MainWebViewActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener,
DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, DownloadLocationPermissionDialog.DownloadLocationPermissionDialogListener, EditBookmarkDialog.EditBookmarkListener,
- EditBookmarkFolderDialog.EditBookmarkFolderListener, NavigationView.OnNavigationItemSelectedListener, WebViewTabFragment.NewTabListener {
+ EditBookmarkFolderDialog.EditBookmarkFolderListener, NavigationView.OnNavigationItemSelectedListener, PopulateBlocklists.PopulateBlocklistsListener, WebViewTabFragment.NewTabListener {
// `orbotStatus` is public static so it can be accessed from `OrbotProxyHelper`. It is also used in `onCreate()`, `onResume()`, and `applyProxyThroughOrbot()`.
public static String orbotStatus;
// The options menu is set in `onCreateOptionsMenu()` and used in `onOptionsItemSelected()`, `updatePrivacyIcons()`, and `initializeWebView()`.
private Menu optionsMenu;
- // The blocklists are populated in `onCreate()` and accessed from `initializeWebView()`.
+ // The blocklists are populated in `finishedPopulatingBlocklists()` and accessed from `initializeWebView()`.
private ArrayList<List<String[]>> easyList;
private ArrayList<List<String[]>> easyPrivacy;
private ArrayList<List<String[]>> fanboysAnnoyanceList;
// Register `orbotStatusBroadcastReceiver` on `this` context.
this.registerReceiver(orbotStatusBroadcastReceiver, new IntentFilter("org.torproject.android.intent.action.STATUS"));
- // Instantiate the blocklist helper.
- BlockListHelper blockListHelper = new BlockListHelper();
-
- // Parse the block lists.
- easyList = blockListHelper.parseBlockList(getAssets(), "blocklists/easylist.txt");
- easyPrivacy = blockListHelper.parseBlockList(getAssets(), "blocklists/easyprivacy.txt");
- fanboysAnnoyanceList = blockListHelper.parseBlockList(getAssets(), "blocklists/fanboy-annoyance.txt");
- fanboysSocialList = blockListHelper.parseBlockList(getAssets(), "blocklists/fanboy-social.txt");
- ultraPrivacy = blockListHelper.parseBlockList(getAssets(), "blocklists/ultraprivacy.txt");
-
// Get handles for views that need to be modified.
DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
NavigationView navigationView = findViewById(R.id.navigationview);
}
});
- // Add the first tab.
- addTab(null);
-
// Set the bookmarks drawer resources according to the theme. This can't be done in the layout due to compatibility issues with the `DrawerLayout` support widget.
// The deprecated `getResources().getDrawable()` must be used until the minimum API >= 21 and and `getResources().getColor()` must be used until the minimum API >= 23.
if (darkTheme) {
// Destroy the bare WebView.
bareWebView.destroy();
+
+ // Populate the blocklists.
+ new PopulateBlocklists(this, this).execute();
}
@Override
assert inputMethodManager != null;
// Hide the keyboard.
- inputMethodManager.hideSoftInputFromWindow(currentWebView.getWindowToken(), 0);
+ inputMethodManager.hideSoftInputFromWindow(toolbar.getWindowToken(), 0);
}
private void applyAppSettings() {
return url;
}
+ public void finishedPopulatingBlocklists(ArrayList<ArrayList<List<String[]>>> combinedBlocklists) {
+ // Store the blocklists.
+ easyList = combinedBlocklists.get(0);
+ easyPrivacy = combinedBlocklists.get(1);
+ fanboysAnnoyanceList = combinedBlocklists.get(2);
+ fanboysSocialList = combinedBlocklists.get(3);
+ ultraPrivacy = combinedBlocklists.get(4);
+
+ // Add the first tab.
+ addNewTab("");
+ }
+
public void addTab(View view) {
// Add a new tab with a blank URL.
addNewTab("");
// Get a handle for the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- // Get the relevant preferences.
- boolean downloadWithExternalApp = sharedPreferences.getBoolean("download_with_external_app", false);
-
// Initialize the favorite icon.
nestedScrollWebView.initializeFavoriteIcon();
// Allow the downloading of files.
nestedScrollWebView.setDownloadListener((String downloadUrl, String userAgent, String contentDisposition, String mimetype, long contentLength) -> {
// Check if the download should be processed by an external app.
- if (downloadWithExternalApp) { // Download with an external app.
+ if (sharedPreferences.getBoolean("download_with_external_app", false)) { // Download with an external app.
// Create a download intent. Not specifying the action type will display the maximum number of options.
Intent downloadIntent = new Intent();
--- /dev/null
+/*
+ * Copyright © 2019 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
+ *
+ * Privacy Browser is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.stoutner.privacybrowser.asynctasks;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.AsyncTask;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.stoutner.privacybrowser.R;
+import com.stoutner.privacybrowser.helpers.BlockListHelper;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
+
+import androidx.appcompat.widget.Toolbar;
+
+public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayList<List<String[]>>>> {
+ // The public interface is used to send information back to the parent activity.
+ public interface PopulateBlocklistsListener {
+ void finishedPopulatingBlocklists(ArrayList<ArrayList<List<String[]>>> combinedBlocklists);
+ }
+
+ // Declare a populate blocklists listener.
+ private PopulateBlocklistsListener populateBlocklistsListener;
+
+ // Declare weak references for the activity and context.
+ private WeakReference<Context> contextWeakReference;
+ private WeakReference<Activity> activityWeakReference;
+
+ public PopulateBlocklists(Context context, Activity activity) {
+ // Populate the weak reference to the context.
+ contextWeakReference = new WeakReference<>(context);
+
+ // Populate the weak reference to the activity.
+ activityWeakReference = new WeakReference<>(activity);
+
+ // Get a handle for the populate blocklists listener from the launching activity.
+ populateBlocklistsListener = (PopulateBlocklistsListener) context;
+ }
+
+ @Override
+ protected ArrayList<ArrayList<List<String[]>>> doInBackground(Void... none) {
+ // Get a handle for the context.
+ Context context = contextWeakReference.get();
+
+ // Instantiate the blocklist helper.
+ BlockListHelper blockListHelper = new BlockListHelper();
+
+ // Create a combined array list.
+ ArrayList<ArrayList<List<String[]>>> combinedBlocklists = new ArrayList<>();
+
+ // Load the blocklists if the context still exists.
+ if (context != null) {
+ // Update the progress.
+ publishProgress(context.getString(R.string.loading_easylist));
+
+ // Populate EasyList.
+ ArrayList<List<String[]>> easyList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/easylist.txt");
+
+
+ // Update the progress.
+ publishProgress(context.getString(R.string.loading_easyprivacy));
+
+ // Populate EasyPrivacy.
+ ArrayList<List<String[]>> easyPrivacy = blockListHelper.parseBlockList(context.getAssets(), "blocklists/easyprivacy.txt");
+
+
+ // Update the progress.
+ publishProgress(context.getString(R.string.loading_fanboys_annoyance_list));
+
+ // Populate Fanboy's Annoyance List.
+ ArrayList<List<String[]>> fanboysAnnoyanceList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/fanboy-annoyance.txt");
+
+
+ // Update the progress.
+ publishProgress(context.getString(R.string.loading_fanboys_social_blocking_list));
+
+ // Populate Fanboy's Social Blocking List.
+ ArrayList<List<String[]>> fanboysSocialList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/fanboy-social.txt");
+
+
+ // Update the progress.
+ publishProgress(context.getString(R.string.loading_ultraprivacy));
+
+ // Populate UltraPrivacy.
+ ArrayList<List<String[]>> ultraPrivacy = blockListHelper.parseBlockList(context.getAssets(), "blocklists/ultraprivacy.txt");
+
+
+ // Populate the combined array list.
+ combinedBlocklists.add(easyList);
+ combinedBlocklists.add(easyPrivacy);
+ combinedBlocklists.add(fanboysAnnoyanceList);
+ combinedBlocklists.add(fanboysSocialList);
+ combinedBlocklists.add(ultraPrivacy);
+ }
+
+ // Return the combined array list.
+ return combinedBlocklists;
+ }
+
+ @Override
+ protected void onProgressUpdate(String... loadingBlocklist) {
+ // Get a handle for the activity.
+ Activity activity = activityWeakReference.get();
+
+ // Abort if the activity is gone.
+ if ((activity == null) || activity.isFinishing()) {
+ return;
+ }
+
+ // Get a handle for the loading blocklist text view.
+ TextView loadingBlocklistTextView = activity.findViewById(R.id.loading_blocklist_textview);
+
+ // Update the status.
+ loadingBlocklistTextView.setText(loadingBlocklist[0]);
+ }
+
+ @Override
+ protected void onPostExecute(ArrayList<ArrayList<List<String[]>>> combinedBlocklists) {
+ // Get a handle for the activity.
+ Activity activity = activityWeakReference.get();
+
+ // Abort if the activity is gone.
+ if ((activity == null) || activity.isFinishing()) {
+ return;
+ }
+
+ // Get handles for the views.
+ Toolbar toolbar = activity.findViewById(R.id.toolbar);
+ LinearLayout tabsLinearLayout = activity.findViewById(R.id.tabs_linearlayout);
+ RelativeLayout loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout);
+
+ // Show the toolbar and tabs linear layout.
+ toolbar.setVisibility(View.VISIBLE);
+ tabsLinearLayout.setVisibility(View.VISIBLE);
+
+ // Hide the loading blocklists screen.
+ loadingBlocklistsRelativeLayout.setVisibility(View.GONE);
+
+ // Add the first tab.
+ populateBlocklistsListener.finishedPopulatingBlocklists(combinedBlocklists);
+ }
+}
// Run the default commands.
super.onAttach(context);
- // Get a handle for `CreateBookmarkListener` from the launching context.
+ // Get a handle for the create bookmark listener from the launching context.
createBookmarkListener = (CreateBookmarkListener) context;
}
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
- app:layout_scrollFlags="scroll|enterAlways|snap" />
+ app:layout_scrollFlags="scroll|enterAlways|snap"
+ android:visibility="gone" />
<!-- The find on page linear layout. It is initially `visibility="gone"`. -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
- app:layout_scrollFlags="scroll|enterAlways|snap" >
+ app:layout_scrollFlags="scroll|enterAlways|snap"
+ android:visibility="gone" >
<ImageView
android:layout_height="wrap_content"
<include layout="@layout/bookmarks_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
- <!-- `The full screen video frame layout is used to display full screen videos. It is initially `android:visibility="gone"` to hide it from view. -->
+ <!-- The full screen video frame layout is used to display full screen videos. It is initially `android:visibility="gone"` to hide it from view. -->
<FrameLayout
android:id="@+id/full_screen_video_framelayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone" />
+
+ <!-- The loading blocklists relative layout displays when the app first starts. It is hidden once the blocklists are populated. -->
+ <RelativeLayout
+ android:id="@+id/loading_blocklists_relativelayout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ImageView
+ android:id="@+id/privacy_browser_logo"
+ android:layout_height="256dp"
+ android:layout_width="256dp"
+ android:layout_centerInParent="true"
+ android:src="@drawable/privacy_browser_foreground"
+ tools:ignore="contentDescription" />
+
+ <TextView
+ android:id="@+id/loading_blocklist_textview"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/privacy_browser_logo"
+ android:layout_centerHorizontal="true" />
+ </RelativeLayout>
</FrameLayout>
\ No newline at end of file
<string name="new_tab">New tab</string>
<string name="loading">Loading…</string>
+ <!-- Loading Blocklists. -->
+ <string name="loading_easylist">Loading EasyList</string>
+ <string name="loading_easyprivacy">Loading EasyPrivacy</string>
+ <string name="loading_fanboys_annoyance_list">Loading Fanboy’s Annoyance List</string>
+ <string name="loading_fanboys_social_blocking_list">Loading Fanboy’s Social Blocking List</string>
+ <string name="loading_ultraprivacy">Loading UltraPrivacy</string>
+
<!-- Save As. -->
<string name="save_as">Save As</string>
<string name="save_image_as">Save Image As</string>