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

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

Issue 1270793002: [Android WebView] Put error page files into WebView resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added RTL direction support Created 5 years, 4 months 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/AwResource.java
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 19662a8d4c9c8ec46b098270e750308c2f5eea7d..fac58818765dcf59426e18e52099cba1e5840479 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;
- }
}

Powered by Google App Engine
This is Rietveld 408576698