Chromecast on Android buildfix: don't try to create a RendererFactory.
[chromium-blink-merge.git] / extensions / browser / renderer_startup_helper.cc
blob5cdd8b125aa0a1f803ca3e47f26203ee04059dba
1 // Copyright 2014 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 "extensions/browser/renderer_startup_helper.h"
7 #include "base/values.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_types.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "extensions/browser/extension_function_dispatcher.h"
13 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/extensions_browser_client.h"
15 #include "extensions/common/extension_messages.h"
16 #include "extensions/common/extension_set.h"
17 #include "extensions/common/extensions_client.h"
18 #include "ui/base/webui/web_ui_util.h"
20 using content::BrowserContext;
22 namespace extensions {
24 RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context)
25 : browser_context_(browser_context) {
26 DCHECK(browser_context);
27 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
28 content::NotificationService::AllBrowserContextsAndSources());
31 RendererStartupHelper::~RendererStartupHelper() {}
33 void RendererStartupHelper::Observe(
34 int type,
35 const content::NotificationSource& source,
36 const content::NotificationDetails& details) {
37 switch (type) {
38 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
39 content::RenderProcessHost* process =
40 content::Source<content::RenderProcessHost>(source).ptr();
41 if (!ExtensionsBrowserClient::Get()->IsSameContext(
42 browser_context_, process->GetBrowserContext()))
43 break;
45 // Platform apps need to know the system font.
46 // TODO(dbeam): this is not the system font in all cases.
47 process->Send(new ExtensionMsg_SetSystemFont(webui::GetFontFamily(),
48 webui::GetFontSize()));
50 // Valid extension function names, used to setup bindings in renderer.
51 std::vector<std::string> function_names;
52 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
53 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
55 // Scripting whitelist. This is modified by tests and must be communicated
56 // to renderers.
57 process->Send(new ExtensionMsg_SetScriptingWhitelist(
58 extensions::ExtensionsClient::Get()->GetScriptingWhitelist()));
60 // Loaded extensions.
61 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
62 const ExtensionSet& extensions =
63 ExtensionRegistry::Get(browser_context_)->enabled_extensions();
64 for (ExtensionSet::const_iterator iter = extensions.begin();
65 iter != extensions.end(); ++iter) {
66 // Renderers don't need to know about themes.
67 if (!(*iter)->is_theme())
68 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(iter->get()));
70 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
71 break;
73 default:
74 NOTREACHED();
75 break;
79 //////////////////////////////////////////////////////////////////////////////
81 // static
82 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext(
83 BrowserContext* context) {
84 return static_cast<RendererStartupHelper*>(
85 GetInstance()->GetServiceForBrowserContext(context, true));
88 // static
89 RendererStartupHelperFactory* RendererStartupHelperFactory::GetInstance() {
90 return Singleton<RendererStartupHelperFactory>::get();
93 RendererStartupHelperFactory::RendererStartupHelperFactory()
94 : BrowserContextKeyedServiceFactory(
95 "RendererStartupHelper",
96 BrowserContextDependencyManager::GetInstance()) {
97 // No dependencies on other services.
100 RendererStartupHelperFactory::~RendererStartupHelperFactory() {}
102 KeyedService* RendererStartupHelperFactory::BuildServiceInstanceFor(
103 content::BrowserContext* context) const {
104 return new RendererStartupHelper(context);
107 BrowserContext* RendererStartupHelperFactory::GetBrowserContextToUse(
108 BrowserContext* context) const {
109 // Redirected in incognito.
110 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
113 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const {
114 return true;
117 } // namespace extensions