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