219 lines
10 KiB
Diff
219 lines
10 KiB
Diff
From: uazo <uazo@users.noreply.github.com>
|
|
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" />
|
|
+ <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
|
|
+ android:key="incognito_history_enabled"
|
|
+ android:title="@string/incognito_history_enabled_title"
|
|
+ android:summary="@string/incognito_history_enabled_summary"
|
|
+ android:defaultValue="false" />
|
|
<Preference
|
|
android:fragment="org.chromium.chrome.browser.privacy.settings.DoNotTrackSettings"
|
|
android:key="do_not_track"
|
|
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
|
|
--- a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
|
|
+++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
|
|
@@ -38,6 +38,8 @@ import org.chromium.components.user_prefs.UserPrefs;
|
|
import org.chromium.ui.text.NoUnderlineClickableSpan;
|
|
import org.chromium.ui.text.SpanApplier;
|
|
|
|
+import org.chromium.base.Log;
|
|
+
|
|
/**
|
|
* Fragment to keep track of the all the privacy related preferences.
|
|
*/
|
|
@@ -52,11 +54,13 @@ public class PrivacySettings
|
|
private static final String PREF_ALWAYS_INCOGNITO = "always_incognito";
|
|
public static final String PREF_ALLOW_CUSTOM_TAB_INTENTS = "allow_custom_tab_intents";
|
|
private static final String PREF_PROXY_OPTIONS = "proxy";
|
|
+ public static final String PREF_INCOGNITO_TAB_HISTORY_ENABLED = "incognito_history_enabled";
|
|
|
|
private static final String[] NEW_PRIVACY_PREFERENCE_ORDER = {PREF_CLEAR_BROWSING_DATA,
|
|
PREF_CAN_MAKE_PAYMENT, PREF_NETWORK_PREDICTIONS,
|
|
PREF_SECURE_DNS, PREF_DO_NOT_TRACK,
|
|
PREF_ALWAYS_INCOGNITO,
|
|
+ PREF_INCOGNITO_TAB_HISTORY_ENABLED,
|
|
PREF_ALLOW_CUSTOM_TAB_INTENTS,
|
|
PREF_CLOSE_TABS_ON_EXIT,
|
|
PREF_PROXY_OPTIONS
|
|
@@ -99,6 +103,11 @@ public class PrivacySettings
|
|
Preference secureDnsPref = findPreference(PREF_SECURE_DNS);
|
|
secureDnsPref.setVisible(SecureDnsSettings.isUiEnabled());
|
|
|
|
+ ChromeSwitchPreference historyInIncognitoPref =
|
|
+ (ChromeSwitchPreference) findPreference(PREF_INCOGNITO_TAB_HISTORY_ENABLED);
|
|
+ historyInIncognitoPref.setOnPreferenceChangeListener(this);
|
|
+ historyInIncognitoPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
|
|
+
|
|
updateSummaries();
|
|
}
|
|
|
|
@@ -118,6 +127,9 @@ public class PrivacySettings
|
|
SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
|
|
sharedPreferencesEditor.putBoolean(PREF_ALLOW_CUSTOM_TAB_INTENTS, (boolean)newValue);
|
|
sharedPreferencesEditor.apply();
|
|
+ } else if (PREF_INCOGNITO_TAB_HISTORY_ENABLED.equals(key)) {
|
|
+ UserPrefs.get(Profile.getLastUsedRegularProfile())
|
|
+ .setBoolean(Pref.INCOGNITO_TAB_HISTORY_ENABLED, (boolean) newValue);
|
|
}
|
|
|
|
return true;
|
|
@@ -162,6 +174,13 @@ public class PrivacySettings
|
|
(ChromeSwitchPreference) findPreference(PREF_CLOSE_TABS_ON_EXIT);
|
|
closeTabsOnExitPref.setOnPreferenceChangeListener(this);
|
|
closeTabsOnExitPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
|
|
+
|
|
+ ChromeSwitchPreference historyInIncognitoPref =
|
|
+ (ChromeSwitchPreference) findPreference(PREF_INCOGNITO_TAB_HISTORY_ENABLED);
|
|
+ if (historyInIncognitoPref != null) {
|
|
+ historyInIncognitoPref.setChecked(
|
|
+ prefService.getBoolean(Pref.INCOGNITO_TAB_HISTORY_ENABLED));
|
|
+ }
|
|
}
|
|
|
|
private ChromeManagedPreferenceDelegate createManagedPreferenceDelegate() {
|
|
diff --git a/chrome/browser/history/history_tab_helper.cc b/chrome/browser/history/history_tab_helper.cc
|
|
--- a/chrome/browser/history/history_tab_helper.cc
|
|
+++ b/chrome/browser/history/history_tab_helper.cc
|
|
@@ -28,6 +28,9 @@
|
|
#if defined(OS_ANDROID)
|
|
#include "chrome/browser/android/background_tab_manager.h"
|
|
#include "components/feed/feed_feature_list.h"
|
|
+#include "chrome/common/pref_names.h"
|
|
+#include "components/prefs/pref_registry_simple.h"
|
|
+#include "components/prefs/pref_service.h"
|
|
#else
|
|
#include "chrome/browser/ui/browser.h"
|
|
#include "chrome/browser/ui/browser_finder.h"
|
|
@@ -255,6 +258,13 @@ void HistoryTabHelper::TitleWasSet(NavigationEntry* entry) {
|
|
history::HistoryService* HistoryTabHelper::GetHistoryService() {
|
|
Profile* profile =
|
|
Profile::FromBrowserContext(web_contents()->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<HistoryTabHelper>;
|
|
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
|
|
<message name="IDS_ALWAYS_INCOGNITO_SUMMARY" desc="Summary for always incognito mode">
|
|
Opens links in incognito tabs when you click on new tab or on a link
|
|
</message>
|
|
+ <message name="IDS_INCOGNITO_HISTORY_ENABLED_TITLE" desc="Title for always enable history in incognito mode">
|
|
+ Enable history in incognito tabs
|
|
+ </message>
|
|
+ <message name="IDS_INCOGNITO_HISTORY_ENABLED_SUMMARY" desc="Summary for always enable history in incognito mode">
|
|
+ Record history even in incognito mode
|
|
+ </message>
|
|
<message name="IDS_CLEAR_BROWSING_HISTORY_SUMMARY_SIGNED_IN" desc="A text explaining other forms of activity for signed in users.">
|
|
Clears history and autocompletions in the address bar. Your Google Account may have other forms of browsing history at <ph name="BEGIN_LINK"><link></ph>myactivity.google.com<ph name="END_LINK"></link></ph>.
|
|
</message>
|
|
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
|
|
|