Chromium Code Reviews| Index: chrome/browser/geolocation/geolocation_permission_context.cc |
| diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc |
| index d71a9353f6337fbbf616dba41dc8cc5dcde9579d..e812e00d514c30fb676bd1a1463b1f29316069f4 100644 |
| --- a/chrome/browser/geolocation/geolocation_permission_context.cc |
| +++ b/chrome/browser/geolocation/geolocation_permission_context.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/browser.h" |
| #include "chrome/browser/browser_list.h" |
| #include "chrome/browser/chrome_thread.h" |
| +#include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" |
| #include "chrome/browser/profile.h" |
| #include "chrome/browser/renderer_host/render_process_host.h" |
| @@ -116,14 +117,55 @@ GeolocationPermissionContext::~GeolocationPermissionContext() { |
| void GeolocationPermissionContext::RequestGeolocationPermission( |
| int render_process_id, int render_view_id, int bridge_id, |
| const GURL& requesting_frame) { |
| - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| - RequestPermissionFromUI(render_process_id, render_view_id, bridge_id, |
| - requesting_frame); |
| + if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| + ChromeThread::PostTask( |
| + ChromeThread::UI, FROM_HERE, |
| + NewRunnableMethod(this, |
| + &GeolocationPermissionContext::RequestGeolocationPermission, |
| + render_process_id, render_view_id, bridge_id, requesting_frame)); |
| + return; |
| + } |
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| + |
| + TabContents* tab_contents = |
| + tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| + if (!tab_contents) { |
| + // The tab may have gone away, or the request may not be from a tab at all. |
| + LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| + << render_process_id << "," << render_view_id << "," << bridge_id |
| + << " (geolocation is not supported in extensions)"; |
| + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, false); |
| + return; |
| + } |
| + |
| + GURL embedder = tab_contents->GetURL(); |
| + ContentSetting content_setting = |
| + profile_->GetGeolocationContentSettingsMap()->GetContentSetting( |
| + requesting_frame, embedder); |
| + if (content_setting == CONTENT_SETTING_BLOCK) { |
| + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, false); |
| + } else if (content_setting == CONTENT_SETTING_ALLOW) { |
| + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, true); |
| + } else { // setting == ask. Prompt the user. |
| + RequestPermissionFromUI(render_process_id, render_view_id, bridge_id, |
| + requesting_frame); |
| + } |
| } |
| void GeolocationPermissionContext::SetPermission( |
| int render_process_id, int render_view_id, int bridge_id, |
| const GURL& requesting_frame, bool allowed) { |
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| + TabContents* tab_contents = |
| + tab_util::GetTabContentsByID(render_process_id, render_view_id); |
|
joth
2010/03/26 13:53:06
should we have a check / if on tab_contents here?
bulach
2010/03/26 14:22:04
I don't think it's needed: this is called by the i
|
| + GURL embedder = tab_contents->GetURL(); |
| + ContentSetting content_setting = |
| + allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| + profile_->GetGeolocationContentSettingsMap()->SetContentSetting( |
| + requesting_frame.GetOrigin(), embedder.GetOrigin(), content_setting); |
| NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| requesting_frame, allowed); |
| } |
| @@ -142,14 +184,6 @@ GeolocationArbitrator* GeolocationPermissionContext::StartUpdatingRequested( |
| void GeolocationPermissionContext::RequestPermissionFromUI( |
| int render_process_id, int render_view_id, int bridge_id, |
| const GURL& requesting_frame) { |
| - if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| - ChromeThread::PostTask( |
| - ChromeThread::UI, FROM_HERE, |
| - NewRunnableMethod(this, |
| - &GeolocationPermissionContext::RequestPermissionFromUI, |
| - render_process_id, render_view_id, bridge_id, requesting_frame)); |
| - return; |
| - } |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| TabContents* tab_contents = |
| @@ -170,15 +204,6 @@ void GeolocationPermissionContext::RequestPermissionFromUI( |
| void GeolocationPermissionContext::NotifyPermissionSet( |
| int render_process_id, int render_view_id, int bridge_id, |
| const GURL& requesting_frame, bool allowed) { |
| - if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| - ChromeThread::PostTask( |
| - ChromeThread::UI, FROM_HERE, |
| - NewRunnableMethod(this, |
| - &GeolocationPermissionContext::NotifyPermissionSet, |
| - render_process_id, render_view_id, bridge_id, requesting_frame, |
| - allowed)); |
| - return; |
| - } |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| RenderViewHostDelegate::Resource* resource = |