| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "gpu/gpu_plugin/gpu_plugin.h" | 5 #include "gpu/gpu_plugin/gpu_plugin.h" |
| 6 #include "gpu/gpu_plugin/gpu_plugin_object_factory.h" | |
| 7 #include "gpu/np_utils/np_browser.h" | |
| 8 #include "gpu/np_utils/np_plugin_object.h" | |
| 9 #include "gpu/np_utils/np_plugin_object_factory.h" | |
| 10 #include "webkit/glue/plugins/nphostapi.h" | 6 #include "webkit/glue/plugins/nphostapi.h" |
| 11 | 7 |
| 12 using np_utils::NPBrowser; | |
| 13 using np_utils::NPPluginObjectFactory; | |
| 14 using np_utils::PluginObject; | |
| 15 | |
| 16 namespace gpu_plugin { | 8 namespace gpu_plugin { |
| 17 | 9 |
| 18 // Definitions of NPAPI plugin entry points. | 10 // Definitions of NPAPI plugin entry points. |
| 19 | 11 |
| 20 namespace { | 12 namespace { |
| 21 NPBrowser* g_browser; | |
| 22 GPUPluginObjectFactory g_plugin_object_factory; | |
| 23 | 13 |
| 24 NPError NPP_New(NPMIMEType plugin_type, NPP instance, | 14 NPError NPP_New(NPMIMEType plugin_type, NPP instance, |
| 25 uint16 mode, int16 argc, char* argn[], | 15 uint16 mode, int16 argc, char* argn[], |
| 26 char* argv[], NPSavedData* saved) { | 16 char* argv[], NPSavedData* saved) { |
| 27 if (!instance) | 17 if (!instance) |
| 28 return NPERR_INVALID_INSTANCE_ERROR; | 18 return NPERR_INVALID_INSTANCE_ERROR; |
| 29 | 19 |
| 30 PluginObject* plugin_object = | 20 return NPERR_NO_ERROR; |
| 31 NPPluginObjectFactory::get()->CreatePluginObject(instance, plugin_type); | |
| 32 if (!plugin_object) | |
| 33 return NPERR_GENERIC_ERROR; | |
| 34 | |
| 35 instance->pdata = plugin_object; | |
| 36 | |
| 37 NPError error = plugin_object->New(plugin_type, argc, argn, argv, saved); | |
| 38 if (error != NPERR_NO_ERROR) { | |
| 39 plugin_object->Release(); | |
| 40 } | |
| 41 | |
| 42 return error; | |
| 43 } | 21 } |
| 44 | 22 |
| 45 NPError NPP_Destroy(NPP instance, NPSavedData** saved) { | 23 NPError NPP_Destroy(NPP instance, NPSavedData** saved) { |
| 46 if (!instance) | 24 if (!instance) |
| 47 return NPERR_INVALID_INSTANCE_ERROR; | 25 return NPERR_INVALID_INSTANCE_ERROR; |
| 48 | 26 |
| 49 PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); | 27 return NPERR_NO_ERROR; |
| 50 NPError error = plugin_object->Destroy(saved); | |
| 51 | |
| 52 if (error == NPERR_NO_ERROR) { | |
| 53 plugin_object->Release(); | |
| 54 } | |
| 55 | |
| 56 return error; | |
| 57 } | 28 } |
| 58 | 29 |
| 59 NPError NPP_SetWindow(NPP instance, NPWindow* window) { | 30 NPError NPP_SetWindow(NPP instance, NPWindow* window) { |
| 60 if (!instance) | 31 return NPERR_NO_ERROR; |
| 61 return NPERR_INVALID_INSTANCE_ERROR; | |
| 62 | |
| 63 PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); | |
| 64 return plugin_object->SetWindow(window); | |
| 65 } | 32 } |
| 66 | 33 |
| 67 int16 NPP_HandleEvent(NPP instance, void* event) { | 34 int16 NPP_HandleEvent(NPP instance, void* event) { |
| 68 if (!instance) | 35 return 0; |
| 69 return 0; | |
| 70 | |
| 71 PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); | |
| 72 return plugin_object->HandleEvent(static_cast<NPEvent*>(event)); | |
| 73 } | 36 } |
| 74 | 37 |
| 75 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { | 38 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { |
| 76 if (!instance) | 39 if (!instance) |
| 77 return NPERR_INVALID_INSTANCE_ERROR; | 40 return NPERR_INVALID_INSTANCE_ERROR; |
| 78 | 41 |
| 79 PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); | 42 return NPERR_GENERIC_ERROR; |
| 80 switch (variable) { | |
| 81 case NPPVpluginScriptableNPObject: | |
| 82 *reinterpret_cast<NPObject**>(value) = | |
| 83 plugin_object->GetScriptableNPObject(); | |
| 84 return NPERR_NO_ERROR; | |
| 85 default: | |
| 86 return NPERR_GENERIC_ERROR; | |
| 87 } | |
| 88 } | 43 } |
| 89 | 44 |
| 90 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { | 45 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { |
| 91 return NPERR_NO_ERROR; | 46 return NPERR_NO_ERROR; |
| 92 } | 47 } |
| 93 } | 48 } |
| 94 | 49 |
| 95 NPError NP_GetEntryPoints(NPPluginFuncs* funcs) { | 50 NPError NP_GetEntryPoints(NPPluginFuncs* funcs) { |
| 96 funcs->newp = NPP_New; | 51 funcs->newp = NPP_New; |
| 97 funcs->destroy = NPP_Destroy; | 52 funcs->destroy = NPP_Destroy; |
| 98 funcs->setwindow = NPP_SetWindow; | 53 funcs->setwindow = NPP_SetWindow; |
| 99 funcs->event = NPP_HandleEvent; | 54 funcs->event = NPP_HandleEvent; |
| 100 funcs->getvalue = NPP_GetValue; | 55 funcs->getvalue = NPP_GetValue; |
| 101 funcs->setvalue = NPP_SetValue; | 56 funcs->setvalue = NPP_SetValue; |
| 102 return NPERR_NO_ERROR; | 57 return NPERR_NO_ERROR; |
| 103 } | 58 } |
| 104 | 59 |
| 105 #if defined(OS_LINUX) | 60 #if defined(OS_LINUX) |
| 106 NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs, | 61 NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs, |
| 107 NPPluginFuncs* plugin_funcs) { | 62 NPPluginFuncs* plugin_funcs) { |
| 108 #else | 63 #else |
| 109 NPError NP_Initialize(NPNetscapeFuncs *browser_funcs) { | 64 NPError NP_Initialize(NPNetscapeFuncs *browser_funcs) { |
| 110 #endif | 65 #endif |
| 111 if (!browser_funcs) | 66 if (!browser_funcs) |
| 112 return NPERR_INVALID_FUNCTABLE_ERROR; | 67 return NPERR_INVALID_FUNCTABLE_ERROR; |
| 113 | 68 |
| 114 if (g_browser) | |
| 115 return NPERR_GENERIC_ERROR; | |
| 116 | |
| 117 #if defined(OS_LINUX) | 69 #if defined(OS_LINUX) |
| 118 NP_GetEntryPoints(plugin_funcs); | 70 NP_GetEntryPoints(plugin_funcs); |
| 119 #endif | 71 #endif |
| 120 | 72 |
| 121 g_browser = new NPBrowser(browser_funcs); | |
| 122 | |
| 123 return NPERR_NO_ERROR; | 73 return NPERR_NO_ERROR; |
| 124 } | 74 } |
| 125 | 75 |
| 126 NPError NP_Shutdown() { | 76 NPError NP_Shutdown() { |
| 127 if (!g_browser) | |
| 128 return NPERR_GENERIC_ERROR; | |
| 129 | |
| 130 delete g_browser; | |
| 131 g_browser = NULL; | |
| 132 | |
| 133 return NPERR_NO_ERROR; | 77 return NPERR_NO_ERROR; |
| 134 } | 78 } |
| 135 } // namespace gpu_plugin | 79 } // namespace gpu_plugin |
| OLD | NEW |