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