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