diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 09:19:04 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 09:19:04 +0000 |
commit | c0561cc86a7dbcccfe6734bb31c4c3300c147b21 (patch) | |
tree | 5485bca9914503c6b077ac7ac63a09cec4a2221d /chrome/browser/geolocation | |
parent | 4af27103e51e25948d6000721a8ef4518619ba58 (diff) | |
download | chromium_src-c0561cc86a7dbcccfe6734bb31c4c3300c147b21.zip chromium_src-c0561cc86a7dbcccfe6734bb31c4c3300c147b21.tar.gz chromium_src-c0561cc86a7dbcccfe6734bb31c4c3300c147b21.tar.bz2 |
Make PermissionQueueController available from other content settings
Make these stuff available from other content settings, e.g. Web MIDI.
This change still have dependency from PermissionQueueController to
GeolocationInfoBarDelegate. It will be removed by the following change.
TEST=PermissionQueueControllerTests
BUG=257618
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/19376004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213063 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
14 files changed, 66 insertions, 648 deletions
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc index cdf6bc4..e3bfc92 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc @@ -11,12 +11,11 @@ #include "base/bind.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/content_settings/permission_request_id.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/suggest_permission_util.h" -#include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" -#include "chrome/browser/geolocation/geolocation_permission_request_id.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/common/extensions/extension.h" @@ -35,9 +34,9 @@ ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { // ChromeGeolocationPermissionContext may be destroyed on either the UI thread - // or the IO thread, but the GeolocationInfobarQueueController must have been + // or the IO thread, but the PermissionQueueController must have been // destroyed on the UI thread. - DCHECK(!geolocation_infobar_queue_controller_.get()); + DCHECK(!permission_queue_controller_.get()); } void ChromeGeolocationPermissionContext::RequestGeolocationPermission( @@ -62,7 +61,7 @@ void ChromeGeolocationPermissionContext::RequestGeolocationPermission( content::WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, render_view_id); - const GeolocationPermissionRequestID id(render_process_id, render_view_id, + const PermissionRequestID id(render_process_id, render_view_id, bridge_id); ExtensionService* extension_service = extensions::ExtensionSystem::Get(profile_)->extension_service(); @@ -112,12 +111,12 @@ void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( int render_view_id, int bridge_id, const GURL& requesting_frame) { - CancelPendingInfoBarRequest(GeolocationPermissionRequestID( + CancelPendingInfoBarRequest(PermissionRequestID( render_process_id, render_view_id, bridge_id)); } void ChromeGeolocationPermissionContext::DecidePermission( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback) { @@ -145,12 +144,12 @@ void ChromeGeolocationPermissionContext::DecidePermission( void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - geolocation_infobar_queue_controller_.reset(); + permission_queue_controller_.reset(); shutting_down_ = true; } void ChromeGeolocationPermissionContext::PermissionDecided( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback, @@ -159,7 +158,7 @@ void ChromeGeolocationPermissionContext::PermissionDecided( } void ChromeGeolocationPermissionContext::NotifyPermissionSet( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame, base::Callback<void(bool)> callback, bool allowed) { @@ -177,23 +176,24 @@ void ChromeGeolocationPermissionContext::NotifyPermissionSet( callback.Run(allowed); } -GeolocationInfoBarQueueController* +PermissionQueueController* ChromeGeolocationPermissionContext::QueueController() { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(!shutting_down_); - if (!geolocation_infobar_queue_controller_) - geolocation_infobar_queue_controller_.reset(CreateQueueController()); - return geolocation_infobar_queue_controller_.get(); + if (!permission_queue_controller_) + permission_queue_controller_.reset(CreateQueueController()); + return permission_queue_controller_.get(); } -GeolocationInfoBarQueueController* +PermissionQueueController* ChromeGeolocationPermissionContext::CreateQueueController() { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - return new GeolocationInfoBarQueueController(profile()); + return new PermissionQueueController(profile(), + CONTENT_SETTINGS_TYPE_GEOLOCATION); } void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( - const GeolocationPermissionRequestID& id) { + const PermissionRequestID& id) { if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.h b/chrome/browser/geolocation/chrome_geolocation_permission_context.h index fde8d5a..06b324d 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.h +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.h @@ -8,15 +8,15 @@ #include <string> #include "base/memory/scoped_ptr.h" -#include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" +#include "chrome/browser/content_settings/permission_queue_controller.h" #include "content/public/browser/geolocation_permission_context.h" -class GeolocationPermissionRequestID; +class PermissionRequestID; class Profile; // Chrome specific implementation of GeolocationPermissionContext; manages // Geolocation permissions flow, and delegates UI handling via -// GeolocationInfoBarQueueController. +// PermissionQueueController. class ChromeGeolocationPermissionContext : public content::GeolocationPermissionContext { public: @@ -45,13 +45,13 @@ class ChromeGeolocationPermissionContext // Return an instance of the infobar queue controller, creating it // if necessary. - GeolocationInfoBarQueueController* QueueController(); + PermissionQueueController* QueueController(); // Notifies whether or not the corresponding bridge is allowed to use // geolocation via // GeolocationPermissionContext::SetGeolocationPermissionResponse(). // Called on the UI thread. - void NotifyPermissionSet(const GeolocationPermissionRequestID& id, + void NotifyPermissionSet(const PermissionRequestID& id, const GURL& requesting_frame, base::Callback<void(bool)> callback, bool allowed); @@ -61,7 +61,7 @@ class ChromeGeolocationPermissionContext // Calls PermissionDecided if permission can be decided non-interactively, // or NotifyPermissionSet if permission decided by presenting an // infobar to the user. Called on the UI thread. - virtual void DecidePermission(const GeolocationPermissionRequestID& id, + virtual void DecidePermission(const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback); @@ -70,25 +70,24 @@ class ChromeGeolocationPermissionContext // the user. Can be overridden to introduce additional UI flow. // Should ultimately ensure that NotifyPermissionSet is called. // Called on the UI thread. - virtual void PermissionDecided(const GeolocationPermissionRequestID& id, + virtual void PermissionDecided(const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback, bool allowed); - // Create an InfoBarQueueController. overriden in derived classes to provide - // additional UI flow. Called on the UI thread. - virtual GeolocationInfoBarQueueController* CreateQueueController(); + // Create an PermissionQueueController. overriden in derived classes to + // provide additional UI flow. Called on the UI thread. + virtual PermissionQueueController* CreateQueueController(); private: // Removes any pending InfoBar request. - void CancelPendingInfoBarRequest(const GeolocationPermissionRequestID& id); + void CancelPendingInfoBarRequest(const PermissionRequestID& id); // These must only be accessed from the UI thread. Profile* const profile_; bool shutting_down_; - scoped_ptr<GeolocationInfoBarQueueController> - geolocation_infobar_queue_controller_; + scoped_ptr<PermissionQueueController> permission_queue_controller_; DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext); }; diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc index 3a8a978..afb213c 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc @@ -22,7 +22,7 @@ ChromeGeolocationPermissionContextAndroid:: } void ChromeGeolocationPermissionContextAndroid::DecidePermission( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback) { @@ -41,7 +41,7 @@ void ChromeGeolocationPermissionContextAndroid::DecidePermission( } void ChromeGeolocationPermissionContextAndroid::PermissionDecided( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback, diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_android.h b/chrome/browser/geolocation/chrome_geolocation_permission_context_android.h index 0dbed899..c14f224 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_android.h +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_android.h @@ -22,12 +22,12 @@ class ChromeGeolocationPermissionContextAndroid virtual ~ChromeGeolocationPermissionContextAndroid(); // ChromeGeolocationPermissionContext implementation: - virtual void DecidePermission(const GeolocationPermissionRequestID& id, + virtual void DecidePermission(const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback) OVERRIDE; - virtual void PermissionDecided(const GeolocationPermissionRequestID& id, + virtual void PermissionDecided(const PermissionRequestID& id, const GURL& requesting_frame, const GURL& embedder, base::Callback<void(bool)> callback, diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 10eae81..7a1c0e5 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -14,9 +14,9 @@ #include "base/synchronization/waitable_event.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/content_settings/permission_request_id.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h" -#include "chrome/browser/geolocation/geolocation_permission_request_id.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" @@ -101,8 +101,8 @@ class GeolocationPermissionContextTests virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; - GeolocationPermissionRequestID RequestID(int bridge_id); - GeolocationPermissionRequestID RequestIDForTab(int tab, int bridge_id); + PermissionRequestID RequestID(int bridge_id); + PermissionRequestID RequestIDForTab(int tab, int bridge_id); InfoBarService* infobar_service() { return InfoBarService::FromWebContents(web_contents()); } @@ -110,12 +110,11 @@ class GeolocationPermissionContextTests return InfoBarService::FromWebContents(extra_tabs_[tab]); } - void RequestGeolocationPermission(const GeolocationPermissionRequestID& id, + void RequestGeolocationPermission(const PermissionRequestID& id, const GURL& requesting_frame); - void CancelGeolocationPermissionRequest( - const GeolocationPermissionRequestID& id, - const GURL& requesting_frame); - void PermissionResponse(const GeolocationPermissionRequestID& id, + void CancelGeolocationPermissionRequest(const PermissionRequestID& id, + const GURL& requesting_frame); + void PermissionResponse(const PermissionRequestID& id, bool allowed); void CheckPermissionMessageSent(int bridge_id, bool allowed); void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); @@ -136,24 +135,25 @@ class GeolocationPermissionContextTests base::hash_map<int, std::pair<int, bool> > responses_; }; -GeolocationPermissionRequestID GeolocationPermissionContextTests::RequestID( +PermissionRequestID GeolocationPermissionContextTests::RequestID( int bridge_id) { - return GeolocationPermissionRequestID( + return PermissionRequestID( web_contents()->GetRenderProcessHost()->GetID(), web_contents()->GetRenderViewHost()->GetRoutingID(), bridge_id); } -GeolocationPermissionRequestID - GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) { - return GeolocationPermissionRequestID( +PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( + int tab, + int bridge_id) { + return PermissionRequestID( extra_tabs_[tab]->GetRenderProcessHost()->GetID(), extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), bridge_id); } void GeolocationPermissionContextTests::RequestGeolocationPermission( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame) { geolocation_permission_context_->RequestGeolocationPermission( id.render_process_id(), id.render_view_id(), id.bridge_id(), @@ -163,7 +163,7 @@ void GeolocationPermissionContextTests::RequestGeolocationPermission( } void GeolocationPermissionContextTests::CancelGeolocationPermissionRequest( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, const GURL& requesting_frame) { geolocation_permission_context_->CancelGeolocationPermissionRequest( id.render_process_id(), id.render_view_id(), id.bridge_id(), @@ -171,7 +171,7 @@ void GeolocationPermissionContextTests::CancelGeolocationPermissionRequest( } void GeolocationPermissionContextTests::PermissionResponse( - const GeolocationPermissionRequestID& id, + const PermissionRequestID& id, bool allowed) { responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); } diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate.cc b/chrome/browser/geolocation/geolocation_infobar_delegate.cc index 017c570..4e9c37d 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate.cc +++ b/chrome/browser/geolocation/geolocation_infobar_delegate.cc @@ -4,7 +4,7 @@ #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" -#include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" +#include "chrome/browser/content_settings/permission_queue_controller.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/navigation_details.h" @@ -27,8 +27,8 @@ typedef GeolocationInfoBarDelegate DelegateType; // static InfoBarDelegate* GeolocationInfoBarDelegate::Create( InfoBarService* infobar_service, - GeolocationInfoBarQueueController* controller, - const GeolocationPermissionRequestID& id, + PermissionQueueController* controller, + const PermissionRequestID& id, const GURL& requesting_frame, const std::string& display_languages) { const content::NavigationEntry* committed_entry = @@ -41,8 +41,8 @@ InfoBarDelegate* GeolocationInfoBarDelegate::Create( GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( InfoBarService* infobar_service, - GeolocationInfoBarQueueController* controller, - const GeolocationPermissionRequestID& id, + PermissionQueueController* controller, + const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, const std::string& display_languages) diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate.h b/chrome/browser/geolocation/geolocation_infobar_delegate.h index 4e63f64..93a6ab7 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate.h +++ b/chrome/browser/geolocation/geolocation_infobar_delegate.h @@ -7,11 +7,11 @@ #include <string> -#include "chrome/browser/geolocation/geolocation_permission_request_id.h" +#include "chrome/browser/content_settings/permission_request_id.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "url/gurl.h" -class GeolocationInfoBarQueueController; +class PermissionQueueController; class InfoBarService; // GeolocationInfoBarDelegates are created by the @@ -22,15 +22,15 @@ class GeolocationInfoBarDelegate : public ConfirmInfoBarDelegate { // Creates a geolocation infobar delegate and adds it to |infobar_service|. // Returns the delegate if it was successfully added. static InfoBarDelegate* Create(InfoBarService* infobar_service, - GeolocationInfoBarQueueController* controller, - const GeolocationPermissionRequestID& id, + PermissionQueueController* controller, + const PermissionRequestID& id, const GURL& requesting_frame, const std::string& display_languages); protected: GeolocationInfoBarDelegate(InfoBarService* infobar_service, - GeolocationInfoBarQueueController* controller, - const GeolocationPermissionRequestID& id, + PermissionQueueController* controller, + const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, const std::string& display_languages); @@ -54,8 +54,8 @@ class GeolocationInfoBarDelegate : public ConfirmInfoBarDelegate { virtual string16 GetLinkText() const OVERRIDE; virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - GeolocationInfoBarQueueController* controller_; - const GeolocationPermissionRequestID id_; + PermissionQueueController* controller_; + const PermissionRequestID id_; GURL requesting_frame_; int contents_unique_id_; std::string display_languages_; diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc b/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc index 032b7f4..52c2b5b 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc +++ b/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc @@ -13,8 +13,8 @@ GeolocationInfoBarDelegateAndroid::GeolocationInfoBarDelegateAndroid( InfoBarService* infobar_service, - GeolocationInfoBarQueueController* controller, - const GeolocationPermissionRequestID& id, + PermissionQueueController* controller, + const PermissionRequestID& id, const GURL& requesting_frame_url, int contents_unique_id, const std::string& display_languages) diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate_android.h b/chrome/browser/geolocation/geolocation_infobar_delegate_android.h index f5059e3..e247f7f 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate_android.h +++ b/chrome/browser/geolocation/geolocation_infobar_delegate_android.h @@ -14,8 +14,8 @@ class GeolocationInfoBarDelegateAndroid : public GeolocationInfoBarDelegate { public: GeolocationInfoBarDelegateAndroid( InfoBarService* infobar_service, - GeolocationInfoBarQueueController* controller, - const GeolocationPermissionRequestID& id, + PermissionQueueController* controller, + const PermissionRequestID& id, const GURL& requesting_frame_url, int contents_unique_id, const std::string& display_languages); diff --git a/chrome/browser/geolocation/geolocation_infobar_queue_controller.cc b/chrome/browser/geolocation/geolocation_infobar_queue_controller.cc deleted file mode 100644 index 69eb13e..0000000 --- a/chrome/browser/geolocation/geolocation_infobar_queue_controller.cc +++ /dev/null @@ -1,321 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" - -#include "base/prefs/pref_service.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/geolocation/geolocation_infobar_delegate.h" -#include "chrome/browser/infobars/infobar.h" -#include "chrome/browser/infobars/infobar_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/tab_contents/tab_util.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/pref_names.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" -#include "content/public/browser/web_contents.h" - - -// Utilities ------------------------------------------------------------------ - -namespace { - -InfoBarService* GetInfoBarService(const GeolocationPermissionRequestID& id) { - content::WebContents* web_contents = - tab_util::GetWebContentsByID(id.render_process_id(), id.render_view_id()); - return web_contents ? InfoBarService::FromWebContents(web_contents) : NULL; -} - -} - - -// GeolocationInfoBarQueueController::PendingInfoBarRequest ------------------- - -class GeolocationInfoBarQueueController::PendingInfoBarRequest { - public: - PendingInfoBarRequest(const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - const GURL& embedder, - PermissionDecidedCallback callback); - ~PendingInfoBarRequest(); - - bool IsForPair(const GURL& requesting_frame, - const GURL& embedder) const; - - const GeolocationPermissionRequestID& id() const { return id_; } - const GURL& requesting_frame() const { return requesting_frame_; } - bool has_infobar() const { return !!infobar_; } - InfoBarDelegate* infobar() { return infobar_; } - - void RunCallback(bool allowed); - void CreateInfoBar(GeolocationInfoBarQueueController* controller, - const std::string& display_languages); - - private: - GeolocationPermissionRequestID id_; - GURL requesting_frame_; - GURL embedder_; - PermissionDecidedCallback callback_; - InfoBarDelegate* infobar_; - - // Purposefully do not disable copying, as this is stored in STL containers. -}; - -GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest( - const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - const GURL& embedder, - PermissionDecidedCallback callback) - : id_(id), - requesting_frame_(requesting_frame), - embedder_(embedder), - callback_(callback), - infobar_(NULL) { -} - -GeolocationInfoBarQueueController::PendingInfoBarRequest:: - ~PendingInfoBarRequest() { -} - -bool GeolocationInfoBarQueueController::PendingInfoBarRequest::IsForPair( - const GURL& requesting_frame, - const GURL& embedder) const { - return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); -} - -void GeolocationInfoBarQueueController::PendingInfoBarRequest::RunCallback( - bool allowed) { - callback_.Run(allowed); -} - -void GeolocationInfoBarQueueController::PendingInfoBarRequest:: - CreateInfoBar(GeolocationInfoBarQueueController* controller, - const std::string& display_languages) { - infobar_ = GeolocationInfoBarDelegate::Create( - GetInfoBarService(id_), controller, id_, requesting_frame_, - display_languages); -} - - -// GeolocationInfoBarQueueController ------------------------------------------ - -GeolocationInfoBarQueueController::GeolocationInfoBarQueueController( - Profile* profile) - : profile_(profile) { -} - -GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() { -} - -void GeolocationInfoBarQueueController::CreateInfoBarRequest( - const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - const GURL& embedder, - PermissionDecidedCallback callback) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - - // We shouldn't get duplicate requests. - for (PendingInfoBarRequests::const_iterator i( - pending_infobar_requests_.begin()); - i != pending_infobar_requests_.end(); ++i) - DCHECK(!i->id().Equals(id)); - - pending_infobar_requests_.push_back(PendingInfoBarRequest( - id, requesting_frame, embedder, callback)); - if (!AlreadyShowingInfoBarForTab(id)) - ShowQueuedInfoBarForTab(id); -} - -void GeolocationInfoBarQueueController::CancelInfoBarRequest( - const GeolocationPermissionRequestID& id) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - - for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin()); - i != pending_infobar_requests_.end(); ++i) { - if (i->id().Equals(id)) { - if (i->has_infobar()) - GetInfoBarService(id)->RemoveInfoBar(i->infobar()); - else - pending_infobar_requests_.erase(i); - return; - } - } -} - -void GeolocationInfoBarQueueController::OnPermissionSet( - const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - const GURL& embedder, - bool update_content_setting, - bool allowed) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - - if (update_content_setting) - UpdateContentSetting(requesting_frame, embedder, allowed); - - // Cancel this request first, then notify listeners. TODO(pkasting): Why - // is this order important? - PendingInfoBarRequests requests_to_notify; - PendingInfoBarRequests infobars_to_remove; - for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); - i != pending_infobar_requests_.end(); ) { - if (i->IsForPair(requesting_frame, embedder)) { - requests_to_notify.push_back(*i); - if (i->id().Equals(id)) { - // The infobar that called us is i->infobar(), and it's currently in - // either Accept() or Cancel(). This means that RemoveInfoBar() will be - // called later on, and that will trigger a notification we're - // observing. - ++i; - } else if (i->has_infobar()) { - // This infobar is for the same frame/embedder pair, but in a different - // tab. We should remove it now that we've got an answer for it. - infobars_to_remove.push_back(*i); - ++i; - } else { - // We haven't created an infobar yet, just remove the pending request. - i = pending_infobar_requests_.erase(i); - } - } else { - ++i; - } - } - - // Remove all infobars for the same |requesting_frame| and |embedder|. - for (PendingInfoBarRequests::iterator i = infobars_to_remove.begin(); - i != infobars_to_remove.end(); ++i) - GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); - - // Send out the permission notifications. - for (PendingInfoBarRequests::iterator i = requests_to_notify.begin(); - i != requests_to_notify.end(); ++i) - i->RunCallback(allowed); -} - -void GeolocationInfoBarQueueController::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); - // We will receive this notification for all infobar closures, so we need to - // check whether this is the geolocation infobar we're tracking. Note that the - // InfoBarContainer (if any) may have received this notification before us and - // caused the infobar to be deleted, so it's not safe to dereference the - // contents of the infobar. The address of the infobar, however, is OK to - // use to find the PendingInfoBarRequest to remove because - // pending_infobar_requests_ will not have received any new entries between - // the NotificationService's call to InfoBarContainer::Observe and this - // method. - InfoBarDelegate* infobar = - content::Details<InfoBarRemovedDetails>(details)->first; - for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); - i != pending_infobar_requests_.end(); ++i) { - if (i->infobar() == infobar) { - GeolocationPermissionRequestID id(i->id()); - pending_infobar_requests_.erase(i); - ShowQueuedInfoBarForTab(id); - return; - } - } -} - -bool GeolocationInfoBarQueueController::AlreadyShowingInfoBarForTab( - const GeolocationPermissionRequestID& id) const { - for (PendingInfoBarRequests::const_iterator i( - pending_infobar_requests_.begin()); - i != pending_infobar_requests_.end(); ++i) { - if (i->id().IsForSameTabAs(id) && i->has_infobar()) - return true; - } - return false; -} - -void GeolocationInfoBarQueueController::ShowQueuedInfoBarForTab( - const GeolocationPermissionRequestID& id) { - DCHECK(!AlreadyShowingInfoBarForTab(id)); - - InfoBarService* infobar_service = GetInfoBarService(id); - if (!infobar_service) { - // We can get here for example during tab shutdown, when the - // InfoBarService is removing all existing infobars, thus calling back to - // Observe(). In this case the service still exists, and is supplied as the - // source of the notification we observed, but is no longer accessible from - // its WebContents. In this case we should just go ahead and cancel further - // infobars for this tab instead of trying to access the service. - ClearPendingInfoBarRequestsForTab(id); - return; - } - - for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); - i != pending_infobar_requests_.end(); ++i) { - if (i->id().IsForSameTabAs(id) && !i->has_infobar()) { - RegisterForInfoBarNotifications(infobar_service); - i->CreateInfoBar( - this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); - return; - } - } - - UnregisterForInfoBarNotifications(infobar_service); -} - -void GeolocationInfoBarQueueController::ClearPendingInfoBarRequestsForTab( - const GeolocationPermissionRequestID& id) { - for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); - i != pending_infobar_requests_.end(); ) { - if (i->id().IsForSameTabAs(id)) { - DCHECK(!i->has_infobar()); - i = pending_infobar_requests_.erase(i); - } else { - ++i; - } - } -} - -void GeolocationInfoBarQueueController::RegisterForInfoBarNotifications( - InfoBarService* infobar_service) { - if (!registrar_.IsRegistered( - this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::Source<InfoBarService>(infobar_service))) { - registrar_.Add(this, - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::Source<InfoBarService>(infobar_service)); - } -} - -void GeolocationInfoBarQueueController::UnregisterForInfoBarNotifications( - InfoBarService* infobar_service) { - if (registrar_.IsRegistered( - this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::Source<InfoBarService>(infobar_service))) { - registrar_.Remove(this, - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::Source<InfoBarService>(infobar_service)); - } -} - -void GeolocationInfoBarQueueController::UpdateContentSetting( - const GURL& requesting_frame, - const GURL& embedder, - bool allowed) { - if (requesting_frame.GetOrigin().SchemeIsFile()) { - // Chrome can be launched with --disable-web-security which allows - // geolocation requests from file:// URLs. We don't want to store these - // in the host content settings map. - return; - } - - ContentSetting content_setting = - allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; - profile_->GetHostContentSettingsMap()->SetContentSetting( - ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), - ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), - CONTENT_SETTINGS_TYPE_GEOLOCATION, - std::string(), - content_setting); -} diff --git a/chrome/browser/geolocation/geolocation_infobar_queue_controller.h b/chrome/browser/geolocation/geolocation_infobar_queue_controller.h deleted file mode 100644 index cc87cba..0000000 --- a/chrome/browser/geolocation/geolocation_infobar_queue_controller.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ -#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ - -#include "base/bind.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" - -class GURL; -class GeolocationPermissionRequestID; -class InfoBarService; -class Profile; - -// This class controls the geolocation infobar queue per profile, and it's -// used by GeolocationPermissionContext. -// An alternate approach would be to have this queue per tab, and use -// notifications to broadcast when permission is set / listen to notification to -// cancel pending requests. This may be specially useful if there are other -// things listening for such notifications. -// For the time being this class is self-contained and it doesn't seem pulling -// the notification infrastructure would simplify. -class GeolocationInfoBarQueueController : content::NotificationObserver { - public: - typedef base::Callback<void(bool /* allowed */)> PermissionDecidedCallback; - - explicit GeolocationInfoBarQueueController(Profile* profile); - virtual ~GeolocationInfoBarQueueController(); - - // The InfoBar will be displayed immediately if the tab is not already - // displaying one, otherwise it'll be queued. - void CreateInfoBarRequest(const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - const GURL& embedder, - PermissionDecidedCallback callback); - - // Cancels a specific infobar request. - void CancelInfoBarRequest(const GeolocationPermissionRequestID& id); - - // Called by the InfoBarDelegate to notify permission has been set. - // It'll notify and dismiss any other pending InfoBar request for the same - // |requesting_frame| and embedder. - void OnPermissionSet(const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - const GURL& embedder, - bool update_content_setting, - bool allowed); - - protected: - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - private: - class PendingInfoBarRequest; - class RequestEquals; - - typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests; - - // Returns true if a geolocation infobar is already visible for the tab - // corresponding to |id|. - bool AlreadyShowingInfoBarForTab( - const GeolocationPermissionRequestID& id) const; - - // Shows the next pending infobar for the tab corresponding to |id|, if any. - // Note that this may not be the pending request whose ID is |id| if other - // requests are higher in the queue. If we can't show infobars because there - // is no InfoBarService for this tab, removes all queued requests for this - // tab. - void ShowQueuedInfoBarForTab(const GeolocationPermissionRequestID& id); - - void ClearPendingInfoBarRequestsForTab( - const GeolocationPermissionRequestID& id); - - void RegisterForInfoBarNotifications(InfoBarService* infobar_service); - void UnregisterForInfoBarNotifications(InfoBarService* infobar_service); - - void UpdateContentSetting( - const GURL& requesting_frame, const GURL& embedder, bool allowed); - - content::NotificationRegistrar registrar_; - - Profile* const profile_; - PendingInfoBarRequests pending_infobar_requests_; - - DISALLOW_COPY_AND_ASSIGN(GeolocationInfoBarQueueController); -}; - -#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ diff --git a/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc b/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc deleted file mode 100644 index 10f563c..0000000 --- a/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" - -#include "base/synchronization/waitable_event.h" -#include "chrome/browser/geolocation/geolocation_permission_request_id.h" -#include "chrome/browser/infobars/infobar_service.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/browser/web_contents.h" -#include "content/public/test/mock_render_process_host.h" -#include "content/public/test/test_browser_thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -class GeolocationInfoBarQueueControllerTests - : public ChromeRenderViewHostTestHarness { - protected: - virtual void SetUp() OVERRIDE { - ChromeRenderViewHostTestHarness::SetUp(); - InfoBarService::CreateForWebContents(web_contents()); - } - - GeolocationPermissionRequestID RequestID(int bridge_id) { - return GeolocationPermissionRequestID( - web_contents()->GetRenderProcessHost()->GetID(), - web_contents()->GetRenderViewHost()->GetRoutingID(), - bridge_id); - } -}; - -class ObservationCountingQueueController : - public GeolocationInfoBarQueueController { - public: - explicit ObservationCountingQueueController(Profile* profile); - - int call_count() const { return call_count_; } - - private: - int call_count_; - - // GeolocationInfoBarQueueController - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - static void NotifyPermissionSet(const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - base::Callback<void(bool)> callback, - bool allowed); -}; - -ObservationCountingQueueController::ObservationCountingQueueController( - Profile* profile) - : GeolocationInfoBarQueueController( - profile), - call_count_(0) { -} - -void ObservationCountingQueueController::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - ++call_count_; - GeolocationInfoBarQueueController::Observe(type, source, details); -} - -void ObservationCountingQueueController::NotifyPermissionSet( - const GeolocationPermissionRequestID& id, - const GURL& requesting_frame, - base::Callback<void(bool)> callback, - bool allowed) { -} - - -TEST_F(GeolocationInfoBarQueueControllerTests, - OneObservationPerInfoBarCancelled) { - // When an infobar is cancelled, the infobar helper sends a notification to - // the controller. If the controller has another infobar queued, it should - // maintain its registration for notifications with the helper, but on the - // last infobar cancellation it should unregister for notifications. - // - // What we don't want is for the controller to unregister and then re-register - // for notifications, which can lead to getting notified multiple times. This - // test checks that in the case where the controller should remain registered - // for notifications, it gets notified exactly once." - - ObservationCountingQueueController infobar_queue_controller(profile()); - GURL url("http://www.example.com/geolocation"); - base::Callback<void(bool)> callback; - infobar_queue_controller.CreateInfoBarRequest(RequestID(0), url, url, - callback); - infobar_queue_controller.CreateInfoBarRequest(RequestID(1), url, url, - callback); - infobar_queue_controller.CancelInfoBarRequest(RequestID(0)); - EXPECT_EQ(1, infobar_queue_controller.call_count()); -}; diff --git a/chrome/browser/geolocation/geolocation_permission_request_id.cc b/chrome/browser/geolocation/geolocation_permission_request_id.cc deleted file mode 100644 index 89df8c4..0000000 --- a/chrome/browser/geolocation/geolocation_permission_request_id.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/geolocation/geolocation_permission_request_id.h" - -#include "base/strings/stringprintf.h" - - -GeolocationPermissionRequestID::GeolocationPermissionRequestID( - int render_process_id, - int render_view_id, - int bridge_id) - : render_process_id_(render_process_id), - render_view_id_(render_view_id), - bridge_id_(bridge_id) { -} - -GeolocationPermissionRequestID::~GeolocationPermissionRequestID() { -} - -bool GeolocationPermissionRequestID::Equals( - const GeolocationPermissionRequestID& other) const { - return IsForSameTabAs(other) && (bridge_id_ == other.bridge_id_); -} - -bool GeolocationPermissionRequestID::IsForSameTabAs( - const GeolocationPermissionRequestID& other) const { - return (render_process_id_ == other.render_process_id_) && - (render_view_id_ == other.render_view_id_); -} - -std::string GeolocationPermissionRequestID::ToString() const { - return base::StringPrintf("%d,%d,%d", render_process_id_, render_view_id_, - bridge_id_); -} diff --git a/chrome/browser/geolocation/geolocation_permission_request_id.h b/chrome/browser/geolocation/geolocation_permission_request_id.h deleted file mode 100644 index eb29de9..0000000 --- a/chrome/browser/geolocation/geolocation_permission_request_id.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_REQUEST_ID_H_ -#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_REQUEST_ID_H_ - -#include <string> - -// Uniquely identifies a particular geolocation permission request. -class GeolocationPermissionRequestID { - public: - GeolocationPermissionRequestID(int render_process_id, - int render_view_id, - int bridge_id); - ~GeolocationPermissionRequestID(); - - int render_process_id() const { return render_process_id_; } - int render_view_id() const { return render_view_id_; } - int bridge_id() const { return bridge_id_; } - - bool Equals(const GeolocationPermissionRequestID& other) const; - bool IsForSameTabAs(const GeolocationPermissionRequestID& other) const; - std::string ToString() const; - - private: - int render_process_id_; - int render_view_id_; - int bridge_id_; - - // Purposefully do not disable copying, as this is stored in STL containers. -}; - -#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_REQUEST_ID_H_ |