Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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/macros.h" | |
| 6 #include "base/memory/ref_counted.h" | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "build/build_config.h" | |
| 10 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" | |
| 11 #include "mojo/examples/pepper_container_app/plugin_instance.h" | |
| 12 #include "mojo/examples/pepper_container_app/plugin_module.h" | |
| 13 #include "mojo/public/bindings/allocation_scope.h" | |
| 14 #include "mojo/public/bindings/remote_ptr.h" | |
| 15 #include "mojo/public/environment/environment.h" | |
| 16 #include "mojo/public/gles2/gles2_cpp.h" | |
| 17 #include "mojo/public/shell/application.h" | |
| 18 #include "mojo/public/system/core.h" | |
| 19 #include "mojom/native_viewport.h" | |
| 20 #include "mojom/shell.h" | |
| 21 #include "ppapi/c/pp_rect.h" | |
| 22 #include "ppapi/shared_impl/proxy_lock.h" | |
| 23 | |
| 24 #if defined(OS_WIN) | |
| 25 #if !defined(CDECL) | |
| 26 #define CDECL __cdecl | |
| 27 #endif | |
| 28 #define PEPPER_CONTAINER_APP_EXPORT __declspec(dllexport) | |
| 29 #else | |
| 30 #define CDECL | |
| 31 #define PEPPER_CONTAINER_APP_EXPORT __attribute__((visibility("default"))) | |
| 32 #endif | |
| 33 | |
| 34 namespace mojo { | |
| 35 namespace examples { | |
| 36 | |
| 37 class PepperContainerApp: public Application, | |
| 38 public NativeViewportClient, | |
| 39 public MojoPpapiGlobals::Delegate { | |
| 40 public: | |
| 41 explicit PepperContainerApp(MojoHandle shell_handle) | |
| 42 : Application(shell_handle), | |
| 43 ppapi_globals_(this), | |
| 44 plugin_module_(new PluginModule) { | |
| 45 InterfacePipe<NativeViewport, AnyInterface> viewport_pipe; | |
| 46 mojo::AllocationScope scope; | |
| 47 shell()->Connect("mojo:mojo_native_viewport_service", | |
| 48 viewport_pipe.handle_to_peer.Pass()); | |
| 49 viewport_.reset(viewport_pipe.handle_to_self.Pass(), this); | |
| 50 Rect::Builder rect; | |
| 51 Point::Builder point; | |
| 52 point.set_x(10); | |
| 53 point.set_y(10); | |
| 54 rect.set_position(point.Finish()); | |
| 55 Size::Builder size; | |
| 56 size.set_width(800); | |
| 57 size.set_height(600); | |
| 58 rect.set_size(size.Finish()); | |
| 59 viewport_->Create(rect.Finish()); | |
| 60 viewport_->Show(); | |
| 61 } | |
| 62 | |
| 63 virtual ~PepperContainerApp() {} | |
| 64 | |
| 65 // NativeViewportClient implementation. | |
| 66 virtual void OnCreated() OVERRIDE { | |
| 67 ppapi::ProxyAutoLock lock; | |
| 68 | |
| 69 plugin_instance_ = plugin_module_->CreateInstance().Pass(); | |
| 70 if (!plugin_instance_->DidCreate()) | |
| 71 plugin_instance_.reset(); | |
| 72 } | |
| 73 | |
| 74 virtual void OnDestroyed() OVERRIDE { | |
| 75 ppapi::ProxyAutoLock lock; | |
| 76 | |
| 77 if (plugin_instance_) { | |
| 78 plugin_instance_->DidDestroy(); | |
| 79 plugin_instance_.reset(); | |
| 80 } | |
| 81 | |
| 82 base::MessageLoop::current()->Quit(); | |
| 83 } | |
| 84 | |
| 85 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { | |
| 86 ppapi::ProxyAutoLock lock; | |
| 87 | |
| 88 if (plugin_instance_) { | |
| 89 PP_Rect rect; | |
| 90 rect.point.x = bounds.position().x(); | |
|
darin (slow to review)
2014/03/20 23:29:35
note: if you want, you can introduce mojo::TypeCon
yzshen1
2014/03/21 03:22:00
Done. I added a new file type_converters for mojom
| |
| 91 rect.point.y = bounds.position().y(); | |
| 92 rect.size.width = bounds.size().width(); | |
| 93 rect.size.height = bounds.size().height(); | |
| 94 | |
| 95 plugin_instance_->DidChangeView(rect); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 virtual void OnEvent(const Event& event) OVERRIDE { | |
| 100 ppapi::ProxyAutoLock lock; | |
| 101 | |
| 102 if (!event.location().is_null()) { | |
| 103 // TODO(yzshen): Handle events. | |
| 104 viewport_->AckEvent(event); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 // MojoPpapiGlobals::Delegate implementation. | |
| 109 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { | |
| 110 MessagePipe gles2_pipe; | |
| 111 viewport_->CreateGLES2Context(gles2_pipe.handle1.Pass()); | |
| 112 return gles2_pipe.handle0.Pass(); | |
| 113 } | |
| 114 | |
| 115 private: | |
| 116 MojoPpapiGlobals ppapi_globals_; | |
| 117 | |
| 118 RemotePtr<NativeViewport> viewport_; | |
| 119 scoped_refptr<PluginModule> plugin_module_; | |
| 120 scoped_ptr<PluginInstance> plugin_instance_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp); | |
| 123 }; | |
| 124 | |
| 125 } // namespace examples | |
| 126 } // namespace mojo | |
| 127 | |
| 128 extern "C" PEPPER_CONTAINER_APP_EXPORT MojoResult CDECL MojoMain( | |
| 129 MojoHandle shell_handle) { | |
| 130 mojo::Environment env; | |
| 131 mojo::GLES2Initializer gles2; | |
| 132 base::MessageLoop run_loop; | |
| 133 mojo::examples::PepperContainerApp app(shell_handle); | |
| 134 | |
| 135 run_loop.Run(); | |
| 136 return MOJO_RESULT_OK; | |
| 137 } | |
| OLD | NEW |