TagSpaces is an offline, open source, document manager with tagging support
install whitelist plugin
Stanimir Marinov71104812adff
diff --git a/cordova/config.xml b/cordova/config.xmlindex eb6452369..1750651db 100644--- a/cordova/config.xml+++ b/cordova/config.xml@@ -24,11 +24,11 @@</platform><allow-navigation href="http://*/*" /><allow-navigation href="https://*/*" />- <plugin name="cordova-plugin-whitelist" spec="^1.3.3" /><plugin name="cordova-plugin-file" spec="^6.0.1" /><preference name="AndroidPersistentFileLocation" value="Compatibility" /><preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" /><preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" /><plugin name="cordova-plugin-device" spec="^2.0.2" />+ <plugin name="cordova-plugin-whitelist" spec="^1.3.3" /><engine name="android" spec="^7.1.4" /></widget>diff --git a/cordova/platforms/android/android.json b/cordova/platforms/android/android.jsonindex c59950b95..1c729d224 100644--- a/cordova/platforms/android/android.json+++ b/cordova/platforms/android/android.json@@ -19,6 +19,10 @@{"xml": "<feature name=\"Device\"><param name=\"android-package\" value=\"org.apache.cordova.device.Device\" /></feature>","count": 1+ },+ {+ "xml": "<feature name=\"Whitelist\"><param name=\"android-package\" value=\"org.apache.cordova.whitelist.WhitelistPlugin\" /><param name=\"onload\" value=\"true\" /></feature>",+ "count": 1}]}@@ -41,6 +45,9 @@},"cordova-plugin-device": {"PACKAGE_NAME": "org.tagspaces.mobile"+ },+ "cordova-plugin-whitelist": {+ "PACKAGE_NAME": "org.tagspaces.mobile"}},"dependent_plugins": {},@@ -229,6 +236,7 @@],"plugin_metadata": {"cordova-plugin-file": "6.0.1",- "cordova-plugin-device": "2.0.2"+ "cordova-plugin-device": "2.0.2",+ "cordova-plugin-whitelist": "1.3.3"}}\ No newline at end of filediff --git a/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.js b/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.jsindex 6b6a4b338..387eea4c7 100644--- a/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.js+++ b/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.js@@ -186,7 +186,8 @@ module.exports.metadata =// TOP OF METADATA{"cordova-plugin-file": "6.0.1",- "cordova-plugin-device": "2.0.2"+ "cordova-plugin-device": "2.0.2",+ "cordova-plugin-whitelist": "1.3.3"};// BOTTOM OF METADATA});\ No newline at end of filediff --git a/cordova/platforms/android/app/src/main/java/org/apache/cordova/whitelist/WhitelistPlugin.java b/cordova/platforms/android/app/src/main/java/org/apache/cordova/whitelist/WhitelistPlugin.javanew file mode 100644index 000000000..365678864--- /dev/null+++ b/cordova/platforms/android/app/src/main/java/org/apache/cordova/whitelist/WhitelistPlugin.java@@ -0,0 +1,161 @@+/*+ Licensed to the Apache Software Foundation (ASF) under one+ or more contributor license agreements. See the NOTICE file+ distributed with this work for additional information+ regarding copyright ownership. The ASF licenses this file+ to you under the Apache License, Version 2.0 (the+ "License"); you may not use this file except in compliance+ with the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing,+ software distributed under the License is distributed on an+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ KIND, either express or implied. See the License for the+ specific language governing permissions and limitations+ under the License.+*/++package org.apache.cordova.whitelist;++import org.apache.cordova.CordovaPlugin;+import org.apache.cordova.ConfigXmlParser;+import org.apache.cordova.LOG;+import org.apache.cordova.Whitelist;+import org.xmlpull.v1.XmlPullParser;++import android.content.Context;++public class WhitelistPlugin extends CordovaPlugin {+ private static final String LOG_TAG = "WhitelistPlugin";+ private Whitelist allowedNavigations;+ private Whitelist allowedIntents;+ private Whitelist allowedRequests;++ // Used when instantiated via reflection by PluginManager+ public WhitelistPlugin() {+ }+ // These can be used by embedders to allow Java-configuration of whitelists.+ public WhitelistPlugin(Context context) {+ this(new Whitelist(), new Whitelist(), null);+ new CustomConfigXmlParser().parse(context);+ }+ public WhitelistPlugin(XmlPullParser xmlParser) {+ this(new Whitelist(), new Whitelist(), null);+ new CustomConfigXmlParser().parse(xmlParser);+ }+ public WhitelistPlugin(Whitelist allowedNavigations, Whitelist allowedIntents, Whitelist allowedRequests) {+ if (allowedRequests == null) {+ allowedRequests = new Whitelist();+ allowedRequests.addWhiteListEntry("file:///*", false);+ allowedRequests.addWhiteListEntry("data:*", false);+ }+ this.allowedNavigations = allowedNavigations;+ this.allowedIntents = allowedIntents;+ this.allowedRequests = allowedRequests;+ }+ @Override+ public void pluginInitialize() {+ if (allowedNavigations == null) {+ allowedNavigations = new Whitelist();+ allowedIntents = new Whitelist();+ allowedRequests = new Whitelist();+ new CustomConfigXmlParser().parse(webView.getContext());+ }+ }++ private class CustomConfigXmlParser extends ConfigXmlParser {+ @Override+ public void handleStartTag(XmlPullParser xml) {+ String strNode = xml.getName();+ if (strNode.equals("content")) {+ String startPage = xml.getAttributeValue(null, "src");+ allowedNavigations.addWhiteListEntry(startPage, false);+ } else if (strNode.equals("allow-navigation")) {+ String origin = xml.getAttributeValue(null, "href");+ if ("*".equals(origin)) {+ allowedNavigations.addWhiteListEntry("http://*/*", false);+ allowedNavigations.addWhiteListEntry("https://*/*", false);+ allowedNavigations.addWhiteListEntry("data:*", false);+ } else {+ allowedNavigations.addWhiteListEntry(origin, false);+ }+ } else if (strNode.equals("allow-intent")) {+ String origin = xml.getAttributeValue(null, "href");+ allowedIntents.addWhiteListEntry(origin, false);+ } else if (strNode.equals("access")) {+ String origin = xml.getAttributeValue(null, "origin");+ String subdomains = xml.getAttributeValue(null, "subdomains");+ boolean external = (xml.getAttributeValue(null, "launch-external") != null);+ if (origin != null) {+ if (external) {+ LOG.w(LOG_TAG, "Found <access launch-external> within config.xml. Please use <allow-intent> instead.");+ allowedIntents.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));+ } else {+ if ("*".equals(origin)) {+ allowedRequests.addWhiteListEntry("http://*/*", false);+ allowedRequests.addWhiteListEntry("https://*/*", false);+ } else {+ allowedRequests.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));+ }+ }+ }+ }+ }+ @Override+ public void handleEndTag(XmlPullParser xml) {+ }+ }++ @Override+ public Boolean shouldAllowNavigation(String url) {+ if (allowedNavigations.isUrlWhiteListed(url)) {+ return true;+ }+ return null; // Default policy+ }++ @Override+ public Boolean shouldAllowRequest(String url) {+ if (Boolean.TRUE == shouldAllowNavigation(url)) {+ return true;+ }+ if (allowedRequests.isUrlWhiteListed(url)) {+ return true;+ }+ return null; // Default policy+ }++ @Override+ public Boolean shouldOpenExternalUrl(String url) {+ if (allowedIntents.isUrlWhiteListed(url)) {+ return true;+ }+ return null; // Default policy+ }++ public Whitelist getAllowedNavigations() {+ return allowedNavigations;+ }++ public void setAllowedNavigations(Whitelist allowedNavigations) {+ this.allowedNavigations = allowedNavigations;+ }++ public Whitelist getAllowedIntents() {+ return allowedIntents;+ }++ public void setAllowedIntents(Whitelist allowedIntents) {+ this.allowedIntents = allowedIntents;+ }++ public Whitelist getAllowedRequests() {+ return allowedRequests;+ }++ public void setAllowedRequests(Whitelist allowedRequests) {+ this.allowedRequests = allowedRequests;+ }+}diff --git a/cordova/platforms/android/app/src/main/res/xml/config.xml b/cordova/platforms/android/app/src/main/res/xml/config.xmlindex 70c593141..c4fb98969 100644--- a/cordova/platforms/android/app/src/main/res/xml/config.xml+++ b/cordova/platforms/android/app/src/main/res/xml/config.xml@@ -8,6 +8,10 @@<feature name="Device"><param name="android-package" value="org.apache.cordova.device.Device" /></feature>+ <feature name="Whitelist">+ <param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />+ <param name="onload" value="true" />+ </feature><name>TagSpaces</name><description>A sample Apache Cordova application that responds to the deviceready event.diff --git a/cordova/platforms/android/platform_www/cordova_plugins.js b/cordova/platforms/android/platform_www/cordova_plugins.jsindex 6b6a4b338..387eea4c7 100644--- a/cordova/platforms/android/platform_www/cordova_plugins.js+++ b/cordova/platforms/android/platform_www/cordova_plugins.js@@ -186,7 +186,8 @@ module.exports.metadata =// TOP OF METADATA{"cordova-plugin-file": "6.0.1",- "cordova-plugin-device": "2.0.2"+ "cordova-plugin-device": "2.0.2",+ "cordova-plugin-whitelist": "1.3.3"};// BOTTOM OF METADATA});\ No newline at end of file