summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/webkit/WebResourceError.java11
-rw-r--r--core/java/android/webkit/WebResourceResponse.java59
-rw-r--r--core/java/android/webkit/WebResourceResponseBase.java48
-rw-r--r--core/java/android/webkit/WebViewClient.java13
4 files changed, 70 insertions, 61 deletions
diff --git a/core/java/android/webkit/WebResourceError.java b/core/java/android/webkit/WebResourceError.java
index 080d1740562b..11f1b6f17566 100644
--- a/core/java/android/webkit/WebResourceError.java
+++ b/core/java/android/webkit/WebResourceError.java
@@ -16,6 +16,8 @@
package android.webkit;
+import android.annotation.SystemApi;
+
/**
* Encapsulates information about errors occured during loading of web resources. See
* {@link WebViewClient#onReceivedError(WebView, WebResourceRequest, WebResourceError) WebViewClient.onReceivedError(WebView, WebResourceRequest, WebResourceError)}
@@ -35,5 +37,12 @@ public abstract class WebResourceError {
*
* @return The description of the error
*/
- public abstract String getDescription();
+ public abstract CharSequence getDescription();
+
+ /**
+ * This class can not be subclassed by applications.
+ * @hide
+ */
+ @SystemApi
+ public WebResourceError() {}
}
diff --git a/core/java/android/webkit/WebResourceResponse.java b/core/java/android/webkit/WebResourceResponse.java
index a42aaa78deb8..3a925c8dc826 100644
--- a/core/java/android/webkit/WebResourceResponse.java
+++ b/core/java/android/webkit/WebResourceResponse.java
@@ -20,12 +20,15 @@ import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Map;
+import android.annotation.SystemApi;
+
/**
* Encapsulates a resource response. Applications can return an instance of this
* class from {@link WebViewClient#shouldInterceptRequest} to provide a custom
* response when the WebView requests a particular resource.
*/
public class WebResourceResponse extends WebResourceResponseBase {
+ private boolean mImmutable;
private String mMimeType;
private String mEncoding;
private int mStatusCode;
@@ -80,13 +83,15 @@ public class WebResourceResponse extends WebResourceResponseBase {
* @param mimeType The resource response's MIME type
*/
public void setMimeType(String mimeType) {
+ checkImmutable();
mMimeType = mimeType;
}
/**
- * {@inheritDoc}
+ * Gets the resource response's MIME type.
+ *
+ * @return The resource response's MIME type
*/
- @Override
public String getMimeType() {
return mMimeType;
}
@@ -98,13 +103,15 @@ public class WebResourceResponse extends WebResourceResponseBase {
* @param encoding The resource response's encoding
*/
public void setEncoding(String encoding) {
+ checkImmutable();
mEncoding = encoding;
}
/**
- * {@inheritDoc}
+ * Gets the resource response's encoding.
+ *
+ * @return The resource response's encoding
*/
- @Override
public String getEncoding() {
return mEncoding;
}
@@ -118,6 +125,7 @@ public class WebResourceResponse extends WebResourceResponseBase {
* and not empty.
*/
public void setStatusCodeAndReasonPhrase(int statusCode, String reasonPhrase) {
+ checkImmutable();
if (statusCode < 100)
throw new IllegalArgumentException("statusCode can't be less than 100.");
if (statusCode > 599)
@@ -140,17 +148,19 @@ public class WebResourceResponse extends WebResourceResponseBase {
}
/**
- * {@inheritDoc}
+ * Gets the resource response's status code.
+ *
+ * @return The resource response's status code.
*/
- @Override
public int getStatusCode() {
return mStatusCode;
}
/**
- * {@inheritDoc}
+ * Gets the description of the resource response's status code.
+ *
+ * @return The description of the resource response's status code.
*/
- @Override
public String getReasonPhrase() {
return mReasonPhrase;
}
@@ -161,13 +171,15 @@ public class WebResourceResponse extends WebResourceResponseBase {
* @param headers Mapping of header name -> header value.
*/
public void setResponseHeaders(Map<String, String> headers) {
+ checkImmutable();
mResponseHeaders = headers;
}
/**
- * {@inheritDoc}
+ * Gets the headers for the resource response.
+ *
+ * @return The headers for the resource response.
*/
- @Override
public Map<String, String> getResponseHeaders() {
return mResponseHeaders;
}
@@ -180,6 +192,7 @@ public class WebResourceResponse extends WebResourceResponseBase {
* StringBufferInputStream.
*/
public void setData(InputStream data) {
+ checkImmutable();
// If data is (or is a subclass of) StringBufferInputStream
if (data != null && StringBufferInputStream.class.isAssignableFrom(data.getClass())) {
throw new IllegalArgumentException("StringBufferInputStream is deprecated and must " +
@@ -189,10 +202,32 @@ public class WebResourceResponse extends WebResourceResponseBase {
}
/**
- * {@inheritDoc}
+ * Gets the input stream that provides the resource response's data.
+ *
+ * @return The input stream that provides the resource response's data
*/
- @Override
public InputStream getData() {
return mInputStream;
}
+
+ /**
+ * The internal version of the constructor that doesn't perform arguments checks.
+ * @hide
+ */
+ @SystemApi
+ public WebResourceResponse(boolean immutable, String mimeType, String encoding, int statusCode,
+ String reasonPhrase, Map<String, String> responseHeaders, InputStream data) {
+ mImmutable = immutable;
+ mMimeType = mimeType;
+ mEncoding = encoding;
+ mStatusCode = statusCode;
+ mReasonPhrase = reasonPhrase;
+ mResponseHeaders = responseHeaders;
+ mInputStream = data;
+ }
+
+ private void checkImmutable() {
+ if (mImmutable)
+ throw new IllegalStateException("This WebResourceResponse instance is immutable");
+ }
}
diff --git a/core/java/android/webkit/WebResourceResponseBase.java b/core/java/android/webkit/WebResourceResponseBase.java
index cffde82c673d..69eb3974699b 100644
--- a/core/java/android/webkit/WebResourceResponseBase.java
+++ b/core/java/android/webkit/WebResourceResponseBase.java
@@ -16,53 +16,9 @@
package android.webkit;
-import java.io.InputStream;
-import java.util.Map;
-
/**
- * Encapsulates a resource response received from the server.
- * This is an abstract class used by WebView callbacks.
+ * This class will be deleted after updated WebView.apk will be submitted
+ * into the Android tree.
*/
public abstract class WebResourceResponseBase {
- /**
- * Gets the resource response's MIME type.
- *
- * @return The resource response's MIME type
- */
- public abstract String getMimeType();
-
- /**
- * Gets the resource response's encoding.
- *
- * @return The resource response's encoding
- */
- public abstract String getEncoding();
-
- /**
- * Gets the resource response's status code.
- *
- * @return The resource response's status code.
- */
- public abstract int getStatusCode();
-
- /**
- * Gets the description of the resource response's status code.
- *
- * @return The description of the resource response's status code.
- */
- public abstract String getReasonPhrase();
-
- /**
- * Gets the headers for the resource response.
- *
- * @return The headers for the resource response.
- */
- public abstract Map<String, String> getResponseHeaders();
-
- /**
- * Gets the input stream that provides the resource response's data.
- *
- * @return The input stream that provides the resource response's data
- */
- public abstract InputStream getData();
}
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java
index 3a40de6312d3..feed2b8f22bf 100644
--- a/core/java/android/webkit/WebViewClient.java
+++ b/core/java/android/webkit/WebViewClient.java
@@ -233,11 +233,20 @@ public class WebViewClient {
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
if (request.isForMainFrame()) {
onReceivedError(view,
- error.getErrorCode(), error.getDescription(), request.getUrl().toString());
+ error.getErrorCode(), error.getDescription().toString(),
+ request.getUrl().toString());
}
}
/**
+ * This method will be deleted after updated WebView.apk will be submitted
+ * into the Android tree.
+ */
+ public void onReceivedHttpError(
+ WebView view, WebResourceRequest request, WebResourceResponseBase errorResponse) {
+ }
+
+ /**
* Notify the host application that an HTTP error has been received from the server while
* loading a resource. HTTP errors have status codes &gt;= 400. This callback will be called
* for any resource (iframe, image, etc), not just for the main page. Thus, it is recommended to
@@ -248,7 +257,7 @@ public class WebViewClient {
* @param errorResponse Information about the error occured.
*/
public void onReceivedHttpError(
- WebView view, WebResourceRequest request, WebResourceResponseBase errorResponse) {
+ WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
}
/**