Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Adds support for clear cache #1517

Merged
merged 2 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer, SessionState> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ public void setLocales(List<String> locales) {
}
}

public void clearCache(long clearFlags) {
for (Map.Entry<Integer, SessionStack> entry : mSessionStacks.entrySet()) {
entry.getValue().clearCache(clearFlags);
}
}

// Permission Delegate

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/options_developer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<ScrollView
android:id="@+id/scrollbar"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/options_privacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
app:buttonText="@string/developer_options_show"
app:description="@string/settings_privacy_policy" />

<org.mozilla.vrbrowser.ui.views.settings.ButtonSetting
android:id="@+id/clearCookiesSite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:buttonText="@string/developer_options_clear_cache"
app:description="@string/developer_options_clear_cache_cookies_site_description" />

<org.mozilla.vrbrowser.ui.views.settings.ButtonSetting
android:id="@+id/clearWebContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:buttonText="@string/developer_options_clear_cache"
app:description="@string/developer_options_clear_cache_web_content_description" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/drmContentPlaybackSwitch"
android:layout_width="match_parent"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@
<!-- The string labels an On/Off switch in the developer options dialog and is used to toggle enabling Servo. -->
<string name="developer_options_servo">Enable Servo</string>

<!-- The string labels the description text for the clear cookies and site data button in the
privacy options dialog. -->
<string name="developer_options_clear_cache_cookies_site_description">Cookies &amp; Site Data</string>

<!-- The string labels the description text for the clear cached web content button in the
privacy options dialog. -->
<string name="developer_options_clear_cache_web_content_description">Cached Web Content</string>

<!-- The string labels the button text for the clear cache buttons in the privacy options dialog. -->
<string name="developer_options_clear_cache">Clear Data</string>

<!-- This string is used to label a numerical-entry field where the user may set a new value to
use for the display density. -->
<string name="developer_options_display_density">Display Density:</string>
Expand Down