Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / extensions / browser / renderer_startup_helper.cc
blobd268a63b09abc0f06b368963a177dd82a10be4da
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/browser/guest_view/web_view/web_view_guest.h"
16 #include "extensions/common/extension_messages.h"
17 #include "extensions/common/extension_set.h"
18 #include "extensions/common/extensions_client.h"
19 #include "ui/base/webui/web_ui_util.h"
21 using content::BrowserContext;
23 namespace extensions {
25 RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context)
26 : browser_context_(browser_context) {
27 DCHECK(browser_context);
28 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
29 content::NotificationService::AllBrowserContextsAndSources());
32 RendererStartupHelper::~RendererStartupHelper() {}
34 void RendererStartupHelper::Observe(
35 int type,
36 const content::NotificationSource& source,
37 const content::NotificationDetails& details) {
38 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_CREATED, type);
39 content::RenderProcessHost* process =
40 content::Source<content::RenderProcessHost>(source).ptr();
41 if (!ExtensionsBrowserClient::Get()->IsSameContext(
42 browser_context_, process->GetBrowserContext()))
43 return;
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 // Scripting whitelist. This is modified by tests and must be communicated
51 // to renderers.
52 process->Send(new ExtensionMsg_SetScriptingWhitelist(
53 extensions::ExtensionsClient::Get()->GetScriptingWhitelist()));
55 // If the new render process is a WebView guest process, propagate the WebView
56 // partition ID to it.
57 std::string webview_partition_id = WebViewGuest::GetPartitionID(process);
58 if (!webview_partition_id.empty()) {
59 process->Send(new ExtensionMsg_SetWebViewPartitionID(
60 WebViewGuest::GetPartitionID(process)));
63 // Loaded extensions.
64 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
65 const ExtensionSet& extensions =
66 ExtensionRegistry::Get(browser_context_)->enabled_extensions();
67 for (const auto& ext : extensions) {
68 // Renderers don't need to know about themes.
69 if (!ext->is_theme()) {
70 // TODO(kalman): Only include tab specific permissions for extension
71 // processes, no other process needs it, so it's mildly wasteful.
72 // I am not sure this is possible to know this here, at such a low
73 // level of the stack. Perhaps site isolation can help.
74 bool include_tab_permissions = true;
75 loaded_extensions.push_back(
76 ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions));
79 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
82 //////////////////////////////////////////////////////////////////////////////
84 // static
85 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext(
86 BrowserContext* context) {
87 return static_cast<RendererStartupHelper*>(
88 GetInstance()->GetServiceForBrowserContext(context, true));
91 // static
92 RendererStartupHelperFactory* RendererStartupHelperFactory::GetInstance() {
93 return base::Singleton<RendererStartupHelperFactory>::get();
96 RendererStartupHelperFactory::RendererStartupHelperFactory()
97 : BrowserContextKeyedServiceFactory(
98 "RendererStartupHelper",
99 BrowserContextDependencyManager::GetInstance()) {
100 // No dependencies on other services.
103 RendererStartupHelperFactory::~RendererStartupHelperFactory() {}
105 KeyedService* RendererStartupHelperFactory::BuildServiceInstanceFor(
106 content::BrowserContext* context) const {
107 return new RendererStartupHelper(context);
110 BrowserContext* RendererStartupHelperFactory::GetBrowserContextToUse(
111 BrowserContext* context) const {
112 // Redirected in incognito.
113 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
116 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const {
117 return true;
120 } // namespace extensions