1999-02-24 02:12:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-02-24 02:12:47 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-02-24 02:12:47 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-02-24 02:12:47 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-02-24 02:12:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
nsPluginsDirMac.cpp
|
|
|
|
|
|
|
|
Mac OS implementation of the nsPluginsDir/nsPluginsFile classes.
|
|
|
|
|
|
|
|
by Patrick C. Beard.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsPluginsDir.h"
|
|
|
|
#include "prlink.h"
|
|
|
|
|
|
|
|
#include <Processes.h>
|
|
|
|
#include <Folders.h>
|
1999-02-25 04:12:55 +00:00
|
|
|
#include <Resources.h>
|
|
|
|
#include <TextUtils.h>
|
1999-03-03 04:11:15 +00:00
|
|
|
#include <Aliases.h>
|
1999-02-25 04:12:55 +00:00
|
|
|
#include <string.h>
|
1999-02-24 02:12:47 +00:00
|
|
|
|
1999-09-18 22:40:36 +00:00
|
|
|
static nsresult getApplicationSpec(FSSpec& outAppSpec)
|
1999-02-24 02:12:47 +00:00
|
|
|
{
|
|
|
|
// Use the process manager to get the application's FSSpec,
|
1999-02-25 20:58:10 +00:00
|
|
|
// then construct an nsFileSpec that encapsulates it.
|
1999-02-24 02:12:47 +00:00
|
|
|
ProcessInfoRec info;
|
|
|
|
info.processInfoLength = sizeof(info);
|
|
|
|
info.processName = NULL;
|
1999-09-18 22:40:36 +00:00
|
|
|
info.processAppSpec = &outAppSpec;
|
1999-02-24 02:12:47 +00:00
|
|
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
|
|
|
OSErr result = GetProcessInformation(&psn, &info);
|
1999-09-18 22:40:36 +00:00
|
|
|
return (result == noErr ? NS_OK : NS_ERROR_FAILURE);
|
1999-02-24 02:12:47 +00:00
|
|
|
}
|
|
|
|
|
2000-01-28 00:49:09 +00:00
|
|
|
nsPluginsDir::nsPluginsDir(PRUint16 location)
|
1999-02-24 02:12:47 +00:00
|
|
|
{
|
1999-09-18 22:40:36 +00:00
|
|
|
#if 0
|
1999-02-24 02:12:47 +00:00
|
|
|
// Use the folder manager to get location of Extensions folder, and
|
|
|
|
// build an FSSpec for "Netscape Plugins" within it.
|
|
|
|
FSSpec& pluginsDir = *this;
|
|
|
|
OSErr result = FindFolder(kOnSystemDisk,
|
|
|
|
kExtensionFolderType,
|
|
|
|
kDontCreateFolder,
|
|
|
|
&pluginsDir.vRefNum,
|
|
|
|
&pluginsDir.parID);
|
|
|
|
if (result == noErr) {
|
|
|
|
SetLeafName("Netscape Plugins");
|
|
|
|
}
|
1999-09-18 22:40:36 +00:00
|
|
|
#else
|
|
|
|
// The "Plugins" folder in the application's directory is where plugins are loaded from.
|
|
|
|
mError = getApplicationSpec(mSpec);
|
2000-09-22 00:58:46 +00:00
|
|
|
if (NS_SUCCEEDED(mError))
|
|
|
|
{
|
|
|
|
if(location == PLUGINS_DIR_LOCATION_MAC_OLD)
|
|
|
|
SetLeafName("Plug-ins");
|
|
|
|
else
|
|
|
|
SetLeafName("Plugins");
|
1999-09-18 22:40:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
1999-02-24 02:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginsDir::~nsPluginsDir() {}
|
|
|
|
|
1999-02-25 20:58:10 +00:00
|
|
|
PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
|
1999-02-24 02:12:47 +00:00
|
|
|
{
|
|
|
|
// look at file's creator/type and make sure it is a code fragment, etc.
|
|
|
|
FInfo info;
|
|
|
|
const FSSpec& spec = fileSpec;
|
|
|
|
OSErr result = FSpGetFInfo(&spec, &info);
|
|
|
|
if (result == noErr)
|
1999-05-17 21:26:48 +00:00
|
|
|
return ((info.fdType == 'shlb' && info.fdCreator == 'MOSS') || info.fdType == 'NSPL');
|
1999-02-24 02:12:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
1999-02-25 20:58:10 +00:00
|
|
|
nsPluginFile::nsPluginFile(const nsFileSpec& spec)
|
|
|
|
: nsFileSpec(spec)
|
1999-02-24 02:12:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginFile::~nsPluginFile() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the plugin into memory using NSPR's shared-library loading
|
|
|
|
* mechanism. Handles platform differences in loading shared libraries.
|
|
|
|
*/
|
|
|
|
nsresult nsPluginFile::LoadPlugin(PRLibrary* &outLibrary)
|
|
|
|
{
|
1999-05-17 21:26:48 +00:00
|
|
|
const char* path = this->GetCString();
|
1999-02-24 02:12:47 +00:00
|
|
|
outLibrary = PR_LoadLibrary(path);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-25 04:12:55 +00:00
|
|
|
static char* p2cstrdup(StringPtr pstr)
|
|
|
|
{
|
|
|
|
int len = pstr[0];
|
|
|
|
char* cstr = new char[len + 1];
|
|
|
|
if (cstr != NULL) {
|
|
|
|
::BlockMoveData(pstr + 1, cstr, len);
|
|
|
|
cstr[len] = '\0';
|
|
|
|
}
|
|
|
|
return cstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* GetPluginString(short id, short index)
|
|
|
|
{
|
|
|
|
Str255 str;
|
|
|
|
::GetIndString(str, id, index);
|
|
|
|
return p2cstrdup(str);
|
|
|
|
}
|
|
|
|
|
1999-02-24 02:12:47 +00:00
|
|
|
/**
|
|
|
|
* Obtains all of the information currently available for this plugin.
|
|
|
|
*/
|
1999-02-25 04:12:55 +00:00
|
|
|
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
1999-02-24 02:12:47 +00:00
|
|
|
{
|
2000-08-21 21:31:28 +00:00
|
|
|
// clear out the info, except for the first field.
|
|
|
|
nsCRT::memset(&info.fName, 0, sizeof(info) - sizeof(PRUint32));
|
2000-08-02 23:01:35 +00:00
|
|
|
|
|
|
|
// need to open the plugin's resource file and read some resources.
|
1999-03-03 04:11:15 +00:00
|
|
|
FSSpec spec = *this;
|
|
|
|
Boolean targetIsFolder, wasAliased;
|
|
|
|
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
|
1999-02-25 04:12:55 +00:00
|
|
|
short refNum = ::FSpOpenResFile(&spec, fsRdPerm);
|
|
|
|
if (refNum != -1) {
|
|
|
|
if (info.fPluginInfoSize >= sizeof(nsPluginInfo)) {
|
|
|
|
// 'STR#', 126, 2 => plugin name.
|
|
|
|
info.fName = GetPluginString(126, 2);
|
|
|
|
|
|
|
|
// 'STR#', 126, 1 => plugin description.
|
|
|
|
info.fDescription = GetPluginString(126, 1);
|
|
|
|
|
1999-03-30 05:53:36 +00:00
|
|
|
// Determine how many 'STR#' resource for all MIME types/extensions.
|
|
|
|
Handle typeList = ::Get1Resource('STR#', 128);
|
|
|
|
if (typeList != NULL) {
|
|
|
|
short stringCount = **(short**)typeList;
|
|
|
|
info.fVariantCount = stringCount / 2;
|
|
|
|
::ReleaseResource(typeList);
|
|
|
|
}
|
|
|
|
|
|
|
|
int variantCount = info.fVariantCount;
|
|
|
|
info.fMimeTypeArray = new char*[variantCount];
|
|
|
|
info.fMimeDescriptionArray = new char*[variantCount];
|
|
|
|
info.fExtensionArray = new char*[variantCount];
|
1999-05-17 21:26:48 +00:00
|
|
|
info.fFileName = p2cstrdup(spec.name);
|
1999-03-30 05:53:36 +00:00
|
|
|
|
|
|
|
short mimeIndex = 1, descriptionIndex = 1;
|
|
|
|
for (int i = 0; i < variantCount; i++) {
|
|
|
|
info.fMimeTypeArray[i] = GetPluginString(128, mimeIndex++);
|
|
|
|
info.fExtensionArray[i] = GetPluginString(128, mimeIndex++);
|
|
|
|
info.fMimeDescriptionArray[i] = GetPluginString(127, descriptionIndex++);
|
|
|
|
}
|
1999-02-25 04:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::CloseResFile(refNum);
|
|
|
|
}
|
1999-02-24 02:12:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-22 00:04:24 +00:00
|
|
|
|
|
|
|
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
|
|
|
{
|
2000-08-02 23:01:35 +00:00
|
|
|
if (info.fPluginInfoSize <= sizeof(nsPluginInfo))
|
|
|
|
{
|
|
|
|
delete[] info.fName;
|
|
|
|
delete[] info.fDescription;
|
|
|
|
int variantCount = info.fVariantCount;
|
|
|
|
for (int i = 0; i < variantCount; i++)
|
|
|
|
{
|
|
|
|
delete[] info.fMimeTypeArray[i];
|
|
|
|
delete[] info.fExtensionArray[i];
|
|
|
|
delete[] info.fMimeDescriptionArray[i];
|
|
|
|
}
|
|
|
|
delete[] info.fMimeTypeArray;
|
|
|
|
delete[] info.fMimeDescriptionArray;
|
|
|
|
delete[] info.fExtensionArray;
|
|
|
|
delete[] info.fFileName;
|
|
|
|
}
|
2000-04-22 00:04:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|