| 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/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 std::vector<std::string> components; | 112 std::vector<std::string> components; |
| 113 for (int i = 0; i < args.Length(); ++i) | 113 for (int i = 0; i < args.Length(); ++i) |
| 114 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 114 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
| 115 | 115 |
| 116 LOG(ERROR) << JoinString(components, ','); | 116 LOG(ERROR) << JoinString(components, ','); |
| 117 return v8::Undefined(); | 117 return v8::Undefined(); |
| 118 } | 118 } |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 void InstallAppBindings(ModuleSystem* module_system, |
| 122 v8::Handle<v8::Object> chrome, |
| 123 v8::Handle<v8::Object> chrome_hidden) { |
| 124 module_system->SetLazyField(chrome, "app", "app", "chromeApp"); |
| 125 module_system->SetLazyField(chrome, "appNotifications", "app", |
| 126 "chromeAppNotifications"); |
| 127 module_system->SetLazyField(chrome_hidden, "app", "app", |
| 128 "chromeHiddenApp"); |
| 129 } |
| 130 |
| 131 void InstallWebstoreBindings(ModuleSystem* module_system, |
| 132 v8::Handle<v8::Object> chrome, |
| 133 v8::Handle<v8::Object> chrome_hidden) { |
| 134 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); |
| 135 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", |
| 136 "chromeHiddenWebstore"); |
| 137 } |
| 138 |
| 121 } | 139 } |
| 122 | 140 |
| 123 ExtensionDispatcher::ExtensionDispatcher() | 141 ExtensionDispatcher::ExtensionDispatcher() |
| 124 : is_webkit_initialized_(false), | 142 : is_webkit_initialized_(false), |
| 125 webrequest_adblock_(false), | 143 webrequest_adblock_(false), |
| 126 webrequest_adblock_plus_(false), | 144 webrequest_adblock_plus_(false), |
| 127 webrequest_other_(false), | 145 webrequest_other_(false), |
| 128 source_map_(&ResourceBundle::GetSharedInstance()) { | 146 source_map_(&ResourceBundle::GetSharedInstance()) { |
| 129 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 147 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
| 130 is_extension_process_ = | 148 is_extension_process_ = |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 471 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
| 454 | 472 |
| 455 Feature::Context context_type = | 473 Feature::Context context_type = |
| 456 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | 474 ClassifyJavaScriptContext(extension_id, extension_group, url_info); |
| 457 | 475 |
| 458 ChromeV8Context* context = | 476 ChromeV8Context* context = |
| 459 new ChromeV8Context(v8_context, frame, extension_id, context_type); | 477 new ChromeV8Context(v8_context, frame, extension_id, context_type); |
| 460 v8_context_set_.Add(context); | 478 v8_context_set_.Add(context); |
| 461 | 479 |
| 462 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_)); | 480 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_)); |
| 481 // Enable natives in startup. |
| 482 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
| 483 |
| 463 RegisterNativeHandlers(module_system.get(), context); | 484 RegisterNativeHandlers(module_system.get(), context); |
| 464 | 485 |
| 465 module_system->RegisterNativeHandler("chrome_hidden", | 486 module_system->RegisterNativeHandler("chrome_hidden", |
| 466 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 487 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
| 467 module_system->RegisterNativeHandler("print", | 488 module_system->RegisterNativeHandler("print", |
| 468 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 489 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
| 469 | 490 |
| 470 int manifest_version = 1; | 491 int manifest_version = 1; |
| 471 if (extension) | 492 if (extension) |
| 472 manifest_version = extension->manifest_version(); | 493 manifest_version = extension->manifest_version(); |
| 473 | 494 |
| 495 typedef void (*BindingInstaller)(ModuleSystem* module_system, |
| 496 v8::Handle<v8::Object> chrome, |
| 497 v8::Handle<v8::Object> chrome_hidden); |
| 498 std::map<std::string, BindingInstaller> lazy_bindings; |
| 499 lazy_bindings["app"] = InstallAppBindings; |
| 500 lazy_bindings["webstore"] = InstallWebstoreBindings; |
| 501 |
| 474 // Create the 'chrome' variable if it doesn't already exist. | 502 // Create the 'chrome' variable if it doesn't already exist. |
| 475 { | 503 { |
| 476 v8::HandleScope handle_scope; | 504 v8::HandleScope handle_scope; |
| 477 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | 505 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); |
| 478 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); | 506 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
| 479 if (global->Get(chrome_string)->IsUndefined()) | 507 if (global->Get(chrome_string)->IsUndefined()) |
| 480 global->Set(chrome_string, v8::Object::New()); | 508 global->Set(chrome_string, v8::Object::New()); |
| 481 } | 509 } |
| 482 | 510 |
| 483 // Loading JavaScript is expensive, so only run the full API bindings | 511 // Loading JavaScript is expensive, so only run the full API bindings |
| (...skipping 22 matching lines...) Expand all Loading... |
| 506 // to write. We really need to factor things differently to delete the | 534 // to write. We really need to factor things differently to delete the |
| 507 // concept of a test extension ID. | 535 // concept of a test extension ID. |
| 508 if (IsTestExtensionId(extension_id)) { | 536 if (IsTestExtensionId(extension_id)) { |
| 509 module_system->Require("miscellaneous_bindings"); | 537 module_system->Require("miscellaneous_bindings"); |
| 510 module_system->Require("schema_generated_bindings"); | 538 module_system->Require("schema_generated_bindings"); |
| 511 apis->insert("extension"); | 539 apis->insert("extension"); |
| 512 } | 540 } |
| 513 | 541 |
| 514 for (std::set<std::string>::iterator i = apis->begin(); i != apis->end(); | 542 for (std::set<std::string>::iterator i = apis->begin(); i != apis->end(); |
| 515 ++i) { | 543 ++i) { |
| 516 module_system->Require(*i); | 544 std::map<std::string, BindingInstaller>::const_iterator lazy_binding = |
| 545 lazy_bindings.find(*i); |
| 546 if (lazy_binding != lazy_bindings.end()) { |
| 547 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
| 548 v8::Handle<v8::Object> chrome = |
| 549 global->Get(v8::String::New("chrome"))->ToObject(); |
| 550 v8::Handle<v8::Object> chrome_hidden = |
| 551 ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject(); |
| 552 (*lazy_binding->second)(module_system.get(), chrome, chrome_hidden); |
| 553 } else { |
| 554 module_system->Require(*i); |
| 555 } |
| 517 } | 556 } |
| 518 | 557 |
| 519 module_system->set_natives_enabled(false); | |
| 520 | |
| 521 context->set_module_system(module_system.Pass()); | 558 context->set_module_system(module_system.Pass()); |
| 522 | 559 |
| 523 context->DispatchOnLoadEvent( | 560 context->DispatchOnLoadEvent( |
| 524 is_extension_process_, | 561 is_extension_process_, |
| 525 ChromeRenderProcessObserver::is_incognito_process(), | 562 ChromeRenderProcessObserver::is_incognito_process(), |
| 526 manifest_version); | 563 manifest_version); |
| 527 | 564 |
| 528 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 565 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 529 } | 566 } |
| 530 | 567 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 return Feature::BLESSED_EXTENSION_CONTEXT; | 739 return Feature::BLESSED_EXTENSION_CONTEXT; |
| 703 | 740 |
| 704 if (extensions_.ExtensionBindingsAllowed(url_info)) | 741 if (extensions_.ExtensionBindingsAllowed(url_info)) |
| 705 return Feature::UNBLESSED_EXTENSION_CONTEXT; | 742 return Feature::UNBLESSED_EXTENSION_CONTEXT; |
| 706 | 743 |
| 707 if (url_info.url().is_valid()) | 744 if (url_info.url().is_valid()) |
| 708 return Feature::WEB_PAGE_CONTEXT; | 745 return Feature::WEB_PAGE_CONTEXT; |
| 709 | 746 |
| 710 return Feature::UNSPECIFIED_CONTEXT; | 747 return Feature::UNSPECIFIED_CONTEXT; |
| 711 } | 748 } |
| OLD | NEW |