Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: gin/modules/module_runner_delegate.cc

Issue 467263006: JavaScript Content Handler Version 0.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "gin/modules/module_runner_delegate.h" 5 #include "gin/modules/module_runner_delegate.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "gin/modules/module_registry.h" 9 #include "gin/modules/module_registry.h"
8 #include "gin/object_template_builder.h" 10 #include "gin/object_template_builder.h"
9 #include "gin/public/context_holder.h" 11 #include "gin/public/context_holder.h"
10 12
11 namespace gin { 13 namespace gin {
12 14
13 ModuleRunnerDelegate::ModuleRunnerDelegate( 15 ModuleRunnerDelegate::ModuleRunnerDelegate(
14 const std::vector<base::FilePath>& search_paths) 16 const std::vector<base::FilePath>& search_paths)
15 : module_provider_(search_paths) { 17 : module_provider_(search_paths) {
16 } 18 }
17 19
18 ModuleRunnerDelegate::~ModuleRunnerDelegate() { 20 ModuleRunnerDelegate::~ModuleRunnerDelegate() {
19 } 21 }
20 22
21 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id, 23 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
22 ModuleGetter getter) { 24 ModuleGetter getter) {
25 builtin_modules_[id] = base::Bind(getter);
26 }
27
28 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
29 const ModuleGetterCallback& getter) {
23 builtin_modules_[id] = getter; 30 builtin_modules_[id] = getter;
24 } 31 }
25 32
26 void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) { 33 void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) {
27 ModuleRegistry* registry = ModuleRegistry::From( 34 ModuleRegistry* registry = ModuleRegistry::From(
28 runner->GetContextHolder()->context()); 35 runner->GetContextHolder()->context());
29 registry->AttemptToLoadMoreModules(runner->GetContextHolder()->isolate()); 36 registry->AttemptToLoadMoreModules(runner->GetContextHolder()->isolate());
30 module_provider_.AttempToLoadModules( 37 module_provider_.AttempToLoadModules(
31 runner, registry->unsatisfied_dependencies()); 38 runner, registry->unsatisfied_dependencies());
32 } 39 }
33 40
34 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate( 41 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate(
35 ShellRunner* runner, 42 ShellRunner* runner,
36 v8::Isolate* isolate) { 43 v8::Isolate* isolate) {
37 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate).Build(); 44 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate).Build();
38 ModuleRegistry::RegisterGlobals(isolate, templ); 45 ModuleRegistry::RegisterGlobals(isolate, templ);
39 return templ; 46 return templ;
40 } 47 }
41 48
42 void ModuleRunnerDelegate::DidCreateContext(ShellRunner* runner) { 49 void ModuleRunnerDelegate::DidCreateContext(ShellRunner* runner) {
43 ShellRunnerDelegate::DidCreateContext(runner); 50 ShellRunnerDelegate::DidCreateContext(runner);
44 51
45 v8::Handle<v8::Context> context = runner->GetContextHolder()->context(); 52 v8::Handle<v8::Context> context = runner->GetContextHolder()->context();
46 ModuleRegistry* registry = ModuleRegistry::From(context); 53 ModuleRegistry* registry = ModuleRegistry::From(context);
47 54
48 v8::Isolate* isolate = runner->GetContextHolder()->isolate(); 55 v8::Isolate* isolate = runner->GetContextHolder()->isolate();
56
49 for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin(); 57 for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin();
50 it != builtin_modules_.end(); ++it) { 58 it != builtin_modules_.end(); ++it) {
51 registry->AddBuiltinModule(isolate, it->first, it->second(isolate)); 59 registry->AddBuiltinModule(isolate, it->first, it->second.Run(isolate));
52 } 60 }
53 } 61 }
54 62
55 void ModuleRunnerDelegate::DidRunScript(ShellRunner* runner) { 63 void ModuleRunnerDelegate::DidRunScript(ShellRunner* runner) {
56 AttemptToLoadMoreModules(runner); 64 AttemptToLoadMoreModules(runner);
57 } 65 }
58 66
59 } // namespace gin 67 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698