From 83814718eb36f98212441127b47d199c62e85920 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 27 Jan 2016 13:54:51 -0700 Subject: [PATCH] Add a menu item to toggle DOM Storage. --- app/src/main/assets/about_text.html | 2 +- .../com/stoutner/privacybrowser/Webview.java | 39 ++++++++++++------- app/src/main/res/menu/menu_webview.xml | 10 ++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/src/main/assets/about_text.html b/app/src/main/assets/about_text.html index 1d2a5ffd..ac8865e0 100644 --- a/app/src/main/assets/about_text.html +++ b/app/src/main/assets/about_text.html @@ -1,6 +1,6 @@ -

Privacy Browser Copyright © 2015 Soren Stoutner

+

Privacy Browser Copyright © 2015-2016 Soren Stoutner

Detailed information about Privacy Browser, including changelogs and a bug tracker, is available at privacybrowser.stoutner.com.

diff --git a/app/src/main/java/com/stoutner/privacybrowser/Webview.java b/app/src/main/java/com/stoutner/privacybrowser/Webview.java index 138a35b0..a1eb26be 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/Webview.java +++ b/app/src/main/java/com/stoutner/privacybrowser/Webview.java @@ -65,8 +65,10 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc private String formattedUrlString; // homepage is used in onCreate and onOptionsItemSelected. private String homepage = "https://www.duckduckgo.com/"; - // enableJavaScript is used onCreate and onOptionsItemSelected. + // enableJavaScript is used in onCreate and onOptionsItemSelected. private boolean enableJavaScript; + // enableDomStorage is used in onCreate and onOptionsItemSelected. + private boolean enableDomStorage; // actionBar is used in onCreate and onOptionsItemSelected. private ActionBar actionBar; @@ -255,14 +257,11 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc // Set JavaScript initial status. enableJavaScript = true; - if (enableJavaScript) { - mainWebView.getSettings().setJavaScriptEnabled(true); - } else { - mainWebView.getSettings().setJavaScriptEnabled(false); - } + mainWebView.getSettings().setJavaScriptEnabled(enableJavaScript); - // Enable DOM Storage. - mainWebView.getSettings().setDomStorageEnabled(true); + // Set DOM Storage initial status. + enableDomStorage = true; + mainWebView.getSettings().setDomStorageEnabled(enableDomStorage); // Get the intent information that started the app. final Intent intent = getIntent(); @@ -287,13 +286,13 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_webview, menu); MenuItem toggleJavaScriptMenuItem = menu.findItem(R.id.toggleJavaScript); + MenuItem toggleDomStorageMenuItem = menu.findItem(R.id.toggleDomStorage); // Set the JavaScript menu item checkbox initial status. - if (enableJavaScript) { - toggleJavaScriptMenuItem.setChecked(true); - } else { - toggleJavaScriptMenuItem.setChecked(false); - } + toggleJavaScriptMenuItem.setChecked(enableJavaScript); + + // Set the DOM Storage menu item checkbox initial status. + toggleDomStorageMenuItem.setChecked(enableDomStorage); return true; } @@ -323,6 +322,20 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc } return true; + case R.id.toggleDomStorage: + if (enableDomStorage) { + enableDomStorage = false; + menuItem.setChecked(false); + mainWebView.getSettings().setDomStorageEnabled(false); + mainWebView.loadUrl(formattedUrlString); + } else { + enableDomStorage = true; + menuItem.setChecked(true); + mainWebView.getSettings().setDomStorageEnabled(true); + mainWebView.loadUrl(formattedUrlString); + } + return true; + case R.id.home: mainWebView.loadUrl(homepage); return true; diff --git a/app/src/main/res/menu/menu_webview.xml b/app/src/main/res/menu/menu_webview.xml index dbe206b1..84e1c75d 100644 --- a/app/src/main/res/menu/menu_webview.xml +++ b/app/src/main/res/menu/menu_webview.xml @@ -1,5 +1,5 @@ JavaScript + DOM Storage Home Refresh Back -- 2.45.2