Merge "Check for null data after decoding a data: url."
This commit is contained in:
committed by
Android (Google) Code Review
commit
c209ccf460
@@ -31,7 +31,6 @@ import java.io.FileInputStream;
|
||||
class ContentLoader extends StreamLoader {
|
||||
|
||||
private String mUrl;
|
||||
private Context mContext;
|
||||
private String mContentType;
|
||||
|
||||
/**
|
||||
@@ -40,11 +39,9 @@ class ContentLoader extends StreamLoader {
|
||||
* @param rawUrl "content:" url pointing to content to be loaded. This url
|
||||
* is the same url passed in to the WebView.
|
||||
* @param loadListener LoadListener to pass the content to
|
||||
* @param context Context to use to access the asset.
|
||||
*/
|
||||
ContentLoader(String rawUrl, LoadListener loadListener, Context context) {
|
||||
ContentLoader(String rawUrl, LoadListener loadListener) {
|
||||
super(loadListener);
|
||||
mContext = context;
|
||||
|
||||
/* strip off mimetype */
|
||||
int mimeIndex = rawUrl.lastIndexOf('?');
|
||||
@@ -81,7 +78,7 @@ class ContentLoader extends StreamLoader {
|
||||
|
||||
try {
|
||||
mDataStream = mContext.getContentResolver().openInputStream(uri);
|
||||
mHandler.status(1, 1, 0, "OK");
|
||||
mHandler.status(1, 1, 200, "OK");
|
||||
} catch (java.io.FileNotFoundException ex) {
|
||||
mHandler.error(EventHandler.FILE_NOT_FOUND_ERROR, errString(ex));
|
||||
return false;
|
||||
@@ -112,11 +109,9 @@ class ContentLoader extends StreamLoader {
|
||||
*
|
||||
* @param url "content:" url pointing to content to be loaded
|
||||
* @param loadListener LoadListener to pass the content to
|
||||
* @param context Context to use to access the asset.
|
||||
*/
|
||||
public static void requestUrl(String url, LoadListener loadListener,
|
||||
Context context) {
|
||||
ContentLoader loader = new ContentLoader(url, loadListener, context);
|
||||
public static void requestUrl(String url, LoadListener loadListener) {
|
||||
ContentLoader loader = new ContentLoader(url, loadListener);
|
||||
loader.load();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package android.webkit;
|
||||
|
||||
import android.net.http.EventHandler;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.apache.harmony.luni.util.Base64;
|
||||
@@ -49,14 +53,22 @@ class DataLoader extends StreamLoader {
|
||||
} else {
|
||||
data = url.getBytes();
|
||||
}
|
||||
mDataStream = new ByteArrayInputStream(data);
|
||||
mContentLength = data.length;
|
||||
if (data != null) {
|
||||
mDataStream = new ByteArrayInputStream(data);
|
||||
mContentLength = data.length;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setupStreamAndSendStatus() {
|
||||
mHandler.status(1, 1, 0, "OK");
|
||||
return true;
|
||||
if (mDataStream != null) {
|
||||
mHandler.status(1, 1, 200, "OK");
|
||||
return true;
|
||||
} else {
|
||||
mHandler.error(EventHandler.ERROR,
|
||||
mContext.getString(R.string.httpError));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,6 @@ import java.lang.reflect.Field;
|
||||
class FileLoader extends StreamLoader {
|
||||
|
||||
private String mPath; // Full path to the file to load
|
||||
private Context mContext; // Application context, used for asset/res loads
|
||||
private int mType; // Indicates the type of the load
|
||||
private boolean mAllowFileAccess; // Allow/block file system access
|
||||
|
||||
@@ -57,16 +56,14 @@ class FileLoader extends StreamLoader {
|
||||
*
|
||||
* @param url Full file url pointing to content to be loaded
|
||||
* @param loadListener LoadListener to pass the content to
|
||||
* @param context Context to use to access the asset.
|
||||
* @param asset true if url points to an asset.
|
||||
* @param allowFileAccess true if this WebView is allowed to access files
|
||||
* on the file system.
|
||||
*/
|
||||
FileLoader(String url, LoadListener loadListener, Context context,
|
||||
int type, boolean allowFileAccess) {
|
||||
FileLoader(String url, LoadListener loadListener, int type,
|
||||
boolean allowFileAccess) {
|
||||
super(loadListener);
|
||||
mType = type;
|
||||
mContext = context;
|
||||
mAllowFileAccess = allowFileAccess;
|
||||
|
||||
// clean the Url
|
||||
@@ -174,7 +171,7 @@ class FileLoader extends StreamLoader {
|
||||
mDataStream = new FileInputStream(mPath);
|
||||
mContentLength = (new File(mPath)).length();
|
||||
}
|
||||
mHandler.status(1, 1, 0, "OK");
|
||||
mHandler.status(1, 1, 200, "OK");
|
||||
|
||||
} catch (java.io.FileNotFoundException ex) {
|
||||
mHandler.error(EventHandler.FILE_NOT_FOUND_ERROR, errString(ex));
|
||||
@@ -198,14 +195,13 @@ class FileLoader extends StreamLoader {
|
||||
*
|
||||
* @param url Full file url pointing to content to be loaded
|
||||
* @param loadListener LoadListener to pass the content to
|
||||
* @param context Context to use to access the asset.
|
||||
* @param asset true if url points to an asset.
|
||||
* @param allowFileAccess true if this FileLoader can load files from the
|
||||
* file system.
|
||||
*/
|
||||
public static void requestUrl(String url, LoadListener loadListener,
|
||||
Context context, int type, boolean allowFileAccess) {
|
||||
FileLoader loader = new FileLoader(url, loadListener, context, type,
|
||||
int type, boolean allowFileAccess) {
|
||||
FileLoader loader = new FileLoader(url, loadListener, type,
|
||||
allowFileAccess);
|
||||
loader.load();
|
||||
}
|
||||
|
||||
@@ -141,22 +141,21 @@ class FrameLoader {
|
||||
return true;
|
||||
}
|
||||
if (URLUtil.isAssetUrl(url)) {
|
||||
FileLoader.requestUrl(url, loadListener, loadListener.getContext(),
|
||||
FileLoader.TYPE_ASSET, true);
|
||||
FileLoader.requestUrl(url, loadListener, FileLoader.TYPE_ASSET,
|
||||
true);
|
||||
return true;
|
||||
} else if (URLUtil.isResourceUrl(url)) {
|
||||
FileLoader.requestUrl(url, loadListener, loadListener.getContext(),
|
||||
FileLoader.TYPE_RES, true);
|
||||
FileLoader.requestUrl(url, loadListener, FileLoader.TYPE_RES,
|
||||
true);
|
||||
return true;
|
||||
} else if (URLUtil.isFileUrl(url)) {
|
||||
FileLoader.requestUrl(url, loadListener, loadListener.getContext(),
|
||||
FileLoader.TYPE_FILE, settings.getAllowFileAccess());
|
||||
FileLoader.requestUrl(url, loadListener, FileLoader.TYPE_FILE,
|
||||
settings.getAllowFileAccess());
|
||||
return true;
|
||||
} else if (URLUtil.isContentUrl(url)) {
|
||||
// Send the raw url to the ContentLoader because it will do a
|
||||
// permission check and the url has to match..
|
||||
ContentLoader.requestUrl(loadListener.url(), loadListener,
|
||||
loadListener.getContext());
|
||||
ContentLoader.requestUrl(loadListener.url(), loadListener);
|
||||
return true;
|
||||
} else if (URLUtil.isDataUrl(url)) {
|
||||
DataLoader.requestUrl(url, loadListener);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.webkit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.http.EventHandler;
|
||||
import android.net.http.Headers;
|
||||
import android.os.Handler;
|
||||
@@ -52,7 +53,8 @@ abstract class StreamLoader extends Handler {
|
||||
private static final int MSG_DATA = 102; // Send data to loader
|
||||
private static final int MSG_END = 103; // Send endData to loader
|
||||
|
||||
protected LoadListener mHandler; // loader class
|
||||
protected final Context mContext;
|
||||
protected final LoadListener mHandler; // loader class
|
||||
protected InputStream mDataStream; // stream to read data from
|
||||
protected long mContentLength; // content length of data
|
||||
private byte [] mData; // buffer to pass data to loader with.
|
||||
@@ -66,6 +68,7 @@ abstract class StreamLoader extends Handler {
|
||||
*/
|
||||
StreamLoader(LoadListener loadlistener) {
|
||||
mHandler = loadlistener;
|
||||
mContext = loadlistener.getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user