Currently, bionic only build a subset of the examples. This changes turns on all...
[chromium-blink-merge.git] / mojo / examples / pepper_container_app / plugin_module.cc
blobd09d42d36d4e24941e964caf7e11a6ee013593e7
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"
7 #include <string>
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"
17 namespace mojo {
18 namespace examples {
20 namespace {
22 const void* GetInterface(const char* name) {
23 const void* interface =
24 InterfaceList::GetInstance()->GetBrowserInterface(name);
26 if (!interface)
27 LOG(WARNING) << "Interface requested " << name;
29 return interface;
32 } // namespace
34 PluginModule::EntryPoints::EntryPoints() : get_interface(NULL),
35 initialize_module(NULL),
36 shutdown_module(NULL) {}
38 PluginModule::PluginModule() : callback_tracker_(new ppapi::CallbackTracker) {
39 Initialize();
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);
56 return NULL;
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
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();
78 return;
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";
86 return;
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";
94 return;
97 // It's okay for PPP_ShutdownModule to not be defined and |shutdown_module| to
98 // be NULL.
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(),
104 &GetInterface);
105 if (result != PP_OK)
106 LOG(WARNING) << "Initializing module failed with error " << result;
109 } // namespace examples
110 } // namespace mojo