Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: extensions/browser/renderer_startup_helper.cc

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: URLPatternSets use shared memory for IPC. Default scope patterns sent once per renderer. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
12 #include "extensions/browser/extension_function_dispatcher.h" 12 #include "extensions/browser/extension_function_dispatcher.h"
13 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/extensions_browser_client.h" 14 #include "extensions/browser/extensions_browser_client.h"
15 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 15 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
16 #include "extensions/common/extension_messages.h" 16 #include "extensions/common/extension_messages.h"
17 #include "extensions/common/extension_set.h" 17 #include "extensions/common/extension_set.h"
18 #include "extensions/common/extensions_client.h" 18 #include "extensions/common/extensions_client.h"
19 #include "extensions/common/features/feature_channel.h" 19 #include "extensions/common/features/feature_channel.h"
20 #include "extensions/common/features/feature_session_type.h" 20 #include "extensions/common/features/feature_session_type.h"
21 #include "extensions/common/permissions/permissions_data.h"
22 #include "ipc/ipc_message_attachment_set.h"
21 #include "ui/base/webui/web_ui_util.h" 23 #include "ui/base/webui/web_ui_util.h"
22 24
23 using content::BrowserContext; 25 using content::BrowserContext;
24 26
25 namespace extensions { 27 namespace extensions {
26 28
27 RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context) 29 RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context)
28 : browser_context_(browser_context) { 30 : browser_context_(browser_context) {
29 DCHECK(browser_context); 31 DCHECK(browser_context);
30 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, 32 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 extensions::ExtensionsClient::Get()->GetScriptingWhitelist())); 86 extensions::ExtensionsClient::Get()->GetScriptingWhitelist()));
85 87
86 // If the new render process is a WebView guest process, propagate the WebView 88 // If the new render process is a WebView guest process, propagate the WebView
87 // partition ID to it. 89 // partition ID to it.
88 std::string webview_partition_id = WebViewGuest::GetPartitionID(process); 90 std::string webview_partition_id = WebViewGuest::GetPartitionID(process);
89 if (!webview_partition_id.empty()) { 91 if (!webview_partition_id.empty()) {
90 process->Send(new ExtensionMsg_SetWebViewPartitionID( 92 process->Send(new ExtensionMsg_SetWebViewPartitionID(
91 WebViewGuest::GetPartitionID(process))); 93 WebViewGuest::GetPartitionID(process)));
92 } 94 }
93 95
96 // Load default runtime_blocked_hosts and runtime_allowed_hosts settings, part
97 // of the ExtensionSettings policy.
98 ExtensionMsg_RuntimeBlockedAllowedHostsStruct params(
99 PermissionsData::default_runtime_blocked_hosts(),
100 PermissionsData::default_runtime_allowed_hosts(), process->GetHandle());
101 process->Send(new ExtensionMsg_UpdateDefaultAllowedAndBlockedHosts(params));
102
94 // Loaded extensions. 103 // Loaded extensions.
95 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; 104 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
96 const ExtensionSet& extensions = 105 const ExtensionSet& extensions =
97 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); 106 ExtensionRegistry::Get(browser_context_)->enabled_extensions();
98 for (const auto& ext : extensions) { 107 for (const auto& ext : extensions) {
99 // Renderers don't need to know about themes. 108 // Renderers don't need to know about themes.
100 if (!ext->is_theme()) { 109 if (!ext->is_theme()) {
101 // TODO(kalman): Only include tab specific permissions for extension 110 // TODO(kalman): Only include tab specific permissions for extension
102 // processes, no other process needs it, so it's mildly wasteful. 111 // processes, no other process needs it, so it's mildly wasteful.
103 // I am not sure this is possible to know this here, at such a low 112 // I am not sure this is possible to know this here, at such a low
104 // level of the stack. Perhaps site isolation can help. 113 // level of the stack. Perhaps site isolation can help.
105 bool include_tab_permissions = true; 114 bool include_tab_permissions = true;
106 loaded_extensions.push_back( 115 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(
107 ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions)); 116 ext.get(), include_tab_permissions, process->GetHandle()));
108 } 117 }
118 #if defined(OS_POSIX)
119 if (loaded_extensions.size() ==
120 IPC::MessageAttachmentSet::kMaxDescriptorsPerMessage) {
121 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
122 loaded_extensions.clear();
123 }
124 #endif
109 } 125 }
110 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); 126 if (loaded_extensions.size() > 0) {
127 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
128 }
111 auto iter = pending_active_extensions_.find(process); 129 auto iter = pending_active_extensions_.find(process);
112 if (iter != pending_active_extensions_.end()) { 130 if (iter != pending_active_extensions_.end()) {
113 for (const ExtensionId& id : iter->second) { 131 for (const ExtensionId& id : iter->second) {
114 DCHECK(extensions.Contains(id)); 132 DCHECK(extensions.Contains(id));
115 process->Send(new ExtensionMsg_ActivateExtension(id)); 133 process->Send(new ExtensionMsg_ActivateExtension(id));
116 } 134 }
117 } 135 }
118 136
119 initialized_processes_.insert(process); 137 initialized_processes_.insert(process);
120 } 138 }
(...skipping 26 matching lines...) Expand all
147 165
148 void RendererStartupHelper::OnExtensionLoaded(const Extension& extension) { 166 void RendererStartupHelper::OnExtensionLoaded(const Extension& extension) {
149 // Renderers don't need to know about themes. 167 // Renderers don't need to know about themes.
150 if (extension.is_theme()) 168 if (extension.is_theme())
151 return; 169 return;
152 170
153 // We don't need to include tab permisisons here, since the extension 171 // We don't need to include tab permisisons here, since the extension
154 // was just loaded. 172 // was just loaded.
155 // Uninitialized renderers will be informed of the extension load during the 173 // Uninitialized renderers will be informed of the extension load during the
156 // first batch of messages. 174 // first batch of messages.
157 std::vector<ExtensionMsg_Loaded_Params> params( 175 for (content::RenderProcessHost* process : initialized_processes_) {
158 1, 176 std::vector<ExtensionMsg_Loaded_Params> params(
159 ExtensionMsg_Loaded_Params(&extension, false /* no tab permissions */)); 177 1,
160 for (content::RenderProcessHost* process : initialized_processes_) 178 ExtensionMsg_Loaded_Params(&extension, false /* no tab permissions */,
179 process->GetHandle()));
161 process->Send(new ExtensionMsg_Loaded(params)); 180 process->Send(new ExtensionMsg_Loaded(params));
181 }
162 } 182 }
163 183
164 void RendererStartupHelper::OnExtensionUnloaded(const Extension& extension) { 184 void RendererStartupHelper::OnExtensionUnloaded(const Extension& extension) {
165 // Renderers don't need to know about themes. 185 // Renderers don't need to know about themes.
166 if (extension.is_theme()) 186 if (extension.is_theme())
167 return; 187 return;
168 188
169 for (content::RenderProcessHost* process : initialized_processes_) 189 for (content::RenderProcessHost* process : initialized_processes_)
170 process->Send(new ExtensionMsg_Unloaded(extension.id())); 190 process->Send(new ExtensionMsg_Unloaded(extension.id()));
171 for (auto& process_extensions_pair : pending_active_extensions_) 191 for (auto& process_extensions_pair : pending_active_extensions_)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 BrowserContext* context) const { 224 BrowserContext* context) const {
205 // Redirected in incognito. 225 // Redirected in incognito.
206 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); 226 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
207 } 227 }
208 228
209 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const { 229 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const {
210 return true; 230 return true;
211 } 231 }
212 232
213 } // namespace extensions 233 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698