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 #ifndef CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <functional> | 9 #include <functional> |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 13 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
14 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
15 | 15 |
16 // This class replaces the ChromeWebUIFactory when the switches::kTestType flag | 16 // This class replaces the ChromeWebUIFactory when the switches::kTestType flag |
17 // is passed. It provides a registry to override CreateWebUIForURL() by host. | 17 // is passed. It provides a registry to override CreateWebUIControllerForURL() |
18 class TestChromeWebUIFactory : public ChromeWebUIFactory { | 18 // by host. |
| 19 class TestChromeWebUIControllerFactory : public ChromeWebUIControllerFactory { |
19 public: | 20 public: |
20 // Interface to create a new WebUI object. | 21 // Interface to create a new WebUI object. |
21 class WebUIProvider { | 22 class WebUIProvider { |
22 public: | 23 public: |
23 // Create and return a new WebUI object for the |tab_contents| based on the | 24 // Create and return a new WebUI object for the |tab_contents| based on the |
24 // |url|. | 25 // |url|. |
25 virtual content::WebUIController* NewWebUI(content::WebUI* web_ui, | 26 virtual content::WebUIController* NewWebUI(content::WebUI* web_ui, |
26 const GURL& url) = 0; | 27 const GURL& url) = 0; |
27 | 28 |
28 protected: | 29 protected: |
29 virtual ~WebUIProvider(); | 30 virtual ~WebUIProvider(); |
30 }; | 31 }; |
31 | 32 |
32 typedef std::map<std::string, WebUIProvider*> FactoryOverridesMap; | 33 typedef std::map<std::string, WebUIProvider*> FactoryOverridesMap; |
33 | 34 |
34 // Override the creation for urls having |host| with |provider|. | 35 // Override the creation for urls having |host| with |provider|. |
35 static void AddFactoryOverride(const std::string& host, | 36 static void AddFactoryOverride(const std::string& host, |
36 WebUIProvider* provider); | 37 WebUIProvider* provider); |
37 | 38 |
38 // Remove the override for urls having |host|. | 39 // Remove the override for urls having |host|. |
39 static void RemoveFactoryOverride(const std::string& host); | 40 static void RemoveFactoryOverride(const std::string& host); |
40 | 41 |
41 // ChromeWebUIFactory overrides. | 42 // ChromeWebUIFactory overrides. |
42 virtual content::WebUI::TypeID GetWebUIType( | 43 virtual content::WebUI::TypeID GetWebUIType( |
43 content::BrowserContext* browser_context, | 44 content::BrowserContext* browser_context, |
44 const GURL& url) const OVERRIDE; | 45 const GURL& url) const OVERRIDE; |
45 virtual content::WebUIController* CreateWebUIForURL( | 46 virtual content::WebUIController* CreateWebUIControllerForURL( |
46 content::WebUI* web_ui, const GURL& url) const OVERRIDE; | 47 content::WebUI* web_ui, const GURL& url) const OVERRIDE; |
47 | 48 |
48 // Return the singleton instance. | 49 // Return the singleton instance. |
49 static TestChromeWebUIFactory* GetInstance(); | 50 static TestChromeWebUIControllerFactory* GetInstance(); |
50 | 51 |
51 private: | 52 private: |
52 TestChromeWebUIFactory(); | 53 TestChromeWebUIControllerFactory(); |
53 virtual ~TestChromeWebUIFactory(); | 54 virtual ~TestChromeWebUIControllerFactory(); |
54 | 55 |
55 friend struct DefaultSingletonTraits<TestChromeWebUIFactory>; | 56 friend struct DefaultSingletonTraits<TestChromeWebUIControllerFactory>; |
56 | 57 |
57 // Return the WebUIProvider for the |url|'s host if it exists, otherwise NULL. | 58 // Return the WebUIProvider for the |url|'s host if it exists, otherwise NULL. |
58 WebUIProvider* GetWebUIProvider(Profile* profile, const GURL& url) const; | 59 WebUIProvider* GetWebUIProvider(Profile* profile, const GURL& url) const; |
59 | 60 |
60 // Stores the mapping of host to WebUIProvider. | 61 // Stores the mapping of host to WebUIProvider. |
61 FactoryOverridesMap factory_overrides_; | 62 FactoryOverridesMap factory_overrides_; |
62 | 63 |
63 DISALLOW_COPY_AND_ASSIGN(TestChromeWebUIFactory); | 64 DISALLOW_COPY_AND_ASSIGN(TestChromeWebUIControllerFactory); |
64 }; | 65 }; |
65 | 66 |
66 #endif // CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ | 67 #endif // CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ |
OLD | NEW |