diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStack.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStack.java index fb6471f63..f3557f63d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStack.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStack.java @@ -24,6 +24,7 @@ import org.mozilla.geckoview.GeckoSession; import org.mozilla.geckoview.GeckoSessionSettings; import org.mozilla.geckoview.MediaElement; +import org.mozilla.geckoview.StorageController; import org.mozilla.geckoview.WebRequestError; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.Media; @@ -835,6 +836,27 @@ protected void setTrackingProtection(final boolean aEnabled) { recreateAllSessions(); } + public void clearCache(final long clearFlags) { + if (mRuntime != null) { + // Per GeckoView Docs: + // Note: Any open session may re-accumulate previously cleared data. + // To ensure that no persistent data is left behind, you need to close all sessions prior to clearing data. + // https://mozilla.github.io/geckoview/javadoc/mozilla-central/org/mozilla/geckoview/StorageController.html#clearData-long- + for (Map.Entry entry : mSessions.entrySet()) { + SessionState state = entry.getValue(); + if (state != null) { + state.mSession.stop(); + state.mSession.close(); + } + } + + mRuntime.getStorageController().clearData(clearFlags).then(aVoid -> { + recreateAllSessions(); + return null; + }); + } + } + // NavigationDelegate @Override diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStore.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStore.java index 4fd966bfc..63fde3322 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStore.java @@ -235,6 +235,12 @@ public void setLocales(List locales) { } } + public void clearCache(long clearFlags) { + for (Map.Entry entry : mSessionStacks.entrySet()) { + entry.getValue().clearCache(clearFlags); + } + } + // Permission Delegate @Override diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java index 9498b71b2..4a5c63dd6 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java @@ -19,6 +19,7 @@ import androidx.databinding.DataBindingUtil; import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.StorageController; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.SettingsStore; import org.mozilla.vrbrowser.browser.engine.SessionStore; @@ -62,6 +63,17 @@ private void initialize(Context aContext) { exitWholeSettings(); }); + mBinding.clearCookiesSite.setOnClickListener(v -> { + SessionStore.get().clearCache( + StorageController.ClearFlags.SITE_DATA | + StorageController.ClearFlags.COOKIES | + StorageController.ClearFlags.SITE_SETTINGS); + }); + + mBinding.clearWebContent.setOnClickListener(v -> { + SessionStore.get().clearCache(StorageController.ClearFlags.ALL_CACHES); + }); + TextView permissionsTitleText = findViewById(R.id.permissionsTitle); permissionsTitleText.setText(getContext().getString(R.string.security_options_permissions_title, getContext().getString(R.string.app_name))); diff --git a/app/src/main/res/layout/options_developer.xml b/app/src/main/res/layout/options_developer.xml index 62199012c..fa4cba336 100644 --- a/app/src/main/res/layout/options_developer.xml +++ b/app/src/main/res/layout/options_developer.xml @@ -13,11 +13,11 @@ android:id="@+id/header_layout" android:layout_width="match_parent" android:layout_height="wrap_content" + app:helpVisibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:title="@string/settings_developer_options" - app:helpVisibility="gone" /> + app:title="@string/settings_developer_options" /> + + + + Enable Servo + + Cookies & Site Data + + + Cached Web Content + + + Clear Data + Display Density: