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

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

Issue 728133002: Update mojo sdk to rev e01f9a49449381a5eb430c1fd88bf2cae73ec35a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + ios gyp fixes Created 6 years, 1 month 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
« no previous file with comments | « mojo/edk/js/mojo_runner_delegate.h ('k') | mojo/edk/js/support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 "mojo/edk/js/mojo_runner_delegate.h"
6
7 #include "base/bind.h"
8 #include "base/path_service.h"
9 #include "gin/converter.h"
10 #include "gin/modules/console.h"
11 #include "gin/modules/module_registry.h"
12 #include "gin/modules/timer.h"
13 #include "gin/try_catch.h"
14 #include "mojo/edk/js/core.h"
15 #include "mojo/edk/js/handle.h"
16 #include "mojo/edk/js/support.h"
17 #include "mojo/edk/js/threading.h"
18
19 namespace mojo {
20 namespace js {
21
22 namespace {
23
24 // TODO(abarth): Rather than loading these modules from the file system, we
25 // should load them from the network via Mojo IPC.
26 std::vector<base::FilePath> GetModuleSearchPaths() {
27 std::vector<base::FilePath> search_paths(2);
28 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]);
29 PathService::Get(base::DIR_EXE, &search_paths[1]);
30 search_paths[1] = search_paths[1].AppendASCII("gen");
31 return search_paths;
32 }
33
34 void StartCallback(base::WeakPtr<gin::Runner> runner,
35 MojoHandle pipe,
36 v8::Handle<v8::Value> module) {
37 v8::Isolate* isolate = runner->GetContextHolder()->isolate();
38 v8::Handle<v8::Function> start;
39 CHECK(gin::ConvertFromV8(isolate, module, &start));
40
41 v8::Handle<v8::Value> args[] = {
42 gin::ConvertToV8(isolate, Handle(pipe)) };
43 runner->Call(start, runner->global(), 1, args);
44 }
45
46 } // namespace
47
48 MojoRunnerDelegate::MojoRunnerDelegate()
49 : ModuleRunnerDelegate(GetModuleSearchPaths()) {
50 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
51 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
52 AddBuiltinModule(js::Core::kModuleName, js::Core::GetModule);
53 AddBuiltinModule(js::Support::kModuleName, js::Support::GetModule);
54 AddBuiltinModule(js::Threading::kModuleName, js::Threading::GetModule);
55 }
56
57 MojoRunnerDelegate::~MojoRunnerDelegate() {
58 }
59
60 void MojoRunnerDelegate::Start(gin::Runner* runner,
61 MojoHandle pipe,
62 const std::string& module) {
63 gin::Runner::Scope scope(runner);
64 gin::ModuleRegistry* registry =
65 gin::ModuleRegistry::From(runner->GetContextHolder()->context());
66 registry->LoadModule(runner->GetContextHolder()->isolate(), module,
67 base::Bind(StartCallback, runner->GetWeakPtr(), pipe));
68 AttemptToLoadMoreModules(runner);
69 }
70
71 void MojoRunnerDelegate::UnhandledException(gin::ShellRunner* runner,
72 gin::TryCatch& try_catch) {
73 gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch);
74 LOG(ERROR) << try_catch.GetStackTrace();
75 }
76
77 } // namespace js
78 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/js/mojo_runner_delegate.h ('k') | mojo/edk/js/support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698