Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 active_extension_ids_.end(); | 265 active_extension_ids_.end(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 bool ExtensionDispatcher::AllowScriptExtension( | 268 bool ExtensionDispatcher::AllowScriptExtension( |
| 269 WebFrame* frame, | 269 WebFrame* frame, |
| 270 const std::string& v8_extension_name, | 270 const std::string& v8_extension_name, |
| 271 int extension_group) { | 271 int extension_group) { |
| 272 return AllowScriptExtension(frame, v8_extension_name, extension_group, 0); | 272 return AllowScriptExtension(frame, v8_extension_name, extension_group, 0); |
| 273 } | 273 } |
| 274 | 274 |
| 275 namespace { | |
| 276 | |
| 277 // This is what the extension_group variable will be when DidCreateScriptContext | |
| 278 // is called. We know because it's the same as what AllowScriptExtension gets | |
| 279 // passed, and the two functions are called sequentially from WebKit. | |
| 280 // | |
| 281 // There is a patch in progress (koz) to properly plumb this through. | |
|
koz (OOO until 15th September)
2012/02/15 23:43:11
TODO(koz): Plumb extension_group through to AllowS
not at google - send to devlin
2012/02/16 00:06:27
Done.
| |
| 282 static int hack_DidCreateScriptContext_extension_group = 0; | |
| 283 | |
| 284 } | |
| 285 | |
| 275 bool ExtensionDispatcher::AllowScriptExtension( | 286 bool ExtensionDispatcher::AllowScriptExtension( |
| 276 WebFrame* frame, | 287 WebFrame* frame, |
| 277 const std::string& v8_extension_name, | 288 const std::string& v8_extension_name, |
| 278 int extension_group, | 289 int extension_group, |
| 279 int world_id) { | 290 int world_id) { |
| 291 hack_DidCreateScriptContext_extension_group = extension_group; | |
| 292 | |
| 280 // NULL in unit tests. | 293 // NULL in unit tests. |
| 281 if (!RenderThread::Get()) | 294 if (!RenderThread::Get()) |
| 282 return true; | 295 return true; |
| 283 | 296 |
| 284 // If we don't know about it, it was added by WebCore, so we should allow it. | 297 // If we don't know about it, it was added by WebCore, so we should allow it. |
| 285 if (!RenderThread::Get()->IsRegisteredExtension(v8_extension_name)) | 298 if (!RenderThread::Get()->IsRegisteredExtension(v8_extension_name)) |
| 286 return true; | 299 return true; |
| 287 | 300 |
| 288 // If the V8 extension is not restricted, allow it to run anywhere. | 301 // If the V8 extension is not restricted, allow it to run anywhere. |
| 289 if (!restricted_v8_extensions_.count(v8_extension_name)) | 302 if (!restricted_v8_extensions_.count(v8_extension_name)) |
| 290 return true; | 303 return true; |
| 291 | 304 |
| 292 // Extension-only bindings should be restricted to content scripts and | 305 // Extension-only bindings should be restricted to content scripts and |
| 293 // extension-blessed URLs. | 306 // extension-blessed URLs. |
| 294 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || | 307 bool is_content_script = extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS; |
| 308 if (is_content_script || | |
| 295 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo( | 309 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo( |
| 296 frame->document().securityOrigin(), | 310 frame->document().securityOrigin(), |
| 297 UserScriptSlave::GetDataSourceURLForFrame(frame)))) { | 311 UserScriptSlave::GetDataSourceURLForFrame(frame)))) { |
| 298 // If the extension is a custom API binding, only allow if the extension | 312 // If the extension is a custom API binding, only allow if the extension |
| 299 // has permission to use the API. | 313 // has permission to use the API. |
| 300 std::string custom_binding_api_name = | 314 std::string custom_binding_api_name = |
| 301 custom_bindings_util::GetAPIName(v8_extension_name); | 315 custom_bindings_util::GetAPIName(v8_extension_name); |
| 302 if (!custom_binding_api_name.empty()) { | 316 if (!custom_binding_api_name.empty()) { |
| 303 std::string extension_id = GetExtensionID(frame, world_id); | 317 std::string extension_id = GetExtensionID(frame, world_id); |
| 304 const Extension* extension = extensions_.GetByID(extension_id); | 318 const Extension* extension = extensions_.GetByID(extension_id); |
| 305 if (!extension) { | 319 if (!extension) { |
| 306 // This can happen when a resource is blocked due to CSP; a valid | 320 // This can happen when a resource is blocked due to CSP; a valid |
| 307 // chrome-extension:// URL is navigated to, so it passes the initial | 321 // chrome-extension:// URL is navigated to, so it passes the initial |
| 308 // checks, but the URL gets changed to "chrome-extension://invalid" | 322 // checks, but the URL gets changed to "chrome-extension://invalid" |
| 309 // afterwards (see chrome_content_renderer_client.cc). An extension | 323 // afterwards (see chrome_content_renderer_client.cc). An extension |
| 310 // page still gets loaded, just for the extension with ID "invalid", | 324 // page still gets loaded, just for the extension with ID "invalid", |
| 311 // which of course isn't found so GetById extension will be NULL. | 325 // which of course isn't found so GetById extension will be NULL. |
| 312 // | 326 // |
| 313 // Reference: http://crbug.com/111614. | 327 // Reference: http://crbug.com/111614. |
| 314 CHECK_EQ("invalid", extension_id); | 328 CHECK_EQ("invalid", extension_id); |
| 315 return false; | 329 return false; |
| 316 } | 330 } |
| 317 return custom_bindings_util::AllowAPIInjection( | 331 return custom_bindings_util::AllowAPIInjection( |
| 318 custom_binding_api_name, *extension); | 332 custom_binding_api_name, *extension, is_content_script); |
|
koz (OOO until 15th September)
2012/02/15 23:43:11
(aside) It'll be nice when we can factor this logi
not at google - send to devlin
2012/02/16 00:06:27
Yeah I'm hoping/expecting that once your require()
| |
| 319 } | 333 } |
| 320 | 334 |
| 321 return true; | 335 return true; |
| 322 } | 336 } |
| 323 | 337 |
| 324 return false; | 338 return false; |
| 325 } | 339 } |
| 326 | 340 |
| 327 void ExtensionDispatcher::DidCreateScriptContext( | 341 void ExtensionDispatcher::DidCreateScriptContext( |
| 328 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { | 342 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { |
| 343 bool is_content_script = (hack_DidCreateScriptContext_extension_group == | |
| 344 EXTENSION_GROUP_CONTENT_SCRIPTS); | |
| 345 | |
| 329 ChromeV8Context* context = | 346 ChromeV8Context* context = |
| 330 new ChromeV8Context(v8_context, frame, GetExtensionID(frame, world_id)); | 347 new ChromeV8Context( |
| 348 v8_context, | |
| 349 frame, | |
| 350 GetExtensionID(frame, world_id), | |
| 351 is_content_script); | |
| 331 v8_context_set_.Add(context); | 352 v8_context_set_.Add(context); |
| 332 | 353 |
| 333 const Extension* extension = extensions_.GetByID(context->extension_id()); | 354 const Extension* extension = extensions_.GetByID(context->extension_id()); |
| 334 int manifest_version = 1; | 355 int manifest_version = 1; |
| 335 if (extension) | 356 if (extension) |
| 336 manifest_version = extension->manifest_version(); | 357 manifest_version = extension->manifest_version(); |
| 337 | 358 |
| 338 context->DispatchOnLoadEvent( | 359 context->DispatchOnLoadEvent( |
| 339 is_extension_process_, | 360 is_extension_process_, |
| 340 ChromeRenderProcessObserver::is_incognito_process(), | 361 ChromeRenderProcessObserver::is_incognito_process(), |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 | 519 |
| 499 RenderThread::Get()->RegisterExtension(extension); | 520 RenderThread::Get()->RegisterExtension(extension); |
| 500 } | 521 } |
| 501 | 522 |
| 502 void ExtensionDispatcher::OnUsingWebRequestAPI( | 523 void ExtensionDispatcher::OnUsingWebRequestAPI( |
| 503 bool adblock, bool adblock_plus, bool other) { | 524 bool adblock, bool adblock_plus, bool other) { |
| 504 webrequest_adblock_ = adblock; | 525 webrequest_adblock_ = adblock; |
| 505 webrequest_adblock_plus_ = adblock_plus; | 526 webrequest_adblock_plus_ = adblock_plus; |
| 506 webrequest_other_ = other; | 527 webrequest_other_ = other; |
| 507 } | 528 } |
| OLD | NEW |