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 "content/browser/tab_contents/tab_contents.h" | 7 #include "content/browser/tab_contents/tab_contents.h" |
8 | 8 |
9 TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() { | 9 TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() { |
10 } | 10 } |
11 | 11 |
12 TestChromeWebUIFactory::TestChromeWebUIFactory() { | 12 TestChromeWebUIFactory::TestChromeWebUIFactory() { |
13 } | 13 } |
14 | 14 |
15 TestChromeWebUIFactory::~TestChromeWebUIFactory() { | 15 TestChromeWebUIFactory::~TestChromeWebUIFactory() { |
16 } | 16 } |
17 | 17 |
18 void TestChromeWebUIFactory::AddFactoryOverride(const std::string& host, | 18 void TestChromeWebUIFactory::AddFactoryOverride(const std::string& host, |
19 WebUIProvider* provider) { | 19 WebUIProvider* provider) { |
20 DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host)); | 20 DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host)); |
21 GetInstance()->factory_overrides_[host] = provider; | 21 GetInstance()->factory_overrides_[host] = provider; |
22 } | 22 } |
23 | 23 |
24 void TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) { | 24 void TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) { |
25 DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host)); | 25 DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host)); |
26 GetInstance()->factory_overrides_.erase(host); | 26 GetInstance()->factory_overrides_.erase(host); |
27 } | 27 } |
28 | 28 |
29 WebUI::TypeID TestChromeWebUIFactory::GetWebUIType( | 29 WebUI::TypeID TestChromeWebUIFactory::GetWebUIType( |
30 Profile* profile, const GURL& url) const { | 30 content::BrowserContext* browser_context, const GURL& url) const { |
| 31 Profile* profile = Profile::FromBrowserContext(browser_context); |
31 WebUIProvider* provider = GetWebUIProvider(profile, url); | 32 WebUIProvider* provider = GetWebUIProvider(profile, url); |
32 return provider ? reinterpret_cast<WebUI::TypeID>(provider) : | 33 return provider ? reinterpret_cast<WebUI::TypeID>(provider) : |
33 ChromeWebUIFactory::GetWebUIType(profile, url); | 34 ChromeWebUIFactory::GetWebUIType(profile, url); |
34 } | 35 } |
35 | 36 |
36 WebUI* TestChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents, | 37 WebUI* TestChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents, |
37 const GURL& url) const { | 38 const GURL& url) const { |
38 WebUIProvider* provider = GetWebUIProvider(tab_contents->profile(), url); | 39 WebUIProvider* provider = GetWebUIProvider(tab_contents->profile(), url); |
39 return provider ? provider->NewWebUI(tab_contents, url) : | 40 return provider ? provider->NewWebUI(tab_contents, url) : |
40 ChromeWebUIFactory::CreateWebUIForURL(tab_contents, url); | 41 ChromeWebUIFactory::CreateWebUIForURL(tab_contents, url); |
41 } | 42 } |
42 | 43 |
43 TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() { | 44 TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() { |
44 return static_cast<TestChromeWebUIFactory*>( | 45 return static_cast<TestChromeWebUIFactory*>( |
45 ChromeWebUIFactory::GetInstance()); | 46 ChromeWebUIFactory::GetInstance()); |
46 } | 47 } |
47 | 48 |
48 TestChromeWebUIFactory::WebUIProvider* TestChromeWebUIFactory::GetWebUIProvider( | 49 TestChromeWebUIFactory::WebUIProvider* TestChromeWebUIFactory::GetWebUIProvider( |
49 Profile* profile, const GURL& url) const { | 50 Profile* profile, const GURL& url) const { |
50 FactoryOverridesMap::const_iterator found = | 51 FactoryOverridesMap::const_iterator found = |
51 factory_overrides_.find(url.host()); | 52 factory_overrides_.find(url.host()); |
52 return (found == factory_overrides_.end()) ? NULL : found->second; | 53 return (found == factory_overrides_.end()) ? NULL : found->second; |
53 } | 54 } |
OLD | NEW |