Chromium Code Reviews| Index: chrome/browser/geolocation/geolocation_permission_context_android.cc |
| diff --git a/chrome/browser/geolocation/geolocation_permission_context_android.cc b/chrome/browser/geolocation/geolocation_permission_context_android.cc |
| index 3023c94b59d89b9670817cf4fdd41460e3c5cc4d..ebdd33f16998848afe85296c0b2775f603e8f81b 100644 |
| --- a/chrome/browser/geolocation/geolocation_permission_context_android.cc |
| +++ b/chrome/browser/geolocation/geolocation_permission_context_android.cc |
| @@ -8,6 +8,7 @@ |
| #include <vector> |
| #include "base/bind.h" |
| +#include "base/feature_list.h" |
| #include "chrome/browser/android/location_settings.h" |
| #include "chrome/browser/android/location_settings_impl.h" |
| #include "chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.h" |
| @@ -15,7 +16,11 @@ |
| #include "chrome/browser/permissions/permission_request_id.h" |
| #include "chrome/browser/permissions/permission_update_infobar_delegate_android.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/search_engines/template_url_service_factory.h" |
| +#include "chrome/common/chrome_features.h" |
| #include "components/infobars/core/infobar.h" |
| +#include "components/search_engines/template_url.h" |
| +#include "components/search_engines/template_url_service.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -128,24 +133,38 @@ void GeolocationPermissionContextAndroid::NotifyPermissionSet( |
| const BrowserPermissionCallback& callback, |
| bool persist, |
| ContentSetting content_setting) { |
| - GeolocationPermissionContext::NotifyPermissionSet(id, requesting_origin, |
| - embedding_origin, callback, |
| - persist, content_setting); |
| + if (content_setting == CONTENT_SETTING_ALLOW && |
| + WillShowLocationSettingsDialog(requesting_origin, embedding_origin)) { |
| + // Work out if this is a default search engine origin. |
| + bool is_dse_origin = false; |
| + TemplateURLService* template_url_service = |
| + TemplateURLServiceFactory::GetForProfile(profile()); |
| + if (template_url_service) { |
| + const TemplateURL* template_url = |
| + template_url_service->GetDefaultSearchProvider(); |
| + if (template_url) { |
| + GURL search_url = template_url->GenerateSearchURL( |
| + template_url_service->search_terms_data()); |
| + is_dse_origin = url::IsSameOriginWith(requesting_origin, search_url); |
| + } |
| + } |
|
raymes
2017/03/02 03:04:04
Just to clarify, this is intentionally different f
benwells
2017/03/02 04:19:28
Yep, that's correct.
|
| - // If this is the default search origin, and the DSE Geolocation setting is |
| - // being used, potentially show the disclosure. |
| - if (requesting_origin == embedding_origin) { |
| content::WebContents* web_contents = |
| content::WebContents::FromRenderFrameHost( |
| content::RenderFrameHost::FromID(id.render_process_id(), |
| id.render_frame_id())); |
| - SearchGeolocationDisclosureTabHelper* disclosure_helper = |
| - SearchGeolocationDisclosureTabHelper::FromWebContents(web_contents); |
| - |
| - // The tab helper can be null in tests. |
| - if (disclosure_helper) |
| - disclosure_helper->MaybeShowDisclosure(requesting_origin); |
| + location_settings_->PromptToEnableSystemLocationSetting( |
| + is_dse_origin ? LocationSettings::SEARCH : LocationSettings::DEFAULT, |
| + web_contents, |
| + base::Bind( |
|
qfiard
2017/03/01 20:38:49
You will need to switch to base::BindOnce since I
benwells
2017/03/03 01:43:09
Done.
|
| + &GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown, |
| + weak_factory_.GetWeakPtr(), id, requesting_origin, embedding_origin, |
| + callback, persist, content_setting)); |
| + return; |
| } |
| + |
| + FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + persist, content_setting); |
| } |
| void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions( |
| @@ -164,6 +183,60 @@ void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions( |
| false /* persist */, new_setting); |
| } |
| +bool GeolocationPermissionContextAndroid::WillShowLocationSettingsDialog( |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin) { |
| + if (!base::FeatureList::IsEnabled(features::kLsdPermissionPrompt)) |
| + return false; |
| + |
| + // TODO(benwells): Also check backoff. |
| + return location_settings_->CanPromptToEnableSystemLocationSetting(); |
| +} |
| + |
| +void GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown( |
| + const PermissionRequestID& id, |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin, |
| + const BrowserPermissionCallback& callback, |
| + bool persist, |
| + ContentSetting content_setting, |
| + LocationSettings::LocationSettingsDialogPromptOutcome prompt_outcome) { |
| + if (prompt_outcome != LocationSettings::GRANTED) { |
| + content_setting = CONTENT_SETTING_BLOCK; |
| + persist = false; |
| + } |
| + |
| + FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + persist, content_setting); |
| +} |
| + |
| +void GeolocationPermissionContextAndroid::FinishNotifyPermissionSet( |
| + const PermissionRequestID& id, |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin, |
| + const BrowserPermissionCallback& callback, |
| + bool persist, |
| + ContentSetting content_setting) { |
| + GeolocationPermissionContext::NotifyPermissionSet(id, requesting_origin, |
| + embedding_origin, callback, |
| + persist, content_setting); |
| + |
| + // If this is the default search origin, and the DSE Geolocation setting is |
| + // being used, potentially show the disclosure. |
| + if (requesting_origin == embedding_origin) { |
| + content::WebContents* web_contents = |
| + content::WebContents::FromRenderFrameHost( |
| + content::RenderFrameHost::FromID(id.render_process_id(), |
| + id.render_frame_id())); |
| + SearchGeolocationDisclosureTabHelper* disclosure_helper = |
| + SearchGeolocationDisclosureTabHelper::FromWebContents(web_contents); |
| + |
| + // The tab helper can be null in tests. |
| + if (disclosure_helper) |
| + disclosure_helper->MaybeShowDisclosure(requesting_origin); |
| + } |
| +} |
| + |
| void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( |
| std::unique_ptr<LocationSettings> settings) { |
| location_settings_ = std::move(settings); |