Build the default plugin as Mach-O, in a way that works in objdir builds. r=cls, sr=bryner, bug 179863.

git-svn-id: svn://10.0.0.236/trunk@140722 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sfraser%netscape.com
2003-04-04 22:47:03 +00:00
parent 5bc7be0507
commit 3c35c30e7e
7 changed files with 830 additions and 136 deletions

View File

@@ -0,0 +1,387 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 38;
objects = {
089C1669FE841209C02AAC07 = {
buildStyles = (
4F9091AC011F3BD104CA0E50,
4F9091AD011F3BD104CA0E50,
F50EB520038ABFA401A9666E,
);
hasScannedForEncodings = 1;
isa = PBXProject;
mainGroup = 089C166AFE841209C02AAC07;
projectDirPath = "";
targets = (
089C1673FE841209C02AAC07,
F59D147102AC328B01000104,
);
};
089C166AFE841209C02AAC07 = {
children = (
08FB77ADFE841716C02AAC07,
089C167CFE841241C02AAC07,
089C1671FE841209C02AAC07,
19C28FB4FE9D528D11CA2CBB,
);
isa = PBXGroup;
name = MRJPlugin;
refType = 4;
};
089C1671FE841209C02AAC07 = {
children = (
F5A7D3AB036E359F01A96660,
08EA7FFBFE8413EDC02AAC07,
F51A400C0299CD65012FC976,
);
isa = PBXGroup;
name = "External Frameworks and Libraries";
refType = 4;
};
089C1673FE841209C02AAC07 = {
buildPhases = (
089C1674FE841209C02AAC07,
089C1675FE841209C02AAC07,
089C1676FE841209C02AAC07,
089C1677FE841209C02AAC07,
089C1679FE841209C02AAC07,
F5BFB5E8029AD01B01000102,
);
buildSettings = {
FRAMEWORK_SEARCH_PATHS = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/CoreFoundation.framework\"";
HEADER_SEARCH_PATHS = "../../../../../dist/sdk/xpcom/include ../../../../../dist/include/caps ../../../../../dist/include/java ../../../../../dist/include/js ../../../../../dist/include/nspr ../../../../../dist/include/nspr/obsolete ../../../../../dist/include/oji ../../../../../dist/include/plugin ../../../../../dist/include/xpcom ../../../../../dist/include/xpconnect ../../../../../dist/include /Developer/Headers/FlatCarbon";
LIBRARY_SEARCH_PATHS = /usr/lib;
OTHER_CFLAGS = "-DXP_MACOSX=1 -DNO_X11=1 -DUSE_SYSTEM_CONSOLE=1";
OTHER_LDFLAGS = "";
OTHER_REZFLAGS = "";
PREFIX_HEADER = DefaultPluginPrefix.h;
PRODUCT_NAME = "Default Plugin";
SECTORDER_FLAGS = "";
WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas";
WRAPPER_EXTENSION = plugin;
};
dependencies = (
F59D147202AC350E01000104,
);
isa = PBXBundleTarget;
name = "Default Plugin";
productName = MRJPlugin;
productReference = 4F9091AB011F3BD104CA0E50;
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Default Plugin</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.netscape.DefaultPlugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>NSPL</string>
<key>CFBundleSignature</key>
<string>MOSS</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CSResourcesFileMapped</key>
<true/>
</dict>
</plist>
";
};
089C1674FE841209C02AAC07 = {
buildActionMask = 2147483647;
files = (
0F64AF2D0433C8A200A96652,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
089C1675FE841209C02AAC07 = {
buildActionMask = 2147483647;
files = (
089C1680FE841241C02AAC07,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
089C1676FE841209C02AAC07 = {
buildActionMask = 2147483647;
files = (
F5E0C350036A130901A96660,
F5E0C352036A130E01A96660,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
089C1677FE841209C02AAC07 = {
buildActionMask = 2147483647;
files = (
08EA7FFCFE8413EDC02AAC07,
F51A400D0299CD65012FC976,
F5A7D695036E35A001A96660,
);
isa = PBXFrameworksBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
089C1679FE841209C02AAC07 = {
buildActionMask = 2147483647;
files = (
F5E0C34E036A12DF01A96660,
);
isa = PBXRezBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
089C167CFE841241C02AAC07 = {
children = (
089C167DFE841241C02AAC07,
F5E0C34D036A12DF01A96660,
);
isa = PBXGroup;
name = Resources;
refType = 4;
};
089C167DFE841241C02AAC07 = {
children = (
089C167EFE841241C02AAC07,
);
isa = PBXVariantGroup;
name = InfoPlist.strings;
path = "";
refType = 2;
};
089C167EFE841241C02AAC07 = {
fileEncoding = 10;
isa = PBXFileReference;
name = English;
path = English.lproj/InfoPlist.strings;
refType = 4;
};
089C1680FE841241C02AAC07 = {
fileRef = 089C167DFE841241C02AAC07;
isa = PBXBuildFile;
settings = {
};
};
08EA7FFBFE8413EDC02AAC07 = {
isa = PBXFrameworkReference;
name = Carbon.framework;
path = /System/Library/Frameworks/Carbon.framework;
refType = 0;
};
08EA7FFCFE8413EDC02AAC07 = {
fileRef = 08EA7FFBFE8413EDC02AAC07;
isa = PBXBuildFile;
settings = {
};
};
08FB77ADFE841716C02AAC07 = {
children = (
0F64AF2C0433C8A200A96652,
F5E0C34F036A130901A96660,
F5E0C351036A130E01A96660,
);
isa = PBXGroup;
name = Source;
refType = 4;
};
//080
//081
//082
//083
//084
//0F0
//0F1
//0F2
//0F3
//0F4
0F64AF2C0433C8A200A96652 = {
fileEncoding = 4;
isa = PBXFileReference;
path = DefaultPluginPrefix.h;
refType = 4;
};
0F64AF2D0433C8A200A96652 = {
fileRef = 0F64AF2C0433C8A200A96652;
isa = PBXBuildFile;
settings = {
};
};
//0F0
//0F1
//0F2
//0F3
//0F4
//190
//191
//192
//193
//194
19C28FB4FE9D528D11CA2CBB = {
children = (
4F9091AB011F3BD104CA0E50,
);
isa = PBXGroup;
name = Products;
refType = 4;
};
//190
//191
//192
//193
//194
//4F0
//4F1
//4F2
//4F3
//4F4
4F9091AB011F3BD104CA0E50 = {
isa = PBXBundleReference;
path = "Default Plugin.plugin";
refType = 3;
};
4F9091AC011F3BD104CA0E50 = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = NO;
OPTIMIZATION_CFLAGS = "-O0";
};
isa = PBXBuildStyle;
name = Development;
};
4F9091AD011F3BD104CA0E50 = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = YES;
};
isa = PBXBuildStyle;
name = Deployment;
};
//4F0
//4F1
//4F2
//4F3
//4F4
//F50
//F51
//F52
//F53
//F54
F50EB520038ABFA401A9666E = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = NO;
DEBUGGING_SYMBOLS = YES;
};
isa = PBXBuildStyle;
name = DeploymentSymbols;
};
F51A400C0299CD65012FC976 = {
isa = PBXFileReference;
name = "libstdc++.a";
path = "/usr/lib/libstdc++.a";
refType = 0;
};
F51A400D0299CD65012FC976 = {
fileRef = F51A400C0299CD65012FC976;
isa = PBXBuildFile;
settings = {
};
};
F59D147102AC328B01000104 = {
buildArgumentsString = "$ACTION resources";
buildPhases = (
);
buildSettings = {
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
OTHER_REZFLAGS = "";
PRODUCT_NAME = Resources;
SECTORDER_FLAGS = "";
WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas";
};
buildToolPath = /usr/bin/gnumake;
buildWorkingDirectory = .;
dependencies = (
);
isa = PBXLegacyTarget;
name = Resources;
passBuildSettingsInEnvironment = 1;
productName = Resources;
settingsToExpand = 6;
settingsToPassInEnvironment = 287;
settingsToPassOnCommandLine = 280;
};
F59D147202AC350E01000104 = {
isa = PBXTargetDependency;
target = F59D147102AC328B01000104;
};
F5A7D3AB036E359F01A96660 = {
isa = PBXFrameworkReference;
name = CoreFoundation.framework;
path = /System/Library/Frameworks/CoreFoundation.framework;
refType = 0;
};
F5A7D695036E35A001A96660 = {
fileRef = F5A7D3AB036E359F01A96660;
isa = PBXBuildFile;
settings = {
};
};
F5BFB5E8029AD01B01000102 = {
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 6;
files = (
);
isa = PBXCopyFilesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
F5E0C34D036A12DF01A96660 = {
isa = PBXFileReference;
path = _NullPlugin.rsrc;
refType = 2;
};
F5E0C34E036A12DF01A96660 = {
fileRef = F5E0C34D036A12DF01A96660;
isa = PBXBuildFile;
settings = {
};
};
F5E0C34F036A130901A96660 = {
fileEncoding = 30;
isa = PBXFileReference;
path = NullPlugin.cpp;
refType = 2;
};
F5E0C350036A130901A96660 = {
fileRef = F5E0C34F036A130901A96660;
isa = PBXBuildFile;
settings = {
};
};
F5E0C351036A130E01A96660 = {
fileEncoding = 30;
isa = PBXFileReference;
path = npmac.cpp;
refType = 2;
};
F5E0C352036A130E01A96660 = {
fileRef = F5E0C351036A130E01A96660;
isa = PBXBuildFile;
settings = {
};
};
};
rootObject = 089C1669FE841209C02AAC07;
}

View File

@@ -0,0 +1 @@
#include "mozilla-config.h"

View File

@@ -0,0 +1,91 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Brian Ryner <bryner@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef MOZ_DEBUG
BUILDSTYLE = Development
else
ifdef CHIMERA_OPT_SYMBOLS
BUILDSTYLE = DeploymentSymbols
else
BUILDSTYLE = Deployment
endif
endif
TARGET = "Default Plugin"
include $(topsrcdir)/config/rules.mk
# decodes resource files from AppleSingle to Resource Manager format.
ASDECODE = $(DIST)/bin/asdecode
RESOURCE_FILES = _NullPlugin.rsrc
# for objdir builds, copy the project, and symlink the sources
ABS_topsrcdir := $(shell cd $(topsrcdir); pwd)
ifneq ($(ABS_topsrcdir),$(MOZ_BUILD_ROOT))
export::
rsync -a --exclude .DS_Store --exclude "CVS/" $(srcdir)/DefaultPlugin.pbproj .
ln -fs $(srcdir)/English.lproj
ln -fs $(srcdir)/DefaultPluginPrefix.h
ln -fs $(srcdir)/NullPlugin.cpp
ln -fs $(srcdir)/npmac.cpp
endif
all:: build-plugin
libs install:: install-plugin
install-plugin: build-plugin
$(INSTALL) "build/Default Plugin.plugin" $(DIST)/bin/plugins
resources: $(RESOURCE_FILES)
build-plugin: resources
pbxbuild -target $(TARGET) -buildstyle $(BUILDSTYLE)
_%.rsrc: %.rsrc
$(ASDECODE) $< $@
clean clobber::
rm -f $(RESOURCE_FILES)
rm -rf build

View File

@@ -40,11 +40,18 @@
#include "npapi.h"
#endif
#ifdef XP_MACOSX
#undef DARWIN
#include <CoreFoundation/CoreFoundation.h>
#else
#include <Gestalt.h>
#include <Icons.h>
#include <Resources.h>
#include <Processes.h>
#include <Script.h>
#include <TextUtils.h>
#include <CFPreferences.h>
#endif
#include <string.h>
#include <ctype.h>
@@ -66,6 +73,9 @@ public:
static NPError Initialize();
static void Shutdown();
// no ctor because CPlugin is allocated and constructed by hand.
// ideally, this should use placement |new|.
void Constructor(NPP instance, NPMIMEType type, uint16 mode, int16 argc, char* argn[], char* argv[]);
void Destructor();
@@ -101,8 +111,9 @@ private:
static char* sDefaultPage;
static char* sRefreshText;
static char* sJavaScriptPage;
static FSSpec sDataFileSpec;
static FSSpec sDataFileSpec; // only used for Mac OS 9
static Boolean sRunningOnOSX;
NPP fInstance;
NPWindow* fWindow;
uint16 fMode;
@@ -131,6 +142,7 @@ char* CPlugin::sDefaultPage = NULL;
char* CPlugin::sRefreshText = NULL;
char* CPlugin::sJavaScriptPage = NULL;
FSSpec CPlugin::sDataFileSpec;
Boolean CPlugin::sRunningOnOSX = false;
extern short gResFile;
@@ -154,9 +166,10 @@ const short rJavaScriptPageURL = 132;
// 'STR#'
const short rTypeListStrings = 129;
static char szPluginFinderCommandBeginning[] = PLUGINFINDER_COMMAND_BEGINNING;
static char szPluginFinderCommandEnd[] = PLUGINFINDER_COMMAND_END;
static const char szPluginFinderCommandBeginning[] = PLUGINFINDER_COMMAND_BEGINNING;
static const char szPluginFinderCommandEnd[] = PLUGINFINDER_COMMAND_END;
//#ifndef XP_MACOSX
//------------------------------------------------------------------------------------
// strcasecomp: Why don't the MW C libraries have this??
@@ -170,11 +183,11 @@ int strcasecmp (const char* one, const char *two)
const char *pB;
for(pA=one, pB=two; *pA && *pB; pA++, pB++)
{
int tmp = XP_TO_LOWER(*pA) - XP_TO_LOWER(*pB);
if (tmp)
{
int tmp = XP_TO_LOWER(*pA) - XP_TO_LOWER(*pB);
if (tmp)
return tmp;
}
}
if (*pA)
return 1;
if (*pB)
@@ -182,6 +195,8 @@ int strcasecmp (const char* one, const char *two)
return 0;
}
//#endif // XP_MACOSX
//------------------------------------------------------------------------------------
// NPP_Initialize:
@@ -337,8 +352,8 @@ NPP_StreamAsFile(NPP /*instance*/, NPStream */*stream*/, const char* /*fname*/)
void NP_LOADDS
NPP_Print(NPP instance, NPPrint* printInfo)
{
if (printInfo == NULL)
return;
if (printInfo == NULL)
return;
if (instance != NULL)
{
@@ -388,6 +403,7 @@ jref NPP_GetJavaClass(void)
return NULL;
}
#pragma mark -
//------------------------------------------------------------------------------------
// CPlugin::Initialize:
@@ -395,11 +411,14 @@ jref NPP_GetJavaClass(void)
NPError CPlugin::Initialize()
{
Handle string;
SInt16 wResFile;
short saveResFile = CurResFile();
UseResFile(gResFile);
long systemVersion;
OSErr err = ::Gestalt(gestaltSystemVersion, &systemVersion);
sRunningOnOSX = (err == noErr) && (systemVersion >= 0x00001000);
// Get Resources
CPlugin::sIconHandle = GetCIcon(rBrokenPluginIcon);
CPlugin::sHandCursor = GetCursor(rHandCursor);
@@ -490,11 +509,13 @@ NPError CPlugin::Initialize()
ReleaseResource(string);
UseResFile(saveResFile);
if (!sRunningOnOSX) // We'll make some CFPreferences the first time we have to on OS X
{
ProcessSerialNumber psn;
ProcessInfoRec info;
FSSpec fsTheApp;
SInt16 wResFile;
OSErr wErr;
psn.highLongOfPSN = 0;
@@ -505,8 +526,7 @@ NPError CPlugin::Initialize()
info.processAppSpec = &fsTheApp;
wErr = ::GetProcessInformation(&psn, &info);
if (wErr == noErr) {
wErr = FSMakeFSSpec(fsTheApp.vRefNum, fsTheApp.parID, "\p:Plug-ins:Default Plug-in Data",
&sDataFileSpec);
wErr = FSMakeFSSpec(fsTheApp.vRefNum, fsTheApp.parID, "\p:Plug-ins:Default Plug-in Data", &sDataFileSpec);
if (wErr == fnfErr) {
FSpCreateResFile(&sDataFileSpec, 'MOSS', 'BINA', smSystemScript);
wResFile = FSpOpenResFile(&CPlugin::sDataFileSpec, fsRdWrPerm);
@@ -521,6 +541,7 @@ NPError CPlugin::Initialize()
}
}
}
return NPERR_NO_ERROR;
}
@@ -721,8 +742,8 @@ void CPlugin::Draw(HiliteState hilite)
#if !TARGET_API_MAC_CARBON
FillRect(&drawRect, &(gQDPtr->white));
#else
Pattern qdWhite;
FillRect(&drawRect, GetQDGlobalsWhite(&qdWhite));
Pattern qdWhite;
FillRect(&drawRect, GetQDGlobalsWhite(&qdWhite));
#endif
if (hilite == kHilited) {
@@ -769,7 +790,8 @@ void CPlugin::MouseDown()
{
Draw(kHilited);
Boolean inside = true;
// evil CPU-hogging loop on Mac OS X!
while (StillDown())
{
Point localMouse;
@@ -811,11 +833,11 @@ Boolean CPlugin::FocusDraw()
{
GetPort(&fSavePort);
SetPort((GrafPtr) ourPort);
Rect portRect;
Rect portRect;
#if !TARGET_API_MAC_CARBON
portRect = ourPort->portRect;
portRect = ourPort->portRect;
#else
GetPortBounds(ourPort, &portRect);
GetPortBounds(ourPort, &portRect);
#endif
fSavePortTop = portRect.top;
fSavePortLeft = portRect.left;
@@ -957,51 +979,106 @@ char *CPlugin::MakeDefaultURL(void)
//------------------------------------------------------------------------------------
void CPlugin::AddMimeTypeToList(StringPtr cTypeString)
{
Handle hTypeList;
SInt32 dwCount;
SInt32 index;
Str255 oldType;
SInt16 wResFile;
Boolean failedToFind = true;
if (sRunningOnOSX)
{
CFStringRef pluginKey = CFSTR("DefaultPluginSeenTypes"); // don't release this
CFStringRef mimeType = ::CFStringCreateWithPascalString(kCFAllocatorDefault, cTypeString, kCFStringEncodingASCII);
CFArrayRef prefsList = (CFArrayRef)::CFPreferencesCopyAppValue(pluginKey, kCFPreferencesCurrentApplication);
Boolean foundType = false;
wResFile = FSpOpenResFile(&CPlugin::sDataFileSpec, fsRdWrPerm);
if (wResFile != -1) {
hTypeList = Get1Resource('STR#', rTypeListStrings);
if (hTypeList != NULL) {
dwCount = **((short **)hTypeList);
if (prefsList == NULL)
{
CFStringRef stringArray[1];
stringArray[0] = mimeType;
// First make sure it's not already in the list.
for (index = 1; index <= dwCount; index++) {
GetIndString(oldType, rTypeListStrings, index);
// if the mimetype already exists in our list, or the plugin is NOT hidden,
// don't bring up the dialog box
if (EqualString(cTypeString, oldType, true, true) && !fHiddenPlugin) {
failedToFind = false;
break; // Found a match, so bail out!
}
prefsList = ::CFArrayCreate(kCFAllocatorDefault, (const void **)stringArray, 1, &kCFTypeArrayCallBacks);
if (prefsList)
{
::CFPreferencesSetAppValue(pluginKey, prefsList, kCFPreferencesCurrentApplication);
::CFRelease(prefsList);
}
if (failedToFind) {
// Grow the string list handle
Size itsSize = GetHandleSize(hTypeList);
Size typeSize = cTypeString[0] + 1;
SetHandleSize(hTypeList, itsSize + typeSize);
// Increment the count of strings in the list
(**((short**)hTypeList)) = (short)(++dwCount);
// Copy the data from our string into the handle
long dwCount = Munger(hTypeList, itsSize, NULL, typeSize, cTypeString, typeSize);
// Mark the resource as changed so it will be written out
if (dwCount > 0) {
ChangedResource(hTypeList);
UpdateResFile(wResFile);
}
}
ReleaseResource(hTypeList);
}
FSClose(wResFile);
else
{
if (::CFGetTypeID(prefsList) == ::CFArrayGetTypeID())
{
// first make sure it's not in the list
CFIndex count = ::CFArrayGetCount(prefsList);
for (CFIndex i = 0; i < count; i ++)
{
CFStringRef item = (CFStringRef)::CFArrayGetValueAtIndex(prefsList, i); // does not retain
if (item &&
(::CFGetTypeID(item) == ::CFStringGetTypeID()) &&
(::CFStringCompareWithOptions(item, mimeType,
CFRangeMake(0, ::CFStringGetLength(item)), kCFCompareCaseInsensitive) == kCFCompareEqualTo))
{
foundType = true;
break;
}
}
if (!foundType && !fHiddenPlugin)
{
CFMutableArrayRef typesArray = ::CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, (CFArrayRef)prefsList);
if (typesArray)
{
::CFArrayAppendValue(typesArray, mimeType);
::CFPreferencesSetAppValue(pluginKey, typesArray, kCFPreferencesCurrentApplication);
}
}
}
::CFRelease(prefsList);
}
::CFRelease(mimeType);
}
else
{
Handle hTypeList;
SInt32 dwCount;
SInt32 index;
Str255 oldType;
SInt16 wResFile;
Boolean failedToFind = true;
wResFile = FSpOpenResFile(&CPlugin::sDataFileSpec, fsRdWrPerm);
if (wResFile != -1) {
hTypeList = Get1Resource('STR#', rTypeListStrings);
if (hTypeList != NULL) {
dwCount = **((short **)hTypeList);
// First make sure it's not already in the list.
for (index = 1; index <= dwCount; index++) {
GetIndString(oldType, rTypeListStrings, index);
// if the mimetype already exists in our list, or the plugin is NOT hidden,
// don't bring up the dialog box
if (EqualString(cTypeString, oldType, true, true) && !fHiddenPlugin) {
failedToFind = false;
break; // Found a match, so bail out!
}
}
if (failedToFind) {
// Grow the string list handle
Size itsSize = GetHandleSize(hTypeList);
Size typeSize = cTypeString[0] + 1;
SetHandleSize(hTypeList, itsSize + typeSize);
// Increment the count of strings in the list
(**((short**)hTypeList)) = (short)(++dwCount);
// Copy the data from our string into the handle
long dwCount = Munger(hTypeList, itsSize, NULL, typeSize, cTypeString, typeSize);
// Mark the resource as changed so it will be written out
if (dwCount > 0) {
ChangedResource(hTypeList);
UpdateResFile(wResFile);
}
}
ReleaseResource(hTypeList);
}
FSClose(wResFile);
}
}
}
@@ -1023,41 +1100,72 @@ void CPlugin::AddMimeTypeToList(StringPtr cTypeString)
//------------------------------------------------------------------------------------
Boolean CPlugin::CheckMimeTypes()
{
Handle hTypeList;
SInt32 index;
Str255 oldType;
Str255 ourType;
SInt16 wResFile;
Boolean failedToFind = true;
Boolean failedToFind = true;
wResFile = FSpOpenResFile(&CPlugin::sDataFileSpec, fsRdPerm);
if (wResFile != -1) {
hTypeList = Get1Resource('STR#', rTypeListStrings);
if (hTypeList != NULL) {
// Convert the mime-type C string to a Pascal string.
index = strlen(fType);
if (index > 255) { // don't blow out the Str255
index = 255;
}
BlockMoveData(fType, &ourType[1], index);
ourType[0] = index;
short count = **((short **)hTypeList);
// Iterate through all the strings in the list.
for (index = 1; index <= count; index++) {
GetIndString(oldType, rTypeListStrings, index);
// if the mimetype already exists in our list, or the plugin is NOT hidden,
// don't bring up the dialog box
if (EqualString(ourType, oldType, true, true) && !fHiddenPlugin) {
failedToFind = false;
break; // Found a match, so bail out!
if (sRunningOnOSX)
{
CFStringRef pluginKey = CFSTR("DefaultPluginSeenTypes"); // don't release this
CFStringRef mimeType = ::CFStringCreateWithCString(kCFAllocatorDefault, fType, kCFStringEncodingASCII);
CFArrayRef prefsList = (CFArrayRef)::CFPreferencesCopyAppValue(pluginKey, kCFPreferencesCurrentApplication);
if (prefsList)
{
if (::CFGetTypeID(prefsList) == ::CFArrayGetTypeID())
{
CFIndex count = ::CFArrayGetCount(prefsList);
for (CFIndex i = 0; i < count; i ++)
{
CFStringRef item = (CFStringRef)::CFArrayGetValueAtIndex(prefsList, i); // does not retain
if (item &&
(::CFGetTypeID(item) == ::CFStringGetTypeID()) &&
(::CFStringCompareWithOptions(item, mimeType,
CFRangeMake(0, ::CFStringGetLength(item)), kCFCompareCaseInsensitive) == kCFCompareEqualTo))
{
failedToFind = false;
break;
}
}
}
ReleaseResource(hTypeList);
::CFRelease(prefsList);
}
::CFRelease(mimeType);
}
else
{
Handle hTypeList;
SInt32 index;
Str255 oldType;
Str255 ourType;
SInt16 wResFile;
wResFile = FSpOpenResFile(&CPlugin::sDataFileSpec, fsRdPerm);
if (wResFile != -1) {
hTypeList = Get1Resource('STR#', rTypeListStrings);
if (hTypeList != NULL) {
// Convert the mime-type C string to a Pascal string.
index = strlen(fType);
if (index > 255) { // don't blow out the Str255
index = 255;
}
BlockMoveData(fType, &ourType[1], index);
ourType[0] = index;
short count = **((short **)hTypeList);
// Iterate through all the strings in the list.
for (index = 1; index <= count; index++) {
GetIndString(oldType, rTypeListStrings, index);
// if the mimetype already exists in our list, or the plugin is NOT hidden,
// don't bring up the dialog box
if (EqualString(ourType, oldType, true, true) && !fHiddenPlugin) {
failedToFind = false;
break; // Found a match, so bail out!
}
}
ReleaseResource(hTypeList);
}
FSClose(wResFile);
}
FSClose(wResFile);
}
return(failedToFind);
}
@@ -1087,7 +1195,7 @@ void CPlugin::AskAndLoadURL()
#if !TARGET_API_MAC_CARBON
SetCursor(&(gQDPtr->arrow));
#else
Cursor qdArrow;
Cursor qdArrow;
SetCursor(GetQDGlobalsArrow(&qdArrow));
#endif

View File

@@ -4,6 +4,8 @@
//
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#include <string.h>
#include <Processes.h>
#include <Gestalt.h>
#include <CodeFragments.h>
@@ -22,7 +24,7 @@
// A4Stuff does not exist as of CW 7. Define them to nothing.
//
#if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
#if (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) || defined(__GNUC__)
#define EnterCodeResource()
#define ExitCodeResource()
#else
@@ -55,7 +57,7 @@
#endif
#endif
// The following fix for static initializers (which fixes a preious
// The following fix for static initializers (which fixes a previous
// incompatibility with some parts of PowerPlant, was submitted by
// Jan Ulbrich.
#ifdef __MWERKS__
@@ -78,7 +80,7 @@
// Define PLUGIN_TRACE to 1 to have the wrapper functions emit
// DebugStr messages whenever they are called.
//
#define PLUGIN_TRACE 0
//#define PLUGIN_TRACE 1
#if PLUGIN_TRACE
#define PLUGINDEBUGSTR(msg) ::DebugStr(msg)
@@ -87,8 +89,91 @@
#endif
#ifdef XP_MACOSX
// glue for mapping outgoing Macho function pointers to TVectors
struct TFPtoTVGlue{
void* glue[2];
};
struct {
TFPtoTVGlue newp;
TFPtoTVGlue destroy;
TFPtoTVGlue setwindow;
TFPtoTVGlue newstream;
TFPtoTVGlue destroystream;
TFPtoTVGlue asfile;
TFPtoTVGlue writeready;
TFPtoTVGlue write;
TFPtoTVGlue print;
TFPtoTVGlue event;
TFPtoTVGlue urlnotify;
TFPtoTVGlue getvalue;
TFPtoTVGlue setvalue;
TFPtoTVGlue shutdown;
} gPluginFuncsGlueTable;
static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
{
functionGlue->glue[0] = fp;
functionGlue->glue[1] = 0;
return functionGlue;
}
#define PLUGIN_TO_HOST_GLUE(name, fp) (SetupFPtoTVGlue(&gPluginFuncsGlueTable.name, (void*)fp))
// glue for mapping netscape TVectors to Macho function pointers
struct TTVtoFPGlue {
uint32 glue[6];
};
struct {
TTVtoFPGlue geturl;
TTVtoFPGlue posturl;
TTVtoFPGlue requestread;
TTVtoFPGlue newstream;
TTVtoFPGlue write;
TTVtoFPGlue destroystream;
TTVtoFPGlue status;
TTVtoFPGlue uagent;
TTVtoFPGlue memalloc;
TTVtoFPGlue memfree;
TTVtoFPGlue memflush;
TTVtoFPGlue reloadplugins;
TTVtoFPGlue getJavaEnv;
TTVtoFPGlue getJavaPeer;
TTVtoFPGlue geturlnotify;
TTVtoFPGlue posturlnotify;
TTVtoFPGlue getvalue;
TTVtoFPGlue setvalue;
TTVtoFPGlue invalidaterect;
TTVtoFPGlue invalidateregion;
TTVtoFPGlue forceredraw;
} gNetscapeFuncsGlueTable;
static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
{
static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
memcpy(functionGlue, &glueTemplate, sizeof(TTVtoFPGlue));
functionGlue->glue[0] |= ((UInt32)tvp >> 16);
functionGlue->glue[1] |= ((UInt32)tvp & 0xFFFF);
::MakeDataExecutable(functionGlue, sizeof(TTVtoFPGlue));
return functionGlue;
}
#define HOST_TO_PLUGIN_GLUE(name, fp) (SetupTVtoFPGlue(&gNetscapeFuncsGlueTable.name, (void*)fp))
#else
#define PLUGIN_TO_HOST_GLUE(name, fp) (fp)
#define HOST_TO_PLUGIN_GLUE(name, fp) (fp)
#endif /* XP_MACOSX */
#pragma mark -
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -103,7 +188,6 @@ QDGlobals* gQDPtr; // Pointer to Netscape
short gResFile; // Refnum of the pluginÕs resource file
NPNetscapeFuncs gNetscapeFuncs; // Function table for procs in Netscape called by plugin
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//
// Wrapper functions for all calls from the plugin to Netscape.
@@ -284,6 +368,8 @@ void NPN_ForceRedraw(NPP instance)
CallNPN_ForceRedrawProc( gNetscapeFuncs.forceredraw, instance);
}
#pragma mark -
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//
// Wrapper functions for all calls from Netscape to the plugin.
@@ -326,7 +412,9 @@ void Private_Shutdown(void)
PLUGINDEBUGSTR("\pShutdown;g;");
NPP_Shutdown();
#ifdef __MWERKS__
__destroy_global_chain();
#endif
ExitCodeResource();
}
@@ -456,8 +544,16 @@ jobject Private_GetJavaClass(void)
void SetUpQD(void);
void SetUpQD(void)
{
#if !TARGET_API_MAC_CARBON
ProcessSerialNumber PSN;
FSSpec myFSSpec;
Str63 name;
ProcessInfoRec infoRec;
OSErr result = noErr;
CFragConnectionID connID;
Str255 errName;
#endif
//
// Memorize the pluginÕs resource file
// refnum for later use.
@@ -540,8 +636,12 @@ void SetUpQD(void)
}
#ifdef __GNUC__
// gcc requires that main have an 'int' return type
int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
#else
NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
#endif
#if !TARGET_API_MAC_CARBON
#pragma export on
@@ -551,12 +651,18 @@ RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, ma
#pragma export off
#endif /* !TARGET_API_MAC_CARBON */
#ifdef __GNUC__
DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
#else
DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
#endif
{
EnterCodeResource();
PLUGINDEBUGSTR("\pmain");
#ifdef __MWERKS__
__InitCode__();
#endif
NPError err = NPERR_NO_ERROR;
@@ -592,62 +698,63 @@ DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs,
int navMinorVers = nsTable->version & 0xFF;
gNetscapeFuncs.version = nsTable->version;
gNetscapeFuncs.size = nsTable->size;
gNetscapeFuncs.posturl = nsTable->posturl;
gNetscapeFuncs.geturl = nsTable->geturl;
gNetscapeFuncs.requestread = nsTable->requestread;
gNetscapeFuncs.newstream = nsTable->newstream;
gNetscapeFuncs.write = nsTable->write;
gNetscapeFuncs.destroystream = nsTable->destroystream;
gNetscapeFuncs.status = nsTable->status;
gNetscapeFuncs.uagent = nsTable->uagent;
gNetscapeFuncs.memalloc = nsTable->memalloc;
gNetscapeFuncs.memfree = nsTable->memfree;
gNetscapeFuncs.memflush = nsTable->memflush;
gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
gNetscapeFuncs.version = nsTable->version;
gNetscapeFuncs.size = nsTable->size;
gNetscapeFuncs.posturl = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
gNetscapeFuncs.geturl = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
gNetscapeFuncs.requestread = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
gNetscapeFuncs.newstream = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
gNetscapeFuncs.write = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
gNetscapeFuncs.destroystream = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
gNetscapeFuncs.status = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
gNetscapeFuncs.uagent = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
gNetscapeFuncs.memalloc = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
gNetscapeFuncs.memfree = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
gNetscapeFuncs.memflush = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
gNetscapeFuncs.reloadplugins = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
{
gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
gNetscapeFuncs.getJavaEnv = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
gNetscapeFuncs.getJavaPeer = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
}
if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
{
gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
gNetscapeFuncs.posturlnotify = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
}
gNetscapeFuncs.getvalue = nsTable->getvalue;
gNetscapeFuncs.setvalue = nsTable->setvalue;
gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
gNetscapeFuncs.forceredraw = nsTable->forceredraw;
gNetscapeFuncs.getvalue = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
gNetscapeFuncs.setvalue = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
gNetscapeFuncs.invalidaterect = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
gNetscapeFuncs.forceredraw = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
//
// Set up the plugin function table that Netscape will use to
// call us. Netscape needs to know about our version and size
// and have a UniversalProcPointer for every function we implement.
//
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
pluginFuncs->size = sizeof(NPPluginFuncs);
pluginFuncs->newp = NewNPP_NewProc(Private_New);
pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
pluginFuncs->write = NewNPP_WriteProc(Private_Write);
pluginFuncs->print = NewNPP_PrintProc(Private_Print);
pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
pluginFuncs->size = sizeof(NPPluginFuncs);
pluginFuncs->newp = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
pluginFuncs->destroy = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
pluginFuncs->setwindow = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
pluginFuncs->newstream = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
pluginFuncs->destroystream = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
pluginFuncs->asfile = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
pluginFuncs->writeready = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
pluginFuncs->write = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
pluginFuncs->print = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
pluginFuncs->event = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
{
pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
}
if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
{
pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
}
*unloadUpp = NewNPP_ShutdownProc(Private_Shutdown);
*unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
SetUpQD();
err = Private_Initialize();
}