Chromium Code Reviews| Index: chrome/browser/geolocation/chrome_geolocation_permission_context.cc |
| diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc |
| index 9964d30114a8b4611cd16968fe03d06d146e0b72..6f67a4cd7991b93c97c0cad4249825a79965a677 100644 |
| --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc |
| +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc |
| @@ -30,18 +30,11 @@ using WebKit::WebSecurityOrigin; |
| using content::BrowserThread; |
| using content::WebContents; |
| - |
| // GeolocationPermissionContext ----------------------------------------------- |
| -ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( |
| - Profile* profile) |
| - : profile_(profile), |
| - ALLOW_THIS_IN_INITIALIZER_LIST(geolocation_infobar_queue_controller_( |
| - new GeolocationInfoBarQueueController( |
| - base::Bind( |
| - &ChromeGeolocationPermissionContext::NotifyPermissionSet, |
| - base::Unretained(this)), |
| - profile))) { |
| +ChromeGeolocationPermissionContext* ChromeGeolocationPermissionContext::Create( |
| + Profile *profile) { |
|
bulach
2012/10/17 12:59:33
nit: s/Profile *p/Profile* p/
Ramya
2012/10/17 17:38:43
Done.
|
| + return new ChromeGeolocationPermissionContext(profile); |
| } |
| void ChromeGeolocationPermissionContext::RegisterUserPrefs( |
| @@ -52,6 +45,11 @@ void ChromeGeolocationPermissionContext::RegisterUserPrefs( |
| #endif |
| } |
| +ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( |
| + Profile* profile) |
| + : profile_(profile) { |
| +} |
| + |
| ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { |
| } |
| @@ -67,15 +65,58 @@ void ChromeGeolocationPermissionContext::RequestGeolocationPermission( |
| requesting_frame, callback)); |
| return; |
| } |
| + |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + WebContents* web_contents = |
| + tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| + if (chrome::GetViewType(web_contents) != chrome::VIEW_TYPE_TAB_CONTENTS) { |
| + // The tab may have gone away, or the request may not be from a tab at all. |
| + // TODO(mpcomplete): the request could be from a background page or |
| + // extension popup (tab_contents will have a different ViewType). But why do |
| + // we care? Shouldn't we still put an infobar up in the current tab? |
| + LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| + << render_process_id << "," << render_view_id << "," |
| + << bridge_id << " (can't prompt user without a visible tab)"; |
| + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, callback, false); |
| + return; |
| + } |
| + |
| + GURL embedder = web_contents->GetURL(); |
| + if (!requesting_frame.is_valid() || !embedder.is_valid()) { |
| + LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
| + << requesting_frame << "," << embedder |
| + << " (geolocation is not supported in popups)"; |
| + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, callback, false); |
| + return; |
| + } |
| + |
| + DecidePermission(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, embedder, callback); |
| +} |
| + |
| +void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| + int render_process_id, |
| + int render_view_id, |
| + int bridge_id, |
| + const GURL& requesting_frame) { |
| + CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); |
| +} |
| + |
| +void ChromeGeolocationPermissionContext::DecidePermission( |
| + int render_process_id, int render_view_id, int bridge_id, |
| + const GURL& requesting_frame, const GURL& embedder, |
| + base::Callback<void(bool)> callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| #if defined(OS_ANDROID) |
| // Check to see if the feature in its entirety has been disabled. |
| // This must happen before other services (e.g. tabs, extensions) |
| // get an opportunity to allow the geolocation request. |
| - if (!profile_->GetPrefs()->GetBoolean(prefs::kGeolocationEnabled)) { |
| - NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| - requesting_frame, callback, false); |
| + if (!profile()->GetPrefs()->GetBoolean(prefs::kGeolocationEnabled)) { |
| + PermissionDecided(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, embedder, callback, false); |
| return; |
| } |
| #endif |
| @@ -93,82 +134,50 @@ void ChromeGeolocationPermissionContext::RequestGeolocationPermission( |
| // Make sure the extension is in the calling process. |
| if (extension_service->process_map()->Contains( |
| extension->id(), render_process_id)) { |
| - NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| - requesting_frame, callback, true); |
| + PermissionDecided(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, embedder, callback, true); |
| return; |
| } |
| } |
| } |
| - WebContents* web_contents = |
| - tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| - if (chrome::GetViewType(web_contents) != chrome::VIEW_TYPE_TAB_CONTENTS) { |
| - // The tab may have gone away, or the request may not be from a tab at all. |
| - // TODO(mpcomplete): the request could be from a background page or |
| - // extension popup (tab_contents will have a different ViewType). But why do |
| - // we care? Shouldn't we still put an infobar up in the current tab? |
| - LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| - << render_process_id << "," << render_view_id << "," |
| - << bridge_id << " (can't prompt user without a visible tab)"; |
| - NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| - requesting_frame, callback, false); |
| - return; |
| - } |
| - |
| - GURL embedder = web_contents->GetURL(); |
| - if (!requesting_frame.is_valid() || !embedder.is_valid()) { |
| - LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
| - << requesting_frame << "," << embedder |
| - << " (geolocation is not supported in popups)"; |
| - NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| - requesting_frame, callback, false); |
| - return; |
| - } |
| - |
| ContentSetting content_setting = |
| profile_->GetHostContentSettingsMap()->GetContentSetting( |
| requesting_frame, |
| embedder, |
| CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| std::string()); |
| - if (content_setting == CONTENT_SETTING_BLOCK) { |
| - NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| - requesting_frame, callback, false); |
| - } else if (content_setting == CONTENT_SETTING_ALLOW) { |
| - NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| - requesting_frame, callback, true); |
| - } else { // setting == ask. Prompt the user. |
| - geolocation_infobar_queue_controller_->CreateInfoBarRequest( |
| - render_process_id, render_view_id, bridge_id, requesting_frame, |
| - embedder, callback); |
| + switch (content_setting) { |
| + case CONTENT_SETTING_BLOCK : |
|
bulach
2012/10/17 12:59:33
nit: here and the blocks below, no space before ":
Ramya
2012/10/17 17:38:43
Done.
|
| + PermissionDecided(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, embedder, callback, false); |
| + break; |
| + case CONTENT_SETTING_ALLOW : |
| + PermissionDecided(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, embedder, callback, true); |
| + break; |
| + default : |
| + // setting == ask. Prompt the user. |
| + QueueController()->CreateInfoBarRequest( |
| + render_process_id, render_view_id, bridge_id, requesting_frame, |
| + embedder, base::Bind( |
| + &ChromeGeolocationPermissionContext::NotifyPermissionSet, |
| + base::Unretained(this), |
| + render_process_id, render_view_id, bridge_id, requesting_frame, |
| + callback)); |
| } |
| } |
| -void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| +void ChromeGeolocationPermissionContext::PermissionDecided( |
| int render_process_id, |
| int render_view_id, |
| int bridge_id, |
| - const GURL& requesting_frame) { |
| - CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); |
| -} |
| - |
| -void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( |
| - int render_process_id, |
| - int render_view_id, |
| - int bridge_id) { |
| - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind( |
| - &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, |
| - this, render_process_id, render_view_id, bridge_id)); |
| - return; |
| - } |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - geolocation_infobar_queue_controller_->CancelInfoBarRequest( |
| - render_process_id, |
| - render_view_id, |
| - bridge_id); |
| + const GURL& requesting_frame, |
| + const GURL& embedder, |
| + base::Callback<void(bool)> callback, |
| + bool allowed) { |
| + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| + requesting_frame, callback, allowed); |
| } |
| void ChromeGeolocationPermissionContext::NotifyPermissionSet( |
| @@ -190,3 +199,36 @@ void ChromeGeolocationPermissionContext::NotifyPermissionSet( |
| callback.Run(allowed); |
| } |
| + |
| +GeolocationInfoBarQueueController* |
| +ChromeGeolocationPermissionContext::QueueController() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!geolocation_infobar_queue_controller_) |
| + geolocation_infobar_queue_controller_.reset(CreateQueueController()); |
| + return geolocation_infobar_queue_controller_.get(); |
| +} |
| + |
| +GeolocationInfoBarQueueController* |
| +ChromeGeolocationPermissionContext::CreateQueueController() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + return new GeolocationInfoBarQueueController(profile()); |
| +} |
| + |
| +void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( |
| + int render_process_id, |
| + int render_view_id, |
| + int bridge_id) { |
| + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind( |
| + &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, |
| + this, render_process_id, render_view_id, bridge_id)); |
| + return; |
| + } |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + QueueController()->CancelInfoBarRequest( |
| + render_process_id, |
| + render_view_id, |
| + bridge_id); |
| +} |