浏览代码

Merge branch 'master' into master

Rafal Wachol 6 年之前
父节点
当前提交
2bca220a60
共有 8 个文件被更改,包括 33 次插入5 次删除
  1. 6 0
      CHANGELOG.md
  2. 5 0
      README.md
  3. 1 0
      android/build.gradle
  4. 0 1
      android/src/main/AndroidManifest.xml
  5. 10 2
      ios/Classes/FlutterWebviewPlugin.m
  6. 6 0
      lib/src/base.dart
  7. 3 0
      lib/src/webview_scaffold.dart
  8. 2 2
      pubspec.yaml

+ 6 - 0
CHANGELOG.md

@@ -1,3 +1,9 @@
+# 0.3.8
+
+- Fix iOS local URL support (fixes #114)
+- bugfix: Added google() repository to allprojects to satisfy androidx build rules
+- fixed min sdk for android
+
 # 0.3.7
 # 0.3.7
 
 
 - Added reloading url with headers
 - Added reloading url with headers

+ 5 - 0
README.md

@@ -161,6 +161,10 @@ Future<String> loadJS(String name) async {
 }
 }
 ```
 ```
 
 
+### Accessing local files in the file system
+Set the `withLocalUrl` option to true in the launch function or in the Webview scaffold to enable support for local URLs.
+
+Note that, on iOS, the `localUrlScope` option also needs to be set to a path to a directory. All files inside this folder (or subfolder) will be allowed access. If ommited, only the local file being opened will have access allowed, resulting in no subresources being loaded. This option is ignored on Android.
 
 
 ### Webview Events
 ### Webview Events
 
 
