• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "gin/modules/module_runner_delegate.h"
6 
7 #include "gin/modules/module_registry.h"
8 
9 namespace gin {
10 
ModuleRunnerDelegate(const std::vector<base::FilePath> & search_paths)11 ModuleRunnerDelegate::ModuleRunnerDelegate(
12   const std::vector<base::FilePath>& search_paths)
13     : module_provider_(search_paths) {
14 }
15 
~ModuleRunnerDelegate()16 ModuleRunnerDelegate::~ModuleRunnerDelegate() {
17 }
18 
AddBuiltinModule(const std::string & id,ModuleTemplateGetter templ)19 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
20                                             ModuleTemplateGetter templ) {
21   builtin_modules_[id] = templ;
22 }
23 
AttemptToLoadMoreModules(Runner * runner)24 void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) {
25   ModuleRegistry* registry = ModuleRegistry::From(runner->context());
26   registry->AttemptToLoadMoreModules(runner->isolate());
27   module_provider_.AttempToLoadModules(
28       runner, registry->unsatisfied_dependencies());
29 }
30 
GetGlobalTemplate(Runner * runner)31 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate(
32     Runner* runner) {
33   v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
34   ModuleRegistry::RegisterGlobals(runner->isolate(), templ);
35   return templ;
36 }
37 
DidCreateContext(Runner * runner)38 void ModuleRunnerDelegate::DidCreateContext(Runner* runner) {
39   RunnerDelegate::DidCreateContext(runner);
40 
41   v8::Handle<v8::Context> context = runner->context();
42   ModuleRegistry* registry = ModuleRegistry::From(context);
43 
44   for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin();
45        it != builtin_modules_.end(); ++it) {
46     registry->AddBuiltinModule(runner->isolate(), it->first,
47                                it->second(runner->isolate()));
48   }
49 }
50 
DidRunScript(Runner * runner)51 void ModuleRunnerDelegate::DidRunScript(Runner* runner) {
52   AttemptToLoadMoreModules(runner);
53 }
54 
55 }  // namespace gin
56