forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_chrome_web_ui_controller_factory.cc
57 lines (46 loc) · 2.06 KB
/
test_chrome_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
// 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 "chrome/test/base/test_chrome_web_ui_controller_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_contents.h"
using content::WebContents;
using content::WebUI;
using content::WebUIController;
TestChromeWebUIControllerFactory::WebUIProvider::~WebUIProvider() {
}
TestChromeWebUIControllerFactory::TestChromeWebUIControllerFactory() {
}
TestChromeWebUIControllerFactory::~TestChromeWebUIControllerFactory() {
}
void TestChromeWebUIControllerFactory::AddFactoryOverride(
const std::string& host, WebUIProvider* provider) {
DCHECK_EQ(0U, factory_overrides_.count(host));
factory_overrides_[host] = provider;
}
void TestChromeWebUIControllerFactory::RemoveFactoryOverride(
const std::string& host) {
DCHECK_EQ(1U, factory_overrides_.count(host));
factory_overrides_.erase(host);
}
WebUI::TypeID TestChromeWebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context, const GURL& url) const {
Profile* profile = Profile::FromBrowserContext(browser_context);
WebUIProvider* provider = GetWebUIProvider(profile, url);
return provider ? reinterpret_cast<WebUI::TypeID>(provider) :
ChromeWebUIControllerFactory::GetWebUIType(profile, url);
}
WebUIController* TestChromeWebUIControllerFactory::CreateWebUIControllerForURL(
content::WebUI* web_ui, const GURL& url) const {
Profile* profile = Profile::FromWebUI(web_ui);
WebUIProvider* provider = GetWebUIProvider(profile, url);
return provider ? provider->NewWebUI(web_ui, url) :
ChromeWebUIControllerFactory::CreateWebUIControllerForURL(web_ui, url);
}
TestChromeWebUIControllerFactory::WebUIProvider*
TestChromeWebUIControllerFactory::GetWebUIProvider(
Profile* profile, const GURL& url) const {
FactoryOverridesMap::const_iterator found =
factory_overrides_.find(url.host());
return (found == factory_overrides_.end()) ? NULL : found->second;
}