OLD | NEW |
1 // Copyright (c) 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.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); | 175 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); |
176 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) { | 176 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) { |
177 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " | 177 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
178 << requesting_frame_origin << "," << embedder | 178 << requesting_frame_origin << "," << embedder |
179 << " (geolocation is not supported in popups)"; | 179 << " (geolocation is not supported in popups)"; |
180 NotifyPermissionSet(id, requesting_frame_origin, result_callback, false); | 180 NotifyPermissionSet(id, requesting_frame_origin, result_callback, false); |
181 return; | 181 return; |
182 } | 182 } |
183 | 183 |
184 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture, | 184 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture, |
185 embedder, "", result_callback); | 185 embedder, result_callback); |
186 } | 186 } |
187 | 187 |
188 void GeolocationPermissionContext::CancelGeolocationPermissionRequest( | 188 void GeolocationPermissionContext::CancelGeolocationPermissionRequest( |
189 int render_process_id, | 189 int render_process_id, |
190 int render_view_id, | 190 int render_view_id, |
191 int bridge_id) { | 191 int bridge_id) { |
192 content::WebContents* web_contents = tab_util::GetWebContentsByID( | 192 content::WebContents* web_contents = tab_util::GetWebContentsByID( |
193 render_process_id, render_view_id); | 193 render_process_id, render_view_id); |
194 if (extensions_context_.CancelPermissionRequest(web_contents, bridge_id)) | 194 if (extensions_context_.CancelPermissionRequest(web_contents, bridge_id)) |
195 return; | 195 return; |
196 | 196 |
197 CancelPendingInfobarRequest(PermissionRequestID( | 197 CancelPendingInfobarRequest(PermissionRequestID( |
198 render_process_id, render_view_id, bridge_id, GURL())); | 198 render_process_id, render_view_id, bridge_id, GURL())); |
199 } | 199 } |
200 | 200 |
201 void GeolocationPermissionContext::DecidePermission( | 201 void GeolocationPermissionContext::DecidePermission( |
202 content::WebContents* web_contents, | 202 content::WebContents* web_contents, |
203 const PermissionRequestID& id, | 203 const PermissionRequestID& id, |
204 const GURL& requesting_frame, | 204 const GURL& requesting_frame, |
205 bool user_gesture, | 205 bool user_gesture, |
206 const GURL& embedder, | 206 const GURL& embedder, |
207 const std::string& accept_button_label, | |
208 base::Callback<void(bool)> callback) { | 207 base::Callback<void(bool)> callback) { |
209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
210 | 209 |
211 ContentSetting content_setting = | 210 ContentSetting content_setting = |
212 profile_->GetHostContentSettingsMap() | 211 profile_->GetHostContentSettingsMap() |
213 ->GetContentSettingAndMaybeUpdateLastUsage( | 212 ->GetContentSettingAndMaybeUpdateLastUsage( |
214 requesting_frame, | 213 requesting_frame, |
215 embedder, | 214 embedder, |
216 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 215 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
217 std::string()); | 216 std::string()); |
(...skipping 13 matching lines...) Expand all Loading... |
231 new GeolocationPermissionRequest( | 230 new GeolocationPermissionRequest( |
232 this, id, requesting_frame, embedder, user_gesture, callback, | 231 this, id, requesting_frame, embedder, user_gesture, callback, |
233 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); | 232 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); |
234 GeolocationPermissionRequest* request = request_ptr.get(); | 233 GeolocationPermissionRequest* request = request_ptr.get(); |
235 pending_requests_.add(id.ToString(), request_ptr.Pass()); | 234 pending_requests_.add(id.ToString(), request_ptr.Pass()); |
236 mgr->AddRequest(request); | 235 mgr->AddRequest(request); |
237 } | 236 } |
238 } else { | 237 } else { |
239 // setting == ask. Prompt the user. | 238 // setting == ask. Prompt the user. |
240 QueueController()->CreateInfoBarRequest( | 239 QueueController()->CreateInfoBarRequest( |
241 id, requesting_frame, embedder, accept_button_label, | 240 id, requesting_frame, embedder, |
242 base::Bind( | 241 base::Bind( |
243 &GeolocationPermissionContext::NotifyPermissionSet, | 242 &GeolocationPermissionContext::NotifyPermissionSet, |
244 base::Unretained(this), id, requesting_frame, callback)); | 243 base::Unretained(this), id, requesting_frame, callback)); |
245 } | 244 } |
246 } | 245 } |
247 } | 246 } |
248 | 247 |
249 void GeolocationPermissionContext::CreateInfoBarRequest( | 248 void GeolocationPermissionContext::CreateInfoBarRequest( |
250 const PermissionRequestID& id, | 249 const PermissionRequestID& id, |
251 const GURL& requesting_frame, | 250 const GURL& requesting_frame, |
252 const GURL& embedder, | 251 const GURL& embedder, |
253 const std::string accept_button_label, | |
254 base::Callback<void(bool)> callback) { | 252 base::Callback<void(bool)> callback) { |
255 QueueController()->CreateInfoBarRequest( | 253 QueueController()->CreateInfoBarRequest( |
256 id, requesting_frame, embedder, accept_button_label, base::Bind( | 254 id, requesting_frame, embedder, base::Bind( |
257 &GeolocationPermissionContext::NotifyPermissionSet, | 255 &GeolocationPermissionContext::NotifyPermissionSet, |
258 base::Unretained(this), id, requesting_frame, callback)); | 256 base::Unretained(this), id, requesting_frame, callback)); |
259 } | 257 } |
260 | 258 |
261 void GeolocationPermissionContext::RequestFinished( | 259 void GeolocationPermissionContext::RequestFinished( |
262 GeolocationPermissionRequest* request) { | 260 GeolocationPermissionRequest* request) { |
263 base::ScopedPtrHashMap<std::string, | 261 base::ScopedPtrHashMap<std::string, |
264 GeolocationPermissionRequest>::iterator it; | 262 GeolocationPermissionRequest>::iterator it; |
265 for (it = pending_requests_.begin(); it != pending_requests_.end(); ++it) { | 263 for (it = pending_requests_.begin(); it != pending_requests_.end(); ++it) { |
266 if (it->second == request) { | 264 if (it->second == request) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 if (cancelling != NULL && web_contents != NULL && | 333 if (cancelling != NULL && web_contents != NULL && |
336 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { | 334 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { |
337 PermissionBubbleManager::FromWebContents(web_contents)-> | 335 PermissionBubbleManager::FromWebContents(web_contents)-> |
338 CancelRequest(cancelling); | 336 CancelRequest(cancelling); |
339 } | 337 } |
340 return; | 338 return; |
341 } | 339 } |
342 | 340 |
343 QueueController()->CancelInfoBarRequest(id); | 341 QueueController()->CancelInfoBarRequest(id); |
344 } | 342 } |
OLD | NEW |