Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / browser / renderer_startup_helper.cc
blob99c7b91de1cd641dc683a84ba674631b1b494dd2
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 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_CREATED, type);
38 content::RenderProcessHost* process =
39 content::Source<content::RenderProcessHost>(source).ptr();
40 if (!ExtensionsBrowserClient::Get()->IsSameContext(
41 browser_context_, process->GetBrowserContext()))
42 return;
44 // Platform apps need to know the system font.
45 // TODO(dbeam): this is not the system font in all cases.
46 process->Send(new ExtensionMsg_SetSystemFont(webui::GetFontFamily(),
47 webui::GetFontSize()));
49 // Valid extension function names, used to setup bindings in renderer.
50 std::vector<std::string> function_names;
51 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
52 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
54 // Scripting whitelist. This is modified by tests and must be communicated
55 // to renderers.
56 process->Send(new ExtensionMsg_SetScriptingWhitelist(
57 extensions::ExtensionsClient::Get()->GetScriptingWhitelist()));
59 // Loaded extensions.
60 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
61 const ExtensionSet& extensions =
62 ExtensionRegistry::Get(browser_context_)->enabled_extensions();
63 for (const auto& ext : extensions) {
64 // Renderers don't need to know about themes.
65 if (!ext->is_theme()) {
66 // TODO(kalman): Only include tab specific permissions for extension
67 // processes, no other process needs it, so it's mildly wasteful.
68 // I am not sure this is possible to know this here, at such a low
69 // level of the stack. Perhaps site isolation can help.
70 bool include_tab_permissions = true;
71 loaded_extensions.push_back(
72 ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions));
75 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
78 //////////////////////////////////////////////////////////////////////////////
80 // static
81 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext(
82 BrowserContext* context) {
83 return static_cast<RendererStartupHelper*>(
84 GetInstance()->GetServiceForBrowserContext(context, true));
87 // static
88 RendererStartupHelperFactory* RendererStartupHelperFactory::GetInstance() {
89 return Singleton<RendererStartupHelperFactory>::get();
92 RendererStartupHelperFactory::RendererStartupHelperFactory()
93 : BrowserContextKeyedServiceFactory(
94 "RendererStartupHelper",
95 BrowserContextDependencyManager::GetInstance()) {
96 // No dependencies on other services.
99 RendererStartupHelperFactory::~RendererStartupHelperFactory() {}
101 KeyedService* RendererStartupHelperFactory::BuildServiceInstanceFor(
102 content::BrowserContext* context) const {
103 return new RendererStartupHelper(context);
106 BrowserContext* RendererStartupHelperFactory::GetBrowserContextToUse(
107 BrowserContext* context) const {
108 // Redirected in incognito.
109 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
112 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const {
113 return true;
116 } // namespace extensions