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

Side by Side Diff: mojo/apps/js/mojo_runner_delegate.cc

Issue 90203002: [Mojo] Remove static "bootstrap" state in mojo_js (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with aa's changes Created 7 years 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 "mojo/apps/js/mojo_runner_delegate.h" 5 #include "mojo/apps/js/mojo_runner_delegate.h"
6 6
7 #include "base/bind.h"
7 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "gin/converter.h"
8 #include "gin/modules/console.h" 10 #include "gin/modules/console.h"
9 #include "gin/modules/module_registry.h" 11 #include "gin/modules/module_registry.h"
10 #include "gin/try_catch.h" 12 #include "gin/try_catch.h"
11 #include "mojo/apps/js/bootstrap.h" 13 #include "mojo/apps/js/threading.h"
12 #include "mojo/public/bindings/js/core.h" 14 #include "mojo/public/bindings/js/core.h"
13 #include "mojo/public/bindings/js/support.h" 15 #include "mojo/public/bindings/js/support.h"
14 16
15 namespace mojo { 17 namespace mojo {
16 namespace apps { 18 namespace apps {
17 19
18 namespace { 20 namespace {
19 21
20 // TODO(abarth): Rather than loading these modules from the file system, we 22 // TODO(abarth): Rather than loading these modules from the file system, we
21 // should load them from the network via Mojo IPC. 23 // should load them from the network via Mojo IPC.
22 std::vector<base::FilePath> GetModuleSearchPaths() { 24 std::vector<base::FilePath> GetModuleSearchPaths() {
23 std::vector<base::FilePath> search_paths(2); 25 std::vector<base::FilePath> search_paths(2);
24 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); 26 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]);
25 PathService::Get(base::DIR_EXE, &search_paths[1]); 27 PathService::Get(base::DIR_EXE, &search_paths[1]);
26 search_paths[1] = search_paths[1].AppendASCII("gen"); 28 search_paths[1] = search_paths[1].AppendASCII("gen");
27 return search_paths; 29 return search_paths;
28 } 30 }
29 31
32 void StartCallback(base::WeakPtr<gin::Runner> runner,
33 MojoHandle pipe,
34 v8::Handle<v8::Value> module) {
35 if (!runner) {
Aaron Boodman 2013/11/27 19:02:41 Can we really get here with runner not populated?
abarth-chromium 2013/11/27 19:18:09 Removed.
36 CHECK(MojoClose(pipe) == MOJO_RESULT_OK);
37 return;
38 }
39 v8::Isolate* isolate = runner->isolate();
40 v8::Handle<v8::Function> start;
41 if (!gin::ConvertFromV8(module, &start)) {
Aaron Boodman 2013/11/27 19:02:41 What would cause this to fail? I think it should j
abarth-chromium 2013/11/27 19:18:09 This can fail if the requested module returns an o
Aaron Boodman 2013/11/27 20:35:49 But we control main.js. It seems like if this ever
42 CHECK(MojoClose(pipe) == MOJO_RESULT_OK);
43 return;
44 }
45 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, pipe) };
46 runner->Call(start, runner->global(), 1, args);
Aaron Boodman 2013/11/27 19:02:41 We should do a wrapper around calling JS functions
abarth-chromium 2013/11/27 19:18:09 I bet! :)
47 }
48
30 } // namespace 49 } // namespace
31 50
32 MojoRunnerDelegate::MojoRunnerDelegate() 51 MojoRunnerDelegate::MojoRunnerDelegate()
33 : ModuleRunnerDelegate(GetModuleSearchPaths()) { 52 : ModuleRunnerDelegate(GetModuleSearchPaths()) {
34 AddBuiltinModule(Bootstrap::kModuleName, Bootstrap::GetTemplate); 53 AddBuiltinModule(Threading::kModuleName, Threading::GetTemplate);
35 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetTemplate); 54 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetTemplate);
36 AddBuiltinModule(js::Core::kModuleName, js::Core::GetTemplate); 55 AddBuiltinModule(js::Core::kModuleName, js::Core::GetTemplate);
37 AddBuiltinModule(js::Support::kModuleName, js::Support::GetTemplate); 56 AddBuiltinModule(js::Support::kModuleName, js::Support::GetTemplate);
38 } 57 }
39 58
40 MojoRunnerDelegate::~MojoRunnerDelegate() { 59 MojoRunnerDelegate::~MojoRunnerDelegate() {
41 } 60 }
42 61
62 void MojoRunnerDelegate::Start(gin::Runner* runner,
63 MojoHandle pipe,
64 const std::string& module) {
65 gin::Runner::Scope scope(runner);
66 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(runner->context());
67 registry->LoadModule(runner->isolate(), module,
68 base::Bind(StartCallback, runner->GetWeakPtr(), pipe));
69 AttemptToLoadMoreModules(runner);
70 }
71
43 void MojoRunnerDelegate::UnhandledException(gin::Runner* runner, 72 void MojoRunnerDelegate::UnhandledException(gin::Runner* runner,
44 gin::TryCatch& try_catch) { 73 gin::TryCatch& try_catch) {
45 gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch); 74 gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch);
46 LOG(ERROR) << try_catch.GetStackTrace(); 75 LOG(ERROR) << try_catch.GetStackTrace();
47 } 76 }
48 77
49 } // namespace apps 78 } // namespace apps
50 } // namespace mojo 79 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698