This source file includes following definitions.
- RegisterFactory
- UnregisterFactoryForTesting
- GetInstance
- CreateWebUIControllerForURL
- GetWebUIType
- UseWebUIForURL
- UseWebUIBindingsForURL
- IsURLAcceptableForWebUI
#include "content/browser/webui/web_ui_controller_factory_registry.h"
#include "base/lazy_instance.h"
#include "content/browser/frame_host/debug_urls.h"
#include "content/public/common/url_constants.h"
#include "url/gurl.h"
namespace content {
base::LazyInstance<std::vector<WebUIControllerFactory*> > g_factories =
LAZY_INSTANCE_INITIALIZER;
void WebUIControllerFactory::RegisterFactory(WebUIControllerFactory* factory) {
g_factories.Pointer()->push_back(factory);
}
void WebUIControllerFactory::UnregisterFactoryForTesting(
WebUIControllerFactory* factory) {
std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
for (size_t i = 0; i < factories->size(); ++i) {
if ((*factories)[i] == factory) {
factories->erase(factories->begin() + i);
return;
}
}
NOTREACHED() << "Tried to unregister a factory but it wasn't found";
}
WebUIControllerFactoryRegistry* WebUIControllerFactoryRegistry::GetInstance() {
return Singleton<WebUIControllerFactoryRegistry>::get();
}
WebUIController* WebUIControllerFactoryRegistry::CreateWebUIControllerForURL(
WebUI* web_ui, const GURL& url) const {
std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
for (size_t i = 0; i < factories->size(); ++i) {
WebUIController* controller = (*factories)[i]->CreateWebUIControllerForURL(
web_ui, url);
if (controller)
return controller;
}
return NULL;
}
WebUI::TypeID WebUIControllerFactoryRegistry::GetWebUIType(
BrowserContext* browser_context, const GURL& url) const {
std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
for (size_t i = 0; i < factories->size(); ++i) {
WebUI::TypeID type = (*factories)[i]->GetWebUIType(browser_context, url);
if (type != WebUI::kNoWebUI)
return type;
}
return WebUI::kNoWebUI;
}
bool WebUIControllerFactoryRegistry::UseWebUIForURL(
BrowserContext* browser_context, const GURL& url) const {
std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
for (size_t i = 0; i < factories->size(); ++i) {
if ((*factories)[i]->UseWebUIForURL(browser_context, url))
return true;
}
return false;
}
bool WebUIControllerFactoryRegistry::UseWebUIBindingsForURL(
BrowserContext* browser_context, const GURL& url) const {
std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
for (size_t i = 0; i < factories->size(); ++i) {
if ((*factories)[i]->UseWebUIBindingsForURL(browser_context, url))
return true;
}
return false;
}
bool WebUIControllerFactoryRegistry::IsURLAcceptableForWebUI(
BrowserContext* browser_context,
const GURL& url) const {
return UseWebUIForURL(browser_context, url) ||
url.spec() == kAboutBlankURL ||
IsRendererDebugURL(url);
}
WebUIControllerFactoryRegistry::WebUIControllerFactoryRegistry() {
}
WebUIControllerFactoryRegistry::~WebUIControllerFactoryRegistry() {
}
}