Chromium Code Reviews| Index: chrome/browser/ui/webui/test_chrome_web_ui_factory.cc |
| diff --git a/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc b/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc8366569bd11c7626b909c58eb62b627cd28e7b |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright (c) 2011 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/ui/webui/test_chrome_web_ui_factory.h" |
| + |
| +#include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
| +#include "content/browser/tab_contents/tab_contents.h" |
| +#include "content/browser/webui/web_ui.h" |
| + |
| +TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() { |
| +} |
| + |
| +TestChromeWebUIFactory::TestChromeWebUIFactory() { |
| +} |
| + |
| +TestChromeWebUIFactory::~TestChromeWebUIFactory() { |
| +} |
| + |
| +void |
|
Evan Stade
2011/05/24 17:25:59
wrap the args rather than the return type
Sheridan Rawlins
2011/05/24 20:17:22
Done.
|
| +TestChromeWebUIFactory::AddFactoryOverride(const std::string& host, |
| + WebUIProvider* provider) { |
| + DCHECK_EQ(size_t(0), GetInstance()->factory_overrides_.count(host)); |
|
Evan Stade
2011/05/24 17:25:59
0U rather than size_t(0)
Sheridan Rawlins
2011/05/24 20:17:22
Done.
|
| + GetInstance()->factory_overrides_[host] = provider; |
| +} |
| + |
| +void |
| +TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) { |
| + DCHECK_EQ(size_t(1), GetInstance()->factory_overrides_.count(host)); |
| + GetInstance()->factory_overrides_.erase(host); |
| +} |
| + |
| +WebUI::TypeID |
| +TestChromeWebUIFactory::GetWebUIType(Profile* profile, const GURL& url) const { |
| + WebUIProvider* provider = GetWebUIProvider(profile, url); |
| + return provider ? reinterpret_cast<WebUI::TypeID>(provider) : |
| + ChromeWebUIFactory::GetWebUIType(profile, url); |
| +} |
| + |
| +WebUI* |
| +TestChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents, |
| + const GURL& url) const { |
| + WebUIProvider* provider = GetWebUIProvider(tab_contents->profile(), url); |
| + return provider ? provider->NewWebUI(tab_contents, url) : |
| + ChromeWebUIFactory::CreateWebUIForURL(tab_contents, url); |
| +} |
| + |
| +TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() { |
| + return static_cast<TestChromeWebUIFactory*>( |
| + ChromeWebUIFactory::GetInstance()); |
| +} |
| + |
| +TestChromeWebUIFactory::WebUIProvider* |
| +TestChromeWebUIFactory::GetWebUIProvider(Profile* profile, |
| + const GURL& url) const { |
| + FactoryOverridesMap::const_iterator found = |
| + factory_overrides_.find(url.host()); |
| + if (found != factory_overrides_.end()) { |
|
Evan Stade
2011/05/24 17:25:59
no curlies
Sheridan Rawlins
2011/05/24 20:17:22
Done.
|
| + return found->second; |
| + } |
| + return NULL; |
| +} |