Fix import error in mac_platform_backend.py
[chromium-blink-merge.git] / extensions / browser / renderer_startup_helper.cc
blobab278aca9e9d0d3f39fed0005ce4751b66d30fb4
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 "chrome/browser/extensions/extension_function_dispatcher.h"
9 #include "chrome/common/extensions/extension_messages.h"
10 #include "chrome/common/extensions/features/feature_channel.h"
11 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extensions_browser_client.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 switch (type) {
39 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
40 content::RenderProcessHost* process =
41 content::Source<content::RenderProcessHost>(source).ptr();
42 if (!ExtensionsBrowserClient::Get()->IsSameContext(
43 browser_context_, process->GetBrowserContext()))
44 break;
46 // Extensions need to know the channel for API restrictions.
47 process->Send(new ExtensionMsg_SetChannel(
48 extensions::GetCurrentChannel()));
50 // Platform apps need to know the system font.
51 scoped_ptr<base::DictionaryValue> fonts(new base::DictionaryValue);
52 webui::SetFontAndTextDirection(fonts.get());
53 std::string font_family, font_size;
54 fonts->GetString("fontfamily", &font_family);
55 fonts->GetString("fontsize", &font_size);
56 process->Send(new ExtensionMsg_SetSystemFont(
57 font_family, font_size));
59 // Valid extension function names, used to setup bindings in renderer.
60 std::vector<std::string> function_names;
61 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
62 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
64 // Scripting whitelist. This is modified by tests and must be communicated
65 // to renderers.
66 process->Send(new ExtensionMsg_SetScriptingWhitelist(
67 extensions::ExtensionsClient::Get()->GetScriptingWhitelist()));
69 // Loaded extensions.
70 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
71 const ExtensionSet& extensions =
72 ExtensionRegistry::Get(browser_context_)->enabled_extensions();
73 for (ExtensionSet::const_iterator iter = extensions.begin();
74 iter != extensions.end(); ++iter) {
75 // Renderers don't need to know about themes.
76 if (!(*iter)->is_theme())
77 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(iter->get()));
79 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
80 break;
82 default:
83 NOTREACHED();
84 break;
88 //////////////////////////////////////////////////////////////////////////////
90 // static
91 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext(
92 BrowserContext* context) {
93 return static_cast<RendererStartupHelper*>(
94 GetInstance()->GetServiceForBrowserContext(context, true));
97 // static
98 RendererStartupHelperFactory* RendererStartupHelperFactory::GetInstance() {
99 return Singleton<RendererStartupHelperFactory>::get();
102 RendererStartupHelperFactory::RendererStartupHelperFactory()
103 : BrowserContextKeyedServiceFactory(
104 "RendererStartupHelper",
105 BrowserContextDependencyManager::GetInstance()) {
106 // No dependencies on other services.
109 RendererStartupHelperFactory::~RendererStartupHelperFactory() {}
111 BrowserContextKeyedService*
112 RendererStartupHelperFactory::BuildServiceInstanceFor(
113 content::BrowserContext* context) const {
114 return new RendererStartupHelper(context);
117 BrowserContext* RendererStartupHelperFactory::GetBrowserContextToUse(
118 BrowserContext* context) const {
119 // Redirected in incognito.
120 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
123 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const {
124 return true;
127 } // namespace extensions