Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
org.mozilla.xpcom.Mozilla Class Reference

A singleton class which provides access to the Mozilla browser. More...

Inheritance diagram for org.mozilla.xpcom.Mozilla:
Inheritance graph
[legend]
Collaboration diagram for org.mozilla.xpcom.Mozilla:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void initialize (File aLibXULDirectory) throws XPCOMInitializationException
 Initialize the Mozilla object with the given XULRunner path.
void initEmbedding (File aLibXULDirectory, File aAppDirectory, IAppFileLocProvider aAppDirProvider) throws XPCOMException
 Initializes libXUL for embedding purposes.
void termEmbedding ()
 Terminates libXUL embedding.
ProfileLock lockProfileDirectory (File aDirectory) throws XPCOMException
 Lock a profile directory using platform-specific semantics.
void notifyProfile ()
 Fire notifications to inform the toolkit about a new profile.
nsIServiceManager initXPCOM (File aMozBinDirectory, IAppFileLocProvider aAppFileLocProvider) throws XPCOMException
 Initializes XPCOM.
void shutdownXPCOM (nsIServiceManager aServMgr) throws XPCOMException
 Shutdown XPCOM.
nsIServiceManager getServiceManager () throws XPCOMException
 Public Method to access to the service manager.
nsIComponentManager getComponentManager () throws XPCOMException
 Public Method to access to the component manager.
nsIComponentRegistrar getComponentRegistrar () throws XPCOMException
 Public Method to access to the component registration manager.
nsILocalFile newLocalFile (String aPath, boolean aFollowLinks) throws XPCOMException
 Public Method to create an instance of a nsILocalFile.
long getNativeHandleFromAWT (Object widget)
 Return the native window handle for an AWT component.
long wrapJavaObject (Object aJavaObject, String aIID)
 Returns a pointer to a C++ proxy object for the given Java object.
Object wrapXPCOMObject (long aXPCOMObject, String aIID)
 Returns a Java proxy for the given C++ XPCOM object.

Static Public Member Functions

static Mozilla getInstance ()
static File getGREPathWithProperties (GREVersionRange[] aVersions, Properties aProperties) throws FileNotFoundException
 Locates the path of a GRE with the specified properties.
static nsISupports queryInterface (nsISupports aObject, String aIID)
 If you create a class that implements nsISupports, you will need to provide an implementation of the queryInterface method.
static String getInterfaceIID (Class aInterface)
 Gets the interface IID for a particular Java interface.

Private Member Functions

 Mozilla ()

Static Private Member Functions

static File getGREPathMacOSX (GREVersionRange[] aVersions)
static File findGREBundleFramework ()
static File findGREFramework (String aRootPath, GREVersionRange[] aVersions)
static File getGREPathWindows (GREVersionRange[] aVersions, Properties aProperties)
static File getGREPathFromRegKey (String aRegKey, GREVersionRange[] aVersions, Properties aProperties)
static File getGREPathFromRegistryFile (String aFileName, String aKeyName, GREVersionRange[] aVersions, Properties aProperties)
static File getGREPathUnix (GREVersionRange[] aVersions, Properties aProperties)
static File getPathFromConfigFile (String aFileName, GREVersionRange[] aVersions, Properties aProperties)
static File getPathFromConfigDir (String aDirName, GREVersionRange[] aVersions, Properties aProperties)
static boolean checkVersion (String aVersionToCheck, GREVersionRange[] aVersions)

Private Attributes

IMozilla mozilla = null
IGRE gre = null
IXPCOM xpcom = null
IJavaXPCOMUtils jxutils = null

Static Private Attributes

static Mozilla mozillaInstance = new Mozilla()
static final String JAVAXPCOM_JAR = "javaxpcom.jar"

Detailed Description

A singleton class which provides access to the Mozilla browser.

Requires that XULRunner be installed on the user's system.

You would use to class to find a XULRunner installation, setup a profile (if necessary), and initialize embedding. A typical scenario would look like this:

 Mozilla mozilla = Mozilla.getInstance();
 GREVersionRange[] range = new GREVersionRange[1];
 range[0] = new GREVersionRange("1.8.0.*", false, "1.8.1.*", true);
 try {
    File grePath = Mozilla.getGREPathWithProperties(range, null);
    mozilla.initialize(grePath);
    profLock = mozilla.lockProfileDirectory(profileDir);
    // LocationProvider is a user class that implements IAppFileLocProvider
    LocationProvider locProvider = new LocationProvider(grePath, profileDir);
    mozilla.initEmbedding(grePath, grePath, locProvider);
    mozilla.notifyProfile();
 } catch (XPCOMInitializationException xie) {
    // handle exception
 } catch (XPCOMException xe) {
    // handle exception
 }
 
