fix log style in AlwaysIncognitoLinkInterceptor

added new method IsAlwaysIncognitoEnabled in AutocompleteProviderClient to activate the minimum necessary
This commit is contained in:
Carmelo Messina 2022-03-02 15:32:30 +01:00 committed by Carl
parent fa0b570677
commit 86225ca1ed

View file

@ -10,7 +10,7 @@ A flag for native management has been inserted
---
chrome/android/chrome_java_sources.gni | 1 +
.../java/res/xml/privacy_preferences.xml | 5 ++
.../AlwaysIncognitoLinkInterceptor.java | 52 +++++++++++++++++++
.../AlwaysIncognitoLinkInterceptor.java | 53 +++++++++++++++++++
.../chrome/browser/ChromeTabbedActivity.java | 6 ++-
.../chrome/browser/app/ChromeActivity.java | 4 ++
.../AppMenuPropertiesDelegateImpl.java | 8 +++
@ -25,7 +25,8 @@ A flag for native management has been inserted
.../tabmodel/TabModelSelectorImpl.java | 3 ++
.../browser/tabmodel/TabPersistentStore.java | 10 ++++
.../webapps/WebappIntentDataProvider.java | 14 +++++
.../chrome_autocomplete_provider_client.cc | 3 ++
.../chrome_autocomplete_provider_client.cc | 7 +++
.../chrome_autocomplete_provider_client.h | 1 +
.../host_content_settings_map_factory.cc | 16 +++++-
.../flags/android/chrome_feature_list.cc | 2 +-
chrome/browser/prefs/browser_prefs.cc | 3 ++
@ -34,7 +35,11 @@ A flag for native management has been inserted
.../snackbar/INeedSnackbarManager.java | 27 ++++++++++
chrome/common/pref_names.cc | 4 ++
chrome/common/pref_names.h | 5 ++
26 files changed, 244 insertions(+), 37 deletions(-)
.../browser/autocomplete_provider_client.cc | 4 ++
.../browser/autocomplete_provider_client.h | 1 +
.../omnibox/browser/base_search_provider.cc | 2 +-
components/omnibox/browser/search_provider.cc | 4 +-
31 files changed, 259 insertions(+), 39 deletions(-)
create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/AlwaysIncognitoLinkInterceptor.java
create mode 100644 chrome/browser/ui/messages/android/java/src/org/chromium/chrome/browser/ui/messages/snackbar/INeedSnackbarManager.java
@ -68,7 +73,7 @@ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/AlwaysIncognito
new file mode 100644
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/AlwaysIncognitoLinkInterceptor.java
@@ -0,0 +1,52 @@
@@ -0,0 +1,53 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -91,6 +96,7 @@ new file mode 100644
+ */
+public class AlwaysIncognitoLinkInterceptor {
+
+ private static final String TAG = "AlwaysIncognito";
+ public static final String PREF_ALWAYS_INCOGNITO = "always_incognito";
+
+ private static @Nullable Boolean cachedIsAlwaysIncognito = null;
@ -115,7 +121,7 @@ new file mode 100644
+ if (isAlwaysIncognito()) {
+ PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+ if(!prefService.getBoolean(Pref.ALWAYS_INCOGNITO_ENABLED)) {
+ Log.i("BROMITE", "Migration: always incognito pref from java to native");
+ Log.i(TAG, "Pref migration from java to native");
+ prefService.setBoolean(Pref.ALWAYS_INCOGNITO_ENABLED, true);
+ }
+ }
@ -570,16 +576,31 @@ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappI
diff --git a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
--- a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
+++ b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
@@ -305,6 +305,9 @@ signin::IdentityManager* ChromeAutocompleteProviderClient::GetIdentityManager()
@@ -304,6 +304,13 @@ signin::IdentityManager* ChromeAutocompleteProviderClient::GetIdentityManager()
return IdentityManagerFactory::GetForProfile(profile_);
}
bool ChromeAutocompleteProviderClient::IsOffTheRecord() const {
+bool ChromeAutocompleteProviderClient::IsAlwaysIncognitoEnabled() const {
+ if (profile_->GetPrefs()->GetBoolean(prefs::kAlwaysIncognitoEnabled)) {
+ return false;
+ return true;
+ }
+ return false;
+}
+
bool ChromeAutocompleteProviderClient::IsOffTheRecord() const {
return profile_->IsOffTheRecord();
}
diff --git a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h
--- a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h
+++ b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h
@@ -77,6 +77,7 @@ class ChromeAutocompleteProviderClient : public AutocompleteProviderClient {
const override;
signin::IdentityManager* GetIdentityManager() const override;
bool IsOffTheRecord() const override;
+ bool IsAlwaysIncognitoEnabled() const override;
bool SearchSuggestEnabled() const override;
bool AllowDeletingBrowserHistory() const override;
bool IsPersonalizedUrlDataCollectionActive() const override;
diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc
--- a/chrome/browser/content_settings/host_content_settings_map_factory.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc
@ -742,5 +763,53 @@ diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
extern const char kPrivacyReviewShowWelcomeCard[];
extern const char kPrivacyGuideViewed[];
diff --git a/components/omnibox/browser/autocomplete_provider_client.cc b/components/omnibox/browser/autocomplete_provider_client.cc
--- a/components/omnibox/browser/autocomplete_provider_client.cc
+++ b/components/omnibox/browser/autocomplete_provider_client.cc
@@ -29,3 +29,7 @@ bool AutocompleteProviderClient::IsIncognitoModeAvailable() const {
bool AutocompleteProviderClient::IsSharingHubAvailable() const {
return false;
}
+
+bool AutocompleteProviderClient::IsAlwaysIncognitoEnabled() const {
+ return false;
+}
diff --git a/components/omnibox/browser/autocomplete_provider_client.h b/components/omnibox/browser/autocomplete_provider_client.h
--- a/components/omnibox/browser/autocomplete_provider_client.h
+++ b/components/omnibox/browser/autocomplete_provider_client.h
@@ -130,6 +130,7 @@ class AutocompleteProviderClient : public OmniboxAction::Client {
virtual signin::IdentityManager* GetIdentityManager() const = 0;
virtual bool IsOffTheRecord() const = 0;
+ virtual bool IsAlwaysIncognitoEnabled() const = 0;
virtual bool SearchSuggestEnabled() const = 0;
// True for almost all users except ones with a specific enterprise policy.
diff --git a/components/omnibox/browser/base_search_provider.cc b/components/omnibox/browser/base_search_provider.cc
--- a/components/omnibox/browser/base_search_provider.cc
+++ b/components/omnibox/browser/base_search_provider.cc
@@ -415,7 +415,7 @@ bool BaseSearchProvider::CanSendURL(
return false;
// Don't run if in incognito mode.
- if (client->IsOffTheRecord())
+ if (client->IsOffTheRecord() && client->IsAlwaysIncognitoEnabled() == false)
return false;
// Don't run if we can't get preferences or search suggest is not enabled.
diff --git a/components/omnibox/browser/search_provider.cc b/components/omnibox/browser/search_provider.cc
--- a/components/omnibox/browser/search_provider.cc
+++ b/components/omnibox/browser/search_provider.cc
@@ -770,7 +770,9 @@ bool SearchProvider::IsQuerySuitableForSuggest(bool* query_is_private) const {
// keyword input to a keyword suggest server, if any.)
const TemplateURL* default_url = providers_.GetDefaultProviderURL();
const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
- return !client()->IsOffTheRecord() && client()->SearchSuggestEnabled() &&
+ return (client()->IsOffTheRecord() == false ||
+ client()->IsAlwaysIncognitoEnabled() == true) &&
+ client()->SearchSuggestEnabled() &&
((default_url && !default_url->suggestions_url().empty() &&
!*query_is_private) ||
(keyword_url && !keyword_url->suggestions_url().empty()));
--
2.25.1