1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/base/PluginPRLibrary.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,320 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=8 et : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/PluginPRLibrary.h" 1.11 +#include "nsNPAPIPluginInstance.h" 1.12 + 1.13 +// Some plugins on Windows, notably Quake Live, implement NP_Initialize using 1.14 +// cdecl instead of the documented stdcall. In order to work around this, 1.15 +// we force the caller to use a frame pointer. 1.16 +#if defined(XP_WIN) && defined(_M_IX86) 1.17 +#include <malloc.h> 1.18 + 1.19 +// gNotOptimized exists so that the compiler will not optimize the alloca 1.20 +// below. 1.21 +static int gNotOptimized; 1.22 +#define CALLING_CONVENTION_HACK void* foo = _alloca(gNotOptimized); 1.23 +#else 1.24 +#define CALLING_CONVENTION_HACK 1.25 +#endif 1.26 + 1.27 +#ifdef MOZ_WIDGET_ANDROID 1.28 +#include "AndroidBridge.h" 1.29 +#include "android_npapi.h" 1.30 +#include <android/log.h> 1.31 +#undef ALOG 1.32 +#define ALOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoJavaEnv", ## args) 1.33 +#endif 1.34 + 1.35 +using namespace mozilla::layers; 1.36 + 1.37 +namespace mozilla { 1.38 +#ifdef MOZ_WIDGET_ANDROID 1.39 +nsresult 1.40 +PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, 1.41 + NPPluginFuncs* pFuncs, NPError* error) 1.42 +{ 1.43 + JNIEnv* env = GetJNIForThread(); 1.44 + 1.45 + mozilla::AutoLocalJNIFrame jniFrame(env); 1.46 + 1.47 + if (mNP_Initialize) { 1.48 + *error = mNP_Initialize(bFuncs, pFuncs, env); 1.49 + } else { 1.50 + NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc) 1.51 + PR_FindFunctionSymbol(mLibrary, "NP_Initialize"); 1.52 + if (!pfNP_Initialize) 1.53 + return NS_ERROR_FAILURE; 1.54 + *error = pfNP_Initialize(bFuncs, pFuncs, env); 1.55 + } 1.56 + 1.57 + // Save pointers to functions that get called through PluginLibrary itself. 1.58 + mNPP_New = pFuncs->newp; 1.59 + mNPP_ClearSiteData = pFuncs->clearsitedata; 1.60 + mNPP_GetSitesWithData = pFuncs->getsiteswithdata; 1.61 + return NS_OK; 1.62 +} 1.63 +#elif defined(MOZ_WIDGET_GONK) 1.64 +nsresult 1.65 +PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error) 1.66 +{ 1.67 + return NS_OK; 1.68 +} 1.69 +#elif defined(XP_UNIX) && !defined(XP_MACOSX) 1.70 +nsresult 1.71 +PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, 1.72 + NPPluginFuncs* pFuncs, NPError* error) 1.73 +{ 1.74 + if (mNP_Initialize) { 1.75 + *error = mNP_Initialize(bFuncs, pFuncs); 1.76 + } else { 1.77 + NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc) 1.78 + PR_FindFunctionSymbol(mLibrary, "NP_Initialize"); 1.79 + if (!pfNP_Initialize) 1.80 + return NS_ERROR_FAILURE; 1.81 + *error = pfNP_Initialize(bFuncs, pFuncs); 1.82 + } 1.83 + 1.84 + 1.85 + // Save pointers to functions that get called through PluginLibrary itself. 1.86 + mNPP_New = pFuncs->newp; 1.87 + mNPP_ClearSiteData = pFuncs->clearsitedata; 1.88 + mNPP_GetSitesWithData = pFuncs->getsiteswithdata; 1.89 + return NS_OK; 1.90 +} 1.91 +#else 1.92 +nsresult 1.93 +PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error) 1.94 +{ 1.95 + CALLING_CONVENTION_HACK 1.96 + 1.97 + if (mNP_Initialize) { 1.98 + *error = mNP_Initialize(bFuncs); 1.99 + } else { 1.100 + NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc) 1.101 + PR_FindFunctionSymbol(mLibrary, "NP_Initialize"); 1.102 + if (!pfNP_Initialize) 1.103 + return NS_ERROR_FAILURE; 1.104 + *error = pfNP_Initialize(bFuncs); 1.105 + } 1.106 + 1.107 + return NS_OK; 1.108 +} 1.109 +#endif 1.110 + 1.111 +nsresult 1.112 +PluginPRLibrary::NP_Shutdown(NPError* error) 1.113 +{ 1.114 + CALLING_CONVENTION_HACK 1.115 + 1.116 + if (mNP_Shutdown) { 1.117 + *error = mNP_Shutdown(); 1.118 + } else { 1.119 + NP_ShutdownFunc pfNP_Shutdown = (NP_ShutdownFunc) 1.120 + PR_FindFunctionSymbol(mLibrary, "NP_Shutdown"); 1.121 + if (!pfNP_Shutdown) 1.122 + return NS_ERROR_FAILURE; 1.123 + *error = pfNP_Shutdown(); 1.124 + } 1.125 + 1.126 + return NS_OK; 1.127 +} 1.128 + 1.129 +nsresult 1.130 +PluginPRLibrary::NP_GetMIMEDescription(const char** mimeDesc) 1.131 +{ 1.132 + CALLING_CONVENTION_HACK 1.133 + 1.134 + if (mNP_GetMIMEDescription) { 1.135 + *mimeDesc = mNP_GetMIMEDescription(); 1.136 + } 1.137 + else { 1.138 + NP_GetMIMEDescriptionFunc pfNP_GetMIMEDescription = 1.139 + (NP_GetMIMEDescriptionFunc) 1.140 + PR_FindFunctionSymbol(mLibrary, "NP_GetMIMEDescription"); 1.141 + if (!pfNP_GetMIMEDescription) { 1.142 + *mimeDesc = ""; 1.143 + return NS_ERROR_FAILURE; 1.144 + } 1.145 + *mimeDesc = pfNP_GetMIMEDescription(); 1.146 + } 1.147 + 1.148 + return NS_OK; 1.149 +} 1.150 + 1.151 +nsresult 1.152 +PluginPRLibrary::NP_GetValue(void *future, NPPVariable aVariable, 1.153 + void *aValue, NPError* error) 1.154 +{ 1.155 +#if defined(XP_UNIX) && !defined(XP_MACOSX) 1.156 + if (mNP_GetValue) { 1.157 + *error = mNP_GetValue(future, aVariable, aValue); 1.158 + } else { 1.159 + NP_GetValueFunc pfNP_GetValue = (NP_GetValueFunc)PR_FindFunctionSymbol(mLibrary, "NP_GetValue"); 1.160 + if (!pfNP_GetValue) 1.161 + return NS_ERROR_FAILURE; 1.162 + *error = pfNP_GetValue(future, aVariable, aValue); 1.163 + } 1.164 + return NS_OK; 1.165 +#else 1.166 + return NS_ERROR_NOT_IMPLEMENTED; 1.167 +#endif 1.168 +} 1.169 + 1.170 +#if defined(XP_WIN) || defined(XP_MACOSX) 1.171 +nsresult 1.172 +PluginPRLibrary::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error) 1.173 +{ 1.174 + CALLING_CONVENTION_HACK 1.175 + 1.176 + if (mNP_GetEntryPoints) { 1.177 + *error = mNP_GetEntryPoints(pFuncs); 1.178 + } else { 1.179 + NP_GetEntryPointsFunc pfNP_GetEntryPoints = (NP_GetEntryPointsFunc) 1.180 + PR_FindFunctionSymbol(mLibrary, "NP_GetEntryPoints"); 1.181 + if (!pfNP_GetEntryPoints) 1.182 + return NS_ERROR_FAILURE; 1.183 + *error = pfNP_GetEntryPoints(pFuncs); 1.184 + } 1.185 + 1.186 + // Save pointers to functions that get called through PluginLibrary itself. 1.187 + mNPP_New = pFuncs->newp; 1.188 + mNPP_ClearSiteData = pFuncs->clearsitedata; 1.189 + mNPP_GetSitesWithData = pFuncs->getsiteswithdata; 1.190 + return NS_OK; 1.191 +} 1.192 +#endif 1.193 + 1.194 +nsresult 1.195 +PluginPRLibrary::NPP_New(NPMIMEType pluginType, NPP instance, 1.196 + uint16_t mode, int16_t argc, char* argn[], 1.197 + char* argv[], NPSavedData* saved, 1.198 + NPError* error) 1.199 +{ 1.200 + if (!mNPP_New) 1.201 + return NS_ERROR_FAILURE; 1.202 + 1.203 + MAIN_THREAD_JNI_REF_GUARD; 1.204 + *error = mNPP_New(pluginType, instance, mode, argc, argn, argv, saved); 1.205 + return NS_OK; 1.206 +} 1.207 + 1.208 +nsresult 1.209 +PluginPRLibrary::NPP_ClearSiteData(const char* site, uint64_t flags, 1.210 + uint64_t maxAge) 1.211 +{ 1.212 + if (!mNPP_ClearSiteData) { 1.213 + return NS_ERROR_NOT_AVAILABLE; 1.214 + } 1.215 + 1.216 + MAIN_THREAD_JNI_REF_GUARD; 1.217 + NPError result = mNPP_ClearSiteData(site, flags, maxAge); 1.218 + 1.219 + switch (result) { 1.220 + case NPERR_NO_ERROR: 1.221 + return NS_OK; 1.222 + case NPERR_TIME_RANGE_NOT_SUPPORTED: 1.223 + return NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED; 1.224 + case NPERR_MALFORMED_SITE: 1.225 + return NS_ERROR_INVALID_ARG; 1.226 + default: 1.227 + return NS_ERROR_FAILURE; 1.228 + } 1.229 +} 1.230 + 1.231 +nsresult 1.232 +PluginPRLibrary::NPP_GetSitesWithData(InfallibleTArray<nsCString>& result) 1.233 +{ 1.234 + if (!mNPP_GetSitesWithData) { 1.235 + return NS_ERROR_NOT_AVAILABLE; 1.236 + } 1.237 + 1.238 + result.Clear(); 1.239 + 1.240 + MAIN_THREAD_JNI_REF_GUARD; 1.241 + char** sites = mNPP_GetSitesWithData(); 1.242 + if (!sites) { 1.243 + return NS_OK; 1.244 + } 1.245 + 1.246 + char** iterator = sites; 1.247 + while (*iterator) { 1.248 + result.AppendElement(*iterator); 1.249 + NS_Free(*iterator); 1.250 + ++iterator; 1.251 + } 1.252 + NS_Free(sites); 1.253 + 1.254 + return NS_OK; 1.255 +} 1.256 + 1.257 +nsresult 1.258 +PluginPRLibrary::AsyncSetWindow(NPP instance, NPWindow* window) 1.259 +{ 1.260 + nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata; 1.261 + NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER); 1.262 + return NS_ERROR_NOT_IMPLEMENTED; 1.263 +} 1.264 + 1.265 +nsresult 1.266 +PluginPRLibrary::GetImageContainer(NPP instance, ImageContainer** aContainer) 1.267 +{ 1.268 + return NS_ERROR_NOT_IMPLEMENTED; 1.269 +} 1.270 + 1.271 +#if defined(XP_MACOSX) 1.272 +nsresult 1.273 +PluginPRLibrary::IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing) 1.274 +{ 1.275 + nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata; 1.276 + NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER); 1.277 + *aDrawing = false; 1.278 + return NS_OK; 1.279 +} 1.280 +nsresult 1.281 +PluginPRLibrary::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor) 1.282 +{ 1.283 + nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata; 1.284 + NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER); 1.285 + return NS_OK; 1.286 +} 1.287 +#endif 1.288 + 1.289 +nsresult 1.290 +PluginPRLibrary::GetImageSize(NPP instance, nsIntSize* aSize) 1.291 +{ 1.292 + return NS_ERROR_NOT_IMPLEMENTED; 1.293 +} 1.294 + 1.295 +nsresult 1.296 +PluginPRLibrary::SetBackgroundUnknown(NPP instance) 1.297 +{ 1.298 + nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata; 1.299 + NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER); 1.300 + NS_ERROR("Unexpected use of async APIs for in-process plugin."); 1.301 + return NS_ERROR_NOT_IMPLEMENTED; 1.302 +} 1.303 + 1.304 +nsresult 1.305 +PluginPRLibrary::BeginUpdateBackground(NPP instance, 1.306 + const nsIntRect&, gfxContext** aCtx) 1.307 +{ 1.308 + nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata; 1.309 + NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER); 1.310 + NS_ERROR("Unexpected use of async APIs for in-process plugin."); 1.311 + *aCtx = nullptr; 1.312 + return NS_OK; 1.313 +} 1.314 + 1.315 +nsresult 1.316 +PluginPRLibrary::EndUpdateBackground(NPP instance, 1.317 + gfxContext*, const nsIntRect&) 1.318 +{ 1.319 + NS_RUNTIMEABORT("This should never be called"); 1.320 + return NS_ERROR_NOT_AVAILABLE; 1.321 +} 1.322 + 1.323 +} // namespace mozilla