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