Issue #1829 - Revert "Issue #1751"

This commit is contained in:
Brian Smith 2022-04-26 11:34:08 -05:00 • committed by roytam1
commit 13fcc4a046
949 changed files with 95662 additions and 444 deletions

View file

@ -24,7 +24,7 @@ static int gNotOptimized;
using namespace mozilla::layers;
namespace mozilla {
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
NPPluginFuncs* pFuncs, NPError* error)
@ -110,7 +110,7 @@ nsresult
PluginPRLibrary::NP_GetValue(void *future, NPPVariable aVariable,
void *aValue, NPError* error)
{
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
if (mNP_GetValue) {
*error = mNP_GetValue(future, aVariable, aValue);
} else {
@ -125,7 +125,7 @@ PluginPRLibrary::NP_GetValue(void *future, NPPVariable aVariable,
#endif
}
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
nsresult
PluginPRLibrary::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error)
{
@ -231,7 +231,17 @@ PluginPRLibrary::GetImageContainer(NPP instance, ImageContainer** aContainer)
return NS_ERROR_NOT_IMPLEMENTED;
}
#if defined(XP_WIN)
#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;
}
#endif
#if defined(XP_MACOSX) || defined(XP_WIN)
nsresult
PluginPRLibrary::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor)
{

View file

@ -17,17 +17,17 @@ class PluginPRLibrary : public PluginLibrary
{
public:
PluginPRLibrary(const char* aFilePath, PRLibrary* aLibrary) :
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
mNP_Initialize(nullptr),
#else
mNP_Initialize(nullptr),
#endif
mNP_Shutdown(nullptr),
mNP_GetMIMEDescription(nullptr),
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
mNP_GetValue(nullptr),
#endif
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
mNP_GetEntryPoints(nullptr),
#endif
mNPP_New(nullptr),
@ -60,17 +60,19 @@ public:
mNP_GetMIMEDescription = (NP_GetMIMEDescriptionFunc)
PR_FindFunctionSymbol(mLibrary, "NP_GetMIMEDescription");
#ifndef XP_MACOSX
if (!mNP_GetMIMEDescription)
return false;
#endif
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
mNP_GetValue = (NP_GetValueFunc)
PR_FindFunctionSymbol(mLibrary, "NP_GetValue");
if (!mNP_GetValue)
return false;
#endif
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
mNP_GetEntryPoints = (NP_GetEntryPointsFunc)
PR_FindFunctionSymbol(mLibrary, "NP_GetEntryPoints");
if (!mNP_GetEntryPoints)
@ -79,7 +81,7 @@ public:
return true;
}
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
virtual nsresult NP_Initialize(NPNetscapeFuncs* aNetscapeFuncs,
NPPluginFuncs* aFuncs, NPError* aError) override;
#else
@ -93,7 +95,7 @@ public:
virtual nsresult NP_GetValue(void* aFuture, NPPVariable aVariable,
void* aValue, NPError* aError) override;
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
virtual nsresult NP_GetEntryPoints(NPPluginFuncs* aFuncs, NPError* aError) override;
#endif
@ -110,7 +112,10 @@ public:
virtual nsresult GetImageContainer(NPP aInstance, mozilla::layers::ImageContainer** aContainer) override;
virtual nsresult GetImageSize(NPP aInstance, nsIntSize* aSize) override;
virtual bool IsOOP() override { return false; }
#if defined(XP_WIN)
#if defined(XP_MACOSX)
virtual nsresult IsRemoteDrawingCoreAnimation(NPP aInstance, bool* aDrawing) override;
#endif
#if defined(XP_MACOSX) || defined(XP_WIN)
virtual nsresult ContentsScaleFactorChanged(NPP aInstance, double aContentsScaleFactor) override;
#endif
virtual nsresult SetBackgroundUnknown(NPP instance) override;
@ -134,10 +139,10 @@ private:
NP_InitializeFunc mNP_Initialize;
NP_ShutdownFunc mNP_Shutdown;
NP_GetMIMEDescriptionFunc mNP_GetMIMEDescription;
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
NP_GetValueFunc mNP_GetValue;
#endif
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
NP_GetEntryPointsFunc mNP_GetEntryPoints;
#endif
NPP_NewProcPtr mNPP_New;

View file

@ -56,6 +56,11 @@ if CONFIG['OS_ARCH'] == 'WINNT':
'nsPluginNativeWindowWin.cpp',
'nsPluginsDirWin.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
SOURCES += [
'nsPluginNativeWindow.cpp',
'nsPluginsDirDarwin.cpp',
]
else:
SOURCES += [
'nsPluginsDirUnix.cpp',
@ -77,6 +82,7 @@ LOCAL_INCLUDES += [
'/layout/xul',
'/netwerk/base',
'/widget',
'/widget/cocoa',
'/xpcom/base',
]

View file

@ -22,6 +22,25 @@
#endif
#endif
#if defined(__APPLE_CC__) && !defined(XP_UNIX)
#ifndef XP_MACOSX
#define XP_MACOSX 1
#endif
#endif
#if defined(XP_MACOSX) && defined(__LP64__)
#define NP_NO_QUICKDRAW
#define NP_NO_CARBON
#endif
#if defined(XP_MACOSX)
#include <ApplicationServices/ApplicationServices.h>
#include <OpenGL/OpenGL.h>
#ifndef NP_NO_CARBON
#include <Carbon/Carbon.h>
#endif
#endif
#if defined(XP_UNIX)
#include <stdio.h>
#if defined(MOZ_X11)
@ -98,6 +117,12 @@ typedef char* NPMIMEType;
/* Structures and definitions */
/*----------------------------------------------------------------------*/
#if !defined(__LP64__)
#if defined(XP_MACOSX)
#pragma options align=mac68k
#endif
#endif /* __LP64__ */
/*
* NPP is a plug-in's opaque instance handle
*/
@ -255,6 +280,15 @@ typedef struct _NPAudioDeviceChangeDetails
typedef enum {
NPDrawingModelDUMMY
#if defined(XP_MACOSX)
#ifndef NP_NO_QUICKDRAW
, NPDrawingModelQuickDraw = 0
#endif
, NPDrawingModelCoreGraphics = 1
, NPDrawingModelOpenGL = 2
, NPDrawingModelCoreAnimation = 3
, NPDrawingModelInvalidatingCoreAnimation = 4
#endif
#if defined(XP_WIN)
, NPDrawingModelSyncWin = 5
#endif
@ -267,6 +301,15 @@ typedef enum {
#endif
} NPDrawingModel;
#ifdef XP_MACOSX
typedef enum {
#ifndef NP_NO_CARBON
NPEventModelCarbon = 0,
#endif
NPEventModelCocoa = 1
} NPEventModel;
#endif
/*
* The following masks are applied on certain platforms to NPNV and
* NPPV selectors that pass around pointers to COM interfaces. Newer
@ -294,7 +337,12 @@ typedef enum {
#define _NP_ABI_MIXIN_FOR_GCC3 0
#endif
#if defined(XP_MACOSX)
#define NP_ABI_MACHO_MASK 0x01000000
#define _NP_ABI_MIXIN_FOR_MACHO NP_ABI_MACHO_MASK
#else
#define _NP_ABI_MIXIN_FOR_MACHO 0
#endif
#define NP_ABI_MASK (_NP_ABI_MIXIN_FOR_GCC3 | _NP_ABI_MIXIN_FOR_MACHO)
@ -345,6 +393,12 @@ typedef enum {
/* Used for negotiating drawing models */
NPPVpluginDrawingModel = 1000
#if defined(XP_MACOSX)
/* Used for negotiating event models */
, NPPVpluginEventModel = 1001
/* In the NPDrawingModelCoreAnimation drawing model, the browser asks the plug-in for a Core Animation layer. */
, NPPVpluginCoreAnimationLayer = 1003
#endif
/* Notification that the plugin just started or stopped playing audio */
, NPPVpluginIsPlayingAudio = 4000
#if defined(XP_WIN)
@ -388,18 +442,39 @@ typedef enum {
NPNVCSSZoomFactor = 23,
NPNVpluginDrawingModel = 1000 /* Get the current drawing model (NPDrawingModel) */
#if defined(XP_WIN)
#if defined(XP_MACOSX) || defined(XP_WIN)
, NPNVcontentsScaleFactor = 1001
#endif
#if defined(XP_MACOSX)
#ifndef NP_NO_QUICKDRAW
, NPNVsupportsQuickDrawBool = 2000
#endif
, NPNVsupportsCoreGraphicsBool = 2001
, NPNVsupportsOpenGLBool = 2002
, NPNVsupportsCoreAnimationBool = 2003
, NPNVsupportsInvalidatingCoreAnimationBool = 2004
#endif
, NPNVsupportsAsyncBitmapSurfaceBool = 2007
#if defined(XP_WIN)
, NPNVsupportsAsyncWindowsDXGISurfaceBool = 2008
, NPNVpreferredDXGIAdapter = 2009
#endif
#if defined(XP_MACOSX)
#ifndef NP_NO_CARBON
, NPNVsupportsCarbonBool = 3000 /* TRUE if the browser supports the Carbon event model */
#endif
, NPNVsupportsCocoaBool = 3001 /* TRUE if the browser supports the Cocoa event model */
, NPNVsupportsUpdatedCocoaTextInputBool = 3002 /* TRUE if the browser supports the updated
Cocoa text input specification. */
#endif
, NPNVmuteAudioBool = 4000 /* Request that the browser wants to mute or unmute the plugin */
#if defined(XP_WIN)
, NPNVaudioDeviceChangeDetails = 4001 /* Provides information about the new default audio device */
#endif
#if defined(XP_MACOSX)
, NPNVsupportsCompositingCoreAnimationPluginsBool = 74656 /* TRUE if the browser supports
CA model compositing */
#endif
} NPNVariable;
typedef enum {
@ -434,7 +509,7 @@ typedef struct _NPWindow
uint32_t width; /* Maximum window size */
uint32_t height;
NPRect clipRect; /* Clipping rectangle in port coordinates */
#if defined(XP_UNIX) || defined(XP_SYMBIAN)
#if (defined(XP_UNIX) || defined(XP_SYMBIAN)) && !defined(XP_MACOSX)
void * ws_info; /* Platform-dependent additional data */
#endif /* XP_UNIX */
NPWindowType type; /* Is this a window or a drawable? */
@ -480,7 +555,11 @@ typedef struct _NPPrint
} print;
} NPPrint;
#if defined(XP_SYMBIAN)
#if defined(XP_MACOSX)
#ifndef NP_NO_CARBON
typedef EventRecord NPEvent;
#endif
#elif defined(XP_SYMBIAN)
typedef QEvent NPEvent;
#elif defined(XP_WIN)
typedef struct _NPEvent
@ -495,7 +574,13 @@ typedef XEvent NPEvent;
typedef void* NPEvent;
#endif
#if defined(XP_WIN)
#if defined(XP_MACOSX)
typedef void* NPRegion;
#ifndef NP_NO_QUICKDRAW
typedef RgnHandle NPQDRegion;
#endif
typedef CGPathRef NPCGRegion;
#elif defined(XP_WIN)
typedef HRGN NPRegion;
#elif defined(XP_UNIX) && defined(MOZ_X11)
typedef Region NPRegion;
@ -509,7 +594,11 @@ typedef struct _NPNSString NPNSString;
typedef struct _NPNSWindow NPNSWindow;
typedef struct _NPNSMenu NPNSMenu;
#if defined(XP_MACOSX)
typedef NPNSMenu NPMenu;
#else
typedef void *NPMenu;
#endif
typedef enum {
NPCoordinateSpacePlugin = 1,
@ -519,6 +608,112 @@ typedef enum {
NPCoordinateSpaceFlippedScreen
} NPCoordinateSpace;
#if defined(XP_MACOSX)
#ifndef NP_NO_QUICKDRAW
typedef struct NP_Port
{
CGrafPtr port;
int32_t portx; /* position inside the topmost window */
int32_t porty;
} NP_Port;
#endif /* NP_NO_QUICKDRAW */
/*
* NP_CGContext is the type of the NPWindow's 'window' when the plugin specifies NPDrawingModelCoreGraphics
* as its drawing model.
*/
typedef struct NP_CGContext
{
CGContextRef context;
void *window; /* A WindowRef under the Carbon event model. */
} NP_CGContext;
/*
* NP_GLContext is the type of the NPWindow's 'window' when the plugin specifies NPDrawingModelOpenGL as its
* drawing model.
*/
typedef struct NP_GLContext
{
CGLContextObj context;
#ifdef NP_NO_CARBON
NPNSWindow *window;
#else
void *window; /* Can be either an NSWindow or a WindowRef depending on the event model */
#endif
} NP_GLContext;
typedef enum {
NPCocoaEventDrawRect = 1,
NPCocoaEventMouseDown,
NPCocoaEventMouseUp,
NPCocoaEventMouseMoved,
NPCocoaEventMouseEntered,
NPCocoaEventMouseExited,
NPCocoaEventMouseDragged,
NPCocoaEventKeyDown,
NPCocoaEventKeyUp,
NPCocoaEventFlagsChanged,
NPCocoaEventFocusChanged,
NPCocoaEventWindowFocusChanged,
NPCocoaEventScrollWheel,
NPCocoaEventTextInput
} NPCocoaEventType;
typedef struct _NPCocoaEvent {
NPCocoaEventType type;
uint32_t version;
union {
struct {
uint32_t modifierFlags;
double pluginX;
double pluginY;
int32_t buttonNumber;
int32_t clickCount;
double deltaX;
double deltaY;
double deltaZ;
} mouse;
struct {
uint32_t modifierFlags;
NPNSString *characters;
NPNSString *charactersIgnoringModifiers;
NPBool isARepeat;
uint16_t keyCode;
} key;
struct {
CGContextRef context;
double x;
double y;
double width;
double height;
} draw;
struct {
NPBool hasFocus;
} focus;
struct {
NPNSString *text;
} text;
} data;
} NPCocoaEvent;
#ifndef NP_NO_CARBON
/* Non-standard event types that can be passed to HandleEvent */
enum NPEventType {
NPEventType_GetFocusEvent = (osEvt + 16),
NPEventType_LoseFocusEvent,
NPEventType_AdjustCursorEvent,
NPEventType_MenuCommandEvent,
NPEventType_ClippingChangedEvent,
NPEventType_ScrollingBeginsEvent = 1000,
NPEventType_ScrollingEndsEvent
};
#endif /* NP_NO_CARBON */
#endif /* XP_MACOSX */
/*
* Values for mode passed to NPP_New:
*/
@ -541,6 +736,12 @@ typedef enum {
#define NP_CLEAR_ALL 0
#define NP_CLEAR_CACHE (1 << 0)
#if !defined(__LP64__)
#if defined(XP_MACOSX)
#pragma options align=reset
#endif
#endif /* __LP64__ */
/*----------------------------------------------------------------------*/
/* Error and Reason Code definitions */
/*----------------------------------------------------------------------*/

View file

@ -182,6 +182,31 @@ typedef struct _NPNetscapeFuncs {
NPN_SetCurrentAsyncSurfacePtr setcurrentasyncsurface;
} NPNetscapeFuncs;
#ifdef XP_MACOSX
/*
* Mac OS X version(s) of NP_GetMIMEDescription(const char *)
* These can be called to retreive MIME information from the plugin dynamically
*
* Note: For compatibility with Quicktime, BPSupportedMIMEtypes is another way
* to get mime info from the plugin only on OSX and may not be supported
* in furture version -- use NP_GetMIMEDescription instead
*/
enum
{
kBPSupportedMIMETypesStructVers_1 = 1
};
typedef struct _BPSupportedMIMETypes
{
SInt32 structVersion; /* struct version */
Handle typeStrings; /* STR# formated handle, allocated by plug-in */
Handle infoStrings; /* STR# formated handle, allocated by plug-in */
} BPSupportedMIMETypes;
OSErr BP_GetSupportedMIMETypes(BPSupportedMIMETypes *mimeInfo, UInt32 flags);
#define NP_GETMIMEDESCRIPTION_NAME "NP_GetMIMEDescription"
typedef const char* (*NP_GetMIMEDescriptionProcPtr)(void);
typedef OSErr (*BP_GetSupportedMIMETypesProcPtr)(BPSupportedMIMETypes*, UInt32);
#endif
#if defined(_WIN32)
#define OSCALL WINAPI
#else
@ -226,8 +251,15 @@ typedef char* (*NP_GetPluginVersionFunc)(void);
NP_EXPORT(char*) NP_GetPluginVersion(void);
typedef const char* (*NP_GetMIMEDescriptionFunc)(void);
NP_EXPORT(const char*) NP_GetMIMEDescription(void);
#ifdef XP_MACOSX
typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*);
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs);
typedef NPError (*NP_GetEntryPointsFunc)(NPPluginFuncs*);
NP_EXPORT(NPError) NP_GetEntryPoints(NPPluginFuncs* pFuncs);
#else
typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*, NPPluginFuncs*);
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs);
#endif
typedef NPError (*NP_ShutdownFunc)(void);
NP_EXPORT(NPError) NP_Shutdown(void);
typedef NPError (*NP_GetValueFunc)(void *, NPPVariable, void *);

