Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc

Issue 2885763002: Only show search geolocation disclosure on omnibox searches or API use. (Closed)
Patch Set: Add comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc
diff --git a/chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc b/chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc
index 3f02fa70b7bf431055d1dae1ce2a2372add2d883..33aee6073e44aad41fcea0f97fc522d1f80dc10b 100644
--- a/chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc
+++ b/chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/android/search_geolocation/search_geolocation_service.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -24,6 +25,7 @@
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
+#include "components/search_engines/template_url_service.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/web_contents.h"
#include "jni/GeolocationHeader_jni.h"
@@ -82,17 +84,61 @@ SearchGeolocationDisclosureTabHelper::~SearchGeolocationDisclosureTabHelper() {}
void SearchGeolocationDisclosureTabHelper::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) {
- MaybeShowDisclosure(web_contents()->GetVisibleURL());
+ MaybeShowDisclosureForNavigation(web_contents()->GetVisibleURL());
}
-void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure(
+void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosureForAPIAccess(
const GURL& gurl) {
if (!consistent_geolocation_disclosure_enabled_)
return;
- if (!ShouldShowDisclosureForUrl(gurl))
+ if (!ShouldShowDisclosureForAPIAccess(gurl))
return;
+ MaybeShowDisclosureForValidUrl(gurl);
+}
+
+// static
+void SearchGeolocationDisclosureTabHelper::ResetDisclosure(Profile* profile) {
+ PrefService* prefs = profile->GetPrefs();
+ prefs->ClearPref(prefs::kSearchGeolocationDisclosureShownCount);
+ prefs->ClearPref(prefs::kSearchGeolocationDisclosureLastShowDate);
+ prefs->ClearPref(prefs::kSearchGeolocationDisclosureDismissed);
+}
+
+// static
+void SearchGeolocationDisclosureTabHelper::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterBooleanPref(prefs::kSearchGeolocationDisclosureDismissed,
+ false);
+ registry->RegisterIntegerPref(prefs::kSearchGeolocationDisclosureShownCount,
+ 0);
+ registry->RegisterInt64Pref(prefs::kSearchGeolocationDisclosureLastShowDate,
+ 0);
+ registry->RegisterBooleanPref(
+ prefs::kSearchGeolocationPreDisclosureMetricsRecorded, false);
+ registry->RegisterBooleanPref(
+ prefs::kSearchGeolocationPostDisclosureMetricsRecorded, false);
+}
+
+// static
+bool SearchGeolocationDisclosureTabHelper::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosureForNavigation(
+ const GURL& gurl) {
+ if (!consistent_geolocation_disclosure_enabled_)
+ return;
+
+ if (!ShouldShowDisclosureForNavigation(gurl))
+ return;
+
+ MaybeShowDisclosureForValidUrl(gurl);
+}
+
+void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosureForValidUrl(
+ const GURL& gurl) {
// Don't show the infobar if the user has dismissed it, or they've seen it
// enough times already.
PrefService* prefs = GetProfile()->GetPrefs();
@@ -149,35 +195,7 @@ void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure(
GetTimeNow().ToInternalValue());
}
-// static
-void SearchGeolocationDisclosureTabHelper::ResetDisclosure(Profile* profile) {
- PrefService* prefs = profile->GetPrefs();
- prefs->ClearPref(prefs::kSearchGeolocationDisclosureShownCount);
- prefs->ClearPref(prefs::kSearchGeolocationDisclosureLastShowDate);
- prefs->ClearPref(prefs::kSearchGeolocationDisclosureDismissed);
-}
-
-// static
-void SearchGeolocationDisclosureTabHelper::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterBooleanPref(prefs::kSearchGeolocationDisclosureDismissed,
- false);
- registry->RegisterIntegerPref(prefs::kSearchGeolocationDisclosureShownCount,
- 0);
- registry->RegisterInt64Pref(prefs::kSearchGeolocationDisclosureLastShowDate,
- 0);
- registry->RegisterBooleanPref(
- prefs::kSearchGeolocationPreDisclosureMetricsRecorded, false);
- registry->RegisterBooleanPref(
- prefs::kSearchGeolocationPostDisclosureMetricsRecorded, false);
-}
-
-// static
-bool SearchGeolocationDisclosureTabHelper::Register(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-bool SearchGeolocationDisclosureTabHelper::ShouldShowDisclosureForUrl(
+bool SearchGeolocationDisclosureTabHelper::ShouldShowDisclosureForAPIAccess(
const GURL& gurl) {
SearchGeolocationService* service =
SearchGeolocationService::Factory::GetForBrowserContext(GetProfile());
@@ -193,6 +211,21 @@ bool SearchGeolocationDisclosureTabHelper::ShouldShowDisclosureForUrl(
return service->UseDSEGeolocationSetting(url::Origin(gurl));
}
+bool SearchGeolocationDisclosureTabHelper::ShouldShowDisclosureForNavigation(
+ const GURL& gurl) {
+ if (!ShouldShowDisclosureForAPIAccess(gurl))
+ return false;
+
+ if (gIgnoreUrlChecksForTesting)
+ return true;
+
+ // Only show the disclosure for default search navigations from the omnibox.
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(GetProfile());
+ return template_url_service->IsSearchResultsPageFromDefaultSearchProvider(
+ gurl);
+}
+
void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics(
const GURL& gurl) {
PrefService* prefs = GetProfile()->GetPrefs();

Powered by Google App Engine
This is Rietveld 408576698