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.
5 #include "mojo/examples/pepper_container_app/plugin_module.h"
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"
22 const void* GetInterface(const char* name
) {
23 const void* interface
=
24 InterfaceList::GetInstance()->GetBrowserInterface(name
);
27 LOG(WARNING
) << "Interface requested " << name
;
34 PluginModule::EntryPoints::EntryPoints() : get_interface(NULL
),
35 initialize_module(NULL
),
36 shutdown_module(NULL
) {}
38 PluginModule::PluginModule() : callback_tracker_(new ppapi::CallbackTracker
) {
42 PluginModule::~PluginModule() {
43 callback_tracker_
->AbortAll();
45 if (entry_points_
.shutdown_module
)
46 entry_points_
.shutdown_module();
49 scoped_ptr
<PluginInstance
> PluginModule::CreateInstance() {
50 return make_scoped_ptr(new PluginInstance(this));
53 const void* PluginModule::GetPluginInterface(const char* name
) const {
54 if (entry_points_
.get_interface
)
55 return entry_points_
.get_interface(name
);
59 void PluginModule::Initialize() {
60 // Platform-specific filename.
61 // TODO(yzshen): Don't hard-code it.
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";
70 base::FilePath
plugin_path(plugin_name
);
72 base::NativeLibraryLoadError error
;
73 plugin_module_
.Reset(base::LoadNativeLibrary(plugin_path
, &error
));
75 if (!plugin_module_
.is_valid()) {
76 LOG(WARNING
) << "Cannot load " << plugin_path
.AsUTF8Unsafe()
77 << ". Error: " << error
.ToString();
81 entry_points_
.get_interface
=
82 reinterpret_cast<PP_GetInterface_Func
>(
83 plugin_module_
.GetFunctionPointer("PPP_GetInterface"));
84 if (!entry_points_
.get_interface
) {
85 LOG(WARNING
) << "No PPP_GetInterface in plugin library";
89 entry_points_
.initialize_module
=
90 reinterpret_cast<PP_InitializeModule_Func
>(
91 plugin_module_
.GetFunctionPointer("PPP_InitializeModule"));
92 if (!entry_points_
.initialize_module
) {
93 LOG(WARNING
) << "No PPP_InitializeModule in plugin library";
97 // It's okay for PPP_ShutdownModule to not be defined and |shutdown_module| to
99 entry_points_
.shutdown_module
=
100 reinterpret_cast<PP_ShutdownModule_Func
>(
101 plugin_module_
.GetFunctionPointer("PPP_ShutdownModule"));
103 int32_t result
= entry_points_
.initialize_module(pp_module(),
106 LOG(WARNING
) << "Initializing module failed with error " << result
;
109 } // namespace examples