diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-29 16:18:33 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-29 16:18:33 +0000 |
commit | e12b30268ea0dffc301a9bb06f25db6a924d6e00 (patch) | |
tree | 9892358261c8cb350d94727ad3a764c7cbb3f5f0 /content/browser/webui | |
parent | 8f34c55ab33c9ae2232c61913882be7e320f5542 (diff) | |
download | chromium_src-e12b30268ea0dffc301a9bb06f25db6a924d6e00.zip chromium_src-e12b30268ea0dffc301a9bb06f25db6a924d6e00.tar.gz chromium_src-e12b30268ea0dffc301a9bb06f25db6a924d6e00.tar.bz2 |
Move WebUIFactory to chrome/browser.
This reduces dependencies from content/ to chrome/.
WebUIFactory is the interface in content/ to ChromeWebUIFactory in chrome/
BUG=77092
TEST=none
Review URL: http://codereview.chromium.org/6713082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79691 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/webui')
-rw-r--r-- | content/browser/webui/empty_web_ui_factory.cc | 44 | ||||
-rw-r--r-- | content/browser/webui/empty_web_ui_factory.h | 37 | ||||
-rw-r--r-- | content/browser/webui/generic_handler.cc | 50 | ||||
-rw-r--r-- | content/browser/webui/generic_handler.h | 28 | ||||
-rw-r--r-- | content/browser/webui/web_ui.cc | 5 | ||||
-rw-r--r-- | content/browser/webui/web_ui.h | 8 | ||||
-rw-r--r-- | content/browser/webui/web_ui_factory.cc | 342 | ||||
-rw-r--r-- | content/browser/webui/web_ui_factory.h | 85 |
8 files changed, 213 insertions, 386 deletions
diff --git a/content/browser/webui/empty_web_ui_factory.cc b/content/browser/webui/empty_web_ui_factory.cc new file mode 100644 index 0000000..fd29847 --- /dev/null +++ b/content/browser/webui/empty_web_ui_factory.cc @@ -0,0 +1,44 @@ +// 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. + +#include "content/browser/webui/empty_web_ui_factory.h" + +namespace content { + +EmptyWebUIFactory::EmptyWebUIFactory() { +} + +EmptyWebUIFactory::~EmptyWebUIFactory() { +} + +WebUI* EmptyWebUIFactory::CreateWebUIForURL(TabContents* source, + const GURL& url) const { + return NULL; +} + +WebUI::TypeID EmptyWebUIFactory::GetWebUIType(Profile* profile, + const GURL& url) const { + return WebUI::kNoWebUI; +} + +bool EmptyWebUIFactory::UseWebUIForURL(Profile* profile, + const GURL& url) const { + return false; +} + +bool EmptyWebUIFactory::HasWebUIScheme(const GURL& url) const { + return false; +} + +bool EmptyWebUIFactory::IsURLAcceptableForWebUI(Profile* profile, + const GURL& url) const { + return false; +} + +// static +EmptyWebUIFactory* EmptyWebUIFactory::GetInstance() { + return Singleton<EmptyWebUIFactory>::get(); +} + +} // namespace content diff --git a/content/browser/webui/empty_web_ui_factory.h b/content/browser/webui/empty_web_ui_factory.h new file mode 100644 index 0000000..3778220 --- /dev/null +++ b/content/browser/webui/empty_web_ui_factory.h @@ -0,0 +1,37 @@ +// 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 CONTENT_BROWSER_WEBUI_EMPTY_WEB_UI_FACTORY_H_ +#define CONTENT_BROWSER_WEBUI_EMPTY_WEB_UI_FACTORY_H_ + +#include "base/memory/singleton.h" +#include "content/browser/webui/web_ui_factory.h" + +namespace content { + +// A stubbed out version of WebUIFactory. +class EmptyWebUIFactory : public content::WebUIFactory { + public: + // Returns the singleton instance. + static EmptyWebUIFactory* GetInstance(); + + virtual WebUI* CreateWebUIForURL(TabContents* source, + const GURL& url) const; + virtual WebUI::TypeID GetWebUIType(Profile* profile, + const GURL& url) const; + virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const; + virtual bool HasWebUIScheme(const GURL& url) const; + virtual bool IsURLAcceptableForWebUI(Profile* profile, + const GURL& url) const; + + private: + EmptyWebUIFactory(); + virtual ~EmptyWebUIFactory(); + + friend struct DefaultSingletonTraits<EmptyWebUIFactory>; +}; + +} // namespace content + +#endif // CONTENT_BROWSER_WEBUI_EMPTY_WEB_UI_FACTORY_H_ diff --git a/content/browser/webui/generic_handler.cc b/content/browser/webui/generic_handler.cc new file mode 100644 index 0000000..f4f57dc --- /dev/null +++ b/content/browser/webui/generic_handler.cc @@ -0,0 +1,50 @@ +// 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. + +#include "content/browser/webui/generic_handler.h" + +#include "base/logging.h" +#include "base/values.h" +#include "content/browser/disposition_utils.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "googleurl/src/gurl.h" + +GenericHandler::GenericHandler() { +} + +GenericHandler::~GenericHandler() { +} + +void GenericHandler::RegisterMessages() { + web_ui_->RegisterMessageCallback("navigateToUrl", + NewCallback(this, &GenericHandler::HandleNavigateToUrl)); +} + +void GenericHandler::HandleNavigateToUrl(const ListValue* args) { + std::string url_string; + double button; + bool alt_key; + bool ctrl_key; + bool meta_key; + bool shift_key; + + CHECK(args->GetString(0, &url_string)); + CHECK(args->GetDouble(1, &button)); + CHECK(args->GetBoolean(2, &alt_key)); + CHECK(args->GetBoolean(3, &ctrl_key)); + CHECK(args->GetBoolean(4, &meta_key)); + CHECK(args->GetBoolean(5, &shift_key)); + + CHECK(button == 0.0 || button == 1.0); + bool middle_button = (button == 1.0); + + WindowOpenDisposition disposition = + disposition_utils::DispositionFromClick(middle_button, alt_key, ctrl_key, + meta_key, shift_key); + + web_ui_->tab_contents()->OpenURL( + GURL(url_string), GURL(), disposition, PageTransition::LINK); + + // This may delete us! +} diff --git a/content/browser/webui/generic_handler.h b/content/browser/webui/generic_handler.h new file mode 100644 index 0000000..408ecbb --- /dev/null +++ b/content/browser/webui/generic_handler.h @@ -0,0 +1,28 @@ +// 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 CONTENT_BROWSER_WEBUI_GENERIC_HANDLER_H_ +#define CONTENT_BROWSER_WEBUI_GENERIC_HANDLER_H_ +#pragma once + +#include "content/browser/webui/web_ui.h" + +class ListValue; + +// A place to add handlers for messages shared across all WebUI pages. +class GenericHandler : public WebUIMessageHandler { + public: + GenericHandler(); + virtual ~GenericHandler(); + + // WebUIMessageHandler implementation. + virtual void RegisterMessages(); + + private: + void HandleNavigateToUrl(const ListValue* args); + + DISALLOW_COPY_AND_ASSIGN(GenericHandler); +}; + +#endif // CONTENT_BROWSER_WEBUI_GENERIC_HANDLER_H_ diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc index 9202958..3cc3633 100644 --- a/content/browser/webui/web_ui.cc +++ b/content/browser/webui/web_ui.cc @@ -10,14 +10,13 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/generic_handler.h" #include "chrome/common/bindings_policy.h" #include "chrome/common/extensions/extension_messages.h" #include "chrome/common/render_messages.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" +#include "content/browser/webui/generic_handler.h" namespace { @@ -59,6 +58,8 @@ WebUI::~WebUI() { // WebUI, public: ------------------------------------------------------------- +const WebUI::TypeID WebUI::kNoWebUI = NULL; + void WebUI::ProcessWebUIMessage( const ExtensionHostMsg_DomMessage_Params& params) { // Look up the callback for this message. diff --git a/content/browser/webui/web_ui.h b/content/browser/webui/web_ui.h index 98adcb1..4d0215f 100644 --- a/content/browser/webui/web_ui.h +++ b/content/browser/webui/web_ui.h @@ -144,6 +144,14 @@ class WebUI { TabContents* tab_contents() const { return tab_contents_; } + // An opaque identifier used to identify a WebUI. This can only be compared to + // kNoWebUI or other WebUI types. See GetWebUIType. + typedef void* TypeID; + + // A special WebUI type that signifies that a given page would not use the + // Web UI system. + static const TypeID kNoWebUI; + protected: void AddMessageHandler(WebUIMessageHandler* handler); diff --git a/content/browser/webui/web_ui_factory.cc b/content/browser/webui/web_ui_factory.cc index 04776a5..63a8c8e 100644 --- a/content/browser/webui/web_ui_factory.cc +++ b/content/browser/webui/web_ui_factory.cc @@ -4,344 +4,14 @@ #include "content/browser/webui/web_ui_factory.h" -#include "base/command_line.h" -#include "chrome/browser/about_flags.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_web_ui.h" -#include "chrome/browser/extensions/extensions_ui.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/bookmarks_ui.h" -#include "chrome/browser/ui/webui/bug_report_ui.h" -#include "chrome/browser/ui/webui/constrained_html_ui.h" -#include "chrome/browser/ui/webui/crashes_ui.h" -#include "chrome/browser/ui/webui/devtools_ui.h" -#include "chrome/browser/ui/webui/downloads_ui.h" -#include "chrome/browser/ui/webui/flags_ui.h" -#include "chrome/browser/ui/webui/gpu_internals_ui.h" -#include "chrome/browser/ui/webui/history2_ui.h" -#include "chrome/browser/ui/webui/history_ui.h" -#include "chrome/browser/ui/webui/html_dialog_ui.h" -#include "chrome/browser/ui/webui/net_internals_ui.h" -#include "chrome/browser/ui/webui/new_tab_ui.h" -#include "chrome/browser/ui/webui/options/options_ui.h" -#include "chrome/browser/ui/webui/plugins_ui.h" -#include "chrome/browser/ui/webui/print_preview_ui.h" -#include "chrome/browser/ui/webui/remoting_ui.h" -#include "chrome/browser/ui/webui/slideshow_ui.h" -#include "chrome/browser/ui/webui/sync_internals_ui.h" -#include "chrome/browser/ui/webui/textfields_ui.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension_constants.h" -#include "chrome/common/url_constants.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "googleurl/src/gurl.h" +#include "content/browser/content_browser_client.h" +#include "content/common/content_client.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/ui/webui/chromeos/imageburner_ui.h" -#include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h" -#include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h" -#include "chrome/browser/ui/webui/chromeos/proxy_settings_ui.h" -#include "chrome/browser/ui/webui/chromeos/register_page_ui.h" -#include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h" -#include "chrome/browser/ui/webui/chromeos/system_info_ui.h" -#include "chrome/browser/ui/webui/filebrowse_ui.h" -#include "chrome/browser/ui/webui/mediaplayer_ui.h" -#endif - -#if defined(TOUCH_UI) -#include "chrome/browser/ui/webui/keyboard_ui.h" -#endif - -#if defined(TOUCH_UI) && defined(OS_CHROMEOS) -#include "chrome/browser/ui/webui/chromeos/login/login_container_ui.h" -#include "chrome/browser/ui/webui/chromeos/login/login_ui.h" -#endif - -#if defined(OS_WIN) -#include "chrome/browser/ui/webui/conflicts_ui.h" -#endif - -const WebUITypeID WebUIFactory::kNoWebUI = NULL; - -// A function for creating a new WebUI. The caller owns the return value, which -// may be NULL (for example, if the URL refers to an non-existent extension). -typedef WebUI* (*WebUIFactoryFunction)(TabContents* tab_contents, - const GURL& url); - -// Template for defining WebUIFactoryFunction. -template<class T> -WebUI* NewWebUI(TabContents* contents, const GURL& url) { - return new T(contents); -} - -// Special case for extensions. -template<> -WebUI* NewWebUI<ExtensionWebUI>(TabContents* contents, const GURL& url) { - // Don't use a WebUI for incognito tabs because we require extensions to run - // within a single process. - ExtensionService* service = contents->profile()->GetExtensionService(); - if (service && - service->ExtensionBindingsAllowed(url)) { - return new ExtensionWebUI(contents, url); - } - return NULL; -} - -// Returns a function that can be used to create the right type of WebUI for a -// tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated -// with it. Even if the factory function is valid, it may yield a NULL WebUI -// when invoked for a particular tab - see NewWebUI<ExtensionWebUI>. -static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, - const GURL& url) { - if (url.host() == chrome::kChromeUIDialogHost) - return &NewWebUI<ConstrainedHtmlUI>; - - ExtensionService* service = profile ? profile->GetExtensionService() : NULL; - if (service && service->ExtensionBindingsAllowed(url)) - return &NewWebUI<ExtensionWebUI>; - - // All platform builds of Chrome will need to have a cloud printing - // dialog as backup. It's just that on Chrome OS, it's the only - // print dialog. - if (url.host() == chrome::kCloudPrintResourcesHost) - return &NewWebUI<ExternalHtmlDialogUI>; - - // This will get called a lot to check all URLs, so do a quick check of other - // schemes to filter out most URLs. - if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && - !url.SchemeIs(chrome::kChromeInternalScheme) && - !url.SchemeIs(chrome::kChromeUIScheme)) - return NULL; - - if (url.host() == chrome::kChromeUISyncResourcesHost || - url.host() == chrome::kChromeUIRemotingResourcesHost || - url.host() == chrome::kCloudPrintSetupHost) - return &NewWebUI<HtmlDialogUI>; - - // Special case the new tab page. In older versions of Chrome, the new tab - // page was hosted at chrome-internal:<blah>. This might be in people's saved - // sessions or bookmarks, so we say any URL with that scheme triggers the new - // tab page. - if (url.host() == chrome::kChromeUINewTabHost || - url.SchemeIs(chrome::kChromeInternalScheme)) - return &NewWebUI<NewTabUI>; - - // Give about:about a generic Web UI so it can navigate to pages with Web UIs. - if (url.spec() == chrome::kChromeUIAboutAboutURL) - return &NewWebUI<WebUI>; - - // We must compare hosts only since some of the Web UIs append extra stuff - // after the host name. - if (url.host() == chrome::kChromeUIBookmarksHost) - return &NewWebUI<BookmarksUI>; - if (url.host() == chrome::kChromeUIBugReportHost) - return &NewWebUI<BugReportUI>; - if (url.host() == chrome::kChromeUICrashesHost) - return &NewWebUI<CrashesUI>; - if (url.host() == chrome::kChromeUIDevToolsHost) - return &NewWebUI<DevToolsUI>; -#if defined(OS_WIN) - if (url.host() == chrome::kChromeUIConflictsHost) - return &NewWebUI<ConflictsUI>; -#endif - if (url.host() == chrome::kChromeUIDownloadsHost) - return &NewWebUI<DownloadsUI>; - if (url.host() == chrome::kChromeUITextfieldsHost) - return &NewWebUI<TextfieldsUI>; - if (url.host() == chrome::kChromeUIExtensionsHost) - return &NewWebUI<ExtensionsUI>; - if (url.host() == chrome::kChromeUIHistoryHost) - return &NewWebUI<HistoryUI>; - if (url.host() == chrome::kChromeUIHistory2Host) - return &NewWebUI<HistoryUI2>; - if (url.host() == chrome::kChromeUIFlagsHost) - return &NewWebUI<FlagsUI>; -#if defined(TOUCH_UI) - if (url.host() == chrome::kChromeUIKeyboardHost) - return &NewWebUI<KeyboardUI>; -#endif - if (url.host() == chrome::kChromeUIGpuInternalsHost) - return &NewWebUI<GpuInternalsUI>; - if (url.host() == chrome::kChromeUINetInternalsHost) - return &NewWebUI<NetInternalsUI>; - if (url.host() == chrome::kChromeUIPluginsHost) - return &NewWebUI<PluginsUI>; - if (url.host() == chrome::kChromeUISyncInternalsHost) - return &NewWebUI<SyncInternalsUI>; -#if defined(ENABLE_REMOTING) - if (url.host() == chrome::kChromeUIRemotingHost) { - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableRemoting)) { - return &NewWebUI<RemotingUI>; - } - } -#endif - -#if defined(OS_CHROMEOS) - if (url.host() == chrome::kChromeUICollectedCookiesHost || - url.host() == chrome::kChromeUIHttpAuthHost) - return &NewWebUI<ConstrainedHtmlUI>; - if (url.host() == chrome::kChromeUIFileBrowseHost) - return &NewWebUI<FileBrowseUI>; - if (url.host() == chrome::kChromeUIImageBurnerHost) - return &NewWebUI<ImageBurnUI>; - if (url.host() == chrome::kChromeUIKeyboardOverlayHost) - return &NewWebUI<KeyboardOverlayUI>; - if (url.host() == chrome::kChromeUIMediaplayerHost) - return &NewWebUI<MediaplayerUI>; - if (url.host() == chrome::kChromeUIMobileSetupHost) - return &NewWebUI<MobileSetupUI>; - if (url.host() == chrome::kChromeUIProxySettingsHost) - return &NewWebUI<chromeos::ProxySettingsUI>; - if (url.host() == chrome::kChromeUIRegisterPageHost) - return &NewWebUI<RegisterPageUI>; - if (url.host() == chrome::kChromeUISettingsHost) - return &NewWebUI<OptionsUI>; - if (url.host() == chrome::kChromeUISlideshowHost) - return &NewWebUI<SlideshowUI>; - if (url.host() == chrome::kChromeUISimUnlockHost) - return &NewWebUI<chromeos::SimUnlockUI>; - if (url.host() == chrome::kChromeUISystemInfoHost) - return &NewWebUI<SystemInfoUI>; -#else - if (url.host() == chrome::kChromeUISettingsHost) - return &NewWebUI<OptionsUI>; - if (url.host() == chrome::kChromeUIPrintHost) { - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnablePrintPreview)) { - return &NewWebUI<PrintPreviewUI>; - } - } -#endif // defined(OS_CHROMEOS) - -#if defined(TOUCH_UI) && defined(OS_CHROMEOS) - if (url.host() == chrome::kChromeUILoginHost) - return &NewWebUI<chromeos::LoginUI>; - if (url.host() == chrome::kChromeUILoginContainerHost) - return &NewWebUI<chromeos::LoginContainerUI>; -#endif - - if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL) - return &NewWebUI<ConstrainedHtmlUI>; - - return NULL; -} - -// static -WebUITypeID WebUIFactory::GetWebUIType(Profile* profile, const GURL& url) { - WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); - return function ? reinterpret_cast<WebUITypeID>(function) : kNoWebUI; -} - -// static -bool WebUIFactory::HasWebUIScheme(const GURL& url) { - return url.SchemeIs(chrome::kChromeDevToolsScheme) || - url.SchemeIs(chrome::kChromeInternalScheme) || - url.SchemeIs(chrome::kChromeUIScheme) || - url.SchemeIs(chrome::kExtensionScheme); -} +namespace content { // static -bool WebUIFactory::UseWebUIForURL(Profile* profile, const GURL& url) { - return GetWebUIFactoryFunction(profile, url) != NULL; +WebUIFactory* WebUIFactory::Get() { + return content::GetContentClient()->browser()->GetWebUIFactory(); } -// static -bool WebUIFactory::IsURLAcceptableForWebUI(Profile* profile, const GURL& url) { - return UseWebUIForURL(profile, url) || - // javacsript: URLs are allowed to run in Web UI pages - url.SchemeIs(chrome::kJavaScriptScheme) || - // It's possible to load about:blank in a Web UI renderer. - // See http://crbug.com/42547 - url.spec() == chrome::kAboutBlankURL || - // about:crash, about:kill, about:hang, and about:shorthang are allowed. - url.spec() == chrome::kAboutCrashURL || - url.spec() == chrome::kAboutKillURL || - url.spec() == chrome::kAboutHangURL || - url.spec() == chrome::kAboutShorthangURL; -} - -// static -WebUI* WebUIFactory::CreateWebUIForURL(TabContents* tab_contents, - const GURL& url) { - WebUIFactoryFunction function = GetWebUIFactoryFunction( - tab_contents->profile(), url); - if (!function) - return NULL; - return (*function)(tab_contents, url); -} - -// static -void WebUIFactory::GetFaviconForURL(Profile* profile, - FaviconService::GetFaviconRequest* request, - const GURL& page_url) { - // All extensions but the bookmark manager get their favicon from the icons - // part of the manifest. - if (page_url.SchemeIs(chrome::kExtensionScheme) && - page_url.host() != extension_misc::kBookmarkManagerId) { - ExtensionWebUI::GetFaviconForURL(profile, request, page_url); - } else { - history::FaviconData favicon; - favicon.image_data = scoped_refptr<RefCountedMemory>( - WebUIFactory::GetFaviconResourceBytes(profile, page_url)); - favicon.known_icon = favicon.image_data.get() != NULL && - favicon.image_data->size() > 0; - request->ForwardResultAsync( - FaviconService::FaviconDataCallback::TupleType(request->handle(), - favicon)); - } -} - -// static -RefCountedMemory* WebUIFactory::GetFaviconResourceBytes(Profile* profile, - const GURL& page_url) { - // The bookmark manager is a chrome extension, so we have to check for it - // before we check for extension scheme. - if (page_url.host() == extension_misc::kBookmarkManagerId) - return BookmarksUI::GetFaviconResourceBytes(); - - // The extension scheme is handled in GetFaviconForURL. - if (page_url.SchemeIs(chrome::kExtensionScheme)) { - NOTREACHED(); - return NULL; - } - - if (!HasWebUIScheme(page_url)) - return NULL; - -#if defined(OS_WIN) - if (page_url.host() == chrome::kChromeUIConflictsHost) - return ConflictsUI::GetFaviconResourceBytes(); -#endif - - if (page_url.host() == chrome::kChromeUICrashesHost) - return CrashesUI::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUIDownloadsHost) - return DownloadsUI::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUIExtensionsHost) - return ExtensionsUI::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUIHistoryHost) - return HistoryUI::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUIHistory2Host) - return HistoryUI2::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUIFlagsHost) - return FlagsUI::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUISettingsHost) - return OptionsUI::GetFaviconResourceBytes(); - - if (page_url.host() == chrome::kChromeUIPluginsHost) - return PluginsUI::GetFaviconResourceBytes(); - -#if defined(ENABLE_REMOTING) - if (page_url.host() == chrome::kChromeUIRemotingHost) - return RemotingUI::GetFaviconResourceBytes(); -#endif - - return NULL; -} +} // namespace content diff --git a/content/browser/webui/web_ui_factory.h b/content/browser/webui/web_ui_factory.h index 2be656a..0658c43 100644 --- a/content/browser/webui/web_ui_factory.h +++ b/content/browser/webui/web_ui_factory.h @@ -6,62 +6,51 @@ #define CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ #pragma once -#include "base/basictypes.h" -#include "chrome/browser/favicon_service.h" +#include "content/browser/webui/web_ui.h" -class WebUI; -class GURL; class Profile; -class RefCountedMemory; class TabContents; +class GURL; -// An opaque identifier used to identify a WebUI. This can only be compared to -// kNoWebUI or other WebUI types. See GetWebUIType. -typedef void* WebUITypeID; +namespace content { +// Interface for an object which controls which URLs are considered WebUI URLs +// and creates WebUI instances for given URLs. class WebUIFactory { public: - // A special WebUI type that signifies that a given page would not use the - // Web UI system. - static const WebUITypeID kNoWebUI; - - // Returns a type identifier indicating what WebUI we would use for the - // given URL. This is useful for comparing the potential WebUIs for two URLs. - // Returns kNoWebUI if the given URL will not use the Web UI system. - static WebUITypeID GetWebUIType(Profile* profile, const GURL& url); - - // Returns true if the given URL's scheme would trigger the Web UI system. - // This is a less precise test than UseDONUIForURL, which tells you whether - // that specific URL matches a known one. This one is faster and can be used - // to determine security policy. - static bool HasWebUIScheme(const GURL& url); - - // Returns true if the given URL must use the Web UI system. - static bool UseWebUIForURL(Profile* profile, const GURL& url); - - // Returns true if the given URL can be loaded by Web UI system. This - // includes URLs that can be loaded by normal tabs as well, such as - // javascript: URLs or about:hang. - static bool IsURLAcceptableForWebUI(Profile* profile, const GURL& url); - - // Allocates a new WebUI object for the given URL, and returns it. If the URL - // is not a Web UI URL, then it will return NULL. When non-NULL, ownership of - // the returned pointer is passed to the caller. - static WebUI* CreateWebUIForURL(TabContents* tab_contents, const GURL& url); - - // Get the favicon for |page_url| and forward the result to the |request| - // when loaded. - static void GetFaviconForURL(Profile* profile, - FaviconService::GetFaviconRequest* request, - const GURL& page_url); + // Returns a WebUI instance for the given URL, or NULL if the URL doesn't + // correspond to a WebUI. + virtual WebUI* CreateWebUIForURL(TabContents* source, + const GURL& url) const = 0; + + // Gets the WebUI type for the given URL. This will return kNoWebUI if the + // corresponding call to CreateWebUIForURL would fail, or something non-NULL + // if CreateWebUIForURL would succeed. + virtual WebUI::TypeID GetWebUIType(Profile* profile, + const GURL& url) const = 0; + + // Shorthand for the above, but returns a simple yes/no. + virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const = 0; + + // Returns true if the url has a scheme for WebUI. This differs from the above + // in that it only checks the scheme; it is faster and can be used to + // determine security policy. + virtual bool HasWebUIScheme(const GURL& url) const = 0; + + // Returns true if the given URL can be loaded by Web UI system. This allows + // URLs with WebUI types (as above) and also URLs that can be loaded by + // normal tabs such as javascript: URLs or about:hang. + virtual bool IsURLAcceptableForWebUI(Profile* profile, + const GURL& url) const = 0; + + virtual ~WebUIFactory() {} + + // Helper function to streamline retrieval of the current WebUIFactory. Only + // to be used in content/. + static WebUIFactory* Get(); +}; - private: - // Gets the data for the favicon for a WebUI page. Returns NULL if the WebUI - // does not have a favicon. - static RefCountedMemory* GetFaviconResourceBytes(Profile* profile, - const GURL& page_url); - DISALLOW_IMPLICIT_CONSTRUCTORS(WebUIFactory); -}; +} // namespace content #endif // CONTENT_BROWSER_WEBUI_WEB_UI_FACTORY_H_ |