Factory API

The Factory class is used to instantiate all other Gears objects. Using the create method, an application specifies the interface version it uses.

Use gears_init.js in your application for the easiest way to create a Factory object. The script defines google.gears.factory to refer to a Factory object.

Factory class

Object  create(className, [classVersion])
string  getBuildInfo()
boolean getPermission([siteName], [imageUrl], [extraMessage])
readonly attribute boolean hasPermission
readonly attribute string version

Code Example:

// gears_init.js defines google.gears.factory.
<script type="text/javascript" src="gears_init.js"></script>
<script type="text/javascript">

// Check whether Gears is installed.
if (window.google && google.gears) {
  // Instantiate Gears objects
  var db = google.gears.factory.create('beta.database');
  db.open();
}
</script>

Methods

Object create(className, [classVersion])
Summary: Creates a Gears object of the given class.
Parameters: className - Type of object to create.
classVersion - Deprecated. There is no longer any need to pass this parameter. The only allowed value is '1.0'. (To see if the machine has the minimum version of Gears you require, use factory.version instead.)
Return value: The new object.
Details: An exception is thrown if the given className is not recognized.

The supported class names are:

className Gears class created
beta.blobbuilder BlobBuilder
beta.canvas Canvas
beta.database Database
beta.desktop Desktop
beta.geolocation Geolocation
beta.httprequest HttpRequest
beta.localserver LocalServer
beta.timer Timer
beta.workerpool WorkerPool
string getBuildInfo()
Summary: Returns a description of the build of Gears installed.
Return value: The build description string.
Details: This string is purely informational. Application developers should not rely on the format of data returned. The contents and layout may change over time.
boolean getPermission([siteName], [imageUrl], [extraMessage])
Summary: Lets a site manually trigger the Gears security dialog, optionally with UI customizations.
Parameters: siteName - Optional. Friendly name of the site requesting permission.
imageUrl - Optional. URL of a .png file to display in the dialog.
extraMessage - Optional. Site-specific text to display to users in the security dialog.
Return value: Indicates whether the site has permission to use Gears.
Details: It is always safe to call this function; it will return immediately if the site already has permission to use Gears.

All arguments are optional. The dialog will only show those that are specified.

Attributes

Attribute Type Description
version readonly string Returns the version of Gears installed, as a string of the form Major.Minor.Build.Patch (e.g., '0.10.2.0').
hasPermission readonly boolean Returns true if the site already has permission to use Gears.