| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur
e_tab_helper.h" | 5 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur
e_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 const content::LoadCommittedDetails& load_details) { | 80 const content::LoadCommittedDetails& load_details) { |
| 81 if (consistent_geolocation_enabled_) | 81 if (consistent_geolocation_enabled_) |
| 82 MaybeShowDisclosure(web_contents()->GetVisibleURL()); | 82 MaybeShowDisclosure(web_contents()->GetVisibleURL()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure( | 85 void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure( |
| 86 const GURL& gurl) { | 86 const GURL& gurl) { |
| 87 if (!ShouldShowDisclosureForUrl(gurl)) | 87 if (!ShouldShowDisclosureForUrl(gurl)) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 // Check that the Chrome app has geolocation permission. | |
| 91 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 92 if (!Java_GeolocationHeader_hasGeolocationPermission(env)) | |
| 93 return; | |
| 94 | |
| 95 // Don't show the infobar if the user has dismissed it, or they've seen it | 90 // Don't show the infobar if the user has dismissed it, or they've seen it |
| 96 // enough times already. | 91 // enough times already. |
| 97 PrefService* prefs = GetProfile()->GetPrefs(); | 92 PrefService* prefs = GetProfile()->GetPrefs(); |
| 98 bool dismissed_already = | 93 bool dismissed_already = |
| 99 prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed); | 94 prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed); |
| 100 int shown_count = | 95 int shown_count = |
| 101 prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount); | 96 prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount); |
| 102 if (dismissed_already || shown_count >= GetMaxShowCount()) { | 97 if (dismissed_already || shown_count >= GetMaxShowCount()) { |
| 103 // Record metrics for the state of permissions after the disclosure has been | 98 // Record metrics for the state of permissions after the disclosure has been |
| 104 // shown. This is not done immediately after showing the last disclosure | 99 // shown. This is not done immediately after showing the last disclosure |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 std::string()); | 123 std::string()); |
| 129 if (status != CONTENT_SETTING_ASK) | 124 if (status != CONTENT_SETTING_ASK) |
| 130 return; | 125 return; |
| 131 | 126 |
| 132 // And only show disclosure if the DSE geolocation setting is on. | 127 // And only show disclosure if the DSE geolocation setting is on. |
| 133 SearchGeolocationService* service = | 128 SearchGeolocationService* service = |
| 134 SearchGeolocationService::Factory::GetForBrowserContext(GetProfile()); | 129 SearchGeolocationService::Factory::GetForBrowserContext(GetProfile()); |
| 135 if (!service->GetDSEGeolocationSetting()) | 130 if (!service->GetDSEGeolocationSetting()) |
| 136 return; | 131 return; |
| 137 | 132 |
| 133 // Check that the Chrome app has geolocation permission. |
| 134 JNIEnv* env = base::android::AttachCurrentThread(); |
| 135 if (!Java_GeolocationHeader_hasGeolocationPermission(env)) |
| 136 return; |
| 137 |
| 138 // All good, let's show the disclosure and increment the shown count. | 138 // All good, let's show the disclosure and increment the shown count. |
| 139 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl); | 139 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl); |
| 140 shown_count++; | 140 shown_count++; |
| 141 prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count); | 141 prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count); |
| 142 prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate, | 142 prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate, |
| 143 GetTimeNow().ToInternalValue()); | 143 GetTimeNow().ToInternalValue()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // static | 146 // static |
| 147 void SearchGeolocationDisclosureTabHelper::ResetDisclosure(Profile* profile) { | 147 void SearchGeolocationDisclosureTabHelper::ResetDisclosure(Profile* profile) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 const base::android::JavaParamRef<jclass>& clazz) { | 235 const base::android::JavaParamRef<jclass>& clazz) { |
| 236 gIgnoreUrlChecksForTesting = true; | 236 gIgnoreUrlChecksForTesting = true; |
| 237 } | 237 } |
| 238 | 238 |
| 239 // static | 239 // static |
| 240 void SetDayOffsetForTesting(JNIEnv* env, | 240 void SetDayOffsetForTesting(JNIEnv* env, |
| 241 const base::android::JavaParamRef<jclass>& clazz, | 241 const base::android::JavaParamRef<jclass>& clazz, |
| 242 jint days) { | 242 jint days) { |
| 243 gDayOffsetForTesting = days; | 243 gDayOffsetForTesting = days; |
| 244 } | 244 } |
| OLD | NEW |