You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 14, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: readme.md
+75-14Lines changed: 75 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,8 @@ When the application is launched, the plugin automatically handles navigation to
37
37
38
38
> **Note:** Although the W3C specs for the Web App manifest consider absolute and relative URLs valid for the _start_url_ value (e.g. _http://www.racer2k.net/racer/start.html_ and _/start.html_ are both valid), the plugin requires this URL **to be an absolute URL**. Otherwise, the installed applications won't be able to navigate to the web site.
39
39
40
+
The plugin enables the injection of additional Cordova plugins and app-specific scripts that consume them allowing you to take advantage of native features in your hosted web apps.
41
+
40
42
Lastly, since network connectivity is essential to the operation of a hosted web application, the plugin implements a basic offline feature that will show an offline page whenever connectivity is lost and will prevent users from interacting with the application until the connection is restored.
41
43
42
44
## Installation
@@ -82,6 +84,68 @@ The plugin enables using content hosted in a web site inside a Cordova applicati
82
84
> **Note:** The plugin updates the Cordova configuration file (config.xml) with the information in the W3C manifest. If the information in the manifest changes, you can reapply the updated manifest settings at any time by executing prepare. For example:
83
85
`cordova prepare`
84
86
87
+
### Using Cordova Plugins in Hosted Web Apps
88
+
The plugin supports the injection of Cordova and the plugin interface scripts into the pages of a hosted site. There are two different plugin modes: '_server_' and '_client_'. In '_client_' mode, the **cordova.js** file and the plugin interface script files are retrieved from the app package. In '_server_' mode, these files are downloaded from the server along with the rest of the app's content. The plugin also provides a mechanism for injecting scripts that can be used, among other things, to consume the plugins added to the app. Imported scripts can be retrieved from the app package or downloaded from a remote source.
89
+
90
+
Very briefly, these are the steps that are needed to use plugins:
91
+
92
+
- Add one or more Cordova plugins to the app.
93
+
94
+
- Enable API access in any pages where Cordova and the plugins will be used. This injects the Cordova runtime environment and is configured via a custom extension in the W3C manifest. The **match** and **platform** attributes specifies the pages and platforms where you will use Cordova.
- Optionally, choose a plugin mode. The default mode is _client_.
106
+
107
+
**Client mode**
108
+
```
109
+
{
110
+
...
111
+
"mjs_cordova": {
112
+
"plugin_mode": "client"
113
+
}
114
+
}
115
+
```
116
+
117
+
**Server mode**
118
+
```
119
+
{
120
+
...
121
+
"mjs_cordova": {
122
+
"plugin_mode": "server",
123
+
"base_url": "js/cordova"
124
+
}
125
+
}
126
+
```
127
+
128
+
(In '_server_' mode, the Cordova files and plugin interface scripts must be deployed to the site to the path specified in **base_url**. Also, the **cordova.js** and **cordova_plugins.js** files for each platform need to be renamed to specify the platform in their names so that **cordova.js** and **cordova_plugins.js** become, in the case of Android for example, **cordova-android.js** and **cordova_plugins-android.js** respectively.)
129
+
130
+
To inject scripts into the hosted web content:
131
+
132
+
- Update the app's manifest to list the imported scripts in a custom **mjs_import_scripts** section.
- For app-hosted scripts, copy the script files to the Cordova project. The path in **mjs_import_scripts** must be specified relative to the '_www_' folder of the project. Server-hosted scripts must be deployed to the site.
146
+
147
+
The following [wiki article](https://github.com/manifoldjs/ManifoldJS/wiki/Using-Cordova-Plugins-in-Hosted-Web-Apps) provides additional information about these features.
148
+
85
149
### Offline Feature
86
150
The plugin implements a basic offline feature that will show an offline page whenever network connectivity is lost. By default, the page shows a suitable message alerting the user about the loss of connectivity. To customize the offline experience, a page named **offline.html** can be placed in the **www** folder of the application and it will be used instead.
87
151
@@ -130,20 +194,18 @@ For example, the following manifest references icons from the _/resources_ path
130
194
}
131
195
</pre>
132
196
133
-
### URL Access Rules
134
-
For a hosted web application, the W3C manifest defines a scope that restricts the URLs to which the application can navigate. Additionally, the manifest can include a proprietary setting named **mjs_access_whitelist** that defines an array of access rules each one consisting of a _url_ attribute that identifies the target of the rule and indicates whether URLs matching the rule should be navigated to by the application. Non-matching URLs will be launched externally.
197
+
### Navigation Scope
198
+
For a hosted web application, the W3C manifest defines a scope that restricts the URLs to which the application can navigate. Additionally, the manifest can include a proprietary setting named **mjs_extended_scope** that defines an array of scope rules each one indicating whether URLs matching the rule should be navigated to by the application. Non-matching URLs will be launched externally.
135
199
136
-
Typically, Cordova applications define access rules to implement a security policy that controls access to external domains. The access rules must not only allow access to the scope defined by the W3C manifest but also to external content used within the site, for example, to reference script files hosted by a CDN origin.
137
-
138
-
To configure the security policy, the plugin hook maps the scope and URL access rules in the W3C manifest (**manifest.json**) to suitable access elements in the Cordova configuration file (**config.xml**). For example:
200
+
Typically, Cordova applications define scope rules to implement a security policy that controls access to external domains. To configure the security policy, the plugin hook maps the scope rules in the W3C manifest (**manifest.json**) to suitable `<allow-navigation>` elements in the Cordova configuration file (**config.xml**). For example:
139
201
140
202
**Manifest.json**
141
203
<pre>
142
204
...
143
205
"start_url": "http://www.xyz.com/",
144
206
"scope": "/",
145
-
"mjs_access_whitelist": [
146
-
{ "url": "http//googleapis.com/*" },
207
+
"mjs_extended_scope": [
208
+
{ "url": "http//otherdomain.com/*" },
147
209
{ "url": "http//login.anotherdomain.com/" }
148
210
]
149
211
...
@@ -152,9 +214,9 @@ To configure the security policy, the plugin hook maps the scope and URL access
Cordova for Android and iOS platforms provide a security policy to control which network requests triggered by the page (css, js, images, XHRs, etc.) are allowed to be made; this means that they will be blocked if they are outside the scope and do not match any of the access rules defined in the manifest.
265
+
Cordova for Android and iOS platforms provide a security policy to control which network requests triggered by the page (css, js, images, XHRs, etc.) are allowed to be made; this means that they will be blocked if they don't match the `origin` attribute of any of the `<access>` elements defined in the Cordova configuration file (**config.xml**).
204
266
205
267
The Windows and Windows Phone platforms do not provide control for these kind of requests, and they will be allowed.
206
268
207
-
208
269
## Changelog
209
270
210
-
Releases are documented in [GitHub](https://github.com/manifoldjs/ManifoldCordova/releases).
271
+
Releases are documented in [GitHub](https://github.com/manifoldjs/ManifoldCordova/releases).
0 commit comments