Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / browser / webui / web_ui_controller_factory_registry.cc
blobede404d9939887171923fd3ded0cc7afe48aa2cd
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/webui/web_ui_controller_factory_registry.h"
7 #include "base/lazy_instance.h"
8 #include "content/public/common/url_constants.h"
9 #include "url/gurl.h"
11 namespace content {
13 base::LazyInstance<std::vector<WebUIControllerFactory*> > g_factories =
14 LAZY_INSTANCE_INITIALIZER;
16 void WebUIControllerFactory::RegisterFactory(WebUIControllerFactory* factory) {
17 g_factories.Pointer()->push_back(factory);
20 void WebUIControllerFactory::UnregisterFactoryForTesting(
21 WebUIControllerFactory* factory) {
22 std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
23 for (size_t i = 0; i < factories->size(); ++i) {
24 if ((*factories)[i] == factory) {
25 factories->erase(factories->begin() + i);
26 return;
29 NOTREACHED() << "Tried to unregister a factory but it wasn't found";
32 WebUIControllerFactoryRegistry* WebUIControllerFactoryRegistry::GetInstance() {
33 return Singleton<WebUIControllerFactoryRegistry>::get();
36 WebUIController* WebUIControllerFactoryRegistry::CreateWebUIControllerForURL(
37 WebUI* web_ui, const GURL& url) const {
38 std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
39 for (size_t i = 0; i < factories->size(); ++i) {
40 WebUIController* controller = (*factories)[i]->CreateWebUIControllerForURL(
41 web_ui, url);
42 if (controller)
43 return controller;
45 return NULL;
48 WebUI::TypeID WebUIControllerFactoryRegistry::GetWebUIType(
49 BrowserContext* browser_context, const GURL& url) const {
50 std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
51 for (size_t i = 0; i < factories->size(); ++i) {
52 WebUI::TypeID type = (*factories)[i]->GetWebUIType(browser_context, url);
53 if (type != WebUI::kNoWebUI)
54 return type;
56 return WebUI::kNoWebUI;
59 bool WebUIControllerFactoryRegistry::UseWebUIForURL(
60 BrowserContext* browser_context, const GURL& url) const {
61 std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
62 for (size_t i = 0; i < factories->size(); ++i) {
63 if ((*factories)[i]->UseWebUIForURL(browser_context, url))
64 return true;
66 return false;
69 bool WebUIControllerFactoryRegistry::UseWebUIBindingsForURL(
70 BrowserContext* browser_context, const GURL& url) const {
71 std::vector<WebUIControllerFactory*>* factories = g_factories.Pointer();
72 for (size_t i = 0; i < factories->size(); ++i) {
73 if ((*factories)[i]->UseWebUIBindingsForURL(browser_context, url))
74 return true;
76 return false;
79 bool WebUIControllerFactoryRegistry::IsURLAcceptableForWebUI(
80 BrowserContext* browser_context,
81 const GURL& url,
82 bool data_urls_allowed) const {
83 return UseWebUIForURL(browser_context, url) ||
84 // javascript: URLs are allowed to run in Web UI pages.
85 url.SchemeIs(kJavaScriptScheme) ||
86 // It's possible to load about:blank in a Web UI renderer.
87 // See http://crbug.com/42547
88 url.spec() == kAboutBlankURL ||
89 // Chrome URLs crash, kill, hang, and shorthang are allowed.
90 url == GURL(kChromeUICrashURL) ||
91 url == GURL(kChromeUIKillURL) ||
92 url == GURL(kChromeUIHangURL) ||
93 url == GURL(kChromeUIShorthangURL) ||
94 // Data URLs are usually not allowed in WebUI for security reasons.
95 // BalloonHosts are one exception needed by ChromeOS, and are safe because
96 // they cannot be scripted by other pages.
97 (data_urls_allowed && url.SchemeIs(chrome::kDataScheme));
100 WebUIControllerFactoryRegistry::WebUIControllerFactoryRegistry() {
103 WebUIControllerFactoryRegistry::~WebUIControllerFactoryRegistry() {
106 } // namespace content