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

Side by Side Diff: mojo/examples/pepper_container_app/pepper_container_app.cc

Issue 178953003: Mojo container example for hosting Pepper plugins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and rebase Created 6 years, 9 months 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 | Annotate | Revision Log
OLDNEW
(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/examples/pepper_container_app/type_converters.h"
14 #include "mojo/public/bindings/allocation_scope.h"
15 #include "mojo/public/bindings/remote_ptr.h"
16 #include "mojo/public/environment/environment.h"
17 #include "mojo/public/gles2/gles2_cpp.h"
18 #include "mojo/public/shell/application.h"
19 #include "mojo/public/shell/shell.mojom.h"
20 #include "mojo/public/system/core.h"
21 #include "mojo/services/native_viewport/native_viewport.mojom.h"
22 #include "ppapi/c/pp_rect.h"
23 #include "ppapi/shared_impl/proxy_lock.h"
24
25 #if defined(OS_WIN)
26 #if !defined(CDECL)
27 #define CDECL __cdecl
28 #endif
29 #define PEPPER_CONTAINER_APP_EXPORT __declspec(dllexport)
30 #else
31 #define CDECL
32 #define PEPPER_CONTAINER_APP_EXPORT __attribute__((visibility("default")))
33 #endif
34
35 namespace mojo {
36 namespace examples {
37
38 class PepperContainerApp: public Application,
39 public NativeViewportClient,
40 public MojoPpapiGlobals::Delegate {
41 public:
42 explicit PepperContainerApp(MojoHandle shell_handle)
43 : Application(shell_handle),
44 ppapi_globals_(this),
45 plugin_module_(new PluginModule) {
46 InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
47 mojo::AllocationScope scope;
48 shell()->Connect("mojo:mojo_native_viewport_service",
49 viewport_pipe.handle_to_peer.Pass());
50 viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
51 Rect::Builder rect;
52 Point::Builder point;
53 point.set_x(10);
54 point.set_y(10);
55 rect.set_position(point.Finish());
56 Size::Builder size;
57 size.set_width(800);
58 size.set_height(600);
59 rect.set_size(size.Finish());
60 viewport_->Create(rect.Finish());
61 viewport_->Show();
62 }
63
64 virtual ~PepperContainerApp() {}
65
66 // NativeViewportClient implementation.
67 virtual void OnCreated() OVERRIDE {
68 ppapi::ProxyAutoLock lock;
69
70 plugin_instance_ = plugin_module_->CreateInstance().Pass();
71 if (!plugin_instance_->DidCreate())
72 plugin_instance_.reset();
73 }
74
75 virtual void OnDestroyed() OVERRIDE {
76 ppapi::ProxyAutoLock lock;
77
78 if (plugin_instance_) {
79 plugin_instance_->DidDestroy();
80 plugin_instance_.reset();
81 }
82
83 base::MessageLoop::current()->Quit();
84 }
85
86 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE {
87 ppapi::ProxyAutoLock lock;
88
89 if (plugin_instance_)
90 plugin_instance_->DidChangeView(bounds);
91 }
92
93 virtual void OnEvent(const Event& event) OVERRIDE {
94 ppapi::ProxyAutoLock lock;
95
96 if (!event.location().is_null()) {
97 // TODO(yzshen): Handle events.
98 viewport_->AckEvent(event);
viettrungluu 2014/03/21 04:20:00 I'm somewhat sceptical that you should call the vi
yzshen1 2014/03/21 17:52:08 Right. I don't think it will lead to deadlock, but
99 }
100 }
101
102 // MojoPpapiGlobals::Delegate implementation.
103 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE {
104 MessagePipe gles2_pipe;
105 viewport_->CreateGLES2Context(gles2_pipe.handle1.Pass());
106 return gles2_pipe.handle0.Pass();
107 }
108
109 private:
110 MojoPpapiGlobals ppapi_globals_;
111
112 RemotePtr<NativeViewport> viewport_;
113 scoped_refptr<PluginModule> plugin_module_;
114 scoped_ptr<PluginInstance> plugin_instance_;
115
116 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp);
117 };
118
119 } // namespace examples
120 } // namespace mojo
121
122 extern "C" PEPPER_CONTAINER_APP_EXPORT MojoResult CDECL MojoMain(
123 MojoHandle shell_handle) {
124 mojo::Environment env;
125 mojo::GLES2Initializer gles2;
126 base::MessageLoop run_loop;
127 mojo::examples::PepperContainerApp app(shell_handle);
128
129 run_loop.Run();
130 return MOJO_RESULT_OK;
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698