OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
| 6 |
| 7 #include "content/browser/tab_contents/tab_contents.h" |
| 8 |
| 9 TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() { |
| 10 } |
| 11 |
| 12 TestChromeWebUIFactory::TestChromeWebUIFactory() { |
| 13 } |
| 14 |
| 15 TestChromeWebUIFactory::~TestChromeWebUIFactory() { |
| 16 } |
| 17 |
| 18 void TestChromeWebUIFactory::AddFactoryOverride(const std::string& host, |
| 19 WebUIProvider* provider) { |
| 20 DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host)); |
| 21 GetInstance()->factory_overrides_[host] = provider; |
| 22 } |
| 23 |
| 24 void TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) { |
| 25 DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host)); |
| 26 GetInstance()->factory_overrides_.erase(host); |
| 27 } |
| 28 |
| 29 WebUI::TypeID TestChromeWebUIFactory::GetWebUIType( |
| 30 Profile* profile, const GURL& url) const { |
| 31 WebUIProvider* provider = GetWebUIProvider(profile, url); |
| 32 return provider ? reinterpret_cast<WebUI::TypeID>(provider) : |
| 33 ChromeWebUIFactory::GetWebUIType(profile, url); |
| 34 } |
| 35 |
| 36 WebUI* TestChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents, |
| 37 const GURL& url) const { |
| 38 WebUIProvider* provider = GetWebUIProvider(tab_contents->profile(), url); |
| 39 return provider ? provider->NewWebUI(tab_contents, url) : |
| 40 ChromeWebUIFactory::CreateWebUIForURL(tab_contents, url); |
| 41 } |
| 42 |
| 43 TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() { |
| 44 return static_cast<TestChromeWebUIFactory*>( |
| 45 ChromeWebUIFactory::GetInstance()); |
| 46 } |
| 47 |
| 48 TestChromeWebUIFactory::WebUIProvider* TestChromeWebUIFactory::GetWebUIProvider( |
| 49 Profile* profile, const GURL& url) const { |
| 50 FactoryOverridesMap::const_iterator found = |
| 51 factory_overrides_.find(url.host()); |
| 52 return (found == factory_overrides_.end()) ? NULL : found->second; |
| 53 } |
OLD | NEW |