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

Unified Diff: chrome/browser/android/tab_android.cc

Issue 2475213002: Update the Google Search geolocation disclosure to make it more obvious. (Closed)
Patch Set: Created 4 years, 1 month 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/tab_android.cc
diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc
index 0d5ff1934de1f8e15b7747dda8598d778e8271d6..eb626b18ed8a07f5abc2f659a35c7ff7717c073f 100644
--- a/chrome/browser/android/tab_android.cc
+++ b/chrome/browser/android/tab_android.cc
@@ -8,6 +8,7 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
+#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
@@ -22,6 +23,7 @@
#include "chrome/browser/android/offline_pages/offline_page_bridge.h"
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
#include "chrome/browser/android/offline_pages/offline_page_utils.h"
+#include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate.h"
#include "chrome/browser/android/tab_web_contents_delegate_android.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
@@ -29,6 +31,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/prerender/prerender_contents.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
@@ -39,6 +42,7 @@
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/search.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
@@ -54,6 +58,7 @@
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tab_helpers.h"
+#include "chrome/common/chrome_features.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/search/instant_types.h"
#include "chrome/common/url_constants.h"
@@ -68,6 +73,8 @@
#include "components/offline_pages/offline_page_feature.h"
#include "components/offline_pages/offline_page_item.h"
#include "components/offline_pages/offline_page_model.h"
+#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_service.h"
#include "components/sessions/content/content_live_tab.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/url_formatter/url_fixer.h"
@@ -76,6 +83,7 @@
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/permission_type.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
@@ -637,6 +645,8 @@ TabAndroid::TabLoadStatus TabAndroid::LoadUrl(
load_params.intent_received_timestamp = intent_received_timestamp;
load_params.has_user_gesture = has_user_gesture;
web_contents()->GetController().LoadURLWithParams(load_params);
+
+ MaybeShowDefaultSearchGeolocationDisclosure(gurl);
gone 2016/11/04 23:21:48 Is it possible to add this to a WebContentsObserve
benwells 2016/11/07 08:36:06 Done.
}
return DEFAULT_PAGE_LOAD;
}
@@ -889,3 +899,44 @@ static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
return RegisterNativesImpl(env);
}
+
+void TabAndroid::MaybeShowDefaultSearchGeolocationDisclosure(GURL gurl) {
+ if (base::FeatureList::IsEnabled(features::kConsistentOmniboxGeolocation)) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(GetProfile());
+ // Only show the disclosure for default search navigations from the omnibox.
+ bool is_search_url =
+ template_url_service->IsSearchResultsPageFromDefaultSearchProvider(
+ gurl);
+ if (!is_search_url)
+ return;
+
+ // 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;
+ }
+
+ // Perform Java side checks for whether the disclosure should be shown.
+ JNIEnv* env = base::android::AttachCurrentThread();
+ if (!Java_Tab_couldShowDefaultSearchGeolocationDisclosure(
+ env, weak_java_tab_.get(env))) {
+ return;
+ }
+
+ // 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)
+ return;
+
+ // All good, let's show the disclosure.
+ SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698