summaryrefslogtreecommitdiffstats
path: root/android_webview/java
diff options
context:
space:
mode:
authormnaganov <mnaganov@chromium.org>2015-08-05 13:09:53 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-05 20:10:29 +0000
commitf082f6cb6e1c2b57554bb9b91b6dbd7214027c4f (patch)
tree7dfc25929a9e1ab9f72d57ac9ded91bea0d36513 /android_webview/java
parentdad5f3d8a876981d8a053bd2f81b13e2b69bb1a6 (diff)
downloadchromium_src-f082f6cb6e1c2b57554bb9b91b6dbd7214027c4f.zip
chromium_src-f082f6cb6e1c2b57554bb9b91b6dbd7214027c4f.tar.gz
chromium_src-f082f6cb6e1c2b57554bb9b91b6dbd7214027c4f.tar.bz2
[Android WebView] Put error page files into WebView resources
Historically, the load error pages displayed by WebView were a part of Android framework resources. This change adds them into WebView resources. This way, the pages will be accessible to sandboxed child services, using Chromium's resource sharing mechanisms. Unlike Chrome's error pages, which use WebUI, WebView pages are completely static, as JavaScript can be disabled. BUG=515691 Review URL: https://codereview.chromium.org/1270793002 Cr-Commit-Position: refs/heads/master@{#341951}
Diffstat (limited to 'android_webview/java')
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwResource.java81
1 files changed, 1 insertions, 80 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwResource.java b/android_webview/java/src/org/chromium/android_webview/AwResource.java
index 19662a8..fac5881 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwResource.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwResource.java
@@ -10,11 +10,7 @@ import android.util.SparseArray;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.lang.ref.SoftReference;
-import java.util.NoSuchElementException;
-import java.util.Scanner;
/**
* A class that defines a set of resource IDs and functionality to resolve
@@ -24,14 +20,6 @@ import java.util.Scanner;
public class AwResource {
// The following resource ID's must be initialized by the embedder.
- // Raw resource ID for an HTML page to be displayed in the case of
- // a specific load error.
- private static int sRawLoadError;
-
- // Raw resource ID for an HTML page to be displayed in the case of
- // a generic load error. (It's called NO_DOMAIN for legacy reasons).
- private static int sRawNoDomain;
-
// Array resource ID for the configuration of platform specific key-systems.
private static int sStringArrayConfigKeySystemUUIDMapping;
@@ -42,17 +30,13 @@ public class AwResource {
// Loading some resources is expensive, so cache the results.
private static SparseArray<SoftReference<String>> sResourceCache;
- private static final int TYPE_STRING = 0;
- private static final int TYPE_RAW = 1;
-
public static void setResources(Resources resources) {
sResources = resources;
sResourceCache = new SparseArray<SoftReference<String>>();
}
public static void setErrorPageResources(int loaderror, int nodomain) {
- sRawLoadError = loaderror;
- sRawNoDomain = nodomain;
+ // TODO(mnaganov): Remove after getting rid of all usages.
}
public static void setConfigKeySystemUuidMapping(int config) {
@@ -60,71 +44,8 @@ public class AwResource {
}
@CalledByNative
- private static String getNoDomainPageContent() {
- return getResource(sRawNoDomain, TYPE_RAW);
- }
-
- @CalledByNative
- private static String getLoadErrorPageContent() {
- return getResource(sRawLoadError, TYPE_RAW);
- }
-
- @CalledByNative
private static String[] getConfigKeySystemUuidMapping() {
// No need to cache, since this should be called only once.
return sResources.getStringArray(sStringArrayConfigKeySystemUUIDMapping);
}
-
- private static String getResource(int resid, int type) {
- assert resid != 0;
- assert sResources != null;
- assert sResourceCache != null;
-
- SoftReference<String> stringRef = sResourceCache.get(resid);
- String result = stringRef == null ? null : stringRef.get();
- if (result == null) {
- switch (type) {
- case TYPE_STRING:
- result = sResources.getString(resid);
- break;
- case TYPE_RAW:
- result = getRawFileResourceContent(resid);
- break;
- default:
- throw new IllegalArgumentException("Unknown resource type");
- }
-
- sResourceCache.put(resid, new SoftReference<String>(result));
- }
- return result;
- }
-
- private static String getRawFileResourceContent(int resid) {
- assert resid != 0;
- assert sResources != null;
-
- InputStreamReader isr = null;
- String result = null;
-
- try {
- isr = new InputStreamReader(
- sResources.openRawResource(resid));
- // \A tells the scanner to use the beginning of the input
- // as the delimiter, hence causes it to read the entire text.
- result = new Scanner(isr).useDelimiter("\\A").next();
- } catch (Resources.NotFoundException e) {
- return "";
- } catch (NoSuchElementException e) {
- return "";
- } finally {
- try {
- if (isr != null) {
- isr.close();
- }
- } catch (IOException e) {
- // Nothing to do if close() fails.
- }
- }
- return result;
- }
}