OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/extensions/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_dispatcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/common/child_process_logging.h" | 8 #include "chrome/common/child_process_logging.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
| 12 #include "chrome/common/extensions/extension_permission_set.h" |
12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
13 #include "chrome/renderer/extensions/chrome_app_bindings.h" | 14 #include "chrome/renderer/extensions/chrome_app_bindings.h" |
14 #include "chrome/renderer/extensions/event_bindings.h" | 15 #include "chrome/renderer/extensions/event_bindings.h" |
15 #include "chrome/renderer/extensions/extension_groups.h" | 16 #include "chrome/renderer/extensions/extension_groups.h" |
16 #include "chrome/renderer/extensions/extension_process_bindings.h" | 17 #include "chrome/renderer/extensions/extension_process_bindings.h" |
17 #include "chrome/renderer/extensions/js_only_v8_extensions.h" | 18 #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
18 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 19 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
19 #include "chrome/renderer/extensions/user_script_slave.h" | 20 #include "chrome/renderer/extensions/user_script_slave.h" |
20 #include "content/renderer/render_thread.h" | 21 #include "content/renderer/render_thread.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 bool handled = true; | 59 bool handled = true; |
59 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) | 60 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) |
60 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 61 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
61 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) | 62 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) |
62 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 63 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
63 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 64 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
64 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 65 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
65 OnSetScriptingWhitelist) | 66 OnSetScriptingWhitelist) |
66 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 67 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
67 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication) | 68 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication) |
| 69 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
68 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 70 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
69 IPC_MESSAGE_UNHANDLED(handled = false) | 71 IPC_MESSAGE_UNHANDLED(handled = false) |
70 IPC_END_MESSAGE_MAP() | 72 IPC_END_MESSAGE_MAP() |
71 | 73 |
72 return handled; | 74 return handled; |
73 } | 75 } |
74 | 76 |
75 void ExtensionDispatcher::WebKitInitialized() { | 77 void ExtensionDispatcher::WebKitInitialized() { |
76 // For extensions, we want to ensure we call the IdleHandler every so often, | 78 // For extensions, we want to ensure we call the IdleHandler every so often, |
77 // even if the extension keeps up activity. | 79 // even if the extension keeps up activity. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 scoped_refptr<const Extension> extension(params.ConvertToExtension()); | 144 scoped_refptr<const Extension> extension(params.ConvertToExtension()); |
143 if (!extension) { | 145 if (!extension) { |
144 // This can happen if extension parsing fails for any reason. One reason | 146 // This can happen if extension parsing fails for any reason. One reason |
145 // this can legitimately happen is if the | 147 // this can legitimately happen is if the |
146 // --enable-experimental-extension-apis changes at runtime, which happens | 148 // --enable-experimental-extension-apis changes at runtime, which happens |
147 // during browser tests. Existing renderers won't know about the change. | 149 // during browser tests. Existing renderers won't know about the change. |
148 return; | 150 return; |
149 } | 151 } |
150 | 152 |
151 extensions_.Insert(extension); | 153 extensions_.Insert(extension); |
| 154 extension->SetActivePermissions(params.GetActivePermissions()); |
152 } | 155 } |
153 | 156 |
154 void ExtensionDispatcher::OnUnloaded(const std::string& id) { | 157 void ExtensionDispatcher::OnUnloaded(const std::string& id) { |
155 extensions_.Remove(id); | 158 extensions_.Remove(id); |
156 // If the extension is later reloaded with a different set of permissions, | 159 // If the extension is later reloaded with a different set of permissions, |
157 // we'd like it to get a new isolated world ID, so that it can pick up the | 160 // we'd like it to get a new isolated world ID, so that it can pick up the |
158 // changed origin whitelist. | 161 // changed origin whitelist. |
159 UserScriptSlave::RemoveIsolatedWorld(id); | 162 UserScriptSlave::RemoveIsolatedWorld(id); |
160 } | 163 } |
161 | 164 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 void ExtensionDispatcher::InitHostPermissions(const Extension* extension) { | 240 void ExtensionDispatcher::InitHostPermissions(const Extension* extension) { |
238 if (extension->HasAPIPermission(ExtensionAPIPermission::kManagement)) { | 241 if (extension->HasAPIPermission(ExtensionAPIPermission::kManagement)) { |
239 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 242 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
240 extension->url(), | 243 extension->url(), |
241 WebString::fromUTF8(chrome::kChromeUIScheme), | 244 WebString::fromUTF8(chrome::kChromeUIScheme), |
242 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), | 245 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), |
243 false); | 246 false); |
244 } | 247 } |
245 | 248 |
246 const URLPatternSet& permissions = | 249 const URLPatternSet& permissions = |
247 extension->permission_set()->explicit_hosts(); | 250 extension->GetActivePermissions()->explicit_hosts(); |
248 for (URLPatternSet::const_iterator i = permissions.begin(); | 251 for (URLPatternSet::const_iterator i = permissions.begin(); |
249 i != permissions.end(); ++i) { | 252 i != permissions.end(); ++i) { |
250 const char* schemes[] = { | 253 const char* schemes[] = { |
251 chrome::kHttpScheme, | 254 chrome::kHttpScheme, |
252 chrome::kHttpsScheme, | 255 chrome::kHttpsScheme, |
253 chrome::kFileScheme, | 256 chrome::kFileScheme, |
254 chrome::kChromeUIScheme, | 257 chrome::kChromeUIScheme, |
255 }; | 258 }; |
256 for (size_t j = 0; j < arraysize(schemes); ++j) { | 259 for (size_t j = 0; j < arraysize(schemes); ++j) { |
257 if (i->MatchesScheme(schemes[j])) { | 260 if (i->MatchesScheme(schemes[j])) { |
258 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 261 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
259 extension->url(), | 262 extension->url(), |
260 WebString::fromUTF8(schemes[j]), | 263 WebString::fromUTF8(schemes[j]), |
261 WebString::fromUTF8(i->host()), | 264 WebString::fromUTF8(i->host()), |
262 i->match_subdomains()); | 265 i->match_subdomains()); |
263 } | 266 } |
264 } | 267 } |
265 } | 268 } |
266 } | 269 } |
267 | 270 |
| 271 void ExtensionDispatcher::OnUpdatePermissions( |
| 272 const std::string& extension_id, |
| 273 const ExtensionAPIPermissionSet& apis, |
| 274 const URLPatternSet& explicit_hosts, |
| 275 const URLPatternSet& scriptable_hosts) { |
| 276 const Extension* extension = extensions_.GetByID(extension_id); |
| 277 if (!extension) |
| 278 return; |
| 279 |
| 280 extension->SetActivePermissions( |
| 281 new ExtensionPermissionSet(apis, explicit_hosts, scriptable_hosts)); |
| 282 } |
| 283 |
268 void ExtensionDispatcher::OnUpdateUserScripts( | 284 void ExtensionDispatcher::OnUpdateUserScripts( |
269 base::SharedMemoryHandle scripts) { | 285 base::SharedMemoryHandle scripts) { |
270 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; | 286 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
271 user_script_slave_->UpdateScripts(scripts); | 287 user_script_slave_->UpdateScripts(scripts); |
272 UpdateActiveExtensions(); | 288 UpdateActiveExtensions(); |
273 } | 289 } |
274 | 290 |
275 void ExtensionDispatcher::UpdateActiveExtensions() { | 291 void ExtensionDispatcher::UpdateActiveExtensions() { |
276 // In single-process mode, the browser process reports the active extensions. | 292 // In single-process mode, the browser process reports the active extensions. |
277 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) | 293 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
278 return; | 294 return; |
279 | 295 |
280 std::set<std::string> active_extensions = active_extension_ids_; | 296 std::set<std::string> active_extensions = active_extension_ids_; |
281 user_script_slave_->GetActiveExtensions(&active_extensions); | 297 user_script_slave_->GetActiveExtensions(&active_extensions); |
282 child_process_logging::SetActiveExtensions(active_extensions); | 298 child_process_logging::SetActiveExtensions(active_extensions); |
283 } | 299 } |
284 | 300 |
285 void ExtensionDispatcher::RegisterExtension(v8::Extension* extension, | 301 void ExtensionDispatcher::RegisterExtension(v8::Extension* extension, |
286 bool restrict_to_extensions) { | 302 bool restrict_to_extensions) { |
287 if (restrict_to_extensions) | 303 if (restrict_to_extensions) |
288 restricted_v8_extensions_.insert(extension->name()); | 304 restricted_v8_extensions_.insert(extension->name()); |
289 | 305 |
290 RenderThread::current()->RegisterExtension(extension); | 306 RenderThread::current()->RegisterExtension(extension); |
291 } | 307 } |
OLD | NEW |