Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2339)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java

Issue 2558223002: Move onReceivedError and onReceivedHttpError out of AwContentsIoThreadClientImpl (Closed)
Patch Set: add move assignment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
index b415e9516b374490dae9b32ecd65e295e8620296..a294913efc1270ead695e6a680faae6726f85b01 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
@@ -14,11 +14,14 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeUnchecked;
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.net.NetError;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
+import java.util.HashMap;
+import java.util.Map;
import javax.security.auth.x500.X500Principal;
@@ -259,10 +262,90 @@ public class AwContentsClientBridge {
}
@CalledByNative
- public void newLoginRequest(String realm, String account, String args) {
+ private void newLoginRequest(String realm, String account, String args) {
mClient.getCallbackHelper().postOnReceivedLoginRequest(realm, account, args);
}
+ @CalledByNative
+ private void onReceivedError(
+ // WebResourceRequest
+ String url, boolean isMainFrame, boolean hasUserGesture, String method,
+ String[] requestHeaderNames, String[] requestHeaderValues,
+ // WebResourceError
+ int errorCode, String description) {
+ AwContentsClient.AwWebResourceRequest request = new AwContentsClient.AwWebResourceRequest();
+ request.url = url;
+ request.isMainFrame = isMainFrame;
+ request.hasUserGesture = hasUserGesture;
+ request.method = method;
+ request.requestHeaders = new HashMap<String, String>(requestHeaderNames.length);
+ for (int i = 0; i < requestHeaderNames.length; ++i) {
+ request.requestHeaders.put(requestHeaderNames[i], requestHeaderValues[i]);
+ }
+ AwContentsClient.AwWebResourceError error = new AwContentsClient.AwWebResourceError();
+ error.errorCode = errorCode;
+ error.description = description;
+
+ String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl();
+ boolean isErrorUrl =
+ unreachableWebDataUrl != null && unreachableWebDataUrl.equals(request.url);
+
+ if (!isErrorUrl && error.errorCode != NetError.ERR_ABORTED) {
+ // NetError.ERR_ABORTED error code is generated for the following reasons:
+ // - WebView.stopLoading is called;
+ // - the navigation is intercepted by the embedder via shouldOverrideUrlLoading;
+ // - server returned 204 status (no content).
+ //
+ // Android WebView does not notify the embedder of these situations using
+ // this error code with the WebViewClient.onReceivedError callback.
+ error.errorCode = ErrorCodeConversionHelper.convertErrorCode(error.errorCode);
+ mClient.getCallbackHelper().postOnReceivedError(request, error);
+ if (request.isMainFrame) {
+ // Need to call onPageFinished after onReceivedError for backwards compatibility
+ // with the classic webview. See also AwWebContentsObserver.didFailLoad which is
+ // used when we want to send onPageFinished alone.
+ mClient.getCallbackHelper().postOnPageFinished(request.url);
+ }
+ }
+ }
+
+ @CalledByNative
+ private void onReceivedHttpError(
+ // WebResourceRequest
+ String url, boolean isMainFrame, boolean hasUserGesture, String method,
+ String[] requestHeaderNames, String[] requestHeaderValues,
+ // WebResourceResponse
+ String mimeType, String encoding, int statusCode, String reasonPhrase,
+ String[] responseHeaderNames, String[] responseHeaderValues) {
+ AwContentsClient.AwWebResourceRequest request = new AwContentsClient.AwWebResourceRequest();
+ request.url = url;
+ request.isMainFrame = isMainFrame;
+ request.hasUserGesture = hasUserGesture;
+ request.method = method;
+ request.requestHeaders = new HashMap<String, String>(requestHeaderNames.length);
+ for (int i = 0; i < requestHeaderNames.length; ++i) {
+ request.requestHeaders.put(requestHeaderNames[i], requestHeaderValues[i]);
+ }
+ Map<String, String> responseHeaders =
+ new HashMap<String, String>(responseHeaderNames.length);
+ // Note that we receive un-coalesced response header lines, thus we need to combine
+ // values for the same header.
+ for (int i = 0; i < responseHeaderNames.length; ++i) {
+ if (!responseHeaders.containsKey(responseHeaderNames[i])) {
+ responseHeaders.put(responseHeaderNames[i], responseHeaderValues[i]);
+ } else if (!responseHeaderValues[i].isEmpty()) {
+ String currentValue = responseHeaders.get(responseHeaderNames[i]);
+ if (!currentValue.isEmpty()) {
+ currentValue += ", ";
+ }
+ responseHeaders.put(responseHeaderNames[i], currentValue + responseHeaderValues[i]);
+ }
+ }
+ AwWebResourceResponse response = new AwWebResourceResponse(
+ mimeType, encoding, null, statusCode, reasonPhrase, responseHeaders);
+ mClient.getCallbackHelper().postOnReceivedHttpError(request, response);
+ }
+
@CalledByNativeUnchecked
private boolean shouldOverrideUrlLoading(
String url, boolean hasUserGesture, boolean isRedirect, boolean isMainFrame) {

Powered by Google App Engine
This is Rietveld 408576698