From b2cf607c2035b942e36ceed49cc770cf15fb1db2 Mon Sep 17 00:00:00 2001 From: hansmuller Date: Fri, 12 Sep 2014 11:53:57 -0700 Subject: JavaScript Content Handler Version 0.0 BUG=403645 Review URL: https://codereview.chromium.org/467263006 Cr-Commit-Position: refs/heads/master@{#294621} --- gin/modules/module_runner_delegate.cc | 10 +++++++++- gin/modules/module_runner_delegate.h | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'gin') diff --git a/gin/modules/module_runner_delegate.cc b/gin/modules/module_runner_delegate.cc index 16b5afd..9d8ce2e 100644 --- a/gin/modules/module_runner_delegate.cc +++ b/gin/modules/module_runner_delegate.cc @@ -4,6 +4,8 @@ #include "gin/modules/module_runner_delegate.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "gin/modules/module_registry.h" #include "gin/object_template_builder.h" #include "gin/public/context_holder.h" @@ -20,6 +22,11 @@ ModuleRunnerDelegate::~ModuleRunnerDelegate() { void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id, ModuleGetter getter) { + builtin_modules_[id] = base::Bind(getter); +} + +void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id, + const ModuleGetterCallback& getter) { builtin_modules_[id] = getter; } @@ -46,9 +53,10 @@ void ModuleRunnerDelegate::DidCreateContext(ShellRunner* runner) { ModuleRegistry* registry = ModuleRegistry::From(context); v8::Isolate* isolate = runner->GetContextHolder()->isolate(); + for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin(); it != builtin_modules_.end(); ++it) { - registry->AddBuiltinModule(isolate, it->first, it->second(isolate)); + registry->AddBuiltinModule(isolate, it->first, it->second.Run(isolate)); } } diff --git a/gin/modules/module_runner_delegate.h b/gin/modules/module_runner_delegate.h index 09d4582..df91f63 100644 --- a/gin/modules/module_runner_delegate.h +++ b/gin/modules/module_runner_delegate.h @@ -7,14 +7,17 @@ #include +#include "base/callback.h" #include "base/compiler_specific.h" #include "gin/gin_export.h" #include "gin/modules/file_module_provider.h" #include "gin/shell_runner.h" +#include "v8/include/v8.h" namespace gin { typedef v8::Local (*ModuleGetter)(v8::Isolate* isolate); +typedef base::Callback(v8::Isolate*)> ModuleGetterCallback; // Emebedders that use AMD modules will probably want to use a RunnerDelegate // that inherits from ModuleRunnerDelegate. ModuleRunnerDelegate lets embedders @@ -26,12 +29,14 @@ class GIN_EXPORT ModuleRunnerDelegate : public ShellRunnerDelegate { virtual ~ModuleRunnerDelegate(); void AddBuiltinModule(const std::string& id, ModuleGetter getter); + void AddBuiltinModule(const std::string& id, + const ModuleGetterCallback& getter); protected: void AttemptToLoadMoreModules(Runner* runner); private: - typedef std::map BuiltinModuleMap; + typedef std::map BuiltinModuleMap; // From ShellRunnerDelegate: virtual v8::Handle GetGlobalTemplate( -- cgit v1.1