Refactor microphone/camera permission requests
[chromium-blink-merge.git] / gin / modules / module_runner_delegate.cc
blobce969a097b4c0e8e72dbdf40814e9a679cd8ff4f
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.
5 #include "gin/modules/module_runner_delegate.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "gin/modules/module_registry.h"
10 #include "gin/object_template_builder.h"
11 #include "gin/public/context_holder.h"
13 namespace gin {
15 ModuleRunnerDelegate::ModuleRunnerDelegate(
16 const std::vector<base::FilePath>& search_paths)
17 : module_provider_(search_paths) {
20 ModuleRunnerDelegate::~ModuleRunnerDelegate() {
23 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
24 ModuleGetter getter) {
25 builtin_modules_[id] = base::Bind(getter);
28 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
29 const ModuleGetterCallback& getter) {
30 builtin_modules_[id] = getter;
33 void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) {
34 ModuleRegistry* registry = ModuleRegistry::From(
35 runner->GetContextHolder()->context());
36 registry->AttemptToLoadMoreModules(runner->GetContextHolder()->isolate());
37 module_provider_.AttempToLoadModules(
38 runner, registry->unsatisfied_dependencies());
41 v8::Local<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate(
42 ShellRunner* runner,
43 v8::Isolate* isolate) {
44 v8::Local<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate).Build();
45 ModuleRegistry::RegisterGlobals(isolate, templ);
46 return templ;
49 void ModuleRunnerDelegate::DidCreateContext(ShellRunner* runner) {
50 ShellRunnerDelegate::DidCreateContext(runner);
52 v8::Local<v8::Context> context = runner->GetContextHolder()->context();
53 ModuleRegistry* registry = ModuleRegistry::From(context);
55 v8::Isolate* isolate = runner->GetContextHolder()->isolate();
57 for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin();
58 it != builtin_modules_.end(); ++it) {
59 registry->AddBuiltinModule(isolate, it->first, it->second.Run(isolate));
63 void ModuleRunnerDelegate::DidRunScript(ShellRunner* runner) {
64 AttemptToLoadMoreModules(runner);
67 } // namespace gin