Chromium Code Reviews| Index: chrome/browser/ui/webui/test_chrome_web_ui_factory.h |
| diff --git a/chrome/browser/ui/webui/test_chrome_web_ui_factory.h b/chrome/browser/ui/webui/test_chrome_web_ui_factory.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b46d2e57136736544f36315b53e3b6d1a21b3d0 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/test_chrome_web_ui_factory.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ |
| +#define CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ |
| +#pragma once |
| + |
| +#include <functional> |
| +#include <map> |
| +#include <string> |
| + |
| +#include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
| +#include "content/browser/webui/web_ui.h" |
| + |
| +class GURL; |
| +class Profile; |
| +class TabContents; |
| + |
| +// This class replaces the ChromeWebUIFactory when the |switches::kTestType| |
| +// flag is passed. It provides a registry to override |CreateWebUIForURL| by |
|
Lei Zhang (Do not use)
2011/05/24 18:00:06
nit: |CreateWebUIForURL| should be just CreateWebU
Sheridan Rawlins
2011/05/24 20:17:22
Done.
|
| +// host. |
| +class TestChromeWebUIFactory : public ChromeWebUIFactory { |
| + public: |
| + // Interface to create a new |WebUI| object. |
| + class WebUIProvider { |
| + public: |
| + // Create and return a new WebUI object for the |tab_contents| based on the |
| + // |url|. |
| + virtual WebUI* NewWebUI(TabContents* tab_contents, |
| + const GURL& url) = 0; |
| + |
| + protected: |
| + virtual ~WebUIProvider(); |
| + }; |
| + |
| + typedef std::map<std::string, WebUIProvider*> FactoryOverridesMap; |
| + |
| + // Override the creation for urls having |host| with |provider|. |
| + static void AddFactoryOverride(const std::string& host, |
| + WebUIProvider* provider); |
| + |
| + // Remove the override for urls having |host|. |
| + static void RemoveFactoryOverride(const std::string& host); |
| + |
| + // ChromeWebUIFactory overrides. |
| + virtual WebUI::TypeID GetWebUIType(Profile* profile, |
| + const GURL& url) const OVERRIDE; |
| + virtual WebUI* CreateWebUIForURL(TabContents* tab_contents, |
| + const GURL& url) const OVERRIDE; |
| + |
| + // Return the singleton instance. |
| + static TestChromeWebUIFactory* GetInstance(); |
| + |
| + private: |
| + virtual ~TestChromeWebUIFactory(); |
| + |
| + friend struct DefaultSingletonTraits<TestChromeWebUIFactory>; |
| + |
| + // Return the WebUIProvider for the |url|'s host if it exists, otherwise NULL. |
| + WebUIProvider* GetWebUIProvider(Profile* profile, const GURL& url) const; |
| + |
| + // Stores the mapping of host to |WebUIProvider|. |
| + FactoryOverridesMap factory_overrides_; |
| + |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(TestChromeWebUIFactory); |
|
Evan Stade
2011/05/24 17:25:59
I think you should use DISALLOW_COPY_AND_ASSIGN an
Sheridan Rawlins
2011/05/24 20:17:22
Done.
|
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ |