Files
palemoon27/dom/plugins/base/PluginPRLibrary.cpp
T
roytam1 c317230594 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1242724: add an export of runnable_utils.h unless/until it gets moved to xpcom/mfbt r=glandium (1d5e839f99)
- Bug 1223240 - Make it easier to set up top-level protocols (r=jld) (3beaf4a6fa)
- Bug 1194259: Make ICE IP restriction to default routes work in E10S r=jesup,mcmanus,drno (cbe463cf27)
- Bug 1239584, Part 1 - Add nsIPushNotifier and nsIPushMessage interfaces. r=dragana (7b71518e7d)
- Bug 1239584, Part 2 - Remove message manager usage from `PushService.jsm`. r=dragana (f76ab36278)
- Bug 1210211 - Part 3: Test for push notification quota with web notifications. r=kitcambridge (f37472f9b2)
- Bug 1189998, Part 3 - Update consolidated Push tests. r=mt (fae3b02e6e)
- Bug 1225968 - Refactor data delivery tests to support addition of new tests, r=kitcambridge (3163083135)
- Bug 1225968 - Adding more messages to the push message tests, r=kitcambridge (7e1bac99ba)
- Bug 1239558 - Exempt system Push subscriptions from quota and permissions checks. r=dragana (0dd8399414)
- Bug 1239584, Part 3 - Update tests. r=dragana (937e339387)
- Bug 1165256 - Make appcache fully work with OriginAttribues. r=jduell (91d666752a)
- reapply Bug 1232506: Make dom/devicestorage really work with e10s. r=alchen (bd77941ea9)
- Bug 1236433 - Part 1: Provide a Native Wrapper to Allow Fallback Whenproperty_get/set is Unavailable; r=edgar (f9026a7f50)
- Bug 1168959 - Memory-safety bugs in NetworkUtils.cpp generally. r=fabrice (13c6c14168)
- Bug 1236433 - Part 2: Adopt Wrapper in Network Utilities; r=edgar (dde58ea083)
- Bug 1209654 - Modify the type of the threshold of addAlarm() and getAllAlarms() to long long from long, and add test cases. r=ettseng, r=bz (79c7e31440)
- Bug 1000040 - Part 1: Add required APIs for Ethernet; r=vicamo,bholley (fcff7c8078)
- Bug 1231306 - Handle plugin state changes correctly in content process (r=jimm) (1f2daa6ad4)
- Bug 1213454: Ensure that mSupportsAsyncInit is propagated from content process; r=jimm (e86f36fe0a)
- Bug 1246574 - Store sandbox level to nsPluginTag for e10s. r=jimm (04617c8d28)
- Bug 1201904 - Force windowless mode for Flash when sandbox level >= 2. r=bsmedberg (662c6612a2)
- Bug 1233619 (part 1) - Remove unneeded gfxContext argument from EndUpdate() and EndUpdateBackground() functions. r=roc. (1f74728aec)
- Bug 1233619 (part 2) - Moz2Dify BeginUpdate() and BeginUpdateBackground() functions. r=roc. (36accc1499)
- Bug 1243656 - Use async for RequestCommitOrCancel. r=masayuki (aa57ea37dc)
- Bug 1243268 - Support ImmSetCandidateWindow(CFS_EXCLUDE) on plugin process. r=masayuki (78975bd3e4)
- Bug 1235573 - Don't post GCS_RESULTSTR when plugin doesn't handle WM_IME_COMPOSITION correctly. r=masayuki (11690062a3)
- Bug 1173371 Part 1: Take Chromium commit 0e49d029d5a1a25d971880b9e44d67ac70b31a80 for sandbox code. r=aklotz (517cb91822)
- Bug 1157864 - Record chromium patch applied in previous commit. r=me (dc1e63191b)
- Bug 1173371 Part 2: Change Chromium sandbox to allow rules for files on network drives to be added. a=aklotz (2bd72777e5)
- Bug 1173371 Part 3: Add sandbox policy rule to allow read access to the Firefox program directory when it is on a network drive. r=aklotz (c0a180d4b8)
- Bug 1244774: Correct wchar_t/char16_t VS2015 compilation problem caused by patches for bug 1173371. r=jimm (d5326694f8)
2023-08-17 14:45:22 +08:00

320 lines
8.3 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/PluginPRLibrary.h"
#include "nsNPAPIPluginInstance.h"
// Some plugins on Windows, notably Quake Live, implement NP_Initialize using
// cdecl instead of the documented stdcall. In order to work around this,
// we force the caller to use a frame pointer.
#if defined(XP_WIN) && defined(_M_IX86)
#include <malloc.h>
// gNotOptimized exists so that the compiler will not optimize the alloca
// below.
static int gNotOptimized;
#define CALLING_CONVENTION_HACK void* foo = _alloca(gNotOptimized);
#else
#define CALLING_CONVENTION_HACK
#endif
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
#include "android_npapi.h"
#include <android/log.h>
#undef ALOG
#define ALOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoJavaEnv", ## args)
#endif
using namespace mozilla::layers;
namespace mozilla {
#ifdef MOZ_WIDGET_ANDROID
nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
NPPluginFuncs* pFuncs, NPError* error)
{
JNIEnv* env = jni::GetEnvForThread();
mozilla::AutoLocalJNIFrame jniFrame(env);
if (mNP_Initialize) {
*error = mNP_Initialize(bFuncs, pFuncs, env);
} else {
NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
if (!pfNP_Initialize)
return NS_ERROR_FAILURE;
*error = pfNP_Initialize(bFuncs, pFuncs, env);
}
// Save pointers to functions that get called through PluginLibrary itself.
mNPP_New = pFuncs->newp;
mNPP_ClearSiteData = pFuncs->clearsitedata;
mNPP_GetSitesWithData = pFuncs->getsiteswithdata;
return NS_OK;
}
#elif defined(MOZ_WIDGET_GONK)
nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
{
return NS_OK;
}
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
NPPluginFuncs* pFuncs, NPError* error)
{
if (mNP_Initialize) {
*error = mNP_Initialize(bFuncs, pFuncs);
} else {
NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
if (!pfNP_Initialize)
return NS_ERROR_FAILURE;
*error = pfNP_Initialize(bFuncs, pFuncs);
}
// Save pointers to functions that get called through PluginLibrary itself.
mNPP_New = pFuncs->newp;
mNPP_ClearSiteData = pFuncs->clearsitedata;
mNPP_GetSitesWithData = pFuncs->getsiteswithdata;
return NS_OK;
}
#else
nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
{
CALLING_CONVENTION_HACK
if (mNP_Initialize) {
*error = mNP_Initialize(bFuncs);
} else {
NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
if (!pfNP_Initialize)
return NS_ERROR_FAILURE;
*error = pfNP_Initialize(bFuncs);
}
return NS_OK;
}
#endif
nsresult
PluginPRLibrary::NP_Shutdown(NPError* error)
{
CALLING_CONVENTION_HACK
if (mNP_Shutdown) {
*error = mNP_Shutdown();
} else {
NP_ShutdownFunc pfNP_Shutdown = (NP_ShutdownFunc)
PR_FindFunctionSymbol(mLibrary, "NP_Shutdown");
if (!pfNP_Shutdown)
return NS_ERROR_FAILURE;
*error = pfNP_Shutdown();
}
return NS_OK;
}
nsresult
PluginPRLibrary::NP_GetMIMEDescription(const char** mimeDesc)
{
CALLING_CONVENTION_HACK
if (mNP_GetMIMEDescription) {
*mimeDesc = mNP_GetMIMEDescription();
}
else {
NP_GetMIMEDescriptionFunc pfNP_GetMIMEDescription =
(NP_GetMIMEDescriptionFunc)
PR_FindFunctionSymbol(mLibrary, "NP_GetMIMEDescription");
if (!pfNP_GetMIMEDescription) {
*mimeDesc = "";
return NS_ERROR_FAILURE;
}
*mimeDesc = pfNP_GetMIMEDescription();
}
return NS_OK;
}
nsresult
PluginPRLibrary::NP_GetValue(void *future, NPPVariable aVariable,
void *aValue, NPError* error)
{
#if defined(XP_UNIX) && !defined(XP_MACOSX)
if (mNP_GetValue) {
*error = mNP_GetValue(future, aVariable, aValue);
} else {
NP_GetValueFunc pfNP_GetValue = (NP_GetValueFunc)PR_FindFunctionSymbol(mLibrary, "NP_GetValue");
if (!pfNP_GetValue)
return NS_ERROR_FAILURE;
*error = pfNP_GetValue(future, aVariable, aValue);
}
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
#if defined(XP_WIN) || defined(XP_MACOSX)
nsresult
PluginPRLibrary::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error)
{
CALLING_CONVENTION_HACK
if (mNP_GetEntryPoints) {
*error = mNP_GetEntryPoints(pFuncs);
} else {
NP_GetEntryPointsFunc pfNP_GetEntryPoints = (NP_GetEntryPointsFunc)
PR_FindFunctionSymbol(mLibrary, "NP_GetEntryPoints");
if (!pfNP_GetEntryPoints)
return NS_ERROR_FAILURE;
*error = pfNP_GetEntryPoints(pFuncs);
}
// Save pointers to functions that get called through PluginLibrary itself.
mNPP_New = pFuncs->newp;
mNPP_ClearSiteData = pFuncs->clearsitedata;
mNPP_GetSitesWithData = pFuncs->getsiteswithdata;
return NS_OK;
}
#endif
nsresult
PluginPRLibrary::NPP_New(NPMIMEType pluginType, NPP instance,
uint16_t mode, int16_t argc, char* argn[],
char* argv[], NPSavedData* saved,
NPError* error)
{
if (!mNPP_New)
return NS_ERROR_FAILURE;
MAIN_THREAD_JNI_REF_GUARD;
*error = mNPP_New(pluginType, instance, mode, argc, argn, argv, saved);
return NS_OK;
}
nsresult
PluginPRLibrary::NPP_ClearSiteData(const char* site, uint64_t flags,
uint64_t maxAge)
{
if (!mNPP_ClearSiteData) {
return NS_ERROR_NOT_AVAILABLE;
}
MAIN_THREAD_JNI_REF_GUARD;
NPError result = mNPP_ClearSiteData(site, flags, maxAge);
switch (result) {
case NPERR_NO_ERROR:
return NS_OK;
case NPERR_TIME_RANGE_NOT_SUPPORTED:
return NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED;
case NPERR_MALFORMED_SITE:
return NS_ERROR_INVALID_ARG;
default:
return NS_ERROR_FAILURE;
}
}
nsresult
PluginPRLibrary::NPP_GetSitesWithData(InfallibleTArray<nsCString>& result)
{
if (!mNPP_GetSitesWithData) {
return NS_ERROR_NOT_AVAILABLE;
}
result.Clear();
MAIN_THREAD_JNI_REF_GUARD;
char** sites = mNPP_GetSitesWithData();
if (!sites) {
return NS_OK;
}
char** iterator = sites;
while (*iterator) {
result.AppendElement(*iterator);
NS_Free(*iterator);
++iterator;
}
NS_Free(sites);
return NS_OK;
}
nsresult
PluginPRLibrary::AsyncSetWindow(NPP instance, NPWindow* window)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
PluginPRLibrary::GetImageContainer(NPP instance, ImageContainer** aContainer)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#if defined(XP_MACOSX)
nsresult
PluginPRLibrary::IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
*aDrawing = false;
return NS_OK;
}
nsresult
PluginPRLibrary::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
return NS_OK;
}
#endif
nsresult
PluginPRLibrary::GetImageSize(NPP instance, nsIntSize* aSize)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
PluginPRLibrary::SetBackgroundUnknown(NPP instance)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
NS_ERROR("Unexpected use of async APIs for in-process plugin.");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
PluginPRLibrary::BeginUpdateBackground(NPP instance, const nsIntRect&,
DrawTarget** aDrawTarget)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
NS_ERROR("Unexpected use of async APIs for in-process plugin.");
*aDrawTarget = nullptr;
return NS_OK;
}
nsresult
PluginPRLibrary::EndUpdateBackground(NPP instance, const nsIntRect&)
{
NS_RUNTIMEABORT("This should never be called");
return NS_ERROR_NOT_AVAILABLE;
}
} // namespace mozilla