| OLD | NEW |
| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "gin/public/isolate_holder.h" | 6 #include "gin/public/isolate_holder.h" |
| 7 #include "mojo/apps/js/bootstrap.h" | |
| 8 #include "mojo/apps/js/mojo_runner_delegate.h" | 7 #include "mojo/apps/js/mojo_runner_delegate.h" |
| 9 #include "mojo/common/bindings_support_impl.h" | 8 #include "mojo/common/bindings_support_impl.h" |
| 10 #include "mojo/public/system/core_cpp.h" | 9 #include "mojo/public/system/core_cpp.h" |
| 11 #include "mojo/public/system/macros.h" | 10 #include "mojo/public/system/macros.h" |
| 12 | 11 |
| 13 #if defined(WIN32) | 12 #if defined(WIN32) |
| 14 #if !defined(CDECL) | 13 #if !defined(CDECL) |
| 15 #define CDECL __cdecl | 14 #define CDECL __cdecl |
| 16 #endif | 15 #endif |
| 17 #define MOJO_APPS_JS_EXPORT __declspec(dllexport) | 16 #define MOJO_APPS_JS_EXPORT __declspec(dllexport) |
| 18 #else | 17 #else |
| 19 #define CDECL | 18 #define CDECL |
| 20 #define MOJO_APPS_JS_EXPORT __attribute__((visibility("default"))) | 19 #define MOJO_APPS_JS_EXPORT __attribute__((visibility("default"))) |
| 21 #endif | 20 #endif |
| 22 | 21 |
| 23 namespace mojo { | 22 namespace mojo { |
| 24 namespace apps { | 23 namespace apps { |
| 25 | 24 |
| 26 void RunMojoJS(MojoHandle pipe) { | 25 void Start(MojoHandle pipe, const std::string& module) { |
| 26 base::MessageLoop loop; |
| 27 |
| 27 gin::IsolateHolder instance; | 28 gin::IsolateHolder instance; |
| 28 Bootstrap::SetInitialHandle(pipe); | |
| 29 | |
| 30 MojoRunnerDelegate delegate; | 29 MojoRunnerDelegate delegate; |
| 31 gin::Runner runner(&delegate, instance.isolate()); | 30 gin::Runner runner(&delegate, instance.isolate()); |
| 32 | 31 delegate.Start(&runner, pipe, module); |
| 33 { | |
| 34 gin::Runner::Scope scope(&runner); | |
| 35 runner.Run("define(['mojo/apps/js/main'], function(main) {});", | |
| 36 "mojo.js"); | |
| 37 } | |
| 38 | 32 |
| 39 base::MessageLoop::current()->Run(); | 33 base::MessageLoop::current()->Run(); |
| 40 } | 34 } |
| 41 | 35 |
| 42 } // namespace apps | 36 } // namespace apps |
| 43 } // namespace mojo | 37 } // namespace mojo |
| 44 | 38 |
| 45 extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { | 39 extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { |
| 46 base::MessageLoop loop; | |
| 47 mojo::common::BindingsSupportImpl bindings_support; | 40 mojo::common::BindingsSupportImpl bindings_support; |
| 48 mojo::BindingsSupport::Set(&bindings_support); | 41 mojo::BindingsSupport::Set(&bindings_support); |
| 49 mojo::apps::RunMojoJS(pipe); | 42 |
| 43 mojo::apps::Start(pipe, "mojo/apps/js/main"); |
| 44 |
| 50 mojo::BindingsSupport::Set(NULL); | 45 mojo::BindingsSupport::Set(NULL); |
| 51 return MOJO_RESULT_OK; | 46 return MOJO_RESULT_OK; |
| 52 } | 47 } |
| OLD | NEW |