[JAEGER] Merge from tracemonkey.
[mozilla-central.git] / modules / plugin / base / src / PluginPRLibrary.cpp
blob13d1981367b516e3d421d1e1ebffdf1dfc487000
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=8 et :
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Plugin App.
18 * The Initial Developer of the Original Code is
19 * Josh Aas <josh@mozilla.com>
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "mozilla/PluginPRLibrary.h"
41 // Some plugins on Windows, notably Quake Live, implement NP_Initialize using
42 // cdecl instead of the documented stdcall. In order to work around this,
43 // we force the caller to use a frame pointer.
44 #if defined(XP_WIN) && defined(_M_IX86)
45 #include <malloc.h>
47 // gNotOptimized exists so that the compiler will not optimize the alloca
48 // below.
49 static int gNotOptimized;
50 #define CALLING_CONVENTION_HACK void* foo = _alloca(gNotOptimized);
51 #else
52 #define CALLING_CONVENTION_HACK
53 #endif
55 namespace mozilla {
57 #if defined(XP_UNIX) && !defined(XP_MACOSX)
58 nsresult
59 PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
60 NPPluginFuncs* pFuncs, NPError* error)
62 if (mNP_Initialize) {
63 *error = mNP_Initialize(bFuncs, pFuncs);
64 } else {
65 NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
66 PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
67 if (!pfNP_Initialize)
68 return NS_ERROR_FAILURE;
69 *error = pfNP_Initialize(bFuncs, pFuncs);
72 // save NPP_New
73 mNPP_New = pFuncs->newp;
74 return NS_OK;
76 #else
77 nsresult
78 PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
80 CALLING_CONVENTION_HACK
82 if (mNP_Initialize) {
83 *error = mNP_Initialize(bFuncs);
84 } else {
85 NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
86 PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
87 if (!pfNP_Initialize)
88 return NS_ERROR_FAILURE;
89 *error = pfNP_Initialize(bFuncs);
92 return NS_OK;
94 #endif
96 nsresult
97 PluginPRLibrary::NP_Shutdown(NPError* error)
99 CALLING_CONVENTION_HACK
101 if (mNP_Shutdown) {
102 *error = mNP_Shutdown();
103 } else {
104 NP_ShutdownFunc pfNP_Shutdown = (NP_ShutdownFunc)
105 PR_FindFunctionSymbol(mLibrary, "NP_Shutdown");
106 if (!pfNP_Shutdown)
107 return NS_ERROR_FAILURE;
108 *error = pfNP_Shutdown();
111 return NS_OK;
114 nsresult
115 PluginPRLibrary::NP_GetMIMEDescription(const char** mimeDesc)
117 CALLING_CONVENTION_HACK
119 if (mNP_GetMIMEDescription) {
120 *mimeDesc = mNP_GetMIMEDescription();
122 else {
123 NP_GetMIMEDescriptionFunc pfNP_GetMIMEDescription =
124 (NP_GetMIMEDescriptionFunc)
125 PR_FindFunctionSymbol(mLibrary, "NP_GetMIMEDescription");
126 if (!pfNP_GetMIMEDescription) {
127 *mimeDesc = "";
128 return NS_ERROR_FAILURE;
130 *mimeDesc = pfNP_GetMIMEDescription();
133 return NS_OK;
136 nsresult
137 PluginPRLibrary::NP_GetValue(void *future, NPPVariable aVariable,
138 void *aValue, NPError* error)
140 if (mNP_GetValue) {
141 *error = mNP_GetValue(future, aVariable, aValue);
142 } else {
143 NP_GetValueFunc pfNP_GetValue = (NP_GetValueFunc)
144 PR_FindFunctionSymbol(mLibrary, "NP_GetValue");
145 if (!pfNP_GetValue)
146 return NS_ERROR_FAILURE;
147 *error = pfNP_GetValue(future, aVariable, aValue);
150 return NS_OK;
153 #if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_OS2)
154 nsresult
155 PluginPRLibrary::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error)
157 CALLING_CONVENTION_HACK
159 if (mNP_GetEntryPoints) {
160 *error = mNP_GetEntryPoints(pFuncs);
161 } else {
162 NP_GetEntryPointsFunc pfNP_GetEntryPoints = (NP_GetEntryPointsFunc)
163 PR_FindFunctionSymbol(mLibrary, "NP_GetEntryPoints");
164 if (!pfNP_GetEntryPoints)
165 return NS_ERROR_FAILURE;
166 *error = pfNP_GetEntryPoints(pFuncs);
169 // save NPP_New
170 mNPP_New = pFuncs->newp;
171 return NS_OK;
173 #endif
175 nsresult
176 PluginPRLibrary::NPP_New(NPMIMEType pluginType, NPP instance,
177 uint16_t mode, int16_t argc, char* argn[],
178 char* argv[], NPSavedData* saved,
179 NPError* error)
181 if (!mNPP_New)
182 return NS_ERROR_FAILURE;
183 *error = mNPP_New(pluginType, instance, mode, argc, argn, argv, saved);
184 return NS_OK;
187 } // namespace mozilla