From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: fgei Date: Fri, 17 Jun 2022 10:15:43 +0000 Subject: [PATCH] Toggle for closing tabs on exit --- chrome/android/chrome_ext_java_sources.gni | 1 + .../java/res/xml/privacy_preferences_ext.xml | 5 ++++ .../chrome/browser/ChromeTabbedActivity.java | 1 + .../chrome/browser/TabPreferencesUtils.java | 24 +++++++++++++++++++ .../privacy/settings/PrivacySettingsExt.java | 16 +++++++++++++ .../browser/preferences/SharedPrefsUtils.java | 3 +++ .../strings/android_chrome_ext_strings.grdp | 6 +++++ 7 files changed, 56 insertions(+) create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/TabPreferencesUtils.java diff --git a/chrome/android/chrome_ext_java_sources.gni b/chrome/android/chrome_ext_java_sources.gni index d580fb6e83875..b4e048ed73ef3 100644 --- a/chrome/android/chrome_ext_java_sources.gni +++ b/chrome/android/chrome_ext_java_sources.gni @@ -5,4 +5,5 @@ chrome_ext_java_sources = [ "java/src/org/chromium/chrome/browser/settings/SettingsExtUtils.java", "java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java", + "java/src/org/chromium/chrome/browser/TabPreferencesUtils.java", ] diff --git a/chrome/android/java/res/xml/privacy_preferences_ext.xml b/chrome/android/java/res/xml/privacy_preferences_ext.xml index 01e8c8217afed..ea1dd6c3f529c 100644 --- a/chrome/android/java/res/xml/privacy_preferences_ext.xml +++ b/chrome/android/java/res/xml/privacy_preferences_ext.xml @@ -10,5 +10,10 @@ that can be found in the LICENSE file. android:title="@string/improve_search_suggestions_title" android:summary="@string/improve_search_suggestions_summary" android:persistent="false"/> + diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java index eb8d976faa065..f595aa4e1b231 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java @@ -1285,6 +1285,7 @@ public class ChromeTabbedActivity extends ChromeActivity { @@ -36,6 +37,8 @@ final class PrivacySettingsExt { String key = pref.getKey(); if (PREF_SEARCH_SUGGESTIONS.equals(key)) { prefService.setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) val); + } else if (PREF_CLOSE_TABS_ON_EXIT.equals(key)) { + SharedPrefsExt.CLOSE_TABS_ON_EXIT.put((boolean) val); } return true; }; @@ -73,6 +76,13 @@ final class PrivacySettingsExt { searchSuggestionsPref.setOnPreferenceChangeListener(LISTENER); searchSuggestionsPref.setManagedPreferenceDelegate(DELEGATE); } + + ChromeSwitchPreference closeTabsOnExitPref = + (ChromeSwitchPreference) prefFragment.findPreference(PREF_CLOSE_TABS_ON_EXIT); + if (closeTabsOnExitPref != null) { + closeTabsOnExitPref.setOrder(PRIVACY_PREFERENCES_ORDER); + closeTabsOnExitPref.setOnPreferenceChangeListener(LISTENER); + } } static void updatePreferences(@NonNull PreferenceFragmentCompat prefFragment) { @@ -83,5 +93,11 @@ final class PrivacySettingsExt { SettingsExtUtils.safelyUpdateSwitchPreference(/* switchPref */ searchSuggestionsPref, /* newSummary*/ null, /* newCheckedValue*/ prefService.getBoolean(Pref.SEARCH_SUGGEST_ENABLED)); + + ChromeSwitchPreference closeTabsOnExitPref = + (ChromeSwitchPreference) prefFragment.findPreference(PREF_CLOSE_TABS_ON_EXIT); + SettingsExtUtils.safelyUpdateSwitchPreference(/* switchPref */ closeTabsOnExitPref, + /* newSummary*/ null, + /* newCheckedValue*/ SharedPrefsExt.CLOSE_TABS_ON_EXIT.get()); } } diff --git a/chrome/browser/preferences/android/java/src/org/chromium/chrome/browser/preferences/SharedPrefsUtils.java b/chrome/browser/preferences/android/java/src/org/chromium/chrome/browser/preferences/SharedPrefsUtils.java index ceec302c0a9d6..8fc7dde1db697 100644 --- a/chrome/browser/preferences/android/java/src/org/chromium/chrome/browser/preferences/SharedPrefsUtils.java +++ b/chrome/browser/preferences/android/java/src/org/chromium/chrome/browser/preferences/SharedPrefsUtils.java @@ -136,6 +136,8 @@ public final class SharedPrefsUtils { // Stores SharedPreferences keys and its default value public static class SharedPrefsExt { + public static final BoolSharedPref CLOSE_TABS_ON_EXIT = + new BoolSharedPref("close_tabs_on_exit", false); } static SharedPreferencesManager getSharedPrefManager() { @@ -146,6 +148,7 @@ public final class SharedPrefsUtils { static boolean isKeyInUse(String key) { // clang-format off return Arrays.asList( + SharedPrefsExt.CLOSE_TABS_ON_EXIT.getKey() ).contains(key); // clang-format on } diff --git a/chrome/browser/ui/android/strings/android_chrome_ext_strings.grdp b/chrome/browser/ui/android/strings/android_chrome_ext_strings.grdp index ba31bf0fad150..a1018b43620cd 100644 --- a/chrome/browser/ui/android/strings/android_chrome_ext_strings.grdp +++ b/chrome/browser/ui/android/strings/android_chrome_ext_strings.grdp @@ -3,4 +3,10 @@ Use of this source code is governed by a GPLv2 only-style license that can be found in the LICENSE file. --> + + Close tabs on exit + + + Don't persist tabs between browsing sessions +