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