Bug 1352726 - Ensure missing fields dont halt theming. r=sebastian

This commit is contained in:
Dale Harvey 2017-04-03 14:26:03 +01:00
Родитель 38a4dbd7f6
Коммит c3024a1b20
1 изменённых файлов: 9 добавлений и 9 удалений

Просмотреть файл

@ -156,7 +156,7 @@ public class WebAppActivity extends GeckoApp {
try {
final File manifestFile = new File(manifestPath);
final JSONObject manifest = FileUtils.readJSONObjectFromFile(manifestFile);
final JSONObject manifestField = (JSONObject) manifest.get("manifest");
final JSONObject manifestField = manifest.getJSONObject("manifest");
final Integer color = readColorFromManifest(manifestField);
final String name = readNameFromManifest(manifestField);
final Bitmap icon = readIconFromManifest(manifest);
@ -180,27 +180,27 @@ public class WebAppActivity extends GeckoApp {
}
}
private Integer readColorFromManifest(JSONObject manifest) throws JSONException {
final String colorStr = (String) manifest.get("theme_color");
private Integer readColorFromManifest(JSONObject manifest) {
final String colorStr = manifest.optString("theme_color", null);
if (colorStr != null) {
return ColorUtil.parseStringColor(colorStr);
}
return null;
}
private String readNameFromManifest(JSONObject manifest) throws JSONException {
String name = (String) manifest.get("name");
private String readNameFromManifest(JSONObject manifest) {
String name = manifest.optString("name", null);
if (name == null) {
name = (String) manifest.get("short_name");
name = manifest.optString("short_name", null);
}
if (name == null) {
name = (String) manifest.get("start_url");
name = manifest.optString("start_url", null);
}
return name;
}
private Bitmap readIconFromManifest(JSONObject manifest) throws JSONException {
final String iconStr = (String) manifest.get("cached_icon");
private Bitmap readIconFromManifest(JSONObject manifest) {
final String iconStr = manifest.optString("cached_icon", null);
if (iconStr != null) {
return FaviconDecoder
.decodeDataURI(getContext(), iconStr)