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

Side by Side Diff: chrome/browser/extensions/extension_function_registry.cc

Issue 9666059: Extract ExtensionFunctionRegistry from ExtensionFunctionDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: aa's changes Created 8 years, 9 months 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 | Annotate | Revision Log
OLDNEW
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/browser/extensions/extension_function_dispatcher.h" 5 #include "chrome/browser/extensions/extension_function_registry.h"
6 6
7 #include <map>
8
9 #include "base/json/json_string_value_serializer.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/singleton.h"
12 #include "base/process_util.h"
13 #include "base/values.h"
14 #include "build/build_config.h"
15 #include "chrome/browser/accessibility/accessibility_extension_api.h" 7 #include "chrome/browser/accessibility/accessibility_extension_api.h"
16 #include "chrome/browser/bookmarks/bookmark_extension_api.h" 8 #include "chrome/browser/bookmarks/bookmark_extension_api.h"
17 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" 9 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h"
18 #include "chrome/browser/download/download_extension_api.h" 10 #include "chrome/browser/download/download_extension_api.h"
19 #include "chrome/browser/extensions/api/app/app_api.h" 11 #include "chrome/browser/extensions/api/app/app_api.h"
20 #include "chrome/browser/extensions/api/browsingdata/browsing_data_api.h" 12 #include "chrome/browser/extensions/api/browsingdata/browsing_data_api.h"
21 #include "chrome/browser/extensions/api/declarative/declarative_api.h" 13 #include "chrome/browser/extensions/api/declarative/declarative_api.h"
22 #include "chrome/browser/extensions/api/dns/dns_api.h"
23 #include "chrome/browser/extensions/api/permissions/permissions_api.h" 14 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
24 #include "chrome/browser/extensions/api/serial/serial_api.h" 15 #include "chrome/browser/extensions/api/serial/serial_api.h"
25 #include "chrome/browser/extensions/api/socket/socket_api.h" 16 #include "chrome/browser/extensions/api/socket/socket_api.h"
26 #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" 17 #include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
27 #include "chrome/browser/extensions/execute_code_in_tab_function.h" 18 #include "chrome/browser/extensions/execute_code_in_tab_function.h"
28 #include "chrome/browser/extensions/extension_activity_log.h"
29 #include "chrome/browser/extensions/extension_browser_actions_api.h" 19 #include "chrome/browser/extensions/extension_browser_actions_api.h"
30 #include "chrome/browser/extensions/extension_chrome_auth_private_api.h" 20 #include "chrome/browser/extensions/extension_chrome_auth_private_api.h"
31 #include "chrome/browser/extensions/extension_content_settings_api.h" 21 #include "chrome/browser/extensions/extension_content_settings_api.h"
32 #include "chrome/browser/extensions/extension_context_menu_api.h" 22 #include "chrome/browser/extensions/extension_context_menu_api.h"
33 #include "chrome/browser/extensions/extension_cookies_api.h" 23 #include "chrome/browser/extensions/extension_cookies_api.h"
34 #include "chrome/browser/extensions/extension_debugger_api.h" 24 #include "chrome/browser/extensions/extension_debugger_api.h"
35 #include "chrome/browser/extensions/extension_font_settings_api.h" 25 #include "chrome/browser/extensions/extension_font_settings_api.h"
36 #include "chrome/browser/extensions/extension_function.h"
37 #include "chrome/browser/extensions/extension_i18n_api.h" 26 #include "chrome/browser/extensions/extension_i18n_api.h"
38 #include "chrome/browser/extensions/extension_idle_api.h" 27 #include "chrome/browser/extensions/extension_idle_api.h"
39 #include "chrome/browser/extensions/extension_managed_mode_api.h" 28 #include "chrome/browser/extensions/extension_managed_mode_api.h"
40 #include "chrome/browser/extensions/extension_management_api.h" 29 #include "chrome/browser/extensions/extension_management_api.h"
41 #include "chrome/browser/extensions/extension_metrics_module.h" 30 #include "chrome/browser/extensions/extension_metrics_module.h"
42 #include "chrome/browser/extensions/extension_module.h" 31 #include "chrome/browser/extensions/extension_module.h"
43 #include "chrome/browser/extensions/extension_omnibox_api.h" 32 #include "chrome/browser/extensions/extension_omnibox_api.h"
44 #include "chrome/browser/extensions/extension_page_actions_module.h" 33 #include "chrome/browser/extensions/extension_page_actions_module.h"
45 #include "chrome/browser/extensions/extension_page_capture_api.h" 34 #include "chrome/browser/extensions/extension_page_capture_api.h"
46 #include "chrome/browser/extensions/extension_preference_api.h" 35 #include "chrome/browser/extensions/extension_preference_api.h"
47 #include "chrome/browser/extensions/extension_processes_api.h" 36 #include "chrome/browser/extensions/extension_processes_api.h"
48 #include "chrome/browser/extensions/extension_service.h"
49 #include "chrome/browser/extensions/extension_tabs_module.h" 37 #include "chrome/browser/extensions/extension_tabs_module.h"
50 #include "chrome/browser/extensions/extension_test_api.h" 38 #include "chrome/browser/extensions/extension_test_api.h"
51 #include "chrome/browser/extensions/extension_tts_api.h" 39 #include "chrome/browser/extensions/extension_tts_api.h"
52 #include "chrome/browser/extensions/extension_tts_engine_api.h" 40 #include "chrome/browser/extensions/extension_tts_engine_api.h"
53 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h" 41 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h"
54 #include "chrome/browser/extensions/extension_web_ui.h"
55 #include "chrome/browser/extensions/extension_webnavigation_api.h" 42 #include "chrome/browser/extensions/extension_webnavigation_api.h"
56 #include "chrome/browser/extensions/extension_webstore_private_api.h" 43 #include "chrome/browser/extensions/extension_webstore_private_api.h"
57 #include "chrome/browser/extensions/extensions_quota_service.h"
58 #include "chrome/browser/extensions/process_map.h"
59 #include "chrome/browser/extensions/settings/settings_api.h" 44 #include "chrome/browser/extensions/settings/settings_api.h"
60 #include "chrome/browser/extensions/system/system_api.h" 45 #include "chrome/browser/extensions/system/system_api.h"
61 #include "chrome/browser/external_protocol/external_protocol_handler.h"
62 #include "chrome/browser/history/history_extension_api.h" 46 #include "chrome/browser/history/history_extension_api.h"
63 #include "chrome/browser/history/top_sites_extension_api.h" 47 #include "chrome/browser/history/top_sites_extension_api.h"
64 #include "chrome/browser/infobars/infobar_extension_api.h" 48 #include "chrome/browser/infobars/infobar_extension_api.h"
65 #include "chrome/browser/profiles/profile.h"
66 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
67 #include "chrome/browser/rlz/rlz_extension_api.h" 49 #include "chrome/browser/rlz/rlz_extension_api.h"
68 #include "chrome/browser/speech/speech_input_extension_api.h" 50 #include "chrome/browser/speech/speech_input_extension_api.h"
69 #include "chrome/browser/ui/browser_list.h" 51 #include "chrome/common/extensions/api/generated_api.h"
70 #include "chrome/browser/ui/browser_window.h"
71 #include "chrome/common/extensions/api/extension_api.h"
72 #include "chrome/common/extensions/extension_messages.h"
73 #include "chrome/common/extensions/extension_set.h"
74 #include "chrome/common/url_constants.h"
75 #include "content/public/browser/render_process_host.h"
76 #include "content/public/browser/render_view_host.h"
77 #include "ipc/ipc_message.h"
78 #include "ipc/ipc_message_macros.h"
79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
80 #include "third_party/skia/include/core/SkBitmap.h"
81 52
82 #if defined(TOOLKIT_VIEWS) 53 #if defined(TOOLKIT_VIEWS)
83 #include "chrome/browser/extensions/extension_input_api.h" 54 #include "chrome/browser/extensions/extension_input_api.h"
84 #endif 55 #endif
85 56
86 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD) 57 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD)
87 #include "chrome/browser/extensions/extension_input_ui_api.h" 58 #include "chrome/browser/extensions/extension_input_ui_api.h"
88 #endif 59 #endif
89 60
90 #if defined(OS_CHROMEOS) 61 #if defined(OS_CHROMEOS)
91 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" 62 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h"
92 #include "chrome/browser/chromeos/media/media_player_extension_api.h" 63 #include "chrome/browser/chromeos/media/media_player_extension_api.h"
93 #include "chrome/browser/extensions/api/terminal/terminal_private_api.h" 64 #include "chrome/browser/extensions/api/terminal/terminal_private_api.h"
94 #include "chrome/browser/extensions/extension_info_private_api_chromeos.h" 65 #include "chrome/browser/extensions/extension_info_private_api_chromeos.h"
95 #include "chrome/browser/extensions/extension_input_ime_api.h" 66 #include "chrome/browser/extensions/extension_input_ime_api.h"
96 #include "chrome/browser/extensions/extension_input_method_api.h" 67 #include "chrome/browser/extensions/extension_input_method_api.h"
97 #endif 68 #endif
98 69
99 using extensions::ExtensionAPI; 70 // static
100 using content::RenderViewHost; 71 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
101 using WebKit::WebSecurityOrigin; 72 return Singleton<ExtensionFunctionRegistry>::get();
102
103 // FactoryRegistry -------------------------------------------------------------
104
105 namespace {
106
107 // Template for defining ExtensionFunctionFactory.
108 template<class T>
109 ExtensionFunction* NewExtensionFunction() {
110 return new T();
111 } 73 }
112 74
113 // Contains a list of all known extension functions and allows clients to 75 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
114 // create instances of them. 76 ResetFunctions();
115 class FactoryRegistry {
116 public:
117 static FactoryRegistry* GetInstance();
118 FactoryRegistry() { ResetFunctions(); }
119
120 // Resets all functions to their default values.
121 void ResetFunctions();
122
123 // Adds all function names to 'names'.
124 void GetAllNames(std::vector<std::string>* names);
125
126 // Allows overriding of specific functions (e.g. for testing). Functions
127 // must be previously registered. Returns true if successful.
128 bool OverrideFunction(const std::string& name,
129 ExtensionFunctionFactory factory);
130
131 // Factory method for the ExtensionFunction registered as 'name'.
132 ExtensionFunction* NewFunction(const std::string& name);
133
134 private:
135 template<class T>
136 void RegisterFunction() {
137 factories_[T::function_name()] = &NewExtensionFunction<T>;
138 }
139
140 typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap;
141 FactoryMap factories_;
142 };
143
144 FactoryRegistry* FactoryRegistry::GetInstance() {
145 return Singleton<FactoryRegistry>::get();
146 } 77 }
147 78
148 void FactoryRegistry::ResetFunctions() { 79 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {
80 }
81
82 void ExtensionFunctionRegistry::ResetFunctions() {
149 // Register all functions here. 83 // Register all functions here.
150 84
151 // Windows 85 // Windows
152 RegisterFunction<GetWindowFunction>(); 86 RegisterFunction<GetWindowFunction>();
153 RegisterFunction<GetCurrentWindowFunction>(); 87 RegisterFunction<GetCurrentWindowFunction>();
154 RegisterFunction<GetLastFocusedWindowFunction>(); 88 RegisterFunction<GetLastFocusedWindowFunction>();
155 RegisterFunction<GetAllWindowsFunction>(); 89 RegisterFunction<GetAllWindowsFunction>();
156 RegisterFunction<CreateWindowFunction>(); 90 RegisterFunction<CreateWindowFunction>();
157 RegisterFunction<UpdateWindowFunction>(); 91 RegisterFunction<UpdateWindowFunction>();
158 RegisterFunction<RemoveWindowFunction>(); 92 RegisterFunction<RemoveWindowFunction>();
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 RegisterFunction<extensions::SerialWriteFunction>(); 444 RegisterFunction<extensions::SerialWriteFunction>();
511 445
512 // Sockets 446 // Sockets
513 RegisterFunction<extensions::SocketCreateFunction>(); 447 RegisterFunction<extensions::SocketCreateFunction>();
514 RegisterFunction<extensions::SocketDestroyFunction>(); 448 RegisterFunction<extensions::SocketDestroyFunction>();
515 RegisterFunction<extensions::SocketConnectFunction>(); 449 RegisterFunction<extensions::SocketConnectFunction>();
516 RegisterFunction<extensions::SocketDisconnectFunction>(); 450 RegisterFunction<extensions::SocketDisconnectFunction>();
517 RegisterFunction<extensions::SocketReadFunction>(); 451 RegisterFunction<extensions::SocketReadFunction>();
518 RegisterFunction<extensions::SocketWriteFunction>(); 452 RegisterFunction<extensions::SocketWriteFunction>();
519 453
520 // DNS
521 RegisterFunction<extensions::DNSResolveFunction>();
522
523 // System 454 // System
524 RegisterFunction<extensions::GetIncognitoModeAvailabilityFunction>(); 455 RegisterFunction<extensions::GetIncognitoModeAvailabilityFunction>();
525 RegisterFunction<extensions::GetUpdateStatusFunction>(); 456 RegisterFunction<extensions::GetUpdateStatusFunction>();
526 457
527 // Net 458 // Net
528 RegisterFunction<extensions::AddRulesFunction>(); 459 RegisterFunction<extensions::AddRulesFunction>();
529 RegisterFunction<extensions::RemoveRulesFunction>(); 460 RegisterFunction<extensions::RemoveRulesFunction>();
530 RegisterFunction<extensions::GetRulesFunction>(); 461 RegisterFunction<extensions::GetRulesFunction>();
462
463 // Generated APIs
464 extensions::api::GeneratedFunctionRegistry::RegisterAll(this);
531 } 465 }
532 466
533 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { 467 void ExtensionFunctionRegistry::GetAllNames(std::vector<std::string>* names) {
534 for (FactoryMap::iterator iter = factories_.begin(); 468 for (FactoryMap::iterator iter = factories_.begin();
535 iter != factories_.end(); ++iter) { 469 iter != factories_.end(); ++iter) {
536 names->push_back(iter->first); 470 names->push_back(iter->first);
537 } 471 }
538 } 472 }
539 473
540 bool FactoryRegistry::OverrideFunction(const std::string& name, 474 bool ExtensionFunctionRegistry::OverrideFunction(
541 ExtensionFunctionFactory factory) { 475 const std::string& name,
476 ExtensionFunctionFactory factory) {
542 FactoryMap::iterator iter = factories_.find(name); 477 FactoryMap::iterator iter = factories_.find(name);
543 if (iter == factories_.end()) { 478 if (iter == factories_.end()) {
544 return false; 479 return false;
545 } else { 480 } else {
546 iter->second = factory; 481 iter->second = factory;
547 return true; 482 return true;
548 } 483 }
549 } 484 }
550 485
551 ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) { 486 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
487 const std::string& name) {
552 FactoryMap::iterator iter = factories_.find(name); 488 FactoryMap::iterator iter = factories_.find(name);
553 DCHECK(iter != factories_.end()); 489 DCHECK(iter != factories_.end());
554 ExtensionFunction* function = iter->second(); 490 ExtensionFunction* function = iter->second();
555 function->set_name(name); 491 function->set_name(name);
556 return function; 492 return function;
557 } 493 }
558
559 const char kAccessDenied[] = "access denied";
560 const char kQuotaExceeded[] = "quota exceeded";
561
562 void LogSuccess(const Extension* extension,
563 const ExtensionHostMsg_Request_Params& params) {
564 ExtensionActivityLog* extension_activity_log =
565 ExtensionActivityLog::GetInstance();
566 if (extension_activity_log->HasObservers(extension)) {
567 std::string call_signature = params.name + "(";
568 ListValue::const_iterator it = params.arguments.begin();
569 for (; it != params.arguments.end(); ++it) {
570 std::string arg;
571 JSONStringValueSerializer serializer(&arg);
572 if (serializer.SerializeAndOmitBinaryValues(**it)) {
573 if (it != params.arguments.begin())
574 call_signature += ", ";
575 call_signature += arg;
576 }
577 }
578 call_signature += ")";
579
580 extension_activity_log->Log(
581 extension,
582 ExtensionActivityLog::ACTIVITY_EXTENSION_API_CALL,
583 call_signature);
584 }
585 }
586
587 void LogFailure(const Extension* extension,
588 const std::string& func_name,
589 const char* reason) {
590 ExtensionActivityLog* extension_activity_log =
591 ExtensionActivityLog::GetInstance();
592 if (extension_activity_log->HasObservers(extension)) {
593 extension_activity_log->Log(
594 extension,
595 ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK,
596 func_name + ": " + reason);
597 }
598 }
599
600 }; // namespace
601
602 // ExtensionFunctionDispatcher -------------------------------------------------
603
604 void ExtensionFunctionDispatcher::GetAllFunctionNames(
605 std::vector<std::string>* names) {
606 FactoryRegistry::GetInstance()->GetAllNames(names);
607 }
608
609 bool ExtensionFunctionDispatcher::OverrideFunction(
610 const std::string& name, ExtensionFunctionFactory factory) {
611 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory);
612 }
613
614 void ExtensionFunctionDispatcher::ResetFunctions() {
615 FactoryRegistry::GetInstance()->ResetFunctions();
616 }
617
618 // static
619 void ExtensionFunctionDispatcher::DispatchOnIOThread(
620 ExtensionInfoMap* extension_info_map,
621 void* profile,
622 int render_process_id,
623 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
624 int routing_id,
625 const ExtensionHostMsg_Request_Params& params) {
626 const Extension* extension =
627 extension_info_map->extensions().GetByID(params.extension_id);
628
629 scoped_refptr<ExtensionFunction> function(
630 CreateExtensionFunction(params, extension, render_process_id,
631 extension_info_map->process_map(), profile,
632 ipc_sender, routing_id));
633 if (!function) {
634 LogFailure(extension, params.name, kAccessDenied);
635 return;
636 }
637
638 IOThreadExtensionFunction* function_io =
639 function->AsIOThreadExtensionFunction();
640 if (!function_io) {
641 NOTREACHED();
642 return;
643 }
644 function_io->set_ipc_sender(ipc_sender, routing_id);
645 function_io->set_extension_info_map(extension_info_map);
646 function->set_include_incognito(
647 extension_info_map->IsIncognitoEnabled(extension->id()));
648
649 ExtensionsQuotaService* quota = extension_info_map->quota_service();
650 if (quota->Assess(extension->id(), function, &params.arguments,
651 base::TimeTicks::Now())) {
652 function->Run();
653 LogSuccess(extension, params);
654 } else {
655 function->OnQuotaExceeded();
656 LogFailure(extension, params.name, kQuotaExceeded);
657 }
658 }
659
660 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile,
661 Delegate* delegate)
662 : profile_(profile),
663 delegate_(delegate) {
664 }
665
666 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
667 }
668
669 Browser* ExtensionFunctionDispatcher::GetCurrentBrowser(
670 RenderViewHost* render_view_host, bool include_incognito) {
671 Browser* browser = delegate_->GetBrowser();
672
673 // If the delegate has an associated browser, that is always the right answer.
674 if (browser)
675 return browser;
676
677 // Otherwise, try to default to a reasonable browser. If |include_incognito|
678 // is true, we will also search browsers in the incognito version of this
679 // profile. Note that the profile may already be incognito, in which case
680 // we will search the incognito version only, regardless of the value of
681 // |include_incognito|.
682 Profile* profile = Profile::FromBrowserContext(
683 render_view_host->GetProcess()->GetBrowserContext());
684 browser = BrowserList::FindAnyBrowser(profile, include_incognito);
685
686 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
687 // a background_page onload chrome.tabs api call can make it into here
688 // before the browser is sufficiently initialized to return here.
689 // A similar situation may arise during shutdown.
690 // TODO(rafaelw): Delay creation of background_page until the browser
691 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
692 return browser;
693 }
694
695 void ExtensionFunctionDispatcher::Dispatch(
696 const ExtensionHostMsg_Request_Params& params,
697 RenderViewHost* render_view_host) {
698 ExtensionService* service = profile()->GetExtensionService();
699 extensions::ProcessMap* process_map = service->process_map();
700 if (!service || !process_map)
701 return;
702
703 const Extension* extension = service->extensions()->GetByID(
704 params.extension_id);
705 if (!extension)
706 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo(
707 WebSecurityOrigin::createFromString(params.source_origin),
708 params.source_url));
709
710 scoped_refptr<ExtensionFunction> function(
711 CreateExtensionFunction(params, extension,
712 render_view_host->GetProcess()->GetID(),
713 *(service->process_map()),
714 profile(), render_view_host,
715 render_view_host->GetRoutingID()));
716 if (!function) {
717 LogFailure(extension, params.name, kAccessDenied);
718 return;
719 }
720
721 UIThreadExtensionFunction* function_ui =
722 function->AsUIThreadExtensionFunction();
723 if (!function_ui) {
724 NOTREACHED();
725 return;
726 }
727 function_ui->SetRenderViewHost(render_view_host);
728 function_ui->set_dispatcher(AsWeakPtr());
729 function_ui->set_profile(profile_);
730 function->set_include_incognito(service->CanCrossIncognito(extension));
731
732 ExtensionsQuotaService* quota = service->quota_service();
733 if (quota->Assess(extension->id(), function, &params.arguments,
734 base::TimeTicks::Now())) {
735 // See crbug.com/39178.
736 ExternalProtocolHandler::PermitLaunchUrl();
737
738 function->Run();
739 LogSuccess(extension, params);
740 } else {
741 function->OnQuotaExceeded();
742 LogFailure(extension, params.name, kQuotaExceeded);
743 }
744
745 // We only adjust the keepalive count for UIThreadExtensionFunction for
746 // now, largely for simplicity's sake. This is OK because currently, only
747 // the webRequest API uses IOThreadExtensionFunction, and that API is not
748 // compatible with lazy background pages.
749 profile()->GetExtensionProcessManager()->IncrementLazyKeepaliveCount(
750 extension);
751 }
752
753 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
754 const Extension* extension) {
755 profile()->GetExtensionProcessManager()->DecrementLazyKeepaliveCount(
756 extension);
757 }
758
759 // static
760 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction(
761 const ExtensionHostMsg_Request_Params& params,
762 const Extension* extension,
763 int requesting_process_id,
764 const extensions::ProcessMap& process_map,
765 void* profile,
766 IPC::Message::Sender* ipc_sender,
767 int routing_id) {
768 if (!extension) {
769 LOG(ERROR) << "Specified extension does not exist.";
770 SendAccessDenied(ipc_sender, routing_id, params.request_id);
771 return NULL;
772 }
773
774 if (ExtensionAPI::GetInstance()->IsPrivileged(params.name) &&
775 !process_map.Contains(extension->id(), requesting_process_id)) {
776 LOG(ERROR) << "Extension API called from incorrect process "
777 << requesting_process_id
778 << " from URL " << params.source_url.spec();
779 SendAccessDenied(ipc_sender, routing_id, params.request_id);
780 return NULL;
781 }
782
783 if (!extension->HasAPIPermission(params.name)) {
784 LOG(ERROR) << "Extension " << extension->id() << " does not have "
785 << "permission to function: " << params.name;
786 SendAccessDenied(ipc_sender, routing_id, params.request_id);
787 return NULL;
788 }
789
790 ExtensionFunction* function =
791 FactoryRegistry::GetInstance()->NewFunction(params.name);
792 function->SetArgs(&params.arguments);
793 function->set_source_url(params.source_url);
794 function->set_request_id(params.request_id);
795 function->set_has_callback(params.has_callback);
796 function->set_user_gesture(params.user_gesture);
797 function->set_extension(extension);
798 function->set_profile_id(profile);
799 return function;
800 }
801
802 // static
803 void ExtensionFunctionDispatcher::SendAccessDenied(
804 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) {
805 ipc_sender->Send(new ExtensionMsg_Response(
806 routing_id, request_id, false, std::string(),
807 "Access to extension API denied."));
808 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_registry.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698