dom/plugins/base/PluginPRLibrary.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "mozilla/PluginPRLibrary.h"
michael@0 8 #include "nsNPAPIPluginInstance.h"
michael@0 9
michael@0 10 // Some plugins on Windows, notably Quake Live, implement NP_Initialize using
michael@0 11 // cdecl instead of the documented stdcall. In order to work around this,
michael@0 12 // we force the caller to use a frame pointer.
michael@0 13 #if defined(XP_WIN) && defined(_M_IX86)
michael@0 14 #include <malloc.h>
michael@0 15
michael@0 16 // gNotOptimized exists so that the compiler will not optimize the alloca
michael@0 17 // below.
michael@0 18 static int gNotOptimized;
michael@0 19 #define CALLING_CONVENTION_HACK void* foo = _alloca(gNotOptimized);
michael@0 20 #else
michael@0 21 #define CALLING_CONVENTION_HACK
michael@0 22 #endif
michael@0 23
michael@0 24 #ifdef MOZ_WIDGET_ANDROID
michael@0 25 #include "AndroidBridge.h"
michael@0 26 #include "android_npapi.h"
michael@0 27 #include <android/log.h>
michael@0 28 #undef ALOG
michael@0 29 #define ALOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoJavaEnv", ## args)
michael@0 30 #endif
michael@0 31
michael@0 32 using namespace mozilla::layers;
michael@0 33
michael@0 34 namespace mozilla {
michael@0 35 #ifdef MOZ_WIDGET_ANDROID
michael@0 36 nsresult
michael@0 37 PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
michael@0 38 NPPluginFuncs* pFuncs, NPError* error)
michael@0 39 {
michael@0 40 JNIEnv* env = GetJNIForThread();
michael@0 41
michael@0 42 mozilla::AutoLocalJNIFrame jniFrame(env);
michael@0 43
michael@0 44 if (mNP_Initialize) {
michael@0 45 *error = mNP_Initialize(bFuncs, pFuncs, env);
michael@0 46 } else {
michael@0 47 NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
michael@0 48 PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
michael@0 49 if (!pfNP_Initialize)
michael@0 50 return NS_ERROR_FAILURE;
michael@0 51 *error = pfNP_Initialize(bFuncs, pFuncs, env);
michael@0 52 }
michael@0 53
michael@0 54 // Save pointers to functions that get called through PluginLibrary itself.
michael@0 55 mNPP_New = pFuncs->newp;
michael@0 56 mNPP_ClearSiteData = pFuncs->clearsitedata;
michael@0 57 mNPP_GetSitesWithData = pFuncs->getsiteswithdata;
michael@0 58 return NS_OK;
michael@0 59 }
michael@0 60 #elif defined(MOZ_WIDGET_GONK)
michael@0 61 nsresult
michael@0 62 PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
michael@0 63 {
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66 #elif defined(XP_UNIX) && !defined(XP_MACOSX)
michael@0 67 nsresult
michael@0 68 PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
michael@0 69 NPPluginFuncs* pFuncs, NPError* error)
michael@0 70 {
michael@0 71 if (mNP_Initialize) {
michael@0 72 *error = mNP_Initialize(bFuncs, pFuncs);
michael@0 73 } else {
michael@0 74 NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
michael@0 75 PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
michael@0 76 if (!pfNP_Initialize)
michael@0 77 return NS_ERROR_FAILURE;
michael@0 78 *error = pfNP_Initialize(bFuncs, pFuncs);
michael@0 79 }
michael@0 80
michael@0 81
michael@0 82 // Save pointers to functions that get called through PluginLibrary itself.
michael@0 83 mNPP_New = pFuncs->newp;
michael@0 84 mNPP_ClearSiteData = pFuncs->clearsitedata;
michael@0 85 mNPP_GetSitesWithData = pFuncs->getsiteswithdata;
michael@0 86 return NS_OK;
michael@0 87 }
michael@0 88 #else
michael@0 89 nsresult
michael@0 90 PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
michael@0 91 {
michael@0 92 CALLING_CONVENTION_HACK
michael@0 93
michael@0 94 if (mNP_Initialize) {
michael@0 95 *error = mNP_Initialize(bFuncs);
michael@0 96 } else {
michael@0 97 NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
michael@0 98 PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
michael@0 99 if (!pfNP_Initialize)
michael@0 100 return NS_ERROR_FAILURE;
michael@0 101 *error = pfNP_Initialize(bFuncs);
michael@0 102 }
michael@0 103
michael@0 104 return NS_OK;
michael@0 105 }
michael@0 106 #endif
michael@0 107
michael@0 108 nsresult
michael@0 109 PluginPRLibrary::NP_Shutdown(NPError* error)
michael@0 110 {
michael@0 111 CALLING_CONVENTION_HACK
michael@0 112
michael@0 113 if (mNP_Shutdown) {
michael@0 114 *error = mNP_Shutdown();
michael@0 115 } else {
michael@0 116 NP_ShutdownFunc pfNP_Shutdown = (NP_ShutdownFunc)
michael@0 117 PR_FindFunctionSymbol(mLibrary, "NP_Shutdown");
michael@0 118 if (!pfNP_Shutdown)
michael@0 119 return NS_ERROR_FAILURE;
michael@0 120 *error = pfNP_Shutdown();
michael@0 121 }
michael@0 122
michael@0 123 return NS_OK;
michael@0 124 }
michael@0 125
michael@0 126 nsresult
michael@0 127 PluginPRLibrary::NP_GetMIMEDescription(const char** mimeDesc)
michael@0 128 {
michael@0 129 CALLING_CONVENTION_HACK
michael@0 130
michael@0 131 if (mNP_GetMIMEDescription) {
michael@0 132 *mimeDesc = mNP_GetMIMEDescription();
michael@0 133 }
michael@0 134 else {
michael@0 135 NP_GetMIMEDescriptionFunc pfNP_GetMIMEDescription =
michael@0 136 (NP_GetMIMEDescriptionFunc)
michael@0 137 PR_FindFunctionSymbol(mLibrary, "NP_GetMIMEDescription");
michael@0 138 if (!pfNP_GetMIMEDescription) {
michael@0 139 *mimeDesc = "";
michael@0 140 return NS_ERROR_FAILURE;
michael@0 141 }
michael@0 142 *mimeDesc = pfNP_GetMIMEDescription();
michael@0 143 }
michael@0 144
michael@0 145 return NS_OK;
michael@0 146 }
michael@0 147
michael@0 148 nsresult
michael@0 149 PluginPRLibrary::NP_GetValue(void *future, NPPVariable aVariable,
michael@0 150 void *aValue, NPError* error)
michael@0 151 {
michael@0 152 #if defined(XP_UNIX) && !defined(XP_MACOSX)
michael@0 153 if (mNP_GetValue) {
michael@0 154 *error = mNP_GetValue(future, aVariable, aValue);
michael@0 155 } else {
michael@0 156 NP_GetValueFunc pfNP_GetValue = (NP_GetValueFunc)PR_FindFunctionSymbol(mLibrary, "NP_GetValue");
michael@0 157 if (!pfNP_GetValue)
michael@0 158 return NS_ERROR_FAILURE;
michael@0 159 *error = pfNP_GetValue(future, aVariable, aValue);
michael@0 160 }
michael@0 161 return NS_OK;
michael@0 162 #else
michael@0 163 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 164 #endif
michael@0 165 }
michael@0 166
michael@0 167 #if defined(XP_WIN) || defined(XP_MACOSX)
michael@0 168 nsresult
michael@0 169 PluginPRLibrary::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error)
michael@0 170 {
michael@0 171 CALLING_CONVENTION_HACK
michael@0 172
michael@0 173 if (mNP_GetEntryPoints) {
michael@0 174 *error = mNP_GetEntryPoints(pFuncs);
michael@0 175 } else {
michael@0 176 NP_GetEntryPointsFunc pfNP_GetEntryPoints = (NP_GetEntryPointsFunc)
michael@0 177 PR_FindFunctionSymbol(mLibrary, "NP_GetEntryPoints");
michael@0 178 if (!pfNP_GetEntryPoints)
michael@0 179 return NS_ERROR_FAILURE;
michael@0 180 *error = pfNP_GetEntryPoints(pFuncs);
michael@0 181 }
michael@0 182
michael@0 183 // Save pointers to functions that get called through PluginLibrary itself.
michael@0 184 mNPP_New = pFuncs->newp;
michael@0 185 mNPP_ClearSiteData = pFuncs->clearsitedata;
michael@0 186 mNPP_GetSitesWithData = pFuncs->getsiteswithdata;
michael@0 187 return NS_OK;
michael@0 188 }
michael@0 189 #endif
michael@0 190
michael@0 191 nsresult
michael@0 192 PluginPRLibrary::NPP_New(NPMIMEType pluginType, NPP instance,
michael@0 193 uint16_t mode, int16_t argc, char* argn[],
michael@0 194 char* argv[], NPSavedData* saved,
michael@0 195 NPError* error)
michael@0 196 {
michael@0 197 if (!mNPP_New)
michael@0 198 return NS_ERROR_FAILURE;
michael@0 199
michael@0 200 MAIN_THREAD_JNI_REF_GUARD;
michael@0 201 *error = mNPP_New(pluginType, instance, mode, argc, argn, argv, saved);
michael@0 202 return NS_OK;
michael@0 203 }
michael@0 204
michael@0 205 nsresult
michael@0 206 PluginPRLibrary::NPP_ClearSiteData(const char* site, uint64_t flags,
michael@0 207 uint64_t maxAge)
michael@0 208 {
michael@0 209 if (!mNPP_ClearSiteData) {
michael@0 210 return NS_ERROR_NOT_AVAILABLE;
michael@0 211 }
michael@0 212
michael@0 213 MAIN_THREAD_JNI_REF_GUARD;
michael@0 214 NPError result = mNPP_ClearSiteData(site, flags, maxAge);
michael@0 215
michael@0 216 switch (result) {
michael@0 217 case NPERR_NO_ERROR:
michael@0 218 return NS_OK;
michael@0 219 case NPERR_TIME_RANGE_NOT_SUPPORTED:
michael@0 220 return NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED;
michael@0 221 case NPERR_MALFORMED_SITE:
michael@0 222 return NS_ERROR_INVALID_ARG;
michael@0 223 default:
michael@0 224 return NS_ERROR_FAILURE;
michael@0 225 }
michael@0 226 }
michael@0 227
michael@0 228 nsresult
michael@0 229 PluginPRLibrary::NPP_GetSitesWithData(InfallibleTArray<nsCString>& result)
michael@0 230 {
michael@0 231 if (!mNPP_GetSitesWithData) {
michael@0 232 return NS_ERROR_NOT_AVAILABLE;
michael@0 233 }
michael@0 234
michael@0 235 result.Clear();
michael@0 236
michael@0 237 MAIN_THREAD_JNI_REF_GUARD;
michael@0 238 char** sites = mNPP_GetSitesWithData();
michael@0 239 if (!sites) {
michael@0 240 return NS_OK;
michael@0 241 }
michael@0 242
michael@0 243 char** iterator = sites;
michael@0 244 while (*iterator) {
michael@0 245 result.AppendElement(*iterator);
michael@0 246 NS_Free(*iterator);
michael@0 247 ++iterator;
michael@0 248 }
michael@0 249 NS_Free(sites);
michael@0 250
michael@0 251 return NS_OK;
michael@0 252 }
michael@0 253
michael@0 254 nsresult
michael@0 255 PluginPRLibrary::AsyncSetWindow(NPP instance, NPWindow* window)
michael@0 256 {
michael@0 257 nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
michael@0 258 NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
michael@0 259 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 260 }
michael@0 261
michael@0 262 nsresult
michael@0 263 PluginPRLibrary::GetImageContainer(NPP instance, ImageContainer** aContainer)
michael@0 264 {
michael@0 265 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 266 }
michael@0 267
michael@0 268 #if defined(XP_MACOSX)
michael@0 269 nsresult
michael@0 270 PluginPRLibrary::IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing)
michael@0 271 {
michael@0 272 nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
michael@0 273 NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
michael@0 274 *aDrawing = false;
michael@0 275 return NS_OK;
michael@0 276 }
michael@0 277 nsresult
michael@0 278 PluginPRLibrary::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor)
michael@0 279 {
michael@0 280 nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
michael@0 281 NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
michael@0 282 return NS_OK;
michael@0 283 }
michael@0 284 #endif
michael@0 285
michael@0 286 nsresult
michael@0 287 PluginPRLibrary::GetImageSize(NPP instance, nsIntSize* aSize)
michael@0 288 {
michael@0 289 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 290 }
michael@0 291
michael@0 292 nsresult
michael@0 293 PluginPRLibrary::SetBackgroundUnknown(NPP instance)
michael@0 294 {
michael@0 295 nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
michael@0 296 NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
michael@0 297 NS_ERROR("Unexpected use of async APIs for in-process plugin.");
michael@0 298 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 299 }
michael@0 300
michael@0 301 nsresult
michael@0 302 PluginPRLibrary::BeginUpdateBackground(NPP instance,
michael@0 303 const nsIntRect&, gfxContext** aCtx)
michael@0 304 {
michael@0 305 nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
michael@0 306 NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
michael@0 307 NS_ERROR("Unexpected use of async APIs for in-process plugin.");
michael@0 308 *aCtx = nullptr;
michael@0 309 return NS_OK;
michael@0 310 }
michael@0 311
michael@0 312 nsresult
michael@0 313 PluginPRLibrary::EndUpdateBackground(NPP instance,
michael@0 314 gfxContext*, const nsIntRect&)
michael@0 315 {
michael@0 316 NS_RUNTIMEABORT("This should never be called");
michael@0 317 return NS_ERROR_NOT_AVAILABLE;
michael@0 318 }
michael@0 319
michael@0 320 } // namespace mozilla

mercurial