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

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

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures Created 8 years, 11 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
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_factory.h"
14 #include "content/browser/webui/web_ui.h" 14 #include "content/browser/webui/web_ui.h"
15 15
16 class GURL;
17 class Profile;
18
19 // This class replaces the ChromeWebUIFactory when the switches::kTestType flag 16 // This class replaces the ChromeWebUIFactory when the switches::kTestType flag
20 // is passed. It provides a registry to override CreateWebUIForURL() by host. 17 // is passed. It provides a registry to override CreateWebUIForURL() by host.
21 class TestChromeWebUIFactory : public ChromeWebUIFactory { 18 class TestChromeWebUIFactory : public ChromeWebUIFactory {
22 public: 19 public:
23 // Interface to create a new WebUI object. 20 // Interface to create a new WebUI object.
24 class WebUIProvider { 21 class WebUIProvider {
25 public: 22 public:
26 // Create and return a new WebUI object for the |tab_contents| based on the 23 // Create and return a new WebUI object for the |tab_contents| based on the
27 // |url|. 24 // |url|.
28 virtual WebUI* NewWebUI(content::WebContents* tab_contents, 25 virtual content::WebUIController* NewWebUI(WebUI* web_ui,
29 const GURL& url) = 0; 26 const GURL& url) = 0;
30 27
31 protected: 28 protected:
32 virtual ~WebUIProvider(); 29 virtual ~WebUIProvider();
33 }; 30 };
34 31
35 typedef std::map<std::string, WebUIProvider*> FactoryOverridesMap; 32 typedef std::map<std::string, WebUIProvider*> FactoryOverridesMap;
36 33
37 // Override the creation for urls having |host| with |provider|. 34 // Override the creation for urls having |host| with |provider|.
38 static void AddFactoryOverride(const std::string& host, 35 static void AddFactoryOverride(const std::string& host,
39 WebUIProvider* provider); 36 WebUIProvider* provider);
40 37
41 // Remove the override for urls having |host|. 38 // Remove the override for urls having |host|.
42 static void RemoveFactoryOverride(const std::string& host); 39 static void RemoveFactoryOverride(const std::string& host);
43 40
44 // ChromeWebUIFactory overrides. 41 // ChromeWebUIFactory overrides.
45 virtual WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, 42 virtual WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
46 const GURL& url) const OVERRIDE; 43 const GURL& url) const OVERRIDE;
47 virtual WebUI* CreateWebUIForURL(content::WebContents* web_contents, 44 virtual content::WebUIController* CreateWebUIForURL(
48 const GURL& url) const OVERRIDE; 45 WebUI* web_ui, const GURL& url) const OVERRIDE;
49 46
50 // Return the singleton instance. 47 // Return the singleton instance.
51 static TestChromeWebUIFactory* GetInstance(); 48 static TestChromeWebUIFactory* GetInstance();
52 49
53 private: 50 private:
54 TestChromeWebUIFactory(); 51 TestChromeWebUIFactory();
55 virtual ~TestChromeWebUIFactory(); 52 virtual ~TestChromeWebUIFactory();
56 53
57 friend struct DefaultSingletonTraits<TestChromeWebUIFactory>; 54 friend struct DefaultSingletonTraits<TestChromeWebUIFactory>;
58 55
59 // Return the WebUIProvider for the |url|'s host if it exists, otherwise NULL. 56 // Return the WebUIProvider for the |url|'s host if it exists, otherwise NULL.
60 WebUIProvider* GetWebUIProvider(Profile* profile, const GURL& url) const; 57 WebUIProvider* GetWebUIProvider(Profile* profile, const GURL& url) const;
61 58
62 // Stores the mapping of host to WebUIProvider. 59 // Stores the mapping of host to WebUIProvider.
63 FactoryOverridesMap factory_overrides_; 60 FactoryOverridesMap factory_overrides_;
64 61
65 DISALLOW_COPY_AND_ASSIGN(TestChromeWebUIFactory); 62 DISALLOW_COPY_AND_ASSIGN(TestChromeWebUIFactory);
66 }; 63 };
67 64
68 #endif // CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_ 65 #endif // CHROME_BROWSER_UI_WEBUI_TEST_CHROME_WEB_UI_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698