From: Soren Stoutner Date: Thu, 28 Jan 2016 05:07:43 +0000 (-0700) Subject: Create Clear Dom Storage and Exit menu items and set launchMode="SingleTask". X-Git-Tag: v1.0~13 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=dcc9119811a9eed34df55da205c55c3092c262a4;p=PrivacyBrowserAndroid.git Create Clear Dom Storage and Exit menu items and set launchMode="SingleTask". --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bf5b63b0..61a4c6f2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,11 +34,14 @@ android:theme="@style/AppTheme" > - + + android:label="@string/privacy_browser" + android:launchMode="singleTask"> + diff --git a/app/src/main/java/com/stoutner/privacybrowser/Webview.java b/app/src/main/java/com/stoutner/privacybrowser/Webview.java index d2631c48..53311f7a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/Webview.java +++ b/app/src/main/java/com/stoutner/privacybrowser/Webview.java @@ -44,6 +44,7 @@ import android.view.inputmethod.InputMethodManager; import android.webkit.CookieManager; import android.webkit.DownloadListener; import android.webkit.WebChromeClient; +import android.webkit.WebStorage; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.EditText; @@ -78,16 +79,15 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc // cookieManager is used in onCreate and onOptionsItemSelected. private CookieManager cookieManager; - //enableCookies is used in onCreate, onCreateOptionsMenu, and onOptionsItemSelected. + // enableCookies is used in onCreate, onCreateOptionsMenu, and onOptionsItemSelected. private boolean enableCookies; // actionBar is used in onCreate and onOptionsItemSelected. private ActionBar actionBar; + @Override // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled. @SuppressLint("SetJavaScriptEnabled") - - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); @@ -268,11 +268,11 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc } // Set JavaScript initial status. - enableJavaScript = true; + enableJavaScript = false; mainWebView.getSettings().setJavaScriptEnabled(enableJavaScript); // Set DOM Storage initial status. - enableDomStorage = true; + enableDomStorage = false; mainWebView.getSettings().setDomStorageEnabled(enableDomStorage); /* Save Form Data does nothing until database storage is implemented. @@ -282,8 +282,8 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc */ // Set Cookies initial status. + enableCookies = false; cookieManager = CookieManager.getInstance(); - enableCookies = true; cookieManager.setAcceptCookie(enableCookies); // Get the intent information that started the app. @@ -304,6 +304,21 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc mainWebView.loadUrl(formattedUrlString); } + @Override + protected void onNewIntent(Intent intent) { + // Sets the new intent as the activity intent, so that any future getIntent() picks up this one. + setIntent(intent); + + if (intent.getData() != null) { + // Get the intent data and convert it to a string. + final Uri intentUriData = intent.getData(); + formattedUrlString = intentUriData.toString(); + } + + // Load the website. + mainWebView.loadUrl(formattedUrlString); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -316,7 +331,6 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc MenuItem toggleSaveFormData = menu.findItem(R.id.toggleSaveFormData); */ MenuItem toggleCookies = menu.findItem(R.id.toggleCookies); - MenuItem clearCookies = menu.findItem(R.id.clearCookies); // Set the initial status of the menu item checkboxes. toggleJavaScript.setChecked(enableJavaScript); @@ -421,6 +435,12 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc } return true; + case R.id.clearDomStorage: + WebStorage webStorage = WebStorage.getInstance(); + webStorage.deleteAllData(); + Toast.makeText(getApplicationContext(), "DOM storage deleted", Toast.LENGTH_SHORT).show(); + return true; + case R.id.clearCookies: if (Build.VERSION.SDK_INT < 21) { cookieManager.removeAllCookie(); @@ -504,6 +524,25 @@ public class Webview extends AppCompatActivity implements CreateHomeScreenShortc aboutDialog.show(getSupportFragmentManager(), "aboutDialog"); return true; + case R.id.exit: + // Clear DOM storage. + WebStorage domStorage = WebStorage.getInstance(); + domStorage.deleteAllData(); + + // Clear cookies. + if (Build.VERSION.SDK_INT < 21) { + cookieManager.removeAllCookie(); + } else { + cookieManager.removeAllCookies(null); + } + + // Destroy the internal state of the webview. + mainWebView.destroy(); + + // Close Privacy Browser. + finish(); + return true; + default: return super.onOptionsItemSelected(menuItem); } diff --git a/app/src/main/res/menu/menu_webview.xml b/app/src/main/res/menu/menu_webview.xml index 18130e28..d0042d98 100644 --- a/app/src/main/res/menu/menu_webview.xml +++ b/app/src/main/res/menu/menu_webview.xml @@ -53,10 +53,16 @@ android:checkable="true" app:showAsAction="never" /> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 34806383..8c2c531b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,6 +28,7 @@ DOM Storage Save Form Data Cookies + Clear DOM Storage Clear Cookies Home Refresh @@ -39,6 +40,7 @@ Add to Home Screen Downloads About + Exit Shortcut name