Chromium Code Reviews| 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 size_t prev = -1, next = field.find_first_of("."); | |
| 592 std::vector<std::string> parts; | |
| 593 // TODO(cduvall): Clean up. | |
| 594 while (next != std::string::npos) { | |
| 595 parts.push_back(field.substr(prev + 1, next - prev - 1)); | |
| 596 prev = next; | |
| 597 next = field.find_first_of(".", prev + 1); | |
| 598 } | |
| 599 parts.push_back(field.substr(prev + 1)); | |
| 600 | |
| 601 v8::Handle<v8::Object> current = object; | |
| 602 for (size_t i = 0; i < parts.size() - 1; i++) { | |
| 603 v8::Handle<v8::String> key = v8::String::New(parts[i].c_str()); | |
| 604 if (current->Has(key)) { | |
| 605 current = v8::Handle<v8::Object>::Cast(current->Get(key)); | |
| 606 } else { | |
| 607 v8::Handle<v8::Object> new_object = v8::Object::New(); | |
| 608 current->Set(key, new_object); | |
| 609 current = new_object; | |
| 610 } | |
| 611 } | |
| 612 | |
| 613 (module_system->*setter)(current, parts.back(), module_name, module_field); | |
| 614 } | |
| 615 | |
| 616 void Dispatcher::RegisterSchemaGeneratedBindings( | |
| 617 ModuleSystem* module_system, | |
| 618 ChromeV8Context* context, | |
| 619 v8::Handle<v8::Context> v8_context) { | |
| 620 std::set<std::string> apis = | |
| 621 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | |
| 622 for (std::set<std::string>::iterator it = apis.begin(); | |
| 623 it != apis.end(); ++it) { | |
| 624 const std::string& api_name = *it; | |
| 625 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { | |
| 626 InstallBindings(module_system, v8_context, api_name); | |
| 627 // If there isn't already a custom binding for this API, we need to make | |
| 628 // sure one exists to load the schema. Otherwise the custom binding will | |
| 629 // need to do it itself. Either way, register it on the chrome object to be | |
| 630 // loaded lazily. | |
| 631 } else if (!source_map_.Contains(api_name)) { | |
| 632 module_system->RegisterNativeHandler( | |
| 633 api_name, | |
| 634 scoped_ptr<NativeHandler>(new SchemaGeneratedNativeHandler( | |
| 635 module_system, | |
| 636 v8_schema_registry(), | |
| 637 api_name, | |
| 638 "bindings"))); | |
| 639 SetUpChainedField(GetOrCreateChrome(v8_context), | |
| 640 api_name, | |
| 641 api_name, | |
| 642 "bindings", | |
| 643 module_system, | |
| 644 &ModuleSystem::SetNativeLazyField); | |
| 645 } else { | |
| 646 // TODO(cduvall): Handle apitest. | |
| 647 SetUpChainedField(GetOrCreateChrome(v8_context), | |
| 648 api_name, | |
| 649 api_name, | |
| 650 "bindings", | |
| 651 module_system, | |
| 652 &ModuleSystem::SetLazyField); | |
| 653 } | |
| 654 } | |
|
not at google - send to devlin
2013/01/25 00:44:31
I feel like this should look more like
const std:
cduvall
2013/02/12 02:13:47
Done.
| |
| 655 module_system->SetLazyField(GetOrCreateChrome(v8_context), | |
| 656 "Event", | |
| 657 "event_bindings", | |
|
not at google - send to devlin
2013/01/25 00:44:31
would it work to make schema_binding_generator req
cduvall
2013/02/12 02:13:47
Done.
| |
| 658 "bindings"); | |
| 659 module_system->SetLazyField(GetOrCreateChrome(v8_context), | |
|
not at google - send to devlin
2013/01/25 00:44:31
Maybe we should fix that test thing before submitt
| |
| 660 "test", | |
| 661 "apitest", | |
| 662 "bindings"); | |
| 663 } | |
| 664 | |
| 555 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 665 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 556 ChromeV8Context* context) { | 666 ChromeV8Context* context) { |
| 557 module_system->RegisterNativeHandler("event_bindings", | 667 module_system->RegisterNativeHandler("event_bindings", |
| 558 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 668 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
| 559 module_system->RegisterNativeHandler("miscellaneous_bindings", | 669 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 560 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 670 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
| 561 module_system->RegisterNativeHandler("apiDefinitions", | 671 module_system->RegisterNativeHandler("apiDefinitions", |
| 562 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 672 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); |
| 563 module_system->RegisterNativeHandler("sendRequest", | 673 module_system->RegisterNativeHandler("sendRequest", |
| 564 scoped_ptr<NativeHandler>( | 674 scoped_ptr<NativeHandler>( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); | 781 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); |
| 672 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); | 782 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); |
| 673 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 783 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
| 674 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 784 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
| 675 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 785 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
| 676 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 786 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
| 677 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 787 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
| 678 source_map_.RegisterSource("webRequestInternal", | 788 source_map_.RegisterSource("webRequestInternal", |
| 679 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 789 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
| 680 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 790 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
| 791 source_map_.RegisterSource("schema_binding_generator", | |
| 792 IDR_SCHEMA_BINDING_GENERATOR_JS); | |
| 681 | 793 |
| 682 // Platform app sources that are not API-specific.. | 794 // Platform app sources that are not API-specific.. |
| 683 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); | 795 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); |
| 684 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); | 796 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); |
| 685 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); | 797 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); |
| 686 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 798 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
| 687 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); | 799 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); |
| 688 } | 800 } |
| 689 | 801 |
| 690 void Dispatcher::PopulateLazyBindingsMap() { | 802 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); | 859 new ChromeV8Context(v8_context, frame, extension, context_type); |
| 748 v8_context_set_.Add(context); | 860 v8_context_set_.Add(context); |
| 749 | 861 |
| 750 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 862 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, |
| 751 &source_map_)); | 863 &source_map_)); |
| 752 // Enable natives in startup. | 864 // Enable natives in startup. |
| 753 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 865 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
| 754 | 866 |
| 755 RegisterNativeHandlers(module_system.get(), context); | 867 RegisterNativeHandlers(module_system.get(), context); |
| 756 | 868 |
| 869 module_system->RegisterNativeHandler("chrome", | |
| 870 scoped_ptr<NativeHandler>(new ChromeNativeHandler())); | |
| 757 module_system->RegisterNativeHandler("chrome_hidden", | 871 module_system->RegisterNativeHandler("chrome_hidden", |
| 758 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 872 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
| 759 module_system->RegisterNativeHandler("print", | 873 module_system->RegisterNativeHandler("print", |
| 760 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 874 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
| 761 module_system->RegisterNativeHandler("lazy_background_page", | 875 module_system->RegisterNativeHandler("lazy_background_page", |
| 762 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 876 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
| 763 module_system->RegisterNativeHandler("logging", | 877 module_system->RegisterNativeHandler("logging", |
| 764 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); | 878 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); |
| 879 module_system->RegisterNativeHandler("schema_registry", | |
| 880 scoped_ptr<NativeHandler>( | |
| 881 new SchemaRegistryNativeHandler(v8_schema_registry()))); | |
| 765 | 882 |
| 766 int manifest_version = extension ? extension->manifest_version() : 1; | 883 int manifest_version = extension ? extension->manifest_version() : 1; |
| 767 bool send_request_disabled = | 884 bool send_request_disabled = |
| 768 (extension && extension->location() == Extension::LOAD && | 885 (extension && extension->location() == Extension::LOAD && |
| 769 extension->has_lazy_background_page()); | 886 extension->has_lazy_background_page()); |
| 770 module_system->RegisterNativeHandler("process", | 887 module_system->RegisterNativeHandler("process", |
| 771 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 888 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 772 this, context->GetExtensionID(), | 889 this, context->GetExtensionID(), |
| 773 context->GetContextTypeDescription(), | 890 context->GetContextTypeDescription(), |
| 774 ChromeRenderProcessObserver::is_incognito_process(), | 891 ChromeRenderProcessObserver::is_incognito_process(), |
| 775 manifest_version, send_request_disabled))); | 892 manifest_version, send_request_disabled))); |
| 776 | 893 |
| 777 GetOrCreateChrome(v8_context); | 894 GetOrCreateChrome(v8_context); |
| 778 | 895 |
| 779 // Loading JavaScript is expensive, so only run the full API bindings | 896 // Loading JavaScript is expensive, so only run the full API bindings |
| 780 // generation mechanisms in extension pages (NOT all web pages). | 897 // generation mechanisms in extension pages (NOT all web pages). |
| 781 switch (context_type) { | 898 switch (context_type) { |
| 782 case Feature::UNSPECIFIED_CONTEXT: | 899 case Feature::UNSPECIFIED_CONTEXT: |
| 783 case Feature::WEB_PAGE_CONTEXT: | 900 case Feature::WEB_PAGE_CONTEXT: |
| 784 // TODO(kalman): see comment below about ExtensionAPI. | 901 // TODO(kalman): see comment below about ExtensionAPI. |
| 785 InstallBindings(module_system.get(), v8_context, "app"); | 902 InstallBindings(module_system.get(), v8_context, "app"); |
| 786 InstallBindings(module_system.get(), v8_context, "webstore"); | 903 InstallBindings(module_system.get(), v8_context, "webstore"); |
| 787 break; | 904 break; |
| 788 | |
| 789 case Feature::BLESSED_EXTENSION_CONTEXT: | 905 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 790 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 906 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| 791 case Feature::CONTENT_SCRIPT_CONTEXT: { | 907 case Feature::CONTENT_SCRIPT_CONTEXT: { |
| 792 module_system->Require("miscellaneous_bindings"); | 908 if (extension && !extension->is_platform_app()) |
| 793 module_system->Require("schema_generated_bindings"); | 909 module_system->Require("miscellaneous_bindings"); |
| 794 module_system->Require("apitest"); | 910 RegisterSchemaGeneratedBindings(module_system.get(), |
| 911 context, | |
| 912 v8_context); | |
| 795 | 913 |
| 796 // TODO(kalman): move this code back out of the switch and execute it | 914 // TODO(kalman): move this code back out of the switch and execute it |
| 797 // regardless of |context_type|. ExtensionAPI knows how to return the | 915 // 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 | 916 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
| 799 // load it in every process. | 917 // 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; | 918 break; |
| 807 } | 919 } |
| 808 } | 920 } |
| 809 | 921 |
| 810 // Inject custom JS into the platform app context. | 922 // Inject custom JS into the platform app context. |
| 811 if (IsWithinPlatformApp(frame)) | 923 if (IsWithinPlatformApp(frame)) |
| 812 module_system->Require("platformApp"); | 924 module_system->Require("platformApp"); |
| 813 | 925 |
| 814 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 926 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 815 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); | 927 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()); | 1245 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1134 v8::ThrowException( | 1246 v8::ThrowException( |
| 1135 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1247 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1136 return false; | 1248 return false; |
| 1137 } | 1249 } |
| 1138 | 1250 |
| 1139 return true; | 1251 return true; |
| 1140 } | 1252 } |
| 1141 | 1253 |
| 1142 } // namespace extensions | 1254 } // namespace extensions |
| OLD | NEW |