summaryrefslogtreecommitdiff
path: root/chromium/content/browser/webui/content_web_ui_controller_factory.cc
blob: 02a02de97ff5b2dc4d87fe0284967e1533808f30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2013 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/content_web_ui_controller_factory.h"

#include "build/build_config.h"
#include "content/browser/accessibility/accessibility_ui.h"
#include "content/browser/appcache/appcache_internals_ui.h"
#include "content/browser/gpu/gpu_internals_ui.h"
#include "content/browser/indexed_db/indexed_db_internals_ui.h"
#include "content/browser/media/media_internals_ui.h"
#include "content/browser/net/network_errors_listing_ui.h"
#include "content/browser/service_worker/service_worker_internals_ui.h"
#include "content/browser/tracing/tracing_ui.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/url_constants.h"
#include "media/media_features.h"

#if BUILDFLAG(ENABLE_WEBRTC)
#include "content/browser/webrtc/webrtc_internals_ui.h"
#endif

namespace content {

WebUI::TypeID ContentWebUIControllerFactory::GetWebUIType(
      BrowserContext* browser_context, const GURL& url) const {
  if (!url.SchemeIs(kChromeUIScheme))
    return WebUI::kNoWebUI;

  if (url.host_piece() == kChromeUIWebRTCInternalsHost ||
#if !defined(OS_ANDROID) && !defined(TOOLKIT_QT)
      url.host_piece() == kChromeUITracingHost ||
#endif
      url.host_piece() == kChromeUIGpuHost ||
      url.host_piece() == kChromeUIIndexedDBInternalsHost ||
      url.host_piece() == kChromeUIMediaInternalsHost ||
      url.host_piece() == kChromeUIServiceWorkerInternalsHost ||
#if !defined(TOOLKIT_QT)
      url.host_piece() == kChromeUIAccessibilityHost ||
#endif
      url.host_piece() == kChromeUIAppCacheInternalsHost ||
      url.host_piece() == kChromeUINetworkErrorsListingHost) {
    return const_cast<ContentWebUIControllerFactory*>(this);
  }
  return WebUI::kNoWebUI;
}

bool ContentWebUIControllerFactory::UseWebUIForURL(
    BrowserContext* browser_context, const GURL& url) const {
  return GetWebUIType(browser_context, url) != WebUI::kNoWebUI;
}

bool ContentWebUIControllerFactory::UseWebUIBindingsForURL(
    BrowserContext* browser_context, const GURL& url) const {
  return UseWebUIForURL(browser_context, url);
}

WebUIController* ContentWebUIControllerFactory::CreateWebUIControllerForURL(
    WebUI* web_ui, const GURL& url) const {
  if (!url.SchemeIs(kChromeUIScheme))
    return nullptr;

  if (url.host_piece() == kChromeUIAppCacheInternalsHost)
    return new AppCacheInternalsUI(web_ui);
  if (url.host_piece() == kChromeUIGpuHost)
    return new GpuInternalsUI(web_ui);
  if (url.host_piece() == kChromeUIIndexedDBInternalsHost)
    return new IndexedDBInternalsUI(web_ui);
  if (url.host_piece() == kChromeUIMediaInternalsHost)
    return new MediaInternalsUI(web_ui);
#if !defined(TOOLKIT_QT)
  if (url.host_piece() == kChromeUIAccessibilityHost)
    return new AccessibilityUI(web_ui);
#endif
  if (url.host_piece() == kChromeUIServiceWorkerInternalsHost)
    return new ServiceWorkerInternalsUI(web_ui);
  if (url.host_piece() == kChromeUINetworkErrorsListingHost)
    return new NetworkErrorsListingUI(web_ui);
#if !defined(OS_ANDROID) && !defined(TOOLKIT_QT)
  if (url.host_piece() == kChromeUITracingHost)
    return new TracingUI(web_ui);
#endif

#if BUILDFLAG(ENABLE_WEBRTC)
  if (url.host_piece() == kChromeUIWebRTCInternalsHost)
    return new WebRTCInternalsUI(web_ui);
#endif

  return nullptr;
}

// static
ContentWebUIControllerFactory* ContentWebUIControllerFactory::GetInstance() {
  return base::Singleton<ContentWebUIControllerFactory>::get();
}

ContentWebUIControllerFactory::ContentWebUIControllerFactory() {
}

ContentWebUIControllerFactory::~ContentWebUIControllerFactory() {
}

}  // namespace content