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

Side by Side Diff: chrome/renderer/extensions/dispatcher.cc

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/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
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
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()?
560 // const std::set<std::string>& apis = context->GetAvailableExtensionAPIs();
561 scoped_ptr<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(v8_schema_registry(),
575 api_name,
576 "schema")));
577 module_system->SetLazyField(GetOrCreateChrome(v8_context),
578 api_name,
579 "schema_binding_generator",
580 "generate",
581 api_name);
582 } else {
583 // TODO: Make this lazy.
not at google - send to devlin 2012/12/13 22:26:40 Yep - the idea is to pull the SetLazyField out of
584 InstallBindings(module_system, v8_context, api_name);
585 }
586 }
587 }
588
553 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, 589 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
554 ChromeV8Context* context) { 590 ChromeV8Context* context) {
555 module_system->RegisterNativeHandler("event_bindings", 591 module_system->RegisterNativeHandler("event_bindings",
556 scoped_ptr<NativeHandler>(EventBindings::Get(this))); 592 scoped_ptr<NativeHandler>(EventBindings::Get(this)));
557 module_system->RegisterNativeHandler("miscellaneous_bindings", 593 module_system->RegisterNativeHandler("miscellaneous_bindings",
558 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); 594 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this)));
559 module_system->RegisterNativeHandler("apiDefinitions", 595 module_system->RegisterNativeHandler("apiDefinitions",
560 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); 596 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this)));
561 module_system->RegisterNativeHandler("sendRequest", 597 module_system->RegisterNativeHandler("sendRequest",
562 scoped_ptr<NativeHandler>( 598 scoped_ptr<NativeHandler>(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); 704 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS);
669 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); 705 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS);
670 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); 706 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS);
671 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); 707 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS);
672 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); 708 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS);
673 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); 709 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS);
674 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); 710 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS);
675 source_map_.RegisterSource("webRequestInternal", 711 source_map_.RegisterSource("webRequestInternal",
676 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); 712 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS);
677 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); 713 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS);
714 source_map_.RegisterSource("schema_binding_generator",
715 IDR_SCHEMA_BINDING_GENERATOR_JS);
678 716
679 // Platform app sources that are not API-specific.. 717 // Platform app sources that are not API-specific..
680 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); 718 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS);
681 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); 719 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS);
682 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); 720 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS);
683 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); 721 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS);
684 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); 722 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS);
685 } 723 }
686 724
687 void Dispatcher::PopulateLazyBindingsMap() { 725 void Dispatcher::PopulateLazyBindingsMap() {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 GetOrCreateChrome(v8_context); 812 GetOrCreateChrome(v8_context);
775 813
776 // Loading JavaScript is expensive, so only run the full API bindings 814 // Loading JavaScript is expensive, so only run the full API bindings
777 // generation mechanisms in extension pages (NOT all web pages). 815 // generation mechanisms in extension pages (NOT all web pages).
778 switch (context_type) { 816 switch (context_type) {
779 case Feature::UNSPECIFIED_CONTEXT: 817 case Feature::UNSPECIFIED_CONTEXT:
780 case Feature::WEB_PAGE_CONTEXT: 818 case Feature::WEB_PAGE_CONTEXT:
781 // TODO(kalman): see comment below about ExtensionAPI. 819 // TODO(kalman): see comment below about ExtensionAPI.
782 InstallBindings(module_system.get(), v8_context, "app"); 820 InstallBindings(module_system.get(), v8_context, "app");
783 InstallBindings(module_system.get(), v8_context, "webstore"); 821 InstallBindings(module_system.get(), v8_context, "webstore");
822
823 // TODO: Move this back down to next case.
not at google - send to devlin 2012/12/13 22:26:40 Why is it up here?
cduvall 2012/12/14 00:25:18 Just so I could make sure everything was working.
824 RegisterSchemaGeneratedBindings(module_system.get(),
825 context,
826 v8_context,
827 context_type);
784 break; 828 break;
785
786 case Feature::BLESSED_EXTENSION_CONTEXT: 829 case Feature::BLESSED_EXTENSION_CONTEXT:
787 case Feature::UNBLESSED_EXTENSION_CONTEXT: 830 case Feature::UNBLESSED_EXTENSION_CONTEXT:
788 case Feature::CONTENT_SCRIPT_CONTEXT: { 831 case Feature::CONTENT_SCRIPT_CONTEXT: {
789 CHECK(extension); 832 CHECK(extension);
790 if (!extension->is_platform_app()) 833 if (!extension->is_platform_app())
791 module_system->Require("miscellaneous_bindings"); 834 module_system->Require("miscellaneous_bindings");
792 module_system->Require("schema_generated_bindings"); 835 // module_system->Require("schema_generated_bindings");
793 module_system->Require("apitest"); 836 module_system->Require("apitest");
794 837
795 // TODO(kalman): move this code back out of the switch and execute it 838 // TODO(kalman): move this code back out of the switch and execute it
796 // regardless of |context_type|. ExtensionAPI knows how to return the 839 // 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 840 // correct APIs, however, until it doesn't have a 2MB overhead we can't
798 // load it in every process. 841 // 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; 842 break;
806 } 843 }
807 } 844 }
808 845
809 // Inject custom JS into the platform app context. 846 // Inject custom JS into the platform app context.
810 if (IsWithinPlatformApp(frame)) 847 if (IsWithinPlatformApp(frame))
811 module_system->Require("platformApp"); 848 module_system->Require("platformApp");
812 849
813 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 850 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
814 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); 851 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1169 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1133 v8::ThrowException( 1170 v8::ThrowException(
1134 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1171 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1135 return false; 1172 return false;
1136 } 1173 }
1137 1174
1138 return true; 1175 return true;
1139 } 1176 }
1140 1177
1141 } // namespace extensions 1178 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698