See also:
http://www.mozilla.org/projects/embedding/GRE.html

Definition at line 88 of file Mozilla.java.


Constructor & Destructor Documentation

org.mozilla.xpcom.Mozilla.Mozilla ( ) [inline, private]

Definition at line 110 of file Mozilla.java.

                    {
  }

Member Function Documentation

static boolean org.mozilla.xpcom.Mozilla.checkVersion ( String  aVersionToCheck,
GREVersionRange[]  aVersions 
) [inline, static, private]
Parameters:
aVersionToCheck
aVersions
Returns:

Definition at line 609 of file Mozilla.java.

                                                                   {
    for (int i = 0; i < aVersions.length; i++) {
      if (aVersions[i].check(aVersionToCheck)) {
        return true;
      }
    }
    return false;
  }

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.findGREBundleFramework ( ) [inline, static, private]
Returns:

Definition at line 213 of file Mozilla.java.

                                               {
    /*
     * Use reflection to get Apple's NSBundle class, which can be used
     * to get the bundle's "Frameworks" directory.
     */
    try {
      URL[] urls = new URL[1];
      urls[0] = new File("/System/Library/Java/").toURL();
      ClassLoader loader = new URLClassLoader(urls);
      Class bundleClass = Class.forName("com.apple.cocoa.foundation.NSBundle",
                                        true, loader);

      // Get the bundle for this app.  If this is not executing from
      // a bundle, this will return null.
      Method mainBundleMethod = bundleClass.getMethod("mainBundle", null);
      Object bundle = mainBundleMethod.invoke(null, null);

      if (bundle != null) {
        // Get the path to the bundle's "Frameworks" directory
        Method fwPathMethod = bundleClass.getMethod("privateFrameworksPath",
                                                    null);
        String path = (String) fwPathMethod.invoke(bundle, null);

        // look for libxpcom.dylib
        if (path.length() != 0) {
          File xulDir = new File(path, "XUL.framework");
          if (xulDir.isDirectory()) {
            File xpcomLib = new File(xulDir, "libxpcom.dylib");
            if (xpcomLib.canRead()) {
              File grePath = xpcomLib.getCanonicalFile().getParentFile();

              // Since GRE Properties aren't supported on Mac OS X, we check
              // for the existence of the "javaxpcom.jar" file in the GRE.
              File jar = new File(grePath, JAVAXPCOM_JAR);
              if (jar.canRead()) {
                // found GRE
                return grePath;
              }
            }
          }
        }
      }
    } catch (Exception e) { }

    return null;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.findGREFramework ( String  aRootPath,
GREVersionRange[]  aVersions 
) [inline, static, private]
Parameters:
aRootPath
aVersions
Returns:

Definition at line 265 of file Mozilla.java.

                                                                    {
    File frameworkDir = new File(aRootPath +
                                 "/Library/Frameworks/XUL.framework/Versions");
    if (!frameworkDir.exists())
      return null;

    File[] files = frameworkDir.listFiles();
    for (int i = 0; i < files.length; i++) {
      if (checkVersion(files[i].getName(), aVersions)) {
        File xpcomLib = new File(files[i], "libxpcom.dylib");

        // Since GRE Properties aren't supported on Mac OS X, we check
        // for the existence of the "javaxpcom.jar" file in the GRE.
        File jar = new File(files[i], JAVAXPCOM_JAR);
        if (xpcomLib.canRead() && jar.canRead()) {
          return files[i];
        }
      }
    }

    return null;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsIComponentManager org.mozilla.xpcom.Mozilla.getComponentManager ( ) throws XPCOMException [inline]

Public Method to access to the component manager.

Returns:
the component manager
Exceptions:
XPCOMExceptionif a failure occurred
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IXPCOM.

Definition at line 883 of file Mozilla.java.

                                                                         {
    try {
      return xpcom.getComponentManager();
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

nsIComponentRegistrar org.mozilla.xpcom.Mozilla.getComponentRegistrar ( ) throws XPCOMException [inline]

Public Method to access to the component registration manager.

Returns:
the component registration manager
Exceptions:
XPCOMExceptionif a failure occurred
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IXPCOM.

Definition at line 901 of file Mozilla.java.

                                                                             {
    try {
      return xpcom.getComponentRegistrar();
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

static File org.mozilla.xpcom.Mozilla.getGREPathFromRegistryFile ( String  aFileName,
String  aKeyName,
GREVersionRange[]  aVersions,
Properties  aProperties 
) [inline, static, private]
Parameters:
aFileName
aCharset
aKeyName
aVersions
aProperties
Returns:

Definition at line 366 of file Mozilla.java.

                                  {
    INIParser parser;
    try {
      parser = new INIParser(aFileName, Charset.forName("UTF-16"));
    } catch (Exception e) {
      // Problem reading from file.  Bail out.
      return null;
    }

    Iterator sectionsIter = parser.getSections();
    while (sectionsIter.hasNext()) {
      // get 'section' name, which will be a registry key name
      String section = (String) sectionsIter.next();

      // Skip over GRE key ("<root>\Software\mozilla.org\GRE")
      int gre_len = aKeyName.length();
      if (section.length() <= gre_len) {
        continue;
      }

      // Get the GRE subkey;  that is, everything after
      // "<root>\Software\mozilla.org\GRE\"
      String subkeyName = section.substring(gre_len + 1);

      // We are only interested in _immediate_ subkeys.  We want
      // "<root>\Software\mozilla.org\GRE<version>" but not
      // "<root>\Software\mozilla.org\GRE<version><moretext>".
      if (subkeyName.indexOf('\\') != -1) {
        continue;
      }

      // See if this registry key has a "Version" value, and if so, compare
      // it to our desired versions.
      String version = parser.getString(section, "\"Version\"");
      if (version == null) {
        continue;
      }
      // remove quotes around string
      version = version.substring(1, version.length() - 1);
      if (!checkVersion(version, aVersions)) {
        continue;
      }

      // All properties must match, keeping in mind that the propery/value
      // pairs returned by regedit.exe have quotes around them.
      if (aProperties != null) {
        boolean ok = true;
        Enumeration e = aProperties.propertyNames();
        while (ok && e.hasMoreElements()) {
          String prop = (String) e.nextElement();
          String greValue = parser.getString(section, "\"" + prop + "\"");
          if (greValue == null) {
            // No such property is set for this GRE. Go on to next GRE.
            ok = false;
          } else  {
            // See if the value of the property for the GRE matches
            // the given value.
            String value = aProperties.getProperty(prop);
            if (!greValue.equals("\"" + value + "\"")) {
              ok = false;
            }
          }
        }
        if (!ok) {
          continue;
        }
      }

      String pathStr = parser.getString(section, "\"GreHome\"");
      if (pathStr != null) {
        // remove quotes around string
        pathStr = pathStr.substring(1, pathStr.length() - 1);
        File grePath = new File(pathStr);
        if (grePath.exists()) {
          File xpcomLib = new File(grePath, "xpcom.dll");
          if (xpcomLib.canRead()) {
            // found a good GRE
            return grePath;
          }
        }
      }
    }

    return null;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.getGREPathFromRegKey ( String  aRegKey,
GREVersionRange[]  aVersions,
Properties  aProperties 
) [inline, static, private]
Parameters:
aRegKey
aVersions
aProperties
Returns:

Definition at line 325 of file Mozilla.java.

                                                               {
    // create a temp file for the registry export
    File tempFile;
    try {
      tempFile = File.createTempFile("jx_registry", null);
    } catch (IOException e) {
      // failed to create temp file.  ABORT
      return null;
    }

    Process proc;
    try {
      proc = Runtime.getRuntime().exec("regedit /e " + "\"" + tempFile.getPath()
              + "\" \"" + aRegKey + "\"");
      proc.waitFor();
    } catch (Exception e) {
      // Failed to run regedit.exe.  Length of temp file is zero, and that's
      // handled next.
    }

    // If there is a key by that name in the registry, then the file length
    // will not be zero.
    File grePath = null;
    if (tempFile.length() != 0) {
      grePath = getGREPathFromRegistryFile(tempFile.getPath(),
              aRegKey, aVersions, aProperties);
    }

    tempFile.delete();
    return grePath;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.getGREPathMacOSX ( GREVersionRange[]  aVersions) [inline, static, private]
Parameters:
aVersions
Returns:

Definition at line 187 of file Mozilla.java.

                                                                    {
    /*
     * Check the application bundle first, for
     * <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib.
     */
    File grePath = findGREBundleFramework();
    if (grePath != null) {
      return grePath;
    }

    // Check ~/Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
    String home = System.getProperty("user.home");
    if (home != null) {
      grePath = findGREFramework(home, aVersions);
      if (grePath != null) {
        return grePath;
      }
    }

    // Check /Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
    return findGREFramework("", aVersions);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.getGREPathUnix ( GREVersionRange[]  aVersions,
Properties  aProperties 
) [inline, static, private]
Parameters:
aVersions
aProperties
Returns:

Definition at line 459 of file Mozilla.java.

                                                             {
    File grePath = null;

    String env = System.getProperty("MOZ_GRE_CONF");
    if (env != null) {
      grePath = getPathFromConfigFile(env, aVersions, aProperties);
      if (grePath != null) {
        return grePath;
      }
    }

    final String greUserConfFile = ".gre.config";
    final String greUserConfDir = ".gre.d";
    final String greConfPath = "/etc/gre.conf";
    final String greConfDir = "/etc/gre.d";

    env = System.getProperty("user.home");
    if (env != null) {
      // Look in ~/.gre.config
      grePath = getPathFromConfigFile(env + File.separator + greUserConfFile,
                                      aVersions, aProperties);
      if (grePath != null) {
        return grePath;
      }

      // Look in ~/.gre.d/*.conf
      grePath = getPathFromConfigDir(env + File.separator + greUserConfDir,
                                     aVersions, aProperties);
      if (grePath != null) {
        return grePath;
      }
    }

    // Look for a global /etc/gre.conf file
    grePath = getPathFromConfigFile(greConfPath, aVersions, aProperties);
    if (grePath != null) {
      return grePath;
    }

    // Look for a group of config files in /etc/gre.d/
    grePath = getPathFromConfigDir(greConfDir, aVersions, aProperties);
    return grePath;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.getGREPathWindows ( GREVersionRange[]  aVersions,
Properties  aProperties 
) [inline, static, private]
Parameters:
aVersions
aProperties
Returns:

Definition at line 294 of file Mozilla.java.

                                                                {
    /*
     * Note the usage of the "Software\\mozilla.org\\GRE" subkey - this allows
     * us to have multiple versions of GREs on the same machine by having
     * subkeys such as 1.0, 1.1, 2.0 etc. under it.
     *
     * Please see http://www.mozilla.org/projects/embedding/GRE.html for
     * more info.
     */

    final String greKey = "Software\\mozilla.org\\GRE";

    // See if there is a GRE registered for the current user.
    // If not, look for one on the system.
    String key = "HKEY_CURRENT_USER" + "\\" + greKey;
    File grePath = getGREPathFromRegKey(key, aVersions, aProperties);
    if (grePath == null) {
      key = "HKEY_LOCAL_MACHINE" + "\\" + greKey;
      grePath = getGREPathFromRegKey(key, aVersions, aProperties);
    }

    return grePath;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.getGREPathWithProperties ( GREVersionRange[]  aVersions,
Properties  aProperties 
) throws FileNotFoundException [inline, static]

Locates the path of a GRE with the specified properties.

This method will only return GREs that support Java embedding (looks for the presence of "javaxpcom.jar").

Currently this uses a "first-fit" algorithm, it does not select the newest available GRE.

Parameters:
aVersionsAn array of version ranges: if any version range matches, the GRE is considered acceptable.
aPropertiesA list of GRE property/value pairs which must all be satisfied. This parameter is ignored on Macintosh, because of the manner in which the XUL frameworks are installed.
Returns:
A file object of the appropriate path. If the "local" GRE is specified (via the USE_LOCAL_GRE environment variable, for example), returns null.
Exceptions:
FileNotFoundExceptionif an appropriate GRE could not be found

Definition at line 135 of file Mozilla.java.

                                                               {
    File grePath = null;

    // if GRE_HOME is in the environment, use that GRE
    String env = System.getProperty("GRE_HOME");
    if (env != null) {
      try {
        grePath = new File(env).getCanonicalFile();
      } catch (IOException e) {
        throw new FileNotFoundException("cannot access GRE_HOME");
      }
      if (!grePath.exists()) {
        throw new FileNotFoundException("GRE_HOME doesn't exist");
      }
      return grePath;
    }

    // the Gecko bits that sit next to the application or in the PATH
    env = System.getProperty("USE_LOCAL_GRE");
    if (env != null) {
      return null;
    }

    // Search for GRE in platform specific locations.  We want a GRE that
    // supports Java, so we look for the "javaxpcom" property by default.
    if (aProperties == null) {
      aProperties = new Properties();
    }
    aProperties.setProperty("javaxpcom", "1");

    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.startsWith("mac os x")) {
      grePath = getGREPathMacOSX(aVersions);
    } else if (osName.startsWith("windows")) {
      grePath = getGREPathWindows(aVersions, aProperties);
    } else {
      // assume everything else is Unix/Linux
      grePath = getGREPathUnix(aVersions, aProperties);
    }

    if (grePath == null) {
      throw new FileNotFoundException("GRE not found");
    }

    return grePath;
  }

Here is the call graph for this function:

static Mozilla org.mozilla.xpcom.Mozilla.getInstance ( ) [inline, static]
Returns:

Definition at line 103 of file Mozilla.java.

                                      {
    return mozillaInstance;
  }
static String org.mozilla.xpcom.Mozilla.getInterfaceIID ( Class  aInterface) [inline, static]

Gets the interface IID for a particular Java interface.

This is similar to NS_GET_IID in the C++ Mozilla files.

Parameters:
aInterfaceinterface which has defined an IID
Returns:
IID for given interface

Definition at line 1005 of file Mozilla.java.

                                                         {
    // Get short class name (i.e. "bar", not "org.blah.foo.bar")
    StringBuffer iidName = new StringBuffer();
    String fullClassName = aInterface.getName();
    int index = fullClassName.lastIndexOf(".");
    String className = index > 0 ? fullClassName.substring(index + 1)
                                 : fullClassName;

    // Create iid field name
    if (className.startsWith("ns")) {
      iidName.append("NS_");
      iidName.append(className.substring(2).toUpperCase());
    } else {
      iidName.append(className.toUpperCase());
    }
    iidName.append("_IID");

    String iid;
    try {
      Field iidField = aInterface.getDeclaredField(iidName.toString());
      iid = (String) iidField.get(null);
    } catch (NoSuchFieldException e) {
      // Class may implement non-Mozilla interfaces, which would not have an
      // IID method.  In that case, just null.
      iid = null;
    } catch (IllegalAccessException e) {
      // Not allowed to access that field for some reason.  Write out an
      // error message, but don't fail.
      System.err.println("ERROR: Could not get field " + iidName.toString());
      iid = null;
    }

    return iid;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Return the native window handle for an AWT component.

Parameters:
widgetAn AWT component (such as Canvas, Frame) that is backed by a real native window.
Returns:
the pointer to the native window (platform specific)

Implements org.mozilla.xpcom.IMozilla.

Definition at line 1040 of file Mozilla.java.

                                                    {
    try {
      return mozilla.getNativeHandleFromAWT(widget);
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

static File org.mozilla.xpcom.Mozilla.getPathFromConfigDir ( String  aDirName,
GREVersionRange[]  aVersions,
Properties  aProperties 
) [inline, static, private]
Parameters:
aDirName
aVersions
aProperties
Returns:

Definition at line 576 of file Mozilla.java.

                                                               {
    /*
     * Open the directory provided and try to read any files in that
     * directory that end with .conf.  We look for an entry that might
     * point to the GRE that we're interested in.
     */

    File dir = new File(aDirName);
    if (!dir.isDirectory()) {
      return null;
    }

    File grePath = null;
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length && grePath == null; i++) {
      // only look for files that end in '.conf'
      if (!files[i].getName().endsWith(".conf")) {
        continue;
      }

      grePath = getPathFromConfigFile(files[i].getPath(), aVersions,
                                      aProperties);
    }

    return grePath;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static File org.mozilla.xpcom.Mozilla.getPathFromConfigFile ( String  aFileName,
GREVersionRange[]  aVersions,
Properties  aProperties 
) [inline, static, private]
Parameters:
aFileName
aVersions
aProperties
Returns:

Definition at line 510 of file Mozilla.java.

                                                               {
    INIParser parser;
    try {
      parser = new INIParser(aFileName);
    } catch (Exception e) {
      // Problem reading from file.  Bail out.
      return null;
    }

    Iterator sectionsIter = parser.getSections();
    while (sectionsIter.hasNext()) {
      // get 'section' name, which will be a version string
      String section = (String) sectionsIter.next();

      // if this isn't one of the versions we are looking for, move
      // on to next section
      if (!checkVersion(section, aVersions)) {
        continue;
      }

      // all properties must match
      if (aProperties != null) {
        boolean ok = true;
        Enumeration e = aProperties.propertyNames();
        while (ok && e.hasMoreElements()) {
          String prop = (String) e.nextElement();
          String greValue = parser.getString(section, prop);
          if (greValue == null) {
            // No such property is set for this GRE. Go on to next GRE.
            ok = false;
          } else  {
            // See if the value of the property for the GRE matches
            // the given value.
            if (!greValue.equals(aProperties.getProperty(prop))) {
              ok = false;
            }
          }
        }
        if (!ok) {
          continue;
        }
      }

      String pathStr = parser.getString(section, "GRE_PATH");
      if (pathStr != null) {
        File grePath = new File(pathStr);
        if (grePath.exists()) {
          File xpcomLib = new File(grePath, "libxpcom.so");
          if (xpcomLib.canRead()) {
            // found a good GRE
            return grePath;
          }
        }
      }
    }

    return null;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsIServiceManager org.mozilla.xpcom.Mozilla.getServiceManager ( ) throws XPCOMException [inline]

Public Method to access to the service manager.

Returns:
the service manager
Exceptions:
XPCOMExceptionif a failure occurred
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IXPCOM.

Definition at line 865 of file Mozilla.java.

                                                                     {
    try {
      return xpcom.getServiceManager();
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

void org.mozilla.xpcom.Mozilla.initEmbedding ( File  aLibXULDirectory,
File  aAppDirectory,
IAppFileLocProvider  aAppDirProvider 
) throws XPCOMException [inline]

Initializes libXUL for embedding purposes.

NOTE: This function must be called from the "main" thread.

NOTE: At the present time, this function may only be called once in a given process. Use termEmbedding to clean up and free resources allocated by initEmbedding.

Parameters:
aLibXULDirectoryThe directory in which the libXUL shared library was found.
aAppDirectoryThe directory in which the application components and resources can be found. This will map to the "resource:app" directory service key.
aAppDirProviderA directory provider for the application. This provider will be aggregated by a libXUL provider which will provide the base required GRE keys.
Exceptions:
XPCOMExceptionif a failure occurred during initialization
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IGRE.

Definition at line 693 of file Mozilla.java.

                                                                     {
    try {
      gre.initEmbedding(aLibXULDirectory, aAppDirectory, aAppDirProvider);
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

void org.mozilla.xpcom.Mozilla.initialize ( File  aLibXULDirectory) throws XPCOMInitializationException [inline]

Initialize the Mozilla object with the given XULRunner path.

All subsequent Mozilla method invocations be done against the given XULRunner version.

Parameters:
aLibXULDirectorypath of XULRunner build to use
Exceptions:
XPCOMInitializationExceptionif failure occurred during initialization

Implements org.mozilla.xpcom.IMozilla.

Definition at line 629 of file Mozilla.java.

                                      {
    File jar = new File(aLibXULDirectory, JAVAXPCOM_JAR);
    if (!jar.exists()) {
      throw new XPCOMInitializationException("Could not find " + JAVAXPCOM_JAR +
          " in " + aLibXULDirectory);
    }

    URL[] urls = new URL[1];
    try {
      urls[0] = jar.toURL();
    } catch (MalformedURLException e) {
      throw new XPCOMInitializationException(e);
    }
    ClassLoader loader = new URLClassLoader(urls,
            this.getClass().getClassLoader());

    try {
      Class mozillaClass = Class.forName("org.mozilla.xpcom.internal.MozillaImpl",
          true, loader);
      mozilla  = (IMozilla) mozillaClass.newInstance();

      Class greClass = Class.forName("org.mozilla.xpcom.internal.GREImpl",
          true, loader);
      gre = (IGRE) greClass.newInstance();

      Class xpcomClass = Class.forName("org.mozilla.xpcom.internal.XPCOMImpl",
                                       true, loader);
      xpcom = (IXPCOM) xpcomClass.newInstance();

      Class javaXPCOMClass =
         Class.forName("org.mozilla.xpcom.internal.JavaXPCOMMethods",
                       true, loader);
      jxutils  = (IJavaXPCOMUtils) javaXPCOMClass.newInstance();
    } catch (Exception e) {
      throw new XPCOMInitializationException("Could not load " +
          "org.mozilla.xpcom.internal.* classes", e);
    }
    
    mozilla.initialize(aLibXULDirectory);
  }

Here is the call graph for this function:

nsIServiceManager org.mozilla.xpcom.Mozilla.initXPCOM ( File  aMozBinDirectory,
IAppFileLocProvider  aAppFileLocProvider 
) throws XPCOMException [inline]

Initializes XPCOM.

You must call this method before proceeding to use XPCOM.

Parameters:
aMozBinDirectoryThe directory containing the component registry and runtime libraries; or use null to use the working directory.
aAppFileLocProviderThe object to be used by Gecko that specifies to Gecko where to find profiles, the component registry preferences and so on; or use null for the default behaviour.
Returns:
the service manager
Exceptions:
XPCOMException
  • NS_ERROR_NOT_INITIALIZED - if static globals were not initialied, which can happen if XPCOM is reloaded, but did not completly shutdown.
  • Other error codes indicate a failure during initialisation.
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IXPCOM.

Definition at line 822 of file Mozilla.java.

                                                                         {
    try {
      return xpcom.initXPCOM(aMozBinDirectory, aAppFileLocProvider);
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

Lock a profile directory using platform-specific semantics.

Parameters:
aDirectoryThe profile directory to lock.
Returns:
A lock object. The directory will remain locked until the lock is released by invoking the release method, or by the termination of the JVM, whichever comes first.
Exceptions:
XPCOMExceptionif profile is already locked (with errorcode == NS_ERROR_FILE_ACCESS_DENIED); or if a failure occurred
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IGRE.

Definition at line 740 of file Mozilla.java.

                        {
         try {
     return gre.lockProfileDirectory(aDirectory);
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);      
    }
  }

Here is the call graph for this function:

nsILocalFile org.mozilla.xpcom.Mozilla.newLocalFile ( String  aPath,
boolean  aFollowLinks 
) throws XPCOMException [inline]

Public Method to create an instance of a nsILocalFile.

Parameters:
aPathA string which specifies a full file path to a location. Relative paths will be treated as an error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
aFollowLinksThis attribute will determine if the nsLocalFile will auto resolve symbolic links. By default, this value will be false on all non unix systems. On unix, this attribute is effectively a noop.
Returns:
an instance of an nsILocalFile that points to given path
Exceptions:
XPCOMException
  • NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths or relative paths (must supply full file path)
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IXPCOM.

Definition at line 930 of file Mozilla.java.

                                {
    try {
      return xpcom.newLocalFile(aPath, aFollowLinks);
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

Fire notifications to inform the toolkit about a new profile.

This method should be called after initEmbedding if the embedder wishes to run with a profile.

Normally the embedder should call lockProfileDirectory to lock the directory before calling this method.

NOTE: There are two possibilities for selecting a profile:

  • Select the profile before calling initEmbedding. The aAppDirProvider object passed to initEmbedding should provide the NS_APP_USER_PROFILE_50_DIR key, and may also provide the following keys:
    • NS_APP_USER_PROFILE_LOCAL_50_DIR
    • NS_APP_PROFILE_DIR_STARTUP
    • NS_APP_PROFILE_LOCAL_DIR_STARTUP
    In this scenario notifyProfile should be called immediately after initEmbedding. Component registration information will be stored in the profile and JS components may be stored in the fastload cache.
  • Select a profile some time after calling initEmbedding. In this case the embedder must install a directory service provider which provides NS_APP_USER_PROFILE_50_DIR and optionally NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information will be stored in the application directory and JS components will not fastload.
Exceptions:
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IGRE.

Definition at line 788 of file Mozilla.java.

                              {
    try {
      gre.notifyProfile();
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    }
  }

Here is the call graph for this function:

static nsISupports org.mozilla.xpcom.Mozilla.queryInterface ( nsISupports  aObject,
String  aIID 
) [inline, static]

If you create a class that implements nsISupports, you will need to provide an implementation of the queryInterface method.

This helper function provides a simple implementation. Therefore, if your class does not need to do anything special with queryInterface, your implementation would look like:

      public nsISupports queryInterface(String aIID) {
        return XPCOM.queryInterface(this, aIID);
      }
 
Parameters:
aObjectobject to query
aIIDrequested interface IID
Returns:
aObject if the given object supports that interface; null otherwise.

Definition at line 959 of file Mozilla.java.

                                                                             {
    ArrayList classes = new ArrayList();
    classes.add(aObject.getClass());

    while (!classes.isEmpty()) {
      Class clazz = (Class) classes.remove(0);

      // Skip over any class/interface in the "java.*" and "javax.*" domains.
      String className = clazz.getName();
      if (className.startsWith("java.") || className.startsWith("javax.")) {
        continue;
      }

      // If given IID matches that of the current interface, then we
      // know that aObject implements the interface specified by the given IID.
      if (clazz.isInterface() && className.startsWith("org.mozilla")) {
        String iid = Mozilla.getInterfaceIID(clazz);
        if (iid != null && aIID.equals(iid)) {
          return aObject;
        }
      }

      // clazz didn't match, so add the interfaces it implements
      Class[] interfaces = clazz.getInterfaces();
      for (int i = 0; i < interfaces.length; i++ ) {
        classes.add(interfaces[i]);
      }

      // Also add its superclass
      Class superclass = clazz.getSuperclass();
      if (superclass != null) {
        classes.add(superclass);
      }
    }

    return null;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void org.mozilla.xpcom.Mozilla.shutdownXPCOM ( nsIServiceManager  aServMgr) throws XPCOMException [inline]

Shutdown XPCOM.

You must call this method after you are finished using xpcom.

Parameters:
aServMgrThe service manager which was returned by initXPCOM. This will release servMgr.
Exceptions:
XPCOMExceptionif a failure occurred during termination
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IXPCOM.

Definition at line 843 of file Mozilla.java.

                                                                              {
    try {
      xpcom.shutdownXPCOM(aServMgr);
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    } finally {
      mozilla = null;
      gre = null;
      xpcom = null;
    }
  }

Here is the call graph for this function:

Terminates libXUL embedding.

NOTE: Release any references to XPCOM objects that you may be holding before calling this function.

Exceptions:
XPCOMInitializationExceptionif Mozilla was not properly initialized

Implements org.mozilla.xpcom.IGRE.

Definition at line 712 of file Mozilla.java.

                              {
    try {
      gre.termEmbedding();
    } catch (NullPointerException e) {
      throw new XPCOMInitializationException("Must call " +
          "Mozilla.getInstance().initialize() before using this method", e);
    } finally {
      mozilla = null;
      gre = null;
      xpcom = null;
    }
  }

Here is the call graph for this function:

long org.mozilla.xpcom.Mozilla.wrapJavaObject ( Object  aJavaObject,
String  aIID 
) [inline]

Returns a pointer to a C++ proxy object for the given Java object.

Parameters:
aJavaObjectJava object to encapsulate in C++ proxy
aIIDinterface ID for requested proxy
Returns:
C pointer (as long) of new proxy

Implements org.mozilla.xpcom.IJavaXPCOMUtils.

Definition at line 1049 of file Mozilla.java.

                                                                   {
              try {
                     return jxutils.wrapJavaObject(aJavaObject, aIID);
              } catch (NullPointerException e) {
                     throw new XPCOMInitializationException("Must call " +
                            "Mozilla.getInstance().initialize() before using this method", e);
              }
       }

Here is the call graph for this function:

Object org.mozilla.xpcom.Mozilla.wrapXPCOMObject ( long  aXPCOMObject,
String  aIID 
) [inline]

Returns a Java proxy for the given C++ XPCOM object.

Parameters:
aXPCOMObjectC++ XPCOM object to encapsulate in Java proxy
aIIDinterface ID for requested proxy
Returns:
new Proxy

Implements org.mozilla.xpcom.IJavaXPCOMUtils.

Definition at line 1058 of file Mozilla.java.

                                                                     {
              try {
                     return jxutils.wrapXPCOMObject(aXPCOMObject, aIID);
              } catch (NullPointerException e) {
                     throw new XPCOMInitializationException("Must call " +
                            "Mozilla.getInstance().initialize() before using this method", e);
              }
       }

Here is the call graph for this function:


Member Data Documentation

Definition at line 96 of file Mozilla.java.

final String org.mozilla.xpcom.Mozilla.JAVAXPCOM_JAR = "javaxpcom.jar" [static, private]

Definition at line 93 of file Mozilla.java.

Definition at line 98 of file Mozilla.java.

Definition at line 95 of file Mozilla.java.

Definition at line 91 of file Mozilla.java.

Definition at line 97 of file Mozilla.java.


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