| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" | 10 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" |
| 11 #include "mojo/examples/pepper_container_app/plugin_instance.h" | 11 #include "mojo/examples/pepper_container_app/plugin_instance.h" |
| 12 #include "mojo/examples/pepper_container_app/plugin_module.h" | 12 #include "mojo/examples/pepper_container_app/plugin_module.h" |
| 13 #include "mojo/examples/pepper_container_app/type_converters.h" | 13 #include "mojo/examples/pepper_container_app/type_converters.h" |
| 14 #include "mojo/public/cpp/application/application.h" | 14 #include "mojo/public/cpp/application/application.h" |
| 15 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
| 16 #include "mojo/public/cpp/gles2/gles2.h" | 15 #include "mojo/public/cpp/gles2/gles2.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 16 #include "mojo/public/cpp/system/core.h" |
| 18 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 17 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 19 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 18 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 20 #include "ppapi/c/pp_rect.h" | 19 #include "ppapi/c/pp_rect.h" |
| 21 #include "ppapi/shared_impl/proxy_lock.h" | 20 #include "ppapi/shared_impl/proxy_lock.h" |
| 22 | 21 |
| 23 namespace mojo { | 22 namespace mojo { |
| 24 namespace examples { | 23 namespace examples { |
| 25 | 24 |
| 26 class PepperContainerApp: public Application, | 25 class PepperContainerApp: public Application, |
| 27 public NativeViewportClient, | 26 public NativeViewportClient, |
| 28 public MojoPpapiGlobals::Delegate { | 27 public MojoPpapiGlobals::Delegate { |
| 29 public: | 28 public: |
| 30 explicit PepperContainerApp() | 29 explicit PepperContainerApp() |
| 31 : Application(), | 30 : Application(), |
| 32 ppapi_globals_(this), | 31 ppapi_globals_(this), |
| 33 plugin_module_(new PluginModule) {} | 32 plugin_module_(new PluginModule) {} |
| 34 | 33 |
| 35 virtual ~PepperContainerApp() {} | 34 virtual ~PepperContainerApp() {} |
| 36 | 35 |
| 37 virtual void Initialize() MOJO_OVERRIDE { | 36 virtual void Initialize() MOJO_OVERRIDE { |
| 38 mojo::AllocationScope scope; | |
| 39 | |
| 40 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); | 37 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); |
| 41 viewport_.set_client(this); | 38 viewport_.set_client(this); |
| 42 | 39 |
| 43 Rect::Builder rect; | 40 RectPtr rect(Rect::New()); |
| 44 rect.set_x(10); | 41 rect->x = 10; |
| 45 rect.set_y(10); | 42 rect->y = 10; |
| 46 rect.set_width(800); | 43 rect->width = 800; |
| 47 rect.set_height(600); | 44 rect->height = 600; |
| 48 viewport_->Create(rect.Finish()); | 45 viewport_->Create(rect.Pass()); |
| 49 viewport_->Show(); | 46 viewport_->Show(); |
| 50 } | 47 } |
| 51 | 48 |
| 52 // NativeViewportClient implementation. | 49 // NativeViewportClient implementation. |
| 53 virtual void OnCreated() OVERRIDE { | 50 virtual void OnCreated() OVERRIDE { |
| 54 ppapi::ProxyAutoLock lock; | 51 ppapi::ProxyAutoLock lock; |
| 55 | 52 |
| 56 plugin_instance_ = plugin_module_->CreateInstance().Pass(); | 53 plugin_instance_ = plugin_module_->CreateInstance().Pass(); |
| 57 if (!plugin_instance_->DidCreate()) | 54 if (!plugin_instance_->DidCreate()) |
| 58 plugin_instance_.reset(); | 55 plugin_instance_.reset(); |
| 59 } | 56 } |
| 60 | 57 |
| 61 virtual void OnDestroyed() OVERRIDE { | 58 virtual void OnDestroyed() OVERRIDE { |
| 62 ppapi::ProxyAutoLock lock; | 59 ppapi::ProxyAutoLock lock; |
| 63 | 60 |
| 64 if (plugin_instance_) { | 61 if (plugin_instance_) { |
| 65 plugin_instance_->DidDestroy(); | 62 plugin_instance_->DidDestroy(); |
| 66 plugin_instance_.reset(); | 63 plugin_instance_.reset(); |
| 67 } | 64 } |
| 68 | 65 |
| 69 base::MessageLoop::current()->Quit(); | 66 base::MessageLoop::current()->Quit(); |
| 70 } | 67 } |
| 71 | 68 |
| 72 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { | 69 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { |
| 73 ppapi::ProxyAutoLock lock; | 70 ppapi::ProxyAutoLock lock; |
| 74 | 71 |
| 75 if (plugin_instance_) | 72 if (plugin_instance_) |
| 76 plugin_instance_->DidChangeView(bounds); | 73 plugin_instance_->DidChangeView(bounds.To<PP_Rect>()); |
| 77 } | 74 } |
| 78 | 75 |
| 79 virtual void OnEvent(const Event& event, | 76 virtual void OnEvent(EventPtr event, |
| 80 const mojo::Callback<void()>& callback) OVERRIDE { | 77 const mojo::Callback<void()>& callback) OVERRIDE { |
| 81 if (!event.location().is_null()) { | 78 if (!event->location.is_null()) { |
| 82 ppapi::ProxyAutoLock lock; | 79 ppapi::ProxyAutoLock lock; |
| 83 | 80 |
| 84 // TODO(yzshen): Handle events. | 81 // TODO(yzshen): Handle events. |
| 85 } | 82 } |
| 86 callback.Run(); | 83 callback.Run(); |
| 87 } | 84 } |
| 88 | 85 |
| 89 // MojoPpapiGlobals::Delegate implementation. | 86 // MojoPpapiGlobals::Delegate implementation. |
| 90 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { | 87 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { |
| 91 MessagePipe gles2_pipe; | 88 MessagePipe gles2_pipe; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 }; | 101 }; |
| 105 | 102 |
| 106 } // namespace examples | 103 } // namespace examples |
| 107 | 104 |
| 108 // static | 105 // static |
| 109 Application* Application::Create() { | 106 Application* Application::Create() { |
| 110 return new examples::PepperContainerApp(); | 107 return new examples::PepperContainerApp(); |
| 111 } | 108 } |
| 112 | 109 |
| 113 } // namespace mojo | 110 } // namespace mojo |
| OLD | NEW |