Bug 402742 - "Stock icons will not display if libgnomeui is not present" (more soft runtime dependencies) [p=ventnor.bugzilla@yahoo.com.au (Michael Ventnor) r=vlad sr=roc aM10=schrep]

This commit is contained in:
reed@reedloden.com 2007-12-07 16:08:09 -08:00
parent 95d3f5f43f
commit f4fc4c5f32
7 changed files with 99 additions and 41 deletions

View File

@ -5500,16 +5500,6 @@ done
dnl ========================================================
dnl Image decoders
dnl ========================================================
case "$MOZ_WIDGET_TOOLKIT" in
beos|windows|os2|mac|cocoa)
;;
*)
if test -z "$MOZ_ENABLE_GNOMEUI"; then
MOZ_IMG_DECODERS_DEFAULT=`echo $MOZ_IMG_DECODERS_DEFAULT | sed -e 's|icon||'`
fi
;;
esac
MOZ_ARG_ENABLE_STRING(image-decoders,
[ --enable-image-decoders[={mod1,mod2,default,all,none}]
Enable specific image decoders],

View File

@ -43,7 +43,7 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifneq (,$(filter icon,$(MOZ_IMG_DECODERS)))
ifdef MOZ_ENABLE_GNOMEUI
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
TOOL_DIRS = icon/gtk icon
endif
ifeq ($(OS_ARCH),WINNT)

View File

@ -49,18 +49,10 @@ MODULE_NAME = nsIconDecoderModule
PACKAGE_FILE = imgicon.pkg
ifdef MOZ_ENABLE_GNOMEUI
EXTRA_DSO_LDOPTS = \
$(MOZ_GNOMEVFS_LIBS) \
$(MOZ_LIBGNOME_LIBS) \
$(MOZ_GTK2_LIBS) \
$(NULL)
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS = $(MOZ_GTK2_LIBS)
PLATFORM = gtk
FORCE_SHARED_LIB = 1
else
LIBXUL_LIBRARY = 1
EXPORT_LIBRARY = 1
endif
ifeq ($(OS_ARCH),WINNT)
@ -94,7 +86,7 @@ CPPSRCS = \
nsIconProtocolHandler.cpp \
$(NULL)
ifdef MOZ_ENABLE_GNOMEUI
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
USE_ICON_DECODER = 1
endif
ifeq (,$(filter-out Darwin OS2 BeOS,$(OS_ARCH)))

View File

@ -54,7 +54,11 @@ REQUIRES = xpcom \
CPPSRCS = nsIconChannel.cpp
ifdef MOZ_ENABLE_GNOMEUI
LOCAL_INCLUDES += $(MOZ_GNOMEUI_CFLAGS)
else
LOCAL_INCLUDES += $(MOZ_GTK2_CFLAGS)
endif
# we don't want the shared lib, but we want to force the creation of a static lib.
FORCE_STATIC_LIB = 1

View File

@ -38,6 +38,7 @@
#include <stdlib.h>
#include <unistd.h>
#ifdef MOZ_ENABLE_GNOMEUI
// Older versions of these headers seem to be missing an extern "C"
extern "C" {
#include <libgnome/libgnome.h>
@ -47,6 +48,7 @@ extern "C" {
#include <libgnomevfs/gnome-vfs-file-info.h>
#include <libgnomevfs/gnome-vfs-ops.h>
}
#endif
#include <gtk/gtkwidget.h>
#include <gtk/gtkiconfactory.h>
@ -69,6 +71,7 @@ NS_IMPL_ISUPPORTS2(nsIconChannel,
nsIRequest,
nsIChannel)
#ifdef MOZ_ENABLE_GNOMEUI
// These let us have a soft dependency on libgnomeui rather than a hard one. These are just basically the prototypes
// of the functions in the libraries.
typedef char* (*_GnomeIconLookup_fn)(GtkIconTheme *icon_theme, GnomeThumbnailFactory *thumbnail_factory,
@ -79,14 +82,23 @@ typedef char* (*_GnomeIconThemeLookupIcon_fn)(GnomeIconTheme *theme, const char
const GnomeIconData **icon_data, int *base_size);
typedef int (*_GnomeInit_fn)(const char *app_id, const char *app_version, int argc, char **argv, const struct poptOption *options,
int flags, poptContext *return_ctx);
typedef GnomeProgram* (*_GnomeProgramGet_fn)(void);
typedef GnomeVFSResult (*_GnomeVFSGetFileInfo_fn)(const gchar *text_uri, GnomeVFSFileInfo *info, GnomeVFSFileInfoOptions options);
typedef void (*_GnomeVFSFileInfoClear_fn)(GnomeVFSFileInfo *info);
static PRLibrary* gLibGnomeUI = nsnull;
static PRBool gTriedToLoadLibGnomeUI = PR_FALSE;
static PRLibrary* gLibGnome = nsnull;
static PRLibrary* gLibGnomeVFS = nsnull;
static PRBool gTriedToLoadGnomeLibs = PR_FALSE;
static _GnomeIconLookup_fn _gnome_icon_lookup = nsnull;
static _GnomeIconThemeNew_fn _gnome_icon_theme_new = nsnull;
static _GnomeIconThemeLookupIcon_fn _gnome_icon_theme_lookup_icon = nsnull;
static _GnomeInit_fn _gnome_init = nsnull;
static _GnomeProgramGet_fn _gnome_program_get = nsnull;
static _GnomeVFSGetFileInfo_fn _gnome_vfs_get_file_info = nsnull;
static _GnomeVFSFileInfoClear_fn _gnome_vfs_file_info_clear = nsnull;
#endif
static nsresult
moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
@ -154,7 +166,9 @@ moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
static GtkWidget *gProtoWindow = nsnull;
static GtkWidget *gStockImageWidget = nsnull;
#ifdef MOZ_ENABLE_GNOMEUI
static GnomeIconTheme *gIconTheme = nsnull;
#endif
#if GTK_CHECK_VERSION(2,4,0)
static GtkIconFactory *gIconFactory = nsnull;
@ -187,14 +201,14 @@ ensure_icon_factory()
}
#endif
#ifdef MOZ_ENABLE_GNOMEUI
static nsresult
ensure_libgnomeui()
{
// Attempt to get the libgnomeui symbol references. We do it this way so that stock icons from Init()
// don't get held back by InitWithGnome()'s libgnomeui dependency.
if (!gTriedToLoadLibGnomeUI) {
if (!gTriedToLoadGnomeLibs) {
gLibGnomeUI = PR_LoadLibrary("libgnomeui-2.so.0");
gTriedToLoadLibGnomeUI = PR_TRUE;
if (!gLibGnomeUI)
return NS_ERROR_NOT_AVAILABLE;
@ -203,7 +217,7 @@ ensure_libgnomeui()
_gnome_icon_lookup = (_GnomeIconLookup_fn)PR_FindFunctionSymbol(gLibGnomeUI, "gnome_icon_lookup");
_gnome_icon_theme_lookup_icon = (_GnomeIconThemeLookupIcon_fn)PR_FindFunctionSymbol(gLibGnomeUI, "gnome_icon_theme_lookup_icon");
if (!_gnome_init || !_gnome_icon_theme_new || !gnome_icon_lookup || !_gnome_icon_theme_lookup_icon) {
if (!_gnome_init || !_gnome_icon_theme_new || !_gnome_icon_lookup || !_gnome_icon_theme_lookup_icon) {
PR_UnloadLibrary(gLibGnomeUI);
gLibGnomeUI = nsnull;
return NS_ERROR_NOT_AVAILABLE;
@ -216,6 +230,52 @@ ensure_libgnomeui()
return NS_OK;
}
static nsresult
ensure_libgnome()
{
if (!gTriedToLoadGnomeLibs) {
gLibGnome = PR_LoadLibrary("libgnome-2.so.0");
if (!gLibGnome)
return NS_ERROR_NOT_AVAILABLE;
_gnome_program_get = (_GnomeProgramGet_fn)PR_FindFunctionSymbol(gLibGnome, "gnome_program_get");
if (!_gnome_program_get) {
PR_UnloadLibrary(gLibGnome);
gLibGnome = nsnull;
return NS_ERROR_NOT_AVAILABLE;
}
}
if (!gLibGnome)
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
static nsresult
ensure_libgnomevfs()
{
if (!gTriedToLoadGnomeLibs) {
gLibGnomeVFS = PR_LoadLibrary("libgnomevfs-2.so.0");
if (!gLibGnomeVFS)
return NS_ERROR_NOT_AVAILABLE;
_gnome_vfs_get_file_info = (_GnomeVFSGetFileInfo_fn)PR_FindFunctionSymbol(gLibGnomeVFS, "gnome_vfs_get_file_info");
_gnome_vfs_file_info_clear = (_GnomeVFSFileInfoClear_fn)PR_FindFunctionSymbol(gLibGnomeVFS, "gnome_vfs_file_info_clear");
if (!_gnome_vfs_get_file_info || !_gnome_vfs_file_info_clear) {
PR_UnloadLibrary(gLibGnomeVFS);
gLibGnomeVFS = nsnull;
return NS_ERROR_NOT_AVAILABLE;
}
}
if (!gLibGnomeVFS)
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
#endif
static GtkIconSize
moz_gtk_icon_size(const char *name)
{
@ -240,15 +300,20 @@ moz_gtk_icon_size(const char *name)
return GTK_ICON_SIZE_MENU;
}
#ifdef MOZ_ENABLE_GNOMEUI
nsresult
nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
{
nsresult rv;
if (NS_FAILED(ensure_libgnomeui()))
if (NS_FAILED(ensure_libgnomeui()) || NS_FAILED(ensure_libgnome()) || NS_FAILED(ensure_libgnomevfs())) {
gTriedToLoadGnomeLibs = PR_TRUE;
return NS_ERROR_NOT_AVAILABLE;
if (!gnome_program_get()) {
}
gTriedToLoadGnomeLibs = PR_TRUE;
if (!_gnome_program_get()) {
// Get the brandShortName from the string bundle to pass to GNOME
// as the application name. This may be used for things such as
// the title of grouped windows in the panel.
@ -305,7 +370,7 @@ nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
// network request
PRBool isFile;
if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) {
gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT);
_gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT);
}
else {
// We have to get a leaf name from our uri...
@ -344,7 +409,7 @@ nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
gIconTheme = _gnome_icon_theme_new();
if (!gIconTheme) {
gnome_vfs_file_info_clear(&fileInfo);
_gnome_vfs_file_info_clear(&fileInfo);
return NS_ERROR_NOT_AVAILABLE;
}
}
@ -353,7 +418,7 @@ nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
type.get(), GNOME_ICON_LOOKUP_FLAGS_NONE,
NULL);
gnome_vfs_file_info_clear(&fileInfo);
_gnome_vfs_file_info_clear(&fileInfo);
if (!name)
return NS_ERROR_NOT_AVAILABLE;
@ -391,6 +456,7 @@ nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
gdk_pixbuf_unref(scaled);
return rv;
}
#endif
nsresult
nsIconChannel::Init(nsIURI* aURI)
@ -401,7 +467,11 @@ nsIconChannel::Init(nsIURI* aURI)
nsCAutoString stockIcon;
iconURI->GetStockIcon(stockIcon);
if (stockIcon.IsEmpty()) {
#ifdef MOZ_ENABLE_GNOMEUI
return InitWithGnome(iconURI);
#else
return NS_ERROR_NOT_AVAILABLE;
#endif
}
nsCAutoString iconSizeString;
@ -455,13 +525,23 @@ nsIconChannel::Shutdown() {
gProtoWindow = nsnull;
gStockImageWidget = nsnull;
}
#ifdef MOZ_ENABLE_GNOMEUI
if (gIconTheme) {
g_object_unref(G_OBJECT(gIconTheme));
gIconTheme = nsnull;
}
gTriedToLoadGnomeLibs = PR_FALSE;
if (gLibGnomeUI) {
PR_UnloadLibrary(gLibGnomeUI);
gLibGnomeUI = nsnull;
gTriedToLoadLibGnomeUI = PR_FALSE;
}
if (gLibGnome) {
PR_UnloadLibrary(gLibGnome);
gLibGnome = nsnull;
}
if (gLibGnomeVFS) {
PR_UnloadLibrary(gLibGnomeVFS);
gLibGnomeVFS = nsnull;
}
#endif
}

View File

@ -119,9 +119,7 @@ IconDecoderModuleCtor(nsIModule* aSelf)
PR_STATIC_CALLBACK(void)
IconDecoderModuleDtor(nsIModule* aSelf)
{
#ifdef MOZ_ENABLE_GNOMEUI
nsIconChannel::Shutdown();
#endif
}
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsIconDecoderModule, components,

View File

@ -275,12 +275,6 @@ ifdef MOZ_ENABLE_POSTSCRIPT
DEFINES += -DMOZ_ENABLE_POSTSCRIPT
STATIC_LIBS += gfxpsshar
endif
ifneq (,$(filter icon,$(MOZ_IMG_DECODERS)))
ifndef MOZ_ENABLE_GNOMEUI
DEFINES += -DICON_DECODER
COMPONENT_LIBS += imgicon
endif
endif
ifdef MOZ_ENABLE_CAIRO_GFX
STATIC_LIBS += thebes