Commit bc6bed18 authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

Added new WebView option minimumFontSize, Added new Android WebView options,...

Added new WebView option minimumFontSize, Added new Android WebView options, Added new iOS WebView options, Added onGeolocationPermissionsShowPrompt event and GeolocationPermissionShowPromptResponse class (available only for Android), updated Android ContentBlocker, updated Android build.gradle compileSdkVersion 29
parent 372b7712
This diff is collapsed.
## 1.3.0
## 2.0.0
- Merge "Avoid null pointer exception after webview is disposed" [#116](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/116) (thanks to [robsonfingo](https://github.com/robsonfingo))
- Merge "Remove async call in close" [#119](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/119) (thanks to [benfingo](https://github.com/benfingo))
......@@ -13,6 +13,10 @@
- Added `onLoadResourceCustomScheme` event and `resourceCustomSchemes` option to set custom schemes that WebView must handle to load resources
- Added `onTargetBlank` event and `useOnTargetBlank` option to manage links with `target="_blank"`
- Added `ContentBlocker`, `ContentBlockerTrigger` and `ContentBlockerAction` classes and the `contentBlockers` option that allows to define a set of rules to use to block content in the WebView
- Added new WebView option `minimumFontSize`
- Added new Android WebView options: `allowContentAccess`, `allowFileAccess`, `allowFileAccessFromFileURLs`, `allowUniversalAccessFromFileURLs`, `appCacheEnabled`, `appCachePath`, `blockNetworkImage`, `blockNetworkLoads`, `cacheMode`, `cursiveFontFamily`, `defaultFixedFontSize`, `defaultFontSize`, `defaultTextEncodingName`, `disabledActionModeMenuItems`, `fantasyFontFamily`, `fixedFontFamily`, `forceDark`, `geolocationEnabled`, `layoutAlgorithm`, `loadWithOverviewMode`, `loadsImagesAutomatically`, `minimumLogicalFontSize`, `needInitialFocus`, `offscreenPreRaster`, `sansSerifFontFamily`, `serifFontFamily`, `standardFontFamily`
- Added new iOS WebView options: `applicationNameForUserAgent`, `isFraudulentWebsiteWarningEnabled`, `selectionGranularity`, `dataDetectorTypes`, `preferredContentMode`
- Added `onGeolocationPermissionsShowPrompt` event and `GeolocationPermissionShowPromptResponse` class (available only for Android)
### BREAKING CHANGES
- Deleted `WebResourceRequest` class
......@@ -20,7 +24,6 @@
- Updated `onLoadResource` event
- WebView options are now available with the new corresponding classes: `InAppWebViewOptions`, `AndroidInAppWebViewOptions`, `iOSInAppWebViewOptions`, `InAppBrowserOptions`, `AndroidInAppBrowserOptions`, `iOSInAppBrowserOptions`, `AndroidChromeCustomTabsOptions` and `iOSChromeCustomTabsOptions`
## 1.2.1
- Merge "Add new option to control the contentMode in Android platform" [#101](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/101) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
......
......@@ -35,7 +35,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
minSdkVersion 17
......
......@@ -3,10 +3,12 @@ package com.pichillilorenzo.flutter_inappbrowser.ContentBlocker;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class ContentBlockerTrigger {
public String urlFilter;
public Pattern urlFilterPatternCompiled;
public Boolean urlFilterIsCaseSensitive;
public List<ContentBlockerTriggerResourceType> resourceType = new ArrayList<>();
public List<String> ifDomain = new ArrayList<>();
......@@ -18,6 +20,8 @@ public class ContentBlockerTrigger {
public ContentBlockerTrigger(String urlFilter, Boolean urlFilterIsCaseSensitive, List<ContentBlockerTriggerResourceType> resourceType, List<String> ifDomain,
List<String> unlessDomain, List<String> loadType, List<String> ifTopUrl, List<String> unlessTopUrl) {
this.urlFilter = urlFilter;
this.urlFilterPatternCompiled = Pattern.compile(this.urlFilter);
this.resourceType = resourceType != null ? resourceType : this.resourceType;
this.urlFilterIsCaseSensitive = urlFilterIsCaseSensitive != null ? urlFilterIsCaseSensitive : false;
this.ifDomain = ifDomain != null ? ifDomain : this.ifDomain;
......
package com.pichillilorenzo.flutter_inappbrowser;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
......@@ -191,7 +192,10 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
result.success((webView != null) && webView.isLoading());
break;
case "takeScreenshot":
result.success((webView != null) ? webView.takeScreenshot() : null);
if (webView != null)
webView.takeScreenshot(result);
else
result.error(LOG_TAG, "webView is null", null);
break;
case "setOptions":
if (webView != null) {
......
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
......@@ -9,6 +11,7 @@ import android.os.Build;
import android.util.Log;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
......@@ -17,6 +20,7 @@ import android.widget.FrameLayout;
import com.pichillilorenzo.flutter_inappbrowser.FlutterWebView;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserActivity;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserFlutterPlugin;
import com.pichillilorenzo.flutter_inappbrowser.RequestPermissionHandler;
import java.util.HashMap;
import java.util.Map;
......@@ -98,6 +102,34 @@ public class InAppWebChromeClient extends WebChromeClient {
return false;
}
@Override
public void onGeolocationPermissionsShowPrompt (final String origin, final GeolocationPermissions.Callback callback) {
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
obj.put("origin", origin);
getChannel().invokeMethod("onGeolocationPermissionsShowPrompt", obj, new MethodChannel.Result() {
@Override
public void success(Object o) {
Map<String, Object> response = (Map<String, Object>) o;
if (response != null)
callback.invoke((String) response.get("origin"),(Boolean) response.get("allow"),(Boolean) response.get("retain"));
else
callback.invoke(origin,false,false);
}
@Override
public void error(String s, String s1, Object o) {
callback.invoke(origin,false,false);
}
@Override
public void notImplemented() {
callback.invoke(origin,false,false);
}
});
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Map<String, Object> obj = new HashMap<>();
......
......@@ -335,7 +335,7 @@ public class InAppWebViewClient extends WebViewClient {
Map<String, String> res = (Map<String, String>) flutterResult.result;
WebResourceResponse response = null;
try {
response = ContentBlocker.checkUrl(webView, url, res.get("content-type"));
response = webView.contentBlockerHandler.checkUrl(webView, url, res.get("content-type"));
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
......@@ -349,7 +349,7 @@ public class InAppWebViewClient extends WebViewClient {
WebResourceResponse response = null;
try {
response = ContentBlocker.checkUrl(webView, url);
response = webView.contentBlockerHandler.checkUrl(webView, url);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
......
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
import android.webkit.WebSettings;
import com.pichillilorenzo.flutter_inappbrowser.Options;
import java.util.ArrayList;
......@@ -19,11 +21,12 @@ public class InAppWebViewOptions extends Options {
public boolean javaScriptEnabled = true;
public boolean javaScriptCanOpenWindowsAutomatically = false;
public boolean mediaPlaybackRequiresUserGesture = true;
public int textZoom = 100;
public Integer textZoom = 100;
public boolean verticalScrollBarEnabled = true;
public boolean horizontalScrollBarEnabled = true;
public List<String> resourceCustomSchemes = new ArrayList<>();
public List<Map<String, Map<String, Object>>> contentBlockers = new ArrayList<>();
public Integer minimumFontSize = 8;
public boolean clearSessionCache = false;
public boolean builtInZoomControls = false;
......@@ -34,5 +37,32 @@ public class InAppWebViewOptions extends Options {
public boolean useWideViewPort = true;
public boolean safeBrowsingEnabled = true;
public boolean transparentBackground = false;
public String mixedContentMode = "";
public Integer mixedContentMode;
public boolean allowContentAccess = true;
public boolean allowFileAccess = true;
public boolean allowFileAccessFromFileURLs = true;
public boolean allowUniversalAccessFromFileURLs = true;
public boolean appCacheEnabled = true;
public String appCachePath;
public boolean blockNetworkImage = false;
public boolean blockNetworkLoads = false;
public Integer cacheMode = WebSettings.LOAD_DEFAULT;
public String cursiveFontFamily = "cursive";
public Integer defaultFixedFontSize = 16;
public Integer defaultFontSize = 16;
public String defaultTextEncodingName = "UTF-8";
public Integer disabledActionModeMenuItems;
public String fantasyFontFamily = "fantasy";
public String fixedFontFamily = "monospace";
public Integer forceDark = 0; // WebSettings.FORCE_DARK_OFF
public boolean geolocationEnabled = true;
public WebSettings.LayoutAlgorithm layoutAlgorithm;
public boolean loadWithOverviewMode = true;
public boolean loadsImagesAutomatically = true;
public Integer minimumLogicalFontSize = 8;
public boolean needInitialFocus = true;
public boolean offscreenPreRaster = false;
public String sansSerifFontFamily = "sans-serif";
public String serifFontFamily = "sans-serif";
public String standardFontFamily = "sans-serif";
}
......@@ -2,6 +2,8 @@ package com.pichillilorenzo.flutter_inappbrowser;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
......@@ -15,8 +17,6 @@ public abstract class RequestPermissionHandler implements ActivityCompat.OnReque
private static Map<Integer, List<Runnable>> actionDictionary = new HashMap<>();
public static int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 1;
public static void checkAndRun(Activity activity, String permission, int requestCode, Runnable runnable) {
int permissionCheck = ContextCompat.checkSelfPermission(activity.getApplicationContext(), permission);
......@@ -34,6 +34,7 @@ public abstract class RequestPermissionHandler implements ActivityCompat.OnReque
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
Log.d("asdasd", "\n\na asd asd \n\n");
if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
List<Runnable> callbacks = actionDictionary.get(requestCode);
for (Runnable runnable : callbacks) {
......
......@@ -91,6 +91,5 @@ public class Util {
result = r;
error = e;
}
}
}
......@@ -9,6 +9,12 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
......
......@@ -56,6 +56,15 @@
});
$(document).ready(function() {
console.log("jQuery ready");
if ("geolocation" in navigator) {
console.log("Geolocation API enabled");
navigator.geolocation.getCurrentPosition(function(position) {
console.log(position.coords.latitude, position.coords.longitude);
});
} else {
console.log("No geolocation API");
}
});
</script>
</body>
......
......@@ -179,7 +179,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1000;
LastUpgradeCheck = 1110;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
......@@ -337,6 +337,7 @@
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
......@@ -384,6 +385,7 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
......@@ -393,6 +395,7 @@
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
......@@ -434,6 +437,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1110"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
......@@ -38,8 +36,8 @@
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
......@@ -61,8 +59,6 @@
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
......
......@@ -4,5 +4,7 @@
<dict>
<key>BuildSystemType</key>
<string>Original</string>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
import UIKit
import Flutter
import flutter_downloader
//import flutter_downloader
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
......@@ -10,9 +10,9 @@ import flutter_downloader
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
FlutterDownloaderPlugin.setPluginRegistrantCallback({(registry: FlutterPluginRegistry) in
/*FlutterDownloaderPlugin.setPluginRegistrantCallback({(registry: FlutterPluginRegistry) in
})
})*/
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
......@@ -2,48 +2,54 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key></key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Need location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need location</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutter_inappbrowser_example</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
......@@ -51,9 +57,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
</dict>
</plist>
......@@ -80,6 +80,16 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
ContentBlockerAction(ContentBlockerActionType.BLOCK)
)
]
),
AndroidInAppWebViewOptions(
databaseEnabled: true,
appCacheEnabled: true,
domStorageEnabled: true,
geolocationEnabled: true,
//blockNetworkImage: true,
),
iOSInAppWebViewOptions(
preferredContentMode: iOSInAppWebViewUserPreferredContentMode.DESKTOP
)
],
onWebViewCreated: (InAppWebViewController controller) {
......@@ -103,6 +113,9 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
onLoadStop: (InAppWebViewController controller, String url) async {
print("stopped $url");
},
onLoadError: (InAppWebViewController controller, String url, int code, String message) async {
print("error $url: $code, $message");
},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
......@@ -131,12 +144,12 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
""");
},
onDownloadStart: (InAppWebViewController controller, String url) async {
final taskId = await FlutterDownloader.enqueue(
/*final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: await _findLocalPath(),
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
);*/
},
onLoadResourceCustomScheme: (InAppWebViewController controller, String scheme, String url) async {
if (scheme == "my-special-custom-scheme") {
......@@ -151,6 +164,37 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
print("target _blank: " + url);
controller.loadUrl(url);
},
onGeolocationPermissionsShowPrompt: (InAppWebViewController controller, String origin) async {
GeolocationPermissionShowPromptResponse response;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text("Permission Geolocation API"),
content: new Text("Can we use Geolocation API?"),
actions: <Widget>[
new FlatButton(
child: new Text("Close"),
onPressed: () {
response = new GeolocationPermissionShowPromptResponse(origin, false, false);
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text("Accept"),
onPressed: () {
response = new GeolocationPermissionShowPromptResponse(origin, true, true);
Navigator.of(context).pop();
},
),
],
);
},
);
return response;
}
),
),
),
......
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
import 'package:flutter_inappbrowser_example/chrome_safari_example.screen.dart';
import 'package:flutter_inappbrowser_example/inline_example.screen.dart';
import 'package:flutter_inappbrowser_example/webview_example.screen.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:permission_handler/permission_handler.dart';
// InAppLocalhostServer localhostServer = new InAppLocalhostServer();
Future main() async {
// await localhostServer.start();
await FlutterDownloader.initialize();
// await FlutterDownloader.initialize();
await PermissionHandler().requestPermissions([PermissionGroup.locationAlways]);
runApp(new MyApp());
}
......
......@@ -76,6 +76,11 @@ class MyInappBrowser extends InAppBrowser {
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) async {
print("custom scheme: " + scheme);
}
@override
Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt(String origin) async {
print("request Geolocation permission API");
}
}
class WebviewExampleScreen extends StatefulWidget {
......
......@@ -21,6 +21,7 @@ dependencies:
cupertino_icons: ^0.1.2
flutter_downloader: ^1.3.2
path_provider: ^1.4.0
permission_handler: ^3.3.0
dev_dependencies:
flutter_test:
......
......@@ -39,7 +39,8 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
webView!.prepare()
if #available(iOS 11.0, *) {
if let contentBlockers = webView!.options?.contentBlockers {
self.webView!.configuration.userContentController.removeAllContentRuleLists()
if let contentBlockers = webView!.options?.contentBlockers, contentBlockers.count > 0 {
do {
let jsonData = try JSONSerialization.data(withJSONObject: contentBlockers, options: [])
let blockRules = String(data: jsonData, encoding: String.Encoding.utf8)
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
//
import Foundation
import WebKit
@objcMembers
public class InAppWebViewOptions: Options {
......@@ -23,6 +24,7 @@ public class InAppWebViewOptions: Options {
var horizontalScrollBarEnabled = true
var resourceCustomSchemes: [String] = []
var contentBlockers: [[String: [String : Any]]] = []
var minimumFontSize = 0;
var disallowOverScroll = false
var enableViewportScale = false
......@@ -35,6 +37,11 @@ public class InAppWebViewOptions: Options {
var allowsInlineMediaPlayback = false
var allowsPictureInPictureMediaPlayback = true
var transparentBackground = false
var applicationNameForUserAgent = "";
var isFraudulentWebsiteWarningEnabled = true;
var selectionGranularity = 0;
var dataDetectorTypes: [String] = ["NONE"]; // WKDataDetectorTypeNone
var preferredContentMode = 0;
override init(){
super.init()
......
......@@ -15,7 +15,7 @@ class ContentBlocker {
class ContentBlockerTriggerResourceType {
final String _value;
const ContentBlockerTriggerResourceType._internal(this._value);
toString() => _value;
toValue() => _value;
static const DOCUMENT = const ContentBlockerTriggerResourceType._internal('document');
static const IMAGE = const ContentBlockerTriggerResourceType._internal('image');
......@@ -30,7 +30,7 @@ class ContentBlockerTriggerResourceType {
class ContentBlockerTriggerLoadType {
final String _value;
const ContentBlockerTriggerLoadType._internal(this._value);
toString() => _value;
toValue() => _value;
static const FIRST_PARTY = const ContentBlockerTriggerLoadType._internal('first-party');
static const THIRD_PARTY = const ContentBlockerTriggerLoadType._internal('third-party');
......@@ -65,11 +65,11 @@ class ContentBlockerTrigger {
Map<String, dynamic> toMap() {
List<String> resourceTypeStringList = [];
resourceType.forEach((type) {
resourceTypeStringList.add(type.toString());
resourceTypeStringList.add(type.toValue());
});
List<String> loadTypeStringList = [];
loadType.forEach((type) {
loadTypeStringList.add(type.toString());
loadTypeStringList.add(type.toValue());
});
Map<String, dynamic> map = {
......@@ -95,7 +95,7 @@ class ContentBlockerTrigger {
class ContentBlockerActionType {
final String _value;
const ContentBlockerActionType._internal(this._value);
toString() => _value;
toValue() => _value;
static const BLOCK = const ContentBlockerActionType._internal('block');
static const CSS_DISPLAY_NONE = const ContentBlockerActionType._internal('css-display-none');
......@@ -116,7 +116,7 @@ class ContentBlockerAction {
Map<String, dynamic> toMap() {
Map<String, dynamic> map = {
"type": type.toString(),
"type": type.toValue(),
"selector": selector
};
......
......@@ -342,7 +342,7 @@ class InAppBrowser {
///Event fires when the [InAppBrowser] webview finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
///[scheme] represents the scheme of the url.
///[url] represents the url of the request.
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) async {
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) {
}
......@@ -352,6 +352,15 @@ class InAppBrowser {
}
///Event that notifies the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin.
///Note that for applications targeting Android N and later SDKs (API level > `Build.VERSION_CODES.M`) this method is only called for requests originating from secure origins such as https.
///On non-secure origins geolocation requests are automatically denied.
///[origin] represents the origin of the web content attempting to use the Geolocation API.
///**NOTE**: available only for Android.
Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt (String origin) {
}
void throwIsAlreadyOpened({String message = ''}) {
if (this.isOpened()) {
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']);
......
......@@ -128,6 +128,13 @@ class InAppWebView extends StatefulWidget {
///[url] represents the url of the link.
final onTargetBlankCallback onTargetBlank;
///Event that notifies the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin.
///Note that for applications targeting Android N and later SDKs (API level > `Build.VERSION_CODES.M`) this method is only called for requests originating from secure origins such as https.
///On non-secure origins geolocation requests are automatically denied.
///[origin] represents the origin of the web content attempting to use the Geolocation API.
///**NOTE**: available only for Android.
final onGeolocationPermissionsShowPromptCallback onGeolocationPermissionsShowPrompt;
///Initial url that will be loaded.
final String initialUrl;
///Initial asset file that will be loaded. See [InAppWebView.loadFile()] for explanation.
......@@ -166,6 +173,7 @@ class InAppWebView extends StatefulWidget {
this.onDownloadStart,
this.onLoadResourceCustomScheme,
this.onTargetBlank,
this.onGeolocationPermissionsShowPrompt,
this.gestureRecognizers,
}) : super(key: key);
......@@ -384,6 +392,13 @@ class InAppWebViewController {
else if (_inAppBrowser != null)
_inAppBrowser.onTargetBlank(url);
break;
case "onGeolocationPermissionsShowPrompt":
String origin = call.arguments["origin"];
if (_widget != null && _widget.onGeolocationPermissionsShowPrompt != null)
return (await _widget.onGeolocationPermissionsShowPrompt(this, origin)).toMap();
else if (_inAppBrowser != null)
return (await _inAppBrowser.onGeolocationPermissionsShowPrompt(origin)).toMap();
break;
case "onCallJsHandler":
String handlerName = call.arguments["handlerName"];
// decode args to json
......
import 'dart:typed_data';
import 'package:uuid/uuid.dart';
import 'package:flutter/services.dart';
import 'in_app_webview.dart' show InAppWebViewController;
......@@ -108,6 +106,28 @@ class WebHistoryItem {
WebHistoryItem(this.originalUrl, this.title, this.url, this.index, this.offset);
}
///GeolocationPermissionPromptResponse class.
///
///Class used by the host application to set the Geolocation permission state for an origin during the [onGeolocationPermissionsShowPrompt] event.
class GeolocationPermissionShowPromptResponse {
///The origin for which permissions are set.
String origin;
///Whether or not the origin should be allowed to use the Geolocation API.
bool allow;
///Whether the permission should be retained beyond the lifetime of a page currently being displayed by a WebView
bool retain;
GeolocationPermissionShowPromptResponse(this.origin, this.allow, this.retain);
Map<String, dynamic> toMap() {
return {
"origin": origin,
"allow": allow,
"retain": retain
};
}
}
typedef onWebViewCreatedCallback = void Function(InAppWebViewController controller);
typedef onWebViewLoadStartCallback = void Function(InAppWebViewController controller, String url);
typedef onWebViewLoadStopCallback = void Function(InAppWebViewController controller, String url);
......@@ -119,4 +139,5 @@ typedef onWebViewLoadResourceCallback = void Function(InAppWebViewController con
typedef onWebViewScrollChangedCallback = void Function(InAppWebViewController controller, int x, int y);
typedef onDownloadStartCallback = void Function(InAppWebViewController controller, String url);
typedef onLoadResourceCustomSchemeCallback = Future<CustomSchemeResponse> Function(InAppWebViewController controller, String scheme, String url);
typedef onTargetBlankCallback = void Function(InAppWebViewController controller, String url);
\ No newline at end of file
typedef onTargetBlankCallback = void Function(InAppWebViewController controller, String url);
typedef onGeolocationPermissionsShowPromptCallback = Future<GeolocationPermissionShowPromptResponse> Function(InAppWebViewController controller, String origin);
\ No newline at end of file
This diff is collapsed.
name: flutter_inappbrowser
description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window.
version: 1.3.0
version: 2.0.0
author: Lorenzo Pichilli <pichillilorenzo@gmail.com>
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment