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