Przeglądaj źródła

Merge branch 'master' into master

Rafal Wachol 6 lat temu
rodzic
commit
2bca220a60

+ 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
 
 - 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
 
@@ -189,6 +193,7 @@ Future<Null> launch(String url, {
    bool withZoom: false,
    bool withLocalStorage: true,
    bool withLocalUrl: true,
+   String localUrlScope: null,
    bool scrollBar: true,
    bool supportMultipleWindows: false,
    bool appCacheEnabled: false,

+ 1 - 0
android/build.gradle

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

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

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

+ 10 - 2
ios/Classes/FlutterWebviewPlugin.m

@@ -177,8 +177,15 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
             NSNumber *withLocalUrl = call.arguments[@"withLocalUrl"];
             if ( [withLocalUrl boolValue]) {
                 NSURL *htmlUrl = [NSURL fileURLWithPath:url isDirectory:false];
+                NSString *localUrlScope = call.arguments[@"localUrlScope"];
                 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 {
                     @throw @"not available on version earlier than ios 9.0";
                 }
@@ -325,7 +332,8 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     if (_enableAppScheme ||
         ([webView.URL.scheme isEqualToString:@"http"] ||
          [webView.URL.scheme isEqualToString:@"https"] ||
-         [webView.URL.scheme isEqualToString:@"about"])) {
+         [webView.URL.scheme isEqualToString:@"about"] ||
+         [webView.URL.scheme isEqualToString:@"file"])) {
          if (isInvalid) {
             decisionHandler(WKNavigationActionPolicyCancel);
          } 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.
   /// - [withLocalUrl]: allow url as a local path
   ///     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
   /// - [supportMultipleWindows] enable multiple windows support in Android
   /// - [invalidUrlRegex] is the regular expression of URLs that web view shouldn't load.
@@ -144,6 +148,7 @@ class FlutterWebviewPlugin {
     bool displayZoomControls,
     bool withLocalStorage,
     bool withLocalUrl,
+    String localUrlScope,
     bool withOverviewMode,
     bool scrollBar,
     bool supportMultipleWindows,
@@ -166,6 +171,7 @@ class FlutterWebviewPlugin {
       'displayZoomControls': displayZoomControls ?? false,
       'withLocalStorage': withLocalStorage ?? true,
       'withLocalUrl': withLocalUrl ?? false,
+      'localUrlScope': localUrlScope,
       'scrollBar': scrollBar ?? true,
       'supportMultipleWindows': supportMultipleWindows ?? false,
       'appCacheEnabled': appCacheEnabled ?? false,

+ 3 - 0
lib/src/webview_scaffold.dart

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

+ 2 - 2
pubspec.yaml

@@ -7,8 +7,8 @@ authors:
 - Simon Lightfoot <simon@devangels.london>
 - Rafal Wachol <gorudonu@gmail.com>
 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:
   sdk: ">=2.0.0 <3.0.0"