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 18 matching lines...) Expand all Loading... | |
29 #include "chrome/renderer/extensions/extension_custom_bindings.h" | 29 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
30 #include "chrome/renderer/extensions/extension_groups.h" | 30 #include "chrome/renderer/extensions/extension_groups.h" |
31 #include "chrome/renderer/extensions/extension_helper.h" | 31 #include "chrome/renderer/extensions/extension_helper.h" |
32 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 32 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
33 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 33 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
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/object_backed_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 26 matching lines...) Expand all Loading... | |
80 namespace extensions { | 81 namespace extensions { |
81 | 82 |
82 namespace { | 83 namespace { |
83 | 84 |
84 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 85 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
85 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 86 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
86 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; | 87 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; |
87 static const char kOnUnloadEvent[] = "runtime.onSuspend"; | 88 static const char kOnUnloadEvent[] = "runtime.onSuspend"; |
88 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 89 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
89 | 90 |
90 class ChromeHiddenNativeHandler : public NativeHandler { | 91 static v8::Handle<v8::Object> GetOrCreateChrome( |
92 v8::Handle<v8::Context> context) { | |
93 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
94 v8::Handle<v8::Object> global(context->Global()); | |
95 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
96 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
97 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
98 global->Set(chrome_string, chrome_object); | |
99 return chrome_object; | |
100 } | |
101 CHECK(chrome->IsObject()); | |
102 return chrome->ToObject(); | |
103 } | |
104 | |
105 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { | |
106 public: | |
107 SchemaRegistryNativeHandler(V8SchemaRegistry* registry) | |
108 : registry_(registry) { | |
109 RouteFunction("GetSchema", | |
110 base::Bind(&SchemaRegistryNativeHandler::GetSchema, | |
111 base::Unretained(this))); | |
112 } | |
113 | |
114 private: | |
115 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) { | |
116 return registry_->GetSchema(*v8::String::AsciiValue(args[0])); | |
117 } | |
118 | |
119 V8SchemaRegistry* registry_; | |
120 }; | |
121 | |
122 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler { | |
91 public: | 123 public: |
92 ChromeHiddenNativeHandler() { | 124 ChromeHiddenNativeHandler() { |
93 RouteFunction("GetChromeHidden", | 125 RouteFunction("GetChromeHidden", |
94 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 126 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
95 base::Unretained(this))); | 127 base::Unretained(this))); |
96 } | 128 } |
97 | 129 |
98 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 130 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
99 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); | 131 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); |
100 } | 132 } |
101 }; | 133 }; |
102 | 134 |
103 class PrintNativeHandler : public NativeHandler { | 135 class ChromeNativeHandler : public ObjectBackedNativeHandler { |
136 public: | |
137 ChromeNativeHandler() { | |
138 RouteFunction("GetChrome", | |
139 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); | |
140 } | |
141 | |
142 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) { | |
143 return GetOrCreateChrome(v8::Context::GetCurrent()); | |
144 } | |
145 }; | |
146 | |
147 class PrintNativeHandler : public ObjectBackedNativeHandler { | |
104 public: | 148 public: |
105 PrintNativeHandler() { | 149 PrintNativeHandler() { |
106 RouteFunction("Print", | 150 RouteFunction("Print", |
107 base::Bind(&PrintNativeHandler::Print, | 151 base::Bind(&PrintNativeHandler::Print, |
108 base::Unretained(this))); | 152 base::Unretained(this))); |
109 } | 153 } |
110 | 154 |
111 v8::Handle<v8::Value> Print(const v8::Arguments& args) { | 155 v8::Handle<v8::Value> Print(const v8::Arguments& args) { |
112 if (args.Length() < 1) | 156 if (args.Length() < 1) |
113 return v8::Undefined(); | 157 return v8::Undefined(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 } | 271 } |
228 | 272 |
229 private: | 273 private: |
230 std::string extension_id_; | 274 std::string extension_id_; |
231 std::string context_type_; | 275 std::string context_type_; |
232 bool is_incognito_context_; | 276 bool is_incognito_context_; |
233 int manifest_version_; | 277 int manifest_version_; |
234 bool send_request_disabled_; | 278 bool send_request_disabled_; |
235 }; | 279 }; |
236 | 280 |
237 class LoggingNativeHandler : public NativeHandler { | 281 class LoggingNativeHandler : public ObjectBackedNativeHandler { |
238 public: | 282 public: |
239 LoggingNativeHandler() { | 283 LoggingNativeHandler() { |
240 RouteFunction("DCHECK", | 284 RouteFunction("DCHECK", |
241 base::Bind(&LoggingNativeHandler::Dcheck, | 285 base::Bind(&LoggingNativeHandler::Dcheck, |
242 base::Unretained(this))); | 286 base::Unretained(this))); |
243 } | 287 } |
244 | 288 |
245 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { | 289 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { |
246 CHECK_LE(args.Length(), 2); | 290 CHECK_LE(args.Length(), 2); |
247 bool check_value = args[0]->BooleanValue(); | 291 bool check_value = args[0]->BooleanValue(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 } | 334 } |
291 | 335 |
292 void InstallWebstoreBindings(ModuleSystem* module_system, | 336 void InstallWebstoreBindings(ModuleSystem* module_system, |
293 v8::Handle<v8::Object> chrome, | 337 v8::Handle<v8::Object> chrome, |
294 v8::Handle<v8::Object> chrome_hidden) { | 338 v8::Handle<v8::Object> chrome_hidden) { |
295 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); | 339 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); |
296 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", | 340 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", |
297 "chromeHiddenWebstore"); | 341 "chromeHiddenWebstore"); |
298 } | 342 } |
299 | 343 |
300 static v8::Handle<v8::Object> GetOrCreateChrome( | |
301 v8::Handle<v8::Context> context) { | |
302 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
303 v8::Handle<v8::Object> global(context->Global()); | |
304 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
305 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
306 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
307 global->Set(chrome_string, chrome_object); | |
308 return chrome_object; | |
309 } | |
310 CHECK(chrome->IsObject()); | |
311 return chrome->ToObject(); | |
312 } | |
313 | |
314 } // namespace | 344 } // namespace |
315 | 345 |
316 Dispatcher::Dispatcher() | 346 Dispatcher::Dispatcher() |
317 : is_webkit_initialized_(false), | 347 : is_webkit_initialized_(false), |
318 webrequest_adblock_(false), | 348 webrequest_adblock_(false), |
319 webrequest_adblock_plus_(false), | 349 webrequest_adblock_plus_(false), |
320 webrequest_other_(false), | 350 webrequest_other_(false), |
321 source_map_(&ResourceBundle::GetSharedInstance()) { | 351 source_map_(&ResourceBundle::GetSharedInstance()) { |
322 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 352 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
323 is_extension_process_ = | 353 is_extension_process_ = |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 } // namespace | 575 } // namespace |
546 | 576 |
547 bool Dispatcher::AllowScriptExtension(WebFrame* frame, | 577 bool Dispatcher::AllowScriptExtension(WebFrame* frame, |
548 const std::string& v8_extension_name, | 578 const std::string& v8_extension_name, |
549 int extension_group, | 579 int extension_group, |
550 int world_id) { | 580 int world_id) { |
551 g_hack_extension_group = extension_group; | 581 g_hack_extension_group = extension_group; |
552 return true; | 582 return true; |
553 } | 583 } |
554 | 584 |
585 void Dispatcher::SetUpChainedField(v8::Handle<v8::Object> object, | |
586 const std::string& field, | |
587 const std::string& module_name, | |
588 const std::string& module_field, | |
589 ModuleSystem* module_system, | |
590 LazyFieldSetter setter) { | |
591 // TODO(cduvall): Set up object chain. | |
592 (module_system->*setter)(object, field, module_name, module_field); | |
593 } | |
594 | |
595 | |
not at google - send to devlin
2013/01/24 21:10:12
extra \n
cduvall
2013/01/24 22:15:15
Done.
| |
596 void Dispatcher::RegisterSchemaGeneratedBindings( | |
597 ModuleSystem* module_system, | |
598 ChromeV8Context* context, | |
599 v8::Handle<v8::Context> v8_context) { | |
600 std::set<std::string> apis = | |
601 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | |
602 for (std::set<std::string>::iterator it = apis.begin(); | |
603 it != apis.end(); ++it) { | |
604 const std::string& api_name = *it; | |
605 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { | |
606 InstallBindings(module_system, v8_context, api_name); | |
607 // If there isn't already a custom binding for this API, we need to make | |
608 // sure one exists to load the schema. Otherwise the custom binding will | |
609 // need to do it itself. Either way, register it on the chrome object to be | |
610 // loaded lazily. | |
611 } else if (!source_map_.Contains(api_name)) { | |
612 module_system->RegisterNativeHandler( | |
613 api_name, | |
614 scoped_ptr<NativeHandler>(new SchemaGeneratedNativeHandler( | |
615 module_system, | |
616 v8_schema_registry(), | |
617 api_name, | |
618 "bindings"))); | |
619 SetUpChainedField(GetOrCreateChrome(v8_context), | |
620 api_name, | |
621 api_name, | |
622 "bindings", | |
623 module_system, | |
624 &ModuleSystem::SetNativeLazyField); | |
625 } else { | |
626 // TODO(cduvall): Handle apitest. | |
not at google - send to devlin
2013/01/24 21:10:12
Would it help to re-implement apitest.js as a cust
cduvall
2013/01/24 22:15:15
That sounds like a good idea. I don't really like
| |
627 SetUpChainedField(GetOrCreateChrome(v8_context), | |
628 api_name, | |
629 api_name, | |
630 "bindings", | |
631 module_system, | |
632 &ModuleSystem::SetLazyField); | |
633 } | |
634 } | |
635 module_system->SetLazyField(GetOrCreateChrome(v8_context), | |
636 "Event", | |
637 "event_bindings", | |
638 "bindings"); | |
639 module_system->SetLazyField(GetOrCreateChrome(v8_context), | |
640 "test", | |
641 "apitest", | |
642 "bindings"); | |
643 } | |
644 | |
555 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 645 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
556 ChromeV8Context* context) { | 646 ChromeV8Context* context) { |
557 module_system->RegisterNativeHandler("event_bindings", | 647 module_system->RegisterNativeHandler("event_bindings", |
558 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 648 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
559 module_system->RegisterNativeHandler("miscellaneous_bindings", | 649 module_system->RegisterNativeHandler("miscellaneous_bindings", |
560 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 650 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
561 module_system->RegisterNativeHandler("apiDefinitions", | 651 module_system->RegisterNativeHandler("apiDefinitions", |
562 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 652 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); |
563 module_system->RegisterNativeHandler("sendRequest", | 653 module_system->RegisterNativeHandler("sendRequest", |
564 scoped_ptr<NativeHandler>( | 654 scoped_ptr<NativeHandler>( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); | 761 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); |
672 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); | 762 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); |
673 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 763 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
674 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 764 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
675 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 765 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
676 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 766 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
677 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 767 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
678 source_map_.RegisterSource("webRequestInternal", | 768 source_map_.RegisterSource("webRequestInternal", |
679 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 769 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
680 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 770 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
771 source_map_.RegisterSource("schema_binding_generator", | |
772 IDR_SCHEMA_BINDING_GENERATOR_JS); | |
681 | 773 |
682 // Platform app sources that are not API-specific.. | 774 // Platform app sources that are not API-specific.. |
683 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); | 775 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); |
684 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); | 776 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); |
685 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); | 777 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); |
686 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 778 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
687 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); | 779 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); |
688 } | 780 } |
689 | 781 |
690 void Dispatcher::PopulateLazyBindingsMap() { | 782 void Dispatcher::PopulateLazyBindingsMap() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 new ChromeV8Context(v8_context, frame, extension, context_type); | 839 new ChromeV8Context(v8_context, frame, extension, context_type); |
748 v8_context_set_.Add(context); | 840 v8_context_set_.Add(context); |
749 | 841 |
750 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 842 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, |
751 &source_map_)); | 843 &source_map_)); |
752 // Enable natives in startup. | 844 // Enable natives in startup. |
753 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 845 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
754 | 846 |
755 RegisterNativeHandlers(module_system.get(), context); | 847 RegisterNativeHandlers(module_system.get(), context); |
756 | 848 |
849 module_system->RegisterNativeHandler("chrome", | |
850 scoped_ptr<NativeHandler>(new ChromeNativeHandler())); | |
757 module_system->RegisterNativeHandler("chrome_hidden", | 851 module_system->RegisterNativeHandler("chrome_hidden", |
758 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 852 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
759 module_system->RegisterNativeHandler("print", | 853 module_system->RegisterNativeHandler("print", |
760 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 854 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
761 module_system->RegisterNativeHandler("lazy_background_page", | 855 module_system->RegisterNativeHandler("lazy_background_page", |
762 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 856 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
763 module_system->RegisterNativeHandler("logging", | 857 module_system->RegisterNativeHandler("logging", |
764 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); | 858 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); |
859 module_system->RegisterNativeHandler("schema_registry", | |
860 scoped_ptr<NativeHandler>( | |
861 new SchemaRegistryNativeHandler(v8_schema_registry()))); | |
765 | 862 |
766 int manifest_version = extension ? extension->manifest_version() : 1; | 863 int manifest_version = extension ? extension->manifest_version() : 1; |
767 bool send_request_disabled = | 864 bool send_request_disabled = |
768 (extension && extension->location() == Extension::LOAD && | 865 (extension && extension->location() == Extension::LOAD && |
769 extension->has_lazy_background_page()); | 866 extension->has_lazy_background_page()); |
770 module_system->RegisterNativeHandler("process", | 867 module_system->RegisterNativeHandler("process", |
771 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 868 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
772 this, context->GetExtensionID(), | 869 this, context->GetExtensionID(), |
773 context->GetContextTypeDescription(), | 870 context->GetContextTypeDescription(), |
774 ChromeRenderProcessObserver::is_incognito_process(), | 871 ChromeRenderProcessObserver::is_incognito_process(), |
775 manifest_version, send_request_disabled))); | 872 manifest_version, send_request_disabled))); |
776 | 873 |
777 GetOrCreateChrome(v8_context); | 874 GetOrCreateChrome(v8_context); |
778 | 875 |
779 // Loading JavaScript is expensive, so only run the full API bindings | 876 // Loading JavaScript is expensive, so only run the full API bindings |
780 // generation mechanisms in extension pages (NOT all web pages). | 877 // generation mechanisms in extension pages (NOT all web pages). |
781 switch (context_type) { | 878 switch (context_type) { |
782 case Feature::UNSPECIFIED_CONTEXT: | 879 case Feature::UNSPECIFIED_CONTEXT: |
783 case Feature::WEB_PAGE_CONTEXT: | 880 case Feature::WEB_PAGE_CONTEXT: |
784 // TODO(kalman): see comment below about ExtensionAPI. | 881 // TODO(kalman): see comment below about ExtensionAPI. |
785 InstallBindings(module_system.get(), v8_context, "app"); | 882 InstallBindings(module_system.get(), v8_context, "app"); |
786 InstallBindings(module_system.get(), v8_context, "webstore"); | 883 InstallBindings(module_system.get(), v8_context, "webstore"); |
787 break; | 884 break; |
788 | |
789 case Feature::BLESSED_EXTENSION_CONTEXT: | 885 case Feature::BLESSED_EXTENSION_CONTEXT: |
790 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 886 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
791 case Feature::CONTENT_SCRIPT_CONTEXT: { | 887 case Feature::CONTENT_SCRIPT_CONTEXT: { |
792 module_system->Require("miscellaneous_bindings"); | 888 CHECK(extension); |
not at google - send to devlin
2013/01/24 21:10:12
IIRC there were some cases where there actually wa
cduvall
2013/01/24 22:15:15
Done.
| |
793 module_system->Require("schema_generated_bindings"); | 889 if (!extension->is_platform_app()) |
794 module_system->Require("apitest"); | 890 module_system->Require("miscellaneous_bindings"); |
891 RegisterSchemaGeneratedBindings(module_system.get(), | |
892 context, | |
893 v8_context); | |
795 | 894 |
796 // TODO(kalman): move this code back out of the switch and execute it | 895 // TODO(kalman): move this code back out of the switch and execute it |
797 // regardless of |context_type|. ExtensionAPI knows how to return the | 896 // regardless of |context_type|. ExtensionAPI knows how to return the |
798 // correct APIs, however, until it doesn't have a 2MB overhead we can't | 897 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
799 // load it in every process. | 898 // load it in every process. |
800 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); | |
801 for (std::set<std::string>::const_iterator i = apis.begin(); | |
802 i != apis.end(); ++i) { | |
803 InstallBindings(module_system.get(), v8_context, *i); | |
804 } | |
805 | |
806 break; | 899 break; |
807 } | 900 } |
808 } | 901 } |
809 | 902 |
810 // Inject custom JS into the platform app context. | 903 // Inject custom JS into the platform app context. |
811 if (IsWithinPlatformApp(frame)) | 904 if (IsWithinPlatformApp(frame)) |
812 module_system->Require("platformApp"); | 905 module_system->Require("platformApp"); |
813 | 906 |
814 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 907 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
815 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); | 908 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1226 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1134 v8::ThrowException( | 1227 v8::ThrowException( |
1135 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1228 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1136 return false; | 1229 return false; |
1137 } | 1230 } |
1138 | 1231 |
1139 return true; | 1232 return true; |
1140 } | 1233 } |
1141 | 1234 |
1142 } // namespace extensions | 1235 } // namespace extensions |
OLD | NEW |