forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_ui_controller_factory.cc
78 lines (59 loc) · 2.28 KB
/
web_ui_controller_factory.cc
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
// Copyright 2019 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 "weblayer/browser/webui/web_ui_controller_factory.h"
#include "base/memory/ptr_util.h"
#include "content/public/browser/web_ui.h"
#include "url/gurl.h"
#include "weblayer/browser/webui/weblayer_internals_ui.h"
namespace weblayer {
namespace {
const content::WebUI::TypeID kWebLayerID = &kWebLayerID;
// A function for creating a new WebUI. The caller owns the return value, which
// may be nullptr (for example, if the URL refers to an non-existent extension).
typedef content::WebUIController* (
*WebUIFactoryFunctionPointer)(content::WebUI* web_ui, const GURL& url);
// Template for defining WebUIFactoryFunctionPointer.
template <class T>
content::WebUIController* NewWebUI(content::WebUI* web_ui, const GURL& url) {
return new T(web_ui);
}
WebUIFactoryFunctionPointer GetWebUIFactoryFunctionPointer(const GURL& url) {
if (url.host() == kChromeUIWebLayerHost) {
return &NewWebUI<WebLayerInternalsUI>;
}
return nullptr;
}
content::WebUI::TypeID GetWebUITypeID(const GURL& url) {
if (url.host() == kChromeUIWebLayerHost) {
return kWebLayerID;
}
return content::WebUI::kNoWebUI;
}
} // namespace
// static
WebUIControllerFactory* WebUIControllerFactory::GetInstance() {
static base::NoDestructor<WebUIControllerFactory> instance;
return instance.get();
}
WebUIControllerFactory::WebUIControllerFactory() = default;
WebUIControllerFactory::~WebUIControllerFactory() = default;
content::WebUI::TypeID WebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context,
const GURL& url) {
return GetWebUITypeID(url);
}
bool WebUIControllerFactory::UseWebUIForURL(
content::BrowserContext* browser_context,
const GURL& url) {
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
}
std::unique_ptr<content::WebUIController>
WebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
const GURL& url) {
WebUIFactoryFunctionPointer function = GetWebUIFactoryFunctionPointer(url);
if (!function)
return nullptr;
return base::WrapUnique((*function)(web_ui, url));
}
} // namespace weblayer