Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
Map<String, String> headers = call.argument("headers");
boolean scrollBar = call.argument("scrollBar");
boolean allowFileURLs = call.argument("allowFileURLs");
boolean geolocationEnabled = call.argument("geolocationEnabled");

if (webViewManager == null || webViewManager.closed == true) {
webViewManager = new WebviewManager(activity);
Expand All @@ -118,7 +119,8 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
scrollBar,
supportMultipleWindows,
appCacheEnabled,
allowFileURLs
allowFileURLs,
geolocationEnabled
);
result.success(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
Expand Down Expand Up @@ -204,7 +205,8 @@ void openUrl(
boolean scrollBar,
boolean supportMultipleWindows,
boolean appCacheEnabled,
boolean allowFileURLs
boolean allowFileURLs,
boolean geolocationEnabled
) {
webView.getSettings().setJavaScriptEnabled(withJavascript);
webView.getSettings().setBuiltInZoomControls(withZoom);
Expand All @@ -219,6 +221,16 @@ void openUrl(
webView.getSettings().setAllowFileAccessFromFileURLs(allowFileURLs);
webView.getSettings().setAllowUniversalAccessFromFileURLs(allowFileURLs);

if (geolocationEnabled) {
webView.getSettings().setGeolocationEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class FlutterWebviewPlugin {
bool supportMultipleWindows,
bool appCacheEnabled,
bool allowFileURLs,
bool geolocationEnabled,
}) async {
final args = <String, dynamic>{
'url': url,
Expand All @@ -126,6 +127,7 @@ class FlutterWebviewPlugin {
'supportMultipleWindows': supportMultipleWindows ?? false,
'appCacheEnabled': appCacheEnabled ?? false,
'allowFileURLs': allowFileURLs ?? false,
'geolocationEnabled': geolocationEnabled ?? false,
};

if (headers != null) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/webview_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WebviewScaffold extends StatefulWidget {
this.hidden = false,
this.initialChild,
this.allowFileURLs,
this.geolocationEnabled
}) : super(key: key);

final PreferredSizeWidget appBar;
Expand All @@ -52,6 +53,7 @@ class WebviewScaffold extends StatefulWidget {
final bool hidden;
final Widget initialChild;
final bool allowFileURLs;
final bool geolocationEnabled;

@override
_WebviewScaffoldState createState() => _WebviewScaffoldState();
Expand Down Expand Up @@ -115,6 +117,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
supportMultipleWindows: widget.supportMultipleWindows,
appCacheEnabled: widget.appCacheEnabled,
allowFileURLs: widget.allowFileURLs,
geolocationEnabled: widget.geolocationEnabled
);
} else {
if (_rect != value) {
Expand Down