Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
nsGNOMERegistry Class Reference

#include <nsGNOMERegistry.h>

List of all members.

Static Public Member Functions

static void Startup ()
static PRBool HandlerExists (const char *aProtocolScheme)
static nsresult LoadURL (nsIURI *aURL)
static void GetAppDescForScheme (const nsACString &aScheme, nsAString &aDesc)
static already_AddRefed
< nsMIMEInfoBase
GetFromExtension (const char *aFileExt)
static already_AddRefed
< nsMIMEInfoBase
GetFromType (const char *aMIMEType)

Detailed Description

Definition at line 43 of file nsGNOMERegistry.h.


Member Function Documentation

void nsGNOMERegistry::GetAppDescForScheme ( const nsACString &  aScheme,
nsAString &  aDesc 
) [static]

Definition at line 255 of file nsGNOMERegistry.cpp.

{
  char *app = getAppForScheme(aScheme);

  if (app) {
    CopyUTF8toUTF16(app, aDesc);
    g_free(app);
  }
}

Here is the call graph for this function:

Definition at line 268 of file nsGNOMERegistry.cpp.

{
  if (!gconfLib)
    return nsnull;

  // Get the MIME type from the extension, then call GetFromType to
  // fill in the MIMEInfo.

  nsCAutoString fileExtToUse;
  if (aFileExt && aFileExt[0] != '.')
    fileExtToUse = '.';

  fileExtToUse.Append(aFileExt);

  const char *mimeType = _gnome_vfs_mime_type_from_name(fileExtToUse.get());
  if (!strcmp(mimeType, "application/octet-stream"))
    return nsnull;

  return GetFromType(mimeType);
}

Here is the call graph for this function:

Definition at line 290 of file nsGNOMERegistry.cpp.

{
  if (!gconfLib)
    return nsnull;

  GnomeVFSMimeApplication *handlerApp = _gnome_vfs_mime_get_default_application(aMIMEType);
  if (!handlerApp)
    return nsnull;

  nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(aMIMEType);
  NS_ENSURE_TRUE(mimeInfo, nsnull);

  // Get the list of extensions and append then to the mimeInfo.
  GList *extensions = _gnome_vfs_mime_get_extensions_list(aMIMEType);
  for (GList *extension = extensions; extension; extension = extension->next)
    mimeInfo->AppendExtension(nsDependentCString((const char *) extension->data));

  _gnome_vfs_mime_extensions_list_free(extensions);

  const char *description = _gnome_vfs_mime_get_description(aMIMEType);
  mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(description));

  // Convert UTF-8 registry value to filesystem encoding, which
  // g_find_program_in_path() uses.

  gchar *nativeCommand = g_filename_from_utf8(handlerApp->command,
                                              -1, NULL, NULL, NULL);
  if (!nativeCommand) {
    NS_ERROR("Could not convert helper app command to filesystem encoding");
    _gnome_vfs_mime_application_free(handlerApp);
    return nsnull;
  }

  gchar *commandPath = g_find_program_in_path(nativeCommand);

  g_free(nativeCommand);

  if (!commandPath) {
    _gnome_vfs_mime_application_free(handlerApp);
    return nsnull;
  }

  nsCOMPtr<nsILocalFile> appFile;
  NS_NewNativeLocalFile(nsDependentCString(commandPath), PR_TRUE,
                        getter_AddRefs(appFile));
  if (appFile) {
    mimeInfo->SetDefaultApplication(appFile);
    mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(handlerApp->name));
    mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
  }

  g_free(commandPath);

  _gnome_vfs_mime_application_free(handlerApp);

  nsMIMEInfoBase* retval;
  NS_ADDREF((retval = mimeInfo));
  return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGNOMERegistry::HandlerExists ( const char *  aProtocolScheme) [static]

Definition at line 216 of file nsGNOMERegistry.cpp.

{
  gchar *app = getAppForScheme(nsDependentCString(aProtocolScheme));

  if (app) {
    g_free(app);
    GConfClient *client = _gconf_client_get_default();

    nsCAutoString enabledPath(NS_LITERAL_CSTRING("/desktop/gnome/url-handlers/") +
                              nsDependentCString(aProtocolScheme) +
                              NS_LITERAL_CSTRING("/enabled"));
    gboolean isEnabled = _gconf_client_get_bool(client, enabledPath.get(), NULL);

    g_object_unref(G_OBJECT(client));

    return isEnabled ? PR_TRUE : PR_FALSE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Definition at line 238 of file nsGNOMERegistry.cpp.

{
  if (!gconfLib)
    return NS_ERROR_FAILURE;

  nsCAutoString spec;
  aURL->GetAsciiSpec(spec);

  // XXX what if gnome_url_show() uses the default handler and that's us?

  if (_gnome_url_show(spec.get(), NULL))
    return NS_OK;

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Definition at line 126 of file nsGNOMERegistry.cpp.

{
  #define ENSURE_LIB(lib) \
    PR_BEGIN_MACRO \
    if (!lib) { \
      CleanUp(); \
      return; \
    } \
    PR_END_MACRO

  #define GET_LIB_FUNCTION(lib, func) \
    PR_BEGIN_MACRO \
    _##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \
    if (!_##func) { \
      CleanUp(); \
      return; \
    } \
    PR_END_MACRO

  // Attempt to open libgconf
  gconfLib = LoadVersionedLibrary("gconf-2", ".4");
  ENSURE_LIB(gconfLib);

  GET_LIB_FUNCTION(gconf, gconf_client_get_default);
  GET_LIB_FUNCTION(gconf, gconf_client_get_string);
  GET_LIB_FUNCTION(gconf, gconf_client_get_bool);

  // Attempt to open libgnome
  gnomeLib = LoadVersionedLibrary("gnome-2", ".0");
  ENSURE_LIB(gnomeLib);

  GET_LIB_FUNCTION(gnome, gnome_url_show);
  GET_LIB_FUNCTION(gnome, gnome_program_init);
  GET_LIB_FUNCTION(gnome, libgnome_module_info_get);
  GET_LIB_FUNCTION(gnome, gnome_program_get);

  // Attempt to open libgnomevfs
  vfsLib = LoadVersionedLibrary("gnomevfs-2", ".0");
  ENSURE_LIB(vfsLib);

  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_type_from_name);
  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_extensions_list);
  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_extensions_list_free);
  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_description);
  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_default_application);
  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_free);

  // Initialize GNOME, if it's not already initialized.  It's not
  // necessary to tell GNOME about our actual command line arguments.

  if (!_gnome_program_get()) {
    char *argv[1] = { "gecko" };
    _gnome_program_init("Gecko", "1.0", _libgnome_module_info_get(),
                        1, argv, NULL);
  }

  // Note: after GNOME has been initialized, do not ever unload these
  // libraries.  They register atexit handlers, so if they are unloaded, we'll
  // crash on exit.
}

Here is the call graph for this function:


The documentation for this class was generated from the following files: