Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/webui/test_chrome_web_ui_factory.h

Issue 6992019: Allow overriding WebUIFactory when test flag is set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment namespace end. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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|
21 // 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.
22 // host.
23 class TestChromeWebUIFactory : public ChromeWebUIFactory {
24 public:
25 // Interface to create a new |WebUI| object.
26 class WebUIProvider {
27 public:
28 // Create and return a new WebUI object for the |tab_contents| based on the
29 // |url|.
30 virtual WebUI* NewWebUI(TabContents* tab_contents,
31 const GURL& url) = 0;
32
33 protected:
34 virtual ~WebUIProvider();
35 };
36
37 typedef std::map<std::string, WebUIProvider*> FactoryOverridesMap;
38
39 // Override the creation for urls having |host| with |provider|.
40 static void AddFactoryOverride(const std::string& host,
41 WebUIProvider* provider);
42
43 // Remove the override for urls having |host|.
44 static void RemoveFactoryOverride(const std::string& host);
45
46 // ChromeWebUIFactory overrides.
47 virtual WebUI::TypeID GetWebUIType(Profile* profile,
48 const GURL& url) const OVERRIDE;
49 virtual WebUI* CreateWebUIForURL(TabContents* tab_contents,
50 const GURL& url) const OVERRIDE;
51
52 // Return the singleton instance.
53 static TestChromeWebUIFactory* GetInstance();
54
55 private:
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_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.
67 };
68
69 #endif // CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698