View file

@ -269,6 +269,14 @@ nsNPAPIPlugin::CreatePlugin(nsPluginTag *aPluginTag, nsNPAPIPlugin** aResult)
return NS_ERROR_FAILURE;
}
#ifdef XP_MACOSX
if (!pluginLib->HasRequiredFunctions()) {
NS_WARNING("Not all necessary functions exposed by plugin, it will not load.");
delete pluginLib;
return NS_ERROR_FAILURE;
}
#endif
plugin->mLibrary = pluginLib;
pluginLib->SetPlugin(plugin);
@ -286,6 +294,19 @@ nsNPAPIPlugin::CreatePlugin(nsPluginTag *aPluginTag, nsNPAPIPlugin** aResult)
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
return NS_ERROR_FAILURE;
}
#elif defined(XP_MACOSX)
// NP_Initialize must be called before NP_GetEntryPoints on Mac OS X.
// We need to match WebKit's behavior.
NPError pluginCallError;
nsresult rv = pluginLib->NP_Initialize(&sBrowserFuncs, &pluginCallError);
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
return NS_ERROR_FAILURE;
}
rv = pluginLib->NP_GetEntryPoints(&plugin->mPluginFuncs, &pluginCallError);
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
return NS_ERROR_FAILURE;
}
#else
NPError pluginCallError;
nsresult rv = pluginLib->NP_Initialize(&sBrowserFuncs, &plugin->mPluginFuncs, &pluginCallError);
@ -1708,7 +1729,7 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
// cases for android_npapi.h's non-standard ANPInterface values.
switch (static_cast<int>(variable)) {
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
case NPNVxDisplay : {
#if defined(MOZ_X11)
if (npp) {
@ -1833,7 +1854,8 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
}
case NPNVSupportsWindowless: {
#if defined(XP_WIN) || (defined(MOZ_X11) && defined(MOZ_WIDGET_GTK))
#if defined(XP_WIN) || defined(XP_MACOSX) || \
(defined(MOZ_X11) && defined(MOZ_WIDGET_GTK))
*(NPBool*)result = true;
#else
*(NPBool*)result = false;
@ -1901,7 +1923,72 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
return *(char**)result ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
}
#if defined(XP_WIN)
#ifdef XP_MACOSX
case NPNVpluginDrawingModel: {
if (npp) {
nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance*)npp->ndata;
if (inst) {
NPDrawingModel drawingModel;
inst->GetDrawingModel((int32_t*)&drawingModel);
*(NPDrawingModel*)result = drawingModel;
return NPERR_NO_ERROR;
}
}
return NPERR_GENERIC_ERROR;
}
#ifndef NP_NO_QUICKDRAW
case NPNVsupportsQuickDrawBool: {
*(NPBool*)result = false;
return NPERR_NO_ERROR;
}
#endif
case NPNVsupportsCoreGraphicsBool: {
*(NPBool*)result = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsCoreAnimationBool: {
*(NPBool*)result = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsInvalidatingCoreAnimationBool: {
*(NPBool*)result = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsCompositingCoreAnimationPluginsBool: {
*(NPBool*)result = PR_TRUE;
return NPERR_NO_ERROR;
}
#ifndef NP_NO_CARBON
case NPNVsupportsCarbonBool: {
*(NPBool*)result = false;
return NPERR_NO_ERROR;
}
#endif
case NPNVsupportsCocoaBool: {
*(NPBool*)result = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsUpdatedCocoaTextInputBool: {
*(NPBool*)result = true;
return NPERR_NO_ERROR;
}
#endif
#if defined(XP_MACOSX) || defined(XP_WIN)
case NPNVcontentsScaleFactor: {
nsNPAPIPluginInstance *inst =
(nsNPAPIPluginInstance *) (npp ? npp->ndata : nullptr);
@ -1964,8 +2051,16 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
// actual pointer value is checked rather than its content
// when passing booleans
case NPPVpluginWindowBool: {
#ifdef XP_MACOSX
// This setting doesn't apply to OS X (only to Windows and Unix/Linux).
// See https://developer.mozilla.org/En/NPN_SetValue#section_5. Return
// NPERR_NO_ERROR here to conform to other browsers' behavior on OS X
// (e.g. Safari and Opera).
return NPERR_NO_ERROR;
#else
NPBool bWindowless = (result == nullptr);
return inst->SetWindowless(bWindowless);
#endif
}
case NPPVpluginTransparentBool: {
NPBool bTransparent = (result != nullptr);
@ -2050,6 +2145,18 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
}
}
#ifdef XP_MACOSX
case NPPVpluginEventModel: {
if (inst) {
inst->SetEventModel((NPEventModel)NS_PTR_TO_INT32(result));
return NPERR_NO_ERROR;
}
else {
return NPERR_GENERIC_ERROR;
}
}
#endif
default:
return NPERR_GENERIC_ERROR;
}

View file

@ -45,6 +45,10 @@ public:
// PluginFuncs() can't fail but results are only valid if GetLibrary() succeeds
NPPluginFuncs* PluginFuncs();
#if defined(XP_MACOSX) && !defined(__LP64__)
void SetPluginRefNum(short aRefNum);
#endif
// The IPC mechanism notifies the nsNPAPIPlugin if the plugin
// crashes and is no longer usable. pluginDumpID/browserDumpID are
// the IDs of respective minidumps that were written, or empty if no

View file

@ -60,6 +60,9 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance()
, mPlugin(nullptr)
, mMIMEType(nullptr)
, mOwner(nullptr)
#ifdef XP_MACOSX
, mCurrentPluginEvent(nullptr)
#endif
, mHaveJavaC2PJSObjectQuirk(false)
, mCachedParamLength(0)
, mCachedParamNames(nullptr)
@ -500,6 +503,9 @@ nsresult nsNPAPIPluginInstance::HandleEvent(void* event, int16_t* result,
int16_t tmpResult = kNPEventNotHandled;
if (pluginFunctions->event) {
#ifdef XP_MACOSX
mCurrentPluginEvent = event;
#endif
#if defined(XP_WIN)
NS_TRY_SAFE_CALL_RETURN(tmpResult, (*pluginFunctions->event)(&mNPP, event), this,
aSafeToReenterGecko);
@ -513,6 +519,9 @@ nsresult nsNPAPIPluginInstance::HandleEvent(void* event, int16_t* result,
if (result)
*result = tmpResult;
#ifdef XP_MACOSX
mCurrentPluginEvent = nullptr;
#endif
}
return NS_OK;
@ -608,6 +617,19 @@ void nsNPAPIPluginInstance::RedrawPlugin()
mOwner->RedrawPlugin();
}
#if defined(XP_MACOSX)
void nsNPAPIPluginInstance::SetEventModel(NPEventModel aModel)
{
// the event model needs to be set for the object frame immediately
if (!mOwner) {
NS_WARNING("Trying to set event model without a plugin instance owner!");
return;
}
mOwner->SetEventModel(aModel);
}
#endif
nsresult nsNPAPIPluginInstance::GetDrawingModel(int32_t* aModel)
{
*aModel = (int32_t)mDrawingModel;
@ -616,14 +638,24 @@ nsresult nsNPAPIPluginInstance::GetDrawingModel(int32_t* aModel)
nsresult nsNPAPIPluginInstance::IsRemoteDrawingCoreAnimation(bool* aDrawing)
{
/** Mac Stub **/
#ifdef XP_MACOSX
if (!mPlugin)
return NS_ERROR_FAILURE;
PluginLibrary* library = mPlugin->GetLibrary();
if (!library)
return NS_ERROR_FAILURE;
return library->IsRemoteDrawingCoreAnimation(&mNPP, aDrawing);
#else
return NS_ERROR_FAILURE;
#endif
}
nsresult
nsNPAPIPluginInstance::ContentsScaleFactorChanged(double aContentsScaleFactor)
{
#if defined(XP_WIN)
#if defined(XP_MACOSX) || defined(XP_WIN)
if (!mPlugin)
return NS_ERROR_FAILURE;
@ -700,7 +732,12 @@ nsNPAPIPluginInstance::ShouldCache()
nsresult
nsNPAPIPluginInstance::IsWindowless(bool* isWindowless)
{
#ifdef XP_MACOSX
// All OS X plugins are windowless.
*isWindowless = true;
#else
*isWindowless = mWindowless;
#endif
return NS_OK;
}

View file

@ -34,6 +34,12 @@ class nsPluginInstanceOwner;
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncWin;
#elif defined(MOZ_X11)
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncX;
#elif defined(XP_MACOSX)
#ifndef NP_NO_QUICKDRAW
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelQuickDraw; // Not supported
#else
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelCoreGraphics;
#endif
#else
const NPDrawingModel kDefaultDrawingModel = static_cast<NPDrawingModel>(0);
#endif
@ -140,6 +146,13 @@ public:
void SetDrawingModel(NPDrawingModel aModel);
void RedrawPlugin();
#ifdef XP_MACOSX
void SetEventModel(NPEventModel aModel);
void* GetCurrentEvent() {
return mCurrentPluginEvent;
}
#endif
nsresult NewStreamListener(const char* aURL, void* notifyData,
nsNPAPIPluginStreamListener** listener);
@ -278,6 +291,11 @@ private:
nsTArray<nsNPAPITimer*> mTimers;
#ifdef XP_MACOSX
// non-null during a HandleEvent call
void* mCurrentPluginEvent;
#endif
// Timestamp for the last time this plugin was stopped.
// This is only valid when the plugin is actually stopped!
mozilla::TimeStamp mStopTime;

View file

@ -33,6 +33,9 @@
#include "nsProtocolProxyService.h"
#include "nsIStreamConverterService.h"
#include "nsIFile.h"
#if defined(XP_MACOSX)
#include "nsILocalFileMac.h"
#endif
#include "nsISeekableStream.h"
#include "nsNetUtil.h"
#include "nsIFileStreams.h"
@ -1921,7 +1924,19 @@ int64_t GetPluginLastModifiedTime(const nsCOMPtr<nsIFile>& localfile)
{
PRTime fileModTime = 0;
#if defined(XP_MACOSX)
// On OS X the date of a bundle's "contents" (i.e. of its Info.plist file)
// is a much better guide to when it was last modified than the date of
// its package directory. See bug 313700.
nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface(localfile);
if (localFileMac) {
localFileMac->GetBundleContentsLastModifiedTime(&fileModTime);
} else {
localfile->GetLastModifiedTime(&fileModTime);
}
#else
localfile->GetLastModifiedTime(&fileModTime);
#endif
return fileModTime;
}

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,11 @@
#include "nsWeakReference.h"
#include "gfxRect.h"
#ifdef XP_MACOSX
#include "mozilla/gfx/QuartzSupport.h"
#include <ApplicationServices/ApplicationServices.h>
#endif
class nsIInputStream;
class nsPluginDOMContextMenuListener;
class nsPluginFrame;
@ -99,6 +104,10 @@ public:
#ifdef XP_WIN
void Paint(const RECT& aDirty, HDC aDC);
#elif defined(XP_MACOSX)
void Paint(const gfxRect& aDirtyRect, CGContextRef cgContext);
void RenderCoreAnimation(CGContextRef aCGContext, int aWidth, int aHeight);
void DoCocoaEventDrawRect(const gfxRect& aDrawRect, CGContextRef cgContext);
#elif defined(MOZ_X11)
void Paint(gfxContext* aContext,
const gfxRect& aFrameRect,
@ -123,11 +132,33 @@ public:
nsresult SetNetscapeWindowAsParent(HWND aWindowToAdopt);
#endif
#ifdef XP_MACOSX
enum { ePluginPaintEnable, ePluginPaintDisable };
void WindowFocusMayHaveChanged();
bool WindowIsActive();
void SendWindowFocusChanged(bool aIsActive);
NPDrawingModel GetDrawingModel();
bool IsRemoteDrawingCoreAnimation();
NPEventModel GetEventModel();
static void CARefresh(nsITimer *aTimer, void *aClosure);
void AddToCARefreshTimer();
void RemoveFromCARefreshTimer();
// This calls into the plugin (NPP_SetWindow) and can run script.
void FixUpPluginWindow(int32_t inPaintState);
void HidePluginWindow();
// Set plugin port info in the plugin (in the 'window' member of the
// NPWindow structure passed to the plugin by SetWindow()).
void SetPluginPort();
#else // XP_MACOSX
void UpdateWindowPositionAndClipRect(bool aSetWindow);
void UpdateWindowVisibility(bool aVisible);
#endif // XP_MACOSX
void ResolutionMayHaveChanged();
#if defined(XP_WIN)
#if defined(XP_MACOSX) || defined(XP_WIN)
nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
#endif
@ -183,7 +214,7 @@ public:
return mPluginWindow->type == NPWindowTypeDrawable &&
(MatchPluginName("Shockwave Flash") ||
MatchPluginName("Test Plug-in"));
#elif defined(MOZ_X11)
#elif defined(MOZ_X11) || defined(XP_MACOSX)
return true;
#else
return false;
@ -280,6 +311,15 @@ private:
nsCOMPtr<nsIWidget> mWidget;
RefPtr<nsPluginHost> mPluginHost;
#ifdef XP_MACOSX
static nsCOMPtr<nsITimer> *sCATimer;
static nsTArray<nsPluginInstanceOwner*> *sCARefreshListeners;
bool mSentInitialTopLevelWindowEvent;
bool mLastWindowIsActive;
bool mLastContentFocused;
// True if, the next time the window is activated, we should blur ourselves.
bool mShouldBlurOnActivate;
#endif
double mLastScaleFactor;
double mLastCSSZoomFactor;
// Initially, the event loop nesting level we were created on, it's updated
@ -295,6 +335,15 @@ private:
bool mPluginWindowVisible;
bool mPluginDocumentActiveState;
#ifdef XP_MACOSX
NPEventModel mEventModel;
// This is a hack! UseAsyncRendering() can incorrectly return false
// when we don't have an object frame (possible as of bug 90268).
// We hack around this by always returning true if we've ever
// returned true.
bool mUseAsyncRendering;
#endif
// pointer to wrapper for nsIDOMContextMenuListener
RefPtr<nsPluginDOMContextMenuListener> mCXMenuListener;
@ -308,6 +357,16 @@ private:
void CallDefaultProc(const mozilla::WidgetGUIEvent* aEvent);
#endif
#ifdef XP_MACOSX
static NPBool ConvertPointPuppet(PuppetWidget *widget, nsPluginFrame* pluginFrame,
double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace);
static NPBool ConvertPointNoPuppet(nsIWidget *widget, nsPluginFrame* pluginFrame,
double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace);
void PerformDelayedBlurs();
#endif // XP_MACOSX
int mLastMouseDownButtonType;
#ifdef MOZ_X11

View file

@ -27,7 +27,7 @@ nsPluginNativeWindowPLATFORM::nsPluginNativeWindowPLATFORM() : nsPluginNativeWin
width = 0;
height = 0;
memset(&clipRect, 0, sizeof(clipRect));
#if defined(XP_UNIX)
#if defined(XP_UNIX) && !defined(XP_MACOSX)
ws_info = nullptr;
#endif
type = NPWindowTypeWindow;

View file

@ -424,7 +424,7 @@ void nsPluginTag::InitMime(const char* const* aMimeTypes,
}
}
#if !defined(XP_WIN)
#if !defined(XP_WIN) && !defined(XP_MACOSX)
static nsresult ConvertToUTF8(nsIUnicodeDecoder *aUnicodeDecoder,
nsAFlatCString& aString)
{
@ -448,7 +448,7 @@ static nsresult ConvertToUTF8(nsIUnicodeDecoder *aUnicodeDecoder,
nsresult nsPluginTag::EnsureMembersAreUTF8()
{
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
return NS_OK;
#else
nsresult rv;

View file

@ -0,0 +1,572 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
/*
nsPluginsDirDarwin.cpp
Mac OS X implementation of the nsPluginsDir/nsPluginsFile classes.
by Patrick C. Beard.
*/
#include "GeckoChildProcessHost.h"
#include "base/process_util.h"
#include "prlink.h"
#include "prnetdb.h"
#include "nsXPCOM.h"
#include "nsPluginsDir.h"
#include "nsNPAPIPlugin.h"
#include "nsPluginsDirUtils.h"
#include "nsILocalFileMac.h"
#include "mozilla/UniquePtr.h"
#include "nsCocoaFeatures.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <Carbon/Carbon.h>
#include <CoreServices/CoreServices.h>
#include <mach-o/loader.h>
#include <mach-o/fat.h>
typedef NS_NPAPIPLUGIN_CALLBACK(const char *, NP_GETMIMEDESCRIPTION) ();
typedef NS_NPAPIPLUGIN_CALLBACK(OSErr, BP_GETSUPPORTEDMIMETYPES) (BPSupportedMIMETypes *mimeInfo, UInt32 flags);
/*
** Returns a CFBundleRef if the path refers to a Mac OS X bundle directory.
** The caller is responsible for calling CFRelease() to deallocate.
*/
static CFBundleRef getPluginBundle(const char* path)
{
CFBundleRef bundle = nullptr;
CFStringRef pathRef = ::CFStringCreateWithCString(nullptr, path,
kCFStringEncodingUTF8);
if (pathRef) {
CFURLRef bundleURL = ::CFURLCreateWithFileSystemPath(nullptr, pathRef,
kCFURLPOSIXPathStyle,
true);
if (bundleURL) {
bundle = ::CFBundleCreate(nullptr, bundleURL);
::CFRelease(bundleURL);
}
::CFRelease(pathRef);
}
return bundle;
}
static nsresult toCFURLRef(nsIFile* file, CFURLRef& outURL)
{
nsCOMPtr<nsILocalFileMac> lfm = do_QueryInterface(file);
if (!lfm)
return NS_ERROR_FAILURE;
CFURLRef url;
nsresult rv = lfm->GetCFURL(&url);
if (NS_SUCCEEDED(rv))
outURL = url;
return rv;
}
bool nsPluginsDir::IsPluginFile(nsIFile* file)
{
nsCString fileName;
file->GetNativeLeafName(fileName);
/*
* Don't load the VDP fake plugin, to avoid tripping a bad bug in OS X
* 10.5.3 (see bug 436575).
*/
if (!strcmp(fileName.get(), "VerifiedDownloadPlugin.plugin")) {
NS_WARNING("Preventing load of VerifiedDownloadPlugin.plugin (see bug 436575)");
return false;
}
return true;
}
// Caller is responsible for freeing returned buffer.
static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
{
const char* buffer = ::CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8);
if (buffer) {
return PL_strdup(buffer);
}
int bufferLength =
::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(cfString),
kCFStringEncodingUTF8) + 1;
char* newBuffer = static_cast<char*>(moz_xmalloc(bufferLength));
if (!newBuffer) {
return nullptr;
}
if (!::CFStringGetCString(cfString, newBuffer, bufferLength,
kCFStringEncodingUTF8)) {
free(newBuffer);
return nullptr;
}
newBuffer = static_cast<char*>(moz_xrealloc(newBuffer,
strlen(newBuffer) + 1));
return newBuffer;
}
class AutoCFTypeObject {
public:
explicit AutoCFTypeObject(CFTypeRef aObject)
{
mObject = aObject;
}
~AutoCFTypeObject()
{
::CFRelease(mObject);
}
private:
CFTypeRef mObject;
};
static Boolean MimeTypeEnabled(CFDictionaryRef mimeDict) {
if (!mimeDict) {
return true;
}
CFTypeRef value;
if (::CFDictionaryGetValueIfPresent(mimeDict, CFSTR("WebPluginTypeEnabled"), &value)) {
if (value && ::CFGetTypeID(value) == ::CFBooleanGetTypeID()) {
return ::CFBooleanGetValue(static_cast<CFBooleanRef>(value));
}
}
return true;
}
static CFDictionaryRef ParsePlistForMIMETypesFilename(CFBundleRef bundle)
{
CFTypeRef mimeFileName = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypesFilename"));
if (!mimeFileName || ::CFGetTypeID(mimeFileName) != ::CFStringGetTypeID()) {
return nullptr;
}
FSRef homeDir;
if (::FSFindFolder(kUserDomain, kCurrentUserFolderType, kDontCreateFolder, &homeDir) != noErr) {
return nullptr;
}
CFURLRef userDirURL = ::CFURLCreateFromFSRef(kCFAllocatorDefault, &homeDir);
if (!userDirURL) {
return nullptr;
}
AutoCFTypeObject userDirURLAutorelease(userDirURL);
CFStringRef mimeFilePath = ::CFStringCreateWithFormat(kCFAllocatorDefault, nullptr, CFSTR("Library/Preferences/%@"), static_cast<CFStringRef>(mimeFileName));
if (!mimeFilePath) {
return nullptr;
}
AutoCFTypeObject mimeFilePathAutorelease(mimeFilePath);
CFURLRef mimeFileURL = ::CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault, mimeFilePath, kCFURLPOSIXPathStyle, false, userDirURL);
if (!mimeFileURL) {
return nullptr;
}
AutoCFTypeObject mimeFileURLAutorelease(mimeFileURL);
SInt32 errorCode = 0;
CFDataRef mimeFileData = nullptr;
Boolean result = ::CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, mimeFileURL, &mimeFileData, nullptr, nullptr, &errorCode);
if (!result) {
return nullptr;
}
AutoCFTypeObject mimeFileDataAutorelease(mimeFileData);
if (errorCode != 0) {
return nullptr;
}
CFPropertyListRef propertyList = ::CFPropertyListCreateFromXMLData(kCFAllocatorDefault, mimeFileData, kCFPropertyListImmutable, nullptr);
if (!propertyList) {
return nullptr;
}
AutoCFTypeObject propertyListAutorelease(propertyList);
if (::CFGetTypeID(propertyList) != ::CFDictionaryGetTypeID()) {
return nullptr;
}
CFTypeRef mimeTypes = ::CFDictionaryGetValue(static_cast<CFDictionaryRef>(propertyList), CFSTR("WebPluginMIMETypes"));
if (!mimeTypes || ::CFGetTypeID(mimeTypes) != ::CFDictionaryGetTypeID() || ::CFDictionaryGetCount(static_cast<CFDictionaryRef>(mimeTypes)) == 0) {
return nullptr;
}
return static_cast<CFDictionaryRef>(::CFRetain(mimeTypes));
}
static void ParsePlistPluginInfo(nsPluginInfo& info, CFBundleRef bundle)
{
CFDictionaryRef mimeDict = ParsePlistForMIMETypesFilename(bundle);
if (!mimeDict) {
CFTypeRef mimeTypes = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypes"));
if (!mimeTypes || ::CFGetTypeID(mimeTypes) != ::CFDictionaryGetTypeID() || ::CFDictionaryGetCount(static_cast<CFDictionaryRef>(mimeTypes)) == 0)
return;
mimeDict = static_cast<CFDictionaryRef>(::CFRetain(mimeTypes));
}
AutoCFTypeObject mimeDictAutorelease(mimeDict);
int mimeDictKeyCount = ::CFDictionaryGetCount(mimeDict);
// Allocate memory for mime data
int mimeDataArraySize = mimeDictKeyCount * sizeof(char*);
info.fMimeTypeArray = static_cast<char**>(moz_xmalloc(mimeDataArraySize));
if (!info.fMimeTypeArray)
return;
memset(info.fMimeTypeArray, 0, mimeDataArraySize);
info.fExtensionArray = static_cast<char**>(moz_xmalloc(mimeDataArraySize));
if (!info.fExtensionArray)
return;
memset(info.fExtensionArray, 0, mimeDataArraySize);
info.fMimeDescriptionArray = static_cast<char**>(moz_xmalloc(mimeDataArraySize));
if (!info.fMimeDescriptionArray)
return;
memset(info.fMimeDescriptionArray, 0, mimeDataArraySize);
// Allocate memory for mime dictionary keys and values
mozilla::UniquePtr<CFTypeRef[]> keys(new CFTypeRef[mimeDictKeyCount]);
if (!keys)
return;
mozilla::UniquePtr<CFTypeRef[]> values(new CFTypeRef[mimeDictKeyCount]);
if (!values)
return;
info.fVariantCount = 0;
::CFDictionaryGetKeysAndValues(mimeDict, keys.get(), values.get());
for (int i = 0; i < mimeDictKeyCount; i++) {
CFTypeRef mimeString = keys[i];
if (!mimeString || ::CFGetTypeID(mimeString) != ::CFStringGetTypeID()) {
continue;
}
CFTypeRef mimeDict = values[i];
if (mimeDict && ::CFGetTypeID(mimeDict) == ::CFDictionaryGetTypeID()) {
if (!MimeTypeEnabled(static_cast<CFDictionaryRef>(mimeDict))) {
continue;
}
info.fMimeTypeArray[info.fVariantCount] = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(mimeString));
if (!info.fMimeTypeArray[info.fVariantCount]) {
continue;
}
CFTypeRef extensions = ::CFDictionaryGetValue(static_cast<CFDictionaryRef>(mimeDict), CFSTR("WebPluginExtensions"));
if (extensions && ::CFGetTypeID(extensions) == ::CFArrayGetTypeID()) {
int extensionCount = ::CFArrayGetCount(static_cast<CFArrayRef>(extensions));
CFMutableStringRef extensionList = ::CFStringCreateMutable(kCFAllocatorDefault, 0);
for (int j = 0; j < extensionCount; j++) {
CFTypeRef extension = ::CFArrayGetValueAtIndex(static_cast<CFArrayRef>(extensions), j);
if (extension && ::CFGetTypeID(extension) == ::CFStringGetTypeID()) {
if (j > 0)
::CFStringAppend(extensionList, CFSTR(","));
::CFStringAppend(static_cast<CFMutableStringRef>(extensionList), static_cast<CFStringRef>(extension));
}
}
info.fExtensionArray[info.fVariantCount] = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(extensionList));
::CFRelease(extensionList);
}
CFTypeRef description = ::CFDictionaryGetValue(static_cast<CFDictionaryRef>(mimeDict), CFSTR("WebPluginTypeDescription"));
if (description && ::CFGetTypeID(description) == ::CFStringGetTypeID())
info.fMimeDescriptionArray[info.fVariantCount] = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(description));
}
info.fVariantCount++;
}
}
nsPluginFile::nsPluginFile(nsIFile *spec)
: mPlugin(spec)
{
}
nsPluginFile::~nsPluginFile() {}
nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary)
{
if (!mPlugin)
return NS_ERROR_NULL_POINTER;
// 64-bit NSPR does not (yet) support bundles. So in 64-bit builds we need
// (for now) to load the bundle's executable. However this can cause
// problems: CFBundleCreate() doesn't run the bundle's executable's
// initialization code, while NSAddImage() and dlopen() do run it. So using
// NSPR's dyld loading mechanisms here (NSAddImage() or dlopen()) can cause
// a bundle's initialization code to run earlier than expected, and lead to
// crashes. See bug 577967.
#ifdef __LP64__
char executablePath[PATH_MAX];
executablePath[0] = '\0';
nsAutoCString bundlePath;
mPlugin->GetNativePath(bundlePath);
CFStringRef pathRef = ::CFStringCreateWithCString(nullptr, bundlePath.get(),
kCFStringEncodingUTF8);
if (pathRef) {
CFURLRef bundleURL = ::CFURLCreateWithFileSystemPath(nullptr, pathRef,
kCFURLPOSIXPathStyle,
true);
if (bundleURL) {
CFBundleRef bundle = ::CFBundleCreate(nullptr, bundleURL);
if (bundle) {
CFURLRef executableURL = ::CFBundleCopyExecutableURL(bundle);
if (executableURL) {
if (!::CFURLGetFileSystemRepresentation(executableURL, true, (UInt8*)&executablePath, PATH_MAX))
executablePath[0] = '\0';
::CFRelease(executableURL);
}
::CFRelease(bundle);
}
::CFRelease(bundleURL);
}
::CFRelease(pathRef);
}
#else
nsAutoCString bundlePath;
mPlugin->GetNativePath(bundlePath);
const char *executablePath = bundlePath.get();
#endif
*outLibrary = PR_LoadLibrary(executablePath);
pLibrary = *outLibrary;
if (!pLibrary) {
return NS_ERROR_FAILURE;
}
#ifdef DEBUG
printf("[loaded plugin %s]\n", bundlePath.get());
#endif
return NS_OK;
}
static char* p2cstrdup(StringPtr pstr)
{
int len = pstr[0];
char* cstr = static_cast<char*>(moz_xmalloc(len + 1));
if (cstr) {
memmove(cstr, pstr + 1, len);
cstr[len] = '\0';
}
return cstr;
}
static char* GetNextPluginStringFromHandle(Handle h, short *index)
{
char *ret = p2cstrdup((unsigned char*)(*h + *index));
*index += (ret ? strlen(ret) : 0) + 1;
return ret;
}
static bool IsCompatibleArch(nsIFile *file)
{
CFURLRef pluginURL = nullptr;
if (NS_FAILED(toCFURLRef(file, pluginURL)))
return false;
bool isPluginFile = false;
CFBundleRef pluginBundle = ::CFBundleCreate(kCFAllocatorDefault, pluginURL);
if (pluginBundle) {
UInt32 packageType, packageCreator;
::CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator);
if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') {
// Get path to plugin as a C string.
char executablePath[PATH_MAX];
executablePath[0] = '\0';
if (!::CFURLGetFileSystemRepresentation(pluginURL, true, (UInt8*)&executablePath, PATH_MAX)) {
executablePath[0] = '\0';
}
uint32_t pluginLibArchitectures;
nsresult rv = mozilla::ipc::GeckoChildProcessHost::GetArchitecturesForBinary(executablePath, &pluginLibArchitectures);
if (NS_FAILED(rv)) {
return false;
}
uint32_t supportedArchitectures =
#ifdef __LP64__
mozilla::ipc::GeckoChildProcessHost::GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
#else
base::GetCurrentProcessArchitecture();
#endif
// Consider the plugin architecture valid if there is any overlap in the masks.
isPluginFile = !!(supportedArchitectures & pluginLibArchitectures);
}
::CFRelease(pluginBundle);
}
::CFRelease(pluginURL);
return isPluginFile;
}
/**
* Obtains all of the information currently available for this plugin.
*/
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary)
{
*outLibrary = nullptr;
nsresult rv = NS_OK;
if (!IsCompatibleArch(mPlugin)) {
return NS_ERROR_FAILURE;
}
// clear out the info, except for the first field.
memset(&info, 0, sizeof(info));
// Try to get a bundle reference.
nsAutoCString path;
if (NS_FAILED(rv = mPlugin->GetNativePath(path)))
return rv;
CFBundleRef bundle = getPluginBundle(path.get());
// fill in full path
info.fFullPath = PL_strdup(path.get());
// fill in file name
nsAutoCString fileName;
if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
return rv;
info.fFileName = PL_strdup(fileName.get());
// Get fName
if (bundle) {
CFTypeRef name = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginName"));
if (name && ::CFGetTypeID(name) == ::CFStringGetTypeID())
info.fName = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(name));
}
// Get fDescription
if (bundle) {
CFTypeRef description = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginDescription"));
if (description && ::CFGetTypeID(description) == ::CFStringGetTypeID())
info.fDescription = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(description));
}
// Get fVersion
if (bundle) {
// Look for the release version first
CFTypeRef version = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString"));
if (!version) // try the build version
version = ::CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey);
if (version && ::CFGetTypeID(version) == ::CFStringGetTypeID())
info.fVersion = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(version));
}
// The last thing we need to do is get MIME data
// fVariantCount, fMimeTypeArray, fExtensionArray, fMimeDescriptionArray
// First look for data in a bundle plist
if (bundle) {
ParsePlistPluginInfo(info, bundle);
::CFRelease(bundle);
if (info.fVariantCount > 0)
return NS_OK;
}
// Don't load "fbplugin" or any plugins whose name starts with "fbplugin_"
// (Facebook plugins) if we're running on OS X 10.10 (Yosemite) or later.
// A "fbplugin" file crashes on load, in the call to LoadPlugin() below.
// See bug 1086977.
if (nsCocoaFeatures::OnYosemiteOrLater()) {
if (fileName.EqualsLiteral("fbplugin") ||
StringBeginsWith(fileName, NS_LITERAL_CSTRING("fbplugin_"))) {
nsAutoCString msg;
msg.AppendPrintf("Preventing load of %s (see bug 1086977)",
fileName.get());
NS_WARNING(msg.get());
return NS_ERROR_FAILURE;
}
}
// It's possible that our plugin has 2 entry points that'll give us mime type
// info. Quicktime does this to get around the need of having admin rights to
// change mime info in the resource fork. We need to use this info instead of
// the resource. See bug 113464.
// Sadly we have to load the library for this to work.
rv = LoadPlugin(outLibrary);
if (NS_FAILED(rv))
return rv;
// Try to get data from NP_GetMIMEDescription
if (pLibrary) {
NP_GETMIMEDESCRIPTION pfnGetMimeDesc = (NP_GETMIMEDESCRIPTION)PR_FindFunctionSymbol(pLibrary, NP_GETMIMEDESCRIPTION_NAME);
if (pfnGetMimeDesc)
ParsePluginMimeDescription(pfnGetMimeDesc(), info);
if (info.fVariantCount)
return NS_OK;
}
// We'll fill this in using BP_GetSupportedMIMETypes and/or resource fork data
BPSupportedMIMETypes mi = {kBPSupportedMIMETypesStructVers_1, nullptr, nullptr};
// Try to get data from BP_GetSupportedMIMETypes
if (pLibrary) {
BP_GETSUPPORTEDMIMETYPES pfnMime = (BP_GETSUPPORTEDMIMETYPES)PR_FindFunctionSymbol(pLibrary, "BP_GetSupportedMIMETypes");
if (pfnMime && noErr == pfnMime(&mi, 0) && mi.typeStrings) {
info.fVariantCount = (**(short**)mi.typeStrings) / 2;
::HLock(mi.typeStrings);
if (mi.infoStrings) // it's possible some plugins have infoStrings missing
::HLock(mi.infoStrings);
}
}
// Fill in the info struct based on the data in the BPSupportedMIMETypes struct
int variantCount = info.fVariantCount;
info.fMimeTypeArray = static_cast<char**>(moz_xmalloc(variantCount * sizeof(char*)));
if (!info.fMimeTypeArray)
return NS_ERROR_OUT_OF_MEMORY;
info.fExtensionArray = static_cast<char**>(moz_xmalloc(variantCount * sizeof(char*)));
if (!info.fExtensionArray)
return NS_ERROR_OUT_OF_MEMORY;
if (mi.infoStrings) {
info.fMimeDescriptionArray = static_cast<char**>(moz_xmalloc(variantCount * sizeof(char*)));
if (!info.fMimeDescriptionArray)
return NS_ERROR_OUT_OF_MEMORY;
}
short mimeIndex = 2;
short descriptionIndex = 2;
for (int i = 0; i < variantCount; i++) {
info.fMimeTypeArray[i] = GetNextPluginStringFromHandle(mi.typeStrings, &mimeIndex);
info.fExtensionArray[i] = GetNextPluginStringFromHandle(mi.typeStrings, &mimeIndex);
if (mi.infoStrings)
info.fMimeDescriptionArray[i] = GetNextPluginStringFromHandle(mi.infoStrings, &descriptionIndex);
}
::HUnlock(mi.typeStrings);
::DisposeHandle(mi.typeStrings);
if (mi.infoStrings) {
::HUnlock(mi.infoStrings);
::DisposeHandle(mi.infoStrings);
}
return NS_OK;
}
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
{
free(info.fName);
free(info.fDescription);
int variantCount = info.fVariantCount;
for (int i = 0; i < variantCount; i++) {
free(info.fMimeTypeArray[i]);
free(info.fExtensionArray[i]);
free(info.fMimeDescriptionArray[i]);
}
free(info.fMimeTypeArray);
free(info.fMimeDescriptionArray);
free(info.fExtensionArray);
free(info.fFileName);
free(info.fFullPath);
free(info.fVersion);
return NS_OK;
}