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/dispatcher.h" | 5 #include "chrome/renderer/extensions/dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "chrome/renderer/extensions/file_system_natives.h" | 34 #include "chrome/renderer/extensions/file_system_natives.h" |
35 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 35 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
36 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 36 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
37 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 37 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
38 #include "chrome/renderer/extensions/module_system.h" | 38 #include "chrome/renderer/extensions/module_system.h" |
39 #include "chrome/renderer/extensions/native_handler.h" | 39 #include "chrome/renderer/extensions/native_handler.h" |
40 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | 40 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
41 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | 41 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
42 #include "chrome/renderer/extensions/request_sender.h" | 42 #include "chrome/renderer/extensions/request_sender.h" |
43 #include "chrome/renderer/extensions/runtime_custom_bindings.h" | 43 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
44 #include "chrome/renderer/extensions/schema_generated_native_handler.h" | |
44 #include "chrome/renderer/extensions/send_request_natives.h" | 45 #include "chrome/renderer/extensions/send_request_natives.h" |
45 #include "chrome/renderer/extensions/set_icon_natives.h" | 46 #include "chrome/renderer/extensions/set_icon_natives.h" |
46 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" | 47 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" |
47 #include "chrome/renderer/extensions/tab_finder.h" | 48 #include "chrome/renderer/extensions/tab_finder.h" |
48 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 49 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
49 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 50 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
50 #include "chrome/renderer/extensions/user_script_slave.h" | 51 #include "chrome/renderer/extensions/user_script_slave.h" |
51 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | 52 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
52 #include "chrome/renderer/extensions/webstore_bindings.h" | 53 #include "chrome/renderer/extensions/webstore_bindings.h" |
53 #include "chrome/renderer/resource_bundle_source_map.h" | 54 #include "chrome/renderer/resource_bundle_source_map.h" |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 } // namespace | 544 } // namespace |
544 | 545 |
545 bool Dispatcher::AllowScriptExtension(WebFrame* frame, | 546 bool Dispatcher::AllowScriptExtension(WebFrame* frame, |
546 const std::string& v8_extension_name, | 547 const std::string& v8_extension_name, |
547 int extension_group, | 548 int extension_group, |
548 int world_id) { | 549 int world_id) { |
549 g_hack_extension_group = extension_group; | 550 g_hack_extension_group = extension_group; |
550 return true; | 551 return true; |
551 } | 552 } |
552 | 553 |
554 void Dispatcher::RegisterSchemaGeneratedBindings( | |
555 ModuleSystem* module_system, | |
556 ChromeV8Context* context, | |
557 v8::Handle<v8::Context> v8_context, | |
558 Feature::Context feature_context) { | |
559 // TODO: Change this to ExtensionAPI::GetAPIsForContext()? | |
not at google - send to devlin
2012/12/14 00:44:00
what you have is correct, the comment and the comm
cduvall
2012/12/14 02:04:50
Done.
| |
560 // const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); | |
561 std::set<std::string> apis = | |
562 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | |
563 for (std::set<std::string>::iterator it = apis.begin(); | |
564 it != apis.end(); ++it) { | |
565 const std::string& api_name = *it; | |
566 // If there isn't already a custom binding for this API, we need to make | |
567 // sure one exists to load the schema. Otherwise the custom binding will | |
568 // need to do it itself. Either way, register it on the chrome object to be | |
569 // loaded lazily. | |
570 if (!module_system->HasNativeHandler(api_name)) { | |
571 module_system->RegisterNativeHandler( | |
572 api_name, | |
573 scoped_ptr<NativeHandler>( | |
574 new SchemaGeneratedNativeHandler(module_system, | |
575 v8_schema_registry(), | |
576 api_name, | |
577 "schema"))); | |
578 module_system->SetLazyField(GetOrCreateChrome(v8_context), | |
579 api_name, | |
580 "schema_binding_generator", | |
581 "generate", | |
582 api_name); | |
not at google - send to devlin
2012/12/14 00:44:00
I think the file roles and their names are getting
cduvall
2012/12/14 02:04:50
Done.
| |
583 } else { | |
584 // TODO: Make this lazy. | |
585 InstallBindings(module_system, v8_context, api_name); | |
586 } | |
587 } | |
588 } | |
589 | |
553 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 590 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
554 ChromeV8Context* context) { | 591 ChromeV8Context* context) { |
555 module_system->RegisterNativeHandler("event_bindings", | 592 module_system->RegisterNativeHandler("event_bindings", |
556 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 593 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
557 module_system->RegisterNativeHandler("miscellaneous_bindings", | 594 module_system->RegisterNativeHandler("miscellaneous_bindings", |
558 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 595 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
559 module_system->RegisterNativeHandler("apiDefinitions", | 596 module_system->RegisterNativeHandler("apiDefinitions", |
560 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 597 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); |
561 module_system->RegisterNativeHandler("sendRequest", | 598 module_system->RegisterNativeHandler("sendRequest", |
562 scoped_ptr<NativeHandler>( | 599 scoped_ptr<NativeHandler>( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); | 705 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); |
669 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); | 706 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); |
670 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 707 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
671 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 708 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
672 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 709 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
673 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 710 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
674 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 711 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
675 source_map_.RegisterSource("webRequestInternal", | 712 source_map_.RegisterSource("webRequestInternal", |
676 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 713 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
677 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 714 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
715 source_map_.RegisterSource("schema_binding_generator", | |
716 IDR_SCHEMA_BINDING_GENERATOR_JS); | |
678 | 717 |
679 // Platform app sources that are not API-specific.. | 718 // Platform app sources that are not API-specific.. |
680 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); | 719 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); |
681 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); | 720 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); |
682 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); | 721 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); |
683 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 722 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
684 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); | 723 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); |
685 } | 724 } |
686 | 725 |
687 void Dispatcher::PopulateLazyBindingsMap() { | 726 void Dispatcher::PopulateLazyBindingsMap() { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 GetOrCreateChrome(v8_context); | 813 GetOrCreateChrome(v8_context); |
775 | 814 |
776 // Loading JavaScript is expensive, so only run the full API bindings | 815 // Loading JavaScript is expensive, so only run the full API bindings |
777 // generation mechanisms in extension pages (NOT all web pages). | 816 // generation mechanisms in extension pages (NOT all web pages). |
778 switch (context_type) { | 817 switch (context_type) { |
779 case Feature::UNSPECIFIED_CONTEXT: | 818 case Feature::UNSPECIFIED_CONTEXT: |
780 case Feature::WEB_PAGE_CONTEXT: | 819 case Feature::WEB_PAGE_CONTEXT: |
781 // TODO(kalman): see comment below about ExtensionAPI. | 820 // TODO(kalman): see comment below about ExtensionAPI. |
782 InstallBindings(module_system.get(), v8_context, "app"); | 821 InstallBindings(module_system.get(), v8_context, "app"); |
783 InstallBindings(module_system.get(), v8_context, "webstore"); | 822 InstallBindings(module_system.get(), v8_context, "webstore"); |
823 | |
824 // TODO: Move this back down to next case. | |
825 module_system->Require("schema_generated_bindings"); | |
826 RegisterSchemaGeneratedBindings(module_system.get(), | |
827 context, | |
828 v8_context, | |
829 context_type); | |
784 break; | 830 break; |
785 | |
786 case Feature::BLESSED_EXTENSION_CONTEXT: | 831 case Feature::BLESSED_EXTENSION_CONTEXT: |
787 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 832 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
788 case Feature::CONTENT_SCRIPT_CONTEXT: { | 833 case Feature::CONTENT_SCRIPT_CONTEXT: { |
789 CHECK(extension); | 834 CHECK(extension); |
790 if (!extension->is_platform_app()) | 835 if (!extension->is_platform_app()) |
791 module_system->Require("miscellaneous_bindings"); | 836 module_system->Require("miscellaneous_bindings"); |
792 module_system->Require("schema_generated_bindings"); | |
793 module_system->Require("apitest"); | 837 module_system->Require("apitest"); |
794 | 838 |
795 // TODO(kalman): move this code back out of the switch and execute it | 839 // TODO(kalman): move this code back out of the switch and execute it |
796 // regardless of |context_type|. ExtensionAPI knows how to return the | 840 // regardless of |context_type|. ExtensionAPI knows how to return the |
797 // correct APIs, however, until it doesn't have a 2MB overhead we can't | 841 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
798 // load it in every process. | 842 // load it in every process. |
799 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); | |
800 for (std::set<std::string>::const_iterator i = apis.begin(); | |
801 i != apis.end(); ++i) { | |
802 InstallBindings(module_system.get(), v8_context, *i); | |
803 } | |
804 | |
805 break; | 843 break; |
806 } | 844 } |
807 } | 845 } |
808 | 846 |
809 // Inject custom JS into the platform app context. | 847 // Inject custom JS into the platform app context. |
810 if (IsWithinPlatformApp(frame)) | 848 if (IsWithinPlatformApp(frame)) |
811 module_system->Require("platformApp"); | 849 module_system->Require("platformApp"); |
812 | 850 |
813 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 851 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
814 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); | 852 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1132 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1170 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1133 v8::ThrowException( | 1171 v8::ThrowException( |
1134 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1172 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1135 return false; | 1173 return false; |
1136 } | 1174 } |
1137 | 1175 |
1138 return true; | 1176 return true; |
1139 } | 1177 } |
1140 | 1178 |
1141 } // namespace extensions | 1179 } // namespace extensions |
OLD | NEW |