Cordova host implementation.
- Version:
- $$Id: cordovaHost.js 1365 2017-04-17 00:44:19Z chadlia.jerad $$
- Source:
Members
(inner) _accessorPath
Relative path (from www) to the accessors directory.
(inner) _includePath
Relative path (from www) to the include directory.
(inner) _loadedAccessors
Cached accessors.
(inner) _loadedModules
Cached modules.
(inner) _modulesCommonPath
Relative path (from www) to the common modules directory.
(inner) _modulesLocalPath
Relative path (from www) to the local modules directory.
(inner) _rootStr
Full path to the root (www).
Methods
(inner) getAccessorCode(path) → {string}
Return the source of an accessor definition from the accessor library on the host. The ".js" extension of the accessor class is optional. This is a blocking call.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | The path on the server for the JavaScript code, e.g. 'net/REST'. |
Returns:
The source code of the accessor.
- Type
- string
(inner) getHostName()
Return the name of this host.
Return the string "Cordova".
Returns:
In cordovaHost.js, return "Cordova".
(inner) getJavaScript(path, callback)
Return the source code of a JavaScript file. Append the string '.js' to the specified path (if it is not already there) and issue an HTTP GET request with the specified relative path. If no callback function is given, then this is a blocking request. If a callback is given, then the response will be passed as the second argument of the callback. The first argument is used to pass an error message in case the operation was unsuccessful (and will be null otherwise).
Parameters:
Name | Type | Description |
---|---|---|
path |
string | The relative path on the server. |
callback |
function | The callback function. |
(inner) getResource(uri, options, callback)
Get a resource using XMLHttpRequest for remote files and window.resolveLocalFileSystemURL for local files.
The reason for using a different function for local files is subtle, and has to do with how mobile apps are sandboxed differently than web apps. XMLHttpRequest will load local files, but is restricted by the domain name and top level domain name of the current URI, which can change from the app's www directory if the user navigates to another page of the app and interfere with file loading. Not only does window.resolveLocalFileSystemURL not have this issue it provides access to other files in the app sandbox which may not be in the app's www directory. For example both Android and iOS provide persistant and private data storage (see https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/) outside of the app's www directory.
Unlike other hosts, this implementation is exclusively asynchronous. Although getJavaScript above shows synchronous loading, this is to be avoided because a synchronous call to getResource during execution would make the swarmlet freeze. Therefore a null callback argument will generate an error.
$KEYSTORE is replaced with _root + "keystore/" This means each cordova swarmlet on a phone is assumed to have its own app-specific read-only keystore.
FIXME: complete this implementation for more resource types such as binary files (see https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html#store-an-existing-binary-file-) WARNING: the encoding parameter in options is currently ignored FIXME: print file errors with more informative messages than "[object]".
Below are the types of resources that are handled all other resources will cause an error.
- Text (UTF-8)
Parameters:
Name | Type | Description |
---|---|---|
uri |
string | A specification for the resource. If the uri starts with http or https, this function will attempt to load the resource from the web. If the uri is an absolute path on mobile (starts with file:///) it will attempt to load it locally. If the uri is a relative path, this function will attempt to load it relative to this app's www directory (located at _root). |
options |
string | FXIME: Until more than UTF-8 resources are supported, encoding inputs are ignored is ignored. The below documentation is copied from the GetResource accessor. The options parameter may have the following values:
|
callback |
A callback function which will be called with two arguments: 1) The first argument is null if the resource was successfully acquired and a non-null error code if wasn't. The error message will be an http status message https://www.w3schools.com/tags/ref_httpmessages.asp if a web resource was sought, and a cordova-plugin-file error code (see https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#list-of-error-codes-and-meanings) if a local resource was sought. 2) The second argument is the desired resource, if successfully acquired and null otherwise. |
(inner) instantiate(accessorName, accessorClass) → {object}
Instantiate and return an accessor. This will throw an exception if there is no such accessor class on the accessor search path.
Parameters:
Name | Type | Description |
---|---|---|
accessorName |
string | The name to give to the instance. |
accessorClass |
string | Fully qualified accessor class name, e.g. 'net/REST'. |
Returns:
An accessor instance.
- Type
- object
(inner) loadModule(id) → {boolean}
Return true if the module was loaded successfully, false otherwise. If the code was loaded before, do nothing, otherwise, retrieve it.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Identifier for the module. |
Returns:
Whether the module was loaded successfully.
- Type
- boolean
(inner) require(id) → {object}
This require function is similar to Node's implementation (module.js). If the given identifier specifies a full path then try to use that path. Otherwise, attempt to load a local module. If that fails, attempt to load a global module. If that also fails, use the native require function implemented by Cordova.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Identifier for the module. |
- Source:
- See:
Returns:
The modules exports.
- Type
- object