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

Setting for enable/disable restoring tabs #2513

Merged
merged 2 commits into from
Dec 20, 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 @@ -1475,6 +1475,11 @@ public TrayWidget getTray() {
return mTray;
}

@Override
public void saveState() {
mWindows.saveState();
}

private native void addWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateVisibleWidgetsNative();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONObject;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.widgets.UISurfaceTextureRenderer;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.LocaleUtils;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.SystemUtils;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -86,6 +84,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean HISTORY_SYNC_DEFAULT = true;
public final static boolean WHATS_NEW_DISPLAYED = false;
public final static long FXA_LAST_SYNC_NEVER = 0;
public final static boolean RESTORE_TABS_ENABLED = true;

// Enable telemetry by default (opt-out).
public final static boolean CRASH_REPORTING_DEFAULT = false;
Expand Down Expand Up @@ -690,8 +689,16 @@ public long getFxALastSync(@NonNull String email) {
} catch (Exception e) {
return FXA_LAST_SYNC_NEVER;
}
}

public void setRestoreTabsEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_restore_tabs), isEnabled);
editor.commit();
}

public boolean isRestoreTabsEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_restore_tabs), RESTORE_TABS_ENABLED);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import androidx.annotation.NonNull;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.VRBrowserActivity;
import org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;

Expand Down Expand Up @@ -88,4 +87,5 @@ interface WorldClickListener {
TrayWidget getTray();
void addConnectivityListener(ConnectivityReceiver.Delegate aListener);
void removeConnectivityListener(ConnectivityReceiver.Delegate aListener);
void saveState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public Windows(Context aContext) {
restoreWindows();
}

private void saveState() {
public void saveState() {
File file = new File(mContext.getFilesDir(), WINDOWS_SAVE_FILENAME);
try (Writer writer = new FileWriter(file)) {
WindowsState state = new WindowsState();
Expand Down Expand Up @@ -602,8 +602,9 @@ private WindowWidget getRightWindow() {
}

private void restoreWindows() {
boolean restoreEnabled = SettingsStore.getInstance(mContext).isRestoreTabsEnabled();
WindowsState windowsState = restoreState();
if (windowsState != null) {
if (restoreEnabled && windowsState != null) {
ArrayList<Session> restoredSessions = new ArrayList<>();
if (windowsState.tabs != null) {
windowsState.tabs.forEach(state -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void initialize(Context aContext) {
onDismiss();

} else if (index == PromptDialogWidget.POSITIVE) {
mWidgetManager.saveState();
postDelayed(() -> SystemUtils.scheduleRestart(getContext(), 100), 500);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ private void initialize(Context aContext) {
setPopUpsBlocking(SettingsStore.getInstance(getContext()).isPopUpsBlockingEnabled(), false);

mBinding.popUpsBlockingExceptionsButton.setOnClickListener(v -> mDelegate.showView(mPopUpsBlockingExceptions));

mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);
setRestoreTabs(SettingsStore.getInstance(getContext()).isRestoreTabsEnabled(), false);
}

private void togglePermission(SwitchSetting aButton, String aPermission) {
Expand Down Expand Up @@ -171,6 +174,10 @@ public void reject() {
setPopUpsBlocking(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mRestoreTabsListener = (compoundButton, value, doApply) -> {
setRestoreTabs(value, doApply);
};

private void resetOptions() {
if (mBinding.drmContentPlaybackSwitch.isChecked() != SettingsStore.DRM_PLAYBACK_DEFAULT) {
setDrmContent(SettingsStore.DRM_PLAYBACK_DEFAULT, true);
Expand Down Expand Up @@ -199,6 +206,10 @@ private void resetOptions() {
if (mBinding.popUpsBlockingSwitch.isChecked() != SettingsStore.POP_UPS_BLOCKING_DEFAULT) {
setPopUpsBlocking(SettingsStore.POP_UPS_BLOCKING_DEFAULT, true);
}

if (mBinding.restoreTabsSwitch.isChecked() != SettingsStore.RESTORE_TABS_ENABLED) {
setRestoreTabs(SettingsStore.RESTORE_TABS_ENABLED, true);
}
}

private void setDrmContent(boolean value, boolean doApply) {
Expand Down Expand Up @@ -273,6 +284,16 @@ private void setPopUpsBlocking(boolean value, boolean doApply) {
}
}

private void setRestoreTabs(boolean value, boolean doApply) {
mBinding.restoreTabsSwitch.setOnCheckedChangeListener(null);
mBinding.restoreTabsSwitch.setValue(value, false);
mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setRestoreTabsEnabled(value);
}
}

@Override
public Point getDimensions() {
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.privacy_options_width),
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_privacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
app:buttonText="@string/developer_options_show"
app:description="@string/settings_privacy_policy" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/restoreTabsSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/security_options_restore_tabs" />

<org.mozilla.vrbrowser.ui.views.settings.ButtonSetting
android:id="@+id/clearCookiesSite"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<string name="settings_key_whats_new_displayed" translatable="false">settings_key_whats_new_displayed</string>
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration</string>
<string name="settings_key_fxa_last_sync" translatable="false">settings_key_fxa_last_sync</string>
<string name="settings_key_restore_tabs" translatable="false">settings_key_restore_tabs</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@
and is used to enable or disable playback of DRM controlled content. -->
<string name="security_options_drm_content">Play DRM-Controlled Content (&lt;a href="http://somesite.com/">Learn More&lt;/a>)</string>

<!-- This string labels an Allow/Don't Allow switch in the Privacy and Security settings dialog
and is used to enable or disable the tabs restoration after a fresh app start. -->
<string name="security_options_restore_tabs">Restore tabs and windows after restart</string>

<!-- This string labels an On/Off switch in the Privacy and Security settings dialog
and is used to enable or disable tracking protection. -->
<string name="security_options_tracking_protection">Tracking Protection</string>
Expand Down