Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit cbb235f

Browse files
author
msrodri
committed
Merge pull request #42 from manifoldjs/v0.1.4
V0.1.4
2 parents 9f8565b + 7abc3a5 commit cbb235f

File tree

5 files changed

+80
-48
lines changed

5 files changed

+80
-48
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-hostedwebapp",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Hosted Web App Plugin",
55
"cordova": {
66
"id": "cordova-plugin-hostedwebapp",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
id="cordova-plugin-hostedwebapp"
4-
version="0.1.3">
4+
version="0.1.4">
55
<name>HostedWebApp</name>
66
<description>Hosted Web App Plugin</description>
77
<license>MIT License</license>

scripts/updateConfigurationBeforePrepare.js

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,34 +79,34 @@ function downloadImage(imageUrl, imagesPath, imageSrc) {
7979
});
8080
}
8181

82-
// normalize icon list and download to res folder
83-
function getManifestIcons(manifest) {
84-
var iconList = [];
85-
if (manifest.icons && manifest.icons instanceof Array) {
86-
manifest.icons.forEach(function (icon) {
87-
var imageUrl = url.resolve(manifest.start_url, icon.src);
88-
icon.src = url.parse(imageUrl).pathname;
89-
var sizes = icon.sizes.toLowerCase().split(' ');
90-
sizes.forEach(function (iconSize) {
91-
var dimensions = iconSize.split('x');
92-
var element = {
93-
"src": icon.src,
94-
"width": dimensions[0],
95-
"height": dimensions[1],
96-
"density": icon.density,
97-
"type": icon.type
98-
};
99-
100-
iconList.push(element);
101-
});
82+
// normalize image list and download images to project folder
83+
function processImageList(images, baseUrl) {
84+
var imageList = [];
85+
if (images && images instanceof Array) {
86+
images.forEach(function (image) {
87+
var imageUrl = url.resolve(baseUrl, image.src);
88+
image.src = url.parse(imageUrl).pathname;
89+
var sizes = image.sizes.toLowerCase().split(' ');
90+
sizes.forEach(function (imageSize) {
91+
var dimensions = imageSize.split('x');
92+
var element = {
93+
"src": image.src,
94+
"width": dimensions[0],
95+
"height": dimensions[1],
96+
"density": image.density,
97+
"type": image.type
98+
};
99+
100+
imageList.push(element);
101+
});
102102

103-
var iconsPath = path.dirname(path.join(projectRoot, icon.src));
103+
var imagePath = path.dirname(path.join(projectRoot, image.src));
104104

105-
downloadImage(imageUrl, iconsPath, icon.src);
106-
});
107-
}
105+
downloadImage(imageUrl, imagePath, image.src);
106+
});
107+
}
108108

109-
return iconList;
109+
return imageList;
110110
}
111111

112112
// Configure Cordova configuration parser
@@ -230,7 +230,7 @@ function isValidFormat(icon, validFormats) {
230230
return false;
231231
}
232232

233-
function processIconsBySize(platform, manifestIcons, splashScreenSizes, iconSizes, validFormats) {
233+
function processImagesBySize(platform, manifestImages, splashScreenSizes, iconSizes, validFormats) {
234234
// get platform section and create it if it does not exist
235235
var root = config.doc.find('platform[@name=\'' + platform + '\']');
236236
if (!root) {
@@ -240,7 +240,7 @@ function processIconsBySize(platform, manifestIcons, splashScreenSizes, iconSize
240240

241241
var platformIcons = root.findall('icon');
242242
var platformScreens = root.findall('splash');
243-
manifestIcons.forEach(function (element) {
243+
manifestImages.forEach(function (element) {
244244
if (!isValidFormat(element, validFormats)) {
245245
return;
246246
}
@@ -286,7 +286,7 @@ function processIconsBySize(platform, manifestIcons, splashScreenSizes, iconSize
286286
});
287287
}
288288

289-
function processIconsByDensity(platform, manifestIcons, screenSizeToDensityMap, iconSizeToDensityMap, dppxToDensityMap, validFormats) {
289+
function processImagesByDensity(platform, manifestImages, screenSizeToDensityMap, iconSizeToDensityMap, dppxToDensityMap, validFormats) {
290290
// get platform section and create it if it does not exist
291291
var root = config.doc.find('platform[@name=\'' + platform + '\']');
292292
if (!root) {
@@ -296,7 +296,7 @@ function processIconsByDensity(platform, manifestIcons, screenSizeToDensityMap,
296296

297297
var platformIcons = root.findall('icon');
298298
var platformScreens = root.findall('splash');
299-
manifestIcons.forEach(function (element) {
299+
manifestImages.forEach(function (element) {
300300
if (!isValidFormat(element, validFormats)) {
301301
return;
302302
}
@@ -455,7 +455,7 @@ function processDefaultIconsBySize(platform, screenSizes, iconSizes) {
455455
});
456456
}
457457

458-
function processiOSIcons(manifestIcons) {
458+
function processiOSIcons(manifestIcons, manifestSplashScreens) {
459459
var iconSizes = [
460460
"40x40",
461461
"80x80",
@@ -487,11 +487,12 @@ function processiOSIcons(manifestIcons) {
487487
"1242x2208"
488488
];
489489

490-
processIconsBySize('ios', manifestIcons, splashScreenSizes, iconSizes);
490+
processImagesBySize('ios', manifestIcons, splashScreenSizes, iconSizes);
491+
processImagesBySize('ios', manifestSplashScreens, splashScreenSizes, []);
491492
processDefaultIconsBySize('ios', splashScreenSizes, iconSizes);
492493
}
493494

494-
function processAndroidIcons(manifestIcons, outputConfiguration, previousIndent) {
495+
function processAndroidIcons(manifestIcons, manifestSplashScreens) {
495496
var iconSizeToDensityMap = {
496497
36: 'ldpi',
497498
48: 'mdpi',
@@ -540,11 +541,12 @@ function processAndroidIcons(manifestIcons, outputConfiguration, previousIndent)
540541
'image/png'
541542
];
542543

543-
processIconsByDensity('android', manifestIcons, screenSizeToDensityMap, iconSizeToDensityMap, dppxToDensityMap, validFormats);
544+
processImagesByDensity('android', manifestIcons, screenSizeToDensityMap, iconSizeToDensityMap, dppxToDensityMap, validFormats);
545+
processImagesByDensity('android', manifestSplashScreens, screenSizeToDensityMap, [], dppxToDensityMap, validFormats);
544546
processDefaultIconsByDensity('android', screenDensities, iconDensities);
545547
}
546548

547-
function processWindowsIcons(manifestIcons) {
549+
function processWindowsIcons(manifestIcons, manifestSplashScreens) {
548550
var iconSizes = [
549551
"30x30",
550552
"44x44",
@@ -566,11 +568,12 @@ function processWindowsIcons(manifestIcons) {
566568
"1152x1920"
567569
];
568570

569-
processIconsBySize('windows', manifestIcons, splashScreenSizes, iconSizes);
571+
processImagesBySize('windows', manifestIcons, splashScreenSizes, iconSizes);
572+
processImagesBySize('windows', manifestSplashScreens, splashScreenSizes, []);
570573
processDefaultIconsBySize('windows', splashScreenSizes, iconSizes);
571574
};
572575

573-
function processWindowsPhoneIcons(manifestIcons) {
576+
function processWindowsPhoneIcons(manifestIcons, manifestSplashScreens) {
574577
var iconSizes = [
575578
"62x62",
576579
"173x173"
@@ -580,7 +583,8 @@ function processWindowsPhoneIcons(manifestIcons) {
580583
"480x800"
581584
];
582585

583-
processIconsBySize('wp8', manifestIcons, splashScreenSizes, iconSizes);
586+
processImagesBySize('wp8', manifestIcons, splashScreenSizes, iconSizes);
587+
processImagesBySize('wp8', manifestSplashScreens, splashScreenSizes, []);
584588
processDefaultIconsBySize('wp8', splashScreenSizes, iconSizes);
585589
};
586590

@@ -665,16 +669,19 @@ module.exports = function (context) {
665669
// configure access rules
666670
processAccessRules(manifest);
667671

668-
// Obtain and download the icons specified in the manidest
669-
var manifestIcons = getManifestIcons(manifest);
672+
// Obtain and download the icons and splash screens specified in the manifest.
673+
// Currently, splash screens specified in the splash_screens section of the manifest
674+
// take precedence over similarly sized splash screens in the icons section.
675+
var manifestIcons = processImageList(manifest.icons, manifest.start_url);
676+
var manifestSplashScreens = processImageList(manifest.splash_screens, manifest.start_url);
670677

671678
Q.allSettled(pendingTasks).then(function () {
672679

673680
// Configure the icons once all icon files are downloaded
674-
processiOSIcons(manifestIcons);
675-
processAndroidIcons(manifestIcons);
676-
processWindowsIcons(manifestIcons);
677-
processWindowsPhoneIcons(manifestIcons);
681+
processiOSIcons(manifestIcons, manifestSplashScreens);
682+
processAndroidIcons(manifestIcons, manifestSplashScreens);
683+
processWindowsIcons(manifestIcons, manifestSplashScreens);
684+
processWindowsPhoneIcons(manifestIcons, manifestSplashScreens);
678685

679686
// save the updated configuration
680687
config.write();

src/android/HostedWebApp.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.net.Uri;
55
import android.content.res.AssetManager;
66
import android.os.Build;
7+
import android.util.Log;
78
import android.view.View;
89
import android.view.ViewGroup;
910
import android.webkit.WebView;
@@ -27,6 +28,7 @@
2728
* This class manipulates the Web App W3C manifest.
2829
*/
2930
public class HostedWebApp extends CordovaPlugin {
31+
private static final String LOG_TAG = "HostedWebApp";
3032
private static final String DEFAULT_MANIFEST_FILE = "manifest.json";
3133
private static final String OFFLINE_PAGE = "offline.html";
3234
private static final String OFFLINE_PAGE_TEMPLATE = "<html><body><div style=\"top:50%%;text-align:center;position:absolute\">%s</div></body></html>";
@@ -35,6 +37,7 @@ public class HostedWebApp extends CordovaPlugin {
3537
private JSONObject manifestObject;
3638

3739
private CordovaActivity activity;
40+
private CordovaPlugin whiteListPlugin;
3841

3942
private LinearLayout rootLayout;
4043
private WebView offlineWebView;
@@ -181,13 +184,27 @@ else if (id.equals("onPageFinished")) {
181184
return null;
182185
}
183186

187+
@Override
188+
public Boolean shouldAllowRequest(String url) {
189+
CordovaPlugin whiteListPlugin = this.getWhitelistPlugin();
190+
191+
if (whiteListPlugin != null && Boolean.TRUE != whiteListPlugin.shouldAllowRequest(url)) {
192+
Log.w(LOG_TAG, String.format("Whitelist rejection: url='%s'", url));
193+
}
194+
195+
// do not alter default behavior.
196+
return super.shouldAllowRequest(url);
197+
}
198+
184199
@Override
185200
public boolean onOverrideUrlLoading(String url) {
186-
CordovaPlugin whiteListPlugin = this.webView.getPluginManager().getPlugin("Whitelist");
201+
CordovaPlugin whiteListPlugin = this.getWhitelistPlugin();
187202

188203
if (whiteListPlugin != null && Boolean.TRUE != whiteListPlugin.shouldAllowNavigation(url)) {
189204
// If the URL is not in the list URLs to allow navigation, open the URL in the external browser
190205
// (code extracted from CordovaLib/src/org/apache/cordova/CordovaWebViewImpl.java)
206+
Log.w(LOG_TAG, String.format("Whitelist rejection: url='%s'", url));
207+
191208
try {
192209
Intent intent = new Intent(Intent.ACTION_VIEW);
193210
intent.addCategory(Intent.CATEGORY_BROWSABLE);
@@ -199,7 +216,7 @@ public boolean onOverrideUrlLoading(String url) {
199216
} else {
200217
intent.setData(uri);
201218
}
202-
cordova.getActivity().startActivity(intent);
219+
this.activity.startActivity(intent);
203220
} catch (android.content.ActivityNotFoundException e) {
204221
e.printStackTrace();
205222
}
@@ -214,6 +231,14 @@ public JSONObject getManifest() {
214231
return this.manifestObject;
215232
}
216233

234+
private CordovaPlugin getWhitelistPlugin() {
235+
if (this.whiteListPlugin == null) {
236+
this.whiteListPlugin = this.webView.getPluginManager().getPlugin("Whitelist");
237+
}
238+
239+
return whiteListPlugin;
240+
}
241+
217242
private boolean assetExists(String asset) {
218243
final AssetManager assetManager = this.activity.getResources().getAssets();
219244
try {

src/windows/HostedWebAppPluginProxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function navigationStartingEvent(evt) {
5050
if (!isInWhitelist) {
5151
evt.stopImmediatePropagation();
5252
evt.preventDefault();
53-
console.log("Popping out URL: " + evt.uri);
53+
console.log("Whitelist rejection: url='" + evt.uri + "'");
5454
Windows.System.Launcher.launchUriAsync(new Windows.Foundation.Uri(evt.uri));
5555
}
5656
}

0 commit comments

Comments
 (0)