From: uazo Date: Fri, 7 Aug 2020 16:33:47 +0000 Subject: Add history support in incognito mode --- .../java/res/xml/privacy_preferences.xml | 5 +++++ .../privacy/settings/PrivacySettings.java | 19 +++++++++++++++++++ chrome/browser/history/history_tab_helper.cc | 16 ++++++++++++++++ chrome/browser/history/history_tab_helper.h | 4 ++++ chrome/browser/prefs/browser_prefs.cc | 3 +++ .../strings/android_chrome_strings.grd | 6 ++++++ chrome/common/pref_names.cc | 5 +++++ chrome/common/pref_names.h | 4 ++++ 8 files changed, 62 insertions(+) diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml --- a/chrome/android/java/res/xml/privacy_preferences.xml +++ b/chrome/android/java/res/xml/privacy_preferences.xml @@ -32,6 +32,11 @@ android:title="@string/close_tabs_on_exit_title" android:summary="@string/close_tabs_on_exit_summary" android:defaultValue="false" /> + GetBrowserContext()); + +#if defined(OS_ANDROID) + if(profile->GetOriginalProfile()->GetPrefs()->GetBoolean(prefs::kIncognitoTabHistoryEnabled)) { + return HistoryServiceFactory::GetForProfile(profile, ServiceAccessType::IMPLICIT_ACCESS); + } +#endif + if (profile->IsOffTheRecord()) return NULL; @@ -262,6 +272,12 @@ history::HistoryService* HistoryTabHelper::GetHistoryService() { profile, ServiceAccessType::IMPLICIT_ACCESS); } +// static +void HistoryTabHelper::RegisterProfilePrefs(PrefRegistrySimple* registry) { + registry->RegisterBooleanPref(prefs::kIncognitoTabHistoryEnabled, + /*default_value=*/false); +} + void HistoryTabHelper::WebContentsDestroyed() { // We update the history for this URL. WebContents* tab = web_contents(); diff --git a/chrome/browser/history/history_tab_helper.h b/chrome/browser/history/history_tab_helper.h --- a/chrome/browser/history/history_tab_helper.h +++ b/chrome/browser/history/history_tab_helper.h @@ -10,6 +10,8 @@ #include "base/time/time.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" +#include "components/prefs/pref_registry_simple.h" +#include "components/prefs/pref_service.h" namespace history { struct HistoryAddPageArgs; @@ -46,6 +48,8 @@ class HistoryTabHelper : public content::WebContentsObserver, int nav_entry_id, content::NavigationHandle* navigation_handle); + static void RegisterProfilePrefs(PrefRegistrySimple* registry); + private: explicit HistoryTabHelper(content::WebContents* web_contents); friend class content::WebContentsUserData; diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -205,6 +205,8 @@ #endif #if defined(OS_ANDROID) +#include "chrome/browser/history/history_tab_helper.h" + #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" #include "chrome/browser/android/explore_sites/history_statistics_reporter.h" #include "chrome/browser/android/ntp/recent_tabs_page_prefs.h" @@ -903,6 +905,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, variations::VariationsService::RegisterProfilePrefs(registry); video_tutorials::RegisterPrefs(registry); feed::prefs::RegisterFeedSharedProfilePrefs(registry); + HistoryTabHelper::RegisterProfilePrefs(registry); feed::RegisterProfilePrefs(registry); #else // defined(OS_ANDROID) AppShortcutManager::RegisterProfilePrefs(registry); diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd @@ -856,6 +856,12 @@ Your Google account may have other forms of browsing history like searches and a Opens links in incognito tabs when you click on new tab or on a link + + Enable history in incognito tabs + + + Record history even in incognito mode + Clears history and autocompletions in the address bar. Your Google Account may have other forms of browsing history at <link>myactivity.google.com</link>. diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -3119,4 +3119,9 @@ const char kSecurityTokenSessionNotificationSeconds[] = "security_token_session_notification_seconds"; #endif // defined(OS_CHROMEOS) +#if defined(OS_ANDROID) +const char kIncognitoTabHistoryEnabled[] = + "incognito_tab_history_enabled"; +#endif + } // namespace prefs diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -1093,6 +1093,10 @@ extern const char kSecurityTokenSessionBehavior[]; extern const char kSecurityTokenSessionNotificationSeconds[]; #endif +#if defined(OS_ANDROID) +extern const char kIncognitoTabHistoryEnabled[]; +#endif + } // namespace prefs #endif // CHROME_COMMON_PREF_NAMES_H_ -- 2.17.1