@@ -189,6 +193,7 @@ Future<Null> launch(String url, {
    bool withZoom: false,
    bool withZoom: false,
    bool withLocalStorage: true,
    bool withLocalStorage: true,
    bool withLocalUrl: true,
    bool withLocalUrl: true,
+   String localUrlScope: null,
    bool scrollBar: true,
    bool scrollBar: true,
    bool supportMultipleWindows: false,
    bool supportMultipleWindows: false,
    bool appCacheEnabled: false,
    bool appCacheEnabled: false,

+ 1 - 0
android/build.gradle

@@ -27,6 +27,7 @@ buildscript {
 allprojects {
 allprojects {
     repositories {
     repositories {
         jcenter()
         jcenter()
+        google()
     }
     }
 }
 }
 
 

+ 0 - 1
android/src/main/AndroidManifest.xml

@@ -1,7 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:tools="http://schemas.android.com/tools"
           xmlns:tools="http://schemas.android.com/tools"
           package="com.flutter_webview_plugin">
           package="com.flutter_webview_plugin">
-    <uses-sdk android:minSdkVersion="16" />
 
 
     <application>
     <application>
         <provider
         <provider

+ 10 - 2
ios/Classes/FlutterWebviewPlugin.m

@@ -177,8 +177,15 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
             NSNumber *withLocalUrl = call.arguments[@"withLocalUrl"];
             NSNumber *withLocalUrl = call.arguments[@"withLocalUrl"];
             if ( [withLocalUrl boolValue]) {
             if ( [withLocalUrl boolValue]) {
                 NSURL *htmlUrl = [NSURL fileURLWithPath:url isDirectory:false];
                 NSURL *htmlUrl = [NSURL fileURLWithPath:url isDirectory:false];
+                NSString *localUrlScope = call.arguments[@"localUrlScope"];
                 if (@available(iOS 9.0, *)) {
                 if (@available(iOS 9.0, *)) {
-                    [self.webview loadFileURL:htmlUrl allowingReadAccessToURL:htmlUrl];
+                    if(localUrlScope == nil) {
+                        [self.webview loadFileURL:htmlUrl allowingReadAccessToURL:htmlUrl];
+                    }
+                    else {
+                        NSURL *scopeUrl = [NSURL fileURLWithPath:localUrlScope];
+                        [self.webview loadFileURL:htmlUrl allowingReadAccessToURL:scopeUrl];
+                    }
                 } else {
                 } else {
                     @throw @"not available on version earlier than ios 9.0";
                     @throw @"not available on version earlier than ios 9.0";
                 }
                 }
@@ -325,7 +332,8 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     if (_enableAppScheme ||
     if (_enableAppScheme ||
         ([webView.URL.scheme isEqualToString:@"http"] ||
         ([webView.URL.scheme isEqualToString:@"http"] ||
          [webView.URL.scheme isEqualToString:@"https"] ||
          [webView.URL.scheme isEqualToString:@"https"] ||
-         [webView.URL.scheme isEqualToString:@"about"])) {
+         [webView.URL.scheme isEqualToString:@"about"] ||
+         [webView.URL.scheme isEqualToString:@"file"])) {
          if (isInvalid) {
          if (isInvalid) {
             decisionHandler(WKNavigationActionPolicyCancel);
             decisionHandler(WKNavigationActionPolicyCancel);
          } else {
          } else {

+ 6 - 0
lib/src/base.dart

@@ -120,6 +120,10 @@ class FlutterWebviewPlugin {
   ///     It is always enabled in UIWebView of iOS and  can not be disabled.
   ///     It is always enabled in UIWebView of iOS and  can not be disabled.
   /// - [withLocalUrl]: allow url as a local path
   /// - [withLocalUrl]: allow url as a local path
   ///     Allow local files on iOs > 9.0
   ///     Allow local files on iOs > 9.0
+  /// - [localUrlScope]: allowed folder for local paths
+  ///     iOS only.
+  ///     If null and withLocalUrl is true, then it will use the url as the scope,
+  ///     allowing only itself to be read.
   /// - [scrollBar]: enable or disable scrollbar
   /// - [scrollBar]: enable or disable scrollbar
   /// - [supportMultipleWindows] enable multiple windows support in Android
   /// - [supportMultipleWindows] enable multiple windows support in Android
   /// - [invalidUrlRegex] is the regular expression of URLs that web view shouldn't load.
   /// - [invalidUrlRegex] is the regular expression of URLs that web view shouldn't load.
@@ -144,6 +148,7 @@ class FlutterWebviewPlugin {
     bool displayZoomControls,
     bool displayZoomControls,
     bool withLocalStorage,
     bool withLocalStorage,
     bool withLocalUrl,
     bool withLocalUrl,
+    String localUrlScope,
     bool withOverviewMode,
     bool withOverviewMode,
     bool scrollBar,
     bool scrollBar,
     bool supportMultipleWindows,
     bool supportMultipleWindows,
@@ -166,6 +171,7 @@ class FlutterWebviewPlugin {
       'displayZoomControls': displayZoomControls ?? false,
       'displayZoomControls': displayZoomControls ?? false,
       'withLocalStorage': withLocalStorage ?? true,
       'withLocalStorage': withLocalStorage ?? true,
       'withLocalUrl': withLocalUrl ?? false,
       'withLocalUrl': withLocalUrl ?? false,
+      'localUrlScope': localUrlScope,
       'scrollBar': scrollBar ?? true,
       'scrollBar': scrollBar ?? true,
       'supportMultipleWindows': supportMultipleWindows ?? false,
       'supportMultipleWindows': supportMultipleWindows ?? false,
       'appCacheEnabled': appCacheEnabled ?? false,
       'appCacheEnabled': appCacheEnabled ?? false,

+ 3 - 0
lib/src/webview_scaffold.dart

@@ -26,6 +26,7 @@ class WebviewScaffold extends StatefulWidget {
     this.displayZoomControls,
     this.displayZoomControls,
     this.withLocalStorage,
     this.withLocalStorage,
     this.withLocalUrl,
     this.withLocalUrl,
+    this.localUrlScope,
     this.withOverviewMode,
     this.withOverviewMode,
     this.useWideViewPort,
     this.useWideViewPort,
     this.scrollBar,
     this.scrollBar,
@@ -56,6 +57,7 @@ class WebviewScaffold extends StatefulWidget {
   final bool displayZoomControls;
   final bool displayZoomControls;
   final bool withLocalStorage;
   final bool withLocalStorage;
   final bool withLocalUrl;
   final bool withLocalUrl;
+  final String localUrlScope;
   final bool scrollBar;
   final bool scrollBar;
   final bool supportMultipleWindows;
   final bool supportMultipleWindows;
   final bool appCacheEnabled;
   final bool appCacheEnabled;
@@ -162,6 +164,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
               displayZoomControls: widget.displayZoomControls,
               displayZoomControls: widget.displayZoomControls,
               withLocalStorage: widget.withLocalStorage,
               withLocalStorage: widget.withLocalStorage,
               withLocalUrl: widget.withLocalUrl,
               withLocalUrl: widget.withLocalUrl,
+              localUrlScope: widget.localUrlScope,
               withOverviewMode: widget.withOverviewMode,
               withOverviewMode: widget.withOverviewMode,
               useWideViewPort: widget.useWideViewPort,
               useWideViewPort: widget.useWideViewPort,
               scrollBar: widget.scrollBar,
               scrollBar: widget.scrollBar,

+ 2 - 2
pubspec.yaml

@@ -7,8 +7,8 @@ authors:
 - Simon Lightfoot <simon@devangels.london>
 - Simon Lightfoot <simon@devangels.london>
 - Rafal Wachol <gorudonu@gmail.com>
 - Rafal Wachol <gorudonu@gmail.com>
 homepage: https://github.com/dart-flitter/flutter_webview_plugin
 homepage: https://github.com/dart-flitter/flutter_webview_plugin
-version: 0.3.7
-maintainer: Simon Lightfoot (@slightfoot)
+version: 0.3.8
+maintainer: Rafal Wachol (@RafalWachol) 
 
 
 environment:
 environment:
   sdk: ">=2.0.0 <3.0.0"
   sdk: ">=2.0.0 <3.0.0"