android:theme="@style/AppTheme" >
<!-- android:configChanges="orientation|screenSize" makes the app not reload when the orientation changes. -->
- <!-- android:windowSoftInputMode="stateAlwaysHidden" hides the keyboard when the app starts. -->
+ <!-- android:launchMode="singleTask" makes the app launch in a new task instead of inside the task of the program that sends it an intent.
+ It also makes it reuse an existing Privacy Browser activity if available instead of launching a new one. -->
<activity
android:name=".Webview"
android:configChanges="orientation|screenSize"
- android:label="@string/privacy_browser" >
+ android:label="@string/privacy_browser"
+ android:launchMode="singleTask">
+
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
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;
// 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);
}
// 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.
*/
// Set Cookies initial status.
+ enableCookies = false;
cookieManager = CookieManager.getInstance();
- enableCookies = true;
cookieManager.setAcceptCookie(enableCookies);
// Get the intent information that started the app.
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.
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);
}
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();
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);
}
android:checkable="true"
app:showAsAction="never" />
+ <item
+ android:id="@+id/clearDomStorage"
+ android:title="@string/clearDomStorage"
+ android:orderInCategory="5"
+ app:showAsAction="never" />
+
<item
android:id="@+id/clearCookies"
android:title="@string/clearCookies"
- android:orderInCategory="5"
+ android:orderInCategory="6"
app:showAsAction="never" />
<item
android:title="@string/about"
android:orderInCategory="100"
app:showAsAction="never" />
+
+ <item
+ android:id="@+id/exit"
+ android:title="@string/exit"
+ android:orderInCategory="110"
+ app:showAsAction="never" />
</menu>
<string name="domStorage">DOM Storage</string>
<string name="saveFormData">Save Form Data</string>
<string name="cookies">Cookies</string>
+ <string name="clearDomStorage">Clear DOM Storage</string>
<string name="clearCookies">Clear Cookies</string>
<string name="home">Home</string>
<string name="refresh">Refresh</string>
<string name="add_to_home_screen">Add to Home Screen</string>
<string name="downloads">Downloads</string>
<string name="about">About</string>
+ <string name="exit">Exit</string>
<!-- Create Home Screen Shorcut Alert Dialog. -->
<string name="shortcut_name">Shortcut name</string>