Commit 153ab602 authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

Updated javascript popups events

parent ab0a5cc5
This diff is collapsed.
def PLUGIN = "flutter_inappbrowser";
def ANDROIDX_WARNING = "flutterPluginsAndroidXWarning";
gradle.buildFinished { buildResult ->
if (buildResult.failure && !rootProject.ext.has(ANDROIDX_WARNING)) {
println ' *********************************************************'
println 'WARNING: This version of ' + PLUGIN + ' will break your Android build if it or its dependencies aren\'t compatible with AndroidX.'
println ' See https://goo.gl/CP92wY for more information on the problem and how to fix it.'
println ' This warning prints for all Android build failures. The real root cause of the error may be unrelated.'
println ' *********************************************************'
rootProject.ext.set(ANDROIDX_WARNING, true);
}
}
group 'com.pichillilorenzo.flutter_inappbrowser'
version '1.0-SNAPSHOT'
......
......@@ -55,13 +55,14 @@
});
});
$(document).ready(function() {
/*
alert("Alert Popup");
console.log(confirm("Press a button!"));
console.log(prompt("Please enter your name", "Harry Potter"));
console.log(prompt("Please enter your name", "Lorenzo"));
*/
console.log("jQuery ready");
/*
/*
if ("geolocation" in navigator) {
console.log("Geolocation API enabled");
navigator.geolocation.getCurrentPosition(function(position) {
......@@ -69,7 +70,8 @@
});
} else {
console.log("No geolocation API");
}*/
}
*/
});
</script>
</body>
......
......@@ -198,90 +198,16 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
return response;
},
onJsAlert: (InAppWebViewController controller, String message) async {
JsAlertResponseAction action;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text("Ok"),
onPressed: () {
action = JsAlertResponseAction.CONFIRM;
Navigator.of(context).pop();
},
),
],
);
},
);
JsAlertResponseAction action = await createAlertDialog(context, message);
return new JsAlertResponse(handledByClient: true, action: action);
},
onJsConfirm: (InAppWebViewController controller, String message) async {
JsConfirmResponseAction action;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
action = JsConfirmResponseAction.CANCEL;
Navigator.of(context).pop();
},
),
FlatButton(
child: Text("Ok"),
onPressed: () {
action = JsConfirmResponseAction.CONFIRM;
Navigator.of(context).pop();
},
),
],
);
},
);
JsConfirmResponseAction action = await createConfirmDialog(context, message);
return new JsConfirmResponse(handledByClient: true, action: action);
},
onJsPrompt: (InAppWebViewController controller, String message, String defaultValue) async {
JsPromptResponseAction action;
_textFieldController.text = defaultValue;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(message),
content: TextField(
controller: _textFieldController,
),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
action = JsPromptResponseAction.CANCEL;
Navigator.of(context).pop();
},
),
FlatButton(
child: Text("Ok"),
onPressed: () {
action = JsPromptResponseAction.CONFIRM;
Navigator.of(context).pop();
},
),
],
);
},
);
JsPromptResponseAction action = await createPromptDialog(context, message);
return new JsPromptResponse(handledByClient: true, action: action, value: _textFieldController.text);
},
),
......@@ -319,6 +245,95 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
]));
}
Future<JsAlertResponseAction> createAlertDialog(BuildContext context, String message) async {
JsAlertResponseAction action;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text("Ok"),
onPressed: () {
action = JsAlertResponseAction.CONFIRM;
Navigator.of(context).pop();
},
),
],
);
},
);
return action;
}
Future<JsConfirmResponseAction> createConfirmDialog(BuildContext context, String message) async {
JsConfirmResponseAction action;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
action = JsConfirmResponseAction.CANCEL;
Navigator.of(context).pop();
},
),
FlatButton(
child: Text("Ok"),
onPressed: () {
action = JsConfirmResponseAction.CONFIRM;
Navigator.of(context).pop();
},
),
],
);
},
);
return action;
}
Future<JsPromptResponseAction> createPromptDialog(BuildContext context, String message) async {
JsPromptResponseAction action;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(message),
content: TextField(
controller: _textFieldController,
),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
action = JsPromptResponseAction.CANCEL;
Navigator.of(context).pop();
},
),
FlatButton(
child: Text("Ok"),
onPressed: () {
action = JsPromptResponseAction.CONFIRM;
Navigator.of(context).pop();
},
),
],
);
},
);
return action;
}
Future<String> _findLocalPath() async {
final directory = Platform.isAndroid
? await getExternalStorageDirectory()
......
......@@ -81,10 +81,27 @@ class MyInappBrowser extends InAppBrowser {
Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt(String origin) async {
print("request Geolocation permission API");
}
@override
Future<JsAlertResponse> onJsAlert(String message) async {
return new JsAlertResponse(handledByClient: false, message: "coma iam");
}
@override
Future<JsConfirmResponse> onJsConfirm(String message) {
}
@override
Future<JsPromptResponse> onJsPrompt(String message, String defaultValue) {
}
}
class WebviewExampleScreen extends StatefulWidget {
final MyInappBrowser browser = new MyInappBrowser();
static BuildContext context = null;
@override
_WebviewExampleScreenState createState() => new _WebviewExampleScreenState();
}
......@@ -97,17 +114,19 @@ class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
@override
Widget build(BuildContext context) {
WebviewExampleScreen.context = context;
return new Center(
child: new RaisedButton(
onPressed: () {
widget.browser.open(
url: "https://www.google.com/",
options: [
InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
useOnLoadResource: true,
)
]
widget.browser.openFile(
"assets/index.html",
//url: "https://www.google.com/",
options: [
InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
useOnLoadResource: true,
)
]
);
},
child: Text("Open Webview Browser")),
......
......@@ -44,7 +44,6 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
do {
let jsonData = try JSONSerialization.data(withJSONObject: contentBlockers, options: [])
let blockRules = String(data: jsonData, encoding: String.Encoding.utf8)
print(blockRules)
WKContentRuleListStore.default().compileContentRuleList(
forIdentifier: "ContentBlockingRules",
encodedContentRuleList: blockRules) { (contentRuleList, error) in
......
This diff is collapsed.
......@@ -18,6 +18,7 @@ A new Flutter plugin.
s.dependency 'Flutter'
s.ios.deployment_target = '8.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
s.swift_version = '5.0'
end
......@@ -358,6 +358,17 @@ 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) {
}
///Event fires when javascript calls the `alert()` method to display an alert dialog.
///If [JsAlertResponse.handledByClient] is `true`, the webview will assume that the client will handle the dialog.
///
......@@ -383,17 +394,6 @@ 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.']);
......
......@@ -428,31 +428,31 @@ class InAppWebViewController {
case "onGeolocationPermissionsShowPrompt":
String origin = call.arguments["origin"];
if (_widget != null && _widget.onGeolocationPermissionsShowPrompt != null)
return (await _widget.onGeolocationPermissionsShowPrompt(this, origin)).toMap();
return (await _widget.onGeolocationPermissionsShowPrompt(this, origin))?.toMap();
else if (_inAppBrowser != null)
return (await _inAppBrowser.onGeolocationPermissionsShowPrompt(origin)).toMap();
return (await _inAppBrowser.onGeolocationPermissionsShowPrompt(origin))?.toMap();
break;
case "onJsAlert":
String message = call.arguments["message"];
if (_widget != null && _widget.onJsAlert != null)
return (await _widget.onJsAlert(this, message)).toMap();
return (await _widget.onJsAlert(this, message))?.toMap();
else if (_inAppBrowser != null)
return (await _inAppBrowser.onJsAlert(message)).toMap();
return (await _inAppBrowser.onJsAlert(message))?.toMap();
break;
case "onJsConfirm":
String message = call.arguments["message"];
if (_widget != null && _widget.onJsConfirm != null)
return (await _widget.onJsConfirm(this, message)).toMap();
return (await _widget.onJsConfirm(this, message))?.toMap();
else if (_inAppBrowser != null)
return (await _inAppBrowser.onJsConfirm(message)).toMap();
return (await _inAppBrowser.onJsConfirm(message))?.toMap();
break;
case "onJsPrompt":
String message = call.arguments["message"];
String defaultValue = call.arguments["defaultValue"];
if (_widget != null && _widget.onJsPrompt != null)
return (await _widget.onJsPrompt(this, message, defaultValue)).toMap();
return (await _widget.onJsPrompt(this, message, defaultValue))?.toMap();
else if (_inAppBrowser != null)
return (await _inAppBrowser.onJsPrompt(message, defaultValue)).toMap();
return (await _inAppBrowser.onJsPrompt(message, defaultValue))?.toMap();
break;
case "onCallJsHandler":
String handlerName = call.arguments["handlerName"];
......
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