Commit b4544c7d authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

updated shouldInterceptFetchRequest

parent e4d8b798
This diff is collapsed.
......@@ -14,6 +14,7 @@ import android.webkit.CookieSyncManager;
import android.webkit.HttpAuthHandler;
import android.webkit.SafeBrowsingResponse;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
......@@ -182,7 +183,7 @@ public class InAppWebViewClient extends WebViewClient {
view.requestFocus();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(InAppWebView.platformReadyJS, (MethodChannel.Result) null);
webView.evaluateJavascript(InAppWebView.platformReadyJS, (ValueCallback<String>) null);
} else {
webView.loadUrl("javascript:" + InAppWebView.platformReadyJS.replaceAll("[\r\n]+", ""));
}
......
......@@ -31,6 +31,8 @@
<option value="1">option 1</option>
<option value="2">option 2</option>
</select>
<input type="file">
<input type="file" accept="image/*" capture>
<button onclick="testHistoryPush1()">History Push 1</button>
<button onclick="testHistoryPush2()">History Push 2</button>
<button onclick="testLocationHref()">Location Href</button>
......@@ -110,6 +112,20 @@
console.error("ERROR: " + error);
});
fetch("http://192.168.1.20:8082/test-ajax-post", {
method: 'POST',
body: JSON.stringify({
name: 'Lorenzo Fetch API'
}),
headers: {
'Content-Type': 'application/json'
}
}).then(function(response) {
console.log(response);
}).catch(function(error) {
console.error("ERROR: " + error);
});
/*
alert("Alert Popup");
console.log(confirm("Press a button!"));
......
......@@ -289,7 +289,7 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
print("Current highlighted: $activeMatchOrdinal, Number of matches found: $numberOfMatches, find operation completed: $isDoneCounting");
},
shouldInterceptAjaxRequest: (InAppWebViewController controller, AjaxRequest ajaxRequest) async {
print("AJAX REQUEST: ${ajaxRequest.method} - ${ajaxRequest.url}, DATA: ${ajaxRequest.data}");
//print("AJAX REQUEST: ${ajaxRequest.method} - ${ajaxRequest.url}, DATA: ${ajaxRequest.data}");
// ajaxRequest.method = "GET";
// ajaxRequest.url = "http://192.168.1.20:8082/test-download-file";
// ajaxRequest.headers = {
......@@ -299,16 +299,17 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
return null;
},
onAjaxReadyStateChange: (InAppWebViewController controller, AjaxRequest ajaxRequest) async {
print("AJAX READY STATE CHANGE: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.status}, ${ajaxRequest.readyState}, ${ajaxRequest.responseType}, ${ajaxRequest.responseText}, ${ajaxRequest.responseHeaders}");
return AjaxRequestAction.ABORT;
//print("AJAX READY STATE CHANGE: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.status}, ${ajaxRequest.readyState}, ${ajaxRequest.responseType}, ${ajaxRequest.responseText}, ${ajaxRequest.responseHeaders}");
return AjaxRequestAction.PROCEED;
},
onAjaxProgress: (InAppWebViewController controller, AjaxRequest ajaxRequest) async {
print("AJAX EVENT: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.event.type}, LOADED: ${ajaxRequest.event.loaded}, ${ajaxRequest.responseHeaders}");
return AjaxRequestAction.ABORT;
//print("AJAX EVENT: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.event.type}, LOADED: ${ajaxRequest.event.loaded}, ${ajaxRequest.responseHeaders}");
return AjaxRequestAction.PROCEED;
},
shouldInterceptFetchRequest: (InAppWebViewController controller, FetchRequest fetchRequest) async {
print("FETCH REQUEST: ${fetchRequest.method} - ${fetchRequest.url}");
print("FETCH REQUEST: ${fetchRequest.method} - ${fetchRequest.url}, headers: ${fetchRequest.headers}");
fetchRequest.action = FetchRequestAction.ABORT;
print(fetchRequest.body);
return fetchRequest;
},
onNavigationStateChange: (InAppWebViewController controller, String url) async {
......
This diff is collapsed.
......@@ -647,9 +647,9 @@ class InAppWebViewController {
String url = argMap["url"];
String method = argMap["method"];
Map<dynamic, dynamic> headers = argMap["headers"];
dynamic body = argMap["body"];
Uint8List body = Uint8List.fromList(argMap["body"].cast<int>());
String mode = argMap["mode"];
String credentials = argMap["credentials"];
FetchRequestCredential credentials = FetchRequest.createFetchRequestCredentialFromMap(argMap["credentials"]);
String cache = argMap["cache"];
String redirect = argMap["redirect"];
String referrer = argMap["referrer"];
......
......@@ -820,14 +820,83 @@ class FetchRequestAction {
static const PROCEED = const FetchRequestAction._internal(1);
}
///
class FetchRequestCredential {
String type;
FetchRequestCredential({this.type});
Map<String, dynamic> toMap() {
return {
"type": type
};
}
}
///
class FetchRequestCredentialDefault extends FetchRequestCredential {
String value;
FetchRequestCredentialDefault({type, this.value}): super(type: type);
Map<String, dynamic> toMap() {
return {
"type": type,
"value": value,
};
}
}
///
class FetchRequestFederatedCredential extends FetchRequestCredential {
dynamic id;
String name;
String protocol;
String provider;
String iconURL;
FetchRequestFederatedCredential({type, this.id, this.name, this.protocol, this.provider, this.iconURL}): super(type: type);
Map<String, dynamic> toMap() {
return {
"type": type,
"id": id,
"name": name,
"protocol": protocol,
"provider": provider,
"iconURL": iconURL
};
}
}
///
class FetchRequestPasswordCredential extends FetchRequestCredential {
dynamic id;
String name;
String password;
String iconURL;
FetchRequestPasswordCredential({type, this.id, this.name, this.password, this.iconURL}): super(type: type);
Map<String, dynamic> toMap() {
return {
"type": type,
"id": id,
"name": name,
"password": password,
"iconURL": iconURL
};
}
}
///
class FetchRequest {
String url;
String method;
Map<dynamic, dynamic> headers;
dynamic body;
Map<String, dynamic> headers;
Uint8List body;
String mode;
String credentials;
FetchRequestCredential credentials;
String cache;
String redirect;
String referrer;
......@@ -847,7 +916,7 @@ class FetchRequest {
"headers": headers,
"body": body,
"mode": mode,
"credentials": credentials,
"credentials": credentials?.toMap(),
"cache": cache,
"redirect": redirect,
"referrer": referrer,
......@@ -861,4 +930,19 @@ class FetchRequest {
Map<String, dynamic> toJson() {
return this.toMap();
}
static FetchRequestCredential createFetchRequestCredentialFromMap(credentialsMap) {
if (credentialsMap != null) {
if (credentialsMap["type"] == "default") {
return FetchRequestCredentialDefault(type: credentialsMap["type"], value: credentialsMap["value"]);
} else if (credentialsMap["type"] == "federated") {
return FetchRequestFederatedCredential(type: credentialsMap["type"], id: credentialsMap["id"], name: credentialsMap["name"],
protocol: credentialsMap["protocol"], provider: credentialsMap["provider"], iconURL: credentialsMap["iconURL"]);
} else if (credentialsMap["type"] == "password") {
return FetchRequestPasswordCredential(type: credentialsMap["type"], id: credentialsMap["id"], name: credentialsMap["name"],
password: credentialsMap["password"], iconURL: credentialsMap["iconURL"]);
}
}
return null;
}
}
\ No newline at end of file
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