| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/geolocation/geolocation_permission_context_android.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 &GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown, | 150 &GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown, |
| 151 weak_factory_.GetWeakPtr(), id, requesting_origin, embedding_origin, | 151 weak_factory_.GetWeakPtr(), id, requesting_origin, embedding_origin, |
| 152 callback, persist, content_setting)); | 152 callback, persist, content_setting)); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 156 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 157 persist, content_setting); | 157 persist, content_setting); |
| 158 } | 158 } |
| 159 | 159 |
| 160 PermissionResult |
| 161 GeolocationPermissionContextAndroid::UpdatePermissionStatusWithDeviceStatus( |
| 162 PermissionResult result, |
| 163 const GURL& requesting_origin, |
| 164 const GURL& embedding_origin) const { |
| 165 if (base::FeatureList::IsEnabled(features::kLsdPermissionPrompt) && |
| 166 result.content_setting != CONTENT_SETTING_BLOCK) { |
| 167 if (!location_settings_->IsSystemLocationSettingEnabled()) { |
| 168 // As this is returning the status for possible future permission |
| 169 // requests, whose gesture status is unknown, pretend there is a user |
| 170 // gesture here. If there is a possibility of PROMPT (i.e. if there is a |
| 171 // user gesture attached to the later request) that should be returned, |
| 172 // not BLOCK. |
| 173 if (CanShowLocationSettingsDialog(requesting_origin, |
| 174 true /* user_gesture */)) { |
| 175 result.content_setting = CONTENT_SETTING_ASK; |
| 176 } else { |
| 177 result.content_setting = CONTENT_SETTING_BLOCK; |
| 178 } |
| 179 result.source = PermissionStatusSource::UNSPECIFIED; |
| 180 } |
| 181 |
| 182 if (result.content_setting != CONTENT_SETTING_BLOCK && |
| 183 !location_settings_->HasAndroidLocationPermission()) { |
| 184 // TODO(benwells): plumb through the RFH and use the associated |
| 185 // WebContents to check that the android location can be prompted for. |
| 186 result.content_setting = CONTENT_SETTING_ASK; |
| 187 result.source = PermissionStatusSource::UNSPECIFIED; |
| 188 } |
| 189 } |
| 190 |
| 191 return result; |
| 192 } |
| 193 |
| 160 bool GeolocationPermissionContextAndroid::IsLocationAccessPossible( | 194 bool GeolocationPermissionContextAndroid::IsLocationAccessPossible( |
| 161 content::WebContents* web_contents, | 195 content::WebContents* web_contents, |
| 162 const GURL& requesting_origin, | 196 const GURL& requesting_origin, |
| 163 bool user_gesture) { | 197 bool user_gesture) { |
| 164 return (location_settings_->HasAndroidLocationPermission() || | 198 return (location_settings_->HasAndroidLocationPermission() || |
| 165 location_settings_->CanPromptForAndroidLocationPermission( | 199 location_settings_->CanPromptForAndroidLocationPermission( |
| 166 web_contents)) && | 200 web_contents)) && |
| 167 (location_settings_->IsSystemLocationSettingEnabled() || | 201 (location_settings_->IsSystemLocationSettingEnabled() || |
| 168 CanShowLocationSettingsDialog(requesting_origin, user_gesture)); | 202 CanShowLocationSettingsDialog(requesting_origin, user_gesture)); |
| 169 } | 203 } |
| 170 | 204 |
| 171 LocationSettingsDialogContext | 205 LocationSettingsDialogContext |
| 172 GeolocationPermissionContextAndroid::GetLocationSettingsDialogContext( | 206 GeolocationPermissionContextAndroid::GetLocationSettingsDialogContext( |
| 173 const GURL& requesting_origin) { | 207 const GURL& requesting_origin) const { |
| 174 bool is_dse_origin = false; | 208 bool is_dse_origin = false; |
| 175 TemplateURLService* template_url_service = | 209 TemplateURLService* template_url_service = |
| 176 TemplateURLServiceFactory::GetForProfile(profile()); | 210 TemplateURLServiceFactory::GetForProfile(profile()); |
| 177 if (template_url_service) { | 211 if (template_url_service) { |
| 178 const TemplateURL* template_url = | 212 const TemplateURL* template_url = |
| 179 template_url_service->GetDefaultSearchProvider(); | 213 template_url_service->GetDefaultSearchProvider(); |
| 180 if (template_url) { | 214 if (template_url) { |
| 181 GURL search_url = template_url->GenerateSearchURL( | 215 GURL search_url = template_url->GenerateSearchURL( |
| 182 template_url_service->search_terms_data()); | 216 template_url_service->search_terms_data()); |
| 183 is_dse_origin = url::IsSameOriginWith(requesting_origin, search_url); | 217 is_dse_origin = url::IsSameOriginWith(requesting_origin, search_url); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 199 ContentSetting new_setting = permissions_updated | 233 ContentSetting new_setting = permissions_updated |
| 200 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 234 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 201 | 235 |
| 202 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback, | 236 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback, |
| 203 false /* persist */, new_setting); | 237 false /* persist */, new_setting); |
| 204 } | 238 } |
| 205 | 239 |
| 206 bool GeolocationPermissionContextAndroid::CanShowLocationSettingsDialog( | 240 bool GeolocationPermissionContextAndroid::CanShowLocationSettingsDialog( |
| 207 const GURL& requesting_origin, | 241 const GURL& requesting_origin, |
| 208 bool user_gesture) { | 242 bool user_gesture) const { |
| 209 if (!base::FeatureList::IsEnabled(features::kLsdPermissionPrompt)) | 243 if (!base::FeatureList::IsEnabled(features::kLsdPermissionPrompt)) |
| 210 return false; | 244 return false; |
| 211 | 245 |
| 212 // If this isn't the default search engine, a gesture is needed. | 246 // If this isn't the default search engine, a gesture is needed. |
| 213 if (GetLocationSettingsDialogContext(requesting_origin) == DEFAULT && | 247 if (GetLocationSettingsDialogContext(requesting_origin) == DEFAULT && |
| 214 !user_gesture) { | 248 !user_gesture) { |
| 215 return false; | 249 return false; |
| 216 } | 250 } |
| 217 | 251 |
| 218 // TODO(benwells): Also check backoff for |requesting_origin|. | 252 // TODO(benwells): Also check backoff for |requesting_origin|. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // The tab helper can be null in tests. | 297 // The tab helper can be null in tests. |
| 264 if (disclosure_helper) | 298 if (disclosure_helper) |
| 265 disclosure_helper->MaybeShowDisclosure(requesting_origin); | 299 disclosure_helper->MaybeShowDisclosure(requesting_origin); |
| 266 } | 300 } |
| 267 } | 301 } |
| 268 | 302 |
| 269 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( | 303 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( |
| 270 std::unique_ptr<LocationSettings> settings) { | 304 std::unique_ptr<LocationSettings> settings) { |
| 271 location_settings_ = std::move(settings); | 305 location_settings_ = std::move(settings); |
| 272 } | 306 } |
| OLD | NEW |