From 6243e7cb0eb836af28b23a2e00d89627b90496e4 Mon Sep 17 00:00:00 2001 From: Selim Gurun Date: Tue, 14 Jan 2014 17:27:54 -0800 Subject: Restrict loading private browser files Bug:11516871 Change-Id: I6a717a157f3d29edfffc36dc2da45c6df30d6ccd --- src/com/android/browser/Tab.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/com/android/browser/Tab.java') diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 28734bd..2f00b26 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -71,6 +71,7 @@ import com.android.browser.TabControl.OnThumbnailUpdatedListener; import com.android.browser.homepages.HomeProvider; import com.android.browser.provider.SnapshotProvider.Snapshots; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -100,6 +101,8 @@ class Tab implements PictureListener { private static final int CAPTURE_DELAY = 100; private static final int INITIAL_PROGRESS = 5; + private static final String RESTRICTED = "not allowed"; + private static Bitmap sDefaultFavicon; private static Paint sAlphaPaint = new Paint(); @@ -623,6 +626,24 @@ class Tab implements PictureListener { @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { + Uri uri = Uri.parse(url); + if (uri.getScheme().toLowerCase().equals("file")) { + File file = new File(uri.getPath()); + try { + if (file.getCanonicalPath().startsWith( + mContext.getDatabasePath("foo").getParent())) { + return new WebResourceResponse("text/html","UTF-8", + new ByteArrayInputStream(RESTRICTED.getBytes("UTF-8"))); + } + } catch (Exception ex) { + Log.e(LOGTAG, "Bad canonical path" + ex.toString()); + try { + return new WebResourceResponse("text/html","UTF-8", + new ByteArrayInputStream(RESTRICTED.getBytes("UTF-8"))); + } catch (java.io.UnsupportedEncodingException e) { + } + } + } WebResourceResponse res = HomeProvider.shouldInterceptRequest( mContext, url); return res; -- cgit v1.1