cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject cordova-plugins git commit: Add legacy-whitelist plugin
Date Thu, 04 Dec 2014 16:04:16 GMT
Repository: cordova-plugins
Updated Branches:
  refs/heads/master b61364dd6 -> 83a461590


Add legacy-whitelist plugin


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

Branch: refs/heads/master
Commit: 83a46159073ad140217b5e79a740bf6dac2d4d21
Parents: b61364d
Author: Ian Clelland <iclelland@chromium.org>
Authored: Thu Dec 4 11:03:58 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Thu Dec 4 11:03:58 2014 -0500

----------------------------------------------------------------------
 legacy-whitelist/README.md                      |   9 ++
 legacy-whitelist/plugin.xml                     |  54 ++++++++++
 .../src/android/LegacyWhitelistPlugin.java      |  83 +++++++++++++++
 .../src/ios/CDVLegacyWhitelistPlugin.h          |  32 ++++++
 .../src/ios/CDVLegacyWhitelistPlugin.m          | 106 +++++++++++++++++++
 5 files changed, 284 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/83a46159/legacy-whitelist/README.md
----------------------------------------------------------------------
diff --git a/legacy-whitelist/README.md b/legacy-whitelist/README.md
new file mode 100644
index 0000000..c7d60fd
--- /dev/null
+++ b/legacy-whitelist/README.md
@@ -0,0 +1,9 @@
+cordova-plugin-legacy-whitelist
+===============================
+
+This plugin implements the Cordova 3.6 Whitelist policy for Cordova 4.0.
+
+Currently only supports the "unplug-whitelist" branch of cordova-android and cordova-ios
+
+Usage:
+  Use <access> tags, just as in previous versions of Cordova.

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/83a46159/legacy-whitelist/plugin.xml
----------------------------------------------------------------------
diff --git a/legacy-whitelist/plugin.xml b/legacy-whitelist/plugin.xml
new file mode 100644
index 0000000..211d4a5
--- /dev/null
+++ b/legacy-whitelist/plugin.xml
@@ -0,0 +1,54 @@
+<?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.legacy-whitelist"
+      version="1.3.2-dev">
+    <name>Whitelist</name>
+    <description>Cordova Legacy Whitelist Plugin</description>
+    <license>Apache 2.0</license>
+    <keywords>cordova,whitelist</keywords>
+
+    <!-- android -->
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Whitelist" >
+                <param name="android-package" value="org.apache.cordova.whitelist.LegacyWhitelistPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/LegacyWhitelistPlugin.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="CDVLegacyWhitelistPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+
+        <header-file src="src/ios/CDVLegacyWhitelistPlugin.h" />
+        <source-file src="src/ios/CDVLegacyWhitelistPlugin.m" />
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/83a46159/legacy-whitelist/src/android/LegacyWhitelistPlugin.java
----------------------------------------------------------------------
diff --git a/legacy-whitelist/src/android/LegacyWhitelistPlugin.java b/legacy-whitelist/src/android/LegacyWhitelistPlugin.java
new file mode 100644
index 0000000..1199466
--- /dev/null
+++ b/legacy-whitelist/src/android/LegacyWhitelistPlugin.java
@@ -0,0 +1,83 @@
+/*
+       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;
+
+public class LegacyWhitelistPlugin extends CordovaPlugin {
+
+    private Whitelist internalWhitelist = new Whitelist();
+    private Whitelist externalWhitelist = new Whitelist();
+
+    private static final String TAG = "Whitelist";
+
+    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+        // Add implicitly allowed URLs
+        internalWhitelist.addWhiteListEntry("file:///*", false);
+        internalWhitelist.addWhiteListEntry("content:///*", false);
+        internalWhitelist.addWhiteListEntry("data:*", false);
+
+        new ConfigXmlParser(){
+            public void handleStartTag(XmlResourceParser xml) {
+                String strNode = xml.getName();
+                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) {
+                            externalWhitelist.addWhiteListEntry(origin, (subdomains != null)
&& (subdomains.compareToIgnoreCase("true") == 0));
+                        } else {
+                            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.
+                                internalWhitelist.addWhiteListEntry("http://*/*", false);
+                                internalWhitelist.addWhiteListEntry("https://*/*", false);
+                            } else {
+                                internalWhitelist.addWhiteListEntry(origin, (subdomains !=
null) && (subdomains.compareToIgnoreCase("true") == 0));
+                            }
+                        }
+                    }
+                }
+            }
+            public void handleEndTag(XmlResourceParser xml) {
+            }
+        }.parse(cordova.getActivity());
+    }
+
+    public Boolean shouldAllowRequest(String url) {
+        return internalWhitelist.isUrlWhiteListed(url);
+    }
+
+    public Boolean shouldAllowNavigation(String url) {
+        return internalWhitelist.isUrlWhiteListed(url);
+    }
+
+    public Boolean shouldOpenExternalUrl(String url) {
+        return externalWhitelist.isUrlWhiteListed(url);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/83a46159/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.h
----------------------------------------------------------------------
diff --git a/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.h b/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.h
new file mode 100644
index 0000000..30ea3e3
--- /dev/null
+++ b/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.h
@@ -0,0 +1,32 @@
+/*
+ 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 CDVLegacyWhitelistPlugin : CDVPlugin {}
+
+@property (nonatomic, readonly, strong) CDVWhitelist* whitelist; // readonly for public
+
+- (BOOL)shouldAllowNavigationToURL:(NSURL *)url;
+- (BOOL)shouldAllowRequestForURL:(NSURL *)url;
+- (BOOL)shouldOpenExternalURL:(NSURL *)url;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/83a46159/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.m
----------------------------------------------------------------------
diff --git a/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.m b/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.m
new file mode 100644
index 0000000..fb7bdf9
--- /dev/null
+++ b/legacy-whitelist/src/ios/CDVLegacyWhitelistPlugin.m
@@ -0,0 +1,106 @@
+/*
+ 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 "CDVLegacyWhitelistPlugin.h"
+#import <Cordova/CDVViewController.h>
+
+#pragma mark CDVWhitelistConfigParser
+
+@interface CDVWhitelistConfigParser : NSObject <NSXMLParserDelegate> {}
+
+@property (nonatomic, strong) NSMutableArray* whitelistHosts;
+
+@end
+
+@implementation CDVWhitelistConfigParser
+
+@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:@"access"]) {
+        [whitelistHosts addObject:attributeDict[@"origin"]];
+    }
+}
+
+- (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 CDVLegacyWhitelistPlugin
+
+@interface CDVLegacyWhitelistPlugin () {}
+@property (nonatomic, strong) CDVWhitelist* whitelist;
+@end
+
+@implementation CDVLegacyWhitelistPlugin
+
+@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];
+}
+
+- (BOOL)shouldAllowRequestForURL:(NSURL *)url
+{
+    return [self.whitelist URLIsAllowed:url];
+}
+
+- (BOOL)shouldOpenExternalURL:(NSURL *)url
+{
+    /*
+     * all tel: scheme urls we let the UIWebview handle it using the default behavior
+     */
+    if ([[url scheme] isEqualToString:@"tel"]) {
+        return YES;
+    }
+    return NO;
+}
+
+@end


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


Mime
View raw message