summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/net/http/Connection.java3
-rw-r--r--core/java/android/net/http/ErrorStrings.java99
-rw-r--r--core/java/android/net/http/EventHandler.java19
-rw-r--r--core/java/android/webkit/BrowserFrame.java11
-rw-r--r--core/java/android/webkit/FrameLoader.java9
5 files changed, 112 insertions, 29 deletions
diff --git a/core/java/android/net/http/Connection.java b/core/java/android/net/http/Connection.java
index 43fb5f17df1b..95cecd2c9b84 100644
--- a/core/java/android/net/http/Connection.java
+++ b/core/java/android/net/http/Connection.java
@@ -437,8 +437,7 @@ abstract class Connection {
ret = false;
String error;
if (errorId < 0) {
- error = mContext.getText(
- EventHandler.errorStringResources[-errorId]).toString();
+ error = ErrorStrings.getString(errorId, mContext);
} else {
Throwable cause = e.getCause();
error = cause != null ? cause.toString() : e.getMessage();
diff --git a/core/java/android/net/http/ErrorStrings.java b/core/java/android/net/http/ErrorStrings.java
new file mode 100644
index 000000000000..8383681561dd
--- /dev/null
+++ b/core/java/android/net/http/ErrorStrings.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.http;
+
+import android.content.Context;
+import android.util.Log;
+
+/**
+ * Localized strings for the error codes defined in EventHandler.
+ *
+ * {@hide}
+ */
+public class ErrorStrings {
+ private ErrorStrings() { /* Utility class, don't instantiate. */ }
+
+ private static final String LOGTAG = "Http";
+
+ /**
+ * Get the localized error message resource for the given error code.
+ * If the code is unknown, we'll return a generic error message.
+ */
+ public static String getString(int errorCode, Context context) {
+ return context.getText(getResource(errorCode)).toString();
+ }
+
+ /**
+ * Get the localized error message resource for the given error code.
+ * If the code is unknown, we'll return a generic error message.
+ */
+ public static int getResource(int errorCode) {
+ switch(errorCode) {
+ case EventHandler.OK:
+ return com.android.internal.R.string.httpErrorOk;
+
+ case EventHandler.ERROR:
+ return com.android.internal.R.string.httpError;
+
+ case EventHandler.ERROR_LOOKUP:
+ return com.android.internal.R.string.httpErrorLookup;
+
+ case EventHandler.ERROR_UNSUPPORTED_AUTH_SCHEME:
+ return com.android.internal.R.string.httpErrorUnsupportedAuthScheme;
+
+ case EventHandler.ERROR_AUTH:
+ return com.android.internal.R.string.httpErrorAuth;
+
+ case EventHandler.ERROR_PROXYAUTH:
+ return com.android.internal.R.string.httpErrorProxyAuth;
+
+ case EventHandler.ERROR_CONNECT:
+ return com.android.internal.R.string.httpErrorConnect;
+
+ case EventHandler.ERROR_IO:
+ return com.android.internal.R.string.httpErrorIO;
+
+ case EventHandler.ERROR_TIMEOUT:
+ return com.android.internal.R.string.httpErrorTimeout;
+
+ case EventHandler.ERROR_REDIRECT_LOOP:
+ return com.android.internal.R.string.httpErrorRedirectLoop;
+
+ case EventHandler.ERROR_UNSUPPORTED_SCHEME:
+ return com.android.internal.R.string.httpErrorUnsupportedScheme;
+
+ case EventHandler.ERROR_FAILED_SSL_HANDSHAKE:
+ return com.android.internal.R.string.httpErrorFailedSslHandshake;
+
+ case EventHandler.ERROR_BAD_URL:
+ return com.android.internal.R.string.httpErrorBadUrl;
+
+ case EventHandler.FILE_ERROR:
+ return com.android.internal.R.string.httpErrorFile;
+
+ case EventHandler.FILE_NOT_FOUND_ERROR:
+ return com.android.internal.R.string.httpErrorFileNotFound;
+
+ case EventHandler.TOO_MANY_REQUESTS_ERROR:
+ return com.android.internal.R.string.httpErrorTooManyRequests;
+
+ default:
+ Log.w(LOGTAG, "Using generic message for unknown error code: " + errorCode);
+ return com.android.internal.R.string.httpError;
+ }
+ }
+}
diff --git a/core/java/android/net/http/EventHandler.java b/core/java/android/net/http/EventHandler.java
index 2aa05ebd606a..3fd471d8e3af 100644
--- a/core/java/android/net/http/EventHandler.java
+++ b/core/java/android/net/http/EventHandler.java
@@ -68,25 +68,6 @@ public interface EventHandler {
/** Too many requests queued */
public static final int TOO_MANY_REQUESTS_ERROR = -15;
- final static int[] errorStringResources = {
- com.android.internal.R.string.httpErrorOk,
- com.android.internal.R.string.httpError,
- com.android.internal.R.string.httpErrorLookup,
- com.android.internal.R.string.httpErrorUnsupportedAuthScheme,
- com.android.internal.R.string.httpErrorAuth,
- com.android.internal.R.string.httpErrorProxyAuth,
- com.android.internal.R.string.httpErrorConnect,
- com.android.internal.R.string.httpErrorIO,
- com.android.internal.R.string.httpErrorTimeout,
- com.android.internal.R.string.httpErrorRedirectLoop,
- com.android.internal.R.string.httpErrorUnsupportedScheme,
- com.android.internal.R.string.httpErrorFailedSslHandshake,
- com.android.internal.R.string.httpErrorBadUrl,
- com.android.internal.R.string.httpErrorFile,
- com.android.internal.R.string.httpErrorFileNotFound,
- com.android.internal.R.string.httpErrorTooManyRequests
- };
-
/**
* Called after status line has been sucessfully processed.
* @param major_version HTTP version advertised by server. major
diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java
index cce7914ccb85..ed5663e0f610 100644
--- a/core/java/android/webkit/BrowserFrame.java
+++ b/core/java/android/webkit/BrowserFrame.java
@@ -26,6 +26,7 @@ import android.graphics.Bitmap;
import android.net.ParseException;
import android.net.Uri;
import android.net.WebAddress;
+import android.net.http.ErrorStrings;
import android.net.http.SslCertificate;
import android.os.Handler;
import android.os.Message;
@@ -323,16 +324,20 @@ class BrowserFrame extends Handler {
* native callback
* Report an error to an activity.
* @param errorCode The HTTP error code.
- * @param description A String description.
+ * @param description Optional human-readable description. If no description
+ * is given, we'll use a standard localized error message.
+ * @param failingUrl The URL that was being loaded when the error occurred.
* TODO: Report all errors including resource errors but include some kind
* of domain identifier. Change errorCode to an enum for a cleaner
* interface.
*/
- private void reportError(final int errorCode, final String description,
- final String failingUrl) {
+ private void reportError(int errorCode, String description, String failingUrl) {
// As this is called for the main resource and loading will be stopped
// after, reset the state variables.
resetLoadingStates();
+ if (description == null || description.isEmpty()) {
+ description = ErrorStrings.getString(errorCode, mContext);
+ }
mCallbackProxy.onReceivedError(errorCode, description, failingUrl);
}
diff --git a/core/java/android/webkit/FrameLoader.java b/core/java/android/webkit/FrameLoader.java
index 021b53ca9ff3..0f127d561013 100644
--- a/core/java/android/webkit/FrameLoader.java
+++ b/core/java/android/webkit/FrameLoader.java
@@ -16,6 +16,7 @@
package android.webkit;
+import android.net.http.ErrorStrings;
import android.net.http.EventHandler;
import android.net.http.RequestHandle;
import android.os.Build;
@@ -247,8 +248,7 @@ class FrameLoader {
error = EventHandler.ERROR_BAD_URL;
}
if (!ret) {
- mListener.error(error, mListener.getContext().getText(
- EventHandler.errorStringResources[Math.abs(error)]).toString());
+ mListener.error(error, ErrorStrings.getString(error, mListener.getContext()));
return false;
}
return true;
@@ -303,9 +303,8 @@ class FrameLoader {
// it has gone.
// Generate a file not found error
int err = EventHandler.FILE_NOT_FOUND_ERROR;
- mListener.error(err, mListener.getContext().getText(
- EventHandler.errorStringResources[Math.abs(err)])
- .toString());
+ mListener.error(err,
+ ErrorStrings.getString(err, mListener.getContext()));
}
return true;
}