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