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' group 'com.pichillilorenzo.flutter_inappbrowser'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
......
...@@ -55,13 +55,14 @@ ...@@ -55,13 +55,14 @@
}); });
}); });
$(document).ready(function() { $(document).ready(function() {
/*
alert("Alert Popup"); alert("Alert Popup");
console.log(confirm("Press a button!")); 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"); console.log("jQuery ready");
/* /*
if ("geolocation" in navigator) { if ("geolocation" in navigator) {
console.log("Geolocation API enabled"); console.log("Geolocation API enabled");
navigator.geolocation.getCurrentPosition(function(position) { navigator.geolocation.getCurrentPosition(function(position) {
...@@ -69,7 +70,8 @@ ...@@ -69,7 +70,8 @@
}); });
} else { } else {
console.log("No geolocation API"); console.log("No geolocation API");
}*/ }
*/
}); });
</script> </script>
</body> </body>
......
...@@ -198,90 +198,16 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> { ...@@ -198,90 +198,16 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
return response; return response;
}, },
onJsAlert: (InAppWebViewController controller, String message) async { onJsAlert: (InAppWebViewController controller, String message) async {
JsAlertResponseAction action; JsAlertResponseAction action = await createAlertDialog(context, message);
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 new JsAlertResponse(handledByClient: true, action: action); return new JsAlertResponse(handledByClient: true, action: action);
}, },
onJsConfirm: (InAppWebViewController controller, String message) async { onJsConfirm: (InAppWebViewController controller, String message) async {
JsConfirmResponseAction action; JsConfirmResponseAction action = await createConfirmDialog(context, message);
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 new JsConfirmResponse(handledByClient: true, action: action); return new JsConfirmResponse(handledByClient: true, action: action);
}, },
onJsPrompt: (InAppWebViewController controller, String message, String defaultValue) async { onJsPrompt: (InAppWebViewController controller, String message, String defaultValue) async {
JsPromptResponseAction action;
_textFieldController.text = defaultValue; _textFieldController.text = defaultValue;
JsPromptResponseAction action = await createPromptDialog(context, message);
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 new JsPromptResponse(handledByClient: true, action: action, value: _textFieldController.text); return new JsPromptResponse(handledByClient: true, action: action, value: _textFieldController.text);
}, },
), ),
...@@ -319,6 +245,95 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> { ...@@ -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 { Future<String> _findLocalPath() async {
final directory = Platform.isAndroid final directory = Platform.isAndroid
? await getExternalStorageDirectory() ? await getExternalStorageDirectory()
......
...@@ -81,10 +81,27 @@ class MyInappBrowser extends InAppBrowser { ...@@ -81,10 +81,27 @@ class MyInappBrowser extends InAppBrowser {
Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt(String origin) async { Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt(String origin) async {
print("request Geolocation permission API"); 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 { class WebviewExampleScreen extends StatefulWidget {
final MyInappBrowser browser = new MyInappBrowser(); final MyInappBrowser browser = new MyInappBrowser();
static BuildContext context = null;
@override @override
_WebviewExampleScreenState createState() => new _WebviewExampleScreenState(); _WebviewExampleScreenState createState() => new _WebviewExampleScreenState();
} }
...@@ -97,17 +114,19 @@ class _WebviewExampleScreenState extends State<WebviewExampleScreen> { ...@@ -97,17 +114,19 @@ class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
WebviewExampleScreen.context = context;
return new Center( return new Center(
child: new RaisedButton( child: new RaisedButton(
onPressed: () { onPressed: () {
widget.browser.open( widget.browser.openFile(
url: "https://www.google.com/", "assets/index.html",
options: [ //url: "https://www.google.com/",
InAppWebViewOptions( options: [
useShouldOverrideUrlLoading: true, InAppWebViewOptions(
useOnLoadResource: true, useShouldOverrideUrlLoading: true,
) useOnLoadResource: true,
] )
]
); );
}, },
child: Text("Open Webview Browser")), child: Text("Open Webview Browser")),
......
...@@ -44,7 +44,6 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView { ...@@ -44,7 +44,6 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
do { do {
let jsonData = try JSONSerialization.data(withJSONObject: contentBlockers, options: []) let jsonData = try JSONSerialization.data(withJSONObject: contentBlockers, options: [])
let blockRules = String(data: jsonData, encoding: String.Encoding.utf8) let blockRules = String(data: jsonData, encoding: String.Encoding.utf8)
print(blockRules)
WKContentRuleListStore.default().compileContentRuleList( WKContentRuleListStore.default().compileContentRuleList(
forIdentifier: "ContentBlockingRules", forIdentifier: "ContentBlockingRules",
encodedContentRuleList: blockRules) { (contentRuleList, error) in encodedContentRuleList: blockRules) { (contentRuleList, error) in
......
This diff is collapsed.
...@@ -18,6 +18,7 @@ A new Flutter plugin. ...@@ -18,6 +18,7 @@ A new Flutter plugin.
s.dependency 'Flutter' s.dependency 'Flutter'
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
s.swift_version = '5.0' s.swift_version = '5.0'
end end
...@@ -358,6 +358,17 @@ class InAppBrowser { ...@@ -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. ///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. ///If [JsAlertResponse.handledByClient] is `true`, the webview will assume that the client will handle the dialog.
/// ///
...@@ -383,17 +394,6 @@ class InAppBrowser { ...@@ -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 = ''}) { void throwIsAlreadyOpened({String message = ''}) {
if (this.isOpened()) { if (this.isOpened()) {
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']); throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']);
......
...@@ -428,31 +428,31 @@ class InAppWebViewController { ...@@ -428,31 +428,31 @@ class InAppWebViewController {
case "onGeolocationPermissionsShowPrompt": case "onGeolocationPermissionsShowPrompt":
String origin = call.arguments["origin"]; String origin = call.arguments["origin"];
if (_widget != null && _widget.onGeolocationPermissionsShowPrompt != null) if (_widget != null && _widget.onGeolocationPermissionsShowPrompt != null)
return (await _widget.onGeolocationPermissionsShowPrompt(this, origin)).toMap(); return (await _widget.onGeolocationPermissionsShowPrompt(this, origin))?.toMap();
else if (_inAppBrowser != null) else if (_inAppBrowser != null)
return (await _inAppBrowser.onGeolocationPermissionsShowPrompt(origin)).toMap(); return (await _inAppBrowser.onGeolocationPermissionsShowPrompt(origin))?.toMap();
break; break;
case "onJsAlert": case "onJsAlert":
String message = call.arguments["message"]; String message = call.arguments["message"];
if (_widget != null && _widget.onJsAlert != null) if (_widget != null && _widget.onJsAlert != null)
return (await _widget.onJsAlert(this, message)).toMap(); return (await _widget.onJsAlert(this, message))?.toMap();
else if (_inAppBrowser != null) else if (_inAppBrowser != null)
return (await _inAppBrowser.onJsAlert(message)).toMap(); return (await _inAppBrowser.onJsAlert(message))?.toMap();
break; break;
case "onJsConfirm": case "onJsConfirm":
String message = call.arguments["message"]; String message = call.arguments["message"];
if (_widget != null && _widget.onJsConfirm != null) if (_widget != null && _widget.onJsConfirm != null)
return (await _widget.onJsConfirm(this, message)).toMap(); return (await _widget.onJsConfirm(this, message))?.toMap();
else if (_inAppBrowser != null) else if (_inAppBrowser != null)
return (await _inAppBrowser.onJsConfirm(message)).toMap(); return (await _inAppBrowser.onJsConfirm(message))?.toMap();
break; break;
case "onJsPrompt": case "onJsPrompt":
String message = call.arguments["message"]; String message = call.arguments["message"];
String defaultValue = call.arguments["defaultValue"]; String defaultValue = call.arguments["defaultValue"];
if (_widget != null && _widget.onJsPrompt != null) 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) else if (_inAppBrowser != null)
return (await _inAppBrowser.onJsPrompt(message, defaultValue)).toMap(); return (await _inAppBrowser.onJsPrompt(message, defaultValue))?.toMap();
break; break;
case "onCallJsHandler": case "onCallJsHandler":
String handlerName = call.arguments["handlerName"]; 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