summaryrefslogtreecommitdiffstats
path: root/gin/modules
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-22 07:30:55 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-22 07:30:55 +0000
commit467834b30f40d1aff0031fbb7660fb211c8112e4 (patch)
tree8e1f09b420bfda00a238ed6613642ac656720d2e /gin/modules
parent3ac7e07966540fe5b41bcc60ef14ff6b18fe6057 (diff)
downloadchromium_src-467834b30f40d1aff0031fbb7660fb211c8112e4.zip
chromium_src-467834b30f40d1aff0031fbb7660fb211c8112e4.tar.gz
chromium_src-467834b30f40d1aff0031fbb7660fb211c8112e4.tar.bz2
Teach mojo_js_bindings_unittests to load generated JS files
This CL generalizes gin::FileModuleProvider to be able to load modules from several places in the file system. I've then made use of this facility in mojo_js_bindings_unittests to load generated JavaScript modules created by mojom_js_generator.py, similar to how C++ files can #include from the generated mojom directory. I've deleted sample_service.js now that we can load it from the generated directory. BUG=317398 Review URL: https://codereview.chromium.org/81673002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/modules')
-rw-r--r--gin/modules/file_module_provider.cc33
-rw-r--r--gin/modules/file_module_provider.h6
-rw-r--r--gin/modules/module_runner_delegate.cc5
-rw-r--r--gin/modules/module_runner_delegate.h3
4 files changed, 28 insertions, 19 deletions
diff --git a/gin/modules/file_module_provider.cc b/gin/modules/file_module_provider.cc
index 0a3e24c..990dcd0 100644
--- a/gin/modules/file_module_provider.cc
+++ b/gin/modules/file_module_provider.cc
@@ -15,14 +15,15 @@ namespace gin {
namespace {
void AttempToLoadModule(const base::WeakPtr<Runner>& runner,
- const base::FilePath& base,
+ const std::vector<base::FilePath>& search_paths,
const std::string& id) {
if (!runner)
return;
std::vector<std::string> components;
base::SplitString(id, '/', &components);
- base::FilePath path = base;
+
+ base::FilePath path;
for (size_t i = 0; i < components.size(); ++i) {
// TODO(abarth): Technically the path components can be UTF-8. We don't
// handle that case correctly yet.
@@ -30,21 +31,25 @@ void AttempToLoadModule(const base::WeakPtr<Runner>& runner,
}
path = path.AddExtension(FILE_PATH_LITERAL("js"));
- std::string source;
- if (!ReadFileToString(path, &source))
- return;
+ for (size_t i = 0; i < search_paths.size(); ++i) {
+ std::string source;
+ if (!ReadFileToString(search_paths[i].Append(path), &source))
+ continue;
- Runner::Scope scope(runner.get());
- v8::Handle<v8::Script> script = v8::Script::New(
- StringToV8(runner->isolate(), source),
- StringToV8(runner->isolate(), id));
- runner->Run(script);
+ Runner::Scope scope(runner.get());
+ v8::Handle<v8::Script> script = v8::Script::New(
+ StringToV8(runner->isolate(), source),
+ StringToV8(runner->isolate(), id));
+ runner->Run(script);
+ return;
+ }
}
} // namespace
-FileModuleProvider::FileModuleProvider(const base::FilePath& base)
- : base_(base) {
+FileModuleProvider::FileModuleProvider(
+ const std::vector<base::FilePath>& search_paths)
+ : search_paths_(search_paths) {
}
FileModuleProvider::~FileModuleProvider() {
@@ -59,8 +64,8 @@ void FileModuleProvider::AttempToLoadModules(
if (attempted_ids_.count(id))
continue;
attempted_ids_.insert(id);
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(AttempToLoadModule, runner->GetWeakPtr(), base_, id));
+ base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+ AttempToLoadModule, runner->GetWeakPtr(), search_paths_, id));
}
}
diff --git a/gin/modules/file_module_provider.h b/gin/modules/file_module_provider.h
index 1e6fb88e..e82d8e3 100644
--- a/gin/modules/file_module_provider.h
+++ b/gin/modules/file_module_provider.h
@@ -7,6 +7,7 @@
#include <set>
#include <string>
+#include <vector>
#include "base/files/file_path.h"
#include "gin/runner.h"
@@ -15,13 +16,14 @@ namespace gin {
class FileModuleProvider {
public:
- explicit FileModuleProvider(const base::FilePath& base);
+ explicit FileModuleProvider(
+ const std::vector<base::FilePath>& search_paths);
~FileModuleProvider();
void AttempToLoadModules(Runner* runner, const std::set<std::string>& ids);
private:
- base::FilePath base_;
+ std::vector<base::FilePath> search_paths_;
std::set<std::string> attempted_ids_;
DISALLOW_COPY_AND_ASSIGN(FileModuleProvider);
diff --git a/gin/modules/module_runner_delegate.cc b/gin/modules/module_runner_delegate.cc
index 50b9f5e..3f2422c 100644
--- a/gin/modules/module_runner_delegate.cc
+++ b/gin/modules/module_runner_delegate.cc
@@ -8,8 +8,9 @@
namespace gin {
-ModuleRunnerDelegate::ModuleRunnerDelegate(const base::FilePath& module_base)
- : module_provider_(module_base) {
+ModuleRunnerDelegate::ModuleRunnerDelegate(
+ const std::vector<base::FilePath>& search_paths)
+ : module_provider_(search_paths) {
}
ModuleRunnerDelegate::~ModuleRunnerDelegate() {
diff --git a/gin/modules/module_runner_delegate.h b/gin/modules/module_runner_delegate.h
index 4d821d2..a66695f 100644
--- a/gin/modules/module_runner_delegate.h
+++ b/gin/modules/module_runner_delegate.h
@@ -18,7 +18,8 @@ typedef v8::Local<v8::ObjectTemplate> (*ModuleTemplateGetter)(
class ModuleRunnerDelegate : public RunnerDelegate {
public:
- explicit ModuleRunnerDelegate(const base::FilePath& module_base);
+ explicit ModuleRunnerDelegate(
+ const std::vector<base::FilePath>& search_paths);
virtual ~ModuleRunnerDelegate();
void AddBuiltinModule(const std::string& id, ModuleTemplateGetter templ);