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/browser/extensions/extension_function_dispatcher.h" | 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); | 420 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); |
421 } | 421 } |
422 | 422 |
423 void ExtensionFunctionDispatcher::ResetFunctions() { | 423 void ExtensionFunctionDispatcher::ResetFunctions() { |
424 FactoryRegistry::GetInstance()->ResetFunctions(); | 424 FactoryRegistry::GetInstance()->ResetFunctions(); |
425 } | 425 } |
426 | 426 |
427 // static | 427 // static |
428 void ExtensionFunctionDispatcher::DispatchOnIOThread( | 428 void ExtensionFunctionDispatcher::DispatchOnIOThread( |
429 const ExtensionInfoMap* extension_info_map, | 429 const ExtensionInfoMap* extension_info_map, |
430 ProfileId profile_id, | 430 void* profile, |
431 int render_process_id, | 431 int render_process_id, |
432 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, | 432 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
433 int routing_id, | 433 int routing_id, |
434 const ExtensionHostMsg_Request_Params& params) { | 434 const ExtensionHostMsg_Request_Params& params) { |
435 const Extension* extension = | 435 const Extension* extension = |
436 extension_info_map->extensions().GetByURL(params.source_url); | 436 extension_info_map->extensions().GetByURL(params.source_url); |
437 | 437 |
438 scoped_refptr<ExtensionFunction> function( | 438 scoped_refptr<ExtensionFunction> function( |
439 CreateExtensionFunction(params, extension, profile_id, render_process_id, | 439 CreateExtensionFunction(params, extension, profile, render_process_id, |
440 ipc_sender, routing_id)); | 440 ipc_sender, routing_id)); |
441 if (!function) | 441 if (!function) |
442 return; | 442 return; |
443 | 443 |
444 IOThreadExtensionFunction* function_io = | 444 IOThreadExtensionFunction* function_io = |
445 function->AsIOThreadExtensionFunction(); | 445 function->AsIOThreadExtensionFunction(); |
446 if (!function_io) { | 446 if (!function_io) { |
447 NOTREACHED(); | 447 NOTREACHED(); |
448 return; | 448 return; |
449 } | 449 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 return; | 503 return; |
504 } | 504 } |
505 | 505 |
506 // TODO(aa): When we allow content scripts to call extension APIs, we will | 506 // TODO(aa): When we allow content scripts to call extension APIs, we will |
507 // have to pass the extension ID explicitly here, not use the source URL. | 507 // have to pass the extension ID explicitly here, not use the source URL. |
508 const Extension* extension = service->GetExtensionByURL(params.source_url); | 508 const Extension* extension = service->GetExtensionByURL(params.source_url); |
509 if (!extension) | 509 if (!extension) |
510 extension = service->GetExtensionByWebExtent(params.source_url); | 510 extension = service->GetExtensionByWebExtent(params.source_url); |
511 | 511 |
512 scoped_refptr<ExtensionFunction> function(CreateExtensionFunction( | 512 scoped_refptr<ExtensionFunction> function(CreateExtensionFunction( |
513 params, extension, profile_->GetRuntimeId(), | 513 params, extension, profile_, |
514 render_view_host->process()->id(), | 514 render_view_host->process()->id(), |
515 render_view_host, render_view_host->routing_id())); | 515 render_view_host, render_view_host->routing_id())); |
516 if (!function) | 516 if (!function) |
517 return; | 517 return; |
518 | 518 |
519 UIThreadExtensionFunction* function_ui = | 519 UIThreadExtensionFunction* function_ui = |
520 function->AsUIThreadExtensionFunction(); | 520 function->AsUIThreadExtensionFunction(); |
521 if (!function_ui) { | 521 if (!function_ui) { |
522 NOTREACHED(); | 522 NOTREACHED(); |
523 return; | 523 return; |
(...skipping 14 matching lines...) Expand all Loading... |
538 render_view_host->Send(new ExtensionMsg_Response( | 538 render_view_host->Send(new ExtensionMsg_Response( |
539 render_view_host->routing_id(), function->request_id(), false, | 539 render_view_host->routing_id(), function->request_id(), false, |
540 std::string(), QuotaLimitHeuristic::kGenericOverQuotaError)); | 540 std::string(), QuotaLimitHeuristic::kGenericOverQuotaError)); |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 // static | 544 // static |
545 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( | 545 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( |
546 const ExtensionHostMsg_Request_Params& params, | 546 const ExtensionHostMsg_Request_Params& params, |
547 const Extension* extension, | 547 const Extension* extension, |
548 ProfileId profile_id, | 548 void* profile, |
549 int render_process_id, | 549 int render_process_id, |
550 IPC::Message::Sender* ipc_sender, | 550 IPC::Message::Sender* ipc_sender, |
551 int routing_id) { | 551 int routing_id) { |
552 // TODO(aa): It would be cool to use ExtensionProcessManager to track which | 552 // TODO(aa): It would be cool to use ExtensionProcessManager to track which |
553 // processes are extension processes rather than ChildProcessSecurityPolicy. | 553 // processes are extension processes rather than ChildProcessSecurityPolicy. |
554 // EPM has richer information: it not only knows which processes contain | 554 // EPM has richer information: it not only knows which processes contain |
555 // at least one extension, but it knows which extensions are inside and what | 555 // at least one extension, but it knows which extensions are inside and what |
556 // permissions the have. So we would be able to enforce permissions more | 556 // permissions the have. So we would be able to enforce permissions more |
557 // granularly. | 557 // granularly. |
558 if (!ChildProcessSecurityPolicy::GetInstance()->HasExtensionBindings( | 558 if (!ChildProcessSecurityPolicy::GetInstance()->HasExtensionBindings( |
(...skipping 20 matching lines...) Expand all Loading... |
579 } | 579 } |
580 | 580 |
581 ExtensionFunction* function = | 581 ExtensionFunction* function = |
582 FactoryRegistry::GetInstance()->NewFunction(params.name); | 582 FactoryRegistry::GetInstance()->NewFunction(params.name); |
583 function->SetArgs(¶ms.arguments); | 583 function->SetArgs(¶ms.arguments); |
584 function->set_source_url(params.source_url); | 584 function->set_source_url(params.source_url); |
585 function->set_request_id(params.request_id); | 585 function->set_request_id(params.request_id); |
586 function->set_has_callback(params.has_callback); | 586 function->set_has_callback(params.has_callback); |
587 function->set_user_gesture(params.user_gesture); | 587 function->set_user_gesture(params.user_gesture); |
588 function->set_extension(extension); | 588 function->set_extension(extension); |
589 function->set_profile_id(profile_id); | 589 function->set_profile(profile); |
590 return function; | 590 return function; |
591 } | 591 } |
592 | 592 |
593 // static | 593 // static |
594 void ExtensionFunctionDispatcher::SendAccessDenied( | 594 void ExtensionFunctionDispatcher::SendAccessDenied( |
595 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { | 595 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
596 ipc_sender->Send(new ExtensionMsg_Response( | 596 ipc_sender->Send(new ExtensionMsg_Response( |
597 routing_id, request_id, false, std::string(), | 597 routing_id, request_id, false, std::string(), |
598 "Access to extension API denied.")); | 598 "Access to extension API denied.")); |
599 } | 599 } |
OLD | NEW |