You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2015/02/13 20:15:01 UTC

cordova-plugins git commit: Add intent and navigation whitelists

Repository: cordova-plugins
Updated Branches:
  refs/heads/master a365e2acc -> 47a7ecd27


Add intent and navigation whitelists


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/47a7ecd2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/47a7ecd2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/47a7ecd2

Branch: refs/heads/master
Commit: 47a7ecd2744d1ecb3f34fca09e6f2cecf54766f8
Parents: a365e2a
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Feb 13 14:14:17 2015 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Feb 13 14:14:22 2015 -0500

----------------------------------------------------------------------
 intent-whitelist/README.md                      | 32 +++++++
 intent-whitelist/plugin.xml                     | 59 +++++++++++++
 .../src/android/IntentWhitelistPlugin.java      | 60 +++++++++++++
 .../src/ios/CDVIntentWhitelistPlugin.h          | 30 +++++++
 .../src/ios/CDVIntentWhitelistPlugin.m          | 86 +++++++++++++++++++
 navigation-whitelist/README.md                  | 25 ++++++
 navigation-whitelist/plugin.xml                 | 59 +++++++++++++
 .../src/android/NavigationWhitelistPlugin.java  | 71 ++++++++++++++++
 .../src/ios/CDVNavigationWhitelistPlugin.h      | 31 +++++++
 .../src/ios/CDVNavigationWhitelistPlugin.m      | 89 ++++++++++++++++++++
 10 files changed, 542 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/intent-whitelist/README.md
