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