| Index: chrome/renderer/extensions/extension_dispatcher.cc
|
| diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
|
| index 1833d64cfa85c23499ccefccec4af4b16bba2fd4..324e93e5c50792370fad2a3bc2d98b07edec22ad 100644
|
| --- a/chrome/renderer/extensions/extension_dispatcher.cc
|
| +++ b/chrome/renderer/extensions/extension_dispatcher.cc
|
| @@ -118,6 +118,24 @@ class PrintNativeHandler : public NativeHandler {
|
| }
|
| };
|
|
|
| +void InstallAppBindings(ModuleSystem* module_system,
|
| + v8::Handle<v8::Object> chrome,
|
| + v8::Handle<v8::Object> chrome_hidden) {
|
| + module_system->SetLazyField(chrome, "app", "app", "chromeApp");
|
| + module_system->SetLazyField(chrome, "appNotifications", "app",
|
| + "chromeAppNotifications");
|
| + module_system->SetLazyField(chrome_hidden, "app", "app",
|
| + "chromeHiddenApp");
|
| +}
|
| +
|
| +void InstallWebstoreBindings(ModuleSystem* module_system,
|
| + v8::Handle<v8::Object> chrome,
|
| + v8::Handle<v8::Object> chrome_hidden) {
|
| + module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore");
|
| + module_system->SetLazyField(chrome_hidden, "webstore", "webstore",
|
| + "chromeHiddenWebstore");
|
| +}
|
| +
|
| }
|
|
|
| ExtensionDispatcher::ExtensionDispatcher()
|
| @@ -460,6 +478,9 @@ void ExtensionDispatcher::DidCreateScriptContext(
|
| v8_context_set_.Add(context);
|
|
|
| scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_));
|
| + // Enable natives in startup.
|
| + ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get());
|
| +
|
| RegisterNativeHandlers(module_system.get(), context);
|
|
|
| module_system->RegisterNativeHandler("chrome_hidden",
|
| @@ -471,6 +492,13 @@ void ExtensionDispatcher::DidCreateScriptContext(
|
| if (extension)
|
| manifest_version = extension->manifest_version();
|
|
|
| + typedef void (*BindingInstaller)(ModuleSystem* module_system,
|
| + v8::Handle<v8::Object> chrome,
|
| + v8::Handle<v8::Object> chrome_hidden);
|
| + std::map<std::string, BindingInstaller> lazy_bindings;
|
| + lazy_bindings["app"] = InstallAppBindings;
|
| + lazy_bindings["webstore"] = InstallWebstoreBindings;
|
| +
|
| // Create the 'chrome' variable if it doesn't already exist.
|
| {
|
| v8::HandleScope handle_scope;
|
| @@ -513,11 +541,20 @@ void ExtensionDispatcher::DidCreateScriptContext(
|
|
|
| for (std::set<std::string>::iterator i = apis->begin(); i != apis->end();
|
| ++i) {
|
| - module_system->Require(*i);
|
| + std::map<std::string, BindingInstaller>::const_iterator lazy_binding =
|
| + lazy_bindings.find(*i);
|
| + if (lazy_binding != lazy_bindings.end()) {
|
| + v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
|
| + v8::Handle<v8::Object> chrome =
|
| + global->Get(v8::String::New("chrome"))->ToObject();
|
| + v8::Handle<v8::Object> chrome_hidden =
|
| + ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject();
|
| + (*lazy_binding->second)(module_system.get(), chrome, chrome_hidden);
|
| + } else {
|
| + module_system->Require(*i);
|
| + }
|
| }
|
|
|
| - module_system->set_natives_enabled(false);
|
| -
|
| context->set_module_system(module_system.Pass());
|
|
|
| context->DispatchOnLoadEvent(
|
|
|