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

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

Issue 178953003: Mojo container example for hosting Pepper plugins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 "mojo/examples/pepper_container_app/plugin_module.h"
6
7 #include <string>
8
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "build/build_config.h"
12 #include "mojo/examples/pepper_container_app/interface_list.h"
13 #include "mojo/examples/pepper_container_app/plugin_instance.h"
14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/shared_impl/callback_tracker.h"
16
17 namespace mojo {
18 namespace examples {
19
20 namespace {
21
22 const void* GetInterface(const char* name) {
23 const void* interface =
24 InterfaceList::GetInstance()->GetBrowserInterface(name);
25
26 if (!interface)
27 LOG(WARNING) << "Interface requested " << name;
28
29 return interface;
30 }
31
32 } // namespace
33
34 PluginModule::EntryPoints::EntryPoints() : get_interface(NULL),
35 initialize_module(NULL),
36 shutdown_module(NULL) {}
37
38 PluginModule::PluginModule() : callback_tracker_(new ppapi::CallbackTracker) {
39 Initialize();
40 }
41
42 PluginModule::~PluginModule() {
43 callback_tracker_->AbortAll();
44
45 if (entry_points_.shutdown_module)
46 entry_points_.shutdown_module();
47 }
48
49 scoped_ptr<PluginInstance> PluginModule::CreateInstance() {
50 return make_scoped_ptr(new PluginInstance(this));
51 }
52
53 const void* PluginModule::GetPluginInterface(const char* name) const {
54 if (entry_points_.get_interface)
55 return entry_points_.get_interface(name);
56 return NULL;
57 }
58
59 void PluginModule::Initialize() {
60 // Platform-specific filename.
61 // TODO(yzshen): Don't hard-code it.
62 #if defined(OS_WIN)
63 static const wchar_t plugin_name[] = L"ppapi_example_gles2_spinning_cube.dll";
64 #elif defined(OS_MACOSX)
65 static const char plugin_name[] = "ppapi_example_gles2_spinning_cube.plugin";
66 #elif defined(OS_POSIX)
67 static const char plugin_name[] = "libppapi_example_gles2_spinning_cube.so";
68 #endif
69
70 base::FilePath plugin_path(plugin_name);
71
72 std::string error;
73 plugin_module_.Reset(
74 base::LoadNativeLibrary(plugin_path, &error));
75
76 if (!plugin_module_.is_valid()) {
77 LOG(WARNING) << "Cannot load " << plugin_path.AsUTF8Unsafe()
78 << ". Error: " << error;
79 return;
80 }
81
82 entry_points_.get_interface =
83 reinterpret_cast<PP_GetInterface_Func>(
84 plugin_module_.GetFunctionPointer("PPP_GetInterface"));
85 if (!entry_points_.get_interface) {
86 LOG(WARNING) << "No PPP_GetInterface in plugin library";
87 return;
88 }
89
90 entry_points_.initialize_module =
91 reinterpret_cast<PP_InitializeModule_Func>(
92 plugin_module_.GetFunctionPointer("PPP_InitializeModule"));
93 if (!entry_points_.initialize_module) {
94 LOG(WARNING) << "No PPP_InitializeModule in plugin library";
95 return;
96 }
97
98 // It's okay for PPP_ShutdownModule to not be defined and |shutdown_module| to
99 // be NULL.
100 entry_points_.shutdown_module =
101 reinterpret_cast<PP_ShutdownModule_Func>(
102 plugin_module_.GetFunctionPointer("PPP_ShutdownModule"));
103
104 int32_t result = entry_points_.initialize_module(pp_module(),
105 &GetInterface);
106 if (result != PP_OK)
107 LOG(WARNING) << "Initializing module failed with error " << result;
108 }
109
110 } // namespace examples
111 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/pepper_container_app/plugin_module.h ('k') | mojo/examples/pepper_container_app/ppb_core_thunk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698