diff --git a/mozilla/camino/Chimera.pbproj/project.pbxproj b/mozilla/camino/Chimera.pbproj/project.pbxproj index 1f5b8e431a1..51cd07b9564 100644 --- a/mozilla/camino/Chimera.pbproj/project.pbxproj +++ b/mozilla/camino/Chimera.pbproj/project.pbxproj @@ -3810,6 +3810,12 @@ isa = PBXTargetDependency; target = F58581AE022B8D62010001CA; }; + F585F52902B2C66C01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F58A94F2023F10CA010001CA = { children = ( 29B97319FDCFA39411CA2CEA, @@ -5805,6 +5811,7 @@ F5BAAC3E02AC6AA201A967F3, F5BAAC3F02AC6AA201A967F3, F5BAAC4002AC6AA201A967F3, + F585F52902B2C66C01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; @@ -6073,6 +6080,18 @@ name = "Gray Images"; refType = 4; }; + F5F14E9602A5A43A01A967F3 = { + isa = PBXFileReference; + name = libwidget.rsrc; + path = ../dist/Embed/libwidget.rsrc; + refType = 2; + }; + F5F14E9802A5A43A01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F5F181C50208006F0124611D = { isa = PBXFileReference; name = history.xpt; @@ -6200,6 +6219,7 @@ F6BD638101B30EA301A962F7, F6BD638201B30EA301A962F7, F6BD638701B30F5301A962F7, + F5F14E9602A5A43A01A967F3, F5247C2F0228B5E7013DD99A, F6BD645501B3167601A962F7, F6BD64FB01B3184301A962F7, @@ -6222,6 +6242,7 @@ F6BD638C01B30F5301A962F7, F6BD638D01B30F5301A962F7, F6BD638E01B30F5301A962F7, + F5F14E9802A5A43A01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; diff --git a/mozilla/camino/projects/Chimera.pbproj/project.pbxproj b/mozilla/camino/projects/Chimera.pbproj/project.pbxproj index 1f5b8e431a1..51cd07b9564 100644 --- a/mozilla/camino/projects/Chimera.pbproj/project.pbxproj +++ b/mozilla/camino/projects/Chimera.pbproj/project.pbxproj @@ -3810,6 +3810,12 @@ isa = PBXTargetDependency; target = F58581AE022B8D62010001CA; }; + F585F52902B2C66C01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F58A94F2023F10CA010001CA = { children = ( 29B97319FDCFA39411CA2CEA, @@ -5805,6 +5811,7 @@ F5BAAC3E02AC6AA201A967F3, F5BAAC3F02AC6AA201A967F3, F5BAAC4002AC6AA201A967F3, + F585F52902B2C66C01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; @@ -6073,6 +6080,18 @@ name = "Gray Images"; refType = 4; }; + F5F14E9602A5A43A01A967F3 = { + isa = PBXFileReference; + name = libwidget.rsrc; + path = ../dist/Embed/libwidget.rsrc; + refType = 2; + }; + F5F14E9802A5A43A01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F5F181C50208006F0124611D = { isa = PBXFileReference; name = history.xpt; @@ -6200,6 +6219,7 @@ F6BD638101B30EA301A962F7, F6BD638201B30EA301A962F7, F6BD638701B30F5301A962F7, + F5F14E9602A5A43A01A967F3, F5247C2F0228B5E7013DD99A, F6BD645501B3167601A962F7, F6BD64FB01B3184301A962F7, @@ -6222,6 +6242,7 @@ F6BD638C01B30F5301A962F7, F6BD638D01B30F5301A962F7, F6BD638E01B30F5301A962F7, + F5F14E9802A5A43A01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; diff --git a/mozilla/chimera/Chimera.pbproj/project.pbxproj b/mozilla/chimera/Chimera.pbproj/project.pbxproj index 1f5b8e431a1..51cd07b9564 100644 --- a/mozilla/chimera/Chimera.pbproj/project.pbxproj +++ b/mozilla/chimera/Chimera.pbproj/project.pbxproj @@ -3810,6 +3810,12 @@ isa = PBXTargetDependency; target = F58581AE022B8D62010001CA; }; + F585F52902B2C66C01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F58A94F2023F10CA010001CA = { children = ( 29B97319FDCFA39411CA2CEA, @@ -5805,6 +5811,7 @@ F5BAAC3E02AC6AA201A967F3, F5BAAC3F02AC6AA201A967F3, F5BAAC4002AC6AA201A967F3, + F585F52902B2C66C01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; @@ -6073,6 +6080,18 @@ name = "Gray Images"; refType = 4; }; + F5F14E9602A5A43A01A967F3 = { + isa = PBXFileReference; + name = libwidget.rsrc; + path = ../dist/Embed/libwidget.rsrc; + refType = 2; + }; + F5F14E9802A5A43A01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F5F181C50208006F0124611D = { isa = PBXFileReference; name = history.xpt; @@ -6200,6 +6219,7 @@ F6BD638101B30EA301A962F7, F6BD638201B30EA301A962F7, F6BD638701B30F5301A962F7, + F5F14E9602A5A43A01A967F3, F5247C2F0228B5E7013DD99A, F6BD645501B3167601A962F7, F6BD64FB01B3184301A962F7, @@ -6222,6 +6242,7 @@ F6BD638C01B30F5301A962F7, F6BD638D01B30F5301A962F7, F6BD638E01B30F5301A962F7, + F5F14E9802A5A43A01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; diff --git a/mozilla/chimera/projects/Chimera.pbproj/project.pbxproj b/mozilla/chimera/projects/Chimera.pbproj/project.pbxproj index 1f5b8e431a1..51cd07b9564 100644 --- a/mozilla/chimera/projects/Chimera.pbproj/project.pbxproj +++ b/mozilla/chimera/projects/Chimera.pbproj/project.pbxproj @@ -3810,6 +3810,12 @@ isa = PBXTargetDependency; target = F58581AE022B8D62010001CA; }; + F585F52902B2C66C01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F58A94F2023F10CA010001CA = { children = ( 29B97319FDCFA39411CA2CEA, @@ -5805,6 +5811,7 @@ F5BAAC3E02AC6AA201A967F3, F5BAAC3F02AC6AA201A967F3, F5BAAC4002AC6AA201A967F3, + F585F52902B2C66C01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; @@ -6073,6 +6080,18 @@ name = "Gray Images"; refType = 4; }; + F5F14E9602A5A43A01A967F3 = { + isa = PBXFileReference; + name = libwidget.rsrc; + path = ../dist/Embed/libwidget.rsrc; + refType = 2; + }; + F5F14E9802A5A43A01A967F3 = { + fileRef = F5F14E9602A5A43A01A967F3; + isa = PBXBuildFile; + settings = { + }; + }; F5F181C50208006F0124611D = { isa = PBXFileReference; name = history.xpt; @@ -6200,6 +6219,7 @@ F6BD638101B30EA301A962F7, F6BD638201B30EA301A962F7, F6BD638701B30F5301A962F7, + F5F14E9602A5A43A01A967F3, F5247C2F0228B5E7013DD99A, F6BD645501B3167601A962F7, F6BD64FB01B3184301A962F7, @@ -6222,6 +6242,7 @@ F6BD638C01B30F5301A962F7, F6BD638D01B30F5301A962F7, F6BD638E01B30F5301A962F7, + F5F14E9802A5A43A01A967F3, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; diff --git a/mozilla/config/Makefile.in b/mozilla/config/Makefile.in index 44959665e85..40e29bfa920 100644 --- a/mozilla/config/Makefile.in +++ b/mozilla/config/Makefile.in @@ -41,7 +41,7 @@ else CSRCS = nsinstall.c pathsub.c endif -TARGETS = $(HOST_PROGRAM) $(PROGRAM) $(PLSRCS:.pl=) +TARGETS = $(HOST_PROGRAM) $(PROGRAM) $(PLSRCS:.pl=) $(SIMPLE_PROGRAMS) # Generate the build number on the fly. TARGETS += build_number nsBuildID.h @@ -50,6 +50,10 @@ ifdef USE_ELF_DYNSTR_GC TARGETS += elf-dynstr-gc endif +ifeq ($(OS_ARCH), Darwin) +SIMPLE_PROGRAMS += asdecode +endif + # IMPORTANT: Disable NSBUILDROOT for this directory only, otherwise we have # a recursive rule for finding nsinstall and the Perl scripts. ifdef NSBUILDROOT diff --git a/mozilla/config/asdecode.cpp b/mozilla/config/asdecode.cpp new file mode 100644 index 00000000000..b66cbca35b7 --- /dev/null +++ b/mozilla/config/asdecode.cpp @@ -0,0 +1,146 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 the AppleSingle decoder. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Patrick Beard (Original author) + * Brian Ryner + * + * 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 ***** */ + +#include +#include +#include +#include + +#define EXIT_IF_FALSE(x) if (!(x)) exit(1); + +// decodes a file into data and resource forks. + +static int read_int(FILE* f) +{ + int result; + EXIT_IF_FALSE(fread(&result, sizeof(result), 1, f) == 1); + return result; +} + +static void copy_range(FILE* input, size_t offset, size_t length, + const char* output_name) +{ + FILE* output = fopen(output_name, "wb"); + EXIT_IF_FALSE(output != NULL); + fseek(input, offset, SEEK_SET); + while (length != 0) { + char buffer[4096]; + size_t amount = (length > sizeof(buffer) ? sizeof(buffer) : length); + EXIT_IF_FALSE(fread(buffer, 1, amount, input) == amount); + fwrite(buffer, 1, amount, output); + length -= amount; + } + fclose(output); +} + +int main(int argc, char** argv) +{ + if (argc < 3) { + printf("usage: %s input output\n", argv[0]); + exit(1); + } + + FILE* input = fopen(argv[1], "rb"); + if (input == NULL) { + printf("can't open file `%s'\n", argv[1]); + exit(2); + } + + struct header { + int magic_number; + int version_number; + char filler[16]; + } header; + + EXIT_IF_FALSE(fread(&header, sizeof(header), 1, input) == 1); + EXIT_IF_FALSE(header.magic_number == 0x00051600); + EXIT_IF_FALSE(header.version_number <= 0x00020000); + // printf("sizeof(header) == %d\n", sizeof(header)); + + short entry_count; + EXIT_IF_FALSE(fread(&entry_count, sizeof(entry_count), 1, input) == 1); + + struct entry { + unsigned int id; + unsigned int offset; + unsigned int length; + }; + + entry* entries = new entry[entry_count]; + EXIT_IF_FALSE(fread(entries, sizeof(entry), entry_count, input) == entry_count); + + entry* data_entry = NULL; + entry* rez_entry = NULL; + + for (int i = 0; i < entry_count; i++) { + entry& entry = entries[i]; + switch (entry.id) { + case 1: + // data fork. + data_entry = &entry; + break; + case 2: + rez_entry = &entry; + break; + } + } + + const char* data_name = argv[2]; + if (data_entry && data_entry->length) { + copy_range(input, data_entry->offset, data_entry->length, data_name); + } else { + // always create the data fork, even if the file doesn't have one. + FILE* tmp = fopen(data_name, "wb"); + EXIT_IF_FALSE(tmp); + fclose(tmp); + } + + if (rez_entry && rez_entry->length) { + char rez_name[512]; + strcpy(rez_name, data_name); + strcat(rez_name, "/rsrc"); + copy_range(input, rez_entry->offset, rez_entry->length, rez_name); + } + + delete[] entries; + + fclose(input); + + return 0; +} diff --git a/mozilla/embedding/config/basebrowser-mac-macho b/mozilla/embedding/config/basebrowser-mac-macho index 4a1533a4b67..d23da5c1ae6 100644 --- a/mozilla/embedding/config/basebrowser-mac-macho +++ b/mozilla/embedding/config/basebrowser-mac-macho @@ -232,6 +232,7 @@ components/uriloader.xpt ; widget components/libwidget_mac.dylib components/widget.xpt +libwidget.rsrc ; xpconnect components/libxpconnect.dylib diff --git a/mozilla/widget/src/cocoa/Makefile.in b/mozilla/widget/src/cocoa/Makefile.in index 479a4f3dad5..db19a47a5ea 100644 --- a/mozilla/widget/src/cocoa/Makefile.in +++ b/mozilla/widget/src/cocoa/Makefile.in @@ -97,6 +97,21 @@ XPIDLSRCS += \ SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a +# nsMacWidget.rsrc is an AppleSingle encoded resource file. +# For Mach-O, we want to decode it and copy it to a data-fork resource file +# that lives in the application directory. + +RES_DEST = $(DIST)/bin/libwidget.rsrc +RES_SRC = $(srcdir)/../mac/nsMacWidget.rsrc + +$(RES_DEST): $(RES_SRC) + $(DIST)/bin/asdecode $(RES_SRC) $(RES_DEST).tmp + rm -f $(RES_DEST) + cp $(RES_DEST).tmp/rsrc $(RES_DEST) + rm -rf $(RES_DEST).tmp + +libs:: $(RES_DEST) + EXTRA_DSO_LDOPTS += \ $(MOZ_UNICHARUTIL_LIBS) \ $(TK_LIBS) \ diff --git a/mozilla/widget/src/cocoa/nsMacResources.cpp b/mozilla/widget/src/cocoa/nsMacResources.cpp index f626dfb8991..ca42f7a2e0c 100644 --- a/mozilla/widget/src/cocoa/nsMacResources.cpp +++ b/mozilla/widget/src/cocoa/nsMacResources.cpp @@ -37,7 +37,7 @@ #include "nsMacResources.h" #include - +#include short nsMacResources::mRefNum = kResFileNotOpened; short nsMacResources::mSaveResFile = 0; @@ -86,11 +86,23 @@ pascal void __terminateResources(void) nsresult nsMacResources::OpenLocalResourceFile() { #ifdef XP_MACOSX - // XXX quick and dirty hack to make resources available so we don't crash. - if (mRefNum == kResFileNotOpened) { - FSSpec spec = { 0, 0, "\plibwidget.rsrc" }; - if (FindFolder(kUserDomain, kDomainLibraryFolderType, false, &spec.vRefNum, &spec.parID) == noErr) - mRefNum = FSpOpenResFile(&spec, fsRdPerm); + if (mRefNum == kResFileNotOpened) { + ProcessSerialNumber PSN; + ProcessInfoRec pinfo; + FSSpec appSpec; + + PSN.highLongOfPSN = 0; + PSN.lowLongOfPSN = kCurrentProcess; + pinfo.processInfoLength = sizeof(pinfo); + pinfo.processName = NULL; + pinfo.processAppSpec = &appSpec; + + if (GetProcessInformation(&PSN, &pinfo) == noErr) { + FSSpec resSpec = { appSpec.vRefNum, appSpec.parID, "\plibwidget.rsrc" }; + FSRef resRef; + if (FSpMakeFSRef(&resSpec, &resRef) == noErr) + FSOpenResourceFile(&resRef, 0, NULL, fsRdPerm, &mRefNum); + } } #endif if (mRefNum == kResFileNotOpened) diff --git a/mozilla/widget/src/mac/Makefile.in b/mozilla/widget/src/mac/Makefile.in index fd197a42df8..95b8b0e952d 100644 --- a/mozilla/widget/src/mac/Makefile.in +++ b/mozilla/widget/src/mac/Makefile.in @@ -114,6 +114,21 @@ include $(topsrcdir)/config/rules.mk export:: $(addprefix $(topsrcdir)/gfx/src/mac/,$(GFX_LCPPSRCS)) $(INSTALL) $^ . +# nsMacWidget.rsrc is an AppleSingle encoded resource file. +# For Mach-O, we want to decode it and copy it to a data-fork resource file +# that lives in the application directory. + +RES_DEST = $(DIST)/bin/libwidget.rsrc +RES_SRC = $(srcdir)/nsMacWidget.rsrc + +$(RES_DEST): $(RES_SRC) + $(DIST)/bin/asdecode $(RES_SRC) $(RES_DEST).tmp + rm -f $(RES_DEST) + cp $(RES_DEST).tmp/rsrc $(RES_DEST) + rm -rf $(RES_DEST).tmp + +libs:: $(RES_DEST) + LOCAL_INCLUDES = \ $(TK_CFLAGS) \ -I$(topsrcdir)/gfx/src/mac \ diff --git a/mozilla/widget/src/mac/nsMacResources.cpp b/mozilla/widget/src/mac/nsMacResources.cpp index f626dfb8991..ca42f7a2e0c 100644 --- a/mozilla/widget/src/mac/nsMacResources.cpp +++ b/mozilla/widget/src/mac/nsMacResources.cpp @@ -37,7 +37,7 @@ #include "nsMacResources.h" #include - +#include short nsMacResources::mRefNum = kResFileNotOpened; short nsMacResources::mSaveResFile = 0; @@ -86,11 +86,23 @@ pascal void __terminateResources(void) nsresult nsMacResources::OpenLocalResourceFile() { #ifdef XP_MACOSX - // XXX quick and dirty hack to make resources available so we don't crash. - if (mRefNum == kResFileNotOpened) { - FSSpec spec = { 0, 0, "\plibwidget.rsrc" }; - if (FindFolder(kUserDomain, kDomainLibraryFolderType, false, &spec.vRefNum, &spec.parID) == noErr) - mRefNum = FSpOpenResFile(&spec, fsRdPerm); + if (mRefNum == kResFileNotOpened) { + ProcessSerialNumber PSN; + ProcessInfoRec pinfo; + FSSpec appSpec; + + PSN.highLongOfPSN = 0; + PSN.lowLongOfPSN = kCurrentProcess; + pinfo.processInfoLength = sizeof(pinfo); + pinfo.processName = NULL; + pinfo.processAppSpec = &appSpec; + + if (GetProcessInformation(&PSN, &pinfo) == noErr) { + FSSpec resSpec = { appSpec.vRefNum, appSpec.parID, "\plibwidget.rsrc" }; + FSRef resRef; + if (FSpMakeFSRef(&resSpec, &resRef) == noErr) + FSOpenResourceFile(&resRef, 0, NULL, fsRdPerm, &mRefNum); + } } #endif if (mRefNum == kResFileNotOpened)