OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/renderer_startup_helper.h" | 5 #include "extensions/browser/renderer_startup_helper.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 8 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 27 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
28 content::NotificationService::AllBrowserContextsAndSources()); | 28 content::NotificationService::AllBrowserContextsAndSources()); |
29 } | 29 } |
30 | 30 |
31 RendererStartupHelper::~RendererStartupHelper() {} | 31 RendererStartupHelper::~RendererStartupHelper() {} |
32 | 32 |
33 void RendererStartupHelper::Observe( | 33 void RendererStartupHelper::Observe( |
34 int type, | 34 int type, |
35 const content::NotificationSource& source, | 35 const content::NotificationSource& source, |
36 const content::NotificationDetails& details) { | 36 const content::NotificationDetails& details) { |
37 switch (type) { | 37 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_CREATED, type); |
38 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { | 38 content::RenderProcessHost* process = |
39 content::RenderProcessHost* process = | 39 content::Source<content::RenderProcessHost>(source).ptr(); |
40 content::Source<content::RenderProcessHost>(source).ptr(); | 40 if (!ExtensionsBrowserClient::Get()->IsSameContext( |
41 if (!ExtensionsBrowserClient::Get()->IsSameContext( | 41 browser_context_, process->GetBrowserContext())) |
42 browser_context_, process->GetBrowserContext())) | 42 return; |
43 break; | |
44 | 43 |
45 // Platform apps need to know the system font. | 44 // Platform apps need to know the system font. |
46 // TODO(dbeam): this is not the system font in all cases. | 45 // TODO(dbeam): this is not the system font in all cases. |
47 process->Send(new ExtensionMsg_SetSystemFont(webui::GetFontFamily(), | 46 process->Send(new ExtensionMsg_SetSystemFont(webui::GetFontFamily(), |
48 webui::GetFontSize())); | 47 webui::GetFontSize())); |
49 | 48 |
50 // Valid extension function names, used to setup bindings in renderer. | 49 // Valid extension function names, used to setup bindings in renderer. |
51 std::vector<std::string> function_names; | 50 std::vector<std::string> function_names; |
52 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); | 51 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); |
53 process->Send(new ExtensionMsg_SetFunctionNames(function_names)); | 52 process->Send(new ExtensionMsg_SetFunctionNames(function_names)); |
54 | 53 |
55 // Scripting whitelist. This is modified by tests and must be communicated | 54 // Scripting whitelist. This is modified by tests and must be communicated |
56 // to renderers. | 55 // to renderers. |
57 process->Send(new ExtensionMsg_SetScriptingWhitelist( | 56 process->Send(new ExtensionMsg_SetScriptingWhitelist( |
58 extensions::ExtensionsClient::Get()->GetScriptingWhitelist())); | 57 extensions::ExtensionsClient::Get()->GetScriptingWhitelist())); |
59 | 58 |
60 // Loaded extensions. | 59 // Loaded extensions. |
61 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; | 60 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; |
62 const ExtensionSet& extensions = | 61 const ExtensionSet& extensions = |
63 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 62 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
64 for (ExtensionSet::const_iterator iter = extensions.begin(); | 63 for (const auto& ext : extensions) { |
65 iter != extensions.end(); ++iter) { | 64 // Renderers don't need to know about themes. |
66 // Renderers don't need to know about themes. | 65 if (!ext->is_theme()) { |
67 if (!(*iter)->is_theme()) { | 66 // TODO(kalman): Only include tab specific permissions for extension |
68 // Don't need to include tab permissions for new tabs. | 67 // processes, no other process needs it, so it's mildly wasteful. |
69 loaded_extensions.push_back(ExtensionMsg_Loaded_Params( | 68 // I am not sure this is possible to know this here, at such a low |
70 iter->get(), false /* no tab permissions */)); | 69 // level of the stack. Perhaps site isolation can help. |
71 } | 70 bool include_tab_permissions = true; |
72 } | 71 loaded_extensions.push_back( |
73 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); | 72 ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions)); |
74 break; | |
75 } | 73 } |
76 default: | |
77 NOTREACHED(); | |
78 break; | |
79 } | 74 } |
| 75 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); |
80 } | 76 } |
81 | 77 |
82 ////////////////////////////////////////////////////////////////////////////// | 78 ////////////////////////////////////////////////////////////////////////////// |
83 | 79 |
84 // static | 80 // static |
85 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext( | 81 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext( |
86 BrowserContext* context) { | 82 BrowserContext* context) { |
87 return static_cast<RendererStartupHelper*>( | 83 return static_cast<RendererStartupHelper*>( |
88 GetInstance()->GetServiceForBrowserContext(context, true)); | 84 GetInstance()->GetServiceForBrowserContext(context, true)); |
89 } | 85 } |
(...skipping 21 matching lines...) Expand all Loading... |
111 BrowserContext* context) const { | 107 BrowserContext* context) const { |
112 // Redirected in incognito. | 108 // Redirected in incognito. |
113 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 109 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
114 } | 110 } |
115 | 111 |
116 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const { | 112 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const { |
117 return true; | 113 return true; |
118 } | 114 } |
119 | 115 |
120 } // namespace extensions | 116 } // namespace extensions |
OLD | NEW |