----------------------------------------------------------------------
diff --git a/intent-whitelist/README.md b/intent-whitelist/README.md
new file mode 100644
index 0000000..ca59e50
--- /dev/null
+++ b/intent-whitelist/README.md
@@ -0,0 +1,32 @@
+cordova-plugin-intent-whitelist
+===============================
+
+This plugin implements a whitelist policy for firing external intents on Cordova 4.0
+
+Currently only supports the "unplug-whitelist" branch of cordova-android and cordova-ios
+
+Usage:
+  In config.xml, add `<allow-intent>` tags, like this:
+
+    <!-- Allow links to example.com to open in a browser -->
+    <allow-intent href="http://example.com/*" />
+
+    <!-- Wildcards are allowed for the protocol, as a prefix
+         to the host, or as a suffix to the path -->
+    <allow-intent href="*://*.example.com/*" />
+
+  On Android, intent urls will launch external applications, if allowed
+  by the `<allow-intent>` tags. For example:
+
+    <!-- Allow SMS links to open messaging app -->
+    <allow-intent href="sms:*" />
+
+    <!-- Allow tel: links to open the dialer -->
+    <allow-intent href="tel:*" />
+
+    <!-- Allow geo: links to open maps -->
+    <allow-intent href="geo:*" />
+
+    <!-- Allow all unrecognized URLs to open installed apps
+         *NOT RECOMMENDED* -->
+    <allow-intent href="*" />

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/intent-whitelist/plugin.xml
----------------------------------------------------------------------
diff --git a/intent-whitelist/plugin.xml b/intent-whitelist/plugin.xml
new file mode 100644
index 0000000..4b0d380
--- /dev/null
+++ b/intent-whitelist/plugin.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+xmlns:android="http://schemas.android.com/apk/res/android"
+           id="org.apache.cordova.intent-whitelist"
+      version="0.0.1-dev">
+    <name>Whitelist</name>
+    <description>Cordova Intent Whitelist Plugin</description>
+    <license>Apache 2.0</license>
+    <keywords>cordova,whitelist</keywords>
+
+    <engines>
+      <engine name="cordova-android" version=">=4.0.0-dev" />
+      <engine name="cordova-ios" version=">=4.0.0-dev" />
+    </engines>
+
+    <!-- android -->
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Whitelist" >
+                <param name="android-package" value="org.apache.cordova.whitelist.IntentWhitelistPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/IntentWhitelistPlugin.java" target-dir="src/org/apache/cordova/whitelist" />
+    </platform>
+
+    <!-- ios -->
+    <platform name="ios">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Whitelist">
+                <param name="ios-package" value="CDVIntentWhitelistPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+
+        <header-file src="src/ios/CDVIntentWhitelistPlugin.h" />
+        <source-file src="src/ios/CDVIntentWhitelistPlugin.m" />
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/intent-whitelist/src/android/IntentWhitelistPlugin.java
----------------------------------------------------------------------
diff --git a/intent-whitelist/src/android/IntentWhitelistPlugin.java b/intent-whitelist/src/android/IntentWhitelistPlugin.java
new file mode 100644
index 0000000..5d72e99
--- /dev/null
+++ b/intent-whitelist/src/android/IntentWhitelistPlugin.java
@@ -0,0 +1,60 @@
+/*
+       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.CordovaInterface;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaWebView;
+import org.apache.cordova.ConfigXmlParser;
+import org.apache.cordova.Whitelist;
+import android.content.res.XmlResourceParser;
+import android.util.Log;
+
+public class IntentWhitelistPlugin extends CordovaPlugin {
+
+    private Whitelist allowedIntentPatterns = new Whitelist();
+
+    private static final String TAG = "IntentWhitelist";
+
+    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+
+        new ConfigXmlParser(){
+            public void handleStartTag(XmlResourceParser xml) {
+                String strNode = xml.getName();
+                if (strNode.equals("allow-intent")) {
+                    String origin = xml.getAttributeValue(null, "href");
+                    allowedIntentPatterns.addWhiteListEntry(origin, false);
+                }
+            }
+            public void handleEndTag(XmlResourceParser xml) {
+            }
+        }.parse(cordova.getActivity());
+    }
+
+    public Boolean shouldOpenExternalURL(String url) {
+        return allowedIntentPatterns.isUrlWhiteListed(url);
+    }
+
+    public Boolean shouldAllowRequest(String url) {
+        return shouldOpenExternalURL(url);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.h
----------------------------------------------------------------------
diff --git a/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.h b/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.h
new file mode 100644
index 0000000..55181fa
--- /dev/null
+++ b/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.h
@@ -0,0 +1,30 @@
+/*
+ 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.
+ */
+
+#import <UIKit/UIKit.h>
+#import <Cordova/CDVPlugin.h>
+#import <Cordova/CDVWhitelist.h>
+
+@interface CDVIntentWhitelistPlugin : CDVPlugin {}
+
+@property (nonatomic, readonly, strong) CDVWhitelist* whitelist; // readonly for public
+
+- (BOOL)shouldOpenExternalURL:(NSURL *)url;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.m
----------------------------------------------------------------------
diff --git a/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.m b/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.m
new file mode 100644
index 0000000..5bd1e5b
--- /dev/null
+++ b/intent-whitelist/src/ios/CDVIntentWhitelistPlugin.m
@@ -0,0 +1,86 @@
+/*
+ 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.
+ */
+
+#import "CDVIntentWhitelistPlugin.h"
+#import <Cordova/CDVViewController.h>
+
+#pragma mark CDVIntentWhitelistConfigParser
+
+@interface CDVIntentWhitelistConfigParser : NSObject <NSXMLParserDelegate> {}
+
+@property (nonatomic, strong) NSMutableArray* whitelistHosts;
+
+@end
+
+@implementation CDVIntentWhitelistConfigParser
+
+@synthesize whitelistHosts;
+
+- (id)init
+{
+    self = [super init];
+    if (self != nil) {
+        self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:30];
+    }
+    return self;
+}
+
+- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
+{
+    if ([elementName isEqualToString:@"allow-intent"]) {
+        [whitelistHosts addObject:attributeDict[@"href"]];
+    }
+}
+
+- (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName
+{
+}
+
+- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
+{
+    NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]);
+}
+
+
+@end
+
+#pragma mark CDVIntentWhitelistPlugin
+
+@interface CDVIntentWhitelistPlugin () {}
+@property (nonatomic, strong) CDVWhitelist* whitelist;
+@end
+
+@implementation CDVIntentWhitelistPlugin
+
+@synthesize whitelist;
+
+- (void)setViewController:(UIViewController *)viewController
+{
+    if ([viewController isKindOfClass:[CDVViewController class]]) {
+        CDVWhitelistConfigParser *whitelistConfigParser = [[CDVWhitelistConfigParser alloc] init];
+        [(CDVViewController *)viewController parseSettingsWithParser:whitelistConfigParser];
+        self.whitelist = [[CDVWhitelist alloc] initWithArray:whitelistConfigParser.whitelistHosts];
+    }
+}
+
+- (BOOL)shouldOpenExternalURL:(NSURL *)url
+{
+    return [self.whitelist URLIsAllowed:url];
+}
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/navigation-whitelist/README.md
----------------------------------------------------------------------
diff --git a/navigation-whitelist/README.md b/navigation-whitelist/README.md
new file mode 100644
index 0000000..78b2b29
--- /dev/null
+++ b/navigation-whitelist/README.md
@@ -0,0 +1,25 @@
+cordova-plugin-navigation-whitelist
+===================================
+
+This plugin implements a whitelist policy for navigating the application webview on Cordova 4.0
+
+Currently only supports the "unplug-whitelist" branch of cordova-android and cordova-ios
+
+Usage:
+  In config.xml, add `<allow-navigation>` tags, like this:
+
+    <!-- Allow links to example.com -->
+    <allow-navigation href="http://example.com/*" />
+
+    <!-- Wildcards are allowed for the protocol, as a prefix
+         to the host, or as a suffix to the path -->
+    <allow-havigation href="*://*.example.com/*" />
+
+    <!-- A wildcard can be used to whitelist the entire network,
+         over HTTP and HTTPS.
+         *NOT RECOMMENDED* -->
+    <allow-navigation href="*" />
+
+    <!-- The above is equivalent to these two declarations -->
+    <allow-navigation href="http://*/*" />
+    <allow-navigation href="https://*/*" />

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/navigation-whitelist/plugin.xml
----------------------------------------------------------------------
diff --git a/navigation-whitelist/plugin.xml b/navigation-whitelist/plugin.xml
new file mode 100644
index 0000000..d50a827
--- /dev/null
+++ b/navigation-whitelist/plugin.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+xmlns:android="http://schemas.android.com/apk/res/android"
+           id="org.apache.cordova.navigation-whitelist"
+      version="0.0.1-dev">
+    <name>Whitelist</name>
+    <description>Cordova Navigation Whitelist Plugin</description>
+    <license>Apache 2.0</license>
+    <keywords>cordova,whitelist</keywords>
+
+    <engines>
+      <engine name="cordova-android" version=">=4.0.0-dev" />
+      <engine name="cordova-ios" version=">=4.0.0-dev" />
+    </engines>
+
+    <!-- android -->
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Whitelist" >
+                <param name="android-package" value="org.apache.cordova.whitelist.NavigationWhitelistPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/NavigationWhitelistPlugin.java" target-dir="src/org/apache/cordova/whitelist" />
+    </platform>
+
+    <!-- ios -->
+    <platform name="ios">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Whitelist">
+                <param name="ios-package" value="CDVNavigationWhitelistPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+
+        <header-file src="src/ios/CDVNavigationWhitelistPlugin.h" />
+        <source-file src="src/ios/CDVNavigationWhitelistPlugin.m" />
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/navigation-whitelist/src/android/NavigationWhitelistPlugin.java
----------------------------------------------------------------------
diff --git a/navigation-whitelist/src/android/NavigationWhitelistPlugin.java b/navigation-whitelist/src/android/NavigationWhitelistPlugin.java
new file mode 100644
index 0000000..9dc6164
--- /dev/null
+++ b/navigation-whitelist/src/android/NavigationWhitelistPlugin.java
@@ -0,0 +1,71 @@
+/*
+       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.CordovaInterface;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaWebView;
+import org.apache.cordova.ConfigXmlParser;
+import org.apache.cordova.Whitelist;
+import android.content.res.XmlResourceParser;
+import android.util.Log;
+
+public class NavigationWhitelistPlugin extends CordovaPlugin {
+
+    private Whitelist allowedNavigationPatterns = new Whitelist();
+
+    private static final String TAG = "NavigationWhitelist";
+
+    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+
+        new ConfigXmlParser(){
+            public void handleStartTag(XmlResourceParser xml) {
+                String strNode = xml.getName();
+                if (strNode.equals("content")) {
+                    String startPage = xml.getAttributeValue(null, "src");
+                    allowedNavigationPatterns.addWhiteListEntry("file:///*", false);
+                } else if (strNode.equals("allow-navigation")) {
+                    String origin = xml.getAttributeValue(null, "href");
+                    if ("*".equals(origin)) {
+                        // Special-case * origin to mean http and https when used for internal
+                        // whitelist. This prevents external urls like sms: and geo: from being
+                        // handled internally.
+                        allowedNavigationPatterns.addWhiteListEntry("http://*/*", false);
+                        allowedNavigationPatterns.addWhiteListEntry("https://*/*", false);
+                    } else {
+                        allowedNavigationPatterns.addWhiteListEntry(origin, false);
+                    }
+                }
+            }
+            public void handleEndTag(XmlResourceParser xml) {
+            }
+        }.parse(cordova.getActivity());
+    }
+
+    public Boolean shouldAllowNavigation(String url) {
+        return allowedNavigationPatterns.isUrlWhiteListed(url);
+    }
+
+    public Boolean shouldAllowRequest(String url) {
+        return shouldAllowNavigation(url);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.h
----------------------------------------------------------------------
diff --git a/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.h b/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.h
new file mode 100644
index 0000000..d0b9365
--- /dev/null
+++ b/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.h
@@ -0,0 +1,31 @@
+/*
+ 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.
+ */
+
+#import <UIKit/UIKit.h>
+#import <Cordova/CDVPlugin.h>
+#import <Cordova/CDVWhitelist.h>
+
+@interface CDVNavigationWhitelistPlugin : CDVPlugin {}
+
+@property (nonatomic, readonly, strong) CDVWhitelist* whitelist; // readonly for public
+
+- (BOOL)shouldAllowNavigationToURL:(NSURL *)url;
+- (BOOL)shouldAllowRequestForURL:(NSURL *)url;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/47a7ecd2/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.m
----------------------------------------------------------------------
diff --git a/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.m b/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.m
new file mode 100644
index 0000000..5895e89
--- /dev/null
+++ b/navigation-whitelist/src/ios/CDVNavigationWhitelistPlugin.m
@@ -0,0 +1,89 @@
+/*
+ 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.
+ */
+
+#import "CDVNavigationWhitelistPlugin.h"
+#import <Cordova/CDVViewController.h>
+
+#pragma mark CDVNavigationWhitelistConfigParser
+
+@interface CDVNavigationWhitelistConfigParser : NSObject <NSXMLParserDelegate> {}
+
+@property (nonatomic, strong) NSMutableArray* whitelistHosts;
+
+@end
+
+@implementation CDVNavigationWhitelistConfigParser
+
+@synthesize whitelistHosts;
+
+- (id)init
+{
+    self = [super init];
+    if (self != nil) {
+        self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:30];
+        [self.whitelistHosts addObject:@"file:///*"];
+        [self.whitelistHosts addObject:@"content:///*"];
+        [self.whitelistHosts addObject:@"data:///*"];
+    }
+    return self;
+}
+
+- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
+{
+    if ([elementName isEqualToString:@"allow-navigation"]) {
+        [whitelistHosts addObject:attributeDict[@"href"]];
+    }
+}
+
+- (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName
+{
+}
+
+- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
+{
+    NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]);
+}
+
+
+@end
+
+#pragma mark CDVNavigationWhitelistPlugin
+
+@interface CDVNavigationWhitelistPlugin () {}
+@property (nonatomic, strong) CDVWhitelist* whitelist;
+@end
+
+@implementation CDVNavigationWhitelistPlugin
+
+@synthesize whitelist;
+
+- (void)setViewController:(UIViewController *)viewController
+{
+    if ([viewController isKindOfClass:[CDVViewController class]]) {
+        CDVWhitelistConfigParser *whitelistConfigParser = [[CDVWhitelistConfigParser alloc] init];
+        [(CDVViewController *)viewController parseSettingsWithParser:whitelistConfigParser];
+        self.whitelist = [[CDVWhitelist alloc] initWithArray:whitelistConfigParser.whitelistHosts];
+    }
+}
+
+- (BOOL)shouldAllowNavigationToURL:(NSURL *)url
+{
+    return [self.whitelist URLIsAllowed:url];
+}
+@end


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org