diff options
author | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 16:47:40 +0000 |
---|---|---|
committer | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 16:47:40 +0000 |
commit | 899dfcaf3de8aeb7ae84be00c53c554417d7c493 (patch) | |
tree | d7457d0fff991dc26a8c765198c334fd139398ed /chrome/browser/custom_handlers | |
parent | 4548245c966267e9ece8228cca59511e3754e0b8 (diff) | |
download | chromium_src-899dfcaf3de8aeb7ae84be00c53c554417d7c493.zip chromium_src-899dfcaf3de8aeb7ae84be00c53c554417d7c493.tar.gz chromium_src-899dfcaf3de8aeb7ae84be00c53c554417d7c493.tar.bz2 |
Replacing the default handler for mailto and webcal
This CL was reviewed before here: http://codereview.chromium.org/10139002/
I did the change to it as requested by koz past the previous submission (changing the name)
TBR=benwells@chromium.org
BUG=123368
TEST=unit test
Review URL: https://chromiumcodereview.appspot.com/10317019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135849 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/custom_handlers')
3 files changed, 39 insertions, 1 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc index ab8753a..0300e6d 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc @@ -151,7 +151,8 @@ ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, delegate_(delegate), enabled_(true), enabled_io_(enabled_), - is_loading_(false) { + is_loading_(false), + is_loaded_(false) { } bool ProtocolHandlerRegistry::SilentlyHandleRegisterHandlerRequest( @@ -247,6 +248,8 @@ bool ProtocolHandlerRegistry::IsDefault( } void ProtocolHandlerRegistry::Load() { + // Any further default additions to the table will get rejected from now on. + is_loaded_ = true; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); is_loading_ = true; PrefService* prefs = profile_->GetPrefs(); @@ -708,3 +711,13 @@ void ProtocolHandlerRegistry::IgnoreProtocolHandler( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); ignored_protocol_handlers_.push_back(handler); } + +void ProtocolHandlerRegistry::AddPredefinedHandler( + const ProtocolHandler& handler) { + // If called after the load command was issued this function will fail. + DCHECK(!is_loaded_); + RegisterProtocolHandler(handler); + SetDefault(handler); +} + + diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h index 508a44c..18f0111 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.h +++ b/chrome/browser/custom_handlers/protocol_handler_registry.h @@ -191,6 +191,10 @@ class ProtocolHandlerRegistry bool enabled() const { return enabled_; } + // Add a predefined protocol handler. This has to be called before the first + // load command was issued, otherwise the command will be ignored. + void AddPredefinedHandler(const ProtocolHandler& handler); + private: friend class base::DeleteHelper<ProtocolHandlerRegistry>; friend struct content::BrowserThread::DeleteOnThread< @@ -280,6 +284,10 @@ class ProtocolHandlerRegistry // Whether or not we are loading. bool is_loading_; + // When the table gets loaded this flag will be set and any further calls to + // AddPredefinedHandler will be rejected. + bool is_loaded_; + DefaultClientObserverList default_client_observers_; // Copy of default_handlers_ that is only accessed on the IO thread. diff --git a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc index f5afb11..2760e01 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc @@ -229,6 +229,16 @@ class ProtocolHandlerRegistryTest : public testing::Test { registry_->Load(); } + void ReloadProtocolHandlerRegistryAndInstallDefaultHandler() { + delegate_ = new FakeDelegate(); + registry_->Finalize(); + registry_ = NULL; + registry_ = new ProtocolHandlerRegistry(profile(), delegate()); + registry_->AddPredefinedHandler(CreateProtocolHandler( + "test", GURL("http://test.com/%s"), "Test")); + registry_->Load(); + } + virtual void SetUp() { ui_message_loop_.reset(new MessageLoopForUI()); ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, @@ -796,3 +806,10 @@ TEST_F(ProtocolHandlerRegistryTest, TestIsSameOrigin) { ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), ph3.IsSameOrigin(ph2)); } + +TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) { + ReloadProtocolHandlerRegistryAndInstallDefaultHandler(); + std::vector<std::string> protocols; + registry()->GetRegisteredProtocols(&protocols); + ASSERT_EQ(static_cast<size_t>(1), protocols.size()); +} |