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

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

Issue 2721293002: Show the Android Location Settings Dialog when sites want permission. (Closed)
Patch Set: 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
« no previous file with comments | « chrome/browser/geolocation/geolocation_permission_context_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/feature_list.h"
11 #include "chrome/browser/android/location_settings.h" 12 #include "chrome/browser/android/location_settings.h"
12 #include "chrome/browser/android/location_settings_impl.h" 13 #include "chrome/browser/android/location_settings_impl.h"
13 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h" 14 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h"
14 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " 15 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h "
15 #include "chrome/browser/permissions/permission_request_id.h" 16 #include "chrome/browser/permissions/permission_request_id.h"
16 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" 17 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/common/chrome_features.h"
18 #include "components/infobars/core/infobar.h" 21 #include "components/infobars/core/infobar.h"
22 #include "components/search_engines/template_url.h"
23 #include "components/search_engines/template_url_service.h"
19 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
22 #include "url/gurl.h" 27 #include "url/gurl.h"
23 28
24 GeolocationPermissionContextAndroid:: 29 GeolocationPermissionContextAndroid::
25 GeolocationPermissionContextAndroid(Profile* profile) 30 GeolocationPermissionContextAndroid(Profile* profile)
26 : GeolocationPermissionContext(profile), 31 : GeolocationPermissionContext(profile),
27 location_settings_(new LocationSettingsImpl()), 32 location_settings_(new LocationSettingsImpl()),
28 permission_update_infobar_(nullptr), 33 permission_update_infobar_(nullptr),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 75
71 return value; 76 return value;
72 } 77 }
73 78
74 void GeolocationPermissionContextAndroid::RequestPermission( 79 void GeolocationPermissionContextAndroid::RequestPermission(
75 content::WebContents* web_contents, 80 content::WebContents* web_contents,
76 const PermissionRequestID& id, 81 const PermissionRequestID& id,
77 const GURL& requesting_frame_origin, 82 const GURL& requesting_frame_origin,
78 bool user_gesture, 83 bool user_gesture,
79 const BrowserPermissionCallback& callback) { 84 const BrowserPermissionCallback& callback) {
80 if (!location_settings_->CanSitesRequestLocationPermission(web_contents)) { 85 if (!location_settings_->CanSitesRequestLocationPermission(web_contents)) {
raymes 2017/03/02 03:04:04 I think we will need to change CanSitesRequestLoca
benwells 2017/03/02 04:19:28 Yep ... you're right - this won't work. I think i
raymes 2017/03/02 04:40:18 Sounds good to me. I think we would still need to
benwells 2017/03/02 04:48:02 In GetPermissoinStatus, if the content setting is
81 PermissionDecided(id, requesting_frame_origin, 86 PermissionDecided(id, requesting_frame_origin,
82 web_contents->GetLastCommittedURL().GetOrigin(), 87 web_contents->GetLastCommittedURL().GetOrigin(),
83 user_gesture, callback, false /* persist */, 88 user_gesture, callback, false /* persist */,
84 CONTENT_SETTING_BLOCK); 89 CONTENT_SETTING_BLOCK);
85 return; 90 return;
86 } 91 }
87 92
88 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); 93 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin();
89 ContentSetting content_setting = 94 ContentSetting content_setting =
90 GeolocationPermissionContext::GetPermissionStatus(requesting_frame_origin, 95 GeolocationPermissionContext::GetPermissionStatus(requesting_frame_origin,
(...skipping 30 matching lines...) Expand all
121 GeolocationPermissionContext::CancelPermissionRequest(web_contents, id); 126 GeolocationPermissionContext::CancelPermissionRequest(web_contents, id);
122 } 127 }
123 128
124 void GeolocationPermissionContextAndroid::NotifyPermissionSet( 129 void GeolocationPermissionContextAndroid::NotifyPermissionSet(
125 const PermissionRequestID& id, 130 const PermissionRequestID& id,
126 const GURL& requesting_origin, 131 const GURL& requesting_origin,
127 const GURL& embedding_origin, 132 const GURL& embedding_origin,
128 const BrowserPermissionCallback& callback, 133 const BrowserPermissionCallback& callback,
129 bool persist, 134 bool persist,
130 ContentSetting content_setting) { 135 ContentSetting content_setting) {
131 GeolocationPermissionContext::NotifyPermissionSet(id, requesting_origin, 136 if (content_setting == CONTENT_SETTING_ALLOW &&
132 embedding_origin, callback, 137 WillShowLocationSettingsDialog(requesting_origin, embedding_origin)) {
133 persist, content_setting); 138 // Work out if this is a default search engine origin.
139 bool is_dse_origin = false;
140 TemplateURLService* template_url_service =
141 TemplateURLServiceFactory::GetForProfile(profile());
142 if (template_url_service) {
143 const TemplateURL* template_url =
144 template_url_service->GetDefaultSearchProvider();
145 if (template_url) {
146 GURL search_url = template_url->GenerateSearchURL(
147 template_url_service->search_terms_data());
148 is_dse_origin = url::IsSameOriginWith(requesting_origin, search_url);
149 }
150 }
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.
134 151
135 // If this is the default search origin, and the DSE Geolocation setting is
136 // being used, potentially show the disclosure.
137 if (requesting_origin == embedding_origin) {
138 content::WebContents* web_contents = 152 content::WebContents* web_contents =
139 content::WebContents::FromRenderFrameHost( 153 content::WebContents::FromRenderFrameHost(
140 content::RenderFrameHost::FromID(id.render_process_id(), 154 content::RenderFrameHost::FromID(id.render_process_id(),
141 id.render_frame_id())); 155 id.render_frame_id()));
142 SearchGeolocationDisclosureTabHelper* disclosure_helper = 156 location_settings_->PromptToEnableSystemLocationSetting(
143 SearchGeolocationDisclosureTabHelper::FromWebContents(web_contents); 157 is_dse_origin ? LocationSettings::SEARCH : LocationSettings::DEFAULT,
158 web_contents,
159 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.
160 &GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown,
161 weak_factory_.GetWeakPtr(), id, requesting_origin, embedding_origin,
162 callback, persist, content_setting));
163 return;
164 }
144 165
145 // The tab helper can be null in tests. 166 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
146 if (disclosure_helper) 167 persist, content_setting);
147 disclosure_helper->MaybeShowDisclosure(requesting_origin);
148 }
149 } 168 }
150 169
151 void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions( 170 void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions(
152 const PermissionRequestID& id, 171 const PermissionRequestID& id,
153 const GURL& requesting_frame_origin, 172 const GURL& requesting_frame_origin,
154 const GURL& embedding_origin, 173 const GURL& embedding_origin,
155 const BrowserPermissionCallback& callback, 174 const BrowserPermissionCallback& callback,
156 bool permissions_updated) { 175 bool permissions_updated) {
157 permission_update_infobar_ = nullptr; 176 permission_update_infobar_ = nullptr;
158 177
159 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
160 ContentSetting new_setting = permissions_updated 179 ContentSetting new_setting = permissions_updated
161 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 180 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
162 181
163 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback, 182 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback,
164 false /* persist */, new_setting); 183 false /* persist */, new_setting);
165 } 184 }
166 185
186 bool GeolocationPermissionContextAndroid::WillShowLocationSettingsDialog(
187 const GURL& requesting_origin,
188 const GURL& embedding_origin) {
189 if (!base::FeatureList::IsEnabled(features::kLsdPermissionPrompt))
190 return false;
191
192 // TODO(benwells): Also check backoff.
193 return location_settings_->CanPromptToEnableSystemLocationSetting();
194 }
195
196 void GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown(
197 const PermissionRequestID& id,
198 const GURL& requesting_origin,
199 const GURL& embedding_origin,
200 const BrowserPermissionCallback& callback,
201 bool persist,
202 ContentSetting content_setting,
203 LocationSettings::LocationSettingsDialogPromptOutcome prompt_outcome) {
204 if (prompt_outcome != LocationSettings::GRANTED) {
205 content_setting = CONTENT_SETTING_BLOCK;
206 persist = false;
207 }
208
209 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
210 persist, content_setting);
211 }
212
213 void GeolocationPermissionContextAndroid::FinishNotifyPermissionSet(
214 const PermissionRequestID& id,
215 const GURL& requesting_origin,
216 const GURL& embedding_origin,
217 const BrowserPermissionCallback& callback,
218 bool persist,
219 ContentSetting content_setting) {
220 GeolocationPermissionContext::NotifyPermissionSet(id, requesting_origin,
221 embedding_origin, callback,
222 persist, content_setting);
223
224 // If this is the default search origin, and the DSE Geolocation setting is
225 // being used, potentially show the disclosure.
226 if (requesting_origin == embedding_origin) {
227 content::WebContents* web_contents =
228 content::WebContents::FromRenderFrameHost(
229 content::RenderFrameHost::FromID(id.render_process_id(),
230 id.render_frame_id()));
231 SearchGeolocationDisclosureTabHelper* disclosure_helper =
232 SearchGeolocationDisclosureTabHelper::FromWebContents(web_contents);
233
234 // The tab helper can be null in tests.
235 if (disclosure_helper)
236 disclosure_helper->MaybeShowDisclosure(requesting_origin);
237 }
238 }
239
167 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( 240 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting(
168 std::unique_ptr<LocationSettings> settings) { 241 std::unique_ptr<LocationSettings> settings) {
169 location_settings_ = std::move(settings); 242 location_settings_ = std::move(settings);
170 } 243 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/geolocation_permission_context_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698