From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: fgei Date: Sun, 19 Jun 2022 06:39:48 +0000 Subject: [PATCH] Toggle for navigating external URL in incognito --- .../shared_preferences/SharedPrefsUtils.java | 5 ++- .../java/res/xml/privacy_preferences_ext.xml | 5 +++ .../chrome/browser/ChromeTabbedActivity.java | 2 ++ .../browser/LaunchIntentDispatcher.java | 3 ++ .../chrome/browser/TabPreferencesUtils.java | 32 +++++++++++++++++++ .../privacy/settings/PrivacySettingsExt.java | 17 ++++++++++ .../strings/android_chrome_ext_strings.grdp | 6 ++++ 7 files changed, 69 insertions(+), 1 deletion(-) diff --git a/base/android/java/src/org/chromium/base/shared_preferences/SharedPrefsUtils.java b/base/android/java/src/org/chromium/base/shared_preferences/SharedPrefsUtils.java index 84784f7ec174c..0bacc94f580dc 100644 --- a/base/android/java/src/org/chromium/base/shared_preferences/SharedPrefsUtils.java +++ b/base/android/java/src/org/chromium/base/shared_preferences/SharedPrefsUtils.java @@ -122,6 +122,8 @@ public final class SharedPrefsUtils { public static class SharedPrefsExt { public static final BoolSharedPref CLOSE_TABS_ON_EXIT = new BoolSharedPref("close_tabs_on_exit", false); + public static final BoolSharedPref OPEN_LINKS_IN_INCOGNITO = + new BoolSharedPref("open_links_in_incognito", false); } static SharedPreferencesManager getSharedPrefManager() { @@ -132,7 +134,8 @@ public final class SharedPrefsUtils { static boolean isKeyInUse(String key) { // clang-format off return Arrays.asList( - SharedPrefsExt.CLOSE_TABS_ON_EXIT.getKey() + SharedPrefsExt.CLOSE_TABS_ON_EXIT.getKey(), + SharedPrefsExt.OPEN_LINKS_IN_INCOGNITO.getKey() ).contains(key); // clang-format on } diff --git a/chrome/android/java/res/xml/privacy_preferences_ext.xml b/chrome/android/java/res/xml/privacy_preferences_ext.xml index ea1dd6c3f529c..4f6b5a3ae75a5 100644 --- a/chrome/android/java/res/xml/privacy_preferences_ext.xml +++ b/chrome/android/java/res/xml/privacy_preferences_ext.xml @@ -15,5 +15,10 @@ that can be found in the LICENSE file. android:title="@string/close_tabs_on_exit_title" android:summary="@string/close_tabs_on_exit_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 e269a2bb14ba4..0d8061367155e 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java @@ -2459,6 +2459,8 @@ public class ChromeTabbedActivity extends ChromeActivity { @@ -39,6 +41,8 @@ final class PrivacySettingsExt { 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); + } else if (PREF_OPEN_LINKS_IN_INCOGNITO.equals(key)) { + SharedPrefsExt.OPEN_LINKS_IN_INCOGNITO.put((boolean) val); } return true; }; @@ -88,6 +92,13 @@ final class PrivacySettingsExt { closeTabsOnExitPref.setOrder(PRIVACY_PREFERENCES_ORDER); closeTabsOnExitPref.setOnPreferenceChangeListener(getListener(profile)); } + + ChromeSwitchPreference openLinksInIncognitoPref = + (ChromeSwitchPreference) prefFragment.findPreference(PREF_OPEN_LINKS_IN_INCOGNITO); + if (openLinksInIncognitoPref != null) { + openLinksInIncognitoPref.setOrder(PRIVACY_PREFERENCES_ORDER); + openLinksInIncognitoPref.setOnPreferenceChangeListener(getListener(profile)); + } } static void updatePreferences(@NonNull PreferenceFragmentCompat prefFragment, @NonNull Profile profile) { @@ -104,5 +115,11 @@ final class PrivacySettingsExt { SettingsExtUtils.safelyUpdateSwitchPreference(/* switchPref */ closeTabsOnExitPref, /* newSummary*/ null, /* newCheckedValue*/ SharedPrefsExt.CLOSE_TABS_ON_EXIT.get()); + + ChromeSwitchPreference openLinksInIncognitoPref = + (ChromeSwitchPreference) prefFragment.findPreference(PREF_OPEN_LINKS_IN_INCOGNITO); + SettingsExtUtils.safelyUpdateSwitchPreference(/* switchPref */ openLinksInIncognitoPref, + /* newSummary*/ null, + /* newCheckedValue*/ SharedPrefsExt.OPEN_LINKS_IN_INCOGNITO.get()); } } 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 a1018b43620cd..52b9ca2042bee 100644 --- a/chrome/browser/ui/android/strings/android_chrome_ext_strings.grdp +++ b/chrome/browser/ui/android/strings/android_chrome_ext_strings.grdp @@ -9,4 +9,10 @@ Don't persist tabs between browsing sessions + + Open external links in incognito + + + Open links navigated by external apps in incognito tabs +