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 CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ | 5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ |
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ | 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "content/browser/webui/web_ui.h" |
10 #include "chrome/browser/favicon_service.h" | |
11 | 10 |
12 class WebUI; | 11 class Profile; |
| 12 class TabContents; |
13 class GURL; | 13 class GURL; |
14 class Profile; | |
15 class RefCountedMemory; | |
16 class TabContents; | |
17 | 14 |
18 // An opaque identifier used to identify a WebUI. This can only be compared to | 15 namespace content { |
19 // kNoWebUI or other WebUI types. See GetWebUIType. | |
20 typedef void* WebUITypeID; | |
21 | 16 |
| 17 // Interface for an object which controls which URLs are considered WebUI URLs |
| 18 // and creates WebUI instances for given URLs. |
22 class WebUIFactory { | 19 class WebUIFactory { |
23 public: | 20 public: |
24 // A special WebUI type that signifies that a given page would not use the | 21 // Returns a WebUI instance for the given URL, or NULL if the URL doesn't |
25 // Web UI system. | 22 // correspond to a WebUI. |
26 static const WebUITypeID kNoWebUI; | 23 virtual WebUI* CreateWebUIForURL(TabContents* source, |
| 24 const GURL& url) const = 0; |
27 | 25 |
28 // Returns a type identifier indicating what WebUI we would use for the | 26 // Gets the WebUI type for the given URL. This will return kNoWebUI if the |
29 // given URL. This is useful for comparing the potential WebUIs for two URLs. | 27 // corresponding call to CreateWebUIForURL would fail, or something non-NULL |
30 // Returns kNoWebUI if the given URL will not use the Web UI system. | 28 // if CreateWebUIForURL would succeed. |
31 static WebUITypeID GetWebUIType(Profile* profile, const GURL& url); | 29 virtual WebUI::TypeID GetWebUIType(Profile* profile, |
| 30 const GURL& url) const = 0; |
32 | 31 |
33 // Returns true if the given URL's scheme would trigger the Web UI system. | 32 // Shorthand for the above, but returns a simple yes/no. |
34 // This is a less precise test than UseDONUIForURL, which tells you whether | 33 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const = 0; |
35 // that specific URL matches a known one. This one is faster and can be used | |
36 // to determine security policy. | |
37 static bool HasWebUIScheme(const GURL& url); | |
38 | 34 |
39 // Returns true if the given URL must use the Web UI system. | 35 // Returns true if the url has a scheme for WebUI. This differs from the above |
40 static bool UseWebUIForURL(Profile* profile, const GURL& url); | 36 // in that it only checks the scheme; it is faster and can be used to |
| 37 // determine security policy. |
| 38 virtual bool HasWebUIScheme(const GURL& url) const = 0; |
41 | 39 |
42 // Returns true if the given URL can be loaded by Web UI system. This | 40 // Returns true if the given URL can be loaded by Web UI system. This allows |
43 // includes URLs that can be loaded by normal tabs as well, such as | 41 // URLs with WebUI types (as above) and also URLs that can be loaded by |
44 // javascript: URLs or about:hang. | 42 // normal tabs such as javascript: URLs or about:hang. |
45 static bool IsURLAcceptableForWebUI(Profile* profile, const GURL& url); | 43 virtual bool IsURLAcceptableForWebUI(Profile* profile, |
| 44 const GURL& url) const = 0; |
46 | 45 |
47 // Allocates a new WebUI object for the given URL, and returns it. If the URL | 46 virtual ~WebUIFactory() {} |
48 // is not a Web UI URL, then it will return NULL. When non-NULL, ownership of | |
49 // the returned pointer is passed to the caller. | |
50 static WebUI* CreateWebUIForURL(TabContents* tab_contents, const GURL& url); | |
51 | 47 |
52 // Get the favicon for |page_url| and forward the result to the |request| | 48 // Helper function to streamline retrieval of the current WebUIFactory. Only |
53 // when loaded. | 49 // to be used in content/. |
54 static void GetFaviconForURL(Profile* profile, | 50 static WebUIFactory* Get(); |
55 FaviconService::GetFaviconRequest* request, | |
56 const GURL& page_url); | |
57 | |
58 private: | |
59 // Gets the data for the favicon for a WebUI page. Returns NULL if the WebUI | |
60 // does not have a favicon. | |
61 static RefCountedMemory* GetFaviconResourceBytes(Profile* profile, | |
62 const GURL& page_url); | |
63 | |
64 DISALLOW_IMPLICIT_CONSTRUCTORS(WebUIFactory); | |
65 }; | 51 }; |
66 | 52 |
| 53 |
| 54 } // namespace content |
| 55 |
67 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ | 56 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ |
OLD | NEW |