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

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_android.cc

Issue 2743603002: Reflect device status in geolocation permissions.request calls. (Closed)
Patch Set: Self review Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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
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 result.content_setting = CanShowLocationSettingsDialog(
raymes 2017/03/10 02:53:31 Maybe we should update the result.status here, oth
benwells 2017/03/10 04:19:19 Done.
174 requesting_origin, true /* user_gesture */)
175 ? CONTENT_SETTING_ASK
176 : CONTENT_SETTING_BLOCK;
raymes 2017/03/10 02:53:31 nit: This might be slightly clearer in the expande
benwells 2017/03/10 04:19:19 I've come to terms with the ternary operator, afte
177 }
178
179 if (result.content_setting != CONTENT_SETTING_BLOCK &&
180 !location_settings_->HasAndroidLocationPermission()) {
181 // TODO(benwells): plumb through the RFH and use the associated
182 // WebContents to check that the android location can be prompted for.
183 result.content_setting = CONTENT_SETTING_ASK;
184 }
185 }
186
187 return result;
188 }
189
160 bool GeolocationPermissionContextAndroid::IsLocationAccessPossible( 190 bool GeolocationPermissionContextAndroid::IsLocationAccessPossible(
161 content::WebContents* web_contents, 191 content::WebContents* web_contents,
162 const GURL& requesting_origin, 192 const GURL& requesting_origin,
163 bool user_gesture) { 193 bool user_gesture) {
164 return (location_settings_->HasAndroidLocationPermission() || 194 return (location_settings_->HasAndroidLocationPermission() ||
165 location_settings_->CanPromptForAndroidLocationPermission( 195 location_settings_->CanPromptForAndroidLocationPermission(
166 web_contents)) && 196 web_contents)) &&
167 (location_settings_->IsSystemLocationSettingEnabled() || 197 (location_settings_->IsSystemLocationSettingEnabled() ||
168 CanShowLocationSettingsDialog(requesting_origin, user_gesture)); 198 CanShowLocationSettingsDialog(requesting_origin, user_gesture));
169 } 199 }
170 200
171 LocationSettingsDialogContext 201 LocationSettingsDialogContext
172 GeolocationPermissionContextAndroid::GetLocationSettingsDialogContext( 202 GeolocationPermissionContextAndroid::GetLocationSettingsDialogContext(
173 const GURL& requesting_origin) { 203 const GURL& requesting_origin) const {
174 bool is_dse_origin = false; 204 bool is_dse_origin = false;
175 TemplateURLService* template_url_service = 205 TemplateURLService* template_url_service =
176 TemplateURLServiceFactory::GetForProfile(profile()); 206 TemplateURLServiceFactory::GetForProfile(profile());
177 if (template_url_service) { 207 if (template_url_service) {
178 const TemplateURL* template_url = 208 const TemplateURL* template_url =
179 template_url_service->GetDefaultSearchProvider(); 209 template_url_service->GetDefaultSearchProvider();
180 if (template_url) { 210 if (template_url) {
181 GURL search_url = template_url->GenerateSearchURL( 211 GURL search_url = template_url->GenerateSearchURL(
182 template_url_service->search_terms_data()); 212 template_url_service->search_terms_data());
183 is_dse_origin = url::IsSameOriginWith(requesting_origin, search_url); 213 is_dse_origin = url::IsSameOriginWith(requesting_origin, search_url);
(...skipping 14 matching lines...) Expand all
198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 228 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
199 ContentSetting new_setting = permissions_updated 229 ContentSetting new_setting = permissions_updated
200 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 230 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
201 231
202 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback, 232 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback,
203 false /* persist */, new_setting); 233 false /* persist */, new_setting);
204 } 234 }
205 235
206 bool GeolocationPermissionContextAndroid::CanShowLocationSettingsDialog( 236 bool GeolocationPermissionContextAndroid::CanShowLocationSettingsDialog(
207 const GURL& requesting_origin, 237 const GURL& requesting_origin,
208 bool user_gesture) { 238 bool user_gesture) const {
209 if (!base::FeatureList::IsEnabled(features::kLsdPermissionPrompt)) 239 if (!base::FeatureList::IsEnabled(features::kLsdPermissionPrompt))
210 return false; 240 return false;
211 241
212 // If this isn't the default search engine, a gesture is needed. 242 // If this isn't the default search engine, a gesture is needed.
213 if (GetLocationSettingsDialogContext(requesting_origin) == DEFAULT && 243 if (GetLocationSettingsDialogContext(requesting_origin) == DEFAULT &&
214 !user_gesture) { 244 !user_gesture) {
215 return false; 245 return false;
216 } 246 }
217 247
218 // TODO(benwells): Also check backoff for |requesting_origin|. 248 // TODO(benwells): Also check backoff for |requesting_origin|.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // The tab helper can be null in tests. 293 // The tab helper can be null in tests.
264 if (disclosure_helper) 294 if (disclosure_helper)
265 disclosure_helper->MaybeShowDisclosure(requesting_origin); 295 disclosure_helper->MaybeShowDisclosure(requesting_origin);
266 } 296 }
267 } 297 }
268 298
269 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( 299 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting(
270 std::unique_ptr<LocationSettings> settings) { 300 std::unique_ptr<LocationSettings> settings) {
271 location_settings_ = std::move(settings); 301 location_settings_ = std::move(settings);
272 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698