- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / java / src / org / chromium / android_webview / ErrorCodeConversionHelper.java
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.android_webview;
6
7 import org.chromium.net.NetError;
8
9 /**
10  * This is a helper class to map native error code about loading a page to Android specific ones.
11  */
12 public abstract class ErrorCodeConversionHelper {
13     // Success
14     public static final int ERROR_OK = 0;
15     // Generic error
16     public static final int ERROR_UNKNOWN = -1;
17     // Server or proxy hostname lookup failed
18     public static final int ERROR_HOST_LOOKUP = -2;
19     // Unsupported authentication scheme (not basic or digest)
20     public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
21     // User authentication failed on server
22     public static final int ERROR_AUTHENTICATION = -4;
23     // User authentication failed on proxy
24     public static final int ERROR_PROXY_AUTHENTICATION = -5;
25     // Failed to connect to the server
26     public static final int ERROR_CONNECT = -6;
27     // Failed to read or write to the server
28     public static final int ERROR_IO = -7;
29     // Connection timed out
30     public static final int ERROR_TIMEOUT = -8;
31     // Too many redirects
32     public static final int ERROR_REDIRECT_LOOP = -9;
33     // Unsupported URI scheme
34     public static final int ERROR_UNSUPPORTED_SCHEME = -10;
35     // Failed to perform SSL handshake
36     public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
37     // Malformed URL
38     public static final int ERROR_BAD_URL = -12;
39     // Generic file error
40     public static final int ERROR_FILE = -13;
41     // File not found
42     public static final int ERROR_FILE_NOT_FOUND = -14;
43     // Too many requests during this load
44     public static final int ERROR_TOO_MANY_REQUESTS = -15;
45
46     static int convertErrorCode(int netError) {
47         // Note: many NetError.Error constants don't have an obvious mapping.
48         // These will be handled by the default case, ERROR_UNKNOWN.
49         switch (netError) {
50             case NetError.ERR_UNSUPPORTED_AUTH_SCHEME:
51               return ERROR_UNSUPPORTED_AUTH_SCHEME;
52
53             case NetError.ERR_INVALID_AUTH_CREDENTIALS:
54             case NetError.ERR_MISSING_AUTH_CREDENTIALS:
55             case NetError.ERR_MISCONFIGURED_AUTH_ENVIRONMENT:
56                 return ERROR_AUTHENTICATION;
57
58             case NetError.ERR_TOO_MANY_REDIRECTS:
59                 return ERROR_REDIRECT_LOOP;
60
61             case NetError.ERR_UPLOAD_FILE_CHANGED:
62                 return ERROR_FILE_NOT_FOUND;
63
64             case NetError.ERR_INVALID_URL:
65                 return ERROR_BAD_URL;
66
67             case NetError.ERR_DISALLOWED_URL_SCHEME:
68             case NetError.ERR_UNKNOWN_URL_SCHEME:
69                 return ERROR_UNSUPPORTED_SCHEME;
70
71             case NetError.ERR_IO_PENDING:
72             case NetError.ERR_NETWORK_IO_SUSPENDED:
73                 return ERROR_IO;
74
75             case NetError.ERR_CONNECTION_TIMED_OUT:
76             case NetError.ERR_TIMED_OUT:
77                 return ERROR_TIMEOUT;
78
79             case NetError.ERR_FILE_TOO_BIG:
80                 return ERROR_FILE;
81
82             case NetError.ERR_HOST_RESOLVER_QUEUE_TOO_LARGE:
83             case NetError.ERR_INSUFFICIENT_RESOURCES:
84             case NetError.ERR_OUT_OF_MEMORY:
85                 return ERROR_TOO_MANY_REQUESTS;
86
87             case NetError.ERR_CONNECTION_CLOSED:
88             case NetError.ERR_CONNECTION_RESET:
89             case NetError.ERR_CONNECTION_REFUSED:
90             case NetError.ERR_CONNECTION_ABORTED:
91             case NetError.ERR_CONNECTION_FAILED:
92             case NetError.ERR_SOCKET_NOT_CONNECTED:
93                 return ERROR_CONNECT;
94
95             case NetError.ERR_INTERNET_DISCONNECTED:
96             case NetError.ERR_ADDRESS_INVALID:
97             case NetError.ERR_ADDRESS_UNREACHABLE:
98             case NetError.ERR_NAME_NOT_RESOLVED:
99             case NetError.ERR_NAME_RESOLUTION_FAILED:
100                 return ERROR_HOST_LOOKUP;
101
102             case NetError.ERR_SSL_PROTOCOL_ERROR:
103             case NetError.ERR_SSL_CLIENT_AUTH_CERT_NEEDED:
104             case NetError.ERR_TUNNEL_CONNECTION_FAILED:
105             case NetError.ERR_NO_SSL_VERSIONS_ENABLED:
106             case NetError.ERR_SSL_VERSION_OR_CIPHER_MISMATCH:
107             case NetError.ERR_SSL_RENEGOTIATION_REQUESTED:
108             case NetError.ERR_CERT_ERROR_IN_SSL_RENEGOTIATION:
109             case NetError.ERR_BAD_SSL_CLIENT_AUTH_CERT:
110             case NetError.ERR_SSL_NO_RENEGOTIATION:
111             case NetError.ERR_SSL_DECOMPRESSION_FAILURE_ALERT:
112             case NetError.ERR_SSL_BAD_RECORD_MAC_ALERT:
113             case NetError.ERR_SSL_UNSAFE_NEGOTIATION:
114             case NetError.ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
115             case NetError.ERR_SSL_CLIENT_AUTH_PRIVATE_KEY_ACCESS_DENIED:
116             case NetError.ERR_SSL_CLIENT_AUTH_CERT_NO_PRIVATE_KEY:
117                 return ERROR_FAILED_SSL_HANDSHAKE;
118
119             case NetError.ERR_PROXY_AUTH_UNSUPPORTED:
120             case NetError.ERR_PROXY_AUTH_REQUESTED:
121             case NetError.ERR_PROXY_CONNECTION_FAILED:
122             case NetError.ERR_UNEXPECTED_PROXY_AUTH:
123                 return ERROR_PROXY_AUTHENTICATION;
124
125             // The certificate errors are handled by onReceivedSslError
126             // and don't need to be reported here.
127             case NetError.ERR_CERT_COMMON_NAME_INVALID:
128             case NetError.ERR_CERT_DATE_INVALID:
129             case NetError.ERR_CERT_AUTHORITY_INVALID:
130             case NetError.ERR_CERT_CONTAINS_ERRORS:
131             case NetError.ERR_CERT_NO_REVOCATION_MECHANISM:
132             case NetError.ERR_CERT_UNABLE_TO_CHECK_REVOCATION:
133             case NetError.ERR_CERT_REVOKED:
134             case NetError.ERR_CERT_INVALID:
135             case NetError.ERR_CERT_WEAK_SIGNATURE_ALGORITHM:
136             case NetError.ERR_CERT_NON_UNIQUE_NAME:
137                 return ERROR_OK;
138
139             default:
140                 return ERROR_UNKNOWN;
141         }
142     }
143 }