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

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

Issue 2627853002: Show the search geolocation disclosure from geolocation API use. (Closed)
Patch Set: Marked old ones obsolete Created 3 years, 11 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 9cd7a6eccfc571072da2d012d0fe2e709e108034..43745792a37222d37066afc052d1dab92539d5ae 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
@@ -12,21 +12,22 @@
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/android/search_geolocation/search_geolocation_disclosure_infobar_delegate.h"
-#include "chrome/browser/permissions/permission_manager.h"
+#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/pref_names.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/common/content_settings.h"
+#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.h"
-#include "components/search_engines/template_url_service.h"
#include "components/variations/variations_associated_data.h"
-#include "content/public/browser/permission_type.h"
#include "content/public/browser/web_contents.h"
#include "jni/GeolocationHeader_jni.h"
#include "jni/SearchGeolocationDisclosureTabHelper_jni.h"
#include "third_party/WebKit/public/platform/modules/permissions/permission_status.mojom.h"
+#include "url/origin.h"
namespace {
@@ -77,47 +78,18 @@ SearchGeolocationDisclosureTabHelper::~SearchGeolocationDisclosureTabHelper() {}
void SearchGeolocationDisclosureTabHelper::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) {
- if (consistent_geolocation_enabled_) {
- MaybeShowDefaultSearchGeolocationDisclosure(
- web_contents()->GetVisibleURL());
- }
-}
-
-// 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);
+ if (consistent_geolocation_enabled_)
+ MaybeShowDisclosure(web_contents()->GetVisibleURL());
}
-void SearchGeolocationDisclosureTabHelper::
- MaybeShowDefaultSearchGeolocationDisclosure(const GURL& gurl) {
- // Don't show in incognito.
- if (GetProfile()->IsOffTheRecord())
+void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure(
+ const GURL& gurl) {
+ if (!ShouldShowDisclosureForUrl(gurl))
return;
- if (!ShouldShowDisclosureForUrl(gurl))
+ // Check that the Chrome app has geolocation permission.
+ JNIEnv* env = base::android::AttachCurrentThread();
+ if (!Java_GeolocationHeader_hasGeolocationPermission(env))
return;
// Don't show the infobar if the user has dismissed it, or they've seen it
@@ -144,22 +116,23 @@ void SearchGeolocationDisclosureTabHelper::
return;
}
- // Check that the Chrome app has geolocation permission.
- JNIEnv* env = base::android::AttachCurrentThread();
- if (!Java_GeolocationHeader_hasGeolocationPermission(env))
- return;
-
// Record metrics for the state of permissions before the disclosure has been
// shown.
RecordPreDisclosureMetrics(gurl);
- // Only show the disclosure if the geolocation permission is set to ASK
- // (i.e. has not been explicitly set or revoked).
- blink::mojom::PermissionStatus status =
- PermissionManager::Get(GetProfile())
- ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
- gurl);
- if (status != blink::mojom::PermissionStatus::ASK)
+ // Only show the disclosure if the geolocation permission is set ask (i.e. has
+ // not been explicitly set or revoked).
+ ContentSetting status =
+ HostContentSettingsMapFactory::GetForProfile(GetProfile())
+ ->GetContentSetting(gurl, gurl, CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string());
+ if (status != CONTENT_SETTING_ASK)
+ return;
+
+ // And only show disclosure if the DSE geolocation setting is on.
+ SearchGeolocationService* service =
+ SearchGeolocationService::Factory::GetForBrowserContext(GetProfile());
+ if (!service->GetDSEGeolocationSetting())
return;
// All good, let's show the disclosure and increment the shown count.
@@ -170,30 +143,48 @@ void SearchGeolocationDisclosureTabHelper::
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(
const GURL& gurl) {
- if (gIgnoreUrlChecksForTesting)
- return true;
+ SearchGeolocationService* service =
+ SearchGeolocationService::Factory::GetForBrowserContext(GetProfile());
- // Only show the disclosure for default search navigations from the omnibox.
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(GetProfile());
- bool is_search_url =
- template_url_service->IsSearchResultsPageFromDefaultSearchProvider(
- gurl);
- if (!is_search_url)
+ // Check the service first, as we don't want to show the infobar even when
+ // testing if it does not exist.
+ if (!service)
return false;
- // Only show the disclosure if Google is the default search engine.
- TemplateURL* default_search =
- template_url_service->GetDefaultSearchProvider();
- if (!default_search ||
- !default_search->url_ref().HasGoogleBaseURLs(
- template_url_service->search_terms_data())) {
- return false;
- }
+ if (gIgnoreUrlChecksForTesting)
+ return true;
- return true;
+ return service->UseDSEGeolocationSetting(url::Origin(gurl));
}
void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics(
@@ -201,15 +192,15 @@ void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics(
PrefService* prefs = GetProfile()->GetPrefs();
if (!prefs->GetBoolean(
prefs::kSearchGeolocationPreDisclosureMetricsRecorded)) {
- blink::mojom::PermissionStatus status =
- PermissionManager::Get(GetProfile())
- ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
- gurl);
- UMA_HISTOGRAM_ENUMERATION("GeolocationDisclosure.PreDisclosurePermission",
- static_cast<base::HistogramBase::Sample>(status),
- static_cast<base::HistogramBase::Sample>(
- blink::mojom::PermissionStatus::LAST) +
- 1);
+ ContentSetting status =
+ HostContentSettingsMapFactory::GetForProfile(GetProfile())
+ ->GetContentSetting(gurl, gurl, CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string());
+ UMA_HISTOGRAM_ENUMERATION(
+ "GeolocationDisclosure.PreDisclosureContentSetting",
+ static_cast<base::HistogramBase::Sample>(status),
+ static_cast<base::HistogramBase::Sample>(CONTENT_SETTING_NUM_SETTINGS) +
+ 1);
prefs->SetBoolean(prefs::kSearchGeolocationPreDisclosureMetricsRecorded,
true);
}
@@ -220,15 +211,15 @@ void SearchGeolocationDisclosureTabHelper::RecordPostDisclosureMetrics(
PrefService* prefs = GetProfile()->GetPrefs();
if (!prefs->GetBoolean(
prefs::kSearchGeolocationPostDisclosureMetricsRecorded)) {
- blink::mojom::PermissionStatus status =
- PermissionManager::Get(GetProfile())
- ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
- gurl);
- UMA_HISTOGRAM_ENUMERATION("GeolocationDisclosure.PostDisclosurePermission",
- static_cast<base::HistogramBase::Sample>(status),
- static_cast<base::HistogramBase::Sample>(
- blink::mojom::PermissionStatus::LAST) +
- 1);
+ ContentSetting status =
+ HostContentSettingsMapFactory::GetForProfile(GetProfile())
+ ->GetContentSetting(gurl, gurl, CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string());
+ UMA_HISTOGRAM_ENUMERATION(
+ "GeolocationDisclosure.PostDisclosureContentSetting",
+ static_cast<base::HistogramBase::Sample>(status),
+ static_cast<base::HistogramBase::Sample>(CONTENT_SETTING_NUM_SETTINGS) +
+ 1);
prefs->SetBoolean(prefs::kSearchGeolocationPostDisclosureMetricsRecorded,
true);
}

Powered by Google App Engine
This is Rietveld 408576698