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 --- .../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 ++++++++++ .../browser/preferences/SharedPrefsUtils.java | 5 ++- .../strings/android_chrome_ext_strings.grdp | 6 ++++ 7 files changed, 69 insertions(+), 1 deletion(-) 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 f595aa4e1b231..2950cc2c8b81b 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java @@ -2373,6 +2373,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; }; @@ -83,6 +87,13 @@ final class PrivacySettingsExt { closeTabsOnExitPref.setOrder(PRIVACY_PREFERENCES_ORDER); closeTabsOnExitPref.setOnPreferenceChangeListener(LISTENER); } + + ChromeSwitchPreference openLinksInIncognitoPref = + (ChromeSwitchPreference) prefFragment.findPreference(PREF_OPEN_LINKS_IN_INCOGNITO); + if (openLinksInIncognitoPref != null) { + openLinksInIncognitoPref.setOrder(PRIVACY_PREFERENCES_ORDER); + openLinksInIncognitoPref.setOnPreferenceChangeListener(LISTENER); + } } static void updatePreferences(@NonNull PreferenceFragmentCompat prefFragment) { @@ -99,5 +110,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/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 8fc7dde1db697..c2ab10e14c29a 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 @@ -138,6 +138,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() { @@ -148,7 +150,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/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 +